[vtkusers] vtkUnstructuredGrid problem
    Teresa Azevedo 
    teresa.azevedo at fe.up.pt
       
    Wed May 21 11:27:34 EDT 2008
    
    
  
Hi all.
I am new at VTK, but I tried to find a solution in this forum, without  
success.
So, my problem is:
I want to draw several voxels using an vtkUnstructuredGrid. Assuming  
that I know how many voxels (for example, 2) I need to draw and its 3D  
coordinates, I can use this code and it works fine:
vtkUnstructuredGrid *octreeGrid = vtkUnstructuredGrid::New();
        octreeGrid->Allocate(2);
        vtkPoints *voxelPoints = vtkPoints::New();
        voxelPoints->SetNumberOfPoints(16);
        voxelPoints->InsertPoint(0, 0, 0, 0);
        voxelPoints->InsertPoint(1, 1, 0, 0);
        voxelPoints->InsertPoint(2, 0, 1, 0);
        voxelPoints->InsertPoint(3, 1, 1, 0);
        voxelPoints->InsertPoint(4, 0, 0, 1);
        voxelPoints->InsertPoint(5, 1, 0, 1);
        voxelPoints->InsertPoint(6, 0, 1, 1);
        voxelPoints->InsertPoint(7, 1, 1, 1);
        voxelPoints->InsertPoint(8, 0, 0, 1);
        voxelPoints->InsertPoint(9, 1, 0, 1);
        voxelPoints->InsertPoint(10, 0, 1, 1);
        voxelPoints->InsertPoint(11, 1, 1, 1);
        voxelPoints->InsertPoint(12, 0, 0, 2);
        voxelPoints->InsertPoint(13, 1, 0, 2);
        voxelPoints->InsertPoint(14, 0, 1, 2);
        voxelPoints->InsertPoint(15, 1, 1, 2);
       
        vtkVoxel *aVoxel1 = vtkVoxel::New();
        aVoxel1->GetPointIds()->SetId(0, 0);
        aVoxel1->GetPointIds()->SetId(1, 1);
        aVoxel1->GetPointIds()->SetId(2, 2);
        aVoxel1->GetPointIds()->SetId(3, 3);
        aVoxel1->GetPointIds()->SetId(4, 4);
        aVoxel1->GetPointIds()->SetId(5, 5);
        aVoxel1->GetPointIds()->SetId(6, 6);
        aVoxel1->GetPointIds()->SetId(7, 7);
        vtkVoxel *aVoxel2 = vtkVoxel::New();
        aVoxel2->GetPointIds()->SetId(0, 8);
        aVoxel2->GetPointIds()->SetId(1, 9);
        aVoxel2->GetPointIds()->SetId(2, 10);
        aVoxel2->GetPointIds()->SetId(3, 11);
        aVoxel2->GetPointIds()->SetId(4, 12);
        aVoxel2->GetPointIds()->SetId(5, 13);
        aVoxel2->GetPointIds()->SetId(6, 14);
        aVoxel2->GetPointIds()->SetId(7, 15);
        octreeGrid->InsertNextCell(VTK_VOXEL,aVoxel1->GetPointIds());
        octreeGrid->InsertNextCell(VTK_VOXEL,aVoxel2->GetPointIds());
       
        octreeGrid->SetPoints(voxelPoints);
My problem is: in the beginning of my program, I do not how many
voxels I need to draw. I tried this and it did not work:
vtkUnstructuredGrid *octreeGrid = vtkUnstructuredGrid::New();
        octreeGrid->Allocate(2);
        vtkPoints *voxelPoints1 = vtkPoints::New();
        voxelPoints->SetNumberOfPoints(8);
        voxelPoints->InsertPoint(0, 0, 0, 0);
        voxelPoints->InsertPoint(1, 1, 0, 0);
        voxelPoints->InsertPoint(2, 0, 1, 0);
        voxelPoints->InsertPoint(3, 1, 1, 0);
        voxelPoints->InsertPoint(4, 0, 0, 1);
        voxelPoints->InsertPoint(5, 1, 0, 1);
        voxelPoints->InsertPoint(6, 0, 1, 1);
        voxelPoints->InsertPoint(7, 1, 1, 1);
         vtkVoxel *aVoxel1 = vtkVoxel::New();
        aVoxel1->GetPointIds()->SetId(0, 0);
        aVoxel1->GetPointIds()->SetId(1, 1);
        aVoxel1->GetPointIds()->SetId(2, 2);
        aVoxel1->GetPointIds()->SetId(3, 3);
        aVoxel1->GetPointIds()->SetId(4, 4);
        aVoxel1->GetPointIds()->SetId(5, 5);
        aVoxel1->GetPointIds()->SetId(6, 6);
        aVoxel1->GetPointIds()->SetId(7, 7);
         octreeGrid->InsertNextCell(VTK_VOXEL,aVoxel1->GetPointIds());
         octreeGrid->SetPoints(voxelPoints1);
        vtkPoints *voxelPoints2 = vtkPoints::New();
        voxelPoints2->SetNumberOfPoints(8);
        voxelPoints2->InsertPoint(8, 0, 0, 1);
        voxelPoints2->InsertPoint(9, 1, 0, 1);
        voxelPoints2->InsertPoint(10, 0, 1, 1);
        voxelPoints2->InsertPoint(11, 1, 1, 1);
        voxelPoints2->InsertPoint(12, 0, 0, 2);
        voxelPoints2->InsertPoint(13, 1, 0, 2);
        voxelPoints2->InsertPoint(14, 0, 1, 2);
        voxelPoints2->InsertPoint(15, 1, 1, 2);
        vtkVoxel *aVoxel2 = vtkVoxel::New();
        aVoxel2->GetPointIds()->SetId(0, 8);
        aVoxel2->GetPointIds()->SetId(1, 9);
        aVoxel2->GetPointIds()->SetId(2, 10);
        aVoxel2->GetPointIds()->SetId(3, 11);
        aVoxel2->GetPointIds()->SetId(4, 12);
        aVoxel2->GetPointIds()->SetId(5, 13);
        aVoxel2->GetPointIds()->SetId(6, 14);
        aVoxel2->GetPointIds()->SetId(7, 15);
        octreeGrid->InsertNextCell(VTK_VOXEL,aVoxel2->GetPointIds());
         octreeGrid->SetPoints(voxelPoints2);
       
Is there any possible way to put the voxels in the unstructuredGrid  
using separate vtkPoints? Something like this pseudo-code:
vtkUnstructuredGrid octreeGrid
allocate_enough_memory octreeGrid
while (voxels_to_draw)
   vtkVoxel voxel
   vtkPoints points
   points->put_coordinates
   voxel->insert_points
   grid->insert_voxel
end
Thank you,
Teresa
    
    
More information about the vtkusers
mailing list