<div dir="ltr"><div><div><div>Hi Alex,<br><br></div><div>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.<br></div><div><br></div>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.<br><br></div>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.<br><br></div>Robert.<br><div><div><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 17 December 2015 at 18:10, Alex Taylor <span dir="ltr"><<a href="mailto:alextaylor@gmail.com" target="_blank">alextaylor@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-size:13px;line-height:19.5px"><div><div dir="ltr"><div>I have a question about the construction of the osgImage and the specification of a transfer function. </div><div><br></div><div>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.</div><div><br></div><div>If I construct my image in a function createTexture3D as follows:</div><div><br></div><div><div> <b> osg::Image* createTexture3D(const mxArray* src, const uint8_T* xfer_table) {</b></div><div><b> </b></div><div><b> if (src == NULL || mxGetNumberOfDimensions(src) != 3 || mxGetClassID(src) != mxUINT8_CLASS) {</b></div><div><b> return NULL;</b></div><div><b> }</b></div><div><b> </b></div><div><b> size_t num_s = mxGetDimensions(src)[0];</b></div><div><b> size_t num_t = mxGetDimensions(src)[1];</b></div><div><b> size_t num_r = mxGetDimensions(src)[2];</b></div><div><b> </b></div><div><b> // now allocate the 3d texture;</b></div></div><div><b><br></b></div></div></div></div><div style="font-size:13px;line-height:19.5px"><div><div dir="ltr"><div><b> osg::ref_ptr<osg::Image> image_3d = new osg::Image;</b></div><div><b> </b></div></div></div></div><div style="font-size:13px;line-height:19.5px"><div><div dir="ltr"><div><div><b> image_3d->setImage(num_s, num_t, num_r, </b></div><div><b> GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE,</b></div><div><b> static_cast<uint8_T *>(mxGetData(src)),</b></div><div><b> osg::Image::NO_DELETE);</b></div><div><b> </b></div><div><b> return image_3d.release();</b></div><div><b> }</b></div></div><div><b><br></b></div><div>And then attempt to setup my transfer function, I can't get the specification of the transfer function right. I've tried:</div><div><br></div><div></div></div></div></div><div style="font-size:13px;line-height:19.5px"><div title="Hide quoted text">…</div><div><div dir="ltr"><div><b> osg::ref_ptr<osg::Image> image_3d = createTexture3D(data,xfer_table);</b></div><div><b> </b></div><div><b> osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image_3d.get());</b></div><div><b> </b></div><div><b> tile->setLayer(layer.get());</b></div><div><b> </b></div></div></div></div><div style="font-size:13px;line-height:19.5px"><div><div dir="ltr"><div><b> //tile->setVolumeTechnique(new osgVolume::FixedFunctionTechnique());</b></div><div><b> tile->setVolumeTechnique(new osgVolume::RayTracedTechnique());</b></div><div><b><br></b></div><div><b> float alphaFunc=0.0f;</b></div></div></div></div><div style="font-size:13px;line-height:19.5px"><div title="Hide quoted text">…</div><div><div dir="ltr"><div><b> float sampleDensityWhenMoving = 0.02;</b></div><div><b> osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc);</b></div><div><b> osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005);</b></div><div><b> osgVolume::SampleDensityWhenMovingProperty* sdwm = sampleDensityWhenMoving!=0.0 ? new osgVolume::SampleDensityWhenMovingProperty(sampleDensityWhenMoving) : 0;</b></div></div></div></div><div style="font-size:13px;line-height:19.5px"><div><div dir="ltr"><div><div><b> osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(0.6);</b></div><div><b> osgVolume::TransferFunctionProperty* tfp = new osgVolume::TransferFunctionProperty(transferFunction);</b></div><div><b> </b></div><div><b> layer->addProperty(ap);</b></div><div><b> layer->addProperty(sd);</b></div><div><b> layer->addProperty(sdwm);</b></div><div><b> layer->addProperty(tp);</b></div><div><b> layer->addProperty(tfp);</b></div></div><div><br></div><div>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]. </div><div><br></div><div>One question I have: what is the expected datatype and normalization of values in the LUT for color and alpha values?</div><div><br></div><div>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.</div><div><br></div><div>How exactly should I specify the transferFunction in terms of datatype and normalization of data values within the transferFunction?</div><div><br></div><div>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.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>- Alex</div></font></span></div></div></div></div>
<br>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></blockquote></div><br></div>