Added SampleRatioWhenMoving property and support to new osgVolume::MultipassTechnique.

This commit is contained in:
Robert Osfield
2013-12-12 09:53:24 +00:00
parent a5c0127a6e
commit 939aa38a2a
8 changed files with 110 additions and 40 deletions

View File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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;
}