在自定义 Paraview 过滤器中使用 vtkPolyLine 时出现分段错误
Segmentation Fault when using vtkPolyLine in custom Paraview Filter
我想使用 vtkPolyLine 显示多组 3D 点。
这些点存储为多维向量中的节点(自定义 class):
vector<vector <Node> > criticalLines;
其中节点具有:double posX; double posY; double posZ;
来存储其位置。
对于以下部分,我尝试使用类似于此示例的 vtkPolyLine:
http://www.paraview.org/Wiki/VTK/Examples/Cxx/GeometricObjects/PolyLine
这个函数在向量被节点填充后被调用:
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);
}
}
points
和lines
都在Algorithm.h文件中定义并在构造函数中初始化如下:
points = vtkSmartPointer<vtkPoints>::New();
lines = vtkSmartPointer<vtkCellArray>::New();
稍后添加到 vtkPolyData
:
vtkSmartPointer<vtkPolyData> opd=vtkSmartPointer<vtkPolyData>::New() ;
opd->SetPoints(algorithm.points);
opd->SetLines(algorithm.lines);
criticalLines[i][j].PrintSelf();
的输出显示了预期的值。
当使用 vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
而不是 vtkPolyLine
时一切正常。
这个 create multiple polylines given a set of points using vtk 某种相关问题的解决方案似乎不是我要找的。
我不确定我的代码中的 missing/wrong 是什么。
如果您需要更多信息,请告诉我。
非常感谢任何帮助!
您的 vtkPolyLine
需要为点 ID 分配一些 space,例如
polyLine->GetPointIds()->SetNumberOfIds(5);
在您链接到的示例中。在你的情况下,你需要调用
polyLine->GetPointIds()->SetNumberOfIds(criticalLines[i].size());
在创建后 polyLine
。
我想使用 vtkPolyLine 显示多组 3D 点。
这些点存储为多维向量中的节点(自定义 class):
vector<vector <Node> > criticalLines;
其中节点具有:double posX; double posY; double posZ;
来存储其位置。
对于以下部分,我尝试使用类似于此示例的 vtkPolyLine: http://www.paraview.org/Wiki/VTK/Examples/Cxx/GeometricObjects/PolyLine
这个函数在向量被节点填充后被调用:
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);
}
}
points
和lines
都在Algorithm.h文件中定义并在构造函数中初始化如下:
points = vtkSmartPointer<vtkPoints>::New();
lines = vtkSmartPointer<vtkCellArray>::New();
稍后添加到 vtkPolyData
:
vtkSmartPointer<vtkPolyData> opd=vtkSmartPointer<vtkPolyData>::New() ;
opd->SetPoints(algorithm.points);
opd->SetLines(algorithm.lines);
criticalLines[i][j].PrintSelf();
的输出显示了预期的值。
当使用 vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
而不是 vtkPolyLine
时一切正常。
这个 create multiple polylines given a set of points using vtk 某种相关问题的解决方案似乎不是我要找的。
我不确定我的代码中的 missing/wrong 是什么。 如果您需要更多信息,请告诉我。
非常感谢任何帮助!
您的 vtkPolyLine
需要为点 ID 分配一些 space,例如
polyLine->GetPointIds()->SetNumberOfIds(5);
在您链接到的示例中。在你的情况下,你需要调用
polyLine->GetPointIds()->SetNumberOfIds(criticalLines[i].size());
在创建后 polyLine
。