2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
|
2009-01-05 19:26:26 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2009-01-05 19:26:26 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2009-01-05 19:26:26 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-01-05 19:26:26 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGVOLUME_LOCATOR
|
|
|
|
#define OSGVOLUME_LOCATOR 1
|
|
|
|
|
|
|
|
#include <osgVolume/Export>
|
|
|
|
|
|
|
|
#include <osg/Object>
|
2013-12-07 03:31:12 +08:00
|
|
|
#include <osg/observer_ptr>
|
2009-01-05 19:26:26 +08:00
|
|
|
#include <osg/Matrixd>
|
2013-12-07 03:31:12 +08:00
|
|
|
#include <osg/TexGen>
|
|
|
|
#include <osg/MatrixTransform>
|
2009-01-05 19:26:26 +08:00
|
|
|
|
2009-07-03 13:54:02 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
namespace osgVolume {
|
|
|
|
|
|
|
|
class OSGVOLUME_EXPORT Locator : public osg::Object
|
|
|
|
{
|
|
|
|
public:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
Locator() {}
|
|
|
|
|
2009-01-09 23:19:25 +08:00
|
|
|
Locator(const osg::Matrixd& transform) { setTransform(transform); }
|
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Locator(const Locator& locator,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
2009-01-07 18:32:59 +08:00
|
|
|
osg::Object(locator, copyop),
|
2009-01-05 19:26:26 +08:00
|
|
|
_transform(locator._transform) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
META_Object(osgVolume, Locator);
|
|
|
|
|
|
|
|
/** Set the transformation from local coordinates to model coordinates.*/
|
2009-07-03 13:54:02 +08:00
|
|
|
void setTransform(const osg::Matrixd& transform) { _transform = transform; _inverse.invert(_transform); locatorModified(); }
|
2009-01-05 19:26:26 +08:00
|
|
|
|
|
|
|
/** Set the transformation from local coordinates to model coordinates.*/
|
|
|
|
const osg::Matrixd& getTransform() const { return _transform; }
|
|
|
|
|
|
|
|
/** Set the extents of the local coords.*/
|
|
|
|
void setTransformAsExtents(double minX, double minY, double maxX, double maxY, double minZ, double maxZ);
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool convertLocalToModel(const osg::Vec3d& /*local*/, osg::Vec3d& /*world*/) const;
|
|
|
|
|
|
|
|
virtual bool convertModelToLocal(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) const;
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
|
2009-01-05 19:26:26 +08:00
|
|
|
const Locator& destination, osg::Vec3d& destinationNDC)
|
|
|
|
{
|
|
|
|
osg::Vec3d model;
|
|
|
|
if (!source.convertLocalToModel(sourceNDC, model)) return false;
|
|
|
|
if (!destination.convertModelToLocal(model, destinationNDC)) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
bool computeLocalBounds(osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
|
|
|
|
bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
|
|
|
|
|
2009-07-03 13:54:02 +08:00
|
|
|
|
|
|
|
/** Callback interface for enabling the monitoring of changes to the Locator.*/
|
|
|
|
class LocatorCallback : virtual public osg::Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LocatorCallback() {}
|
|
|
|
LocatorCallback(const LocatorCallback& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): osg::Object(rhs,copyop) {}
|
|
|
|
META_Object(osgVolume, LocatorCallback);
|
|
|
|
|
2013-06-28 20:00:43 +08:00
|
|
|
virtual void locatorModified(Locator* /*locator*/) {};
|
2009-07-03 13:54:02 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~LocatorCallback() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void addCallback(LocatorCallback* callback);
|
|
|
|
void removeCallback(LocatorCallback* callback);
|
|
|
|
|
|
|
|
typedef std::vector< osg::ref_ptr<LocatorCallback> > LocatorCallbacks;
|
|
|
|
LocatorCallbacks& getLocatorCallbacks() { return _locatorCallbacks; }
|
|
|
|
const LocatorCallbacks& getLocatorCallbacks() const { return _locatorCallbacks; }
|
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
protected:
|
2009-07-03 13:54:02 +08:00
|
|
|
|
|
|
|
void locatorModified();
|
|
|
|
osg::Matrixd _transform;
|
|
|
|
osg::Matrixd _inverse;
|
|
|
|
|
|
|
|
LocatorCallbacks _locatorCallbacks;
|
2009-01-05 19:26:26 +08:00
|
|
|
};
|
|
|
|
|
2013-12-07 03:31:12 +08:00
|
|
|
class OSGVOLUME_EXPORT TransformLocatorCallback : public Locator::LocatorCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TransformLocatorCallback(osg::MatrixTransform* transform);
|
|
|
|
|
|
|
|
void locatorModified(Locator* locator);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
osg::observer_ptr<osg::MatrixTransform> _transform;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OSGVOLUME_EXPORT TexGenLocatorCallback : public Locator::LocatorCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TexGenLocatorCallback(osg::TexGen* texgen, Locator* geometryLocator, Locator* imageLocator);
|
|
|
|
|
|
|
|
void locatorModified(Locator*);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
osg::observer_ptr<osg::TexGen> _texgen;
|
|
|
|
osg::observer_ptr<osgVolume::Locator> _geometryLocator;
|
|
|
|
osg::observer_ptr<osgVolume::Locator> _imageLocator;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-05 19:26:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|