Added scaling of shader transfer function input values to honour original dicom input values
This commit is contained in:
@@ -182,7 +182,7 @@ void ImageLayer::offsetAndScaleImage(const osg::Vec4& offset, const osg::Vec4& s
|
||||
|
||||
void ImageLayer::rescaleToZeroToOneRange()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"ImageLayer::rescaleToZeroToOneRange()"<<std::endl;
|
||||
osg::notify(osg::INFO)<<"ImageLayer::rescaleToZeroToOneRange()"<<std::endl;
|
||||
|
||||
osg::Vec4 minValue, maxValue;
|
||||
if (computeMinMax(minValue, maxValue))
|
||||
@@ -200,8 +200,8 @@ void ImageLayer::rescaleToZeroToOneRange()
|
||||
float scale = 0.99f/(maxComponent-minComponent);
|
||||
float offset = -minComponent * scale;
|
||||
|
||||
osg::notify(osg::NOTICE)<<" scale "<<scale<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" offset "<<offset<<std::endl;
|
||||
osg::notify(osg::INFO)<<" scale "<<scale<<std::endl;
|
||||
osg::notify(osg::INFO)<<" offset "<<offset<<std::endl;
|
||||
|
||||
offsetAndScaleImage(osg::Vec4(offset, offset, offset, offset),
|
||||
osg::Vec4(scale, scale, scale, scale));
|
||||
|
||||
@@ -251,6 +251,20 @@ void RayTracedTechnique::init()
|
||||
|
||||
if (tf)
|
||||
{
|
||||
float tfScale = 1.0f;
|
||||
float tfOffset = 0.0f;
|
||||
|
||||
ImageLayer* imageLayer = dynamic_cast<ImageLayer*>(_volumeTile->getLayer());
|
||||
if (imageLayer)
|
||||
{
|
||||
tfOffset = (imageLayer->getTexelOffset()[3] - tf->getMinimum()) / (tf->getMaximum() - tf->getMinimum());
|
||||
tfScale = imageLayer->getTexelScale()[3] / (tf->getMaximum() - tf->getMinimum());
|
||||
}
|
||||
else
|
||||
{
|
||||
tfOffset = -tf->getMinimum() / (tf->getMaximum()-tf->getMinimum());
|
||||
tfScale = 1.0f / (tf->getMaximum()-tf->getMinimum());
|
||||
}
|
||||
osg::ref_ptr<osg::Texture1D> tf_texture = new osg::Texture1D;
|
||||
tf_texture->setImage(tf->getImage());
|
||||
tf_texture->setResizeNonPowerOfTwoHint(false);
|
||||
@@ -258,10 +272,10 @@ void RayTracedTechnique::init()
|
||||
tf_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
||||
tf_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
osg::ref_ptr<osg::Uniform> tf_sampler = new osg::Uniform("tfTexture",1);
|
||||
|
||||
stateset->setTextureAttributeAndModes(1, tf_texture.get(), osg::StateAttribute::ON);
|
||||
stateset->addUniform(tf_sampler.get());
|
||||
stateset->addUniform(new osg::Uniform("tfTexture",1));
|
||||
stateset->addUniform(new osg::Uniform("tfOffset",tfOffset));
|
||||
stateset->addUniform(new osg::Uniform("tfScale",tfScale));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float tfScale;\n"
|
||||
"uniform float tfOffset;\n"
|
||||
"\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
@@ -83,7 +87,7 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
||||
" while(num_iterations>0.0)\n"
|
||||
" {\n"
|
||||
" float v = texture3D( baseTexture, texcoord).a;\n"
|
||||
" float v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n"
|
||||
" vec4 color = texture1D( tfTexture, v);\n"
|
||||
"\n"
|
||||
" float a = v;\n"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float tfScale;\n"
|
||||
"uniform float tfOffset;\n"
|
||||
"\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
@@ -76,7 +80,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
||||
" while(num_iterations>0.0)\n"
|
||||
" {\n"
|
||||
" float v = texture3D( baseTexture, texcoord).a;\n"
|
||||
" float v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n"
|
||||
" vec4 color = texture1D( tfTexture, v);\n"
|
||||
"\n"
|
||||
" float r = color[3]*TransparencyValue;\n"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float tfScale;\n"
|
||||
"uniform float tfOffset;\n"
|
||||
"\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float IsoSurfaceValue;\n"
|
||||
@@ -91,7 +95,7 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" float r = (IsoSurfaceValue-v)/(previousV-v);\n"
|
||||
" texcoord = texcoord - r*deltaTexCoord;\n"
|
||||
"\n"
|
||||
" v = texture3D( baseTexture, texcoord).a;\n"
|
||||
" v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n"
|
||||
" vec4 color = texture1D( tfTexture, v);\n"
|
||||
"\n"
|
||||
" float px = texture3D( baseTexture, texcoord + deltaX).a;\n"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float tfScale;\n"
|
||||
"uniform float tfOffset;\n"
|
||||
"\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
@@ -73,7 +77,7 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
||||
" while(num_iterations>0.0)\n"
|
||||
" {\n"
|
||||
" float v = texture3D( baseTexture, texcoord).s;\n"
|
||||
" float v = texture3D( baseTexture, texcoord).s * tfScale + tfOffset;\n"
|
||||
" vec4 color = texture1D( tfTexture, v);\n"
|
||||
" if (fragColor.w<color.w)\n"
|
||||
" {\n"
|
||||
|
||||
Reference in New Issue
Block a user