gpt4 book ai didi

c++ - 如何使用 vtkStreamTracer 类通过我的非结构化网格数据 (vtu) 生成流线

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:03:13 27 4
gpt4 key购买 nike

我正在使用 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:

关于如何解决这个问题有什么想法吗?

最佳答案

我一直在搜索或多或少相同的东西。我在我的数据上试过你的代码。而且我也没有看到结果。另一方面,我做了一个调试语句:

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

所以我认为问题可能更多地与其他问题有关?

你已经解决了吗?

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

关于c++ - 如何使用 vtkStreamTracer 类通过我的非结构化网格数据 (vtu) 生成流线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55674921/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com