[vtkusers] Reg vtkCamera and vtkimageviewer2 - No camera change reflected in the image

Karthik Krishnan karthik.krishnan at kitware.com
Mon Jan 18 04:31:18 EST 2010


You don't want to control a vtkImageViewer2 using an external camera.
You will end up with conflicting settings of camera orientation from
your code and the vtkImageViewer2 class (See
vtkImageViewer2::UpdateOrientation).

The right way to do this would be ...

  viewer->SetSliceOrientationToXY(); // or YZ or XZ etc.

Alternatively subclass vtkImageViewer2 if you wish to override the
ViewUp's it provides with the corresponding SliceOrientaiton.



On Mon, Jan 18, 2010 at 4:10 AM, Anu <anuradha.tcs at gmail.com> wrote:
> I have a simple vtkImageViewer2 code displaying 3D data. I am trying to
> display correct orientation due to ITK to vtk conversion.
> but change in any of the variables of vtkCamera like viewUp is not reflected
> in the image. Have tried to see user list but the code seems to be not
> working.
> Please help in finding whats wrong with the code.
>
> // Create Renderer
> vtkRenderer *ren1 = vtkRenderer::New();
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> typedef unsigned short    PixelType;
> const unsigned int      Dimension = 3;
> typedef itk::Image< PixelType, Dimension >         ImageType;
> // Create the reader for the data
> typedef itk::ImageFileReader <ImageType> FileReaderType;
> FileReaderType::Pointer reader = FileReaderType::New();
> reader->SetFileName(argv[1]);
> reader->Update();
>    std::cout << "Reading and conversion Complete.." << std::endl;
> // ITK To VTK conversion
>
> typedef itk::ImageToVTKImageFilter <ImageType>   itktovtkConnectorType;
>  itktovtkConnectorType::Pointer connector1_UC =
> itktovtkConnectorType::New();
> connector1_UC->SetInput(reader->GetOutput());
> try
> {
> connector1_UC->Update();
> }
> catch(itk::ExceptionObject &e)
> {
> std::cout <<"excep in spacing"<< e<<std::endl;
> }
>
>     vtkImageViewer2 * viewer = vtkImageViewer2::New();
>     viewer->SetupInteractor(iren );
>     viewer->GetRenderWindow()->AddRenderer(ren1);
>     viewer->SetInput( connector1_UC->GetOutput() );
>     viewer->SetSlice(0);
> vtkCamera *aCamera = vtkCamera::New();
> aCamera->SetViewUp (0,-1, 0);
> aCamera->SetPosition (0, 0, 1);
> aCamera->SetFocalPoint (0, 0, 0);
> viewer->GetRenderer()->SetActiveCamera(aCamera);
> viewer->GetRenderer()->ResetCamera();
>     viewer->SetColorWindow( 255 );
>     viewer->SetColorLevel( 128 );
>      viewer->Render();
>      iren->Start();
>
> return 0 ;
> Thanks
> Anu..
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



_________________________________
Karthik Krishnan
Ph: +1 5188814919, +91 9538477060



More information about the vtkusers mailing list