<div dir="ltr"><div style>Hello,</div><div><br></div>I am trying to retrieve the values of a pixel from a mouse clicks and I pass the x and y parameters to the crop function , but when I click on the image , the application crashes. here is my code:<br>
<div><br></div><div><div>class MouseInteractorStyle3 : public vtkInteractorStyleTrackballCamera</div><div>{</div><div> public:</div><div> static MouseInteractorStyle3* New();</div><div><br></div><div> virtual void OnLeftButtonDown() </div>
<div> {</div><div>typedef itk::Image<unsigned short,2> ImageType;</div><div><br></div><div><br></div><div> std::cout << "Pressed left mouse button." << std::endl;</div><div> int x = this->Interactor->GetEventPosition()[0];</div>
<div> int y = this->Interactor->GetEventPosition()[1];</div><div><span class="" style="white-space:pre">        </span></div><div><br></div><div> vtkSmartPointer<vtkCoordinate> coordinate = </div><div> vtkSmartPointer<vtkCoordinate>::New();</div>
<div> coordinate->SetCoordinateSystemToDisplay();</div><div> coordinate->SetValue(x,y,0);</div><div><span class="" style="white-space:pre">        </span> </div><div><span class="" style="white-space:pre">        </span> </div>
<div> </div><div> // This doesn't produce the right value if the sphere is zoomed in???</div><div> double* world = coordinate->GetComputedWorldValue(this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());</div>
<div> std::cout << "World coordinate: " << world[0] << ", " << world[1] << ", " << world[2] << std::endl;</div><div> Crop(x,y);</div><div> // Forward events</div>
<div> vtkInteractorStyleTrackballCamera::OnLeftButtonDown();</div><div><span class="" style="white-space:pre">        </span> </div><div> }</div><div><span class="" style="white-space:pre">        </span>void Crop(int x, int y){</div>
<div>typedef itk::Image<unsigned short,2> ImageType;</div><div>typedef itk::ImageFileReader<ImageType> ReaderType;</div><div>typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;</div><div>ReaderType::Pointer reader= ReaderType::New();</div>
<div>ConnectorType::Pointer Connector= ConnectorType::New();</div><div><br></div><div>ImageType::Pointer image = ImageType::New();</div><div> ImageType::SizeType cropSize;</div><div><br></div><div>reader->SetFileName("C:/Test.jpg");</div>
<div>reader->Update();</div><div> </div><div>image = reader->GetOutput();</div><div> cropSize[0] = x;</div><div> cropSize[1] = y;</div><div><span class="" style="white-space:pre">        </span>typedef itk::CropImageFilter <ImageType, ImageType></div>
<div> CropImageFilterType;</div><div> </div><div> CropImageFilterType::Pointer cropFilter</div><div> = CropImageFilterType::New();</div><div> cropFilter->SetInput(image);</div><div> cropFilter->SetBoundaryCropSize(cropSize);</div>
<div> cropFilter->Update();</div><div><br></div><div>typedef itk::FlipImageFilter< ImageType > FlipImageFilterType;</div><div><br></div><div>FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New ();</div>
<div> // flipFilter->SetInput( reader->GetOutput() );</div><div> flipFilter->SetInput( cropFilter->GetOutput() );</div><div><br></div><div> bool flipAxes[3] = { false, true, false };</div><div>flipFilter->SetFlipAxes(flipAxes);</div>
<div>flipFilter->Update();</div><div><br></div><div>Connector->SetInput( flipFilter->GetOutput() );</div><div>vtkImageViewer* viewer= vtkImageViewer::New();</div><div><br></div><div>vtkRenderWindowInteractor* renderWindowInteractor = vtkRenderWindowInteractor::New();</div>
<div>viewer->SetupInteractor( renderWindowInteractor);</div><div>viewer->SetInput( Connector->GetOutput() );</div><div>viewer->Render();</div><div>viewer->SetColorWindow( 255);</div><div>viewer->SetColorLevel(128);</div>
<div>renderWindowInteractor->Start();</div><div><span class="" style="white-space:pre">        </span>}</div><div> </div><div>};</div><div> </div><div>vtkStandardNewMacro(MouseInteractorStyle3);</div></div><div><br></div><div>
<br></div><div><br></div><div>I spent a lot temp to seek a solution to a crop with mouse manipulation, I tried to find a solution that unfortunately contains a bug, I count on you to help me, I really need your help.<br></div>
<div><br></div><div style>Please answer me!!</div><div style>thank you</div><div><br></div><div><br></div></div>