Addd ExteriorTransparencyFactorProperty for support of upcomming functionality of rendering a cube volume with a hull volume inside it.
This commit is contained in:
@@ -306,6 +306,7 @@ public:
|
||||
region_in_pixel_coords(false),
|
||||
alphaValue("1.0"),
|
||||
cutoffValue("0.1"),
|
||||
exteriorTransparencyFactorValue(""),
|
||||
sampleDensityValue("0.005"),
|
||||
sampleRatioValue("1.0"),
|
||||
colorSpaceOperation(osg::NO_COLOR_SPACE_OPERATION),
|
||||
@@ -325,6 +326,7 @@ public:
|
||||
bool region_in_pixel_coords;
|
||||
std::string alphaValue;
|
||||
std::string cutoffValue;
|
||||
std::string exteriorTransparencyFactorValue;
|
||||
std::string sampleDensityValue;
|
||||
std::string sampleDensityWhenMovingValue;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ class SampleRatioWhenMovingProperty;
|
||||
class SampleDensityProperty;
|
||||
class SampleDensityWhenMovingProperty;
|
||||
class TransparencyProperty;
|
||||
class ExteriorTransparencyFactorProperty;
|
||||
|
||||
class OSGVOLUME_EXPORT PropertyVisitor
|
||||
{
|
||||
@@ -62,6 +63,7 @@ class OSGVOLUME_EXPORT PropertyVisitor
|
||||
virtual void apply(SampleDensityProperty&) {}
|
||||
virtual void apply(SampleDensityWhenMovingProperty&) {}
|
||||
virtual void apply(TransparencyProperty&) {}
|
||||
virtual void apply(ExteriorTransparencyFactorProperty&) {}
|
||||
|
||||
bool _traverseOnlyActiveChildren;
|
||||
|
||||
@@ -385,6 +387,23 @@ class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty
|
||||
virtual ~TransparencyProperty() {}
|
||||
};
|
||||
|
||||
class OSGVOLUME_EXPORT ExteriorTransparencyFactorProperty : public ScalarProperty
|
||||
{
|
||||
public:
|
||||
|
||||
ExteriorTransparencyFactorProperty(float value=0.0f);
|
||||
|
||||
ExteriorTransparencyFactorProperty(const ExteriorTransparencyFactorProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, ExteriorTransparencyFactorProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ExteriorTransparencyFactorProperty() {}
|
||||
};
|
||||
|
||||
|
||||
class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisitor
|
||||
{
|
||||
@@ -404,6 +423,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
|
||||
virtual void apply(SampleRatioProperty& sdp);
|
||||
virtual void apply(SampleRatioWhenMovingProperty& sdp);
|
||||
virtual void apply(TransparencyProperty& tp);
|
||||
virtual void apply(ExteriorTransparencyFactorProperty& tp);
|
||||
|
||||
osg::ref_ptr<TransferFunctionProperty> _tfProperty;
|
||||
osg::ref_ptr<IsoSurfaceProperty> _isoProperty;
|
||||
@@ -415,6 +435,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
|
||||
osg::ref_ptr<SampleRatioProperty> _sampleRatioProperty;
|
||||
osg::ref_ptr<SampleRatioWhenMovingProperty> _sampleRatioWhenMovingProperty;
|
||||
osg::ref_ptr<TransparencyProperty> _transparencyProperty;
|
||||
osg::ref_ptr<ExteriorTransparencyFactorProperty> _exteriorTransparencyFactorProperty;
|
||||
|
||||
};
|
||||
|
||||
@@ -437,6 +458,9 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle
|
||||
void setKeyEventActivatesTransparencyAdjustment(int key) { _transparencyKey = key; }
|
||||
int getKeyEventActivatesTransparencyAdjustment() const { return _transparencyKey; }
|
||||
|
||||
void setKeyEventActivatesExteriorTransparencyFactorAdjustment(int key) { _exteriorTransparencyFactorKey = key; }
|
||||
int getKeyEventActivatesExteriorTransparencyFactorAdjustment() const { return _exteriorTransparencyFactorKey; }
|
||||
|
||||
void setKeyEventActivatesSampleDensityAdjustment(int key) { _sampleDensityKey = key; }
|
||||
int getKeyEventActivatesSampleDensityAdjustment() const { return _sampleDensityKey; }
|
||||
|
||||
@@ -448,10 +472,12 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle
|
||||
int _cyleForwardKey;
|
||||
int _cyleBackwardKey;
|
||||
int _transparencyKey;
|
||||
int _exteriorTransparencyFactorKey;
|
||||
int _alphaFuncKey;
|
||||
int _sampleDensityKey;
|
||||
|
||||
bool _updateTransparency;
|
||||
bool _updateExteriorTransparencyFactor;
|
||||
bool _updateAlphaCutOff;
|
||||
bool _updateSampleDensity;
|
||||
};
|
||||
|
||||
@@ -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)) {}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user