[vtkusers] how to add a cursor on an image ?

little.black.dog at netcourrier.com little.black.dog at netcourrier.com
Fri Aug 3 05:00:49 EDT 2007


Hi

this is my first post on this mailing list, nice to meet you :)

I'd like to add a cross in the center of an image created with vtk ; I succeeded in drawing the cross alone, and in viewing the image alone in a correct way, but I cant get the two together.
I've tried to change the Z-position of the image, or a couple of other ways that sounded worth of it like moving the Znear closer, but I didn' get any probant results...

Thanks for helping ^^


ps. for information, the image is some 2D-projection of a 4D-function hat represent a plasma, and the goal of the cross is to (later ^^°) materialize the focus point.
pps. I post my main code, hoping it will help you to understand the problem ...



int main( int argc, char *argv[] )
{
  int x, y;
  int width = 600, height = 600;
  
  vtkImageData *image;
  image = vtkImageData::New();
  image->SetDimensions(64, 64, 1);

// image initialization
  for (x = 0; x < 64; x++)
  {
    for (y = 0; y < 64; y++)
    { image->SetScalarComponentFromDouble(x,y,0,0,dataStruct2D[0]->read(x,y));
/* dataStruct2D[0]->read(x,y) is a function (defined somewhere else)
  wich returns the double value corresponding to coords (x,y)
*/    
    }
  }

// a little lookuptable for adding some colors to the project
  vtkLookupTable *lookupTable = vtkLookupTable::New();
  lookupTable->SetTableRange(scalaireMin,scalaireMax);
  lookupTable->SetHueRange(couleurMax,0);
  lookupTable->SetSaturationRange(1,1);
  lookupTable->SetValueRange(1,1);
  lookupTable->Build();
  
  vtkImageMapToColors *map = vtkImageMapToColors::New();
  map->SetInput(image);
  map->SetLookupTable(lookupTable);
  
  vtkImageActor* actor = vtkImageActor::New();
  actor->SetInput(map->GetOutput());

  vtkRenderer* ren1 ;
  ren1 = vtkRenderer::New();

/* when I remove the following line, I get the cursor alone, but
  (of course) not my image.
*/  
  ren1->AddActor(actor);

  ren1->SetViewport(0.0, 0.5, 0.5, 1.0);
  ren1->GetActiveCamera()->Zoom(1.58);

// the following lines draw a cross (the cursor) at the center of the render
  vtkLineSource *cursor = vtkLineSource::New();
  cursor->SetPoint1(0,-.02,0);
  cursor->SetPoint2(0,.02,0);
  vtkPolyDataMapper *mCursor = vtkPolyDataMapper::New();
  mCursor->SetInput(cursor->GetOutput());
  vtkActor *aCursor = vtkActor::New();
  aCursor->SetMapper(mCursor);
  aCursor->GetProperty()->SetLineWidth(3.0);
  vtkLineSource *cursor2 = vtkLineSource::New();
  cursor2->SetPoint1(-.02,0,0);
  cursor2->SetPoint2(.02,0,0);
  vtkPolyDataMapper *mCursor2 = vtkPolyDataMapper::New();
  mCursor2->SetInput(cursor2->GetOutput());
  vtkActor *aCursor2 = vtkActor::New();
  aCursor2->SetMapper(mCursor2);
  aCursor2->GetProperty()->SetLineWidth(3.0);
  ren1->AddActor(aCursor);
  ren1->AddActor(aCursor2);
  
  renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);
  renWin->SetSize( width, height );

  vtkCallbackCommand* callback = vtkCallbackCommand::New();
  callback->SetCallback(MouseEvent);
  
  vtkInteractorStyleUser *style = vtkInteractorStyleUser::New();
  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();  
  iren->SetInteractorStyle(style);
  iren->SetRenderWindow(renWin);
  iren->Initialize();
/* adding some MousEvent callback function which I dont posted here
*/
  iren->AddObserver(vtkCommand::LeftButtonPressEvent, callback);
  iren->AddObserver(vtkCommand::LeftButtonReleaseEvent, callback);
  iren->AddObserver(vtkCommand::MouseMoveEvent, callback);
  iren->Start();
  
  actor->Delete();
  callback->Delete();
  image->Delete();
  iren->Delete();
  lookupTable->Delete();
  map->Delete();
  ren1->Delete();
  renWin->Delete();
  
  return 0;
}




More information about the vtkusers mailing list