Introduce osgVolume::PropertVisitor, and IsoSurface, MaximumImageProjection, Ligting and AlphaFunc Properties
This commit is contained in:
@@ -2309,6 +2309,23 @@ int main( int argc, char **argv )
|
||||
|
||||
if (useShader)
|
||||
{
|
||||
switch(shadingModel)
|
||||
{
|
||||
case(Standard):
|
||||
break;
|
||||
case(Light):
|
||||
layer->addProperty(new osgVolume::LightingProperty);
|
||||
break;
|
||||
case(Isosurface):
|
||||
layer->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc));
|
||||
break;
|
||||
case(MaximumIntensityProjection):
|
||||
layer->addProperty(new osgVolume::MaximumIntensityProjectionProperty);
|
||||
break;
|
||||
}
|
||||
|
||||
layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc));
|
||||
|
||||
tile->setVolumeTechnique(new osgVolume::ShaderTechnique);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -73,6 +73,9 @@ class OSGVOLUME_EXPORT Layer : public osg::Object
|
||||
/** Get the const Property that informs the VolumeTechnique how this layer should be rendered.*/
|
||||
const Property* getProperty() const { return _property.get(); }
|
||||
|
||||
/** Add a property, automatically creating a CompositePorperty if one isn't already assigned.*/
|
||||
void addProperty(Property* property);
|
||||
|
||||
|
||||
/** increment the modified count."*/
|
||||
virtual void dirty() {};
|
||||
|
||||
@@ -15,11 +15,39 @@
|
||||
#define OSGVOLUME_PROPERTY 1
|
||||
|
||||
#include <osg/TransferFunction>
|
||||
#include <osg/Uniform>
|
||||
|
||||
#include <osgVolume/Export>
|
||||
|
||||
namespace osgVolume {
|
||||
|
||||
// forward decarle
|
||||
class Property;
|
||||
class CompositeProperty;
|
||||
class TransferFunctionProperty;
|
||||
class ScalarProperty;
|
||||
class IsoSurfaceProperty;
|
||||
class MaximumIntensityProjectionProperty;
|
||||
class LightingProperty;
|
||||
class AlphaFuncProperty;
|
||||
|
||||
class PropertyVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
PropertyVisitor() {}
|
||||
virtual ~PropertyVisitor() {}
|
||||
|
||||
virtual void apply(Property&) {}
|
||||
virtual void apply(CompositeProperty&) {}
|
||||
virtual void apply(TransferFunctionProperty&) {}
|
||||
virtual void apply(ScalarProperty&) {}
|
||||
virtual void apply(IsoSurfaceProperty&) {}
|
||||
virtual void apply(AlphaFuncProperty&) {}
|
||||
virtual void apply(MaximumIntensityProjectionProperty&) {}
|
||||
virtual void apply(LightingProperty&) {}
|
||||
};
|
||||
|
||||
class OSGVOLUME_EXPORT Property : public osg::Object
|
||||
{
|
||||
public:
|
||||
@@ -31,6 +59,8 @@ class OSGVOLUME_EXPORT Property : public osg::Object
|
||||
|
||||
META_Object(osgVolume, Property);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Property();
|
||||
@@ -47,6 +77,8 @@ class OSGVOLUME_EXPORT CompositeProperty : public Property
|
||||
|
||||
META_Object(osgVolume, CompositeProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
void clear();
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Property> > Properties;
|
||||
@@ -78,10 +110,21 @@ class OSGVOLUME_EXPORT TransferFunctionProperty : public Property
|
||||
TransferFunctionProperty(osg::TransferFunction* tf = 0);
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
TransferFunctionProperty(const TransferFunctionProperty& tfProperty,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
TransferFunctionProperty(const TransferFunctionProperty& tfp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, TransferFunctionProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
/** Set the transfer function.*/
|
||||
void setTransferFunction(osg::TransferFunction* tf) { _tf = tf; }
|
||||
|
||||
/** Get the transfer function.*/
|
||||
osg::TransferFunction* getTransferFunction() { return _tf.get(); }
|
||||
|
||||
/** Get the const transfer function.*/
|
||||
const osg::TransferFunction* getTransferFunction() const { return _tf.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TransferFunctionProperty() {}
|
||||
@@ -90,6 +133,111 @@ class OSGVOLUME_EXPORT TransferFunctionProperty : public Property
|
||||
};
|
||||
|
||||
|
||||
|
||||
class OSGVOLUME_EXPORT ScalarProperty : public Property
|
||||
{
|
||||
public:
|
||||
|
||||
ScalarProperty();
|
||||
|
||||
ScalarProperty(const std::string& scaleName, float value);
|
||||
|
||||
ScalarProperty(const ScalarProperty& scalarProperty,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, ScalarProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
/** Set the value.*/
|
||||
void setValue(float v) { _uniform->set(v); }
|
||||
|
||||
/** Get the value.*/
|
||||
float getValue() const { float v; _uniform->get(v); return v; }
|
||||
|
||||
/** Get the underlying uniform.*/
|
||||
osg::Uniform* getUniform() { return _uniform.get(); }
|
||||
|
||||
/** Get the underlying uniform.*/
|
||||
const osg::Uniform* getUniform() const { return _uniform.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ScalarProperty() {}
|
||||
|
||||
osg::ref_ptr<osg::Uniform> _uniform;
|
||||
};
|
||||
|
||||
|
||||
class OSGVOLUME_EXPORT IsoSurfaceProperty : public ScalarProperty
|
||||
{
|
||||
public:
|
||||
|
||||
IsoSurfaceProperty(float value=1.0);
|
||||
|
||||
IsoSurfaceProperty(const IsoSurfaceProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, IsoSurfaceProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~IsoSurfaceProperty() {}
|
||||
};
|
||||
|
||||
class OSGVOLUME_EXPORT AlphaFuncProperty : public ScalarProperty
|
||||
{
|
||||
public:
|
||||
|
||||
AlphaFuncProperty(float value=1.0);
|
||||
|
||||
AlphaFuncProperty(const AlphaFuncProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, AlphaFuncProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~AlphaFuncProperty() {}
|
||||
};
|
||||
|
||||
class OSGVOLUME_EXPORT MaximumIntensityProjectionProperty : public Property
|
||||
{
|
||||
public:
|
||||
|
||||
MaximumIntensityProjectionProperty();
|
||||
|
||||
MaximumIntensityProjectionProperty(const MaximumIntensityProjectionProperty& mipp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, MaximumIntensityProjectionProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~MaximumIntensityProjectionProperty() {}
|
||||
};
|
||||
|
||||
|
||||
class OSGVOLUME_EXPORT LightingProperty : public Property
|
||||
{
|
||||
public:
|
||||
|
||||
LightingProperty();
|
||||
|
||||
LightingProperty(const LightingProperty& mipp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, LightingProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~LightingProperty() {}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -117,16 +117,17 @@ class OSGVOLUME_EXPORT VolumeTile : public osg::Group
|
||||
|
||||
void setLayer(Layer* layer) { _layer = layer; }
|
||||
Layer* getLayer() { return _layer.get(); }
|
||||
const Layer* getLayer() const { return _layer.get(); }
|
||||
const Layer* getLayer() const { return _layer.get(); }
|
||||
|
||||
|
||||
/** Set the VolumeTechnique*/
|
||||
|
||||
/** Set the VolumeTechnique that will be used to render this tile. */
|
||||
void setVolumeTechnique(VolumeTechnique* VolumeTechnique);
|
||||
|
||||
/** Get the VolumeTechnique*/
|
||||
/** Get the VolumeTechnique that will be used to render this tile. */
|
||||
VolumeTechnique* getVolumeTechnique() { return _volumeTechnique.get(); }
|
||||
|
||||
/** Get the const VolumeTechnique*/
|
||||
/** Get the const VolumeTechnique that will be used to render this tile. */
|
||||
const VolumeTechnique* getVolumeTechnique() const { return _volumeTechnique.get(); }
|
||||
|
||||
|
||||
|
||||
@@ -43,13 +43,36 @@ osg::BoundingSphere Layer::computeBound() const
|
||||
osg::Vec3d left, right;
|
||||
getLocator()->computeLocalBounds(left, right);
|
||||
|
||||
osg::notify(osg::NOTICE)<<"left = "<<left<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"right = "<<right<<std::endl;
|
||||
//osg::notify(osg::NOTICE)<<"left = "<<left<<std::endl;
|
||||
//osg::notify(osg::NOTICE)<<"right = "<<right<<std::endl;
|
||||
|
||||
return osg::BoundingSphere((left+right)*0.5, (right-left).length()*0.5);
|
||||
}
|
||||
|
||||
|
||||
void Layer::addProperty(Property* property)
|
||||
{
|
||||
if (!property) return;
|
||||
|
||||
if (!_property)
|
||||
{
|
||||
_property = property;
|
||||
return;
|
||||
}
|
||||
|
||||
CompositeProperty* cp = dynamic_cast<CompositeProperty*>(_property.get());
|
||||
if (cp)
|
||||
{
|
||||
cp->addProperty(property);
|
||||
}
|
||||
else
|
||||
{
|
||||
cp = new CompositeProperty;
|
||||
cp->addProperty(property);
|
||||
_property = cp;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ImageLayer
|
||||
|
||||
@@ -36,7 +36,7 @@ CompositeProperty::CompositeProperty()
|
||||
{
|
||||
}
|
||||
|
||||
CompositeProperty::CompositeProperty(const CompositeProperty& compositeProperty,const osg::CopyOp& copyop):
|
||||
CompositeProperty::CompositeProperty(const CompositeProperty& compositeProperty, const osg::CopyOp& copyop):
|
||||
Property(compositeProperty,copyop)
|
||||
{
|
||||
}
|
||||
@@ -56,8 +56,85 @@ TransferFunctionProperty::TransferFunctionProperty(osg::TransferFunction* tf):
|
||||
{
|
||||
}
|
||||
|
||||
TransferFunctionProperty::TransferFunctionProperty(const TransferFunctionProperty& tfp,const osg::CopyOp& copyop):
|
||||
TransferFunctionProperty::TransferFunctionProperty(const TransferFunctionProperty& tfp, const osg::CopyOp& copyop):
|
||||
Property(tfp,copyop),
|
||||
_tf(tfp._tf)
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ScalarProperty
|
||||
//
|
||||
ScalarProperty::ScalarProperty()
|
||||
{
|
||||
_uniform = new osg::Uniform;
|
||||
}
|
||||
|
||||
ScalarProperty::ScalarProperty(const std::string& scalarName, float value)
|
||||
{
|
||||
setName(scalarName);
|
||||
_uniform = new osg::Uniform(scalarName.c_str(), value);
|
||||
}
|
||||
|
||||
ScalarProperty::ScalarProperty(const ScalarProperty& sp, const osg::CopyOp& copyop):
|
||||
Property(sp,copyop)
|
||||
{
|
||||
_uniform = new osg::Uniform(sp._uniform->getName().c_str(), getValue());
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IsoSurfaceProperty
|
||||
//
|
||||
IsoSurfaceProperty::IsoSurfaceProperty(float value):
|
||||
ScalarProperty("IsoSurfaceValue",value)
|
||||
{
|
||||
}
|
||||
|
||||
IsoSurfaceProperty::IsoSurfaceProperty(const IsoSurfaceProperty& isp,const osg::CopyOp& copyop):
|
||||
ScalarProperty(isp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// AlphaFuncProperty
|
||||
//
|
||||
AlphaFuncProperty::AlphaFuncProperty(float value):
|
||||
ScalarProperty("AlphaFuncValue",value)
|
||||
{
|
||||
}
|
||||
|
||||
AlphaFuncProperty::AlphaFuncProperty(const AlphaFuncProperty& afp,const osg::CopyOp& copyop):
|
||||
ScalarProperty(afp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MaximumIntensityProjectionProperty
|
||||
//
|
||||
MaximumIntensityProjectionProperty::MaximumIntensityProjectionProperty()
|
||||
{
|
||||
}
|
||||
|
||||
MaximumIntensityProjectionProperty::MaximumIntensityProjectionProperty(const MaximumIntensityProjectionProperty& isp,const osg::CopyOp& copyop):
|
||||
Property(isp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// LightingProperty
|
||||
//
|
||||
LightingProperty::LightingProperty()
|
||||
{
|
||||
}
|
||||
|
||||
LightingProperty::LightingProperty(const LightingProperty& isp,const osg::CopyOp& copyop):
|
||||
Property(isp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,6 +49,36 @@ enum ShadingModel
|
||||
MaximumIntensityProjection
|
||||
};
|
||||
|
||||
class CollectPropertiesVisitor : public osgVolume::PropertyVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
CollectPropertiesVisitor() {}
|
||||
|
||||
virtual void apply(Property&) {}
|
||||
|
||||
virtual void apply(CompositeProperty& cp)
|
||||
{
|
||||
for(unsigned int i=0; i<cp.getNumProperties(); ++i)
|
||||
{
|
||||
cp.getProperty(i)->accept(*this);
|
||||
}
|
||||
}
|
||||
virtual void apply(TransferFunctionProperty& tf) { _tfProperty = &tf; }
|
||||
virtual void apply(ScalarProperty&) {}
|
||||
virtual void apply(IsoSurfaceProperty& iso) { _isoProperty = &iso; }
|
||||
virtual void apply(AlphaFuncProperty& af) { _afProperty = ⁡ }
|
||||
virtual void apply(MaximumIntensityProjectionProperty& mip) { _mipProperty = &mip; }
|
||||
virtual void apply(LightingProperty& lp) { _lightingProperty = &lp; }
|
||||
|
||||
osg::ref_ptr<TransferFunctionProperty> _tfProperty;
|
||||
osg::ref_ptr<IsoSurfaceProperty> _isoProperty;
|
||||
osg::ref_ptr<AlphaFuncProperty> _afProperty;
|
||||
osg::ref_ptr<MaximumIntensityProjectionProperty> _mipProperty;
|
||||
osg::ref_ptr<LightingProperty> _lightingProperty;
|
||||
|
||||
};
|
||||
|
||||
void ShaderTechnique::init()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"ShaderTechnique::init()"<<std::endl;
|
||||
@@ -66,6 +96,41 @@ void ShaderTechnique::init()
|
||||
|
||||
image_3d = _volumeTile->getLayer()->getImage();
|
||||
|
||||
CollectPropertiesVisitor cpv;
|
||||
if (_volumeTile->getLayer()->getProperty())
|
||||
{
|
||||
_volumeTile->getLayer()->getProperty()->accept(cpv);
|
||||
}
|
||||
|
||||
if (cpv._isoProperty.valid())
|
||||
{
|
||||
shadingModel = Isosurface;
|
||||
alphaFuncValue = cpv._isoProperty->getValue();
|
||||
}
|
||||
else if (cpv._mipProperty.valid())
|
||||
{
|
||||
shadingModel = MaximumIntensityProjection;
|
||||
}
|
||||
else if (cpv._lightingProperty.valid())
|
||||
{
|
||||
shadingModel = Light;
|
||||
}
|
||||
else
|
||||
{
|
||||
shadingModel = Standard;
|
||||
}
|
||||
|
||||
if (cpv._tfProperty.valid())
|
||||
{
|
||||
tf = dynamic_cast<osg::TransferFunction1D*>(cpv._tfProperty->getTransferFunction());
|
||||
}
|
||||
|
||||
if (cpv._afProperty.valid())
|
||||
{
|
||||
alphaFuncValue = cpv._afProperty->getValue();
|
||||
}
|
||||
|
||||
|
||||
if (_volumeTile->getLayer() && !masterLocator)
|
||||
{
|
||||
masterLocator = _volumeTile->getLayer()->getLocator();
|
||||
|
||||
@@ -158,7 +158,26 @@ void VolumeTile::setDirty(bool dirty)
|
||||
|
||||
osg::BoundingSphere VolumeTile::computeBound() const
|
||||
{
|
||||
if (_layer.valid()) return _layer->computeBound();
|
||||
const Locator* masterLocator = getLocator();
|
||||
if (_layer.valid() && !masterLocator)
|
||||
{
|
||||
masterLocator = _layer->getLocator();
|
||||
}
|
||||
|
||||
return osg::BoundingSphere();
|
||||
if (masterLocator)
|
||||
{
|
||||
osg::Vec3d left, right;
|
||||
masterLocator->computeLocalBounds(left, right);
|
||||
|
||||
return osg::BoundingSphere((left+right)*0.5, (right-left).length()*0.5);
|
||||
}
|
||||
else if (_layer.valid())
|
||||
{
|
||||
// we have a layer but no Locator defined so will assume a Identity Locator
|
||||
return osg::BoundingSphere( osg::Vec3(0.5,0.5,0.5), 0.867);
|
||||
}
|
||||
else
|
||||
{
|
||||
return osg::BoundingSphere();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user