Introduced osgVolume::Layer and Locator classes mirrroring similar classes in osgTerrain.
This commit is contained in:
@@ -44,7 +44,7 @@ class BoundingSphereImpl
|
|||||||
BoundingSphereImpl() : _center(0.0,0.0,0.0),_radius(-1.0) {}
|
BoundingSphereImpl() : _center(0.0,0.0,0.0),_radius(-1.0) {}
|
||||||
|
|
||||||
/** Creates a bounding sphere initialized to the given extents. */
|
/** Creates a bounding sphere initialized to the given extents. */
|
||||||
BoundingSphereImpl(const vec_type& center,value_type radius) : _center(center),_radius(radius) {}
|
BoundingSphereImpl(const vec_type& center, value_type radius) : _center(center),_radius(radius) {}
|
||||||
|
|
||||||
/** Creates a bounding sphere initialized to the given extents. */
|
/** Creates a bounding sphere initialized to the given extents. */
|
||||||
BoundingSphereImpl(const BoundingSphereImpl& bs) : _center(bs._center),_radius(bs._radius) {}
|
BoundingSphereImpl(const BoundingSphereImpl& bs) : _center(bs._center),_radius(bs._radius) {}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class OSGTERRAIN_EXPORT Locator : public osg::Object
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight);
|
bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
|
||||||
|
|
||||||
void setDefinedInFile(bool flag) { _definedInFile = flag; }
|
void setDefinedInFile(bool flag) { _definedInFile = flag; }
|
||||||
bool getDefinedInFile() const { return _definedInFile; }
|
bool getDefinedInFile() const { return _definedInFile; }
|
||||||
|
|||||||
202
include/osgVolume/Layer
Normal file
202
include/osgVolume/Layer
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (at your option) any later version. The full license is in LICENSE file
|
||||||
|
* included with this distribution, and on the openscenegraph.org website.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* OpenSceneGraph Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OSGVOLUME_LAYER
|
||||||
|
#define OSGVOLUME_LAYER 1
|
||||||
|
|
||||||
|
#include <osg/Object>
|
||||||
|
#include <osg/Image>
|
||||||
|
#include <osg/Shape>
|
||||||
|
#include <osg/Array>
|
||||||
|
#include <osg/TransferFunction>
|
||||||
|
|
||||||
|
#include <osgVolume/Locator>
|
||||||
|
|
||||||
|
namespace osgVolume {
|
||||||
|
|
||||||
|
class OSGVOLUME_EXPORT Layer : public osg::Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Layer();
|
||||||
|
|
||||||
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||||
|
Layer(const Layer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||||
|
|
||||||
|
META_Object(osgVolume, Layer);
|
||||||
|
|
||||||
|
/** Set the file name of the data associated with this layer. */
|
||||||
|
virtual void setFileName(const std::string& filename) { _filename = filename; }
|
||||||
|
|
||||||
|
/** Get the file name of the layer. */
|
||||||
|
virtual const std::string& getFileName() const { return _filename; }
|
||||||
|
|
||||||
|
void setLocator(Locator* locator) { _locator = locator; }
|
||||||
|
Locator* getLocator() { return _locator.get(); }
|
||||||
|
const Locator* getLocator() const { return _locator.get(); }
|
||||||
|
|
||||||
|
void setDefaultValue(const osg::Vec4& value) { _defaultValue = value; }
|
||||||
|
const osg::Vec4& getDefaultValue() const { return _defaultValue; }
|
||||||
|
|
||||||
|
/** Set the minification texture filter to use when do texture associated with this layer.*/
|
||||||
|
void setMinFilter(osg::Texture::FilterMode filter) { _minFilter = filter; }
|
||||||
|
|
||||||
|
/** Get the minification texture filter to use when do texture associated with this layer.*/
|
||||||
|
osg::Texture::FilterMode getMinFilter() const { return _minFilter; }
|
||||||
|
|
||||||
|
/** Set the magniification texture filter to use when do texture associated with this layer.*/
|
||||||
|
void setMagFilter(osg::Texture::FilterMode filter) { _magFilter = filter; }
|
||||||
|
|
||||||
|
/** Get the magnification texture filter to use when do texture associated with this layer.*/
|
||||||
|
osg::Texture::FilterMode getMagFilter() const { return _magFilter; }
|
||||||
|
|
||||||
|
/** Return image associated with layer if supported. */
|
||||||
|
virtual osg::Image* getImage() { return 0; }
|
||||||
|
|
||||||
|
/** Return const image associated with layer if supported. */
|
||||||
|
virtual const osg::Image* getImage() const { return 0; }
|
||||||
|
|
||||||
|
|
||||||
|
/** Set the optional transfer function that maps the imagery pixels to new colours.
|
||||||
|
* Transfer function may be implemented on the GPU or via pre-processing step. */
|
||||||
|
void setTransferFunction(osg::TransferFunction* tf) { _transferFunction = tf; }
|
||||||
|
|
||||||
|
/** Get the transfer function.*/
|
||||||
|
osg::TransferFunction* getTransferFunction() { return _transferFunction.get(); }
|
||||||
|
|
||||||
|
/** Get the const transfer function.*/
|
||||||
|
const osg::TransferFunction* getTransferFunction() const { return _transferFunction.get(); }
|
||||||
|
|
||||||
|
|
||||||
|
/** increment the modified count."*/
|
||||||
|
virtual void dirty() {};
|
||||||
|
|
||||||
|
/** Set the modified count value. */
|
||||||
|
virtual void setModifiedCount(unsigned int /*value*/) {};
|
||||||
|
|
||||||
|
/** Get modified count value. */
|
||||||
|
virtual unsigned int getModifiedCount() const { return 0; }
|
||||||
|
|
||||||
|
virtual osg::BoundingSphere computeBound() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual ~Layer();
|
||||||
|
|
||||||
|
std::string _filename;
|
||||||
|
osg::ref_ptr<Locator> _locator;
|
||||||
|
osg::Vec4 _defaultValue;
|
||||||
|
osg::Texture::FilterMode _minFilter;
|
||||||
|
osg::Texture::FilterMode _magFilter;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::TransferFunction> _transferFunction;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class OSGVOLUME_EXPORT ImageLayer : public Layer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ImageLayer(osg::Image* image=0);
|
||||||
|
|
||||||
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||||
|
ImageLayer(const ImageLayer& imageLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||||
|
|
||||||
|
META_Object(osgVolume, ImageLayer);
|
||||||
|
|
||||||
|
void setFileName(const std::string& filename) { _filename = filename; if (_image.valid()) _image->setFileName(filename); }
|
||||||
|
virtual const std::string& getFileName() const { return _image.get() ? _image->getFileName() : _filename; }
|
||||||
|
|
||||||
|
void setImage(osg::Image* image);
|
||||||
|
|
||||||
|
/** Return image associated with layer. */
|
||||||
|
virtual osg::Image* getImage() { return _image.get(); }
|
||||||
|
|
||||||
|
/** Return const image associated with layer. */
|
||||||
|
virtual const osg::Image* getImage() const { return _image.get(); }
|
||||||
|
|
||||||
|
virtual void dirty();
|
||||||
|
virtual void setModifiedCount(unsigned int value);
|
||||||
|
virtual unsigned int getModifiedCount() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual ~ImageLayer() {}
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Image> _image;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class OSGVOLUME_EXPORT CompositeLayer : public Layer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
CompositeLayer();
|
||||||
|
|
||||||
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||||
|
CompositeLayer(const CompositeLayer& compositeLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||||
|
|
||||||
|
META_Object(osgVolume, CompositeLayer);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
void setFileName(unsigned int i, const std::string& filename) { _layers[i].filename = filename; if (_layers[i].layer.valid()) _layers[i].layer->setFileName(filename); }
|
||||||
|
const std::string& getFileName(unsigned int i) const { return _layers[i].layer.valid() ? _layers[i].layer->getFileName() : _layers[i].filename; }
|
||||||
|
|
||||||
|
void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; }
|
||||||
|
Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; }
|
||||||
|
const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; }
|
||||||
|
|
||||||
|
void addLayer(Layer* layer) { _layers.push_back(NameLayer(layer->getFileName(),layer)); }
|
||||||
|
|
||||||
|
void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); }
|
||||||
|
|
||||||
|
unsigned int getNumLayers() const { return _layers.size(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual ~CompositeLayer() {}
|
||||||
|
|
||||||
|
struct NameLayer
|
||||||
|
{
|
||||||
|
NameLayer() {}
|
||||||
|
|
||||||
|
NameLayer(const NameLayer& cnl):
|
||||||
|
filename(cnl.filename),
|
||||||
|
layer(cnl.layer) {}
|
||||||
|
|
||||||
|
NameLayer(const std::string& fn, Layer* l):
|
||||||
|
filename(fn),
|
||||||
|
layer(l) {}
|
||||||
|
|
||||||
|
NameLayer& operator = (const NameLayer& cnl)
|
||||||
|
{
|
||||||
|
if (&cnl==this) return *this;
|
||||||
|
|
||||||
|
filename = cnl.filename;
|
||||||
|
layer = cnl.layer;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string filename;
|
||||||
|
osg::ref_ptr<Layer> layer;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector< NameLayer > Layers;
|
||||||
|
|
||||||
|
Layers _layers;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
70
include/osgVolume/Locator
Normal file
70
include/osgVolume/Locator
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (at your option) any later version. The full license is in LICENSE file
|
||||||
|
* included with this distribution, and on the openscenegraph.org website.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* OpenSceneGraph Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OSGVOLUME_LOCATOR
|
||||||
|
#define OSGVOLUME_LOCATOR 1
|
||||||
|
|
||||||
|
#include <osgVolume/Export>
|
||||||
|
|
||||||
|
#include <osg/Object>
|
||||||
|
#include <osg/Matrixd>
|
||||||
|
|
||||||
|
namespace osgVolume {
|
||||||
|
|
||||||
|
class OSGVOLUME_EXPORT Locator : public osg::Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Locator() {}
|
||||||
|
|
||||||
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||||
|
Locator(const Locator& locator,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||||
|
_transform(locator._transform) {}
|
||||||
|
|
||||||
|
META_Object(osgVolume, Locator);
|
||||||
|
|
||||||
|
/** Set the transformation from local coordinates to model coordinates.*/
|
||||||
|
void setTransform(const osg::Matrixd& transform) { _transform = transform; _inverse.invert(_transform); }
|
||||||
|
|
||||||
|
/** 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;
|
||||||
|
|
||||||
|
static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool computeLocalBounds(osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
|
||||||
|
bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
osg::Matrixd _transform;
|
||||||
|
osg::Matrixd _inverse;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -56,7 +56,7 @@ void Locator::setTransformAsExtents(double minX, double minY, double maxX, doubl
|
|||||||
_inverse.invert(_transform);
|
_inverse.invert(_transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Locator::computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight)
|
bool Locator::computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const
|
||||||
{
|
{
|
||||||
typedef std::list<osg::Vec3d> Corners;
|
typedef std::list<osg::Vec3d> Corners;
|
||||||
Corners corners;
|
Corners corners;
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ SET(LIB_PUBLIC_HEADERS
|
|||||||
${HEADER_PATH}/ImageUtils
|
${HEADER_PATH}/ImageUtils
|
||||||
${HEADER_PATH}/Version
|
${HEADER_PATH}/Version
|
||||||
${HEADER_PATH}/Volume
|
${HEADER_PATH}/Volume
|
||||||
|
${HEADER_PATH}/Locator
|
||||||
|
${HEADER_PATH}/Layer
|
||||||
${HEADER_PATH}/VolumeTechnique
|
${HEADER_PATH}/VolumeTechnique
|
||||||
${HEADER_PATH}/VolumeTile
|
${HEADER_PATH}/VolumeTile
|
||||||
)
|
)
|
||||||
@@ -24,6 +26,8 @@ ADD_LIBRARY(${LIB_NAME}
|
|||||||
Version.cpp
|
Version.cpp
|
||||||
Volume.cpp
|
Volume.cpp
|
||||||
VolumeTechnique.cpp
|
VolumeTechnique.cpp
|
||||||
|
Layer.cpp
|
||||||
|
Locator.cpp
|
||||||
VolumeTile.cpp
|
VolumeTile.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
103
src/osgVolume/Layer.cpp
Normal file
103
src/osgVolume/Layer.cpp
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (at your option) any later version. The full license is in LICENSE file
|
||||||
|
* included with this distribution, and on the openscenegraph.org website.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* OpenSceneGraph Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <osgVolume/Layer>
|
||||||
|
|
||||||
|
using namespace osgVolume;
|
||||||
|
|
||||||
|
Layer::Layer():
|
||||||
|
_minFilter(osg::Texture::LINEAR_MIPMAP_LINEAR),
|
||||||
|
_magFilter(osg::Texture::LINEAR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Layer::Layer(const Layer& layer,const osg::CopyOp& copyop):
|
||||||
|
osg::Object(layer,copyop),
|
||||||
|
_filename(layer._filename),
|
||||||
|
_minFilter(layer._minFilter),
|
||||||
|
_magFilter(layer._magFilter)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Layer::~Layer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::BoundingSphere Layer::computeBound() const
|
||||||
|
{
|
||||||
|
if (!getLocator()) return osg::BoundingSphere();
|
||||||
|
|
||||||
|
osg::Vec3d left, right;
|
||||||
|
getLocator()->computeLocalBounds(left, right);
|
||||||
|
|
||||||
|
return osg::BoundingSphere((left+right)*0.5, (right-left).length()*0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// ImageLayer
|
||||||
|
//
|
||||||
|
ImageLayer::ImageLayer(osg::Image* image):
|
||||||
|
_image(image)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageLayer::ImageLayer(const ImageLayer& imageLayer,const osg::CopyOp& copyop):
|
||||||
|
Layer(imageLayer, copyop),
|
||||||
|
_image(imageLayer._image)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageLayer::setImage(osg::Image* image)
|
||||||
|
{
|
||||||
|
_image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageLayer::dirty()
|
||||||
|
{
|
||||||
|
if (_image.valid()) _image->dirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageLayer::setModifiedCount(unsigned int value)
|
||||||
|
{
|
||||||
|
if (!_image) return;
|
||||||
|
else _image->setModifiedCount(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int ImageLayer::getModifiedCount() const
|
||||||
|
{
|
||||||
|
if (!_image) return 0;
|
||||||
|
else return _image->getModifiedCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// CompositeLayer
|
||||||
|
//
|
||||||
|
CompositeLayer::CompositeLayer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CompositeLayer::CompositeLayer(const CompositeLayer& compositeLayer,const osg::CopyOp& copyop):
|
||||||
|
Layer(compositeLayer,copyop)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CompositeLayer::clear()
|
||||||
|
{
|
||||||
|
_layers.clear();
|
||||||
|
}
|
||||||
167
src/osgVolume/Locator.cpp
Normal file
167
src/osgVolume/Locator.cpp
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (at your option) any later version. The full license is in LICENSE file
|
||||||
|
* included with this distribution, and on the openscenegraph.org website.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* OpenSceneGraph Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <osgVolume/Locator>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
using namespace osgVolume;
|
||||||
|
|
||||||
|
void Locator::setTransformAsExtents(double minX, double minY, double maxX, double maxY, double minZ, double maxZ)
|
||||||
|
{
|
||||||
|
_transform.set(maxX-minX, 0.0, 0.0, 0.0,
|
||||||
|
0.0, maxY-minY, 0.0, 0.0,
|
||||||
|
0.0, 0.0, maxZ-minZ, 0.0,
|
||||||
|
minX, minY, minZ, 1.0);
|
||||||
|
|
||||||
|
_inverse.invert(_transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Locator::convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const
|
||||||
|
{
|
||||||
|
world = local * _transform;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Locator::convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const
|
||||||
|
{
|
||||||
|
local = world * _inverse;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Locator::computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const
|
||||||
|
{
|
||||||
|
typedef std::list<osg::Vec3d> Corners;
|
||||||
|
Corners corners;
|
||||||
|
|
||||||
|
osg::Vec3d cornerNDC;
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,0.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,0.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,1.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,1.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,0.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,0.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,1.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,1.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (corners.empty()) return false;
|
||||||
|
|
||||||
|
|
||||||
|
for(Corners::iterator itr = corners.begin();
|
||||||
|
itr != corners.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
bottomLeft.x() = osg::minimum( bottomLeft.x(), itr->x());
|
||||||
|
bottomLeft.y() = osg::minimum( bottomLeft.y(), itr->y());
|
||||||
|
bottomLeft.z() = osg::minimum( bottomLeft.z(), itr->z());
|
||||||
|
topRight.x() = osg::maximum( topRight.x(), itr->x());
|
||||||
|
topRight.y() = osg::maximum( topRight.y(), itr->y());
|
||||||
|
topRight.z() = osg::maximum( topRight.z(), itr->z());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Locator::computeLocalBounds(osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const
|
||||||
|
{
|
||||||
|
typedef std::list<osg::Vec3d> Corners;
|
||||||
|
Corners corners;
|
||||||
|
|
||||||
|
osg::Vec3d cornerNDC;
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,0.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,0.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,1.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,1.0,0.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,0.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,0.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(0.0,1.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convertLocalToModel(osg::Vec3d(1.0,1.0,1.0), cornerNDC))
|
||||||
|
{
|
||||||
|
corners.push_back(cornerNDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (corners.empty()) return false;
|
||||||
|
|
||||||
|
for(Corners::iterator itr = corners.begin();
|
||||||
|
itr != corners.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
bottomLeft.x() = osg::minimum( bottomLeft.x(), itr->x());
|
||||||
|
bottomLeft.y() = osg::minimum( bottomLeft.y(), itr->y());
|
||||||
|
bottomLeft.z() = osg::minimum( bottomLeft.z(), itr->z());
|
||||||
|
topRight.x() = osg::maximum( topRight.x(), itr->x());
|
||||||
|
topRight.y() = osg::maximum( topRight.y(), itr->y());
|
||||||
|
topRight.z() = osg::maximum( topRight.z(), itr->z());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user