[vtkusers] Interactor not working with ImageMapper and Actor2D

Suresh Joshi Suresh.Joshi at insa-lyon.fr
Mon Jun 29 09:15:34 EDT 2009


Hello everyone,

I am having a problem getting an interactor functional with the code
snippet shown below... All I would really like is to be able to change
the window level by dragging the mouse, so I used
vtkInteractorStyleImage, but any interactors/styles are completely
non-responsive (no zooming, no panning, no response in the render
window).

Essentially, I have a 2D picture and I would like to modify
contrasts/intensities (similar to using vtkImageViewer2), however I
need multiple viewports and cannot seem to do that with ImageViewer2.

I have used very similar code in previous projects without problems,
however this time I used vtkImageMapper and vtkActor2D and suddenly,
nothing seems to want to work.

Any advice would be much appreciated.
Cheers.

  vtkRenderWindow* renWin = vtkRenderWindow::New();
  vtkRenderer* rend1 = vtkRenderer::New();
  vtkRenderer* rend2 = vtkRenderer::New();
  vtkRenderer* rend3 = vtkRenderer::New();
    renWin->AddRenderer(rend1);
    renWin->AddRenderer(rend2);
    renWin->AddRenderer(rend3);

  vtkImageMapper* map1 = vtkImageMapper::New();
    map1->SetInput(image1);
  vtkImageMapper* map2 = vtkImageMapper::New();
    map2->SetInput(image2);
  vtkImageMapper* map3 = vtkImageMapper::New();
    map3->SetInput(image3);
    map3->SetColorWindow(255);
    map3->SetColorLevel(50);

  vtkActor2D* act1 = vtkActor2D::New();
  vtkActor2D* act2 = vtkActor2D::New();
  vtkActor2D* act3 = vtkActor2D::New();
    act1->SetMapper(map1);
    act2->SetMapper(map2);
    act3->SetMapper(map3);

  rend1->SetViewport(0.00, 0, 0.33, 1.0);
  rend2->SetViewport(0.33, 0, 0.66, 1.0);
  rend3->SetViewport(0.66, 0, 1.00, 1.0);
  rend1->AddActor(act1);	
  rend2->AddActor(act2);
  rend3->AddActor(act3);

  renWin->SetSize( 3*image1->GetDimensions()[0],
imageOriginal->GetDimensions()[1]);

  rend1->ResetCamera();
  rend1->GetActiveCamera()->Zoom(1.0);
  rend2->ResetCamera();
  rend2->GetActiveCamera()->Zoom(1.0);
  rend3->ResetCamera();
  rend3->GetActiveCamera()->Zoom(1.0);


  vtkRenderWindowInteractor *inter = vtkRenderWindowInteractor::New();
    inter->SetRenderWindow(renWin);
  vtkInteractorStyleImage* style = vtkInteractorStyleImage::New();
    inter->SetInteractorStyle(style);

  renWin->Render();
  inter->Initialize();
  inter->Start();



More information about the vtkusers mailing list