Hi Tim,

I've merged your changes with svn/trunk and everything builds when I
do use the wrappers, but if run the make wrappers and the build the
wrappers I get many hundreds of build errors.  I don't know how
whether it's possible to fix these errors without disabling the
wrapping of BoundingBox and BoundingSphere completely.  Perhaps mods
to src/osgWrappers/genwrapper.conf would do the trick, perhaps mods to
genwrapper source code itself.

I have lots of other work to complete, so fixing all the problems that
this submission brings with it isn't something I can take on, so for
the time being I'm going to have to reject this submission.

Perhaps one solution, albiet a bit crude would be to implement the
BoundingBox/Sphere double and float versions as separate headers, and
have a single implementation in to the .cpp as is done for the Matrix
class.  It does throw away one of the strengths of C++ but it would
solve the wrapping issues.

A couple of side notes, the use of member templates can cause cross
platform build problems, and the NumberTraits<double> implememtation
returns a DBL_MAX as a float, whereas it should be a double:

template<>
class NumberTraits<double>
{
public:
    static inline float maxNumber() { return DBL_MAX; }
};

When I did the merge I avoided the use of NumberTraits completely,
instead just using FLT_MAX in the init codes as this is sufficient for
the way BoundingBox functions in either float or double cases.

Robert.

On Wed, Oct 29, 2008 at 9:49 PM, Tim Moore <[EMAIL PROTECTED]> wrote:
> Hello,
> Double precision versions of BoundingBox and BoundingSphere are useful for
> doing computations in world coordinates, especially when working with a
> geocentric scene. By default, these classes are built using floats, so
> templated versions fill a need. I've used the double precision templates to
> fix some problems with ViewDependentShadow, which will follow shortly.
>
> In case it's not clear from the tar file, src/osg/BoundingBox.cpp and
> src/osg/BoundingSphere.cpp are deleted.
>
> Tim
>
>
>
> >From 621d264d8e5fbdaebed311b0359829597152cc71 Mon Sep 17 00:00:00 2001
> From: Tim Moore <[EMAIL PROTECTED]>
> Date: Tue, 28 Oct 2008 12:17:51 +0100
> Subject: [PATCH] Turn BoundingBox, BoundingSphere into templates
>
> The types BoundingBoxf, BoundingBoxd, BoundingSpheref, BoundingSphered
> are always defined.
> ---
>  include/osg/BoundingBox         |   89 ++++++++++++----
>  include/osg/BoundingSphere      |  214
> ++++++++++++++++++++++++++++++++++-----
>  include/osg/ConvexPlanarPolygon |    3 -
>  include/osg/NumberTraits        |   37 +++++++
>  src/osg/BoundingBox.cpp         |   45 --------
>  src/osg/BoundingSphere.cpp      |  209
> --------------------------------------
>  src/osg/CMakeLists.txt          |    4 +-
>  7 files changed, 293 insertions(+), 308 deletions(-)
>  create mode 100644 include/osg/NumberTraits
>  delete mode 100644 src/osg/BoundingBox.cpp
>  delete mode 100644 src/osg/BoundingSphere.cpp
>
> diff --git a/include/osg/BoundingBox b/include/osg/BoundingBox
> index f4ca8e0..777d163 100644
> --- a/include/osg/BoundingBox
> +++ b/include/osg/BoundingBox
> @@ -16,30 +16,25 @@
>
>  #include <osg/Config>
>  #include <osg/Export>
> +#include <osg/NumberTraits>
>  #include <osg/Vec3>
>  #include <osg/Vec3d>
> -#include <float.h>
>
>  namespace osg {
>
> -class BoundingSphere;
> +template<typename VT>
> +class BoundingSphereImpl;
>
>  /** General purpose axis-aligned bounding box class for enclosing
> objects/vertices.
>   * Bounds leaf objects in a scene such as osg::Drawable objects. Used for
> frustum
>   * culling etc.
>  */
> -class OSG_EXPORT BoundingBox
> +template<typename VT>
> +class BoundingBoxImpl
>  {
>     public:
> -
> -#ifdef OSG_USE_FLOAT_BOUNDINGBOX
> -        typedef Vec3f vec_type;
> -        typedef float value_type;
> -#else
> -        typedef Vec3d vec_type;
> -        typedef double value_type;
> -#endif
> -
> +        typedef VT vec_type;
> +        typedef typename VT::value_type value_type;
>
>         /** Minimum extent. (Smallest X, Y, and Z values of all
> coordinates.) */
>         vec_type _min;
> @@ -47,25 +42,35 @@ class OSG_EXPORT BoundingBox
>         vec_type _max;
>
>         /** Creates an uninitialized bounding box. */
> -        inline BoundingBox() : _min(FLT_MAX,FLT_MAX,FLT_MAX),
> -                        _max(-FLT_MAX,-FLT_MAX,-FLT_MAX) {}
> +        inline BoundingBoxImpl() :
> +            _min(NumberTraits<value_type>::maxNumber(),
> +                 NumberTraits<value_type>::maxNumber(),
> +                 NumberTraits<value_type>::maxNumber()),
> +            _max(-NumberTraits<value_type>::maxNumber(),
> +                 -NumberTraits<value_type>::maxNumber(),
> +                 -NumberTraits<value_type>::maxNumber())
> +        {}
>
>         /** Creates a bounding box initialized to the given extents. */
> -        inline BoundingBox(value_type xmin, value_type ymin, value_type
> zmin,
> +        inline BoundingBoxImpl(value_type xmin, value_type ymin, value_type
> zmin,
>                            value_type xmax, value_type ymax, value_type
> zmax) :
>                            _min(xmin,ymin,zmin),
>                            _max(xmax,ymax,zmax) {}
>
>         /** Creates a bounding box initialized to the given extents. */
> -        inline BoundingBox(const vec_type& min,const vec_type& max) :
> +        inline BoundingBoxImpl(const vec_type& min,const vec_type& max) :
>                     _min(min),
>                     _max(max) {}
>
>         /** Clear the bounding box. Erases existing minimum and maximum
> extents. */
>         inline void init()
>         {
> -            _min.set(FLT_MAX,FLT_MAX,FLT_MAX);
> -            _max.set(-FLT_MAX,-FLT_MAX,-FLT_MAX);
> +            _min.set(NumberTraits<value_type>::maxNumber(),
> +                     NumberTraits<value_type>::maxNumber(),
> +                     NumberTraits<value_type>::maxNumber());
> +            _max.set(-NumberTraits<value_type>::maxNumber(),
> +                     -NumberTraits<value_type>::maxNumber(),
> +                     -NumberTraits<value_type>::maxNumber());
>         }
>
>         /** Returns true if the bounding box extents are valid, false
> otherwise. */
> @@ -168,22 +173,22 @@ class OSG_EXPORT BoundingBox
>
>         /** Expands this bounding box to include the given bounding box.
>           * If this box is uninitialized, set it equal to bb. */
> -        void expandBy(const BoundingBox& bb);
> +        void expandBy(const BoundingBoxImpl& bb);
>
>         /** Expands this bounding box to include the given sphere.
>           * If this box is uninitialized, set it to include sh. */
> -        void expandBy(const BoundingSphere& sh);
> +        void expandBy(const BoundingSphereImpl<VT>& sh);
>
>
>         /** Returns the intersection of this bounding box and the specified
> bounding box. */
> -        BoundingBox intersect(const BoundingBox& bb) const
> -        {    return
> osg::BoundingBox(osg::maximum(xMin(),bb.xMin()),osg::maximum(yMin(),bb.yMin()),osg::maximum(zMin(),bb.zMin()),
> +        BoundingBoxImpl intersect(const BoundingBoxImpl& bb) const
> +        {    return
> BoundingBoxImpl(osg::maximum(xMin(),bb.xMin()),osg::maximum(yMin(),bb.yMin()),osg::maximum(zMin(),bb.zMin()),
>
>  
> osg::minimum(xMax(),bb.xMax()),osg::minimum(yMax(),bb.yMax()),osg::minimum(zMax(),bb.zMax()));
>
>         }
>
>         /** Return true if this bounding box intersects the specified
> bounding box. */
> -        bool intersects(const BoundingBox& bb) const
> +        bool intersects(const BoundingBoxImpl& bb) const
>         {    return osg::maximum(xMin(),bb.xMin()) <=
> osg::minimum(xMax(),bb.xMax()) &&
>                     osg::maximum(yMin(),bb.yMin()) <=
> osg::minimum(yMax(),bb.yMax()) &&
>                     osg::maximum(zMin(),bb.zMin()) <=
> osg::minimum(zMax(),bb.zMax());
> @@ -200,6 +205,44 @@ class OSG_EXPORT BoundingBox
>         }
>  };
>
> +template<typename VT>
> +void BoundingBoxImpl<VT>::expandBy(const BoundingBoxImpl<VT>& bb)
> +{
> +    if (!bb.valid()) return;
> +
> +    if(bb._min.x()<_min.x()) _min.x() = bb._min.x();
> +    if(bb._max.x()>_max.x()) _max.x() = bb._max.x();
> +
> +    if(bb._min.y()<_min.y()) _min.y() = bb._min.y();
> +    if(bb._max.y()>_max.y()) _max.y() = bb._max.y();
> +
> +    if(bb._min.z()<_min.z()) _min.z() = bb._min.z();
> +    if(bb._max.z()>_max.z()) _max.z() = bb._max.z();
> +}
> +
> +template<typename VT>
> +void BoundingBoxImpl<VT>::expandBy(const BoundingSphereImpl<VT>& sh)
> +{
> +    if (!sh.valid()) return;
> +
> +    if(sh._center.x()-sh._radius<_min.x()) _min.x() =
> sh._center.x()-sh._radius;
> +    if(sh._center.x()+sh._radius>_max.x()) _max.x() =
> sh._center.x()+sh._radius;
> +
> +    if(sh._center.y()-sh._radius<_min.y()) _min.y() =
> sh._center.y()-sh._radius;
> +    if(sh._center.y()+sh._radius>_max.y()) _max.y() =
> sh._center.y()+sh._radius;
> +
> +    if(sh._center.z()-sh._radius<_min.z()) _min.z() =
> sh._center.z()-sh._radius;
> +    if(sh._center.z()+sh._radius>_max.z()) _max.z() =
> sh._center.z()+sh._radius;
> +}
> +
> +typedef BoundingBoxImpl<Vec3f> BoundingBoxf;
> +typedef BoundingBoxImpl<Vec3d> BoundingBoxd;
> +#ifdef OSG_USE_FLOAT_BOUNDINGBOX
> +typedef BoundingBoxf BoundingBox;
> +#else
> +typedef BoundingBoxd BoundingBox;
> +#endif
> +
>  }
>
>  #endif
> diff --git a/include/osg/BoundingSphere b/include/osg/BoundingSphere
> index 4a44229..d20dc5f 100644
> --- a/include/osg/BoundingSphere
> +++ b/include/osg/BoundingSphere
> @@ -21,7 +21,8 @@
>
>  namespace osg {
>
> -class BoundingBox;
> +template<typename VT>
> +class BoundingBoxImpl;
>
>  /** General purpose bounding sphere class for enclosing
> nodes/objects/vertices.
>   * Bounds internal osg::Nodes in the scene, assists in view frustum
> culling,
> @@ -29,32 +30,26 @@ class BoundingBox;
>   * culling but generally will not cull as aggressively because it encloses
> a
>   * greater volume.
>  */
> -class OSG_EXPORT BoundingSphere
> +template<typename VT>
> +class BoundingSphereImpl
>  {
>     public:
> -
> -#ifdef OSG_USE_FLOAT_BOUNDINGSPHERE
> -        typedef Vec3f vec_type;
> -        typedef float value_type;
> -#else
> -        typedef Vec3d vec_type;
> -        typedef double value_type;
> -#endif
> -
> +        typedef VT vec_type;
> +        typedef typename vec_type::value_type value_type;
>         vec_type    _center;
>         value_type  _radius;
>
>         /** Construct a default bounding sphere with radius to -1.0f,
> representing an invalid/unset bounding sphere.*/
> -        BoundingSphere() : _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. */
> -        BoundingSphere(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. */
> -        BoundingSphere(const BoundingSphere& bs) :
> _center(bs._center),_radius(bs._radius) {}
> +        BoundingSphereImpl(const BoundingSphereImpl& bs) :
> _center(bs._center),_radius(bs._radius) {}
>
>         /** Creates a bounding sphere initialized to the given extents. */
> -        BoundingSphere(const BoundingBox& bb) :
> _center(0.0,0.0,0.0),_radius(-1.0) { expandBy(bb); }
> +        BoundingSphereImpl(const BoundingBoxImpl<VT>& bb) :
> _center(0.0,0.0,0.0),_radius(-1.0) { expandBy(bb); }
>
>         /** Clear the bounding sphere. Reset to default values. */
>         inline void init()
> @@ -93,13 +88,15 @@ class OSG_EXPORT BoundingSphere
>         /** Expands the sphere to encompass the given point. Repositions the
>           * sphere center to minimize the radius increase. If the sphere is
>           * uninitialized, set its center to v and radius to zero. */
> -        void expandBy(const Vec3f& v);
> +        template<typename vector_type>
> +        void expandBy(const vector_type& v);
>
>         /** Expands the sphere to encompass the given point. Does not
>           * reposition the sphere center. If the sphere is
>           * uninitialized, set its center to v and radius to zero. */
> -        void expandRadiusBy(const Vec3f& v);
> -
> +        template<typename vector_type>
> +        void expandRadiusBy(const vector_type& v);
> +#if 0
>         /** Expands the sphere to encompass the given point. Repositions the
>           * sphere center to minimize the radius increase. If the sphere is
>           * uninitialized, set its center to v and radius to zero. */
> @@ -109,24 +106,24 @@ class OSG_EXPORT BoundingSphere
>           * reposition the sphere center. If the sphere is
>           * uninitialized, set its center to v and radius to zero. */
>         void expandRadiusBy(const Vec3d& v);
> -
> +#endif
>         /** Expands the sphere to encompass the given sphere. Repositions
> the
>           * sphere center to minimize the radius increase. If the sphere is
>           * uninitialized, set its center and radius to match sh. */
> -        void expandBy(const BoundingSphere& sh);
> +        void expandBy(const BoundingSphereImpl<VT>& sh);
>
>         /** Expands the sphere to encompass the given sphere. Does not
>           * repositions the sphere center. If the sphere is
>           * uninitialized, set its center and radius to match sh. */
> -        void expandRadiusBy(const BoundingSphere& sh);
> +        void expandRadiusBy(const BoundingSphereImpl<VT>& sh);
>
>         /** Expands the sphere to encompass the given box. Repositions the
>           * sphere center to minimize the radius increase. */
> -        void expandBy(const BoundingBox& bb);
> +        void expandBy(const BoundingBoxImpl<VT>& bb);
>
>         /** Expands the sphere to encompass the given box. Does not
>           * repositions the sphere center. */
> -        void expandRadiusBy(const BoundingBox& bb);
> +        void expandRadiusBy(const BoundingBoxImpl<VT>& bb);
>
>         /** Returns true if v is within the sphere. */
>         inline bool contains(const vec_type& v) const
> @@ -137,14 +134,181 @@ class OSG_EXPORT BoundingSphere
>
>         /** Returns true if there is a non-empty intersection with the given
>           * bounding sphere. */
> -        inline bool intersects( const BoundingSphere& bs ) const
> +        inline bool intersects( const BoundingSphereImpl<VT>& bs ) const
>         {
>             return valid() && bs.valid() &&
>                    ((_center - bs._center).length2() <= (_radius +
> bs._radius)*(_radius + bs._radius));
>         }
> -
> +
>  };
>
> +
> +template<typename VT>
> + template<typename vector_type>
> +void BoundingSphereImpl<VT>::expandBy(const vector_type& v)
> +{
> +    if (valid())
> +    {
> +        vec_type dv = v-_center;
> +        value_type r = dv.length();
> +        if (r>_radius)
> +        {
> +            value_type dr = (r-_radius)*0.5;
> +            _center += dv*(dr/r);
> +            _radius += dr;
> +        } // else do nothing as vertex is within sphere.
> +    }
> +    else
> +    {
> +        _center = v;
> +        _radius = 0.0;
> +    }
> +}
> +
> +template<typename VT>
> + template<typename vector_type>
> +void BoundingSphereImpl<VT>::expandRadiusBy(const vector_type& v)
> +{
> +    if (valid())
> +    {
> +        value_type r = (v-_center).length();
> +        if (r>_radius) _radius = r;
> +        // else do nothing as vertex is within sphere.
> +    }
> +    else
> +    {
> +        _center = v;
> +        _radius = 0.0;
> +    }
> +}
> +
> +template<typename VT>
> +void BoundingSphereImpl<VT>::expandBy(const BoundingSphereImpl& sh)
> +{
> +    // ignore operation if incomming BoundingSphere is invalid.
> +    if (!sh.valid()) return;
> +
> +    // This sphere is not set so use the inbound sphere
> +    if (!valid())
> +    {
> +        _center = sh._center;
> +        _radius = sh._radius;
> +
> +        return;
> +    }
> +
> +
> +    // Calculate d == The distance between the sphere centers
> +    double d = ( _center - sh.center() ).length();
> +
> +    // New sphere is already inside this one
> +    if ( d + sh.radius() <= _radius )
> +    {
> +        return;
> +    }
> +
> +    //  New sphere completely contains this one
> +    if ( d + _radius <= sh.radius() )
> +    {
> +        _center = sh._center;
> +        _radius = sh._radius;
> +        return;
> +    }
> +
> +
> +    // Build a new sphere that completely contains the other two:
> +    //
> +    // The center point lies halfway along the line between the furthest
> +    // points on the edges of the two spheres.
> +    //
> +    // Computing those two points is ugly - so we'll use similar triangles
> +    double new_radius = (_radius + d + sh.radius() ) * 0.5;
> +    double ratio = ( new_radius - _radius ) / d ;
> +
> +    _center[0] += ( sh.center()[0] - _center[0] ) * ratio;
> +    _center[1] += ( sh.center()[1] - _center[1] ) * ratio;
> +    _center[2] += ( sh.center()[2] - _center[2] ) * ratio;
> +
> +    _radius = new_radius;
> +
> +}
> +
> +template<typename VT>
> +void BoundingSphereImpl<VT>::expandRadiusBy(const BoundingSphereImpl& sh)
> +{
> +    if (sh.valid())
> +    {
> +        if (valid())
> +        {
> +            value_type r = (sh._center-_center).length()+sh._radius;
> +            if (r>_radius) _radius = r;
> +            // else do nothing as vertex is within sphere.
> +        }
> +        else
> +        {
> +            _center = sh._center;
> +            _radius = sh._radius;
> +        }
> +    }
> +}
> +
> +template<typename VT>
> +void BoundingSphereImpl<VT>::expandBy(const BoundingBoxImpl<VT>& bb)
> +{
> +    if (bb.valid())
> +    {
> +        if (valid())
> +        {
> +            BoundingBoxImpl<vec_type> newbb(bb);
> +
> +            for(unsigned int c=0;c<8;++c)
> +            {
> +                vec_type v = bb.corner(c)-_center; // get the direction
> vector from corner
> +                v.normalize(); // normalise it.
> +                v *= -_radius; // move the vector in the opposite direction
> distance radius.
> +                v += _center; // move to absolute position.
> +                newbb.expandBy(v); // add it into the new bounding box.
> +            }
> +
> +            _center = newbb.center();
> +            _radius = newbb.radius();
> +
> +        }
> +        else
> +        {
> +            _center = bb.center();
> +            _radius = bb.radius();
> +        }
> +    }
> +}
> +
> +template<typename VT>
> +void BoundingSphereImpl<VT>::expandRadiusBy(const BoundingBoxImpl<VT>& bb)
> +{
> +    if (bb.valid())
> +    {
> +        if (valid())
> +        {
> +            for(unsigned int c=0;c<8;++c)
> +            {
> +                expandRadiusBy(bb.corner(c));
> +            }
> +        }
> +        else
> +        {
> +            _center = bb.center();
> +            _radius = bb.radius();
> +        }
> +    }
> +}
> +
> +typedef BoundingSphereImpl<Vec3f> BoundingSpheref;
> +typedef BoundingSphereImpl<Vec3d> BoundingSphered;
> +#ifdef OSG_USE_FLOAT_BOUNDINGSPHERE
> +        typedef BoundingSpheref BoundingSphere;
> +#else
> +        typedef BoundingSphered BoundingSphere;
> +#endif
>  }
>
>  #endif
> diff --git a/include/osg/ConvexPlanarPolygon
> b/include/osg/ConvexPlanarPolygon
> index e5d10f1..8c4546b 100644
> --- a/include/osg/ConvexPlanarPolygon
> +++ b/include/osg/ConvexPlanarPolygon
> @@ -20,9 +20,6 @@
>
>  namespace osg {
>
> -class BoundingBox;
> -class BoundingSphere;
> -
>  /** A class for representing components of convex clipping volumes. */
>  class OSG_EXPORT ConvexPlanarPolygon
>  {
> diff --git a/include/osg/NumberTraits b/include/osg/NumberTraits
> new file mode 100644
> index 0000000..6c46e75
> --- /dev/null
> +++ b/include/osg/NumberTraits
> @@ -0,0 +1,37 @@
> +/* -*-c++-*-
> + *
> + * 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 OSG_NUMBERTRAITS
> +#define OSG_NUMBERTRAITS 1
> +#include <float.h>
> +
> +namespace osg {
> +
> +template<typename NT> class NumberTraits;
> +
> +template<>
> +class NumberTraits<float>
> +{
> +public:
> +    static inline float maxNumber() { return FLT_MAX; }
> +};
> +
> +template<>
> +class NumberTraits<double>
> +{
> +public:
> +    static inline float maxNumber() { return DBL_MAX; }
> +};
> +
> +}
> +#endif
> diff --git a/src/osg/BoundingBox.cpp b/src/osg/BoundingBox.cpp
> deleted file mode 100644
> index 3f64403..0000000
> --- a/src/osg/BoundingBox.cpp
> +++ /dev/null
> @@ -1,45 +0,0 @@
> -/* -*-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 <osg/BoundingBox>
> -#include <osg/BoundingSphere>
> -
> -using namespace osg;
> -
> -void BoundingBox::expandBy(const BoundingBox& bb)
> -{
> -    if (!bb.valid()) return;
> -
> -    if(bb._min.x()<_min.x()) _min.x() = bb._min.x();
> -    if(bb._max.x()>_max.x()) _max.x() = bb._max.x();
> -
> -    if(bb._min.y()<_min.y()) _min.y() = bb._min.y();
> -    if(bb._max.y()>_max.y()) _max.y() = bb._max.y();
> -
> -    if(bb._min.z()<_min.z()) _min.z() = bb._min.z();
> -    if(bb._max.z()>_max.z()) _max.z() = bb._max.z();
> -}
> -
> -
> -void BoundingBox::expandBy(const BoundingSphere& sh)
> -{
> -    if (!sh.valid()) return;
> -
> -    if(sh._center.x()-sh._radius<_min.x()) _min.x() =
> sh._center.x()-sh._radius;
> -    if(sh._center.x()+sh._radius>_max.x()) _max.x() =
> sh._center.x()+sh._radius;
> -
> -    if(sh._center.y()-sh._radius<_min.y()) _min.y() =
> sh._center.y()-sh._radius;
> -    if(sh._center.y()+sh._radius>_max.y()) _max.y() =
> sh._center.y()+sh._radius;
> -
> -    if(sh._center.z()-sh._radius<_min.z()) _min.z() =
> sh._center.z()-sh._radius;
> -    if(sh._center.z()+sh._radius>_max.z()) _max.z() =
> sh._center.z()+sh._radius;
> -}
> diff --git a/src/osg/BoundingSphere.cpp b/src/osg/BoundingSphere.cpp
> deleted file mode 100644
> index 558eb15..0000000
> --- a/src/osg/BoundingSphere.cpp
> +++ /dev/null
> @@ -1,209 +0,0 @@
> -/* -*-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 <osg/BoundingSphere>
> -#include <osg/BoundingBox>
> -
> -using namespace osg;
> -
> -void BoundingSphere::expandBy(const Vec3f& v)
> -{
> -    if (valid())
> -    {
> -        vec_type dv = v-_center;
> -        value_type r = dv.length();
> -        if (r>_radius)
> -        {
> -            value_type dr = (r-_radius)*0.5;
> -            _center += dv*(dr/r);
> -            _radius += dr;
> -        } // else do nothing as vertex is within sphere.
> -    }
> -    else
> -    {
> -        _center = v;
> -        _radius = 0.0;
> -    }
> -}
> -
> -
> -void BoundingSphere::expandRadiusBy(const Vec3f& v)
> -{
> -    if (valid())
> -    {
> -        value_type r = (v-_center).length();
> -        if (r>_radius) _radius = r;
> -        // else do nothing as vertex is within sphere.
> -    }
> -    else
> -    {
> -        _center = v;
> -        _radius = 0.0;
> -    }
> -}
> -
> -
> -
> -void BoundingSphere::expandBy(const Vec3d& v)
> -{
> -    if (valid())
> -    {
> -        vec_type dv = v-_center;
> -        value_type r = dv.length();
> -        if (r>_radius)
> -        {
> -            value_type dr = (r-_radius)*0.5;
> -            _center += dv*(dr/r);
> -            _radius += dr;
> -        } // else do nothing as vertex is within sphere.
> -    }
> -    else
> -    {
> -        _center = v;
> -        _radius = 0.0;
> -    }
> -}
> -
> -
> -void BoundingSphere::expandRadiusBy(const Vec3d& v)
> -{
> -    if (valid())
> -    {
> -        value_type r = (v-_center).length();
> -        if (r>_radius) _radius = r;
> -        // else do nothing as vertex is within sphere.
> -    }
> -    else
> -    {
> -        _center = v;
> -        _radius = 0.0;
> -    }
> -}
> -
> -
> -
> -void BoundingSphere::expandBy(const BoundingSphere& sh)
> -{
> -    // ignore operation if incomming BoundingSphere is invalid.
> -    if (!sh.valid()) return;
> -
> -    // This sphere is not set so use the inbound sphere
> -    if (!valid())
> -    {
> -        _center = sh._center;
> -        _radius = sh._radius;
> -
> -        return;
> -    }
> -
> -
> -    // Calculate d == The distance between the sphere centers
> -    double d = ( _center - sh.center() ).length();
> -
> -    // New sphere is already inside this one
> -    if ( d + sh.radius() <= _radius )
> -    {
> -        return;
> -    }
> -
> -    //  New sphere completely contains this one
> -    if ( d + _radius <= sh.radius() )
> -    {
> -        _center = sh._center;
> -        _radius = sh._radius;
> -        return;
> -    }
> -
> -
> -    // Build a new sphere that completely contains the other two:
> -    //
> -    // The center point lies halfway along the line between the furthest
> -    // points on the edges of the two spheres.
> -    //
> -    // Computing those two points is ugly - so we'll use similar triangles
> -    double new_radius = (_radius + d + sh.radius() ) * 0.5;
> -    double ratio = ( new_radius - _radius ) / d ;
> -
> -    _center[0] += ( sh.center()[0] - _center[0] ) * ratio;
> -    _center[1] += ( sh.center()[1] - _center[1] ) * ratio;
> -    _center[2] += ( sh.center()[2] - _center[2] ) * ratio;
> -
> -    _radius = new_radius;
> -
> -}
> -
> -
> -void BoundingSphere::expandRadiusBy(const BoundingSphere& sh)
> -{
> -    if (sh.valid())
> -    {
> -        if (valid())
> -        {
> -            value_type r = (sh._center-_center).length()+sh._radius;
> -            if (r>_radius) _radius = r;
> -            // else do nothing as vertex is within sphere.
> -        }
> -        else
> -        {
> -            _center = sh._center;
> -            _radius = sh._radius;
> -        }
> -    }
> -}
> -
> -void BoundingSphere::expandBy(const BoundingBox& bb)
> -{
> -    if (bb.valid())
> -    {
> -        if (valid())
> -        {
> -            BoundingBox newbb(bb);
> -
> -            for(unsigned int c=0;c<8;++c)
> -            {
> -                Vec3 v = bb.corner(c)-_center; // get the direction vector
> from corner
> -                v.normalize(); // normalise it.
> -                v *= -_radius; // move the vector in the opposite direction
> distance radius.
> -                v += _center; // move to absolute position.
> -                newbb.expandBy(v); // add it into the new bounding box.
> -            }
> -
> -            _center = newbb.center();
> -            _radius = newbb.radius();
> -
> -        }
> -        else
> -        {
> -            _center = bb.center();
> -            _radius = bb.radius();
> -        }
> -    }
> -}
> -
> -void BoundingSphere::expandRadiusBy(const BoundingBox& bb)
> -{
> -    if (bb.valid())
> -    {
> -        if (valid())
> -        {
> -            for(unsigned int c=0;c<8;++c)
> -            {
> -                expandRadiusBy(bb.corner(c));
> -            }
> -        }
> -        else
> -        {
> -            _center = bb.center();
> -            _radius = bb.radius();
> -        }
> -    }
> -}
> diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt
> index 54e3327..2ffb034 100644
> --- a/src/osg/CMakeLists.txt
> +++ b/src/osg/CMakeLists.txt
> @@ -30,7 +30,6 @@ SET(LIB_PUBLIC_HEADERS
>     ${HEADER_PATH}/BlendColor
>     ${HEADER_PATH}/BlendEquation
>     ${HEADER_PATH}/BlendFunc
> -    ${HEADER_PATH}/BoundingBox
>     ${HEADER_PATH}/BoundingSphere
>     ${HEADER_PATH}/BoundsChecking
>     ${HEADER_PATH}/buffered_value
> @@ -105,6 +104,7 @@ SET(LIB_PUBLIC_HEADERS
>     ${HEADER_PATH}/NodeTrackerCallback
>     ${HEADER_PATH}/NodeVisitor
>     ${HEADER_PATH}/Notify
> +    ${HEADER_PATH}/NumberTraits
>     ${HEADER_PATH}/Object
>     ${HEADER_PATH}/observer_ptr
>     ${HEADER_PATH}/OccluderNode
> @@ -197,8 +197,6 @@ ADD_LIBRARY(${LIB_NAME}
>     BlendColor.cpp
>     BlendEquation.cpp
>     BlendFunc.cpp
> -    BoundingBox.cpp
> -    BoundingSphere.cpp
>     BufferObject.cpp
>     Camera.cpp
>     CameraView.cpp
> --
> 1.5.5.1
>
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to