OpenSceneGraph 3.6.5
Property
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_PROPERTY
15#define OSGVOLUME_PROPERTY 1
16
17#include <osg/TransferFunction>
18#include <osg/Uniform>
19#include <osg/AlphaFunc>
20
21#include <osgGA/GUIEventHandler>
22
23#include <osgVolume/Export>
24
25namespace osgVolume {
26
27// forward decarle
28class Property;
29class CompositeProperty;
30class SwitchProperty;
31class TransferFunctionProperty;
32class ScalarProperty;
33class IsoSurfaceProperty;
34class MaximumIntensityProjectionProperty;
35class LightingProperty;
36class AlphaFuncProperty;
37class SampleRatioProperty;
38class SampleRatioWhenMovingProperty;
39class SampleDensityProperty;
40class SampleDensityWhenMovingProperty;
41class TransparencyProperty;
42class ExteriorTransparencyFactorProperty;
43class VolumeSettings;
44
46{
47 public:
48
49 PropertyVisitor(bool traverseOnlyActiveChildren=true);
50
51 virtual ~PropertyVisitor() {}
52
53 virtual void apply(Property&);
54 virtual void apply(CompositeProperty&);
55 virtual void apply(SwitchProperty&);
57 virtual void apply(ScalarProperty&);
58 virtual void apply(IsoSurfaceProperty&);
59 virtual void apply(AlphaFuncProperty&);
61 virtual void apply(LightingProperty&);
62 virtual void apply(SampleRatioProperty&);
68 virtual void apply(VolumeSettings&);
69
71};
72
73
75{
76 public:
77
79
82
84
85 void dirty() { ++_modifiedCount; }
86
87 void setModifiedCount(unsigned int c) { _modifiedCount = c; }
88 unsigned int getModifiedCount() const { return _modifiedCount; }
89
90 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
91 virtual void traverse(PropertyVisitor& /*pv*/) {}
92
93 protected:
94
95 virtual ~Property();
96
97 unsigned int _modifiedCount;
98};
99
101{
102 public:
103
105
108
110
111 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
112
113 virtual void traverse(PropertyVisitor& pv)
114 {
115 for(Properties::iterator itr = _properties.begin();
116 itr != _properties.end();
117 ++itr)
118 {
119 (*itr)->accept(pv);
120 }
121 }
122
123 void clear();
124
125 typedef std::vector< osg::ref_ptr<Property> > Properties;
126
127 void setProperty(unsigned int i, Property* property) { if (i>=_properties.size()) _properties.resize(i+1); _properties[i] = property; }
128
129 template<class T> void setProperty(unsigned int i, const osg::ref_ptr<T>& p) { setProperty(i, p.get()); }
130
131 Property* getProperty(unsigned int i) { return i<_properties.size() ? _properties[i].get() : 0; }
132
133 const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; }
134
135 void addProperty(Property* property) { _properties.push_back(property); dirty(); }
136
137 template<class T> void addProperty(const osg::ref_ptr<T>& p) { addProperty(p.get()); }
138
139 void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); }
140
141 unsigned int getNumProperties() const { return _properties.size(); }
142
143 protected:
144
146
147
149};
150
151
153{
154 public:
155
157
160
162
163 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
164
165 virtual void traverse(PropertyVisitor& pv)
166 {
168 {
169 if (_activeProperty>=0 && static_cast<unsigned int>(_activeProperty)<=getNumProperties())
170 {
171 _properties[_activeProperty]->accept(pv);
172 }
173 }
174 else
175 {
177 }
178 }
179
180
184
186 int getActiveProperty() const { return _activeProperty; }
187
188 protected:
189
190 virtual ~SwitchProperty() {}
191
193};
194
223
224
225
227{
228 public:
229
230 ScalarProperty(const std::string& scaleName, float value);
231
233
235
236 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
237
239 virtual void setValue(float v) { _uniform->set(v); dirty(); }
240
242 float getValue() const { float v; _uniform->get(v); return v; }
243
245 osg::Uniform* getUniform() { return _uniform.get(); }
246
248 const osg::Uniform* getUniform() const { return _uniform.get(); }
249
250 protected:
251
252 virtual ~ScalarProperty() {}
253
255
257};
258
259
261{
262 public:
263
264 IsoSurfaceProperty(float value=1.0f);
265
267
269
270 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
271
272 protected:
273
275};
276
278{
279 public:
280
281 AlphaFuncProperty(float value=1.0f);
282
284
286
287 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
288
289 virtual void setValue(float v);
290
292
293 const osg::AlphaFunc* getAlphaFunc() const { return _alphaFunc.get(); }
294
295
296 protected:
297
299
301};
302
319
320
322{
323 public:
324
326
328
330
331 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
332
333 protected:
334
335 virtual ~LightingProperty() {}
336};
337
338
341{
342 public:
343
344 SampleDensityProperty(float value=1.0f);
345
347
349
350 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
351
352 protected:
353
355};
356
374
377{
378 public:
379
380 SampleRatioProperty(float value=1.0f);
381
383
385
386 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
387
388 protected:
389
391};
392
410
411
413{
414 public:
415
416 TransparencyProperty(float value=1.0f);
417
419
421
422 virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
423
424 protected:
425
427};
428
445
446
448{
449 public:
450
451 CollectPropertiesVisitor(bool traverseOnlyActiveChildren=true);
452
454 virtual void apply(ScalarProperty&);
455 virtual void apply(IsoSurfaceProperty& iso);
456 virtual void apply(AlphaFuncProperty& af);
458 virtual void apply(LightingProperty& lp);
459 virtual void apply(SampleDensityProperty& sdp);
461 virtual void apply(SampleRatioProperty& sdp);
463 virtual void apply(TransparencyProperty& tp);
465
477
478};
479
481{
482 public:
483
485
487
489
492
495
498
499 virtual bool run(osg::Object* object, osg::Object* data) { return osgGA::GUIEventHandler::run(object, data); }
500
503
506
509
512
515
518
520
527
532};
533
534}
535
536#endif
The osgVolume library is a NodeKit that extends the core scene graph to support volume rendering.
Encapsulates OpenGL glAlphaFunc.
Definition AlphaFunc:24
virtual bool run(osg::Object *object, osg::Object *data)
Invoke the callback, first parameter is the Object that the callback is attached to,...
Definition Callback:80
NodeCallback()
Definition Callback:219
virtual NodeCallback * asNodeCallback()
Definition Callback:227
virtual DrawableEventCallback * asDrawableEventCallback()
Definition Callback:330
DrawableEventCallback()
Definition Callback:322
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
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
Definition StateSet:446
TransferFunction is a class that provide a 1D,2D or 3D colour look up table that can be used on the G...
Definition TransferFunction:31
Uniform encapsulates glUniform values.
Definition Uniform:414
EventHandler is base class for adding handling of events, either as node event callback,...
Definition EventHandler:34
virtual EventHandler * asEventHandler()
Definition EventHandler:52
Definition GUIActionAdapter:62
Event class for storing Keyboard, mouse and window events.
Definition GUIEventAdapter:82
GUIEventHandler provides a basic interface for any class which wants to handle a GUI Events.
Definition GUIEventHandler:50
Definition Property:46
virtual void apply(AlphaFuncProperty &)
virtual void apply(SampleDensityWhenMovingProperty &)
virtual void apply(ScalarProperty &)
virtual void apply(TransparencyProperty &)
virtual void apply(IsoSurfaceProperty &)
virtual void apply(CompositeProperty &)
virtual void apply(MaximumIntensityProjectionProperty &)
PropertyVisitor(bool traverseOnlyActiveChildren=true)
virtual void apply(SampleRatioWhenMovingProperty &)
virtual void apply(ExteriorTransparencyFactorProperty &)
virtual void apply(SwitchProperty &)
virtual void apply(VolumeSettings &)
virtual void apply(SampleDensityProperty &)
virtual void apply(TransferFunctionProperty &)
bool _traverseOnlyActiveChildren
Definition Property:70
virtual void apply(SampleRatioProperty &)
virtual void apply(Property &)
virtual void apply(LightingProperty &)
virtual ~PropertyVisitor()
Definition Property:51
Definition Property:75
META_Object(osgVolume, Property)
void setModifiedCount(unsigned int c)
Definition Property:87
Property(const Property &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
virtual void accept(PropertyVisitor &pv)
Definition Property:90
void dirty()
Definition Property:85
unsigned int _modifiedCount
Definition Property:97
virtual void traverse(PropertyVisitor &)
Definition Property:91
unsigned int getModifiedCount() const
Definition Property:88
Definition Property:101
virtual void accept(PropertyVisitor &pv)
Definition Property:111
void addProperty(const osg::ref_ptr< T > &p)
Definition Property:137
unsigned int getNumProperties() const
Definition Property:141
void removeProperty(unsigned int i)
Definition Property:139
Properties _properties
Definition Property:148
CompositeProperty(const CompositeProperty &compositeProperty, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
Property * getProperty(unsigned int i)
Definition Property:131
void addProperty(Property *property)
Definition Property:135
virtual ~CompositeProperty()
Definition Property:145
META_Object(osgVolume, CompositeProperty)
const Property * getProperty(unsigned int i) const
Definition Property:133
virtual void traverse(PropertyVisitor &pv)
Definition Property:113
void setProperty(unsigned int i, Property *property)
Definition Property:127
std::vector< osg::ref_ptr< Property > > Properties
Definition Property:125
void setProperty(unsigned int i, const osg::ref_ptr< T > &p)
Definition Property:129
Definition Property:153
META_Object(osgVolume, SwitchProperty)
SwitchProperty(const SwitchProperty &switchProperty, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
virtual ~SwitchProperty()
Definition Property:190
void setActiveProperty(int i)
Set which child property is active.
Definition Property:183
virtual void traverse(PropertyVisitor &pv)
Definition Property:165
virtual void accept(PropertyVisitor &pv)
Definition Property:163
int _activeProperty
Definition Property:192
int getActiveProperty() const
Get the active property.
Definition Property:186
META_Object(osgVolume, TransferFunctionProperty)
osg::ref_ptr< osg::TransferFunction > _tf
Definition Property:221
osg::TransferFunction * getTransferFunction()
Get the transfer function.
Definition Property:212
const osg::TransferFunction * getTransferFunction() const
Get the const transfer function.
Definition Property:215
virtual ~TransferFunctionProperty()
Definition Property:219
void setTransferFunction(osg::TransferFunction *tf)
Set the transfer function.
Definition Property:209
virtual void accept(PropertyVisitor &pv)
Definition Property:206
TransferFunctionProperty(const TransferFunctionProperty &tfp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
TransferFunctionProperty(osg::TransferFunction *tf=0)
Definition Property:227
virtual ~ScalarProperty()
Definition Property:252
ScalarProperty(const ScalarProperty &scalarProperty, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
ScalarProperty(const std::string &scaleName, float value)
osg::ref_ptr< osg::Uniform > _uniform
Definition Property:256
const osg::Uniform * getUniform() const
Get the underlying uniform.
Definition Property:248
virtual void setValue(float v)
Set the value.
Definition Property:239
osg::Uniform * getUniform()
Get the underlying uniform.
Definition Property:245
float getValue() const
Get the value.
Definition Property:242
virtual void accept(PropertyVisitor &pv)
Definition Property:236
META_Object(osgVolume, ScalarProperty)
Definition Property:261
META_Object(osgVolume, IsoSurfaceProperty)
IsoSurfaceProperty(const IsoSurfaceProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
IsoSurfaceProperty(float value=1.0f)
virtual ~IsoSurfaceProperty()
Definition Property:274
virtual void accept(PropertyVisitor &pv)
Definition Property:270
Definition Property:278
virtual ~AlphaFuncProperty()
Definition Property:298
virtual void accept(PropertyVisitor &pv)
Definition Property:287
virtual void setValue(float v)
Set the value.
AlphaFuncProperty(const AlphaFuncProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
META_Object(osgVolume, AlphaFuncProperty)
const osg::AlphaFunc * getAlphaFunc() const
Definition Property:293
osg::ref_ptr< osg::AlphaFunc > _alphaFunc
Definition Property:300
osg::AlphaFunc * getAlphaFunc()
Definition Property:291
AlphaFuncProperty(float value=1.0f)
MaximumIntensityProjectionProperty(const MaximumIntensityProjectionProperty &mipp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual void accept(PropertyVisitor &pv)
Definition Property:313
virtual ~MaximumIntensityProjectionProperty()
Definition Property:317
META_Object(osgVolume, MaximumIntensityProjectionProperty)
Definition Property:322
virtual void accept(PropertyVisitor &pv)
Definition Property:331
META_Object(osgVolume, LightingProperty)
virtual ~LightingProperty()
Definition Property:335
LightingProperty(const LightingProperty &mipp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Sample density to use when the volume is static relative to the eye point or when moving if no Sample...
Definition Property:341
META_Object(osgVolume, SampleDensityProperty)
SampleDensityProperty(float value=1.0f)
SampleDensityProperty(const SampleDensityProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual ~SampleDensityProperty()
Definition Property:354
virtual void accept(PropertyVisitor &pv)
Definition Property:350
Sample density to use when the volume is moving relative to the eye point.
Definition Property:359
virtual ~SampleDensityWhenMovingProperty()
Definition Property:372
SampleDensityWhenMovingProperty(const SampleDensityWhenMovingProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual void accept(PropertyVisitor &pv)
Definition Property:368
META_Object(osgVolume, SampleDensityWhenMovingProperty)
Sample ratioto use when the volume is static relative to the eye point or when moving if no SampleRat...
Definition Property:377
virtual ~SampleRatioProperty()
Definition Property:390
META_Object(osgVolume, SampleRatioProperty)
SampleRatioProperty(const SampleRatioProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
SampleRatioProperty(float value=1.0f)
virtual void accept(PropertyVisitor &pv)
Definition Property:386
Sample density to use when the volume is moving relative to the eye point.
Definition Property:395
META_Object(osgVolume, SampleRatioWhenMovingProperty)
virtual void accept(PropertyVisitor &pv)
Definition Property:404
virtual ~SampleRatioWhenMovingProperty()
Definition Property:408
SampleRatioWhenMovingProperty(const SampleRatioWhenMovingProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Property:413
virtual ~TransparencyProperty()
Definition Property:426
TransparencyProperty(float value=1.0f)
META_Object(osgVolume, TransparencyProperty)
TransparencyProperty(const TransparencyProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual void accept(PropertyVisitor &pv)
Definition Property:422
virtual void accept(PropertyVisitor &pv)
Definition Property:439
ExteriorTransparencyFactorProperty(const ExteriorTransparencyFactorProperty &isp, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual ~ExteriorTransparencyFactorProperty()
Definition Property:443
META_Object(osgVolume, ExteriorTransparencyFactorProperty)
CollectPropertiesVisitor(bool traverseOnlyActiveChildren=true)
osg::ref_ptr< AlphaFuncProperty > _afProperty
Definition Property:468
osg::ref_ptr< SampleRatioProperty > _sampleRatioProperty
Definition Property:473
virtual void apply(SampleRatioProperty &sdp)
osg::ref_ptr< ExteriorTransparencyFactorProperty > _exteriorTransparencyFactorProperty
Definition Property:476
osg::ref_ptr< TransferFunctionProperty > _tfProperty
Definition Property:466
virtual void apply(ExteriorTransparencyFactorProperty &tp)
virtual void apply(ScalarProperty &)
virtual void apply(IsoSurfaceProperty &iso)
osg::ref_ptr< SampleRatioWhenMovingProperty > _sampleRatioWhenMovingProperty
Definition Property:474
osg::ref_ptr< SampleDensityWhenMovingProperty > _sampleDensityWhenMovingProperty
Definition Property:472
virtual void apply(SampleRatioWhenMovingProperty &sdp)
virtual void apply(SampleDensityWhenMovingProperty &sdp)
osg::ref_ptr< IsoSurfaceProperty > _isoProperty
Definition Property:467
osg::ref_ptr< SampleDensityProperty > _sampleDensityProperty
Definition Property:471
virtual void apply(TransferFunctionProperty &)
osg::ref_ptr< TransparencyProperty > _transparencyProperty
Definition Property:475
osg::ref_ptr< MaximumIntensityProjectionProperty > _mipProperty
Definition Property:469
virtual void apply(AlphaFuncProperty &af)
virtual void apply(TransparencyProperty &tp)
virtual void apply(LightingProperty &lp)
virtual void apply(MaximumIntensityProjectionProperty &mip)
osg::ref_ptr< LightingProperty > _lightingProperty
Definition Property:470
virtual void apply(SampleDensityProperty &sdp)
virtual const osgGA::EventHandler * asEventHandler() const
Definition Property:497
void setKeyEventActivatesSampleDensityAdjustment(int key)
Definition Property:513
int getKeyEventActivatesAlphaFuncAdjustment() const
Definition Property:517
int _sampleDensityKey
Definition Property:526
int _exteriorTransparencyFactorKey
Definition Property:524
int getKeyEventActivatesSampleDensityAdjustment() const
Definition Property:514
bool _updateTransparency
Definition Property:528
void setKeyEventActivatesAlphaFuncAdjustment(int key)
Definition Property:516
bool _updateAlphaCutOff
Definition Property:530
int _cyleBackwardKey
Definition Property:522
void setKeyEventActivatesTransparencyAdjustment(int key)
Definition Property:507
META_Object(osgVolume, PropertyAdjustmentCallback)
virtual osgGA::EventHandler * asEventHandler()
Definition Property:496
int getKeyEventCycleForward() const
Definition Property:502
virtual DrawableEventCallback * asDrawableEventCallback()
Definition Property:493
int getKeyEventActivatesTransparencyAdjustment() const
Definition Property:508
int _cyleForwardKey
Definition Property:521
int getKeyEventActivatesExteriorTransparencyFactorAdjustment() const
Definition Property:511
void setKeyEventCycleBackward(int key)
Definition Property:504
int getKeyEventCycleBackward() const
Definition Property:505
PropertyAdjustmentCallback(const PropertyAdjustmentCallback &, const osg::CopyOp &)
virtual const DrawableEventCallback * asDrawableEventCallback() const
Definition Property:494
virtual const NodeCallback * asNodeCallback() const
Definition Property:491
virtual bool run(osg::Object *object, osg::Object *data)
NodeCallback overrides the Callback::run() method to adapt it the old style NodeCallback::operator()(...
Definition Property:499
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &, osg::Object *object, osg::NodeVisitor *)
Handle events, return true if handled, false otherwise.
bool _updateExteriorTransparencyFactor
Definition Property:529
int _transparencyKey
Definition Property:523
void setKeyEventCycleForward(int key)
Definition Property:501
virtual NodeCallback * asNodeCallback()
Definition Property:490
void setKeyEventActivatesExteriorTransparencyFactorAdjustment(int key)
Definition Property:510
bool _updateSampleDensity
Definition Property:531
int _alphaFuncKey
Definition Property:525
Definition VolumeSettings:23
#define OSGVOLUME_EXPORT
Definition Export:39

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.