How to create vtk heptagonal prism (7 faces with 4 vertices and 2 faces with 7 vertices)

Viewed 1485

In vtk you can add up to a hexagonal prism cell to a vtkUnstructuredGrid with InsertNextCell (int type, vtkIdType npts, vtkIdType *ptIds). This is nice but I would like to include a heptagonal and octagonal prism into a vtkUnstructuredGrid. The cell type is not defined in vtk...

Just to clear some doubts I am working with c# but a c++ or python example would be enough to translate it to c#.

Back to the issue, I first copied and slightly modified the code in this example to get a voxel (8 points and celltype = 11)

            vtkPoints points = vtkPoints.New();
            points.InsertNextPoint(-1.0, -1.0, -1.0);
            points.InsertNextPoint(1.0, -1.0, -1.0);
            points.InsertNextPoint(1.0, 1.0, -1.0);
            points.InsertNextPoint(-1.0, 1.0, -1.0);
            points.InsertNextPoint(-1.0, -1.0, 1.0);
            points.InsertNextPoint(1.0, -1.0, 1.0);
            points.InsertNextPoint(1.0, 1.0, 1.0);
            points.InsertNextPoint(-1.0, 1.0, 1.0);
            vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New();
            unstructuredGrid1.SetPoints(points);
            int[] ptIds = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            IntPtr ptIdsPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 8);
            Marshal.Copy(ptIds, 0, ptIdsPointer, 8);
            unstructuredGrid1.InsertNextCell(11, 8, ptIdsPointer);
            Marshal.FreeHGlobal(ptIdsPointer);
            // Create a mapper and actor
            vtkDataSetMapper mapper = vtkDataSetMapper.New();
                  mapper.SetInputConnection(unstructuredGrid1.GetProducerPort());

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1, 0, 0);
            actor.GetProperty().SetPointSize(3);
            actor.GetProperty().SetOpacity(1);
            actor.GetProperty().SetLineWidth(2);
            actor.GetProperty().EdgeVisibilityOn();
            Renderer3D.AddActor(actor);

That shows correctly a voxel getting:enter image description here

but as I want a heptahedron I was trying to adapt the idea using VTK_POLYHEDRON, changing the line that tells the type pf cell to add to unstructuredgrid

            unstructuredGrid1.InsertNextCell(11, 8, ptIdsPointer);

to (42 stands for VTK_POLYHEDRON, 11 stands for VTK_VOXEL) and points = 14

            unstructuredGrid1.InsertNextCell(42, 14, ptIdsPointer);

like this example. I triedsomething like c++ but I do not get any result

int numberOfVertices = 14;
int numberOfFaces = 9; //how to tell heptagonal prism has 2 faces with 7 vertices and 7 with 4 vertices?
int numberOfFaceVertices = 4;
vtkIdType heptagonPointsIds[14] =  
    {0, 1,  2,  3,  4,  5,  6
     7,  8, 9, 10, 11, 12,13};

//points that only change in z
vtkSmartPointer<vtkPoints> points =  vtkSmartPointer<vtkPoints>::New();
        points->InsertNextPoint(454.6, 678.534, 1.1009301757813); //id 0
        points->InsertNextPoint(454.6, 678.545, 1.1500146484375);//id 1
        points->InsertNextPoint(454.6, 678.556, 1.2255187988281);//id 2
        points->InsertNextPoint(455.1, 678.556, 1.6478076171875);//id 3
        points->InsertNextPoint(455.1, 678.534, 1.7926538085938);//id 4
        points->InsertNextPoint(455.1, 678.545, 1.7166479492188);//id 5
        points->InsertNextPoint(454.85, 678.534, 1.0092297363281);//id 6

        points->InsertNextPoint(454.6, 678.534, 5.1009301757813);//id 7
        points->InsertNextPoint(454.6, 678.545, 5.1500146484375);//id 8
        points->InsertNextPoint(454.6, 678.556, 5.2255187988281);//id 9
        points->InsertNextPoint(455.1, 678.556, 5.6478076171875);//id 10
        points->InsertNextPoint(455.1, 678.534, 5.7926538085938);//id 11
        points->InsertNextPoint(455.1, 678.545, 5.7166479492188);//id 12
        points->InsertNextPoint(454.85, 678.534, 5.0092297363281);//id13    
vtkIdType heptagonPrismFace[9][4] = {
      {0, 1, 7, 8},
      {1, 2, 8, 9},
      {2, 3, 9, 10},
      {3, 4, 10, 11},
      {4, 5, 11, 12},
      {5, 6, 12, 13},
      {6, 1, 13, 8},
      //last two faces how to tel they should be 0 1 2 3 4 5 6 and  7 8 9 10 11 12 13 ?
      {0, 1, 2, 3},
      {7, 8, 9, 10},
      };

  vtkSmartPointer<vtkCellArray> heptagonFaces=
    vtkSmartPointer<vtkCellArray>::New();
  for (int i = 0; i < numberOfFaces; i++)
    {
    heptagonFaces->InsertNextCell(numberOfFaceVertices, heptagonPrismFace[i]);
    }

  vtkSmartPointer<vtkUnstructuredGrid> uGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
  uGrid->InsertNextCell(VTK_POLYHEDRON,
          numberOfVertices, heptagonPointsIds,
        numberOfFaces, heptagonFaces->GetPointer());
  uGrid->SetPoints(points);

vtkSmartPointer<vtkDataSetMapper> mapper =     vtkSmartPointer<vtkDataSetMapper>::New();
  mapper->SetInputConnection(uGrid->GetProducerPort());


  //add actor to render and stuff...

How would I get something like image: enter image description here

3 Answers
Related