Contour Polygon Rendering:
#include <vtkSmartPointer.h> #include <vtkImageData.h> #include <vtkStructuredPoints.h> #include <vtkStructuredPointsReader.h> #include <vtkVolumeRayCastIsosurfaceFunction.h> #include < vtkvolumeraycastmapper.h> #include <vtkColorTransferFunction.h> #include <vtkpiecewisefunction.h># Include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkrenderwindowinteractor.h># Include <vtkVolumeProperty.h> #include <vtkAxesActor.h> #include <vtkImageShiftScale.h> #include <vtkimagecast.h>//equivalent polygon drawing effect int main (int argc, char *argv[]) {vtksmartpointer<vtkstructuredpointsreader> Reader =vtksmartpointer<vtkstructuredpointsreader>::new (); Reader->setfilename (".. /MUMMY.128.VTK "); Reader->update ();//The Contour drawing function is used to render a specific contour in the body data vtksmartpointer< Vtkvolumeraycastisosurfacefunction> Raycastfun =vtksmartpointer<vtkvolumeraycastisosurfacefunction>:: New (); Raycastfun->setisovalue (100);//For setting the value of the contour less than the value of the pixel is less than the non-transparentThe lightness is set to 0//to define a ray projection body to draw vtksmartpointer<vtkvolumeraycastmapper> Volumemapper =vtksmartpointer< Vtkvolumeraycastmapper>::new (); Volumemapper->setinputdata (Reader->getoutput ());//Accept input data volumeMapper- >setvolumeraycastfunction (Raycastfun);//must be set or error set ray projection function type vtksmartpointer<vtkvolumeproperty> Volumeproperty =vtksmartpointer<vtkvolumeproperty>::new (); volumeproperty->setinterpolationtypetolinear ();//Set linear interpolation type Volumeproperty->shadeon (); volumeproperty->setambient (0.2);//Shadow Color volumeproperty-> Setdiffuse (0.6);//Diffuse volumeproperty->setspecular (0.4);//highlights this attribute to 0.8 has a "copper" effect ~~////transparency mapping function definition//assigning opaque values to data points. The internal structure of a three-dimensional data field needs to be displayed, resulting in a transparent image. Vtksmartpointer<vtkpiecewisefunction> compositeopacity =vtksmartpointer<vtkpiecewisefunction>::new () ; Compositeopacity->addpoint (0.00), Compositeopacity->addpoint (0.40); Compositeopacity->addpoint ( 0.60); volumeproperty->setscalaropacity (compositeopacity);////color map function definition//Assign color values to data points, separate the organized information into different colors for easy imageAnalysis. Vtksmartpointer<vtkcolortransferfunction> color =vtksmartpointer<vtkcolortransferfunction>::new (); Color->addrgbpoint (0.000, 0.00, 0.00, 0.00); Color->addrgbpoint (64.00, 1.00, 0.52, 0.30); Color->addrgbpoint ( 190.0, 1.00, 1.00, 1.00) color->addrgbpoint (220.0, 0.20, 0.20, 0.20); Volumeproperty->setcolor (color);// The Vtkvolume governs the Mapper and property objects, controls the position of the body data and faces vtksmartpointer<vtkvolume> volume =vtksmartpointer<vtkvolume>::new () ; Volume->setmapper (volumemapper);//Build Body Object Volume->setproperty (Volumeproperty);//Set Body object generic type vtksmartpointer< Vtkrenderer> ren = vtksmartpointer<vtkrenderer>::new (); Ren->setbackground (1.0, 1.0, 1.0);ren-> Addvolume (volume);vtksmartpointer<vtkrenderwindow> renwin = Vtksmartpointer<vtkrenderwindow>::new (); Renwin->addrenderer (ren); renwin->setsize (640, 480); Renwin->render (); Renwin->setwindowname (" Isosurfacevolrenderingapp ");vtksmartpointer<vtkrenderwindowinteractor> Iren =vtkSmartPointer<vtkRenderWIndowinteractor>::new (); Iren->setrenderwindow (Renwin); Ren->resetcamera (); Renwin->render (); iren- >start (); return exit_success;}
Ignore the red word above, originally want to make expression bag = =
Two-dimensional texture mapping:
Rendering faster than the ray projection, but only the alpha synthesis technology, and the slice using bilinear interpolation to achieve texture mapping, there is no interpolation between slices, rendering quality is reduced, and need to save the corresponding texture image stack in three directions, occupy a large memory
#include <vtkSmartPointer.h> #include <vtkImageData.h> #include <vtkStructuredPoints.h> #include <vtkStructuredPointsReader.h> #include <vtkVolumeTextureMapper2D.h> #include < vtkcolortransferfunction.h> #include <vtkPiecewiseFunction.h> #include <vtkRenderer.h> #include < vtkrenderwindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkVolumeProperty.h> #include <vtkAxesActor.h> #include <vtkImageShiftScale.h> #include <vtkimagecast.h>int main (int argc, char * Argv[]) {vtksmartpointer<vtkstructuredpointsreader> reader =vtksmartpointer<vtkstructuredpointsreader >::new (); Reader->setfilename (".. /MUMMY.128.VTK "); Reader->update ();//The previous Code of mapper (now looked at is the meaning of cartography = =) is called vtkvolumeraycastmappervtksmartpointer< Vtkvolumetexturemapper2d> volumemapper =vtksmartpointer<vtkvolumetexturemapper2d>::new (); volumeMapper- >setinputdata (Reader->getoutput ());//This section sets the body drawing property as the previous copy ==VTKSMARTPOINTER<VTKVOLUMEPRoperty> volumeproperty =vtksmartpointer<vtkvolumeproperty>::new ();volumeproperty-> Setinterpolationtypetolinear (); Volumeproperty->shadeon (); volumeproperty->setambient (0.4); volumeProperty- >setdiffuse (0.6); Volumeproperty->setspecular (0.2);//Transparency settings, cliché ==vtksmartpointer<vtkpiecewisefunction > Compositeopacity =vtksmartpointer<vtkpiecewisefunction>::new (); Compositeopacity->addpoint (70, 0.00) ; Compositeopacity->addpoint (0.40); Compositeopacity->addpoint (0.60);volumeproperty-> Setscalaropacity (compositeopacity);//color mapping function definition, is still the same as the following function is the same = = no wonder the book is no longer written vtksmartpointer< Vtkcolortransferfunction> color =vtksmartpointer<vtkcolortransferfunction>::new (); color->AddRGBPoint (0.000, 0.00, 0.00, 0.00); Color->addrgbpoint (64.00, 1.00, 0.52, 0.30); Color->addrgbpoint (190.0, 1.00, 1.00, 1.00) ; Color->addrgbpoint (220.0, 0.20, 0.20, 0.20); Volumeproperty->setcolor (color); vtksmartpointer<vtkvolume > Volume =VTKSMARTPOINTER<VTKVOlume>::new (); Volume->setmapper (Volumemapper); Volume->setproperty (Volumeproperty);vtkSmartPointer< Vtkrenderer> ren = vtksmartpointer<vtkrenderer>::new (); Ren->setbackground (1.0, 1.0, 1.0);ren-> Addvolume (volume);vtksmartpointer<vtkrenderwindow> renwin = Vtksmartpointer<vtkrenderwindow>::new (); Renwin->addrenderer (ren); renwin->setsize (640, 480); Renwin->render (); Renwin->setwindowname (" Texture2dvolrenderingapp ");vtksmartpointer<vtkrenderwindowinteractor> Iren =vtkSmartPointer< Vtkrenderwindowinteractor>::new (); Iren->setrenderwindow (Renwin); Ren->resetcamera (); RenWin->Render ( ); Iren->start (); return exit_success;}
(How about a word?
Three-dimensional texture mapping:
The three-dimensional mapping is to map the body data to a set of quadrilateral shapes parallel to the view plane, avoiding the defects caused by texture image switching in the two-dimensional texture mapping method. Except that the class becomes ~3d, the others are the same, comments omit = =
Vtksmartpointer<vtkstructuredpointsreader> Reader =vtksmartpointer<vtkstructuredpointsreader>::new () ; Reader->setfilename (".. /MUMMY.128.VTK "); Reader->update ();vtksmartpointer<vtkvolumetexturemapper3d> volumeMapper = Vtksmartpointer<vtkvolumetexturemapper3d>::new (); Volumemapper->setinputdata (Reader->GetOutput ()); Vtksmartpointer<vtkvolumeproperty> Volumeproperty =vtksmartpointer<vtkvolumeproperty>::new (); Volumeproperty->setinterpolationtypetolinear (); Volumeproperty->shadeon (); Volumeproperty->setambient ( 0.4); Volumeproperty->setdiffuse (0.6); Volumeproperty->setspecular (0.2);vtksmartpointer< Vtkpiecewisefunction> compositeopacity =vtksmartpointer<vtkpiecewisefunction>::new (); compositeOpacity- >addpoint (0.00), Compositeopacity->addpoint (0.40), Compositeopacity->addpoint (180, 0.60); Volumeproperty->setscalaropacity (compositeopacity);vtksmartpointer<vtkcolortransferfunction> color = Vtksmartpointer<vTkcolortransferfunction>::new (); Color->addrgbpoint (0.000, 0.00, 0.00, 0.00); Color->addrgbpoint (64.00, 1.00, 0.52, 0.30); Color->addrgbpoint (190.0, 1.00, 1.00, 1.00); Color->addrgbpoint (220.0, 0.20, 0.20, 0.20); Volumeproperty->setcolor (color);vtksmartpointer<vtkvolume> volume =vtksmartpointer<vtkvolume>:: New (); Volume->setmapper (Volumemapper); Volume->setproperty (volumeproperty); vtksmartpointer<vtkrenderer > ren = vtksmartpointer<vtkrenderer>::new (); Ren->setbackground (1.0, 1.0, 1.0); Ren->addvolume (volume) ;vtksmartpointer<vtkrenderwindow> Renwin = vtksmartpointer<vtkrenderwindow>::new ();renWin-> Addrenderer (ren); renwin->setsize (640, 480); Renwin->render (); Renwin->setwindowname (" Texture3dvolrenderingapp "); int valid = volumemapper->isrendersupported (Volumeproperty, ren); if (!valid) return exit_success;//determines whether the current render vtksmartpointer<vtkrenderwindowinteractor> Iren is supported =vtksmartpointer< Vtkrenderwindowinteractor>::New (); Iren->setrenderwindow (Renwin); Ren->resetcamera (); Renwin->render (); Iren->start (); return EXIT_ SUCCESS;
Well, let's talk about the opacity transfer function, color transfer function, lighting and shading.
Opacity transfer function
That's the text.
vtksmartpointer<vtkpiecewisefunction> compositeopacity = Vtksmartpointer<vtkpiecewisefunction>::new () ; Compositeopacity->addpoint ( 0.00), Compositeopacity->addpoint ( 0.40);compositeopacity-> Addpoint ( 0.60); volumeproperty->setscalaropacity (compositeopacity);
Addpoint is just one way to define scalar linear piecewise functions. The first parameter, X, is the independent variable, which is the grayscale value; y is the map value, which is the opacity
Addsegment is another way to add a line segment directly, adding two breakpoints X1,y1,x2,y2
Gradient Opacity function addition method is setgradientopacity ()
Color Transfer function
Map a scalar to a color value, either RGB or HSV RGB to HSV.
Vtksmartpointer<vtkcolortransferfunction> color = vtksmartpointer<vtkcolortransferfunction>::new (); Color->addrgbpoint (0.000, 0.00, 0.00, 0.00); Color->addrgbpoint (64.00, 1.00, 0.52, 0.30);color-> Addrgbpoint (190.0, 1.00, 1.00, 1.00); Color->addrgbpoint (220.0, 0.20, 0.20, 0.20);volumeproperty-> SetColor (color);
Light and Shadow
The previous comment is a bit inaccurate here qaq
Volumeproperty->shadeon ();//Open Shadow effect volumeproperty->setambient (0.4);//Set ambient light factor volumeproperty->setdiffuse (0.6);//Set the scattering light coefficient volumeproperty->setspecular (0.2);//Set the reflected light coefficient
In General, three coefficients and = 1, for increased brightness, and may be greater than 1
In these three coefficients, when the ambient light dominates, the shadow effect is not obvious, the scattering light coefficient dominates, the display effect is rough, the reflected light dominates, the display effect is relatively smooth. When the shadow effect is off, it is equal to the ambient light factor = 1.0, and the other two coefficients =0
VTK Contour Rendering | Texture mapping body drawing attached: opaque transfer function, color transfer function, illumination and shading