[vtkusers] Contouring streamtracer (lines)

Cory Quammen cory.quammen at kitware.com
Tue Jul 3 13:34:16 EDT 2018


Hi James,

Please see my responses inlined below.

On Mon, Jul 2, 2018 at 5:21 PM James Robinson <j.robinson at kepler-systems.com>
wrote:

>
>
> Dear All,
>
>
>
> I am trying to use VTK in its Activiz format (version 5.8.0) in C#. It is
> working reasonably well 9very well in places) – but I am trying to do some
> visualisation of vector data. I have been trying for a week now (or more)
> doing online searches for sample code etc. to no avail.
>

Have you searched through the VTK wiki?
https://lorensen.github.io/VTKExamples/site/Cxx/ Some of the best examples
for learning VTK are there. You may have to translate from C++ or Python to
C#, but that shouldn't be too bad.


> Ideally what I would like to achieve was described in this article on
> ParaView:
> https://blog.kitware.com/paraview-technique-curved-and-nicely-spaced-arrow-glyphs/
> Beautiful work, but the description of how it was achieved is somewhat
> cryptic when viewed from the perspective of trying to replicate it in
> Activiz.
>

That visualization is indeed possible with VTK - that is what ParaView is
using to generate it. While you can easily generate Python code that uses
the ParaView Python API to reproduce the technique, there is nothing that
generates plain VTK code to reproduce it, I'm afraid.


> If I could get one of the following visualisation tools developed it would
> be fit for my purpose:
>
> 1. Ideal – as per the link above.
>
> 2. Flow arrow glyphs that are coloured and scaled according to the vector
> field magnitude.
>

Examples (searched for vtkGlyph3D on the wiki examples page)
*
https://lorensen.github.io/VTKExamples/site/Cxx/Visualization/OrientedGlyphs/
*
https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/CarotidFlowGlyphs/

*
https://raw.githubusercontent.com/lorensen/VTKExamples/master/src/Testing/Baseline/Cxx/Visualization/TestCurvatureBandsWithGlyphs.png


> 3. Minimum: Standard streamtracer lines with colour according to vector
> magnitude.
>

Examples (searched for vtkStreamTracer on the wiki page):
*
https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/BluntStreamlines/
*
https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/CarotidFlow/
* https://lorensen.github.io/VTKExamples/site/Cxx/Visualization/Kitchen/


