# Streamlines using unstructered grid.

**URL:** https://discourse.vtk.org/t/streamlines-using-unstructered-grid/793
**Category:** Support
**Created:** [April 19, 2019, 4:34pm UTC](https://discourse.vtk.org/t/streamlines-using-unstructered-grid/793 "2019-04-19T16:34:50Z")
**Posts on this page:** 3
**Page:** 1

<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, 4:34pm UTC](https://discourse.vtk.org/t/streamlines-using-unstructered-grid/793/1 "2019-04-19T16:34:50Z")

</div>

Hello,

I am quite new to VTK library.  
I have a data which is unstructered grid. While paraview is able to visualize it in a second, I couldnt find a way to do it in c++.

Does any of you have experience with this ?

Best regards,

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 22, 2019, 12:25pm UTC](https://discourse.vtk.org/t/streamlines-using-unstructered-grid/793/2 "2019-04-22T12:25:45Z")

</div>

Here’s an example that should get you started with `vtkStreamTracer`: [https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/Office/](https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/Office/)

---

<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: [August 26, 2019, 9:33pm UTC](https://discourse.vtk.org/t/streamlines-using-unstructered-grid/793/3 "2019-08-26T21:33:05Z")

</div>

Hello Cory,

Thank you for the reply. I found a solution long ago(The result is same with paraview).

It is ‘quite’ hard actually when it is unstructured grid.  
The solution is : vtkCellDataToPointData

This nice class interpolates the cell data to point data, which is necessary for it. In short a code may be following, after seeds are set:

```
     vtkSmartPointer<vtkStreamTracer> streamer;
     vtkSmartPointer<vtkUnstructuredGrid> data;
     vtkSmartPointer<vtkUnstructuredGridReader> gridReader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
    
    gridReader->SetFileName("myfile.vtk");
    gridReader->Update();
    
    data = gridReader->GetOutput();
    streamer = vtkStreamTracer::New();
    std::cout << " Calculation of streamlines are started." << std::endl;
    // Interpolate cell values to point values
    vtkSmartPointer<vtkCellDataToPointData> c2p = vtkSmartPointer<vtkCellDataToPointData>::New();
    c2p->SetInputData(data);
    c2p->Update();
    // Calculate streamline
    streamer->SetInputConnection(c2p->GetOutputPort());
    streamer->SetSourceConnection(seeds->GetOutputPort());
    streamer->SetInitialIntegrationStep(0.2);
    streamer->SetMinimumIntegrationStep(.01);
    streamer->SetMaximumIntegrationStep(.5);
    streamer->SetMaximumNumberOfSteps(2000);
    streamer->SetInterpolatorTypeToCellLocator();
    streamer->SetIntegrationDirectionToBoth();
    streamer->SetIntegratorTypeToRungeKutta4();
    //streamer->SetComputeVorticity(true);

    streamer->Update();

```

And rest is the mappers and actors. .
