OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Locator.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_LOCATOR
15 #define OSGVOLUME_LOCATOR 1
16 
17 #include <osgVolume/Export>
18 
19 #include <osg/Object>
20 #include <osg/observer_ptr>
21 #include <osg/Matrixd>
22 #include <osg/TexGen>
23 #include <osg/MatrixTransform>
24 
25 #include <vector>
26 
27 namespace osgVolume {
28 
30 {
31  public:
32 
33  Locator() {}
34 
35  Locator(const osg::Matrixd& transform) { setTransform(transform); }
36 
38  Locator(const Locator& locator,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
39  osg::Object(locator, copyop),
40  _transform(locator._transform) {}
41 
43 
45  void setTransform(const osg::Matrixd& transform) { _transform = transform; _inverse.invert(_transform); locatorModified(); }
46 
48  const osg::Matrixd& getTransform() const { return _transform; }
49 
51  void setTransformAsExtents(double minX, double minY, double maxX, double maxY, double minZ, double maxZ);
52 
53 
54  virtual bool convertLocalToModel(const osg::Vec3d& /*local*/, osg::Vec3d& /*world*/) const;
55 
56  virtual bool convertModelToLocal(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) const;
57 
58  static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
59  const Locator& destination, osg::Vec3d& destinationNDC)
60  {
61  osg::Vec3d model;
62  if (!source.convertLocalToModel(sourceNDC, model)) return false;
63  if (!destination.convertModelToLocal(model, destinationNDC)) return false;
64  return true;
65  }
66 
67  bool computeLocalBounds(osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
68  bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
69 
70 
72  class LocatorCallback : virtual public osg::Object
73  {
74  public:
76  LocatorCallback(const LocatorCallback& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): osg::Object(rhs,copyop) {}
78 
79  virtual void locatorModified(Locator* /*locator*/) {};
80 
81  protected:
82  virtual ~LocatorCallback() {}
83  };
84 
85  void addCallback(LocatorCallback* callback);
86  void removeCallback(LocatorCallback* callback);
87 
88  typedef std::vector< osg::ref_ptr<LocatorCallback> > LocatorCallbacks;
89  LocatorCallbacks& getLocatorCallbacks() { return _locatorCallbacks; }
90  const LocatorCallbacks& getLocatorCallbacks() const { return _locatorCallbacks; }
91 
92  protected:
93 
94  void locatorModified();
97 
98  LocatorCallbacks _locatorCallbacks;
99 };
100 
102 {
103  public:
104 
106 
107  void locatorModified(Locator* locator);
108 
109  protected:
110 
112 };
113 
114 
116 {
117  public:
118 
119  TexGenLocatorCallback(osg::TexGen* texgen, Locator* geometryLocator, Locator* imageLocator);
120 
121  void locatorModified(Locator*);
122 
123  protected:
124 
128 };
129 
130 
131 }
132 
133 #endif
osg::observer_ptr< osg::TexGen > _texgen
Definition: Locator.h:125
virtual void locatorModified(Locator *)
Definition: Locator.h:79
osg::Matrixd _inverse
Definition: Locator.h:96
static bool convertLocalCoordBetween(const Locator &source, const osg::Vec3d &sourceNDC, const Locator &destination, osg::Vec3d &destinationNDC)
Definition: Locator.h:58
const osg::Matrixd & getTransform() const
Definition: Locator.h:48
osg::observer_ptr< osgVolume::Locator > _imageLocator
Definition: Locator.h:127
#define OSGVOLUME_EXPORT
Definition: Export.h:39
LocatorCallback(const LocatorCallback &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Locator.h:76
osg::Matrixd _transform
Definition: Locator.h:95
#define META_Object(library, name)
Definition: Object.h:42
Locator(const osg::Matrixd &transform)
Definition: Locator.h:35
const LocatorCallbacks & getLocatorCallbacks() const
Definition: Locator.h:90
osg::observer_ptr< osg::MatrixTransform > _transform
Definition: Locator.h:111
osg::observer_ptr< osgVolume::Locator > _geometryLocator
Definition: Locator.h:126
virtual bool convertModelToLocal(const osg::Vec3d &, osg::Vec3d &) const
LocatorCallbacks _locatorCallbacks
Definition: Locator.h:98
Definition: AlphaFunc.h:19
virtual bool convertLocalToModel(const osg::Vec3d &, osg::Vec3d &) const
bool invert(const Matrixd &rhs)
Definition: Matrixd.h:233
std::vector< osg::ref_ptr< LocatorCallback > > LocatorCallbacks
Definition: Locator.h:88
Locator(const Locator &locator, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Locator.h:38
void setTransform(const osg::Matrixd &transform)
Definition: Locator.h:45
LocatorCallbacks & getLocatorCallbacks()
Definition: Locator.h:89