> For test purposes I am reading in a set of data points in 3D with pressure
> values (a history) for each point. I am meshing the points into a linear
> tet mesh (using VTK class - vtkDelaunay3D) and then extract the resulting
> mesh as a vtkUnstructuredGrid. Then I am using the pressure field to
> calculate a pressure gradient at the nodes (points) of the tet mesh. As the
> pressure data has a set of values for a series of timesteps, the resulting
> gradient values are also per node per timestep.
>
>
>
> I associate the pressure data and the resulting gradient data with the
> vtkUnstructuredGrid (called _vtkUSGrid) as follows:
>
>
>
>
> //===========================================================================
>
>
> //===========================================================================
>
>         void AddDataSet(RiverDataSet dataset)
>
>         {
>
>             switch (dataset.Type) // POINT or CELL
>
>             {
>
>                 case "POINT":
>
>                     _vtkUSGrid.GetPointData().AddArray(dataset.Values);
>
>                     break;
>
>                 case "CELL":
>
>                     _vtkUSGrid.GetCellData().AddArray(dataset.Values);
>
>                     break;
>
>             }
>
>             _vtkUSGrid.Update();
>
>             _vtkUSGrid.Modified();
>
>
>
> Where dataset is a class that I have written to manage various data sets.
> Note all data sets (scalars and vector) are added in this manner. The
> resulting scalar (e.g. pressure) visualisation works perfectly. In
> addition, I manage to extract the streamtracers from the data and can see
> the evolution of that vector field in time. The vtkStreamTracer (which I
> refer to as streamlines in the code) are created as follows:
>
>
>
>
> //===========================================================================
>
>
> //===========================================================================
>
>         private void CreateStreamLine()
>
>         {
>
>             StreamTracer = new vtkStreamTracer();
>
>             StreamTracer.SetInput(_USGrid);
>
>             _FlowPlaneSource = new vtkPlaneSource();
>
>
> StreamTracer.SetSourceConnection(_FlowPlaneSource.GetOutputPort());
>
>
>
>             double Initial_and_minimum_step = 0.05; // 5% of cell size
>
>
> StreamTracer.SetInitialIntegrationStep(Initial_and_minimum_step);
>
>             StreamTracer.SetMaximumPropagation(100);
>
>             StreamTracer.SetIntegrationDirectionToBackward();
>
>             StreamTracer.SetIntegratorTypeToRungeKutta45();
>
>             StreamTracer.SetComputeVorticity(true);
>
>
>
>             //vtkContourFilter contourFilter = new vtkContourFilter();
>
>             //contourFilter.SetInputArrayToProcess(StreamTracer.)
>
>
> //contourFilter.SetInputConnection(StreamTracer.GetOutputPort());
>
>
>
>             _StreamTube = new vtkTubeFilter();
>
>             _StreamTube.SetInput(StreamTracer.GetOutput());
>
>             //_StreamTube.SetInput(contourFilter.GetOutput());
>
>             _StreamTube.SetNumberOfSides(12);
>
>             _StreamTube.SetVaryRadiusToVaryRadiusByVector();
>
>
>
>             vtkPolyDataMapper StreamLineMapper = vtkPolyDataMapper.New();
>
>             StreamLineMapper.SetInput(_StreamTube.GetOutput());
>
>             StreamLineMapper.ScalarVisibilityOn();
>
>             StreamLineMapper.SetScalarModeToUsePointData();
>
>             StreamLineMapper.SetLookupTable(_ColourMap_LUT);
>
>
>
>             _StreamlineActor = new vtkActor();
>
>             _StreamlineActor.SetMapper(StreamLineMapper);
>
>
>
>             AddActor(_StreamlineActor);
>
>             _StreamlineActor.VisibilityOff();
>
>
>
>             CreateStreamlinePointLocator();
>
>         }
>
>
>
> Note that in this code I have made an attempt (but commented it out) to
> introduce contours on the streamlines as a first step to achieve the ideal
> objective (as stated above) – but as I can’t even get them to come out in
> colour the attempt at creating definite (line) contours is futile for the
> moment.
>

contourFilter.SetInputArrayToProcess() takes some port and connection
information along with a field type (point or cell) and a character string
containing the name of the array on which you want the filter to operate.
See
https://www.vtk.org/doc/nightly/html/classvtkAlgorithm.html#a42a55ca2c277aecc909ad592d12978aa
for details. I believe you want the point array named "IntegrationTime"
produced by the vtkStreamTracer.

I hope that is helpful.

Cheers,
Cory


>
>
> Each time I change timestep I set the data upon which the stream lines are
> to be calculated to the appropriate set of gradients:
>
>
> //===========================================================================
>
>
> //===========================================================================
>
>         private void UpDate_FlowActor(string Type, bool bRender = false)
>
>         {
>
>             switch (Type)
>
>             {
>
>                 case "NONE":  // No data set visible
>
>                     _StreamlineActor.VisibilityOff();
>
>                     break;
>
>                 case "POINT":
>
>                     _USGrid.GetPointData().SetActiveVectors(_
> DataSet.CurrentVectorDataSet.Name);
>
>                     _StreamlineActor.GetMapper().SelectColorArray(_
> DataSet.CurrentVectorDataSet.Name);
>
>
> _StreamlineActor.GetMapper().GetInput().GetPointData().SetActiveVectors(_
> DataSet.CurrentVectorDataSet.Name);
>
> //                    _StreamlineActor.GetMapper().ColorByArrayComponent(_
> DataSet.CurrentVectorDataSet.Name, 0);
>
>
> _StreamlineActor.GetMapper().SetColorModeToMapScalars();
>
>                     break;
>
>                 case "CELL":
>
>                     _USGrid.GetCellData().SetActiveVectors(_
> DataSet.CurrentVectorDataSet.Name);
>
>                     _StreamlineActor.GetMapper().SelectColorArray(_
> DataSet.CurrentVectorDataSet.Name);
>
>
> _StreamlineActor.GetMapper().GetInput().GetCellData().SetActiveVectors(_
> DataSet.CurrentVectorDataSet.Name);
>
> //                    _StreamlineActor.GetMapper().ColorByArrayComponent(_
> DataSet.CurrentVectorDataSet.Name, 0);
>
>
>      _StreamlineActor.GetMapper().SetColorModeToMapScalars();
>
>                     break;
>
>                 default:
>
>                     _StreamlineActor.VisibilityOff();
>
>                     break;
>
>             }
>
>             _StreamlineActor.Modified();
>
>
>
>             if (bRender)
>
>             {
>
>                 ReRender();
>
>             }
>
>         }
>
>
>
> Any advice would be most welcomed. (And I can supply any additional code –
> but the overall project is too large to share).
>
>
>
> Many thanks in advance,
>
>
>
> Kind regards,
>
>
>
> Jim Robinson PhD
>
>
>
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>


-- 
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180703/113c4e88/attachment.html>


More information about the vtkusers mailing list