<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&lt;unsigned short,2&gt; ImageType;</div><div><br></div><div><br></div><div>      std::cout &lt;&lt; &quot;Pressed left mouse button.&quot; &lt;&lt; std::endl;</div><div>      int x = this-&gt;Interactor-&gt;GetEventPosition()[0];</div>
<div>      int y = this-&gt;Interactor-&gt;GetEventPosition()[1];</div><div><span class="" style="white-space:pre">        </span></div><div><br></div><div>      vtkSmartPointer&lt;vtkCoordinate&gt; coordinate = </div><div>        vtkSmartPointer&lt;vtkCoordinate&gt;::New();</div>
<div>      coordinate-&gt;SetCoordinateSystemToDisplay();</div><div>      coordinate-&gt;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&#39;t produce the right value if the sphere is zoomed in???</div><div>      double* world = coordinate-&gt;GetComputedWorldValue(this-&gt;Interactor-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer());</div>
<div>      std::cout &lt;&lt; &quot;World coordinate: &quot; &lt;&lt; world[0] &lt;&lt; &quot;, &quot; &lt;&lt; world[1] &lt;&lt; &quot;, &quot; &lt;&lt; world[2] &lt;&lt; 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&lt;unsigned short,2&gt; ImageType;</div><div>typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;</div><div>typedef itk::ImageToVTKImageFilter&lt;ImageType&gt; 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-&gt;SetFileName(&quot;C:/Test.jpg&quot;);</div>
<div>reader-&gt;Update();</div><div> </div><div>image = reader-&gt;GetOutput();</div><div>    cropSize[0] = x;</div><div>    cropSize[1] = y;</div><div><span class="" style="white-space:pre">        </span>typedef itk::CropImageFilter &lt;ImageType, ImageType&gt;</div>
<div>    CropImageFilterType;</div><div> </div><div>  CropImageFilterType::Pointer cropFilter</div><div>    = CropImageFilterType::New();</div><div>  cropFilter-&gt;SetInput(image);</div><div>  cropFilter-&gt;SetBoundaryCropSize(cropSize);</div>
<div>  cropFilter-&gt;Update();</div><div><br></div><div>typedef itk::FlipImageFilter&lt; ImageType &gt;   FlipImageFilterType;</div><div><br></div><div>FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New ();</div>
<div> // flipFilter-&gt;SetInput( reader-&gt;GetOutput() );</div><div>  flipFilter-&gt;SetInput( cropFilter-&gt;GetOutput() );</div><div><br></div><div>  bool flipAxes[3] = { false, true, false };</div><div>flipFilter-&gt;SetFlipAxes(flipAxes);</div>
<div>flipFilter-&gt;Update();</div><div><br></div><div>Connector-&gt;SetInput( flipFilter-&gt;GetOutput() );</div><div>vtkImageViewer* viewer= vtkImageViewer::New();</div><div><br></div><div>vtkRenderWindowInteractor* renderWindowInteractor = vtkRenderWindowInteractor::New();</div>
<div>viewer-&gt;SetupInteractor( renderWindowInteractor);</div><div>viewer-&gt;SetInput( Connector-&gt;GetOutput() );</div><div>viewer-&gt;Render();</div><div>viewer-&gt;SetColorWindow( 255);</div><div>viewer-&gt;SetColorLevel(128);</div>
<div>renderWindowInteractor-&gt;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>