2

I want to display multiple sets of 3D points using vtkPolyLine. The points are stored as Nodes(custom class) in a multidimensional vector: vector<vector <Node> > criticalLines; where a node has: double posX; double posY; double posZ; to store its position.

For the following section I tried to use vtkPolyLine similar to this example: http://www.paraview.org/Wiki/VTK/Examples/Cxx/GeometricObjects/PolyLine

This function is called after the vector has been filled with nodes:

void Algorithm::displayLines(vtkSmartPointer<vtkPoints> points,vtkSmartPointer<vtkCellArray> lines)
{
for(int i = 0; i<criticalLines.size(); i++)
{
    if(criticalLines[i].empty())
    {
        continue;
    }

    vtkSmartPointer<vtkPolyLine> polyLine =
        vtkSmartPointer<vtkPolyLine>::New()

    for(int j =0; j< criticalLines[i].size(); ++j)
    {

        vtkIdType idx=points->InsertNextPoint(criticalLines[i][j].posX,
                      criticalLines[i][j].posY,
                      criticalLines[i][j].posZ);
        //print posX,posY,posZ of current Node
        criticalLines[i][j].PrintSelf();


        //Seg. Fault occurs here 
        polyLine->GetPointIds()->SetId(j,idx);


    }
    lines->InsertNextCell(polyLine);

}

}

Both points and lines are defined in Algorithm.h file and initialized in the constructor as follows:

points = vtkSmartPointer<vtkPoints>::New();
lines = vtkSmartPointer<vtkCellArray>::New();

And added to vtkPolyData later on:

vtkSmartPointer<vtkPolyData> opd=vtkSmartPointer<vtkPolyData>::New() ;
opd->SetPoints(algorithm.points);
opd->SetLines(algorithm.lines);

Output ofcriticalLines[i][j].PrintSelf(); shows values as expected.

When using vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New(); instead of vtkPolyLine everything works fine.

The solution to this create multiple polylines given a set of points using vtk somehow related problem did not seem to be what I was looking for.

I am not sure what is missing/wrong in my Code. Please let me know if you need more information.

Any help is very much appreciated!

Community
  • 1
  • 1
Philipp Jung
  • 105
  • 1
  • 1
  • 3

1 Answers1

1

Your vtkPolyLine needs to allocate some space for the point IDs, like

polyLine->GetPointIds()->SetNumberOfIds(5);

in the example you linked to. In your case, you need to call

polyLine->GetPointIds()->SetNumberOfIds(criticalLines[i].size());

right after creating polyLine.

Cory Quammen
  • 1,243
  • 7
  • 9