目标是使用 xml 文件中的 vtkLineSource 绘制线条。所以,我从 xml 文件中检索值到向量中,然后在嵌套循环中循环遍历向量以检索值并将它们作为参数传递给绘图函数。
这是我的代码
for ( std::vector<double>::iterator i = tab_recupere_X1.begin();
i != tab_recupere_X1.end();
i++)
{
p0[0]= *i;
std::cout << "p0[0]"<<p0[0]<<std::endl;
for (std::vector<double>::iterator j = tab_recupere_Y1.begin();
j != tab_recupere_Y1.end();
j++)
{
p0[1] = *j;
std::cout << "p0[1]"<<p0[1]<<std::endl;
// break;
for (std::vector<double>::iterator k = tab_recupere_X2.begin();
k != tab_recupere_X2.end();
k++)
{
p1[0] = *k;
std::cout << "p1[0]"<<p1[0]<<std::endl;
for (std::vector<double>::iterator p = tab_recupere_Y2.begin();
p != tab_recupere_Y2.end();
p++)
{
p1[1] = *p;
std::cout << "p1[1]"<<p1[1]<<std::endl;
vtkSmartPointer<vtkLineSource> lineSource =
vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoint1(p0);
lineSource->SetPoint2(p1);
lineSource->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(lineSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetLineWidth(4);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
}
}
}
}
但是最后一个循环无限期地运行而没有停止,并且没有绘制任何内容。我使用了 (break) 但没有任何改进。
我的目的是每次迭代,检索x和y的值并画线。
你能帮我吗!先感谢您。