Addd ExteriorTransparencyFactorProperty for support of upcomming functionality of rendering a cube volume with a hull volume inside it.

This commit is contained in:
Robert Osfield
2014-03-18 18:14:15 +00:00
parent ed724a730e
commit d7944b6ca9
6 changed files with 83 additions and 1 deletions

View File

@@ -1454,6 +1454,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
}
if (getProperty(cur, "alpha", volumeData.alphaValue)) {}
if (getProperty(cur, "exteriorTransparencyFactor", volumeData.exteriorTransparencyFactorValue) || getProperty(cur, "etf", volumeData.exteriorTransparencyFactorValue)) {}
if (getProperty(cur, "cutoff", volumeData.cutoffValue)) {}
if (getProperty(cur, "region", volumeData.region)) {}
if (getProperty(cur, "sampleDensity", volumeData.sampleDensityValue)) {}

View File

@@ -2737,6 +2737,13 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
osg::ref_ptr<osgVolume::TransparencyProperty> tp = new osgVolume::TransparencyProperty(1.0f);
setUpVolumeScalarProperty(tile.get(), tp.get(), volumeData.alphaValue);
osg::ref_ptr<osgVolume::ExteriorTransparencyFactorProperty> etfp;
if (!volumeData.exteriorTransparencyFactorValue.empty())
{
etfp = new osgVolume::ExteriorTransparencyFactorProperty(0.0f);
setUpVolumeScalarProperty(tile.get(), etfp.get(), volumeData.exteriorTransparencyFactorValue);
}
osg::ref_ptr<osgVolume::SampleDensityProperty> sd = new osgVolume::SampleDensityProperty(0.005);
setUpVolumeScalarProperty(tile.get(), sd.get(), volumeData.sampleDensityValue);
@@ -2770,6 +2777,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (sr.valid()) cp->addProperty(sr.get());
if (srm.valid()) cp->addProperty(srm.get());
if (tfp.valid()) cp->addProperty(tfp.get());
if (etfp.valid()) cp->addProperty(etfp.get());
sp->addProperty(cp);
}
@@ -2785,6 +2793,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (sr.valid()) cp->addProperty(sr.get());
if (srm.valid()) cp->addProperty(srm.get());
if (tfp.valid()) cp->addProperty(tfp.get());
if (etfp.valid()) cp->addProperty(etfp.get());
sp->addProperty(cp);
}
@@ -2804,6 +2813,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (sr.valid()) cp->addProperty(sr.get());
if (srm.valid()) cp->addProperty(srm.get());
if (tfp.valid()) cp->addProperty(tfp.get());
if (etfp.valid()) cp->addProperty(etfp.get());
sp->addProperty(cp);
}
@@ -2819,6 +2829,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (sr.valid()) cp->addProperty(sr.get());
if (srm.valid()) cp->addProperty(srm.get());
if (tfp.valid()) cp->addProperty(tfp.get());
if (etfp.valid()) cp->addProperty(etfp.get());
sp->addProperty(cp);
}

View File

@@ -299,6 +299,17 @@ void MultipassTechnique::init()
unsigned int volumeTextureUnit = 3;
bool requiresRenderingOfCubeAndHull = cpv._exteriorTransparencyFactorProperty.valid() && cpv._exteriorTransparencyFactorProperty->getValue()!=0.0f;
if (requiresRenderingOfCubeAndHull)
{
OSG_NOTICE<<"******* We need to set up the rendering of the Cube and Hull, ETF = "<<cpv._exteriorTransparencyFactorProperty->getValue()<<std::endl;
}
else
{
OSG_NOTICE<<"--- We do not need to render Cube and Hull, ETF = "<<std::endl;
}
// set up uniforms
{
stateset->addUniform(new osg::Uniform("colorTexture",0));
@@ -325,6 +336,11 @@ void MultipassTechnique::init()
else
stateset->addUniform(new osg::Uniform("TransparencyValue",1.0f));
if (cpv._exteriorTransparencyFactorProperty.valid())
stateset->addUniform(cpv._exteriorTransparencyFactorProperty->getUniform());
else
stateset->addUniform(new osg::Uniform("ExteriorTransparencyFactorValue",0.0f));
if (cpv._afProperty.valid())
stateset->addUniform(cpv._afProperty->getUniform());
@@ -341,6 +357,7 @@ void MultipassTechnique::init()
{
tf = dynamic_cast<osg::TransferFunction1D*>(cpv._tfProperty->getTransferFunction());
}
}

