openscenegraph
osgVolume/Locator
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
27namespace osgVolume {
28
30{
31 public:
32
34
35 Locator(const osg::Matrixd& transform) { setTransform(transform); }
36
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
71 bool inverted() const;
72
75
76
78 class LocatorCallback : virtual public osg::Object
79 {
80 public:
82 LocatorCallback(const LocatorCallback& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): osg::Object(rhs,copyop) {}
84
85 virtual void locatorModified(Locator* /*locator*/) {};
86
87 protected:
88 virtual ~LocatorCallback() {}
89 };
90
92 template<class T> void addCallback(const osg::ref_ptr<T>& callback) { addCallback(callback.get()); }
93
94
96
97 typedef std::vector< osg::ref_ptr<LocatorCallback> > LocatorCallbacks;
98 LocatorCallbacks& getLocatorCallbacks() { return _locatorCallbacks; }
99 const LocatorCallbacks& getLocatorCallbacks() const { return _locatorCallbacks; }
100
101 protected:
102
106
108};
109
122
123
138
139
140}
141
142#endif
Definition osgVolume/Locator:79
META_Object(osgVolume, LocatorCallback)
virtual void locatorModified(Locator *)
Definition osgVolume/Locator:85
virtual ~LocatorCallback()
Definition osgVolume/Locator:88
LocatorCallback(const LocatorCallback &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition osgVolume/Locator:82
LocatorCallback()
Definition osgVolume/Locator:81
Definition osgVolume/Locator:30
Locator(const osg::Matrixd &transform)
Definition osgVolume/Locator:35
const osg::Matrixd & getTransform() const
Definition osgVolume/Locator:48
bool inverted() const
void addCallback(const osg::ref_ptr< T > &callback)
Definition osgVolume/Locator:92
osg::Matrixd _transform
Definition osgVolume/Locator:104
Locator(const Locator &locator, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition osgVolume/Locator:38
std::vector< osg::ref_ptr< LocatorCallback > > LocatorCallbacks
Definition osgVolume/Locator:97
void removeCallback(LocatorCallback *callback)
bool computeLocalBounds(osg::Vec3d &bottomLeft, osg::Vec3d &topRight) const
static bool convertLocalCoordBetween(const Locator &source, const osg::Vec3d &sourceNDC, const Locator &destination, osg::Vec3d &destinationNDC)
Definition osgVolume/Locator:58
osg::Matrixd _inverse
Definition osgVolume/Locator:105
void applyAppropriateFrontFace(osg::StateSet *ss) const
META_Object(osgVolume, Locator)
bool computeLocalBounds(Locator &source, osg::Vec3d &bottomLeft, osg::Vec3d &topRight) const
void addCallback(LocatorCallback *callback)
const LocatorCallbacks & getLocatorCallbacks() const
Definition osgVolume/Locator:99
void setTransform(const osg::Matrixd &transform)
Definition osgVolume/Locator:45
Locator()
Definition osgVolume/Locator:33
LocatorCallbacks _locatorCallbacks
Definition osgVolume/Locator:107
LocatorCallbacks & getLocatorCallbacks()
Definition osgVolume/Locator:98
void setTransformAsExtents(double minX, double minY, double maxX, double maxY, double minZ, double maxZ)
virtual bool convertLocalToModel(const osg::Vec3d &, osg::Vec3d &) const
virtual bool convertModelToLocal(const osg::Vec3d &, osg::Vec3d &) const
Definition osgVolume/Locator:125
osg::observer_ptr< osgVolume::Locator > _imageLocator
Definition osgVolume/Locator:136
osg::observer_ptr< osgVolume::Locator > _geometryLocator
Definition osgVolume/Locator:135
TexGenLocatorCallback(osg::TexGen *texgen, Locator *geometryLocator, Locator *imageLocator)
osg::observer_ptr< osg::TexGen > _texgen
Definition osgVolume/Locator:134
Definition osgVolume/Locator:111
TransformLocatorCallback(osg::MatrixTransform *transform)
osg::observer_ptr< osg::MatrixTransform > _transform
Definition osgVolume/Locator:120
void locatorModified(Locator *locator)
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition MatrixTransform:26
Definition Matrixd:27
bool invert(const Matrixd &rhs)
Definition Matrixd:233
Definition Object:61
Definition StateSet:46
Definition TexGen:43
Definition Vec3d:30
Definition observer_ptr:39
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSGVOLUME_EXPORT
Definition osgVolume/Export:39