[vtkusers] One Actor for several points

Imran Ahmed Khan imran.ahmed.khan at gmail.com
Wed Jun 29 10:09:00 EDT 2005


Hi,
I am a beginner in VTK and i was trying to display two or more
vtlPixel, vtkQuad or vtkVertex objects using single
vtkUnstructuredGrid, vtkMapper and vtkActor. The problem I am facing
is that only the last inserted object in the vtkUnstructuredGrid is
being displayed. Below is the code :

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

vtkPoints *vertexPoints=vtkPoints::New();
vertexPoints->SetNumberOfPoints(2);

vtkVertex *aVertex=vtkVertex::New();

//1st vertex
aVertex->GetPointIds()->SetId( 0, 0);
vertexPoints->InsertPoint( 0, 20, 20, 0.0);

//2nd vertex
aVertex->GetPointIds()->SetId( 1, 1);
vertexPoints->InsertPoint( 0, 40, 40, 0.0);

vtkUnstructuredGrid *aVertexGrid=vtkUnstructuredGrid::New();
aVertexGrid->Allocate( 1, 1);
aVertexGrid->InsertNextCell( aVertex->GetCellType(),aVertex->GetPointIds());
aVertexGrid->SetPoints( vertexPoints);

vtkDataSetMapper *aVertexMapper=vtkDataSetMapper::New();
aVertexMapper->SetInput( aVertexGrid);

vtkActor *aVertexActor=vtkActor::New();
aVertexActor->SetMapper( aVertexMapper);

aVertexActor->GetProperty()->SetColor(1,0,0);

         // Create a renderer
vtkRenderer *d_renderer = vtkRenderer::New();
d_renderer->SetBackground(0.1, 0.2, 0.4);
d_renderer->ResetCameraClippingRange();

         // set the window
vtkRenderWindow *d_render_window = vtkRenderWindow::New();
d_render_window->SetSize(500,500);
d_render_window->AddRenderer(d_renderer);

         // ************* adding the actor ************* 
d_renderer->AddActor( aVertexActor);


         // Turn on erasing the screen between images
d_render_window->EraseOn();

         //3D interactor
vtkInteractorStyleSwitch *istyle = vtkInteractorStyleSwitch::New();
vtkRenderWindowInteractor *ia = vtkRenderWindowInteractor::New();
ia->SetInteractorStyle(istyle);
d_render_window->SetInteractor(ia);

d_render_window->Render();
iren->Start();

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

By running this code; only one vertex is drawn, Same is the case with
vtkQuad and vtkPixel classes.
Do I have to use different grids, mappers and actors for each and
every object ?? Like if there are two vertexes then do i have to use
two different grids, mappers and actors for them. Please help me.
thanks in advance.

Best Regards,
Imran Ahmed Khan.



More information about the vtkusers mailing list