Volume Rendering Method in VTK

Source: Internet
Author: User

VTK was initially designed for medical applications. Therefore, it has powerful functions for medical visualization, such as CT scan data processing. It shields the details that are frequently encountered in the visualization process and encapsulates some common VISUAL algorithms, such as the commonly used MC (Marching Cubes) in surface painting) the ray-casting algorithms and commonly used Ray-casting algorithms in volume rendering are encapsulated into classes for users. In this way, you can directly use the related classes provided in VTK for medical body data visualization.
VTK provides three types of Volume Rendering technologies, in addition to the ray projection method, as well as two-dimensional texture ing and volumepro-based hardware-assisted volume rendering.
The ray projection method is a typical rendering algorithm based on image space scanning to generate high-quality images. The basic idea is to emit a Ray from each pixel in the image plane along the line of sight, this ray passes through the body dataset and is sampled at a certain step. The color value and opacity of each sampling point are calculated by interpolation, then, the accumulated color value and opacity value are calculated from the beginning to the back or from the back to the front until the light is completely absorbed or passed through the object. This method can well reflect the changes in the material boundary. Using the phong model, the introduction of mirror reflection, diffuse reflection, and environmental reflection can produce a good illumination effect, in medicine, the properties, shape features, and hierarchical relationships of various tissues and organs can be displayed, enriching image information.
Two-dimensional texture ing is different from the ray projection method. It is based on the object space scan, that is, it processes the data points of the object space, computes the contribution of each data point to the screen pixel, and synthesize it, form the final image. Its rendering speed is 5 to 5 faster than the ray projection method ~ 10 times, but the imaging quality is far less accurate than the Light Projection Method Using tri-linear interpolation. When the angle of view changes, it will also produce false traces.
Based on the volumepro hardware-assisted volume rendering method, although the imaging quality is not as good as the ray projection method, it is better than two-dimensional texture ing. The volumepro hardware supports the fastest volume rendering speed, generally at least 20 frames per second, but currently only supports parallel projection and is expensive.
Each technology has its own advantages and disadvantages, and developers should choose based on actual needs. Currently, the ray projection method in VTK is the most widely used. This is because not only does it have the best imaging quality, but with the development of computer technology and the continuous improvement of algorithms, its rendering capability is also constantly improved. Due to the limited imaging quality and graphics hardware, volumepro is rarely used for its price.
Ray Projection Method in VTK
VTK provides users with three functions for ray projection: vtkvolumeraycastisosurfacefunction, vtkvolumeraycast mipfunction, and vtkvolumeraycastcompositefunction ). In the isosurface painting method, light passes through the isosurface to be displayed in the data field, and then parameters such as color and shade are defined in the VTK volume body property-vtkvolumeproperty, by setting the isosurface value, you can reconstruct a specific tissue, such as skin and skeleton. The result image is similar to the surface display. Maximum intensity projection (MIP) is used to plot the maximum density of light when it passes through the data field. It can be considered as the simplest method of volume rendering, you do not need to clearly define the Conversion Relationship Between the body data and the color value. The data values related to the maximum density are projected into each pixel on the corresponding screen to form the final image. Because the MIP method can provide more intuitive images, just like X-ray imaging, this method is often used to display the three-dimensional structure of blood vessels. However, like an x-ray, MIP cannot provide depth information or describe overlapping structures. The synthetic volume rendering method is the most commonly used method for ray projection. in VTK, the transfer function is used to convert the volume data value into optical properties such as color and opacity, finally, these attributes are synthesized into pixels on the screen to form a three-dimensional image. In VTK, the following three transfer functions must be defined to achieve the best rendering effect:
(1) opacity transfer function. This function determines the opacity of each element or unit length value;
(2) color transfer function. This function determines the color value or gray value of the object;
(3) gradient transfer function. This function determines the opacity of different gradient values to highlight the structure and hierarchy between different organizations.
In VTK, The vtkpiecewisefunction class is used to design the transfer function. The addpoint and addsegment functions in this class are used to add numerical points. The following code designs a simple transfer function:
Vtkpiecewisefunction * opacitytransferfunction = vtkpiecewise function: New ();
Opacitytransferfunction-> addpoint (0, 0.0 );
Opacitytransferfunction-> addpoint (500, 0.0 );
Opacitytransferfunction-> addsegment (600, 0.73, 900, 0.9 );
Opacitytransferfunction-> addpoint (1300, 2.0 );
The design of complex transfer functions is realized by using straight lines for curve approximation.
In VTK, You need to perform a set of medical body data volume rendering, nine steps are required: drawing class settings, drawing window settings, interaction settings, Data Reading, passing function settings, body attribute settings, drawing method ing, loading of various attributes, and drawing. The following is the c ++ code drawn in VTK. The key classes and functions are annotated.
Vtkrenderer * arender = vtkrenderer: New (); // you can specify a painting class.
Vtkrenderwindow * renwin = vtkrenderwindow: New (); // you can specify a drawing window.
Renwin-> addrenderer (arender); // load the rendering class
Vtkrenderwindowindowinteractor * iren = vtkrenderwindowindowinteractor: New (); // you can specify the interaction of the drawing window.
Iren-> setrenderwindow (renwin); // load the drawing window
Vtkvolume16reader * reader = vtkvolume 16 reader: New (); // read DICOM data
Reader-> setdatadimensions (64, 64); // sets the image pixel value.
Reader-> setimagerange (); // you can specify the number of images.
Reader-> setdatabyteordertolittleendian ();
Reader-> setfileprefix ("X: // data"); // you can specify the data path.
Reader-> setdataspacing (1.0, 1.0, 0.48); // you can specify the data spacing.
Vtkpiecewisefunction * opacitytransferfunction = vtkpiecewise function: New (); // sets the opacity Transfer Function
Opacitytransferfunction-> addpoint (0, 0.0 );
Opacitytransferfunction-> addpoint (500, 0.0 );
Opacitytransferfunction-> addsegment (600, 0.73, 900, 0.9 );
Opacitytransferfunction-> addpoint (1300, 2.0 );
Vtkcolortransferfunction * colortransferfunction = vtkcolortransferfunction: New (); // sets the color transfer function.
Colortransferfunction-> addrgbpoint (0, 0, 0, 0); // set the color to a gray value.
Colortransferfunction-> addrgbpoint (500, 0.1, 0.1, 0.1 );
Colortransferfunction-> addrgbpoint (600, 0.7, 0.7, 0.7 );
Colortransferfunction-> addrgbpoint (900, 0.85, 0.85, 0.85 );
Colortransferfunction-> addrgbpoint (1300, 1.0, 1.0, 1.0 );
Vtkpiecewisefunction * gradienttransferfunction = vtkpiecewisefunction: New (); // you can specify a gradient transfer function.
Gradienttransferfunction-> addpoint (0, 2.0 );
Gradienttransferfunction-> addpoint (500, 2.0 );
Gradienttransferfunction-> addsegment (600, 0.73, 900, 0.9 );
Gradienttransferfunction-> addpoint (1300, 0.1 );
Vtkvolumeproperty * volumeproperty = vtkvolumeproperty: New (); // define and set relevant body attributes
Volumeproperty-> setcolor (colortransferfunction );
Volumeproperty-> setscalaropacity (opacitytransferfunction );
Volumeproperty-> setgradientopacity (gradienttransferfunction );
Vtkvolumeraycastcompositefunction * compositeraycastfunction = vtkvolumeraycastcompositefunction: New (); // define the method of ray casting as the method of synthetic Volume Rendering
Vtkvolumeraycaw.apper * volumemapper = vtkvolumeraycaw.apper: New ();
Volumemapper-> setvolumeraycastfunction (compositeraycastfunction); // volume loading method
Volumemapper-> setinput (Reader-> getoutput ());
Vtkvolume * volume = vtkvolume: New (); // define volume
Volume-> setmapper (volumemapper); volume-> setproperty (volumeproperty); // you can specify the volume attribute.
Arender-> addvolume (volume); // load the volume into the drawing class
Arender-> setbackground (0, 0, 0 );
Renwin-> setsize (500,500); // set the background color and the size of the drawing window.
Renwin-> render (); // draw a window
Iren-> initialize ();
Iren-> Start (); // initialize and interactive drawing
In the above Code, you only need to initialize the maximum density projection function vtkvolumeraycastmipfunction and the isosurface rendering function vtkvolumeraycastisosurfacefunction, respectively, in the setvolumerayumeraycaw.apper class of vtkvolumeraycastfunction, you can replace the volume rendering method to achieve maximum density projection volume rendering and isosurface volume rendering.

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.