Article 05-Visualization Techniques (2)

Source: Internet
Author: User
Tags modulus tcl code

Translator: This series of tutorials is a Chinese translation of VTK User's guide-11th edition, published by Kitware Corporation (published on 2010, isbn:978-1-930934-23-8), due to the time relationship, We cannot guarantee that the contents of this book will be updated every week. But try to do a weekly update to two articles. Please look forward to ^_^. Welcome reprint, please also reprint the source of this article, thank you for your cooperation. At the same time, because the translator level is limited, the error is unavoidable, welcome to point out the correction! ""This section corresponds to pages 95th through 105th of the original book."Streamline (streamlines)

Streamline can be regarded as the moving path of the non-weight particles in the vector field (such as velocity field). Streamline can express the structure of the vector field. You can often create multiple streamlines to explore the characteristics of interest in a vector field.

5-4. Streamline can be calculated by numerical integration. So we can only approximate the true streamline.


Fig. 5-4 Streamline line surrounded by pipelines

Creating a streamline requires specifying a starting point, direction (along or against the flow). and other parameters that control the progression. The following code shows how to create a streamline.

The streamline is represented by a pipe, and the pipe radius is proportional to the reciprocal of the velocity modulus value. When the stream is less than an hour, the pipe is thicker. Vice versa. TCL code excerpt from VTK/EXMAPLES/VISUALIZATIONALGORITHMS/TCL/OFFICETUBE.TCL.

Vtkstructuredgridreader Reader Reader Setfilename "$VTK _data_root/data/office.binary.vtk" reader Update; #force a read To occur vtkRungeKutta4 integvtkstreamtracer streamer Streamer setinputconnection [reader Getoutputport] Streamer S Etstartposition 0.1 2.1 0.5 Streamer Setmaximumpropagation-Streamersetmaximumpropagationunittotimeunit stream Er setinitialintegrationstep 0.05 streamer setinitialintegrationstepunittocelllengthunit Streamer SetIntegrationDire Ctiontobothstreamer setintegrator integ vtktubefilter streamtube streamtube setinputconnection [Streamer GetOutputPort    ] Streamtube setinputarraytoprocess 1 0 0vtkdataobject::field_association_points vectors streamtube SetRadius 0.02 Streamtube setnumberofsides streamtube setvaryradiustovaryradiusbyvectorvtkpolydatamapper mapStreamTube mapStre Amtube setinputconnection[streamtube Getoutputport] eval mapstreamtube setscalarrange [[[Reader GetOutput] GetP Ointdata]getscalars] GetrAnge]vtkactor streamtubeactor streamtubeactor setmapper mapstreamtube[streamtubeactor GetProperty] BackfaceCullingOn 

In this example we set the starting point to be (0.1,2.1, 0.5).

You can also specify a unit ID by specifying it. The cell sub-ID and the parameter coordinates to specify the starting coordinates. The maximumpropagation variable is used to control the maximum length of the streamline (the unit of measure is specified by the Maximumpropagationunit variable). If higher precision is required (at the cost of more computation time), set the INITIALINTEGRATIONSETP variable to a smaller value. (This parameter is specified as the cell length.) can also choose time or distance) in addition. Precision can also be controlled by selecting a subclass of Vtkinitialvalueproblemsolver, such as VtkRungeKutta2 or VTKRUNGEKUTTA45, which can be set to an adaptive step. By default, the Streamline tracking class uses VTKRUNGEKUTTA2 to perform numerical integration operations. The direction of the integral can be controlled by the following three functions.

    • Setintegrationdirectiontoforward ()
    • Setintegrationdirectiontobackward ()
    • Setintergrationdirectiontoboth ()

Since lines are often difficult to observe, we use a pipe filter to represent them. The pipe filter is set to the inverse of the radius proportional to the velocity modulus value, which is turned on by the function Setvaryradiustovaryradiusbyvector (). The Setvaryradiustovaryradiusbyscalar () can also be set according to the scalar control radius, or the RADIUS is variable (setvaryradiustovaryradiusoff ()). Note that you need to notify the pipe filter which array to use to control the radius. Here the "vectors" array notifies the pipe filter through the setinputarraytoprocess () function.

Sometimes we need to produce a lot of streamlines in sync. One method is to use the Setsourceconnection () method to specify an instance of a vtkdataset. Use the point of this example to track the flow line. Here is an example of the application. The code is excerpted from VTK/EXAMPLES/VISUALIZATIONALGORITHMS/TCL/OFFCICESTUBES.TCL.

