[vtkusers] Set Cell type

Naim Himrane naim_canada at yahoo.ca
Wed Feb 16 13:22:20 EST 2005


Hi everybody,

I am new to vtk,  I tried to create a cube datatype (see the code below), when I called the polys->SetCells(12, IdTypeArray) function the system crashes.

Is it the correct manner to set the cell type as VTK_TETRA like this?

vtkIdTypeArray *IdTypeArray = vtkIdTypeArray::New(); 
IdTypeArray->SetNumberOfValues(12);

for (i=0; i<12; i++) {
 polys->InsertNextCell(4,pts[i]); // tetra
 IdTypeArray->SetValue(i,VTK_TETRA);
}
polys->SetCells(12, IdTypeArray);

thanks for your time

Naim

// code source

void CGLModelViewCtrl::Cube()
{

static float x[9][3]={{5.000000e-001, -2.840789e-002, 4.103363e-002}, 

 {0.000000e+000, -2.840789e-002, 4.103363e-002}, 
 {5.000000e-001, -2.840789e-002, -4.589664e-001}, 
 {0.000000e+000, -2.840789e-002, -4.589664e-001},
 {5.000000e-001, 4.715921e-001, -4.589664e-001}, 
 {0.000000e+000, 4.715921e-001, -4.589664e-001}, 
 {5.000000e-001, 4.715921e-001, 4.103363e-002}, 
 {0.000000e+000, 4.715921e-001, 4.103363e-002},
 {3.438136e-001, 2.000117e-001, -2.254762e-001}};

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

 

// We'll create the building blocks of polydata including data attributes.

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

// Load the point, cell, and data attributes.

for (int i=0; i<9; i++) points->InsertPoint(i,x[i]);

vtkIdTypeArray *IdTypeArray = vtkIdTypeArray::New(); 
IdTypeArray->SetNumberOfValues(12);

for (i=0; i<12; i++) {
 polys->InsertNextCell(4,pts[i]);
 IdTypeArray->SetValue(i,VTK_TETRA);
}
polys->SetCells(12, IdTypeArray);

scalars->InsertTuple1(0,0.866885);
scalars->InsertTuple1(1,0.562442);
scalars->InsertTuple1(2,0.661086);
scalars->InsertTuple1(3,0);
scalars->InsertTuple1(4,0.740853);
scalars->InsertTuple1(5,1);
scalars->InsertTuple1(6,0.728700);
scalars->InsertTuple1(7,0.739150);
scalars->InsertTuple1(8,0.260398);

// We now assign the pieces to the vtkPolyData.

cube->SetPoints(points);
points->Delete();
cube->SetPolys(polys);
polys->Delete();
cube->GetPointData()->SetScalars(scalars);
cube->Squeeze();
cube->Update();
scalars->Delete();

// Now we'll look at it.

cubeMapper = vtkPolyDataMapper::New();
cubeMapper->SetInput(cube);

cubeActor = vtkActor::New();
cubeActor->SetMapper(cubeMapper);
renderer->AddActor(cubeActor);
renderer->SetActiveCamera(camera);
renderer->ResetCamera();
}



---------------------------------
Post your free ad now! Yahoo! Canada Personals
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050216/8ccfd053/attachment.htm>


More information about the vtkusers mailing list