Hello,
I don’t use vtkCellArray
s and Append()
to build the geometry of my vtkUnstructuredGrid
s. Maybe you’re better off changing the way you build the visualization grid.
Here’s how I do it:
// Create a VTK container with the points (mesh vertexes)
vtkSmartPointer< vtkPoints > hexaPoints = vtkSmartPointer< vtkPoints >::New();
hexaPoints->SetNumberOfPoints( geoGrid->getMeshNumberOfVertexes() );
for( int i = 0; i < hexaPoints->GetNumberOfPoints(); ++i ){
double x, y, z;
geoGrid->getMeshVertexLocation( i, x, y, z );
hexaPoints->InsertPoint(i, x, y, z);
}
// Create a VTK unstructured grid object (allows faults, erosions, and other geologic discordances )
vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
uint nCells = geoGrid->getMeshNumberOfCells();
unstructuredGrid->Allocate( nCells );
vtkSmartPointer< vtkHexahedron > hexa = vtkSmartPointer< vtkHexahedron >::New();
for( uint i = 0; i < nCells; ++i ) {
uint vIds[8];
geoGrid->getMeshCellDefinition( i, vIds );
hexa->GetPointIds()->SetId(0, vIds[0]);
hexa->GetPointIds()->SetId(1, vIds[1]);
hexa->GetPointIds()->SetId(2, vIds[2]);
hexa->GetPointIds()->SetId(3, vIds[3]);
hexa->GetPointIds()->SetId(4, vIds[4]);
hexa->GetPointIds()->SetId(5, vIds[5]);
hexa->GetPointIds()->SetId(6, vIds[6]);
hexa->GetPointIds()->SetId(7, vIds[7]);
unstructuredGrid->InsertNextCell(hexa->GetCellType(), hexa->GetPointIds());
}
unstructuredGrid->SetPoints(hexaPoints);
My grid cells are all-hexas, but you could freely vary the cell type at will inside the second loop.
The supported cell types are:
In the figure above, the small numbers in the cell vertexes are the hardcoded constants in the second loop. The
vIds[]
array contains the vertex IDs (run-length indexes) of the XYZ vertexes loaded in the first loop.
I hope this helps,
Paulo