The code to create a basic VolumeViz scene graph is shown below. First we create a volume data node and load a small data file from the sample data directory that comes with the Open Inventor SDK (after installing the demos and examples). This will be explained further in Section 1.2, “Data”. Next we create a material node, a transfer function node using the predefined INTENSITY (gray scale) color map and a data range node. These will be explained in Section 1.3, “Appearance”. Next we create an axis aligned slice, set the axis to be the default camera view axis and set the slice number to position the slice at the center of the volume (which we already know in this case). This will be explained in Section 1.4, “Slice Rendering”. Finally we build the scene graph. Note that we put all the VolumeViz nodes under their own SoSeparator( C++ | Java | .NET ) node, which is then added to the root node for the complete scene graph. This is not required for a simple example, but it is good practice to start with a logical organization of the scene graph.
Not shown here are the “#include” or “using” statements to access these nodes. This works the same as for core Open Inventor nodes. If you’re not sure about the include path or assembly name, just look up the node in the reference manual. Also not shown are the initialization statements (for C++), creation of a viewer and the cleanup statements (for C++). These are essentially the same as for any Open Inventor application. Later we will discuss how to add interactivity to your application.
Before using VolumeViz:
After using VolumeViz:
|
// Create nodes SoVolumeData* pVolData = new SoVolumeData(); pVolData->fileName = "$OIVHOME/src/VolumeViz/Data/3DHead.vol"; SoMaterial* pMaterial = new SoMaterial; pMaterial->diffuseColor.setColor( 1, 1, 1 ); SoTransferFunction* pTF = new SoTransferFunction; pTF->predefColorMap = SoTransferFunction::INTENSITY; SoDataRange* pRange = new SoDataRange; SoOrthoSlice *pSliceZ = new SoOrthoSlice; pSliceZ->axis = SoOrthoSlice::Z; pSliceZ->sliceNumber = 54; // Build scene graph SoSeparator* pRoot = new SoSeparator; SoSeparator* pVolSep = new SoSeparator; pVolSep->addChild( pVolData ); pVolSep->addChild( pMaterial ); pVolSep->addChild( pTF ); pVolSep->addChild( pRange ); pVolSep->addChild( pSliceZ ); pRoot->addChild( pVolSep );
// Create nodes SoVolumeData VolData = new SoVolumeData(); VolData.fileName.Value = "$OIVHOME/src/VolumeViz/Data/3DHead.vol"; SoMaterial Material = new SoMaterial (); Material.diffuseColor.SetValue( 1, 1, 1 ); SoTransferFunction TF = new SoTransferFunction(); TF.predefColorMap.Value = SoTransferFunction.PredefColorMaps.INTENSITY; SoDataRange Range = new SoDataRange(); SoOrthoSlice SliceZ = new SoOrthoSlice(); SliceZ.axis.Value = SoOrthoSlice.AxisType.Z; SliceZ.sliceNumber.Value = 54; // Build scene graph SoSeparator Root = new SoSeparator(); SoSeparator VolSep = new SoSeparator(); VolSep.AddChild( VolData ); VolSep.AddChild( Material ); VolSep.AddChild( TF ); VolSep.AddChild( Range ); VolSep.AddChild( SliceZ ); Root.AddChild( VolSep );
// Create nodes SoVolumeData volData = new SoVolumeData(); volData.fileName.setValue( "$OIVHOME/src/VolumeViz/Data/3DHead.vol" ); SoMaterial material = new SoMaterial (); material.diffuseColor.setValue( 1, 1, 1 ); SoTransferFunction TF = new SoTransferFunction(); TF.predefColorMap.setValue( SoTransferFunction.PredefColorMaps.INTENSITY ); SoDataRange range = new SoDataRange(); SoOrthoSlice sliceZ = new SoOrthoSlice(); sliceZ.axis.setValue( SoOrthoSlice.AxisType.Z ); sliceZ.sliceNumber.setValue( 54 ); // Build scene graph SoSeparator root = new SoSeparator(); SoSeparator volSep = new SoSeparator(); volSep.addChild( volData ); volSep.addChild( material ); volSep.addChild( TF ); volSep.addChild( range ); volSep.addChild( sliceZ ); root.addChild( volSep );
The resulting image will be something like this:
You can open IvTune (by pressing Shift-F12) and examine the nodes in this scene graph, just like any Open Inventor scene graph. For example, you can select the SoTransferFunction( C++ | Java | .NET ) node and switch to a different predefined color map or select the SoOrthoSlice( C++ | Java | .NET ) node and change the slice number. Various sample data files and many example/demo programs are provided with VolumeViz for use in test/prototype applications. |