View File

@@ -238,6 +238,20 @@ TransparencyProperty::TransparencyProperty(const TransparencyProperty& isp,const
{
}
/////////////////////////////////////////////////////////////////////////////
//
// ExteriorTransparencyFactorProperty
//
ExteriorTransparencyFactorProperty::ExteriorTransparencyFactorProperty(float value):
ScalarProperty("ExteriorTransparencyFactorValue",value)
{
}
ExteriorTransparencyFactorProperty::ExteriorTransparencyFactorProperty(const ExteriorTransparencyFactorProperty& etfp,const osg::CopyOp& copyop):
ScalarProperty(etfp, copyop)
{
}
/////////////////////////////////////////////////////////////////////////////
//
// PropertyVisitor
@@ -295,6 +309,7 @@ void CollectPropertiesVisitor::apply(SampleDensityWhenMovingProperty& sdp) { _sa
void CollectPropertiesVisitor::apply(SampleRatioProperty& srp) { _sampleRatioProperty = &srp; }
void CollectPropertiesVisitor::apply(SampleRatioWhenMovingProperty& srp) { _sampleRatioWhenMovingProperty = &srp; }
void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; }
void CollectPropertiesVisitor::apply(ExteriorTransparencyFactorProperty& etfp) { _exteriorTransparencyFactorProperty = &etfp; }
class CycleSwitchVisitor : public osgVolume::PropertyVisitor
@@ -355,6 +370,7 @@ PropertyAdjustmentCallback::PropertyAdjustmentCallback():
_cyleForwardKey('v'),
_cyleBackwardKey('V'),
_transparencyKey('t'),
_exteriorTransparencyFactorKey('T'),
_alphaFuncKey('a'),
_sampleDensityKey('d'),
_updateTransparency(false),
@@ -367,6 +383,7 @@ PropertyAdjustmentCallback::PropertyAdjustmentCallback(const PropertyAdjustmentC
_cyleForwardKey(pac._cyleForwardKey),
_cyleBackwardKey(pac._cyleBackwardKey),
_transparencyKey(pac._transparencyKey),
_exteriorTransparencyFactorKey(pac._exteriorTransparencyFactorKey),
_alphaFuncKey(pac._alphaFuncKey),
_sampleDensityKey(pac._sampleDensityKey),
_updateTransparency(false),
@@ -410,6 +427,7 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::
}
}
else if (ea.getKey()==_transparencyKey) _updateTransparency = passOnUpdates = true;
else if (ea.getKey()==_exteriorTransparencyFactorKey) _updateExteriorTransparencyFactor = passOnUpdates = true;
else if (ea.getKey()==_alphaFuncKey) _updateAlphaCutOff = passOnUpdates = true;
else if (ea.getKey()==_sampleDensityKey) _updateSampleDensity = passOnUpdates = true;
break;
@@ -417,6 +435,7 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::
case(osgGA::GUIEventAdapter::KEYUP):
{
if (ea.getKey()==_transparencyKey) _updateTransparency = false;
else if (ea.getKey()==_exteriorTransparencyFactorKey) _updateExteriorTransparencyFactor = false;
else if (ea.getKey()==_alphaFuncKey) _updateAlphaCutOff = false;
else if (ea.getKey()==_sampleDensityKey) _updateSampleDensity = false;
break;
@@ -447,8 +466,14 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::
if (_updateTransparency && cpv._transparencyProperty.valid())
{
OSG_NOTICE<<"Setting transparency to "<<v2<<std::endl;
cpv._transparencyProperty->setValue((1.0f-v2)*2.0f);
OSG_NOTICE<<"Setting transparency to "<<cpv._transparencyProperty->getValue()<<std::endl;
}
if (_updateExteriorTransparencyFactor && cpv._exteriorTransparencyFactorProperty.valid())
{
cpv._exteriorTransparencyFactorProperty->setValue((1.0f-v));
OSG_NOTICE<<"Setting exterior transparency factor to "<<cpv._exteriorTransparencyFactorProperty->getValue()<<std::endl;
}
if (_updateSampleDensity && cpv._sampleDensityProperty.valid())