OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Property.h
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 
25 namespace osgVolume {
26 
27 // forward decarle
28 class Property;
29 class CompositeProperty;
30 class SwitchProperty;
31 class TransferFunctionProperty;
32 class ScalarProperty;
33 class IsoSurfaceProperty;
34 class MaximumIntensityProjectionProperty;
35 class LightingProperty;
36 class AlphaFuncProperty;
37 class SampleRatioProperty;
38 class SampleRatioWhenMovingProperty;
39 class SampleDensityProperty;
40 class SampleDensityWhenMovingProperty;
41 class TransparencyProperty;
42 class ExteriorTransparencyFactorProperty;
43 class 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&);
56  virtual void apply(TransferFunctionProperty&);
57  virtual void apply(ScalarProperty&);
58  virtual void apply(IsoSurfaceProperty&);
59  virtual void apply(AlphaFuncProperty&);
60  virtual void apply(MaximumIntensityProjectionProperty&);
61  virtual void apply(LightingProperty&);
62  virtual void apply(SampleRatioProperty&);
63  virtual void apply(SampleRatioWhenMovingProperty&);
64  virtual void apply(SampleDensityProperty&);
65  virtual void apply(SampleDensityWhenMovingProperty&);
66  virtual void apply(TransparencyProperty&);
67  virtual void apply(ExteriorTransparencyFactorProperty&);
68  virtual void apply(VolumeSettings&);
69 
71 };
72 
73 
75 {
76  public:
77 
78  Property();
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 
107  CompositeProperty(const CompositeProperty& compositeProperty,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
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  Property* getProperty(unsigned int i) { return i<_properties.size() ? _properties[i].get() : 0; }
130 
131  const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; }
132 
133  void addProperty(Property* property) { _properties.push_back(property); dirty(); }
134 
135  void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); }
136 
137  unsigned int getNumProperties() const { return _properties.size(); }
138 
139  protected:
140 
141  virtual ~CompositeProperty() {}
142 
143 
144  Properties _properties;
145 };
146 
147 
149 {
150  public:
151 
152  SwitchProperty();
153 
155  SwitchProperty(const SwitchProperty& switchProperty,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
156 
158 
159  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
160 
161  virtual void traverse(PropertyVisitor& pv)
162  {
164  {
165  if (_activeProperty>=0 && static_cast<unsigned int>(_activeProperty)<=getNumProperties())
166  {
167  _properties[_activeProperty]->accept(pv);
168  }
169  }
170  else
171  {
173  }
174  }
175 
176 
179  void setActiveProperty(int i) { _activeProperty = i; dirty(); }
180 
182  int getActiveProperty() const { return _activeProperty; }
183 
184  protected:
185 
186  virtual ~SwitchProperty() {}
187 
189 };
190 
192 {
193  public:
194 
196 
199 
201 
202  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
203 
206 
209 
211  const osg::TransferFunction* getTransferFunction() const { return _tf.get(); }
212 
213  protected:
214 
216 
218 };
219 
220 
221 
223 {
224  public:
225 
226  ScalarProperty(const std::string& scaleName, float value);
227 
228  ScalarProperty(const ScalarProperty& scalarProperty,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
229 
231 
232  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
233 
235  virtual void setValue(float v) { _uniform->set(v); dirty(); }
236 
238  float getValue() const { float v; _uniform->get(v); return v; }
239 
241  osg::Uniform* getUniform() { return _uniform.get(); }
242 
244  const osg::Uniform* getUniform() const { return _uniform.get(); }
245 
246  protected:
247 
248  virtual ~ScalarProperty() {}
249 
250  ScalarProperty();
251 
253 };
254 
255 
257 {
258  public:
259 
260  IsoSurfaceProperty(float value=1.0f);
261 
263 
265 
266  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
267 
268  protected:
269 
270  virtual ~IsoSurfaceProperty() {}
271 };
272 
274 {
275  public:
276 
277  AlphaFuncProperty(float value=1.0f);
278 
280 
282 
283  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
284 
285  virtual void setValue(float v);
286 
287  osg::AlphaFunc* getAlphaFunc() { return _alphaFunc.get(); }
288 
289  const osg::AlphaFunc* getAlphaFunc() const { return _alphaFunc.get(); }
290 
291 
292  protected:
293 
294  virtual ~AlphaFuncProperty() {}
295 
297 };
298 
300 {
301  public:
302 
304 
306 
308 
309  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
310 
311  protected:
312 
314 };
315 
316 
318 {
319  public:
320 
322 
324 
326 
327  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
328 
329  protected:
330 
331  virtual ~LightingProperty() {}
332 };
333 
334 
337 {
338  public:
339 
340  SampleDensityProperty(float value=1.0f);
341 
343 
345 
346  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
347 
348  protected:
349 
351 };
352 
355 {
356  public:
357 
358  SampleDensityWhenMovingProperty(float value=1.0f);
359 
361 
363 
364  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
365 
366  protected:
367 
369 };
370 
373 {
374  public:
375 
376  SampleRatioProperty(float value=1.0f);
377 
379 
381 
382  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
383 
384  protected:
385 
386  virtual ~SampleRatioProperty() {}
387 };
388 
391 {
392  public:
393 
394  SampleRatioWhenMovingProperty(float value=1.0f);
395 
397 
399 
400  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
401 
402  protected:
403 
405 };
406 
407 
409 {
410  public:
411 
412  TransparencyProperty(float value=1.0f);
413 
415 
417 
418  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
419 
420  protected:
421 
423 };
424 
426 {
427  public:
428 
429  ExteriorTransparencyFactorProperty(float value=0.0f);
430 
432 
434 
435  virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
436 
437  protected:
438 
440 };
441 
442 
444 {
445  public:
446 
447  CollectPropertiesVisitor(bool traverseOnlyActiveChildren=true);
448 
449  virtual void apply(TransferFunctionProperty&);
450  virtual void apply(ScalarProperty&);
451  virtual void apply(IsoSurfaceProperty& iso);
452  virtual void apply(AlphaFuncProperty& af);
453  virtual void apply(MaximumIntensityProjectionProperty& mip);
454  virtual void apply(LightingProperty& lp);
455  virtual void apply(SampleDensityProperty& sdp);
456  virtual void apply(SampleDensityWhenMovingProperty& sdp);
457  virtual void apply(SampleRatioProperty& sdp);
458  virtual void apply(SampleRatioWhenMovingProperty& sdp);
459  virtual void apply(TransparencyProperty& tp);
460  virtual void apply(ExteriorTransparencyFactorProperty& tp);
461 
473 
474 };
475 
477 {
478  public:
479 
481 
483 
485 
486  virtual bool run(osg::Object* object, osg::Object* data) { return osgGA::GUIEventHandler::run(object, data); }
487 
488  void setKeyEventCycleForward(int key) { _cyleForwardKey = key; }
489  int getKeyEventCycleForward() const { return _cyleForwardKey; }
490 
491  void setKeyEventCycleBackward(int key) { _cyleBackwardKey = key; }
492  int getKeyEventCycleBackward() const { return _cyleBackwardKey; }
493 
494  void setKeyEventActivatesTransparencyAdjustment(int key) { _transparencyKey = key; }
495  int getKeyEventActivatesTransparencyAdjustment() const { return _transparencyKey; }
496 
497  void setKeyEventActivatesExteriorTransparencyFactorAdjustment(int key) { _exteriorTransparencyFactorKey = key; }
498  int getKeyEventActivatesExteriorTransparencyFactorAdjustment() const { return _exteriorTransparencyFactorKey; }
499 
500  void setKeyEventActivatesSampleDensityAdjustment(int key) { _sampleDensityKey = key; }
501  int getKeyEventActivatesSampleDensityAdjustment() const { return _sampleDensityKey; }
502 
503  void setKeyEventActivatesAlphaFuncAdjustment(int key) { _alphaFuncKey = key; }
504  int getKeyEventActivatesAlphaFuncAdjustment() const { return _alphaFuncKey; }
505 
506  virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&, osg::Object* object, osg::NodeVisitor*);
507 
514 
519 };
520 
521 }
522 
523 #endif
const osg::Uniform * getUniform() const
Definition: Property.h:244
virtual void setValue(float v)
Definition: Property.h:235
osg::ref_ptr< ExteriorTransparencyFactorProperty > _exteriorTransparencyFactorProperty
Definition: Property.h:472
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:346
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:418
Property * getProperty(unsigned int i)
Definition: Property.h:129
const osg::TransferFunction * getTransferFunction() const
Definition: Property.h:211
osg::ref_ptr< MaximumIntensityProjectionProperty > _mipProperty
Definition: Property.h:465
osg::ref_ptr< TransparencyProperty > _transparencyProperty
Definition: Property.h:471
void setModifiedCount(unsigned int c)
Definition: Property.h:87
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:232
unsigned int _modifiedCount
Definition: Property.h:97
osg::ref_ptr< SampleDensityProperty > _sampleDensityProperty
Definition: Property.h:467
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:435
virtual bool run(osg::Object *object, osg::Object *data)
Definition: Property.h:486
#define OSGVOLUME_EXPORT
Definition: Export.h:39
osg::ref_ptr< SampleRatioWhenMovingProperty > _sampleRatioWhenMovingProperty
Definition: Property.h:470
virtual ~PropertyVisitor()
Definition: Property.h:51
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:283
osg::ref_ptr< osg::AlphaFunc > _alphaFunc
Definition: Property.h:296
void setKeyEventActivatesExteriorTransparencyFactorAdjustment(int key)
Definition: Property.h:497
void setActiveProperty(int i)
Definition: Property.h:179
float getValue() const
Definition: Property.h:238
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:309
int getKeyEventActivatesAlphaFuncAdjustment() const
Definition: Property.h:504
osg::ref_ptr< LightingProperty > _lightingProperty
Definition: Property.h:466
#define META_Object(library, name)
Definition: Object.h:42
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:90
const osg::AlphaFunc * getAlphaFunc() const
Definition: Property.h:289
std::vector< osg::ref_ptr< Property > > Properties
Definition: Property.h:125
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:202
int getKeyEventActivatesTransparencyAdjustment() const
Definition: Property.h:495
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:159
virtual void traverse(PropertyVisitor &pv)
Definition: Property.h:113
unsigned int getModifiedCount() const
Definition: Property.h:88
virtual void apply(Property &)
osg::ref_ptr< SampleRatioProperty > _sampleRatioProperty
Definition: Property.h:469
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:327
virtual void traverse(PropertyVisitor &pv)
Definition: Property.h:91
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:364
osg::ref_ptr< TransferFunctionProperty > _tfProperty
Definition: Property.h:462
virtual void traverse(PropertyVisitor &pv)
Definition: Property.h:161
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:400
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:382
bool get(float &f) const
void setKeyEventActivatesAlphaFuncAdjustment(int key)
Definition: Property.h:503
unsigned int getNumProperties() const
Definition: Property.h:137
osg::ref_ptr< AlphaFuncProperty > _afProperty
Definition: Property.h:464
void removeProperty(unsigned int i)
Definition: Property.h:135
int getActiveProperty() const
Definition: Property.h:182
osg::Uniform * getUniform()
Definition: Property.h:241
void setProperty(unsigned int i, Property *property)
Definition: Property.h:127
osg::TransferFunction * getTransferFunction()
Definition: Property.h:208
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:111
virtual void accept(PropertyVisitor &pv)
Definition: Property.h:266
void addProperty(Property *property)
Definition: Property.h:133
osg::ref_ptr< osg::TransferFunction > _tf
Definition: Property.h:217
virtual bool run(osg::Object *object, osg::Object *data)
Definition: EventHandler.h:46
const Property * getProperty(unsigned int i) const
Definition: Property.h:131
void setKeyEventActivatesSampleDensityAdjustment(int key)
Definition: Property.h:500
osg::ref_ptr< SampleDensityWhenMovingProperty > _sampleDensityWhenMovingProperty
Definition: Property.h:468
int getKeyEventActivatesExteriorTransparencyFactorAdjustment() const
Definition: Property.h:498
void setTransferFunction(osg::TransferFunction *tf)
Definition: Property.h:205
osg::AlphaFunc * getAlphaFunc()
Definition: Property.h:287
osg::ref_ptr< osg::Uniform > _uniform
Definition: Property.h:252
osg::ref_ptr< IsoSurfaceProperty > _isoProperty
Definition: Property.h:463
void setKeyEventActivatesTransparencyAdjustment(int key)
Definition: Property.h:494
int getKeyEventActivatesSampleDensityAdjustment() const
Definition: Property.h:501