Vtkpointsource seeds    seeds setradius 0.15    eval seeds setcenter 0.1 2.1 0.5    seeds setnumberofpoints 6VTKRUNGEKUTTA4 integvtkstreamtracer Streamer    streamer setinputconnection  [reader Getoutputport]    Streamer setsourceconnection [seeds Getoutputport]    streamer setmaximumpropagation-    streamer Setmaximumpropagationunittotimeunit    Streamer Setinitialintegrationstep 0.05    streamer Setinitialintegrationstepunittocelllengthunit    Streamer Setintegrationdirectiontoboth    Streamer Setintegrator Integ

Note that the Vtkpointsource object is used in this example to create a spherical point cloud as input to the streamer.

A streamline is calculated for each point of the input.

Flow surface (Streamsurfaces)

Advanced users may want to take advantage of VTK's flow surface computing capabilities. The flow surface calculation is divided into two steps, first generating a streamline sequence with an ordered point set, and then creating the flow surface by Vtkruledsurfacefilter. Vtkruledsurfacefilter assumes that each streamline is arranged in an orderly manner, and that each streamline is within a specified distance from the left and right adjacent lines. Therefore, it is important to keep the input point set in order. Otherwise the calculation will be very bad.

The following code shows how to create a flow surface (the code is taken from VTK/EXAMPLES/VISUALIZATIONALGORITHMS/TCH/STREAMSURFACE.TCL. Result 5-5).

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd3d3x2rvbgluz19uzxq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

Figure 5-5 Flow Surface

Vtklinesource Rake rake SetPoint1 15-5 rake SetPoint2 5 rake setresolution 21vtkPolyDataMapper rakemapper RA Kemapper setinputconnection [Rake getoutputport]vtkactor rakeactor rakeactor setmapper rakeMapper vtkRungeKutta4 Integvtkstreamtracer SL SL Setinputconnection [Pl3d getoutputport] SL setsourceconnection [rake Getoutputport] SL SetIn  Tegrator Integ SL setmaximumpropagation 0.1 SL Setmaximumpropagationunittotimeunit SL SETINITIALINTEGRATIONSTEP 0.1 sl Setinitialintegrationstepunittocelllengthunit SL Setintegrationdirectiontobackward VtkRuledSurfaceFilter  Scalarsurface scalarsurface setinputconnection [slgetoutputport] scalarsurface setoffset 0 scalarSurface SetOnRatio 2 Scalarsurface Passlineson scalarsurface setruledmodetopointwalk scalarsurface setdistancefactor 30vtkPolyDataMapper Mapper Mapper Setinputconnection [scalarsurface Getoutputport] eval mapper setscalarrange [[Pl3d GetOutput] Getscalarran Ge]vtkactoractor actor Setmapper Mapper

One advantage of Vtkruledsurfacefilter is that when multiple streamlines are entered, the band function can be turned off, which helps to understand the structure of the surface.

Cutting (cutting)

Cutting or slicing a dataset in VTK means using any type of implicit function in the dataset to create a cross-section. For example, we can use a plane to create a planar tangent face data set for slice display. Slices are interpolated when cutting and then displayed using any of the standard visualization techniques.

The cut result is usually the Vtkpolydata type (the cut result of an n-dimensional object is a n-1 dimension geometry. For example, cutting a tetrahedron will produce a triangle or quadrilateral).

The following TCL example shows a result of a combustion chamber being cut by a plane. 5-6. The code is excerpted from Vtk/graphics/tesing/tcl/pro.

Vtkplane plane    eval plane setorigin [[Pl3d getoutput] getcenter]    plane SetNormal-0.287 0 0.9579vtkCutter Planecu T    planecut setinputconnection [Pl3d getoutputport]    planecut setcutfunction planevtkprobefilter probe    Probe setinputconnection [Planecut Getoutputport]    probe setsourceconnection [Pl3d Getoutputport] Vtkdatasetmappercutmapper    cutmapper setinputconnection [probe Getoutputport]    eval cutmapper setscalarrange [[[[       Pl3d GetOutput] getpointdata] getscalars] getrange]vtkactor cutactorcutactor setmapper cutMapper

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd3d3x2rvbgluz19uzxq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

Fig. 5-6 Combustion chamber Cutting

Vtkcutter needs to specify the implicit function to complete the cut. In addition, you may want to specify one or more cut values that can be implemented by the SetValue () or the generatevalues () function. These values specify the implicit function values for the execution of the cut. (By default, the cut value is 0, that is, the surface is precisely on the hidden function surface, and surfaces that are less than or greater than 0 values are located below and above the hidden surface.) The cut value can be considered as the "distance" to the hidden surface. )

