[vtk-developers] More in speed in extrude polygons procedure

Markos Kopanos mkopano at gmail.com
Thu Dec 20 09:02:33 EST 2018


Hello,

I wonder if someone has a solution to the following problem that i have:
I have a very large number of non-convex polygons (70000) and i want to
extrude each one of them. The procedure that i follow is this:
vtkPoints, vtkPolygon, vtkPolyData, vtkTriangleFilter,
vtkLinearExtrusionFilter and add invtkAppendPolyData
After the extrusion of all of them:
 vtkPolyDataMapper and i apply the Actor and put them in Renderer

Here is the code

////////////////////////////////////////////////////////////
       vtkSmartPointer<vtkAppendPolyData> appendFilter =
vtkSmartPointer<vtkAppendPolyData>::New();
       ////////////////////////////////////////////////////////////
       for (int i = 0; i < numbeams; i++) { // numcolumns
              ////////////////////////////////////////////////////////////
              // Setup four points
              vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
              for (int j = num_kop_draw_from; j < num_kop_draw_to; j++) {
                     points->InsertNextPoint(profile_points[j].x,
-profile_points[j].z, profile_points[j].y);
              }
              int NumberofIds = points->GetNumberOfPoints();

////////////////////////////////////////////////////////////////////////////
////////////////////
              vtkSmartPointer<vtkFloatArray> line_Attrib =
vtkSmartPointer<vtkFloatArray>::New();
              line_Attrib->SetNumberOfComponents(2);  // 0=color , 1=ID
              // Create the polygon
              vtkSmartPointer<vtkPolygon> polygon =
vtkSmartPointer<vtkPolygon>::New();
              polygon->GetPointIds()->SetNumberOfIds(NumberofIds); //make a
quad
              for (int ip = 0; ip < NumberofIds; ip++) {
                     polygon->GetPointIds()->SetId(ip, ip);
                     line_Attrib->InsertNextTuple2(2, id);
              }
              // Add the polygon to a list of polygons
              vtkSmartPointer<vtkCellArray> polygons =
vtkSmartPointer<vtkCellArray>::New();
              polygons->InsertNextCell(polygon);
              // Create a PolyData
              vtkSmartPointer<vtkPolyData> polygonPolyData =
vtkSmartPointer<vtkPolyData>::New();
              polygonPolyData->SetPoints(points);
              polygonPolyData->SetPolys(polygons);
              polygonPolyData->GetCellData()->SetScalars(line_Attrib);
              vtkSmartPointer<vtkTriangleFilter> triFilter =
vtkSmartPointer<vtkTriangleFilter>::New();
              triFilter->PassLinesOff();
              triFilter->PassVertsOff();
              triFilter->SetInputData(polygonPolyData);
              triFilter->Update();
              vtkSmartPointer<vtkLinearExtrusionFilter> extrudeFilter =
vtkSmartPointer<vtkLinearExtrusionFilter>::New();
              extrudeFilter->SetInputData(triFilter->GetOutput());
//extruding base
              extrudeFilter->SetExtrusionType(VTK_VECTOR_EXTRUSION);
              extrudeFilter->SetVector(Vector_Math[0], Vector_Math[1],
Vector_Math[2]); //direction
              extrudeFilter->SetScaleFactor(Len);
              extrudeFilter->Update();
              appendFilter->AddInputData(extrudeFilter->GetOutput());
              ////////////////////////////////////////////////////////////
}
       appendFilter->Update();
       // Create a mapper and actor
       vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
       mapper->SetInputData(appendFilter->GetOutput());
       if (CGI_View) {
              mapper->ScalarVisibilityOn();
              mapper->SetScalarRange(0,
CGI_View->colors_Palete_scada->GetNumberOfColors() - 1);
              mapper->SetLookupTable(CGI_View->colors_Palete_scada);
       }
       vtkSmartPointer<CGIScadaActor> actor =
vtkSmartPointer<CGIScadaActor>::New();
       actor->SetMapper(mapper);

Although the final result is pretty fast, the initial creation of the
objects with the previous procedure is very slow. Do you have any ideas how
to speed up this procedure?

Thank in advanced
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtk-developers/attachments/20181220/44d411d1/attachment.html>


More information about the vtk-developers mailing list