Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added SampleRatioWhenMoving property and support to new osgVolume::Mu…

…ltipassTechnique.
  • Loading branch information...
commit f9ea722616e2c0689c6603db92420346d49cc3a7 1 parent 6d5c0df
Robert OSFIELD authored
View
17 examples/osgvolume/osgvolume.cpp
@@ -664,6 +664,9 @@ int main( int argc, char **argv )
double sampleDensityWhenMoving = 0.0;
while(arguments.read("--sdwm", sampleDensityWhenMoving)) {}
+ double sampleRatioWhenMoving = 0.0;
+ while(arguments.read("--srwm", sampleRatioWhenMoving)) {}
+
while(arguments.read("--lod")) { sampleDensityWhenMoving = 0.02; }
double sequenceLength = 10.0;
@@ -1075,6 +1078,7 @@ int main( int argc, char **argv )
// use SampleRatio in place of SampleDensity
osgVolume::SampleRatioProperty* sr = new osgVolume::SampleRatioProperty(1.0f);
+ osgVolume::SampleRatioWhenMovingProperty* srwm = sampleRatioWhenMoving!=0.0 ? new osgVolume::SampleRatioWhenMovingProperty(sampleRatioWhenMoving) : 0;
osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0);
osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0;
@@ -1083,11 +1087,18 @@ int main( int argc, char **argv )
// Standard
osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty;
cp->addProperty(ap);
- if (useMultipass) cp->addProperty(sr);
- else cp->addProperty(sd);
+ if (useMultipass)
+ {
+ cp->addProperty(sr);
+ if (srwm) cp->addProperty(srwm);
+ }
+ else
+ {
+ cp->addProperty(sd);
+ if (sdwm) cp->addProperty(sdwm);
+ }
cp->addProperty(tp);
- if (sdwm) cp->addProperty(sdwm);
if (tfp)
{
OSG_NOTICE<<"Adding TransferFunction"<<std::endl;
View
24 include/osgVolume/Property
@@ -35,6 +35,7 @@ class MaximumIntensityProjectionProperty;
class LightingProperty;
class AlphaFuncProperty;
class SampleRatioProperty;
+class SampleRatioWhenMovingProperty;
class SampleDensityProperty;
class SampleDensityWhenMovingProperty;
class TransparencyProperty;
@@ -57,6 +58,7 @@ class OSGVOLUME_EXPORT PropertyVisitor
virtual void apply(MaximumIntensityProjectionProperty&) {}
virtual void apply(LightingProperty&) {}
virtual void apply(SampleRatioProperty&) {}
+ virtual void apply(SampleRatioWhenMovingProperty&) {}
virtual void apply(SampleDensityProperty&) {}
virtual void apply(SampleDensityWhenMovingProperty&) {}
virtual void apply(TransparencyProperty&) {}
@@ -329,7 +331,7 @@ class OSGVOLUME_EXPORT SampleDensityWhenMovingProperty : public ScalarProperty
virtual ~SampleDensityWhenMovingProperty() {}
};
-/** Sample density to use when the volume is static relative to the eye point or when moving if no SampleDensityWhenMovingProperty is assigned.*/
+/** Sample ratioto use when the volume is static relative to the eye point or when moving if no SampleRatioWhenMovingProperty is assigned.*/
class OSGVOLUME_EXPORT SampleRatioProperty : public ScalarProperty
{
public:
@@ -347,6 +349,24 @@ class OSGVOLUME_EXPORT SampleRatioProperty : public ScalarProperty
virtual ~SampleRatioProperty() {}
};
+/** Sample density to use when the volume is moving relative to the eye point.*/
+class OSGVOLUME_EXPORT SampleRatioWhenMovingProperty : public ScalarProperty
+{
+ public:
+
+ SampleRatioWhenMovingProperty(float value=1.0f);
+
+ SampleRatioWhenMovingProperty(const SampleRatioWhenMovingProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
+
+ META_Object(osgVolume, SampleRatioWhenMovingProperty);
+
+ virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
+
+ protected:
+
+ virtual ~SampleRatioWhenMovingProperty() {}
+};
+
class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty
{
@@ -382,6 +402,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
virtual void apply(SampleDensityProperty& sdp);
virtual void apply(SampleDensityWhenMovingProperty& sdp);
virtual void apply(SampleRatioProperty& sdp);
+ virtual void apply(SampleRatioWhenMovingProperty& sdp);
virtual void apply(TransparencyProperty& tp);
osg::ref_ptr<TransferFunctionProperty> _tfProperty;
@@ -392,6 +413,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
osg::ref_ptr<SampleDensityProperty> _sampleDensityProperty;
osg::ref_ptr<SampleDensityWhenMovingProperty> _sampleDensityWhenMovingProperty;
osg::ref_ptr<SampleRatioProperty> _sampleRatioProperty;
+ osg::ref_ptr<SampleRatioWhenMovingProperty> _sampleRatioWhenMovingProperty;
osg::ref_ptr<TransparencyProperty> _transparencyProperty;
};
View
5 include/osgVolume/RayTracedTechnique
@@ -47,11 +47,6 @@ class OSGVOLUME_EXPORT RayTracedTechnique : public VolumeTechnique
osg::ref_ptr<osg::MatrixTransform> _transform;
- typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;
-
- OpenThreads::Mutex _mutex;
- ModelViewMatrixMap _modelViewMatrixMap;
-
osg::ref_ptr<osg::StateSet> _whenMovingStateSet;
};
View
5 include/osgVolume/VolumeTechnique
@@ -43,6 +43,8 @@ class OSGVOLUME_EXPORT VolumeTechnique : public osg::Object
virtual void update(osgUtil::UpdateVisitor* nv);
+ virtual bool isMoving(osgUtil::CullVisitor* nv);
+
virtual void cull(osgUtil::CullVisitor* nv);
/** Clean scene graph from any terrain technique specific nodes.*/
@@ -61,6 +63,9 @@ class OSGVOLUME_EXPORT VolumeTechnique : public osg::Object
VolumeTile* _volumeTile;
+ typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;
+ OpenThreads::Mutex _mutex;
+ ModelViewMatrixMap _modelViewMatrixMap;
};
}
View
20 src/osgVolume/MultipassTechnique.cpp
@@ -419,6 +419,12 @@ void MultipassTechnique::init()
}
+ if (cpv._sampleRatioWhenMovingProperty.valid())
+ {
+ _whenMovingStateSet = new osg::StateSet;
+ _whenMovingStateSet->addUniform(cpv._sampleRatioWhenMovingProperty->getUniform(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
+ }
+
}
void MultipassTechnique::update(osgUtil::UpdateVisitor* /*uv*/)
@@ -435,8 +441,18 @@ void MultipassTechnique::cull(osgUtil::CullVisitor* cv)
if (postTraversal)
{
- // OSG_NOTICE<<" OK need to handle postTraversal"<<std::endl;
- _transform->accept(*cv);
+ if (_whenMovingStateSet.valid() && isMoving(cv))
+ {
+ OSG_NOTICE<<"Using MovingStateSet"<<std::endl;
+ cv->pushStateSet(_whenMovingStateSet.get());
+ _transform->accept(*cv);
+ cv->popStateSet();
+ }
+ else
+ {
+ OSG_NOTICE<<"NOT using MovingStateSet"<<std::endl;
+ _transform->accept(*cv);
+ }
}
else
{
View
22 src/osgVolume/Property.cpp
@@ -207,6 +207,20 @@ SampleRatioProperty::SampleRatioProperty(const SampleRatioProperty& srp,const os
{
}
+/////////////////////////////////////////////////////////////////////////////
+//
+// SampleRatioWhenMovingProperty
+//
+SampleRatioWhenMovingProperty::SampleRatioWhenMovingProperty(float value):
+ ScalarProperty("SampleRatioValue",value)
+{
+}
+
+SampleRatioWhenMovingProperty::SampleRatioWhenMovingProperty(const SampleRatioWhenMovingProperty& isp,const osg::CopyOp& copyop):
+ ScalarProperty(isp, copyop)
+{
+}
+
/////////////////////////////////////////////////////////////////////////////
@@ -278,6 +292,7 @@ void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty =
void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; }
void CollectPropertiesVisitor::apply(SampleDensityWhenMovingProperty& sdp) { _sampleDensityWhenMovingProperty = &sdp; }
void CollectPropertiesVisitor::apply(SampleRatioProperty& srp) { _sampleRatioProperty = &srp; }
+void CollectPropertiesVisitor::apply(SampleRatioWhenMovingProperty& srp) { _sampleRatioWhenMovingProperty = &srp; }
void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; }
@@ -449,6 +464,13 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::
OSG_NOTICE<<"Setting sample ratio to "<<sampleRatio<<std::endl;
cpv._sampleRatioProperty->setValue(sampleRatio);
}
+
+ if (_updateSampleDensity && cpv._sampleRatioWhenMovingProperty.valid())
+ {
+ float sampleRatio = v2*4;
+ OSG_NOTICE<<"Setting sample ratio to "<<sampleRatio<<std::endl;
+ cpv._sampleRatioWhenMovingProperty->setValue(sampleRatio);
+ }
}
View
33 src/osgVolume/RayTracedTechnique.cpp
@@ -498,36 +498,11 @@ void RayTracedTechnique::cull(osgUtil::CullVisitor* cv)
{
if (!_transform.valid()) return;
- if (_whenMovingStateSet.valid())
+ if (_whenMovingStateSet.valid() && isMoving(cv))
{
- bool moving = false;
- {
- OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
- ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv->getIdentifier());
- if (itr!=_modelViewMatrixMap.end())
- {
- osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
- osg::Matrix& previousModelViewMatrix = itr->second;
- moving = (newModelViewMatrix != previousModelViewMatrix);
-
- previousModelViewMatrix = newModelViewMatrix;
- }
- else
- {
- _modelViewMatrixMap[cv->getIdentifier()] = *(cv->getModelViewMatrix());
- }
- }
-
- if (moving)
- {
- cv->pushStateSet(_whenMovingStateSet.get());
- _transform->accept(*cv);
- cv->popStateSet();
- }
- else
- {
- _transform->accept(*cv);
- }
+ cv->pushStateSet(_whenMovingStateSet.get());
+ _transform->accept(*cv);
+ cv->popStateSet();
}
else
{
View
24 src/osgVolume/VolumeTechnique.cpp
@@ -86,3 +86,27 @@ void VolumeTechnique::traverse(osg::NodeVisitor& nv)
// otherwise fallback to the Group::traverse()
_volumeTile->osg::Group::traverse(nv);
}
+
+bool VolumeTechnique::isMoving(osgUtil::CullVisitor* cv)
+{
+ bool moving = false;
+
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
+
+ OSG_NOTICE<<"cv="<<cv<<", cv->getIdentifier()="<<cv->getIdentifier()<<std::endl;
+
+ ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv->getIdentifier());
+ if (itr!=_modelViewMatrixMap.end())
+ {
+ osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
+ osg::Matrix& previousModelViewMatrix = itr->second;
+ moving = (newModelViewMatrix != previousModelViewMatrix);
+
+ previousModelViewMatrix = newModelViewMatrix;
+ }
+ else
+ {
+ _modelViewMatrixMap[cv->getIdentifier()] = *(cv->getModelViewMatrix());
+ }
+ return moving;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.