[vtkusers] Link error between polydata, mapper et actor

Benoit Frédéricque benoit.fredericque.1 at ulaval.ca
Fri Jan 6 11:27:42 EST 2006


Hi,

I defined a simple function to set geometry, mapper and actor associated 
with a cube.

When I am using this function several times to draw several cubes, all 
actors seem refer to the same geometry instead of refer to different 
geometries.


I don’t understand what’s wrong.

My Code is hereafter.



Thank’s for your help



Benoit




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


void

CreateCube(vtkPolyData * &o_geometry, vtkPolyDataMapper * &o_mapper , 
vtkActor * &o_actor,

float i_L , float i_l ,float i_H , float i_alpha , float i_X ,float i_Y, 
float i_Z)

{
int i;
static float Pt[8][3]={
// (0) (1) (2) (3)
{0,0, i_H} , {i_L,0,i_H}, {i_L,i_l,i_H}, {0 ,i_l,i_H} ,

// (4) (5) (6) (7)
{0,0, 0} , {i_L,0,0}, {i_L,i_l,0}, {0 ,i_l,0}
} ;


static vtkIdType Faces[6][4]=
{
{0,1,2,3}, {4,5,6,7},
{0,1,5,4}, {1,2,6,5}, {6,7,3,2}, {7,4,0,3}
};


o_geometry = vtkPolyData::New();

vtkPoints *points = vtkPoints::New();
vtkCellArray *polys = vtkCellArray::New();
vtkFloatArray *scalars = vtkFloatArray::New();

for (i=0; i<8; i++) points->InsertPoint(i,Pt[i]);

for (i=0; i<6; i++) polys->InsertNextCell(4,Faces[i]);

o_geometry->SetPoints(points);

points->Delete();

o_geometry->SetPolys(polys);
polys->Delete();



o_mapper = vtkPolyDataMapper::New();
o_mapper->SetInput(o_geometry);



o_actor = vtkActor::New();

o_actor->SetMapper(o_mapper);
o_actor->RotateZ( i_alpha );
o_actor->SetPosition( i_X, i_Y, i_Z);
}



void
DeleteCube(vtkPolyData* &o_geometry, vtkPolyDataMapper * &o_mapper , 
vtkActor * &o_actor )
{
o_geometry->Delete();
o_mapper->Delete();
o_actor->Delete();
}





int main( int argc, char *argv[] )

{


vtkPolyData *cube0 = 0;

vtkPolyDataMapper *cubeMapper0 = 0;

vtkActor *cubeActor0 = 0;



vtkPolyData *cube1 = 0;

vtkPolyDataMapper *cubeMapper1 = 0;

vtkActor *cubeActor1 = 0;



CreateCube(cube0 , cubeMapper0 , cubeActor0, 10.0, 3.0 ,2.0 , 0.0 , 0.0 
,0.0, 0.0);

CreateCube(cube1 , cubeMapper1 , cubeActor1, 10.0, 10.0 ,2.0 , 0.0 , 
20.0 ,0.0, 0.0);


vtkCamera *camera = vtkCamera::New();

camera->SetPosition(1,1,1);

camera->SetFocalPoint(0,0,0);
vtkRenderer *renderer = vtkRenderer::New();

vtkRenderWindow *renWin = vtkRenderWindow::New();

renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

iren->SetRenderWindow(renWin);
renderer->AddActor(cubeActor0);
renderer->AddActor(cubeActor1);

renderer->SetActiveCamera(camera);
renderer->ResetCamera();



renderer->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(300,300);


renWin->Render();

iren->Start();

DeleteCube(cube0 , cubeMapper0 , cubeActor0);
DeleteCube(cube1 , cubeMapper1 , cubeActor1);

camera->Delete();
renderer->Delete();
renWin->Delete();
iren->Delete();

return 0;



}




More information about the vtkusers mailing list