vtk Insertnextcell is too expensive

//  cell_x   the triangle vertex index x
//  cell_y  the triangle vertex  index y
//  cell_z  the triangle vertex index z
// _ptCellArray is a  vtkCellArray object 
//   the code  is  c# 
for(int i = 0; i < cellNum; i++)
{
   var triangle = vtkTriangle.New();
   triangle.GetPointIds().SetId(0, cell_x[i]);
   triangle.GetPointIds().SetId(1, cell_y[i]);
   triangle.GetPointIds().SetId(2, cell_z[i]);
   _ptCellArray.InsertNextCell(triangle);
}

the above code is too expensive, every 100 points need 1ms. how can i accelerate it.

__ptCellArray.Allocate(cellNum * 3);
for(int i = 0; i < cellNum; i++)
{
   __ptCellArray.InsertNextCell(3);
   __ptCellArray.InsertCellPoint(cell_x[i]);
   __ptCellArray.InsertCellPoint(cell_y[i]);
   __ptCellArray.InsertCellPoint(cell_z[i]);
}

2 Likes

thank you every much, your code worked! It cost 3 percent of the previous time。
I have another question want to ask you, I use the following code

// _pd is a vtkPolyData object  only with points
// the code is c# 
var delaunay =  vtkDelaunay2D.New();
delaunay.SetTolerance(0.001);
delaunay.SetInput(_pd);
delaunay.Update();

the above code cost 100 millisecond level while the _pd have 10,000 points,.
So i use c++ CGAL build delaunay2D , in c++ code, CGAL build delaunay2D cost 10 ms level with the same points. Then I Pass cell information to c#.
I think I’m using it wrong, can you tell me how to speed up the delaunay2D of vtk? I just need cell and point information。

You should post under another topic. For your second question, I have no idea.

1 Like

thank you very much, i will do it