[osg-users] Question about working with osgVolume

Robert Osfield robert.osfield at gmail.com
Fri Dec 18 01:44:18 PST 2015


Hi Alex,

As a general rule in the OSG when an colour is represented by an osg::Vec4
then the r,g,b,a values are all in the unit range i.e. 0.0f to 1.0f.
OpenGL works this way too.  When you pass ubyte/ushort/byte/short/uint/int
data as a Image/Texture it'll be scaled from the max range of that data
type to 0.0 to 1.0 for unsigned and -1 to 1.0 for signed, for instance a
ubyte 255 value will be mapped to 1.0.

For the case a osg::TranserferFunction1D it's working in Vec4 for colours
so will be in the 0.0 to 1.0 range, 0.0 for fully off, 1.0 for full on.

The ranges for TransferFunction1D will be the same as input data, I think
but not 100% that is in the un-normalized range, unfortunately I'm a bit
rusty on this as it's quite a while since I wrote this code.

Robert.



On 17 December 2015 at 18:10, Alex Taylor <alextaylor at gmail.com> wrote:

> 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, *
> *                GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE,*
> *                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
> osgVolume::ImageLayer(image_3d.get());*
>
> *            tile->setLayer(layer.get());*
>
> *            //tile->setVolumeTechnique(new
> osgVolume::FixedFunctionTechnique());*
> *            tile->setVolumeTechnique(new
> osgVolume::RayTracedTechnique());*
>
> *            float alphaFunc=0.0f;*
>> *            float sampleDensityWhenMoving = 0.02;*
> *            osgVolume::AlphaFuncProperty* ap = new
> osgVolume::AlphaFuncProperty(alphaFunc);*
> *            osgVolume::SampleDensityProperty* sd = new
> osgVolume::SampleDensityProperty(0.005);*
> *            osgVolume::SampleDensityWhenMovingProperty* sdwm =
> sampleDensityWhenMoving!=0.0 ? new
> osgVolume::SampleDensityWhenMovingProperty(sampleDensityWhenMoving) : 0;*
> *            osgVolume::TransparencyProperty* tp = new
> osgVolume::TransparencyProperty(0.6);*
> *            osgVolume::TransferFunctionProperty* tfp = new
> osgVolume::TransferFunctionProperty(transferFunction);*
>
> *            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
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151218/f6a5cc23/attachment-0003.htm>


More information about the osg-users mailing list