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

**URL:** https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790
**Category:** Support
**Created:** [April 19, 2019, 11:14am UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790 "2019-04-19T11:14:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![stargazer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@stargazer](https://discourse.vtk.org/u/stargazer)
#### Post date: [April 19, 2019, 11:14am UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/1 "2019-04-19T11:14:58Z")

</div>

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:

```auto
    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 my desired output generated in paraview:
![paraview1|455x209](upload://2NoqWPUqUNU2P53b7iBL7mnxeGD.png) 

This is the result of my code:
![%E6%88%91%E7%9A%84%E6%95%88%E6%9E%9C|690x305](upload://99P9p8A20iDJ9XhZV3XSePEPASR.png) 

Sorry,I`m a new here,I don`t find the image function.Any ideas on how to solve this?
```

---

<div class="post-metadata">

### Author: ![sariug](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@sariug](https://discourse.vtk.org/u/sariug)
#### Post date: [April 19, 2019, 2:18pm UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/2 "2019-04-19T14:18:19Z")

</div>

Hello, we spoke on stackoverflow if you remember. How is your solution going ? I am kind of looking for creating another class such as poly data and apply streamline to that but really in doubt if this is the only way

---

<div class="post-metadata">

### Author: ![stargazer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@stargazer](https://discourse.vtk.org/u/stargazer)
#### Post date: [April 21, 2019, 7:44am UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/3 "2019-04-21T07:44:19Z")

</div>

Sorry, my work has not progressed. I think the streamtracer should support the grid data,because the unstructured grid is a common data structure in streamline render.There may be some other detail I have never know in the streamtracer.

---

<div class="post-metadata">

### Author: ![sariug](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@sariug](https://discourse.vtk.org/u/sariug)
#### Post date: [April 22, 2019, 10:50am UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/4 "2019-04-22T10:50:01Z")

</div>

try this and let me know the result:

vtkSmartPointer\<vtkUnstructuredGrid\> data = reader-\>GetOutput();

// cell 2 point and contour

vtkCellDataToPointData\* c2p = vtkCellDataToPointData::New();

c2p-\>SetInputData(data);

vtkStreamTracer\* streamer = vtkStreamTracer::New();

streamer-\>SetInputConnection(c2p-\>GetOutputPort());

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [July 2, 2019, 3:51pm UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/7 "2019-07-02T15:51:30Z")

</div>

If you’re open to Python, maybe [PyVista](https://docs.pyvista.org/index.html) and specifically, [these examples](https://docs.pyvista.org/examples/01-filter/streamlines.html) on using the `vtkStreamTracer` would make your life easier.

`vtkStreamTracer` is a complicated filter and we worked to make it much easier to use with any data type and more accessible for people wanting to experiment with it in PyVista

---

<div class="post-metadata">

### Author: ![Samuel\_James](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@Samuel\_James](https://discourse.vtk.org/u/Samuel_James)
#### Post date: [August 5, 2020, 5:22pm UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/8 "2020-08-05T17:22:47Z")

</div>

I’ve tried using the code provided in your examples on my data-set. Unfortunately it did not produce any streamlines.

Printing the mesh gives:  
UnstructuredGrid (0x7fb52607f3a0)  
N Cells: 16135415  
N Points: 17027364  
X Bounds: -1.250e+01, 1.250e+01  
Y Bounds: -1.250e+01, 1.250e+01  
Z Bounds: -1.516e+00, 2.000e+00  
N Arrays: 13

But there are no mesh vectors. Perhaps that’s why when trying to produce streamlines I get:  
PolyData (0x7fb568557d00)  
N Cells: 0  
N Points: 0  
X Bounds: 1.000e+00, -1.000e+00  
Y Bounds: 1.000e+00, -1.000e+00  
Z Bounds: 1.000e+00, -1.000e+00  
N Arrays: 0

Am I missing something?

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [August 11, 2020, 5:44pm UTC](https://discourse.vtk.org/t/how-can-i-use-the-vtkstreamtracer-to-generate-a-streamline-with-my-unstructured-grid-data-vtu/790/9 "2020-08-11T17:44:56Z")

</div>

> [@Samuel\_James](#):
>
> But there are no mesh vectors. Perhaps that’s why when trying to produce streamlines I get:

You’ll need to have vectors on the input in order to do this
