Added SampleDensityWhenMovingProperty to control LOD property of osgVolume.

This commit is contained in:
Robert Osfield 2011-03-17 15:37:39 +00:00
parent 79cb22eb06
commit 89eadcfe82
5 changed files with 49 additions and 6 deletions

View File

@ -1576,6 +1576,7 @@ int main( int argc, char **argv )
osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc); osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc);
osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005);
osgVolume::SampleDensityWhenMovingProperty* sdwm = new osgVolume::SampleDensityWhenMovingProperty(0.02);
osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0);
osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0; osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0;
@ -1584,6 +1585,7 @@ int main( int argc, char **argv )
osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty;
cp->addProperty(ap); cp->addProperty(ap);
cp->addProperty(sd); cp->addProperty(sd);
cp->addProperty(sdwm);
cp->addProperty(tp); cp->addProperty(tp);
if (tfp) cp->addProperty(tfp); if (tfp) cp->addProperty(tfp);

View File

@ -35,6 +35,7 @@ class MaximumIntensityProjectionProperty;
class LightingProperty; class LightingProperty;
class AlphaFuncProperty; class AlphaFuncProperty;
class SampleDensityProperty; class SampleDensityProperty;
class SampleDensityWhenMovingProperty;
class TransparencyProperty; class TransparencyProperty;
class OSGVOLUME_EXPORT PropertyVisitor class OSGVOLUME_EXPORT PropertyVisitor
@ -55,6 +56,7 @@ class OSGVOLUME_EXPORT PropertyVisitor
virtual void apply(MaximumIntensityProjectionProperty&) {} virtual void apply(MaximumIntensityProjectionProperty&) {}
virtual void apply(LightingProperty&) {} virtual void apply(LightingProperty&) {}
virtual void apply(SampleDensityProperty&) {} virtual void apply(SampleDensityProperty&) {}
virtual void apply(SampleDensityWhenMovingProperty&) {}
virtual void apply(TransparencyProperty&) {} virtual void apply(TransparencyProperty&) {}
bool _traverseOnlyActiveChildren; bool _traverseOnlyActiveChildren;
@ -289,6 +291,7 @@ class OSGVOLUME_EXPORT LightingProperty : public Property
}; };
/** Sample density to use when the volume is static relative to the eye point or when moving if no SampleDensityWhenMovingProperty is assigned.*/
class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty
{ {
public: public:
@ -306,6 +309,24 @@ class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty
virtual ~SampleDensityProperty() {} virtual ~SampleDensityProperty() {}
}; };
/** Sample density to use when the volume is moving relative to the eye point.*/
class OSGVOLUME_EXPORT SampleDensityWhenMovingProperty : public ScalarProperty
{
public:
SampleDensityWhenMovingProperty(float value=1.0);
SampleDensityWhenMovingProperty(const SampleDensityWhenMovingProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, SampleDensityWhenMovingProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~SampleDensityWhenMovingProperty() {}
};
class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty
{ {
public: public:
@ -338,6 +359,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
virtual void apply(MaximumIntensityProjectionProperty& mip); virtual void apply(MaximumIntensityProjectionProperty& mip);
virtual void apply(LightingProperty& lp); virtual void apply(LightingProperty& lp);
virtual void apply(SampleDensityProperty& sdp); virtual void apply(SampleDensityProperty& sdp);
virtual void apply(SampleDensityWhenMovingProperty& sdp);
virtual void apply(TransparencyProperty& tp); virtual void apply(TransparencyProperty& tp);
osg::ref_ptr<TransferFunctionProperty> _tfProperty; osg::ref_ptr<TransferFunctionProperty> _tfProperty;
@ -346,6 +368,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
osg::ref_ptr<MaximumIntensityProjectionProperty> _mipProperty; osg::ref_ptr<MaximumIntensityProjectionProperty> _mipProperty;
osg::ref_ptr<LightingProperty> _lightingProperty; osg::ref_ptr<LightingProperty> _lightingProperty;
osg::ref_ptr<SampleDensityProperty> _sampleDensityProperty; osg::ref_ptr<SampleDensityProperty> _sampleDensityProperty;
osg::ref_ptr<SampleDensityWhenMovingProperty> _sampleDensityWhenMovingProperty;
osg::ref_ptr<TransparencyProperty> _transparencyProperty; osg::ref_ptr<TransparencyProperty> _transparencyProperty;
}; };

View File

@ -52,7 +52,7 @@ class OSGVOLUME_EXPORT RayTracedTechnique : public VolumeTechnique
OpenThreads::Mutex _mutex; OpenThreads::Mutex _mutex;
ModelViewMatrixMap _modelViewMatrixMap; ModelViewMatrixMap _modelViewMatrixMap;
osg::ref_ptr<osg::StateSet> _lodStateSet; osg::ref_ptr<osg::StateSet> _whenMovingStateSet;
}; };
} }

View File

@ -179,6 +179,21 @@ SampleDensityProperty::SampleDensityProperty(const SampleDensityProperty& isp,co
} }
/////////////////////////////////////////////////////////////////////////////
//
// SampleDensityWhenMovingProperty
//
SampleDensityWhenMovingProperty::SampleDensityWhenMovingProperty(float value):
ScalarProperty("SampleDensityValue",value)
{
}
SampleDensityWhenMovingProperty::SampleDensityWhenMovingProperty(const SampleDensityWhenMovingProperty& isp,const osg::CopyOp& copyop):
ScalarProperty(isp, copyop)
{
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// TransparencyProperty // TransparencyProperty
@ -246,6 +261,7 @@ void CollectPropertiesVisitor::apply(AlphaFuncProperty& af) { _afProperty = &af;
void CollectPropertiesVisitor::apply(MaximumIntensityProjectionProperty& mip) { _mipProperty = &mip; } void CollectPropertiesVisitor::apply(MaximumIntensityProjectionProperty& mip) { _mipProperty = &mip; }
void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty = &lp; } void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty = &lp; }
void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; } void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; }
void CollectPropertiesVisitor::apply(SampleDensityWhenMovingProperty& sdp) { _sampleDensityWhenMovingProperty = &sdp; }
void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; } void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; }

View File

@ -534,9 +534,11 @@ void RayTracedTechnique::init()
} }
_lodStateSet = new osg::StateSet; if (cpv._sampleDensityWhenMovingProperty.valid())
_lodStateSet->addUniform(new osg::Uniform("SampleDensityValue",0.01f), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); {
_whenMovingStateSet = new osg::StateSet;
_whenMovingStateSet->addUniform(cpv._sampleDensityWhenMovingProperty->getUniform(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
}
} }
void RayTracedTechnique::update(osgUtil::UpdateVisitor* uv) void RayTracedTechnique::update(osgUtil::UpdateVisitor* uv)
@ -548,7 +550,7 @@ void RayTracedTechnique::cull(osgUtil::CullVisitor* cv)
{ {
if (!_transform.valid()) return; if (!_transform.valid()) return;
if (_lodStateSet.valid()) if (_whenMovingStateSet.valid())
{ {
bool moving = false; bool moving = false;
{ {
@ -570,7 +572,7 @@ void RayTracedTechnique::cull(osgUtil::CullVisitor* cv)
if (moving) if (moving)
{ {
cv->pushStateSet(_lodStateSet.get()); cv->pushStateSet(_whenMovingStateSet.get());
_transform->accept(*cv); _transform->accept(*cv);
cv->popStateSet(); cv->popStateSet();
} }