OpenSceneGraph/include/osgVolume/Property

269 lines
7.8 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVOLUME_PROPERTY
#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:
Property();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Property(const Property&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, Property);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~Property();
};
class OSGVOLUME_EXPORT CompositeProperty : public Property
{
public:
CompositeProperty();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
CompositeProperty(const CompositeProperty& compositeProperty,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, CompositeProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
void clear();
typedef std::vector< osg::ref_ptr<Property> > Properties;
void setProperty(unsigned int i, Property* property) { if (i>=_properties.size()) _properties.resize(i+1); _properties[i] = property; }
Property* getProperty(unsigned int i) { return i<_properties.size() ? _properties[i].get() : 0; }
const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; }
void addProperty(Property* property) { _properties.push_back(property); }
void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); }
unsigned int getNumProperties() const { return _properties.size(); }
protected:
virtual ~CompositeProperty() {}
Properties _properties;
};
class OSGVOLUME_EXPORT TransferFunctionProperty : public Property
{
public:
TransferFunctionProperty(osg::TransferFunction* tf = 0);
/** Copy constructor using CopyOp to manage deep vs 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() {}
osg::ref_ptr<osg::TransferFunction> _tf;
};
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() {}
};
class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisitor
{
public:
CollectPropertiesVisitor();
virtual void apply(Property&);
virtual void apply(CompositeProperty& cp);
virtual void apply(TransferFunctionProperty& tf);
virtual void apply(ScalarProperty&);
virtual void apply(IsoSurfaceProperty& iso);
virtual void apply(AlphaFuncProperty& af);
virtual void apply(MaximumIntensityProjectionProperty& mip);
virtual void apply(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;
};
}
#endif