osgVolume/Layer
Go to the documentation of this file.
/* -*-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_LAYER
#define OSGVOLUME_LAYER 1
#include <osg/Image>
#include <osg/TransferFunction>
#include <osgVolume/Locator>
#include <osgVolume/Property>
namespace osgVolume {
class OSGVOLUME_EXPORT ImageDetails : public osg::Object
{
public:
ImageDetails();
ImageDetails(const ImageDetails&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, ImageDetails);
void setTexelOffset(const osg::Vec4& offset) { _texelOffset = offset; }
const osg::Vec4& getTexelOffset() const { return _texelOffset; }
void setTexelScale(const osg::Vec4& scale) { _texelScale = scale; }
const osg::Vec4& getTexelScale() const { return _texelScale; }
void setMatrix(osg::RefMatrix* matrix) { _matrix = matrix; }
osg::RefMatrix* getMatrix() { return _matrix.get(); }
const osg::RefMatrix* getMatrix() const { return _matrix.get(); }
protected:
osg::Vec4 _texelOffset;
osg::Vec4 _texelScale;
osg::ref_ptr<osg::RefMatrix> _matrix;
};
class OSGVOLUME_EXPORT Layer : public osg::Object
{
public:
Layer();
Layer(const Layer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, Layer);
virtual void setFileName(const std::string& filename) { _filename = filename; }
virtual const std::string& getFileName() const { return _filename; }
void setLocator(Locator* locator) { _locator = locator; }
template<class T> void setLocator(const osg::ref_ptr<T>& locator) { setLocator(locator.get()); }
Locator* getLocator() { return _locator.get(); }
const Locator* getLocator() const { return _locator.get(); }
void setDefaultValue(const osg::Vec4& value) { _defaultValue = value; }
const osg::Vec4& getDefaultValue() const { return _defaultValue; }
void setMinFilter(osg::Texture::FilterMode filter) { _minFilter = filter; }
osg::Texture::FilterMode getMinFilter() const { return _minFilter; }
void setMagFilter(osg::Texture::FilterMode filter) { _magFilter = filter; }
osg::Texture::FilterMode getMagFilter() const { return _magFilter; }
virtual osg::Image* getImage() { return 0; }
virtual const osg::Image* getImage() const { return 0; }
void setProperty(Property* property) { _property = property; }
template<class T> void setProperty(const osg::ref_ptr<T>& p) { setProperty(p.get()); }
Property* getProperty() { return _property.get(); }
const Property* getProperty() const { return _property.get(); }
void addProperty(Property* property);
template<class T> void addProperty(const osg::ref_ptr<T>& p) { addProperty(p.get()); }
virtual bool requiresUpdateTraversal() const { return false; }
virtual void update(osg::NodeVisitor& /*nv*/) {}
virtual void dirty() {};
virtual void setModifiedCount(unsigned int /*value*/) {};
virtual unsigned int getModifiedCount() const { return 0; }
virtual osg::BoundingSphere computeBound() const;
protected:
virtual ~Layer();
std::string _filename;
osg::ref_ptr<Locator> _locator;
osg::Vec4 _defaultValue;
osg::Texture::FilterMode _minFilter;
osg::Texture::FilterMode _magFilter;
osg::ref_ptr<Property> _property;
};
class OSGVOLUME_EXPORT ImageLayer : public Layer
{
public:
ImageLayer(osg::Image* image=0);
ImageLayer(const ImageLayer& imageLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, ImageLayer);
void setFileName(const std::string& filename) { _filename = filename; if (_image.valid()) _image->setFileName(filename); }
virtual const std::string& getFileName() const { return _image.get() ? _image->getFileName() : _filename; }
void setImage(osg::Image* image);
template<class T> void setImage(const osg::ref_ptr<T>& image) { setImage(image.get()); }
virtual osg::Image* getImage() { return _image.get(); }
virtual const osg::Image* getImage() const { return _image.get(); }
void setTexelOffset(const osg::Vec4& offset) { _texelOffset = offset; }
const osg::Vec4& getTexelOffset() const { return _texelOffset; }
void setTexelScale(const osg::Vec4& scale) { _texelScale = scale; }
const osg::Vec4& getTexelScale() const { return _texelScale; }
bool computeMinMax(osg::Vec4& min, osg::Vec4& max);
void offsetAndScaleImage(const osg::Vec4& offset, const osg::Vec4& scale);
void rescaleToZeroToOneRange();
void translateMinToZero();
virtual bool requiresUpdateTraversal() const;
virtual void update(osg::NodeVisitor& /*nv*/);
virtual void dirty();
virtual void setModifiedCount(unsigned int value);
virtual unsigned int getModifiedCount() const;
protected:
virtual ~ImageLayer() {}
osg::Vec4 _texelOffset;
osg::Vec4 _texelScale;
osg::ref_ptr<osg::Image> _image;
};
class OSGVOLUME_EXPORT CompositeLayer : public Layer
{
public:
CompositeLayer();
CompositeLayer(const CompositeLayer& compositeLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, CompositeLayer);
void clear();
void setFileName(unsigned int i, const std::string& filename) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].filename = filename; if (_layers[i].layer.valid()) _layers[i].layer->setFileName(filename); }
const std::string& getFileName(unsigned int i) const { return _layers[i].layer.valid() ? _layers[i].layer->getFileName() : _layers[i].filename; }
void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; }
template<class T> void setLayer(unsigned int i, const osg::ref_ptr<T>& layer) { setLayer(i, layer.get()); }
Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; }
const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; }
void addLayer(Layer* layer) { _layers.push_back(NameLayer(layer->getFileName(),layer)); }
template<class T> void addLayer(const osg::ref_ptr<T>& layer) { addLayer(layer.get()); }
void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); }
unsigned int getNumLayers() const { return _layers.size(); }
bool requiresUpdateTraversal() const;
virtual void update(osg::NodeVisitor& /*nv*/);
protected:
virtual ~CompositeLayer() {}
struct NameLayer
{
NameLayer() {}
NameLayer(const NameLayer& cnl):
filename(cnl.filename),
layer(cnl.layer) {}
NameLayer(const std::string& fn, Layer* l):
filename(fn),
layer(l) {}
NameLayer& operator = (const NameLayer& cnl)
{
if (&cnl==this) return *this;
filename = cnl.filename;
layer = cnl.layer;
return *this;
}
std::string filename;
osg::ref_ptr<Layer> layer;
};
typedef std::vector< NameLayer > Layers;
Layers _layers;
};
extern OSGVOLUME_EXPORT osg::Image* createNormalMapTexture(osg::Image* image_3d);
extern OSGVOLUME_EXPORT osg::Image* applyTransferFunction(osg::Image* image, osg::TransferFunction1D* transferFunction);
}
#endif
Image
Property
TransferFunction
osgVolume::CompositeLayer::setLayer
void setLayer(unsigned int i, Layer *layer)
Definition osgVolume/Layer:227
osgVolume::CompositeLayer::setFileName
void setFileName(unsigned int i, const std::string &filename)
Definition osgVolume/Layer:224
osgVolume::CompositeLayer::CompositeLayer
CompositeLayer(const CompositeLayer &compositeLayer, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgVolume::CompositeLayer::Layers
std::vector< NameLayer > Layers
Definition osgVolume/Layer:276
osgVolume::CompositeLayer::~CompositeLayer
virtual ~CompositeLayer()
Definition osgVolume/Layer:249
osgVolume::CompositeLayer::getFileName
const std::string & getFileName(unsigned int i) const
Definition osgVolume/Layer:225
osgVolume::CompositeLayer::removeLayer
void removeLayer(unsigned int i)
Definition osgVolume/Layer:239
osgVolume::CompositeLayer::requiresUpdateTraversal
bool requiresUpdateTraversal() const
osgVolume::CompositeLayer::getLayer
const Layer * getLayer(unsigned int i) const
Definition osgVolume/Layer:233
osgVolume::CompositeLayer::update
virtual void update(osg::NodeVisitor &)
osgVolume::CompositeLayer::addLayer
void addLayer(const osg::ref_ptr< T > &layer)
Definition osgVolume/Layer:237
osgVolume::CompositeLayer::META_Object
META_Object(osgVolume, CompositeLayer)
osgVolume::CompositeLayer::clear
void clear()
osgVolume::CompositeLayer::addLayer
void addLayer(Layer *layer)
Definition osgVolume/Layer:235
osgVolume::CompositeLayer::CompositeLayer
CompositeLayer()
osgVolume::CompositeLayer::getLayer
Layer * getLayer(unsigned int i)
Definition osgVolume/Layer:231
osgVolume::CompositeLayer::getNumLayers
unsigned int getNumLayers() const
Definition osgVolume/Layer:241
osgVolume::CompositeLayer::_layers
Layers _layers
Definition osgVolume/Layer:278
osgVolume::CompositeLayer::setLayer
void setLayer(unsigned int i, const osg::ref_ptr< T > &layer)
Definition osgVolume/Layer:229
osgVolume::ImageDetails::getTexelScale
const osg::Vec4 & getTexelScale() const
Definition osgVolume/Layer:41
osgVolume::ImageDetails::getTexelOffset
const osg::Vec4 & getTexelOffset() const
Definition osgVolume/Layer:38
osgVolume::ImageDetails::getMatrix
const osg::RefMatrix * getMatrix() const
Definition osgVolume/Layer:45
osgVolume::ImageDetails::META_Object
META_Object(osgVolume, ImageDetails)
osgVolume::ImageDetails::setMatrix
void setMatrix(osg::RefMatrix *matrix)
Definition osgVolume/Layer:43
osgVolume::ImageDetails::_matrix
osg::ref_ptr< osg::RefMatrix > _matrix
Definition osgVolume/Layer:51
osgVolume::ImageDetails::ImageDetails
ImageDetails()
osgVolume::ImageDetails::setTexelScale
void setTexelScale(const osg::Vec4 &scale)
Definition osgVolume/Layer:40
osgVolume::ImageDetails::_texelOffset
osg::Vec4 _texelOffset
Definition osgVolume/Layer:49
osgVolume::ImageDetails::_texelScale
osg::Vec4 _texelScale
Definition osgVolume/Layer:50
osgVolume::ImageDetails::setTexelOffset
void setTexelOffset(const osg::Vec4 &offset)
Definition osgVolume/Layer:37
osgVolume::ImageDetails::getMatrix
osg::RefMatrix * getMatrix()
Definition osgVolume/Layer:44
osgVolume::ImageDetails::ImageDetails
ImageDetails(const ImageDetails &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgVolume::ImageLayer::getTexelOffset
const osg::Vec4 & getTexelOffset() const
Definition osgVolume/Layer:175
osgVolume::ImageLayer::getTexelScale
const osg::Vec4 & getTexelScale() const
Definition osgVolume/Layer:178
osgVolume::ImageLayer::setModifiedCount
virtual void setModifiedCount(unsigned int value)
osgVolume::ImageLayer::ImageLayer
ImageLayer(osg::Image *image=0)
osgVolume::ImageLayer::rescaleToZeroToOneRange
void rescaleToZeroToOneRange()
osgVolume::ImageLayer::dirty
virtual void dirty()
osgVolume::ImageLayer::ImageLayer
ImageLayer(const ImageLayer &imageLayer, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgVolume::ImageLayer::_texelOffset
osg::Vec4 _texelOffset
Definition osgVolume/Layer:205
osgVolume::ImageLayer::META_Object
META_Object(osgVolume, ImageLayer)
osgVolume::ImageLayer::setTexelScale
void setTexelScale(const osg::Vec4 &scale)
Definition osgVolume/Layer:177
osgVolume::ImageLayer::~ImageLayer
virtual ~ImageLayer()
Definition osgVolume/Layer:203
osgVolume::ImageLayer::getModifiedCount
virtual unsigned int getModifiedCount() const
osgVolume::ImageLayer::setImage
void setImage(osg::Image *image)
osgVolume::ImageLayer::requiresUpdateTraversal
virtual bool requiresUpdateTraversal() const
osgVolume::ImageLayer::getImage
virtual const osg::Image * getImage() const
Definition osgVolume/Layer:171
osgVolume::ImageLayer::setTexelOffset
void setTexelOffset(const osg::Vec4 &offset)
Definition osgVolume/Layer:174
osgVolume::ImageLayer::setFileName
void setFileName(const std::string &filename)
Definition osgVolume/Layer:160
osgVolume::ImageLayer::setImage
void setImage(const osg::ref_ptr< T > &image)
Definition osgVolume/Layer:165
osgVolume::ImageLayer::update
virtual void update(osg::NodeVisitor &)
osgVolume::ImageLayer::translateMinToZero
void translateMinToZero()
osgVolume::ImageLayer::getImage
virtual osg::Image * getImage()
Definition osgVolume/Layer:168
osgVolume::ImageLayer::offsetAndScaleImage
void offsetAndScaleImage(const osg::Vec4 &offset, const osg::Vec4 &scale)
osgVolume::ImageLayer::getFileName
virtual const std::string & getFileName() const
Definition osgVolume/Layer:161
osgVolume::ImageLayer::_texelScale
osg::Vec4 _texelScale
Definition osgVolume/Layer:206
osgVolume::ImageLayer::computeMinMax
bool computeMinMax(osg::Vec4 &min, osg::Vec4 &max)
osgVolume::ImageLayer::_image
osg::ref_ptr< osg::Image > _image
Definition osgVolume/Layer:207
osgVolume::Layer::setProperty
void setProperty(Property *property)
Definition osgVolume/Layer:103
osgVolume::Layer::_minFilter
osg::Texture::FilterMode _minFilter
Definition osgVolume/Layer:142
osgVolume::Layer::update
virtual void update(osg::NodeVisitor &)
Definition osgVolume/Layer:122
osgVolume::Layer::getMagFilter
osg::Texture::FilterMode getMagFilter() const
Definition osgVolume/Layer:93
osgVolume::Layer::getProperty
const Property * getProperty() const
Definition osgVolume/Layer:111
osgVolume::Layer::_defaultValue
osg::Vec4 _defaultValue
Definition osgVolume/Layer:141
osgVolume::Layer::setFileName
virtual void setFileName(const std::string &filename)
Definition osgVolume/Layer:68
osgVolume::Layer::getLocator
const Locator * getLocator() const
Definition osgVolume/Layer:78
osgVolume::Layer::requiresUpdateTraversal
virtual bool requiresUpdateTraversal() const
Definition osgVolume/Layer:119
osgVolume::Layer::_magFilter
osg::Texture::FilterMode _magFilter
Definition osgVolume/Layer:143
osgVolume::Layer::setModifiedCount
virtual void setModifiedCount(unsigned int)
Definition osgVolume/Layer:128
osgVolume::Layer::~Layer
virtual ~Layer()
osgVolume::Layer::_locator
osg::ref_ptr< Locator > _locator
Definition osgVolume/Layer:140
osgVolume::Layer::getProperty
Property * getProperty()
Definition osgVolume/Layer:108
osgVolume::Layer::Layer
Layer(const Layer &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgVolume::Layer::_filename
std::string _filename
Definition osgVolume/Layer:139
osgVolume::Layer::computeBound
virtual osg::BoundingSphere computeBound() const
osgVolume::Layer::setDefaultValue
void setDefaultValue(const osg::Vec4 &value)
Definition osgVolume/Layer:80
osgVolume::Layer::setMinFilter
void setMinFilter(osg::Texture::FilterMode filter)
Definition osgVolume/Layer:84
osgVolume::Layer::getFileName
virtual const std::string & getFileName() const
Definition osgVolume/Layer:71
osgVolume::Layer::getLocator
Locator * getLocator()
Definition osgVolume/Layer:77
osgVolume::Layer::setMagFilter
void setMagFilter(osg::Texture::FilterMode filter)
Definition osgVolume/Layer:90
osgVolume::Layer::addProperty
void addProperty(Property *property)
osgVolume::Layer::getImage
virtual const osg::Image * getImage() const
Definition osgVolume/Layer:99
osgVolume::Layer::getImage
virtual osg::Image * getImage()
Definition osgVolume/Layer:96
osgVolume::Layer::Layer
Layer()
osgVolume::Layer::setLocator
void setLocator(Locator *locator)
Definition osgVolume/Layer:73
osgVolume::Layer::getDefaultValue
const osg::Vec4 & getDefaultValue() const
Definition osgVolume/Layer:81
osgVolume::Layer::dirty
virtual void dirty()
Definition osgVolume/Layer:125
osgVolume::Layer::_property
osg::ref_ptr< Property > _property
Definition osgVolume/Layer:145
osgVolume::Layer::getModifiedCount
virtual unsigned int getModifiedCount() const
Definition osgVolume/Layer:131
osgVolume::Layer::addProperty
void addProperty(const osg::ref_ptr< T > &p)
Definition osgVolume/Layer:116
osgVolume::Layer::META_Object
META_Object(osgVolume, Layer)
osgVolume::Layer::setLocator
void setLocator(const osg::ref_ptr< T > &locator)
Definition osgVolume/Layer:75
osgVolume::Layer::getMinFilter
osg::Texture::FilterMode getMinFilter() const
Definition osgVolume/Layer:87
osgVolume::Layer::setProperty
void setProperty(const osg::ref_ptr< T > &p)
Definition osgVolume/Layer:105
osgVolume::Locator
Definition osgVolume/Locator:30
osgVolume::Property
Definition Property:75
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Image
Definition Image:179
osg::NodeVisitor
Definition NodeVisitor:82
osg::Object
Definition Object:61
osg::Texture::FilterMode
FilterMode
Definition Texture:499
osg::TransferFunction1D
Definition TransferFunction:56
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osgVolume
osgVolume::createNormalMapTexture
OSGVOLUME_EXPORT osg::Image * createNormalMapTexture(osg::Image *image_3d)
osgVolume::applyTransferFunction
OSGVOLUME_EXPORT osg::Image * applyTransferFunction(osg::Image *image, osg::TransferFunction1D *transferFunction)
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Vec4
Vec4f Vec4
Definition Vec4:21
osg::RefMatrix
RefMatrixd RefMatrix
Definition Matrix:28
OSGVOLUME_EXPORT
#define OSGVOLUME_EXPORT
Definition osgVolume/Export:39
Locator
osgVolume::CompositeLayer::NameLayer
Definition osgVolume/Layer:252
osgVolume::CompositeLayer::NameLayer::NameLayer
NameLayer(const std::string &fn, Layer *l)
Definition osgVolume/Layer:259
osgVolume::CompositeLayer::NameLayer::NameLayer
NameLayer(const NameLayer &cnl)
Definition osgVolume/Layer:255
osgVolume::CompositeLayer::NameLayer::filename
std::string filename
Definition osgVolume/Layer:272
osgVolume::CompositeLayer::NameLayer::NameLayer
NameLayer()
Definition osgVolume/Layer:253
osgVolume::CompositeLayer::NameLayer::layer
osg::ref_ptr< Layer > layer
Definition osgVolume/Layer:273