[vtkusers] working with vtkImageViewer2

Ziv Yaniv zivy at isis.imac.georgetown.edu
Mon May 2 16:40:47 EDT 2005


Hi all,

 I am trying to use vtkImageViewer2 with not much success.
 I try to display images of different sizes using the same pipeline.
 When I update the image data (change its size) and request that the 
image viewer
  render the new scene, the program fails with an error message "update 
extent does not lie within whole extent".

  Below is a small program that causes this error. To see the problem 
run the program and press shift+right mouse so that the vtkCommand
   is executed.
   I can't figure out how exactly I am breaking the vtk pipeline found 
inside the vtkImageViewer2.

                                                                                                        
thanks
                                                                                                             
Ziv

#include <vtkImageViewer2.h>
#include <vtkFlRenderWindowInteractor.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkInteractorStyleImage.h>
#include <vtkCommand.h>

vtkImageData *image;
vtkImageViewer2* imageViewer;

//when callback is called, update the image to a new size
class ImageClickedCallback : public vtkCommand
{
public:
 static ImageClickedCallback *New() {return new ImageClickedCallback;}
 virtual void Execute(vtkObject *caller, unsigned long eventId, void 
*userData)
   {
           vtkImageCanvasSource2D *imageSource = 
vtkImageCanvasSource2D::New();
           imageSource->SetExtent(0,10,0,10,0,0);
       image->DeepCopy(imageSource->GetOutput());          
imageViewer->Render();
       imageSource->Delete();
   }
};

void ExitCallback(Fl_Widget *, void *)
{
   exit(0);
}

void main(int argc, char *argv[])
{
                          //create GUI
   int windowSize = 400;
   int padding = 5;
   Fl_Window *mainWindow = new Fl_Window(windowSize,windowSize);
   vtkFlRenderWindowInteractor *renderWindowInteractor = new 
vtkFlRenderWindowInteractor(padding,padding,windowSize-padding,windowSize-padding,NULL); 


   mainWindow->callback(ExitCallback, renderWindowInteractor);
   mainWindow->end();        imageViewer = vtkImageViewer2::New();
   imageViewer->SetupInteractor(renderWindowInteractor);
   renderWindowInteractor->Initialize();

   ImageClickedCallback *clickedCallback = ImageClickedCallback::New();
   vtkInteractorStyleImage *interactorStyle = 
(vtkInteractorStyleImage*)(((imageViewer->GetRenderWindow())->GetInteractor())->GetInteractorStyle());  

   interactorStyle->AddObserver(vtkCommand::EndPickEvent,clickedCallback);
   clickedCallback->Delete();

                           //create initial image
   vtkImageCanvasSource2D *imageSource = vtkImageCanvasSource2D::New();
   imageSource->SetExtent(0,1000,0,1,0,0);
   image = vtkImageData::New();
   image->DeepCopy(imageSource->GetOutput());      
imageViewer->SetInput(image);
   imageSource->Delete();

                  //show GUI and enter event loop
   mainWindow->show();
   renderWindowInteractor->show();
   Fl::run();
}




More information about the vtkusers mailing list