[osg-users] Question about working with osgVolume

Alex Taylor alextaylor at gmail.com
Thu Dec 17 10:10:07 PST 2015

I have a question about the construction of the osgImage and the
specification of a transfer function.

I have uint8_T intensity data in the range [0 255] and a 1-D transfer
function of RGBA uint8_T values in a lookup table, also in the range [0
255]. I can't figure out the right setup for my osgImage and the
specification of the TransferFunction1D when working with
RayTracedTechnique as the rendering algorithm.

If I construct my image in a function createTexture3D as follows:

  * osg::Image* createTexture3D(const mxArray* src, const uint8_T*
xfer_table) {*

*        if (src == NULL || mxGetNumberOfDimensions(src) != 3 ||
mxGetClassID(src) != mxUINT8_CLASS) {*
*            return NULL;*
*        }*

*        size_t num_s = mxGetDimensions(src)[0];*
*        size_t num_t = mxGetDimensions(src)[1];*
*        size_t num_r = mxGetDimensions(src)[2];*

*        // now allocate the 3d texture;*

*        osg::ref_ptr<osg::Image> image_3d = new osg::Image;*

*        image_3d->setImage(num_s, num_t, num_r, *
*                static_cast<uint8_T *>(mxGetData(src)),*
*                osg::Image::NO_DELETE);*

*        return image_3d.release();*
*    }*

And then attempt to setup my transfer function, I can't get the
specification of the transfer function right. I've tried:

*    osg::ref_ptr<osg::Image> image_3d = createTexture3D(data,xfer_table);*

*            osg::ref_ptr<osgVolume::ImageLayer> layer = new

*            tile->setLayer(layer.get());*

*            //tile->setVolumeTechnique(new
*            tile->setVolumeTechnique(new osgVolume::RayTracedTechnique());*

*            float alphaFunc=0.0f;*
*            float sampleDensityWhenMoving = 0.02;*
*            osgVolume::AlphaFuncProperty* ap = new
*            osgVolume::SampleDensityProperty* sd = new
*            osgVolume::SampleDensityWhenMovingProperty* sdwm =
sampleDensityWhenMoving!=0.0 ? new
osgVolume::SampleDensityWhenMovingProperty(sampleDensityWhenMoving) : 0;*
*            osgVolume::TransparencyProperty* tp = new
*            osgVolume::TransferFunctionProperty* tfp = new

*            layer->addProperty(ap);*
*            layer->addProperty(sd);*
*            layer->addProperty(sdwm);*
*            layer->addProperty(tp);*
*            layer->addProperty(tfp);*

If I don't specify a TransferFunctionProperty, depending on the dataset, I
sometimes see a cube shaped brick that roughly shows the structure of my
data, othertimes I see nothing at all. When I specify the transfer
function, I don't see anything at all. I've tried defining my
TransferFunction1D as a 4-vec of float values in the range [0 1] and a
uint8_T values in the range [0 255].

One question I have: what is the expected datatype and normalization of
values in the LUT for color and alpha values?

As a debugging step, I tried FixedFunctionTechnique. In that algorithm, I
see my data as I would expect as grayscale without any color mapping
applied. It looks like it's modulating alpha using the intensity values for
each voxel. This at least suggests I'm roughly using the setImage method of
osgImage properly, it seems like I"m just not able to set the
transferFunction correctly.

How exactly should I specify the transferFunction in terms of datatype and
normalization of data values within the transferFunction?

Hoping someone on the list can help me, I feel like working with uint8
intensity data and a known colormap/transfer function is a pretty common
use case of volume rendering, but I can't seem to get this right.

- Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151217/910f1926/attachment-0002.htm>

More information about the osg-users mailing list