Merging data (Mergingdata)

So far we've learned about simple linear visualization pipelines.

The pipeline can then have branches, merges, and even loops.

Next we introduce two filter, which can use other datasets to build new datasets. Now start with the Vtkmergefilter.

Vtkmergefilter merges data fragments from multiple datasets into a new dataset. For example, you can combine the structure of one dataset (topology and geometry), the scalar data of the second dataset, and the vector data of the third dataset into a single dataset. Here is an example of the application.

(Code excerpt from VTK/EXAMPLES/VISUALIZATIONALGORITHMS/TCL/IMAGEWARP.TCL). (The main concern Vtkmergefilter, other unfamiliar can be ignored first.)

We'll describe it in more detail on page 106th.

Vtkbmpreader Reader  Reader setfilename $VTK _data_root/data/masonry.bmpvtkimageluminance luminance  Luminance setinputconnection [reader getoutputport]vtkimagedatageometryfilter geometry  geometry setinputconnection [Luminance Getoutputport]vtkwarpscalarwarp  warp setinputconnection [geometry GetOutputPort]  Warp SetScaleFactor-0.1 vtkmergefilter merge  merge setgeometryconnection [warp Getoutputport]  merge Setscalarsconnection  [Reader getoutputport]vtkdatasetmapper mapper  mapper setinputconnection [merge Getoutputport]  mapper setscalarrange 0 255  Mapper Immediatemoderenderingoffvtkactor actor  actor Setmapper mapper<span style= "FONT-SIZE:14PX; line-height:1.846153846; font-family:arial; Background-color:rgb (255, 255, 255); " > </span>

What is done here is to merge the output of Vtkwarpscalar (the output is the Vtkpolydata type) with the Vtkbmpreader scalar data.

The pipeline is first divided and then closed. Because the geometry needs to be handled separately using scalar data.

When data is merged. The number of tuples in the array must be the same as the number of points. The same is true for cell data.

Append Data (Appendingdata)

Similar to Vtkmergefilter,vtkappendfilter and vtkappendpolydata by appending datasets to produce new datasets. The Append filter receives a series of inputs that must be of the same type.

In the append operation. Only those common data will be merged together.

A better example is shown in the next section.

Detection (probing)

Probing is the process of sampling data sets with other datasets.

In VTK, any data set can be used as the probing geometry, and its point attributes are mapped by other datasets. For example, the following example creates three planes as probe geometry to sample a structured grid dataset. These planes then calculate the contour lines by Vtkcontourfilter. The code is excerpted from VTK/EXAMPLES/VISUALIZATIONALGORITHMS/TCL/PROBECOMB.TCL.

Vtkplot3dreader pl3d pl3d setxyzfilename "$VTK _data_root/data/combxyz.bin" Pl3d setqfilename "$VTK _data_root/data/co Mbq.bin "Pl3d setscalarfunctionnumber pl3d setvectorfunctionnumber 202pl3d Update vtkplanesource plane plane Setresolution 50vtkTransform transP1 transP1 Translate 3.7 0.0 28.37 transP1 scale 5 5 5 transP1 Rotatey 90VTK  Transformpolydatafilter tpd1 tpd1 setinputconnection [plane getoutputport] TPD1 settransform transp1vtkoutlinefilter OUTTPD1 OUTTPD1 setinputconnection [tpd1 getoutputport]vtkpolydatamapper mapTpd1 mapTpd1 setinputconnection [outtpd 1 getoutputport]vtkactort pd1actor tpd1actor setmapper mapTpd1 [tpd1actor GetProperty] setcolor 0 0 0 Vtktransform t RansP2 transP2 Translate 9.2 0.0 31.20 transP2 Scale 5 5 5 transP2 rotatey 90vtkTransformPolyDataFilter tpd2 t PD2 setinputconnection [plane getoutputport] tpd2 settransform transp2vtkoutlinefilter outTpd2 outTpd2 Setinputconne ction [Tpd2 GetoutputporT]vtkpolydatamapper mapTpd2 mapTpd2 setinputconnection [outTpd2 getoutputport]vtkactor tpd2actor tpd2actor SetMapper MAPTPD2 [tpd2actor GetProperty] setcolor 0 0 0 vtktransform transP3 transP3 Translate 13.27 0.0 33.30 transP3 Sc Ale 5 5 5 transP3 rotatey 90vtkTransformPolyDataFilter tpd3 tpd3 setinputconnection [plane Getoutputport] tpd3 Se    Ttransform transp3vtkoutlinefilter outTpd3 outTpd3 setinputconnection [tpd3 getoutputport]vtkpolydatamapper mapTpd3 MapTpd3 setinputconnection [outTpd3 getoutputport]vtkactort pd3actor tpd3actor setmapper mapTpd3 [Tpd3actor GetPrope Rty] SetColor 0 0 0 vtkappendpolydata appendf appendf addinputconnection [tpd1 getoutputport] APPENDF AddInputConnec  tion [tpd2 getoutputport]appendf addinputconnection [tpd3 getoutputport]vtkprobefilter probe probe setinputconnection [APPENDF Getoutputport] Probe setsourceconnection [pl3d getoutputport]vtkcontourfilter contour Contour Setinputconne ction [ProbegetoutputporT]evalcontour generatevalues [[Pl3d getoutput] getscalarrange] vtkpolydatamapper contourmapper contourMapper SetInpu tconnection [Contour Getoutputport]evalcontourmapper setscalarrange [[Pl3d getoutput] Getscalarrange] VtkActor Planeactorplaneactor Setmapper Contourmapper

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd3d3x2rvbgluz19uzxq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

