Chapter 4 visualization technology (4)

Source: Internet
Author: User
This series of tutorials is a Chinese translation of VTK User's Guide-11th edition published by kitware: 978-1-930934-23-8), due to the time relationship, we cannot guarantee that the content of this book can be updated every week, but try to update one or two articles every week. Please wait until ^_^. Thank you for your cooperation! At the same time, due to the limited level of translators, errors are inevitable. You are welcome to make corrections !] [This section corresponds to page 112nd to page 117th of the original book] 5.3 rule grid Visualization

The rule mesh rules on the topology structure, while the ry is irregular, as shown in 3-2. Rule grids are often used for data analysis (such as fluid dynamics calculation ). The rule grid vtkstructuredgrid dataset consists of vtkhexahedral units or vtkquad units.

Manually create vtkstructedgrid

To create a rule grid, you must specify the dimensions (topology definition) of the grid and the vtkpoints object (ry definition) that defines the x-y-zcoordinate ). The following code is modified from VTK/examples/datamaniulation/cxx/sgrid. cxx.

 

Vtkpoints points

Points insertpoint 0 0.0 0.0 0.0

... Etc...

 

Vtkstructedgrid sgrid

Sgrid setdimensions 13 11 11

Sgrid setpoints points

 

The number of vertices in the primary vtkpoints object must be the same as the number of vertices in the mesh I, j, and k directions.

Extract computing plane

