How to: Include Volume Rendering in P3D
Volumes can be created from many different types of data, usually by recombining images that have been taken at set intervals through a 3D object, either by using a scanning technology like CT, MRI etc; or by physically slicing an object up and imaging each slice as in the Visible Human project. But there is no reason why it should be limited to this, anything from a series of frames of a movie, to images created in photoshop, could be used to create a volume.
- Creating Volumes from DICOM Files.
- Including Volumes in P3D
- Creating Volumes from an Image Series (.jpg, png, .tif)
- Creating Volumes from a Movie
Creating Volumes from DICOM Files.
Updating in progress : Updating in progress : Updating in progress
To view a volume from a folder (directory) of dicom files you will use the osgvolume cmd.
First, in your shell, you will need to navigate to the directory that has the folder that you want to use...
cd main_volume_directory/directory_that contains_the_folder_of _dicom_files
Then use osgvolume to load the folder you want use..
osgvolume folder_with_dicom_files
This will allow you to test that the dataset is working as expected before going any further. If you don't get the expected results, then open the folder and check how many files/slices there are. Your graphics card might be limiting the number of slices that can be used to 256, 512, 1024 or larger... make a copy of the folder and reduce the number of files to each of these limits in turn, until it works. Currently the ATI 4870 on the Mac should display 1024 slices.
To create a .dds, .osg or .ive from the folder do the same command but add -o and the name you want to use for the new volume and using the extension for the data type you want to create...
osgvolume folder_with_dicom_files -o volume.dds
osgvolume folder_with_dicom_files -o volume.osg
osgvolume folder_with_dicom_files -o volume.ive
Using osgvolume with colour transfer function
See colour transfer function info below :
osgvolume folder_with_dicom_files --tf colour.tf
osgvolume folder_with_dicom_files --tf-255 colour.tf (this doesn't work at present)
Where colour.tf is a text file with the appropriate values.
Including Volumes in P3D
There are two main methods of including a volume dataset in P3D.
<volume> </volume>
the volume tag is used to load a folder of dicom files or a .dds volume file.
<model> </model>
the model tag is used to load a .osg or .ive volume file.
The Volume Tag
Currently, using the volume tag directly with a folder/directory of dicom files enables more features, so we will deal with that first. It is hoped that the same features will be available for the other methods of loading volumes in the near future.
Below is an example of the volume tag being used....
<!-- sample volume -->
<slide>
<background></background>
<title></title>
<duration>18</duration>
<key>g</key>
<layer>
<volume tf-255="clut/colour.tf" alpha="0.9" cutoff="0.7" sampleDensity="0.004" technique="light" region="0.0 0.0 0.0 1.0 1.0 1.0">folder_with dicom_files</volume>
</layer>
</slide>
So lets go through the various properties that have been applied here :
tf-255="clut/colour.tf"
This is the transfer function property, there are two versions "tf" where colour and alpha values are set between 0 and 1, and "tf-255" where they are set between 0 and 255, as this allows you to use a RGB colour picker in say photoshop, find the colour you want and just grab the rgb values and enter them into the .tf text file. So lets have look at a bit of the colour.tf file...
36 0 0 0 0.00
37 203 202 198 0
45 145 143 143 0
46 110 9 14 0
60 86 8 12 30
100 153 8 8 60
101 183 35 84 200
150 183 35 84 150
250 244 240 210 50
300 132 85 35 80
400 255 208 117 200
1000 255 185 117 255
1001 0 0 0 0.00
1500 0 0 0 0.00
The first column is the density in Hounsfield Units (hu), this allows you select which parts of the data the colour or alpha values that follow, will be applied to.
The second, third and fourth columns are colour using 0-255 range (RGB). So, in the above example, bone, which is between 400 - 1,000 hu has been coloured 255 208 117 changing to 255 185 117.
The fifth column is the alpha value also set using 0-255 range. o, in the above example, the alpha for the range 400 - 1,000 hu has been set to go from 200 to 255(full on).
Information on Hounsfield Units : http://www.medcyclopaedia.com/library/topics/volume_iii_1/h/hounsfield_unit.aspx
Some sample tf-255 colour.tf (CLUT) files : colour_255.zip
Sample Colour chart : .psd : volumeColours.psd
Sample Colour chart : .jpg :
alpha="0.9"
The "alpha" property is the alpha value that controls transparency/blending, 1.0 is the default.
cutoff="0.7"
The "cutoff" property is the alpha value below which fragments are automatically discarded that 0.1 is the default.
sampleDensity="0.004"
The "sampleDensity" property is the sample density used in the ray tracing, the lower the value the higher the quality the result, but the slower it is.
region="0.0 0.0 0.0 1.0 1.0 1.0"
The "region" property is the "xmin ymin zmin xmax ymax zmax" region of the volume that is displayed on screen, the range is 0.0 to 1.0. Note, that in this case, as with rotate and rotation y the second and fifth value is in/out of the screen and z is up/down. The above values will show the complete volume where as
region="0.15 0.0 0.0 0.5 1.0 1.0"
will clip both left and right sides of the data, cutting the dataset in half vertically.
technique="light"
The "technique" property selects which of the rendering options to use and equates to pressing the v key in P3D. There are four options :
technique="default"
technique="light"
technique="iso"
technique="mip"
Other Properties
You can also include, position, rotate and rotation properties as usual.
position="0.5 0.5 0.15"
rotate="30 0 0 1"
rotate1="30 0 0 1"
rotate2="60 0 1 0"
rotation="20 0 0 1"
Known Issues
Coming soon :
<volume dragger="box">CardiacCT</volume>
Creating Volumes from an Image Series (.jpg, png, .tif)
This page needs to be updated :
Create a script as below substituting .tif for the image type you are using ie: .jpg .png etc.
To create the script open a new document in BBedit and paste the following text into it
(Note from Robert Osfield, currently the .ive format does not support the osgVolume NodeKit so you can't save volumes as .ive files, instead you must use .osg. A future release of the OpenSceneGraph will add osgVolume support to .ive, but for now one must use .osg for saving volumes).
#!/bin/sh
osgvolume --images *.tif --num-components 1 --r_maxTextureSize 512 -n --zMultiplier -1.0 -o volume.osg
echo make volume complete
exit 0
and save it into the directory where your image files are, with a name like:
make_volume
then change permissions of the file - use terminal and go to the directory and do:
Now if you type :
this will create a file called volume.osg and a volume.dss image file. Both the .osg and .dds file will need to be used together. One loads the volume.osg file, and this volume.osg will reference the volume.dds file for you.
You can also do part volumes by using the following and changing the **** part:
Other options
for help :
osgvolume --help
Usage: osgvolume [options] filename ...
Options:
-h or --help Display this information
-s <numSlices> Number of slices to create.
-n Create normal map for per voxel lighting.
--clip <ratio> clip volume as a ratio, 0.0 clip all, 1.0 clip none.
--compressed Enable the usage of compressed textures.
--compressed-arb Enable the usage of OpenGL ARB compressed textures.
--compressed-dxt1 Enable the usage of S3TC DXT1 compressed textures.
--compressed-dxt3 Enable the usage of S3TC DXT3 compressed textures.
--compressed-dxt5 Enable the usage of S3TC DXT5 compressed textures.
--images [filenames] Specify a stack of 2d images to build the 3d volume from.
--maxTextureSize <size> Set the texture maximum resolution in the s,t,r (x,y,z) dimensions.
--num-components <num> Set the number of components to in he target image.
--r_maxTextureSize <size> Set the texture maximum resolution in the r (z) dimension.
--s_maxTextureSize <size> Set the texture maximum resolution in the s (x) dimension.
--t_maxTextureSize <size> Set the texture maximum resolution in the t (y) dimension.
--modulate-alpha-by-luminance For each pixel multiply the alpha value by the luminance.
--replace-alpha-with-luminance For each pixel m Set the alpha value to the luminance.
--shader Use OpenGL Shading Language.
--xMultiplier <multiplier> Tex coord x mulitplier.
--yMultiplier <multiplier> Tex coord y mulitplier.
--zMultiplier <multiplier> Tex coord z mulitplier.
--xSize <size> Relative width of rendered brick.
--ySize <size> Relative length of rendered brick.
--zSize <size> Relative height of rendered brick.
____
Using in Present3D
You can load and view the resulting volume either by creating a P3D xml file with your volume and other data or just by using present3D on the command line, so type :
and this will load your volume. You can now use the the a, t and k keys along with mouse movement, to interact with the volume, try it :-)
Comments (0)
You don't have permission to comment on this page.