Introduced osgVolume::Layer and Locator classes mirrroring similar classes in osgTerrain.
This commit is contained in:
@@ -56,7 +56,7 @@ void Locator::setTransformAsExtents(double minX, double minY, double maxX, doubl
|
||||
_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;
|
||||
Corners corners;
|
||||
|
||||
@@ -12,6 +12,8 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/ImageUtils
|
||||
${HEADER_PATH}/Version
|
||||
${HEADER_PATH}/Volume
|
||||
${HEADER_PATH}/Locator
|
||||
${HEADER_PATH}/Layer
|
||||
${HEADER_PATH}/VolumeTechnique
|
||||
${HEADER_PATH}/VolumeTile
|
||||
)
|
||||
@@ -24,6 +26,8 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
Version.cpp
|
||||
Volume.cpp
|
||||
VolumeTechnique.cpp
|
||||
Layer.cpp
|
||||
Locator.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