Figure 5-7 Data detection

Note that the probe is set by the Setinputconnection () method, and the data set to be probed is set by the Setsourceconnection () function.

Another application for probing is resampling data.

For example. If you have a unstructured grid data, you want to display it (for example, body drawing) with a tool that specializes in visualizing vtkimagedata. 139 pages). Then you can use Vtkprobefilter to use unstructured grid data as one body data and then visualize it.

You can also use a straight line to probe the data and draw the results into an X-y curve.

Finally, it is worth noting that both cutting and probing can achieve similar results. Apart from the difference in resolution. A cut instance similar to 98 pages. Vtkprobefilter can use Vtkplanesource to produce a plane, and the property data for that plane is derived from the structure grid data. However. The surface resolution produced by the cut depends on the input data. The surface resolution produced by the probe is independent of the input data. Therefore, in the detection of data, the need to pay special attention to low or oversampling.

Low sampling causes an error to be displayed. Oversampling takes too much time to compute.

Shading contours with other scalars

It is a common visual operation to compute the contour and color it with another scalar. You might think of using a detector, but if you have a contour that contains the data you want to use to color. There will be a more effective way. Because Vtkcontourfilter (which is actually used to produce a contour), all data is interpolated during the calculation. The interpolated data is used for coloring during the mapping process. The following example is taken from VTK/EXAMPLES/VISUALIZATIONALGORITHMS/TCL/COLORISOSURFACE.TCL.

Vtkplot3dreader Pl3d    pl3d setxyzfilename "$VTK _data_root/data/combxyz.bin"    pl3d setqfilename "$VTK _data_ Root/data/combq.bin "    pl3d setscalarfunctionnumber    pl3d setvectorfunctionnumber 202 Pl3d    AddFunction 153    Pl3d Update vtkcontourfilter ISO    ISO setinputconnection [pl3d getoutputport]    ISO SetValue 0.24 Vtkpolydatanormals normals    normals setinputconnection [ISO getoutputport]normals setfeatureangle 45 Vtkpolydatamapper isomapper    isomapper setinputconnection [normals getoutputport]    isomapper Scalarvisibilityon    isomapper setscalarrange 0    isomapper setscalarmodetousepointfielddata    Isomapper colorbyarraycomponent "velocitymagnitude" 0 vtklodactor isoactor isoactor setmapper    isoMapper    Isoactor Setnumberofcloudpoints 1000


Figure 5-8 Coloring the contour with another title

The data set is read first through Vtkplot3dreader.

Here we add a function to read (number 153), the function name is "Velocity Magnitude".

When the contour is computed. All input data including the velocity field data is interpolated. Then we call the Setscalarmodetousepointfielddata () function to use the velocity modulus value to color the contour, and the Colorbyarraycomponent () method is used to specify the data array to use for the shading.

Extracting a subset of cells

The amount of data that is visualized is generally very large, and processing such data often consumes a lot of time and memory. Therefore, extracting part of the data function display is very important. Most of the cases. Only part of the data contains meaningful information, or the data is subtracted without compromising accuracy.

A number of tools are available in VTK to extract part of the data or to de-sample data. We have learned that Vtkprobefilter can be used for de-sampling (see page 100, "probing"). Other tools include a reduced-sampling class, and some tools enable extracting units from the spatial area (the drop-down tool is for specific data, see 105-page "downsampling image Data", and 113-page "de-Sampling rule grid data"). In this section we mainly describe how to extract fragments of data in a spatial area.

