vtkPolyLine时可以一次设置多个点再连接成一段:
vtkSmartPointer<vtkPolyLine> polyLine=
vtkSmartPointer<vtkPolyLine>::New();
polyLine->GetPointIds()->SetNumberOfIds(5);
for(unsignedint i = 0; i< 5; i++)
{
polyLine->GetPointIds()->SetId(i,i);
}
用vtkLine连接多点成线段时,一次只能连接两个点:
for(unsignedint i = 0; i< 3; i++)
{
vtkSmartPointer<vtkLine> line=
vtkSmartPointer<vtkLine>::New();
line->GetPointIds()->SetId(0,i);
line->GetPointIds()->SetId(1,i+1);
lines->InsertNextCell(line);
}
用vtkLineSource时一次也只能指定两个点,也可以一次性指定多个点,根据点的插入顺序来连接成线段:
vtkSmartPointer<vtkLineSource> lineSource=
vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoint1(p0);
lineSource->SetPoint2(p1);
lineSource->Update();
vtkSmartPointer<vtkLineSource> lineSource =
vtkSmartPointer<vtkLineSource>::New();
//lineSource->SetPoint1(p0);
//lineSource->SetPoint2(p1);
double origin[3] = {0.0, 0.0, 0.0};
double p0[3] = {1.0, 0.0, 0.0};
double p1[3] = {0.0, 1.0, 0.0};
double p2[3] = {0.0, 1.0, 2.0};
double p3[3] = {1.0, 2.0, 3.0};
// Create a vtkPoints object and store the points in it
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(origin);
points->InsertNextPoint(p0);
points->InsertNextPoint(p1);
points->InsertNextPoint(p2);
points->InsertNextPoint(p3);
lineSource->SetPoints(points);
lineSource->Update();