[vtkusers] vtkImageviewer2 related

ankit.master at gmail.com ankit.master at gmail.com
Thu Mar 1 17:30:43 EST 2012


Hello, 

I had two questions related to the use of ImageViewer2, I am working on a
project in which I am required to create an image viewer to visualize
floating point data with multiple render windows. I tried looking up at the
documentation of vtkImageViewer2 but did not find my answers in it therefore
I thought of seeking your help. 

Following are my questions 
1) Is vtkImageViewer2 suitable for viewing floating point data. When I look
at the images they look really smooth , which makes me wonder if the
intensities are automatically scaled from float to unsigned char ( I was
able to load the images and view them using vtkImageViewer2)  . 

2) I am trying to render multiple windows and each of these windows need to
display pixel coordinate and value when the mouse is hovered over the pixel,
so I looked up online and came across an example to do so
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/PickPixel

I even successfully implemented this design but as soon as I extend this
concept to multiple window rendering, my code breaks. Could you please
advise what am I doing incorrect here. (Please see the code at the bottom of
the page) 

Thank you 
Sincerely, 
Ankit 



Following is my source code. 

 vtkSmartPointer<vtkImageData> grayImageReal =
vtkSmartPointer<vtkImageData>::New();
 vtkSmartPointer<vtkImageData> grayImageImaginary =
vtkSmartPointer<vtkImageData>::New();

    CreateGrayScaleImage(grayImageReal, realImage);
    CreateGrayScaleImage(grayImageImaginary, imaginaryImage);


    std::vector < vtkSmartPointer<vtkImageData> >  imageDataP; 
    std::vector < vtkSmartPointer<vtkImageData> >::iterator it; 
   

    imageDataP.push_back(grayImageReal);
    imageDataP.push_back(grayImageImaginary);

   for (it = imageDataP.begin(); it < imageDataP.end(); it++)
    {
        vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();

        // Visualize
        vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
vtkSmartPointer<vtkRenderWindowInteractor>::New();
        imageViewer->SetInputConnection( (*it)->GetProducerPort() );
        imageViewer->SetupInteractor( renderWindowInteractor );
        imageViewer->SetSize( 700, 700 );
     
        // Set Color level and window  
        double* range = (*it)->GetScalarRange(); 
        imageViewer->SetColorLevel(0.5* (range[1]+range[0])); 
        imageViewer->SetColorWindow(range[1]-range[0]); 

        // Picker to pick pixels
        vtkSmartPointer<vtkPropPicker> propPicker =
vtkSmartPointer<vtkPropPicker>::New();
        propPicker->PickFromListOn();
        propPicker->AddPickList( imageViewer->GetImageActor() );

        // Annotate the image with window/level and mouse over pixel
information
        vtkSmartPointer<vtkCornerAnnotation> cornerAnnotation =
vtkSmartPointer<vtkCornerAnnotation>::New();
        cornerAnnotation->SetLinearFontScaleFactor( 2 );
        cornerAnnotation->SetNonlinearFontScaleFactor( 1 );
        cornerAnnotation->SetMaximumFontSize( 20 );
        cornerAnnotation->SetText( 0, "Off Image" );
        cornerAnnotation->SetText( 3, "<window>\n<level>" );
        cornerAnnotation->GetTextProperty()->SetColor( 1,0,0);

        imageViewer->GetRenderer()->AddViewProp( cornerAnnotation );

        // Callback listens to MouseMoveEvents invoked by the interactor's
style
        vtkSmartPointer<vtkImageInteractionCallback1> callback =
vtkSmartPointer<vtkImageInteractionCallback1>::New();
        callback->SetViewer( imageViewer );
        callback->SetAnnotation( cornerAnnotation );
        callback->SetPicker( propPicker );

        vtkRenderer* renderer = imageViewer->GetRenderer();

       // vtkSmartPointer<vtkInteractorStyleImage> style =
vtkSmartPointer<vtkInteractorStyleImage>::New();
  
        vtkInteractorStyleImage* imageStyle =
imageViewer->GetInteractorStyle();
        imageStyle->AddObserver( vtkCommand::MouseMoveEvent, callback );

        renderer->ResetCamera();
        
        m_interactors.push_back(renderWindowInteractor);
        renderWindowInteractor->Initialize();
        renderWindowInteractor->Start(); 
  }
  
       m_interactors[1]->Start();

where m_interactors is a vector of type vtkrenderWindowInteractor . 
     return 1; 
}

--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageviewer2-related-tp5529444p5529444.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list