In most cases, the rule grid is processed by the filter that receives input of the vtkdataset type (see "Visualization Technology" On page 89 "). One of the filters that directly receive input of the vtkstructuredgrid type is vtkstructuredgridgeometryfilter. The filter extracts the local point, line segment, or plane of the grid based on its extent variable value (extent is a six-dimensional vector (,) describing the area (,)).

In the following example, we read a rule grid data and extract the three planes, the relevant vector data is used for warp processing on the plane (the code is taken from VTK/examples/visualizationalgorithms/Tcl/warpcomb. TCL ).

 

Vtkplot3dreader pl3d

Pl3d setxyzfilename "$ vtk_data_root/data/combxyz. bin"

Pl3d setqfilename "$ vtk_data_root/data/combq. bin"

Pl3d setscalarfunctionnumber 100

Pl3d setvectorfunctionnumber 202

Pl3d update

Vtkstructuredgridgeometryfilter plane

Plane setinputconnection [pl3d getoutputport]

Plane setextent 10 10 1 100 1 100

Vtkstructuredgridgeometryfilter plane2

Plane2 setinputconnection [pl3d getoutputport]

Plane2 setextent 30 30 1 100 1 100

Vtkstructuredgridgeometryfilter plane3

Plane3 setinputconnection [pl3d getoutputport]

Plane3 setextent 45 45 1 100 1 100

Vtkappendpolydata appendf

Appendf addinputconnection [Plane getoutputport]

Appendf addinputconnection [plane2 getoutputport]

Appendf addinputconnection [plane3 getoutputport]

Vtkwarpscalar warp

Warp setinputconnection [appendf getoutputport]

Warp usenormalon

Warp setnormal 1.0 0.0 0.0

Warp setscalefactor 2.5

Vtkpolydatanormals Normals

Normals setinputconnection [warp getoutputport]

Normals setfeatureangle 60

Vtkpolydatamapper planemapper

Planemapper setinputconnection [normals getoutputport]

Evalplanemapper setscalarrange [[pl3d getoutput] getscalarrange]

Vtkactor planeactor

Planeactor setmapper planemapper

Rule grid data downsampling

Like data, the rule grid data can also be downsampled (see "Image Data downsampling" On page 105 "). Vtkextractgrid is used for downsampling and extraction of data.

 

Vtkplot3dreader pl3d

Pl3d setxyzfilename "$ vtk_data_root/data/combxyz. bin"

Pl3d setqfilename "$ vtk_data_root/data/combq. bin"

Pl3d setscalarfunctionnumber 100

Pl3d setvectorfunctionnumber 202

Pl3d update

Vtkextractgrid Extract

Extract setinputconnection [pl3d getoutputport]

Extract setvoi 30 30-1000 1000-1000 1000

Extract setsamplerate 1 2 3

Extract includeboundaryon

 

In this example, the initial regular grid (with a dimension of 57x33X25) samples according to the sampling rate (, 3) to generate a subset of a dimension (, 9. The includeboundaryon () function ensures that the boundary is also extracted in the sample operation without selection boundaries.

5.4 linear grid Visualization

The linear mesh rules on the topology, but on the top of the geometric half (3-2 (B )). Linear grids are also commonly used for numerical analysis. Vtkrectilineargrid consists of vtkvoxel or vtkpixel.

Manually create vtkrectlineargrid

To create a linear grid, you must specify the grid dimension to define the grid topology, and define the x-y-Z coordinates in three scalar arrays to define the ry. The following code is modified from VTK/examples/datamanipulation/cxx/rgrid. cxx.

 

Vtkfloatarray * xcoords = vtkfloatarray: New ();

For (I = 0; I <47; I ++) xcoords-> insertnextvalue (X [I]);

Vtkfloatarray * ycoords = vtkfloatarray: New ();

For (I = 0; I <33; I ++) ycoords-> insertnextvalue (Y [I]);

Vtkfloatarray * zcoords = vtkfloatarray: New ();

For (I = 0; I <44; I ++) zcoords-> insertnextvalue (Z [I]);

 

Vtkrectilineargrid * rgrid = vtkrectilineargrid: New ();

Rgrid-> setdimensions (47,33, 44 );

Rgrid-> setxcoordinates (xcoords );

Rgrid-> setycoordinates (ycoords );

Rgrid-> setzcoordinates (zcoords );

 

Make sure that the number of scalar numbers in the X, Y, and Z directions must be consistent with those in the I, j, and k directions of the topology.

Extract computing plane

In most cases, linear grids are processed by filters that receive input from the vtkdataset type (see "Visualization Technology" On page 89 "). One of the filters that directly receive input of the vtkrectilineargrid type is vtkrectilineargridgeometryfilter. The filter extracts the local point, line segment, or plane of the grid based on its extent variable value (extent is a six-dimensional vector (,) describing the area (,)).

The following example shows the above Code VTK/examples/datamanipulation/cxx/rgrid. cxx. We extract a plane as follows:

Vtkrectilineargridgeometryfilter * plane =

Vtkrectilineargridgeometryfilter: New ();

Plane-> setinput (rgrid );

Plane-> setextent (, 16, 16 );

5.5 visualization of Irregular Grids

Irregular Grids are irregular in topology or ry (3-2 (f )). Irregular Grids are often used for numerical analysis (such as finite element analysis ). Any element type can be used to represent an irregular grid.

Manually create vtkunstructuredgrid

The definition of an irregular grid uses vtkpoints to define the ry and inserts a unit to define the topology. (The following code is taken from VTK/examples/datamanipulation/Tcl/buildugrid. TCL .)

 

Vtkpoints tetrapoints

Tetrapoints setnumberofpoints 4

Tetrapoints insertpoint 0 0 0 0

Tetrapoints insertpoint 1 1 0 0

Tetrapoints insertpoint 2. 5 1 0

Tetrapoints insertpoint 3. 5. 5 1

Vtktetra atetra

[Atetra getpointids] setid 0 0

[Atetra getpointids] setid 1

[Atetra getpointids] setid 2 2

[Atetra getpointids] setid 3 3

Vtkunstructuredgrid atetragrid

Atetragrid allocate 1 1

Atetragrid insertnextcell [atetra getcelltype] [atetra getpointids]

Atetragrid setpoints tetrapoints

... Insertother cells if any...

 

Before inserting unit data for the vtkunstructuredgrid instance, you must first execute the allocate () function to allocate space. The two parameters of this function indicate the size of the initially allocated data space and the size of the memory space extended when additional memory is required. Generally, a large value will have a better effect (because less Memory re-allocation is required ).

Extract local Mesh

In most cases, the irregular grid is processed by the filter that receives input of the vtkdataset type (see "Visualization Technology" On page 89 "). One of the filters that directly receive input of the vtkunstructuredgrid type is vtkextractunstructuredgrid. This filter extracts the local grid based on the specified vertex IDs, cell IDs, and geometric boundaries (extent parameter defines a box ). The following code is taken from VTK/examples/visualizationalgorithms/Tcl/extractugrid. TCL.

Vtkdatasetreader

Reader setfilename "$ vtk_data_root/data/blow. VTK"

Reader setscalarsname "thickness9"

Reader setvectorsname "displacement9"

Vtkcasttoconcrete casttounstructuredgrid

Casttounstructuredgrid setinputconnection [READER getoutputport]

Vtkwarpvector warp

Warp setinput [casttounstructuredgrid getunstructuredgridoutput]

 

Vtkconnectivityfilter connect

Connect setinputconnection [warp getoutputport]

Connect setextractionmodetospecifiedregions

Connect addspecifiedregion 0

Connect addspecifiedregion 1

Vtkdatasetmapper moldmapper

Moldmapper setinputconnection [READER getoutputport]

Moldmapper scalarvisibilityoff

Vtkactor moldactor

Moldactorsetmapper moldmapper

[Moldactor getproperty] setcolor. 2. 2. 2

[Moldactor getproperty] setrepresentationtowireframe

 

Vtkconnectivityfilter connect2

Connect2 setinputconnection [warp getoutputport]

Connect2 setextractionmodetospecifiedregions

Connect2 addspecifiedregion 2

Vtkextractunstructuredgrid extractgrid

Extractgrid setinputconnection [connect2 getoutputport]

Extractgrid cellclippingon

Extractgrid setcellminimum 0

Extractgrid setcellmaximum 23

Vtkgeometryfilter Parison

Parison setinputconnection [extractgrid getoutputport]

Vtkpolydatanormals normals2

Normals2 setinputconnection [Parison getoutputport]

Normals2 setfeatureangle 60

Vtklookuptable LUT

Lut sethuerange 0.0 0.66667

Vtkpolydatamapper parisonmapper

Parisonmapper setinputconnection [normals2 getoutputport]

Parisonmapper setlookuptable LUT

Parisonmapper setscalarrange 0.12 1.0

Vtkactor parisonactor

Parisonactor setmapper parisonmapper

 

In this example, we use the cell pruning (using the cell id) and a connected filter to extract the local mesh. Vtkconnectivityfilter (and vtkpolydataconnectivityfilter) is used to extract the connected part of the data (when the unit is shared, they are connected ). The setextractionmodetospecifiedregions () method sets the connected region to be extracted. The connected filter extracts the largest connected area by default. You can also extract a specific region as in this example, but some additional experiments are required to correspond to each region.

Irregular mesh Contour Extraction

Vtkw.grid is used to extract the contour of an irregular grid. This class is more efficient than the common vtkmeanfilter class. Generally, you do not need to instantiate this class directly, because when vtkw.filter identifies the input data of the vtkunstructuredgrid type, vtkw.filter automatically creates a vtkw.grid instance.

The above is an overview of visualization technology. Next, you may want to learn about image processing and volume rendering technologies. You can also refer to the "filter summary" section on page 444 to learn about the filter in VTK.


Chapter 2-visualization technology translation completed]

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.