OpenSceneGraph 3.6.5
Layer
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGVOLUME_LAYER
15#define OSGVOLUME_LAYER 1
16
17#include <osg/Image>
18#include <osg/TransferFunction>
19
20#include <osgVolume/Locator>
21#include <osgVolume/Property>
22
23namespace osgVolume {
24
27{
28 public:
29
31
34
36
37 void setTexelOffset(const osg::Vec4& offset) { _texelOffset = offset; }
38 const osg::Vec4& getTexelOffset() const { return _texelOffset; }
39
40 void setTexelScale(const osg::Vec4& scale) { _texelScale = scale; }
41 const osg::Vec4& getTexelScale() const { return _texelScale; }
42
43 void setMatrix(osg::RefMatrix* matrix) { _matrix = matrix; }
44 osg::RefMatrix* getMatrix() { return _matrix.get(); }
45 const osg::RefMatrix* getMatrix() const { return _matrix.get(); }
46
47 protected:
48
52
53};
54
57{
58 public:
59
61
64
66
68 virtual void setFileName(const std::string& filename) { _filename = filename; }
69
71 virtual const std::string& getFileName() const { return _filename; }
72
73 void setLocator(Locator* locator) { _locator = locator; }
74
75 template<class T> void setLocator(const osg::ref_ptr<T>& locator) { setLocator(locator.get()); }
76
77 Locator* getLocator() { return _locator.get(); }
78 const Locator* getLocator() const { return _locator.get(); }
79
80 void setDefaultValue(const osg::Vec4& value) { _defaultValue = value; }
81 const osg::Vec4& getDefaultValue() const { return _defaultValue; }
82
85
88
91
94
96 virtual osg::Image* getImage() { return 0; }
97
99 virtual const osg::Image* getImage() const { return 0; }
100
101
103 void setProperty(Property* property) { _property = property; }
104
105 template<class T> void setProperty(const osg::ref_ptr<T>& p) { setProperty(p.get()); }
106
108 Property* getProperty() { return _property.get(); }
109
111 const Property* getProperty() const { return _property.get(); }
112
114 void addProperty(Property* property);
115
116 template<class T> void addProperty(const osg::ref_ptr<T>& p) { addProperty(p.get()); }
117
119 virtual bool requiresUpdateTraversal() const { return false; }
120
122 virtual void update(osg::NodeVisitor& /*nv*/) {}
123
125 virtual void dirty() {};
126
128 virtual void setModifiedCount(unsigned int /*value*/) {};
129
131 virtual unsigned int getModifiedCount() const { return 0; }
132
134
135 protected:
136
137 virtual ~Layer();
138
139 std::string _filename;
144
146
147};
148
150{
151 public:
152
154
157
159
160 void setFileName(const std::string& filename) { _filename = filename; if (_image.valid()) _image->setFileName(filename); }
161 virtual const std::string& getFileName() const { return _image.get() ? _image->getFileName() : _filename; }
162
163 void setImage(osg::Image* image);
164
165 template<class T> void setImage(const osg::ref_ptr<T>& image) { setImage(image.get()); }
166
168 virtual osg::Image* getImage() { return _image.get(); }
169
171 virtual const osg::Image* getImage() const { return _image.get(); }
172
173
174 void setTexelOffset(const osg::Vec4& offset) { _texelOffset = offset; }
175 const osg::Vec4& getTexelOffset() const { return _texelOffset; }
176
177 void setTexelScale(const osg::Vec4& scale) { _texelScale = scale; }
178 const osg::Vec4& getTexelScale() const { return _texelScale; }
179
180
183
185 void offsetAndScaleImage(const osg::Vec4& offset, const osg::Vec4& scale);
186
189
192
193 virtual bool requiresUpdateTraversal() const;
194
195 virtual void update(osg::NodeVisitor& /*nv*/);
196
197 virtual void dirty();
198 virtual void setModifiedCount(unsigned int value);
199 virtual unsigned int getModifiedCount() const;
200
201 protected:
202
203 virtual ~ImageLayer() {}
204
208
209};
210
212{
213 public:
214
216
219
221
222 void clear();
223
224 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); }
225 const std::string& getFileName(unsigned int i) const { return _layers[i].layer.valid() ? _layers[i].layer->getFileName() : _layers[i].filename; }
226
227 void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; }
228
229 template<class T> void setLayer(unsigned int i, const osg::ref_ptr<T>& layer) { setLayer(i, layer.get()); }
230
231 Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; }
232
233 const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; }
234
235 void addLayer(Layer* layer) { _layers.push_back(NameLayer(layer->getFileName(),layer)); }
236
237 template<class T> void addLayer(const osg::ref_ptr<T>& layer) { addLayer(layer.get()); }
238
239 void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); }
240
241 unsigned int getNumLayers() const { return _layers.size(); }
242
244
245 virtual void update(osg::NodeVisitor& /*nv*/);
246
247 protected:
248
249 virtual ~CompositeLayer() {}
250
252 {
254
255 NameLayer(const NameLayer& cnl):
256 filename(cnl.filename),
257 layer(cnl.layer) {}
258
259 NameLayer(const std::string& fn, Layer* l):
260 filename(fn),
261 layer(l) {}
262
263 NameLayer& operator = (const NameLayer& cnl)
264 {
265 if (&cnl==this) return *this;
266
267 filename = cnl.filename;
268 layer = cnl.layer;
269 return *this;
270 }
271
272 std::string filename;
274 };
275
276 typedef std::vector< NameLayer > Layers;
277
279};
280
283
286
287}
288
289#endif
BoundingSphered BoundingSphere
Definition BoundingSphere:308
Vec4f Vec4
Definition Vec4:21
RefMatrixd RefMatrix
Definition Matrix:28
The osgVolume library is a NodeKit that extends the core scene graph to support volume rendering.
OSGVOLUME_EXPORT osg::Image * createNormalMapTexture(osg::Image *image_3d)
Compute a 3d image that represent the normal map of the specified 3d image.
OSGVOLUME_EXPORT osg::Image * applyTransferFunction(osg::Image *image, osg::TransferFunction1D *transferFunction)
Create an image that has a transfer function applied specified Image.
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Image class for encapsulating the storage texture image data.
Definition Image:179
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
FilterMode
Definition Texture:499
1D variant of TransferFunction.
Definition TransferFunction:56
const osg::Vec4 & getTexelScale() const
Definition Layer:41
const osg::Vec4 & getTexelOffset() const
Definition Layer:38
const osg::RefMatrix * getMatrix() const
Definition Layer:45
META_Object(osgVolume, ImageDetails)
void setMatrix(osg::RefMatrix *matrix)
Definition Layer:43
osg::ref_ptr< osg::RefMatrix > _matrix
Definition Layer:51
void setTexelScale(const osg::Vec4 &scale)
Definition Layer:40
osg::Vec4 _texelOffset
Definition Layer:49
osg::Vec4 _texelScale
Definition Layer:50
void setTexelOffset(const osg::Vec4 &offset)
Definition Layer:37
osg::RefMatrix * getMatrix()
Definition Layer:44
ImageDetails(const ImageDetails &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
void setProperty(Property *property)
Set the Property (or Properties via the CompositeProperty) that informs the VolumeTechnique how this ...
Definition Layer:103
osg::Texture::FilterMode _minFilter
Definition Layer:142
virtual void update(osg::NodeVisitor &)
Call update on the Layer.
Definition Layer:122
osg::Texture::FilterMode getMagFilter() const
Get the magnification texture filter to use when do texture associated with this layer.
Definition Layer:93
const Property * getProperty() const
Get the const Property that informs the VolumeTechnique how this layer should be rendered.
Definition Layer:111
osg::Vec4 _defaultValue
Definition Layer:141
virtual void setFileName(const std::string &filename)
Set the file name of the data associated with this layer.
Definition Layer:68
const Locator * getLocator() const
Definition Layer:78
virtual bool requiresUpdateTraversal() const
Specify whether ImageLayer requires update traversal.
Definition Layer:119
osg::Texture::FilterMode _magFilter
Definition Layer:143
virtual void setModifiedCount(unsigned int)
Set the modified count value.
Definition Layer:128
virtual ~Layer()
osg::ref_ptr< Locator > _locator
Definition Layer:140
Property * getProperty()
Get the Property that informs the VolumeTechnique how this layer should be rendered.
Definition Layer:108
Layer(const Layer &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
std::string _filename
Definition Layer:139
virtual osg::BoundingSphere computeBound() const
void setDefaultValue(const osg::Vec4 &value)
Definition Layer:80
void setMinFilter(osg::Texture::FilterMode filter)
Set the minification texture filter to use when do texture associated with this layer.
Definition Layer:84
virtual const std::string & getFileName() const
Get the file name of the layer.
Definition Layer:71
Locator * getLocator()
Definition Layer:77
void setMagFilter(osg::Texture::FilterMode filter)
Set the magniification texture filter to use when do texture associated with this layer.
Definition Layer:90
void addProperty(Property *property)
Add a property, automatically creating a CompositePorperty if one isn't already assigned.
virtual const osg::Image * getImage() const
Return const image associated with layer if supported.
Definition Layer:99
virtual osg::Image * getImage()
Return image associated with layer if supported.
Definition Layer:96
void setLocator(Locator *locator)
Definition Layer:73
const osg::Vec4 & getDefaultValue() const
Definition Layer:81
virtual void dirty()
increment the modified count.
Definition Layer:125
osg::ref_ptr< Property > _property
Definition Layer:145
virtual unsigned int getModifiedCount() const
Get modified count value.
Definition Layer:131
void addProperty(const osg::ref_ptr< T > &p)
Definition Layer:116
META_Object(osgVolume, Layer)
void setLocator(const osg::ref_ptr< T > &locator)
Definition Layer:75
osg::Texture::FilterMode getMinFilter() const
Get the minification texture filter to use when do texture associated with this layer.
Definition Layer:87
void setProperty(const osg::ref_ptr< T > &p)
Definition Layer:105
const osg::Vec4 & getTexelOffset() const
Definition Layer:175
const osg::Vec4 & getTexelScale() const
Definition Layer:178
virtual void setModifiedCount(unsigned int value)
Set the modified count value.
ImageLayer(osg::Image *image=0)
void rescaleToZeroToOneRange()
Compute the min max range of the image, and then remap this to a 0 to 1 range.
virtual void dirty()
increment the modified count.
ImageLayer(const ImageLayer &imageLayer, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
osg::Vec4 _texelOffset
Definition Layer:205
META_Object(osgVolume, ImageLayer)
void setTexelScale(const osg::Vec4 &scale)
Definition Layer:177
virtual ~ImageLayer()
Definition Layer:203
virtual unsigned int getModifiedCount() const
Get modified count value.
void setImage(osg::Image *image)
virtual bool requiresUpdateTraversal() const
Specify whether ImageLayer requires update traversal.
virtual const osg::Image * getImage() const
Return const image associated with layer.
Definition Layer:171
void setTexelOffset(const osg::Vec4 &offset)
Definition Layer:174
void setFileName(const std::string &filename)
Set the file name of the data associated with this layer.
Definition Layer:160
void setImage(const osg::ref_ptr< T > &image)
Definition Layer:165
virtual void update(osg::NodeVisitor &)
Call update on the Layer.
void translateMinToZero()
Compute the min color component of the image and then translate and pixels by this offset to make the...
virtual osg::Image * getImage()
Return image associated with layer.
Definition Layer:168
void offsetAndScaleImage(const osg::Vec4 &offset, const osg::Vec4 &scale)
Apply color transformation to pixels using c' = offset + c * scale .
virtual const std::string & getFileName() const
Get the file name of the layer.
Definition Layer:161
osg::Vec4 _texelScale
Definition Layer:206
bool computeMinMax(osg::Vec4 &min, osg::Vec4 &max)
Compute the min and max pixel colors.
osg::ref_ptr< osg::Image > _image
Definition Layer:207
void setLayer(unsigned int i, Layer *layer)
Definition Layer:227
void setFileName(unsigned int i, const std::string &filename)
Definition Layer:224
CompositeLayer(const CompositeLayer &compositeLayer, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
std::vector< NameLayer > Layers
Definition Layer:276
virtual ~CompositeLayer()
Definition Layer:249
const std::string & getFileName(unsigned int i) const
Definition Layer:225
void removeLayer(unsigned int i)
Definition Layer:239
bool requiresUpdateTraversal() const
Specify whether ImageLayer requires update traversal.
const Layer * getLayer(unsigned int i) const
Definition Layer:233
virtual void update(osg::NodeVisitor &)
Call update on the Layer.
void addLayer(const osg::ref_ptr< T > &layer)
Definition Layer:237
META_Object(osgVolume, CompositeLayer)
void addLayer(Layer *layer)
Definition Layer:235
Layer * getLayer(unsigned int i)
Definition Layer:231
unsigned int getNumLayers() const
Definition Layer:241
Layers _layers
Definition Layer:278
void setLayer(unsigned int i, const osg::ref_ptr< T > &layer)
Definition Layer:229
NameLayer(const std::string &fn, Layer *l)
Definition Layer:259
NameLayer(const NameLayer &cnl)
Definition Layer:255
std::string filename
Definition Layer:272
osg::ref_ptr< Layer > layer
Definition Layer:273
Definition Locator:30
Definition Property:75
#define OSGVOLUME_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.