[vtkusers] How can i use the vtkStreamtracer to generate a streamline with my unstructured grid data(vtu)

stargazerrrrr t1449768199 at gmail.com
Thu Apr 18 09:41:34 EDT 2019


I`m using  VTK  to visualize data coming from xflow in vtu. When I use the
Paraview, it can generate the right streamline, but when I use the VTK to
visualize my data, it only displays the outline and the airplane model.
There is no streamline being generated.
This is my code:
//The background color
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();

This is the result in paraview:
<http://vtk.1045678.n5.nabble.com/file/t342734/paraview1.png> 
This is the result of my code:
<http://vtk.1045678.n5.nabble.com/file/t342734/%E6%88%91%E7%9A%84%E6%95%88%E6%9E%9C.png> 

Is there any problem in my code?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list