我从此网站SpaceShuttle加载航天飞机运载火箭模型 使用StreamLines示例,但我遇到了两个问题。 首先,宇宙飞船的轮廓不会显示在qvtkwidget上。 第二个我得到错误“vtkStreamLine(0x2c5a0c0):没有定义矢量数据!”
我正在使用vtk版本5.8和QT 2.5.2
如果我将.vtk文件加载到qvtkWidget中,它可以正常工作。
我尝试了一切,仍然无法摆脱这一点。我会感激任何消化。
这是我的代码:
void MainWindow::DrawSpaceshuttle()
{
std::string xyzFile = "../grid.xyz";
std::string qFile = "../solution.q";
#if VTK_MAJOR_VERSION <= 5
vtkSmartPointer<vtkPLOT3DReader> pl3d =
vtkSmartPointer<vtkPLOT3DReader>::New();
#else
vtkSmartPointer<vtkMultiBlockPLOT3DReader> pl3d =
vtkSmartPointer<vtkMultiBlockPLOT3DReader>::New();
#endif
pl3d->SetXYZFileName(xyzFile.c_str());
pl3d->SetQFileName(qFile.c_str());
pl3d->SetScalarFunctionNumber(100);
pl3d->SetVectorFunctionNumber(202);
pl3d->Update();
// Source of the streamlines
vtkSmartPointer<vtkPlaneSource> seeds =
vtkSmartPointer<vtkPlaneSource>::New();
seeds->SetXResolution(4);
seeds->SetYResolution(4);
seeds->SetOrigin(2,-2,26);
seeds->SetPoint1(2,2,26);
seeds->SetPoint2(2,-2,32);
// Streamline itself
vtkSmartPointer<vtkStreamLine> streamLine =
vtkSmartPointer<vtkStreamLine>::New();
#if VTK_MAJOR_VERSION <= 5
streamLine->SetInputConnection(pl3d->GetOutputPort());
streamLine->SetSource(seeds->GetOutput());
#else
pl3d->Update();
streamLine->SetInputData(pl3d->GetOutput()->GetBlock(0));
streamLine->SetSourceConnection(seeds->GetOutputPort());
#endif
streamLine->SetMaximumPropagationTime(200);
streamLine->SetIntegrationStepLength(.2);
streamLine->SetStepLength(.001);
streamLine->SetNumberOfThreads(1);
streamLine->SetIntegrationDirectionToForward();
streamLine->VorticityOn();
vtkSmartPointer<vtkPolyDataMapper> streamLineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
streamLineMapper->SetInputConnection(streamLine->GetOutputPort());
vtkSmartPointer<vtkActor> streamLineActor =
vtkSmartPointer<vtkActor>::New();
streamLineActor->SetMapper(streamLineMapper);
streamLineActor->VisibilityOn();
// Outline-Filter for the grid
vtkSmartPointer<vtkStructuredGridOutlineFilter> outline =
vtkSmartPointer<vtkStructuredGridOutlineFilter>::New();
#if VTK_MAJOR_VERSION <= 5
outline->SetInputConnection(pl3d->GetOutputPort());
#else
outline->SetInputData(pl3d->GetOutput()->GetBlock(0));
#endif
vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());
vtkSmartPointer<vtkActor> outlineActor =
vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);
outlineActor->GetProperty()->SetColor(1, 1, 1);
// Create the RenderWindow, Renderer and Actors
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
interactor->SetInteractorStyle(style);
renderer->AddActor(streamLineActor);
renderer->AddActor(outlineActor);
// Add the actors to the renderer, set the background and size
renderer->SetBackground(0.1, 0.2, 0.4);
renderWindow->SetSize(300, 300);
interactor->Initialize();
renderWindow->Render();
interactor->Start();
}
void MainWindow::on_pushButton_4_clicked()
{
DrawSpaceshuttle();
}