Chapter 2-Volume Rendering (1)

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 pages 139th to 142nd in the original book]

Chapter 2 Volume Rendering

Volume Rendering is a technology used to draw 3D data on a two-dimensional surface in a three-dimensional space rather than a three-dimensional space. There is no strict boundary between volume rendering and geometric rendering. The two technologies often have similar results, and sometimes the two can be considered a technology. For example, contour extraction technology is used to extract isosurface from graph data, and geometric rendering technology is used to draw isosurface. Ray projection technology can also be used, end ray tracing to draw an isosurface when a value is reached. These two methods produce similar results. For example, texture ing-based hybrid painting. This method applies to images, so it can be seen as volume rendering or geometric drawing because it uses geometric graphics and standard graphics hardware.

In order to customize the rendering data attributes, the two rendering technologies in VTK are distinguished. In the example shown so far, vtkactor, vtkproperty, and vtkmapper subclasses are used for data rendering. Vtkactor stores location, direction, scaling, and other information, as well as property and mapper pointers. Vtkproperty stores the surface properties during Data Rendering, such as ambient light parameters and shadow types. Vtkmapper is responsible for data rendering. There are many classes available for volume rendering. Vtkvolume is used to replace vtkactor to represent space objects. Similar to vtkactor, vtkvolume stores the data location, direction, and scaling parameters. However, it also contains vtkvolumeproperty and vktabstractvolumemapper references. Vtkvolumeproperty stores parameters for the actual display of image data. These parameters are different from those for geometric drawing. Vktabstractvolumemapper is responsible for checking the legality of data volume rendering and input data.

In VTK, you can perform volume rendering on both the rectangle mesh data (vtkimagedata) and the non-Rule mesh (vtkunstructuredgrid. Set the corresponding Data Pointer (vtkimagedata or vtkunstructuredgrid) based on the setinput () function of the vktabstractvolumemapper subclass ). Note: You can resample non-rule data into rule data for volume rendering. (100 page "probing "). In addition, you can also generate Irregular Grids by using the technology of parameterization for volume rendering.

For each supported data type, there are a variety of different volume rendering technologies available for use. Next we will perform a specific analysis. Next, we will introduce some objects and parameters used in these technologies and analyze each technical detail in detail. Finally, we will discuss the efficiency of each method.

7.1 Development History of Data Types supported by volume rendering

VTK only supports the vtkimagedata-based rendering method. The vtkvolumemapper class defines all the API functions for these volume rendering methods. Later, the Volume Rendering Method Based on vtkunstructuredgrid data was added. To maintain forward compatibility, an abstract base class is introduced as the parent class of all the Volume Rendering Method classes. Similarly, a parent class vtkw.actvolumemapper is introduced for vtkvolumemapper (this class renders vtkunstructuredgridvolumemapper) and vtkunstructuredgrid.

7.2 A simple example

Figure 7-1 shows a simple volume rendering effect (see VTK/examples/volumerendering/Tcl/simpleraycast. TCL ). In this example, vtkimagedata is rendered using the ray projection method, and the simhei part of the code is the Code related to the volume rendering. From this example, we can see that other mappers that can be used in the Code related to volume rendering can be replaced to implement volume rendering. This mainly includes the texture ing method for vtkimagedata and the projection-based Volume Rendering Method for vtkunstructuredgrid data. In the current example, you only need to make a small change, because most function functions are defined in the base class, so all the child classes of the volume rendering method are common.


Figure 7-1 Volume Rendering

# Create the reader for the data

Vtkstructuredpointsreader

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

 

# Create transfer mapping scalar value to Opacity

Vtkpiecewisefunction opacitytransferfunction

Opacitytransferfunction addpoint 20 0.0

Opacitytransferfunction addpoint 255 0.2

 

# Create transfer mapping scalar value to color

Vtkcolortransferfunction colortransferfunction

Colortransferfunction addrgbpoint 0.0 0.0 0.0

Colortransferfunctionaddrgbpoint 64.0 1.0 0.0

Colortransferfunction addrgbpoint 128.0 0.0 0.0

Colortransferfunction addrgbpoint 192.0 0.0 1.0

Colortransferfunction addrgbpoint 255.0 0.0 0.2

 

# The property describes how the data will look

Vtkvolumeproperty volumeproperty

Volumeproperty setcolor colortransferfunction

Volumeproperty setscalaropacity opacitytransferfunction

Volumeproperty shadeon

Volumeproperty setinterpolationtypetolinear

 

# The Mapper/Ray cast function Know How To renderthe data

Vtkvolumeraycastcompositefunction compositefunction

Vtkvolumeraycaw.apper volumemapper

Volumemapper setvolumeraycastfunction compositefunction

Volumemapper setinputconnection [readergetoutputport]

 

# The volume holds the Mapper and the property and

# Can be used to position/orient the volume

Vtkvolume volume

Volumesetmapper volumemapper

Volume setproperty volumeproperty

 

Ren1 addvolume volume

Renwin render

 

First, read an image from the hard disk, and then define two functions for vtkvolumeproperty to map pixels to opacity and color. Then, define a vtkvolumeraycastcompositefunction object dedicated to the ray projection method. This object is used to synthesize the sample data on the projected light. In addition, a vtkvolumeraycaw.apper object is defined to perform basic ray projection operations, such as space transformation and cropping. Use the read image as the input data of the mappper object, and create a vtkvolume (this class is a subclass of vtkprop3d, similar to the vtkactor function) object to store Mapper and property objects. Finally, add the vtkvolume object to Renderer for scene rendering.

If the two-dimensional texture ing method is used to replace the ray projection method, the simhei code can be replaced:

Vtkvolumetexturemapper2d volumemapper

Volumemapper setinputconnection [readergetoutputport]

If the video card supports 3D texture ing, the above Code can also replace the following with 3D texture ing:

Vtkvolumetexturemapper3d volumemapper

Volumemapper setinputconnection [readergetoutputport]

Vtkfixedpointraycaw.apper can also be used to replace vtkvolumeraycaw.apper. In most cases, this mapper is recommended. Vtkfixedpointraycaw.apper regards all data types as multi-metadata, and uses the fixed-point computing and spatial skip Technology for efficient computing. Since its hybrid operation uses hard encoding, it is difficult to customize a new ray projection algorithm, which has poor scalability. In the preceding example, vtkfixedpointraycaw.apper is replaced with the following:

Vtkfixedpointraycaw.apper volumemapper

Volumemapper setinputconnection [readergetoutputport]

If you use the Volume Rendering Method of irregular data to replace it, the replacement code will be slightly more complex, because you need to convert vtkimagedata to vtkunstructuredgrid type data before setting mapper input. The following code uses the non-Rule mesh rendering technology to project the four-dimensional mesh data using a video card.

# Convert data to unstructured grid

Vtkdatasettrianglefilter tetrafilter

Tetrafilter setinputconnection [readergetoutputport]

 

# Creates the objects specific to the projectedtetrahedral Method

Vtkprojectedtetrahedramapper volumemapper

Volumemapper setinputconnection [tetrafilter getoutputport]

It is not recommended to convert vtkimagedata to vtkunstructuredgrid data. Because the mappers for vtkimagedata is superior to those for vtkunstructuredgrid in terms of time efficiency and rendering effect.


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.