The Vtkextractgeometryl class extracts all the cells inside or outside the hidden function surface vtkimplicitfucntion the dataset (note that the implicit function can be a combination of two values for multiple implicit functions). The following code creates a two-value combination of two ellipsoid to extract the region. The vtkshrinkfilter is used to shrink the unit so that it can observe the extracted data.

(The code is taken from VTK/EXAMPLES/VISUALIZATIONALGORITHMS/TCL/EXTRACTIONGEOMETRY.TCL.)

Vtkquadric quadric quadric setcoefficients. 5 1.2 0.1 0 0.0vtkSampleFunction Sample Sample Setsampledimensions Sample setimplicitfunction Quadric Sample Computenormalsoffvtktransform trans trans scale 1.5.333vtkS Phere Sphere Sphere Setradius 0.25 sphere settransform transvtktransform trans2 trans2 scale. 5 1.0vtkSphere Sphere2 sphere2 Setradius 0.25 sphere2 settransform trans2vtkimplicitboolean Union Union addfunction Sphere UN Ion AddFunction Sphere2 Union setoperationtype 0; #union vtkextractgeometryextract extract setinputconnection [sample Getoutputport] Extract setimplicitfunction unionvtkshrinkfilter shrink shrink setinputconnection [extract GETOUTPUTP ORT] Shrink setshrinkfactor 0.5vtkDataSetMapper datamapper datamapper setinputconnection [Shrink Getoutputport]vtkac Tor Dataactordataactor Setmapper Datamapper

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd3d3x2rvbgluz19uzxq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

Figure 5-9 extracting a subset of cells

The output of the vtkextractgeometry is usually the Vtkunstructuredgrid type. Because the topology of the dataset is often destroyed during the extraction process, the most common data format must be used to represent the output.

Note that implicit functions can be transformed by assigning a vtktransform.

If a transform is specified, Vtktransform is used to change the value of the implicit function.

You may want to test this functionality.

Extracting units with Polygon data type as output

Most data types cannot be directly rendered by the graphics hardware or the graphics library. Only polygon data (Vtkpolydata) is widely supported in the rendering system. Rule datasets, especially images and body data, can also be supported by the graphics system.

Other data requires special processing to be rendered.

In VTK, one way to render non-polygonal data is to convert it to polygon data. The vtkgeometryfilter can be implemented with this feature.

Vtkgeometryfilter receives arbitrary vtkdataset type data and outputs Vtkpolydata data. When performing the conversion, follow the rules below.

All two-dimensional and below topological units, such as polygons. lines, vertices) are passed directly to the output. A three-dimensional cell polygon at the boundary of the dataset is passed to the output result. (If a polygon belongs to only one cell, the polygon is at the boundary.)

Vtkgeometryfilter are often used for data format conversions.

The following code uses Vtkgeometryfilter to convert a two-dimensional irregular mesh into polygonal data, which is then received as another filter receiving vtkpolydata.

The code is taken from VTK/EXAMPLES/DATAMANIPULATION/TCL/POINTTOCELLDATA.TCL.

Here Vtkconnectivityfilter extracts the Vtkunstructedgrid data and converts it to polygon data through Vtkgeometryfilter.

Vtkconnectivityfilter connect2    connect2 setinputconnection [thresh getoutputport]vtkgeometryfilter Parison    Parison setinputconnection [connect2 getoutputport]vtkpolydatanormals normals2    normals2 setinputconnection [ Parison Getoutputport]    normals2 setfeatureangle 60vtkLookupTable lut    lut sethuerange 0.0 0.66667vtkPolyDataMapper parisonmapper    parisonmapper setinputconnection [normals2 Getoutputport]    Parisonmapper setlookuptable lut    parisonmapper setscalarrange 0.12 1.0vtkActor parisonactorparisonactor SetMapper Parisonmapper

In fact, Vtkdatasetmapper internally uses Vtkgeometryfilter to convert any data type to polygon data. (The filter can pass the input vtkpolydata directly to the output.) )

In addition Vtkgeometryfilter provides a series of functions to set according to the point ID. The Unit IDs collection, or whether it is located in a specific rectangular space region to extract data cells. When extracting data fragments using point or Polygon ID collections, the functions used are Pointclippingon (), Setpointminimum (), Setpointmaximum () and Cellclippingon (), Setcellminimum ( ), Setcellmaximum ().

The minimum and maximum values specify the range of the extracted IDs.

You can also specify a space rectangular area to limit the range of extracts.

Use Extentclippingon () and SetExtent () to start the space cut and specify the range.

The extent contains six parameters to define a surround-


Article 05-Visualization Techniques (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.