Introduce osgVolume::PropertVisitor, and IsoSurface, MaximumImageProjection, Ligting and AlphaFunc Properties
This commit is contained in:
@@ -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