Hi All,<br><br>I have developed a callback to update the pixel value of an image being displayed in a widget. The idea is to set the pixels to zero in the points where the mouse is over and the left button is pressed.<br><br>
The problem is that I can&#39;t see any changes in the image, even after calling the Render method.<br><br>This is the code:<br><br>class vtkImageInteractionCallback : public vtkCommand<br>{<br>public:<br><br>&nbsp; static vtkImageInteractionCallback *New() {<br>
&nbsp;&nbsp;&nbsp; return new vtkImageInteractionCallback;<br>&nbsp; };<br>&nbsp;<br>&nbsp; vtkImageInteractionCallback() {<br>&nbsp;&nbsp;&nbsp; this-&gt;Slicing = 0;<br>&nbsp; };<br><br>&nbsp; void SetInteractor(vtkRenderWindowInteractor *interactor) {<br>&nbsp;&nbsp;&nbsp; this-&gt;Interactor = interactor;<br>
&nbsp; };<br><br>&nbsp; void SetImageViewer(vtkImageViewer2* viewer) {<br>&nbsp;&nbsp;&nbsp; this-&gt;viewer = viewer;<br>&nbsp; };<br><br>&nbsp; void SetPicker(vtkPointPicker* picker) {<br>&nbsp;&nbsp;&nbsp; this-&gt;picker = picker;<br>&nbsp; };<br><br>&nbsp; void performAction() {<br>
&nbsp;&nbsp;&nbsp; if (!picker-&gt;Pick(this-&gt;Interactor-&gt;GetEventPosition()[0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;Interactor-&gt;GetEventPosition()[1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer-&gt;GetRenderer())) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; double ptMapped[3];<br>&nbsp;&nbsp; picker-&gt;GetMapperPosition(ptMapped);<br><br>&nbsp;&nbsp; double dSpacing[3];<br>&nbsp;&nbsp; viewer-&gt;GetInput()-&gt;GetSpacing(dSpacing);<br>&nbsp;&nbsp; ptMapped[2] = viewer-&gt;GetSlice() * dSpacing[2];<br>
<br>&nbsp;&nbsp; printf(&quot;x=%d : y=%d\n&quot;, (int)ptMapped[0], (int)ptMapped[1]);<br><br>&nbsp;&nbsp; // Update the image<br>&nbsp;&nbsp; vtkImageData* image = viewer-&gt;GetInput(); // It is a 2D image.<br>&nbsp;&nbsp; image-&gt;AllocateScalars();<br>&nbsp;&nbsp; image-&gt;SetScalarComponentFromDouble(ptMapped[0], ptMapped[1], 0, 0, image-&gt;GetScalarTypeMin());<br>
&nbsp;&nbsp; image-&gt;Update();<br>&nbsp;&nbsp; viewer-&gt;SetInput(image);<br><br>&nbsp;&nbsp; printf(&quot;GetScalarTypeMin: %f\n&quot;, image-&gt;GetScalarTypeMin());<br>&nbsp;&nbsp; viewer-&gt;Render();<br>&nbsp; };<br><br>&nbsp; virtual void Execute(vtkObject *, unsigned long event, void *) {<br>
&nbsp;&nbsp;&nbsp; if (event == vtkCommand::LeftButtonPressEvent) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;Slicing = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; performAction();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; else if (event == vtkCommand::LeftButtonReleaseEvent) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;Slicing = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; performAction();<br>
&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; else if (event == vtkCommand::MouseMoveEvent) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this-&gt;Slicing) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; performAction();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; };<br>&nbsp;<br>private: <br>&nbsp; int Slicing;<br>&nbsp; vtkRenderWindowInteractor* Interactor;<br>
&nbsp; vtkPointPicker* picker;<br>&nbsp; vtkImageViewer2* viewer;<br>};<br><br>Thanks in advance,<br>Luis<br>