[vtkusers] Contouring streamtracer (lines)

James Robinson j.robinson at kepler-systems.com
Mon Jul 2 12:35:41 EDT 2018


 

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.

 

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-g
lyphs/ 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.

 

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.

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

 

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.

 

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(_Dat
aSet.CurrentVectorDataSet.Name);

//
_StreamlineActor.GetMapper().ColorByArrayComponent(_DataSet.CurrentVectorDat
aSet.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(_Data
Set.CurrentVectorDataSet.Name);

//
_StreamlineActor.GetMapper().ColorByArrayComponent(_DataSet.CurrentVectorDat
aSet.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

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180702/6b691cad/attachment.html>


More information about the vtkusers mailing list