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'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> static vtkImageInteractionCallback *New() {<br>
return new vtkImageInteractionCallback;<br> };<br> <br> vtkImageInteractionCallback() {<br> this->Slicing = 0;<br> };<br><br> void SetInteractor(vtkRenderWindowInteractor *interactor) {<br> this->Interactor = interactor;<br>
};<br><br> void SetImageViewer(vtkImageViewer2* viewer) {<br> this->viewer = viewer;<br> };<br><br> void SetPicker(vtkPointPicker* picker) {<br> this->picker = picker;<br> };<br><br> void performAction() {<br>
if (!picker->Pick(this->Interactor->GetEventPosition()[0],<br> this->Interactor->GetEventPosition()[1],<br> 0,<br> viewer->GetRenderer())) {<br>
return;<br> }<br> double ptMapped[3];<br> picker->GetMapperPosition(ptMapped);<br><br> double dSpacing[3];<br> viewer->GetInput()->GetSpacing(dSpacing);<br> ptMapped[2] = viewer->GetSlice() * dSpacing[2];<br>
<br> printf("x=%d : y=%d\n", (int)ptMapped[0], (int)ptMapped[1]);<br><br> // Update the image<br> vtkImageData* image = viewer->GetInput(); // It is a 2D image.<br> image->AllocateScalars();<br> image->SetScalarComponentFromDouble(ptMapped[0], ptMapped[1], 0, 0, image->GetScalarTypeMin());<br>
image->Update();<br> viewer->SetInput(image);<br><br> printf("GetScalarTypeMin: %f\n", image->GetScalarTypeMin());<br> viewer->Render();<br> };<br><br> virtual void Execute(vtkObject *, unsigned long event, void *) {<br>
if (event == vtkCommand::LeftButtonPressEvent) {<br> this->Slicing = 1;<br> performAction();<br> }<br> else if (event == vtkCommand::LeftButtonReleaseEvent) {<br> this->Slicing = 0;<br> performAction();<br>
}<br> else if (event == vtkCommand::MouseMoveEvent) {<br> if (this->Slicing) {<br> performAction();<br> }<br> }<br> };<br> <br>private: <br> int Slicing;<br> vtkRenderWindowInteractor* Interactor;<br>
vtkPointPicker* picker;<br> vtkImageViewer2* viewer;<br>};<br><br>Thanks in advance,<br>Luis<br>