如何使用vtkStreamTracer类使用非结构化网格数据(vtu)生成流线

时间:2019-04-14 11:48:37

标签: c++ vtk

我正在使用VTKC++来可视化来自vtu中xflow的数据。当我使用Paraview时,它可以生成正确的流线,但是当我使用VTK来可视化我的数据时,它仅显示轮廓和飞机模型。没有生成任何流水线。

vtkSmartPointer<vtkNamedColors> namedColors = vtkSmartPointer<vtkNamedColors>::New();

//The AirplaneModel file
std::string meshfilename = "K:/Project/VTKproject/Airplane_Process/data/Mesh.vtp";
vtkSmartPointer<vtkXMLPolyDataReader> meshreader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
meshreader->SetFileName(meshfilename.c_str());
meshreader->Update();

//The data file
std::string datafilename ="K:/Project/VTKproject/Airplane_Process/data/data.vtu";
vtkSmartPointer<vtkXMLUnstructuredGridReader> datareader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
datareader->SetFileName(datafilename.c_str());
datareader->Update();

//The seed points
vtkSmartPointer<vtkPointSource> seeds = vtkSmartPointer<vtkPointSource>::New();
seeds->SetCenter(0,0,0);
seeds->SetRadius(0.05);
seeds->SetNumberOfPoints(100);


//streamline generate

vtkSmartPointer<vtkStreamTracer> streamline = vtkSmartPointer<vtkStreamTracer>::New();
datareader->Update();
streamline->SetInputConnection(datareader->GetOutputPort());
streamline->SetSourceConnection(seeds->GetOutputPort());
//streamline->SetIntegrationStepUnit(vtkStreamTracer::CELL_LENGTH_UNIT);
streamline->SetMaximumPropagation(500);
streamline->SetMaximumIntegrationStep(0.1);
streamline->SetMinimumIntegrationStep(0.01);
streamline->SetInitialIntegrationStep(0.05);
//streamline->SetIntegrationStepUnit(vtkStreamTracer::CELL_LENGTH_UNIT);
streamline->SetIntegrationDirectionToBoth();
streamline->SetIntegratorTypeToRungeKutta45();
streamline->Update();

vtkSmartPointer<vtkPolyDataMapper> streamLineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
streamLineMapper->SetInputConnection(streamline->GetOutputPort());

vtkSmartPointer<vtkActor> streamLineActor = vtkSmartPointer<vtkActor>::New();
streamLineActor->SetMapper(streamLineMapper);

//outlinefilter
vtkSmartPointer<vtkOutlineFilter> outline =vtkSmartPointer<vtkOutlineFilter>::New();
outline->SetInputConnection(datareader->GetOutputPort());

vtkSmartPointer<vtkPolyDataMapper> outlineMapper =vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());

vtkSmartPointer<vtkActor> outlineActor =vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);
outlineActor->GetProperty()->SetColor(0,0,0);

//
vtkSmartPointer<vtkPolyDataMapper> meshmapper = vtkSmartPointer<vtkPolyDataMapper>::New();
meshmapper->SetInputConnection(meshreader->GetOutputPort());

vtkSmartPointer<vtkActor> meshactor = vtkSmartPointer<vtkActor>::New();
meshactor->SetMapper(meshmapper);

//rendering
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(meshactor);
renderer->AddActor(outlineActor);
renderer->AddActor(streamLineActor);
//renderer->AddActor(actor);
renderer->SetBackground(namedColors->GetColor3d("Cadet").GetData());
//window
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);

//interaction
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
renderWindowInteractor->SetInteractorStyle(style);
renderWindowInteractor->Initialize();
renderWindow->SetSize(300, 300);
renderWindow->Render();
renderWindowInteractor->Start();

这是我在paraview中生成的所需输出 This is my desired output generated in paraview

这是我的代码的结果:

This is the result of my code:

关于如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:0)

我或多或少都在搜寻同一件事。我在数据上尝试了您的代码。而且我也没有看到结果。另一方面,我做了一个调试语句:

streamline->Print(std::cout);

streamline->GetOutput()->Print(std::cout);

我的结果是:

vtkPStreamTracer (0x555c851095d0)



Debug: Off

  Modified Time: 1444545

  Reference Count: 2

  Registered Events: (none)

  Executive: 0x555c854fb270

  ErrorCode: Success

  Information: 0x555c8556c100

  AbortExecute: Off

  Progress: 1

  Progress Text: (None)

  Start position: 0 0 0

  Terminal speed: 1e-12

  Maximum propagation: 500 unit: length.

  Integration step unit: cell length.

  Initial integration step: 0.05

  Minimum integration step: 0.01

  Maximum integration step: 0.1

  Integration direction: both directions.

  Integrator: 0x555c85572320

  Maximum error: 1e-06

  Maximum number of steps: 2000

  Vorticity computation:  On

  Rotation scale: 1

  Controller: 0

所以我认为问题可能出在其他方面?

您已经解决了吗?

对不起,我也是新来的,找不到“评论”按钮。