Added doxygen groups

This commit is contained in:
Paolo Cignoni 2004-02-19 15:40:56 +00:00
parent ca807a0787
commit 04fe64ca77
1 changed files with 311 additions and 309 deletions

View File

@ -1,309 +1,311 @@
/**************************************************************************** /****************************************************************************
* VCGLib o o * * VCGLib o o *
* Visual and Computer Graphics Library o o * * Visual and Computer Graphics Library o o *
* _ O _ * * _ O _ *
* Copyright(C) 2004 \/)\/ * * Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| * * Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | * * ISTI - Italian National Research Council | *
* \ * * \ *
* All rights reserved. * * All rights reserved. *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. * * for more details. *
* * * *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.1 2004/02/13 02:16:22 cignoni
****************************************************************************/ First working release.
#ifndef __VCGLIB_BOX3 ****************************************************************************/
#define __VCGLIB_BOX3
#include <vcg/space/point3> #ifndef __VCGLIB_BOX3
#define __VCGLIB_BOX3
namespace vcg {
#include <vcg/space/point3.h>
/** @name Box3
Class Box3. namespace vcg {
This is the class for definition of a bounding box in 3D space.
@param BoxScalarType (Templete Parameter) Specifies the scalar field. /** \addtogroup space */
*/ /*@{*/
template <class BoxScalarType> /**
class Box3 Templated class for 3D boxes.
{ This is the class for definition of a axis aligned bounding box in 3D space. It is stored just as two Point3
public: @param BoxScalarType (template parameter) Specifies the type of scalar used to represent coords.
*/
/// The scalar type template <class BoxScalarType>
typedef BoxScalarType ScalarType; class Box3
{
/// min coordinate point public:
Point3<BoxScalarType> min;
/// max coordinate point /// The scalar type
Point3<BoxScalarType> max; typedef BoxScalarType ScalarType;
/// The bounding box constructor
inline Box3() { min.x()= 1;max.x()= -1;min.y()= 1;max.y()= -1;min.z()= 1;max.z()= -1;} /// min coordinate point
/// Copy constructor Point3<BoxScalarType> min;
inline Box3( const Box3 & b ) { min=b.min; max=b.max; } /// max coordinate point
/// Min Max constructor Point3<BoxScalarType> max;
inline Box3( const Point3<BoxScalarType> & mi, const Point3<BoxScalarType> & ma ) { min = mi; max = ma; } /// The bounding box constructor
/// The bounding box distructor inline Box3() { min.x()= 1;max.x()= -1;min.y()= 1;max.y()= -1;min.z()= 1;max.z()= -1;}
inline ~Box3() { } /// Copy constructor
/// Operator to compare two bounding box inline Box3( const Box3 & b ) { min=b.min; max=b.max; }
inline bool operator == ( Box3<BoxScalarType> const & p ) const /// Min Max constructor
{ inline Box3( const Point3<BoxScalarType> & mi, const Point3<BoxScalarType> & ma ) { min = mi; max = ma; }
return min==p.min && max==p.max; /// The bounding box distructor
} inline ~Box3() { }
/// Operator to dispare two bounding box /// Operator to compare two bounding box
inline bool operator != ( Box3<BoxScalarType> const & p ) const inline bool operator == ( Box3<BoxScalarType> const & p ) const
{ {
return min!=p.min || max!=p.max; return min==p.min && max==p.max;
} }
/** Varia le dimensioni del bounding box scalandole rispetto al parametro scalare. /// Operator to dispare two bounding box
@param s Valore scalare che indica di quanto deve variare il bounding box inline bool operator != ( Box3<BoxScalarType> const & p ) const
*/ {
void Inflate( const BoxScalarType s ) return min!=p.min || max!=p.max;
{ }
Inflate( (max-min)*s ); /** Varia le dimensioni del bounding box scalandole rispetto al parametro scalare.
} @param s Valore scalare che indica di quanto deve variare il bounding box
/** Varia le dimensioni del bounding box di (k,k,k) con k = bbox.diag*s */
*/ void Inflate( const BoxScalarType s )
void InflateFix( const BoxScalarType s ) {
{ Inflate( (max-min)*s );
BoxScalarType k = Diag()*s; }
Inflate( Point3<BoxScalarType> (k,k,k)); /** Varia le dimensioni del bounding box di (k,k,k) con k = bbox.diag*s
} */
/** Varia le dimensioni del bounding box del valore fornito attraverso il parametro. void InflateFix( const BoxScalarType s )
@param delta Point in 3D space {
*/ BoxScalarType k = Diag()*s;
void Inflate( const Point3<BoxScalarType> & delta ) Inflate( Point3<BoxScalarType> (k,k,k));
{ }
min -= delta; /** Varia le dimensioni del bounding box del valore fornito attraverso il parametro.
max += delta; @param delta Point in 3D space
} */
/// Initializing the bounding box void Inflate( const Point3<BoxScalarType> & delta )
void Set( const Point3<BoxScalarType> & p ) {
{ min -= delta;
min = max = p; max += delta;
} }
/// Set the bounding box to a null value /// Initializing the bounding box
void SetNull() void Set( const Point3<BoxScalarType> & p )
{ {
min.x()= 1; max.x()= -1; min = max = p;
min.y()= 1; max.y()= -1; }
min.z()= 1; max.z()= -1; /// Set the bounding box to a null value
} void SetNull()
/** Function to add two bounding box {
@param b Il bounding box che si vuole aggiungere min.x()= 1; max.x()= -1;
*/ min.y()= 1; max.y()= -1;
void Add( Box3<BoxScalarType> const & b ) min.z()= 1; max.z()= -1;
{ }
if(IsNull()) *this=b; /** Function to add two bounding box
else @param b Il bounding box che si vuole aggiungere
{ */
if(min.x() > b.min.x()) min.x() = b.min.x(); void Add( Box3<BoxScalarType> const & b )
if(min.y() > b.min.y()) min.y() = b.min.y(); {
if(min.z() > b.min.z()) min.z() = b.min.z(); if(IsNull()) *this=b;
else
if(max.x() < b.max.x()) max.x() = b.max.x(); {
if(max.y() < b.max.y()) max.y() = b.max.y(); if(min.x() > b.min.x()) min.x() = b.min.x();
if(max.z() < b.max.z()) max.z() = b.max.z(); if(min.y() > b.min.y()) min.y() = b.min.y();
} if(min.z() > b.min.z()) min.z() = b.min.z();
}
/** Funzione per aggiungere un punto al bounding box. Il bounding box viene modificato se il punto if(max.x() < b.max.x()) max.x() = b.max.x();
cade fuori da esso. if(max.y() < b.max.y()) max.y() = b.max.y();
@param p The point 3D if(max.z() < b.max.z()) max.z() = b.max.z();
*/ }
void Add( const Point3<BoxScalarType> & p ) }
{ /** Funzione per aggiungere un punto al bounding box. Il bounding box viene modificato se il punto
if(IsNull()) Set(p); cade fuori da esso.
else @param p The point 3D
{ */
if(min.x() > p.x()) min.x() = p.x(); void Add( const Point3<BoxScalarType> & p )
if(min.y() > p.y()) min.y() = p.y(); {
if(min.z() > p.z()) min.z() = p.z(); if(IsNull()) Set(p);
else
if(max.x() < p.x()) max.x() = p.x(); {
if(max.y() < p.y()) max.y() = p.y(); if(min.x() > p.x()) min.x() = p.x();
if(max.z() < p.z()) max.z() = p.z(); if(min.y() > p.y()) min.y() = p.y();
} if(min.z() > p.z()) min.z() = p.z();
}
if(max.x() < p.x()) max.x() = p.x();
// Aggiunge ad un box un altro box trasformato secondo la matrice m if(max.y() < p.y()) max.y() = p.y();
void Add( const Matrix44<BoxScalarType> &m, const Box3<BoxScalarType> & b ) if(max.z() < p.z()) max.z() = p.z();
{ }
const Point3<BoxScalarType> &mn= b.min; }
const Point3<BoxScalarType> &mx= b.max;
Add(m.Apply(Point3<BoxScalarType>(mn[0],mn[1],mn[2]))); // Aggiunge ad un box un altro box trasformato secondo la matrice m
Add(m.Apply(Point3<BoxScalarType>(mx[0],mn[1],mn[2]))); void Add( const Matrix44<BoxScalarType> &m, const Box3<BoxScalarType> & b )
Add(m.Apply(Point3<BoxScalarType>(mn[0],mx[1],mn[2]))); {
Add(m.Apply(Point3<BoxScalarType>(mx[0],mx[1],mn[2]))); const Point3<BoxScalarType> &mn= b.min;
Add(m.Apply(Point3<BoxScalarType>(mn[0],mn[1],mx[2]))); const Point3<BoxScalarType> &mx= b.max;
Add(m.Apply(Point3<BoxScalarType>(mx[0],mn[1],mx[2]))); Add(m.Apply(Point3<BoxScalarType>(mn[0],mn[1],mn[2])));
Add(m.Apply(Point3<BoxScalarType>(mn[0],mx[1],mx[2]))); Add(m.Apply(Point3<BoxScalarType>(mx[0],mn[1],mn[2])));
Add(m.Apply(Point3<BoxScalarType>(mx[0],mx[1],mx[2]))); Add(m.Apply(Point3<BoxScalarType>(mn[0],mx[1],mn[2])));
} Add(m.Apply(Point3<BoxScalarType>(mx[0],mx[1],mn[2])));
/** Calcola l'intersezione tra due bounding box. Al bounding box viene assegnato il valore risultante. Add(m.Apply(Point3<BoxScalarType>(mn[0],mn[1],mx[2])));
@param b Il bounding box con il quale si vuole effettuare l'intersezione Add(m.Apply(Point3<BoxScalarType>(mx[0],mn[1],mx[2])));
*/ Add(m.Apply(Point3<BoxScalarType>(mn[0],mx[1],mx[2])));
void Intersect( const Box3<BoxScalarType> & b ) Add(m.Apply(Point3<BoxScalarType>(mx[0],mx[1],mx[2])));
{ }
if(min.x() < b.min.x()) min.x() = b.min.x(); /** Calcola l'intersezione tra due bounding box. Al bounding box viene assegnato il valore risultante.
if(min.y() < b.min.y()) min.y() = b.min.y(); @param b Il bounding box con il quale si vuole effettuare l'intersezione
if(min.z() < b.min.z()) min.z() = b.min.z(); */
void Intersect( const Box3<BoxScalarType> & b )
if(max.x() > b.max.x()) max.x() = b.max.x(); {
if(max.y() > b.max.y()) max.y() = b.max.y(); if(min.x() < b.min.x()) min.x() = b.min.x();
if(max.z() > b.max.z()) max.z() = b.max.z(); if(min.y() < b.min.y()) min.y() = b.min.y();
if(min.z() < b.min.z()) min.z() = b.min.z();
if(min.x()>max.x() || min.y()>max.y() || min.z()>max.z()) SetNull();
} if(max.x() > b.max.x()) max.x() = b.max.x();
/** Trasla il bounding box di un valore definito dal parametro. if(max.y() > b.max.y()) max.y() = b.max.y();
@param p Il bounding box trasla sulla x e sulla y in base alle coordinate del parametro if(max.z() > b.max.z()) max.z() = b.max.z();
*/
void Translate( const Point3<BoxScalarType> & p ) if(min.x()>max.x() || min.y()>max.y() || min.z()>max.z()) SetNull();
{ }
min += p; /** Trasla il bounding box di un valore definito dal parametro.
max += p; @param p Il bounding box trasla sulla x e sulla y in base alle coordinate del parametro
} */
/** Verifica se un punto appartiene ad un bounding box. void Translate( const Point3<BoxScalarType> & p )
@param p The point 3D {
@return True se p appartiene al bounding box, false altrimenti min += p;
*/ max += p;
bool IsIn( Point3<BoxScalarType> const & p ) const }
{ /** Verifica se un punto appartiene ad un bounding box.
return ( @param p The point 3D
min.x() <= p.x() && p.x() <= max.x() && @return True se p appartiene al bounding box, false altrimenti
min.y() <= p.y() && p.y() <= max.y() && */
min.z() <= p.z() && p.z() <= max.z() bool IsIn( Point3<BoxScalarType> const & p ) const
); {
} return (
/** Verifica se un punto appartiene ad un bounding box aperto sul max. min.x() <= p.x() && p.x() <= max.x() &&
@param p The point 3D min.y() <= p.y() && p.y() <= max.y() &&
@return True se p appartiene al bounding box, false altrimenti min.z() <= p.z() && p.z() <= max.z()
*/ );
bool IsInEx( Point3<BoxScalarType> const & p ) const }
{ /** Verifica se un punto appartiene ad un bounding box aperto sul max.
return ( @param p The point 3D
min.x() <= p.x() && p.x() < max.x() && @return True se p appartiene al bounding box, false altrimenti
min.y() <= p.y() && p.y() < max.y() && */
min.z() <= p.z() && p.z() < max.z() bool IsInEx( Point3<BoxScalarType> const & p ) const
); {
} return (
/** Verifica se due bounding box collidono cioe' se hanno una intersezione non vuota. Per esempio min.x() <= p.x() && p.x() < max.x() &&
due bounding box adiacenti non collidono. min.y() <= p.y() && p.y() < max.y() &&
@param b A bounding box min.z() <= p.z() && p.z() < max.z()
@return True se collidoo, false altrimenti );
*/ }
/* old version /** Verifica se due bounding box collidono cioe' se hanno una intersezione non vuota. Per esempio
bool Collide(Box3<BoxScalarType> const &b) due bounding box adiacenti non collidono.
{ @param b A bounding box
Box3<BoxScalarType> bb=*this; @return True se collidoo, false altrimenti
bb.Intersect(b); */
return bb.IsValid(); /* old version
} bool Collide(Box3<BoxScalarType> const &b)
*/ {
bool Collide(Box3<BoxScalarType> const &b) Box3<BoxScalarType> bb=*this;
{ bb.Intersect(b);
return b.min.x()<max.x() && b.max.x()>min.x() && return bb.IsValid();
b.min.y()<max.y() && b.max.y()>min.y() && }
b.min.z()<max.z() && b.max.z()>min.z() ; */
} bool Collide(Box3<BoxScalarType> const &b)
/** Controlla se il bounding box e' nullo. {
@return True se il bounding box e' nullo, false altrimenti return b.min.x()<max.x() && b.max.x()>min.x() &&
*/ b.min.y()<max.y() && b.max.y()>min.y() &&
bool IsNull() const { return min.x()>max.x() || min.y()>max.y() || min.z()>max.z(); } b.min.z()<max.z() && b.max.z()>min.z() ;
/** Controlla se il bounding box e' vuoto. }
@return True se il bounding box e' vuoto, false altrimenti /** Controlla se il bounding box e' nullo.
*/ @return True se il bounding box e' nullo, false altrimenti
bool IsEmpty() const { return min==max; } */
/// Restituisce la lunghezza della diagonale del bounding box. bool IsNull() const { return min.x()>max.x() || min.y()>max.y() || min.z()>max.z(); }
BoxScalarType Diag() const /** Controlla se il bounding box e' vuoto.
{ @return True se il bounding box e' vuoto, false altrimenti
return Distance(min,max); */
} bool IsEmpty() const { return min==max; }
/// Calcola il quadrato della diagonale del bounding box. /// Restituisce la lunghezza della diagonale del bounding box.
BoxScalarType SquaredDiag() const BoxScalarType Diag() const
{ {
return SquaredDistance(min,max); return Distance(min,max);
} }
/// Calcola il centro del bounding box. /// Calcola il quadrato della diagonale del bounding box.
Point3<BoxScalarType> Center() const BoxScalarType SquaredDiag() const
{ {
return (min+max)/2; return SquaredDistance(min,max);
} }
/// Compute bounding box size. /// Calcola il centro del bounding box.
Point3<BoxScalarType> Dim() const Point3<BoxScalarType> Center() const
{ {
return (max-min); return (min+max)/2;
} }
/// Returns global coords of a local point expressed in [0..1]^3 /// Compute bounding box size.
Point3<BoxScalarType> LocalToGlobal(Point3<BoxScalarType> const & p) const{ Point3<BoxScalarType> Dim() const
return Point3<BoxScalarType>( {
min[0] + p[0]*(max[0]-min[0]), return (max-min);
min[1] + p[1]*(max[1]-min[1]), }
min[2] + p[2]*(max[2]-min[2])); /// Returns global coords of a local point expressed in [0..1]^3
} Point3<BoxScalarType> LocalToGlobal(Point3<BoxScalarType> const & p) const{
/// Returns local coords expressed in [0..1]^3 of a point in 3D return Point3<BoxScalarType>(
Point3<BoxScalarType> GlobalToLocal(Point3<BoxScalarType> const & p) const{ min[0] + p[0]*(max[0]-min[0]),
return Point3<BoxScalarType>( min[1] + p[1]*(max[1]-min[1]),
(p[0]-min[0])/(max[0]-min[0]), min[2] + p[2]*(max[2]-min[2]));
(p[1]-min[1])/(max[1]-min[1]), }
(p[2]-min[2])/(max[2]-min[2]) /// Returns local coords expressed in [0..1]^3 of a point in 3D
); Point3<BoxScalarType> GlobalToLocal(Point3<BoxScalarType> const & p) const{
} return Point3<BoxScalarType>(
/// Calcola il volume del bounding box. (p[0]-min[0])/(max[0]-min[0]),
BoxScalarType Volume() const (p[1]-min[1])/(max[1]-min[1]),
{ (p[2]-min[2])/(max[2]-min[2])
return (max.x()-min.x())*(max.y()-min.y())*(max.z()-min.z()); );
} }
/// Calcola la dimensione del bounding box sulla x. /// Calcola il volume del bounding box.
inline BoxScalarType DimX() const { return max.x()-min.x();} BoxScalarType Volume() const
/// Calcola la dimensione del bounding box sulla y. {
inline BoxScalarType DimY() const { return max.y()-min.y();} return (max.x()-min.x())*(max.y()-min.y())*(max.z()-min.z());
/// Calcola la dimensione del bounding box sulla z. }
inline BoxScalarType DimZ() const { return max.z()-min.z();} /// Calcola la dimensione del bounding box sulla x.
inline BoxScalarType DimX() const { return max.x()-min.x();}
template <class Q> /// Calcola la dimensione del bounding box sulla y.
inline void Import( const Box3<Q> & b ) inline BoxScalarType DimY() const { return max.y()-min.y();}
{ /// Calcola la dimensione del bounding box sulla z.
min.Import(b.min); inline BoxScalarType DimZ() const { return max.z()-min.z();}
max.Import(b.max);
} template <class Q>
inline void Import( const Box3<Q> & b )
template <class Q> {
inline Box3 Construct( const Box3<Q> & b ) min.Import(b.min);
{ max.Import(b.max);
return Box3(Point3<ScalarType>::Construct(b.min),Point3<ScalarType>::Construct(b.max)); }
}
template <class Q>
}; // end class definition inline Box3 Construct( const Box3<Q> & b )
{
return Box3(Point3<ScalarType>::Construct(b.min),Point3<ScalarType>::Construct(b.max));
}
#endif }; // end class definition
/// Specificazione di box of short
typedef Box3<short> Box3s;
/// Specificazione di box of int
typedef Box3<int> Box3i;
/// Specificazione di box of float #endif
typedef Box3<float> Box3f; typedef Box3<short> Box3s;
/// Specificazione di box of double typedef Box3<int> Box3i;
typedef Box3<double> Box3d; typedef Box3<float> Box3f;
typedef Box3<double> Box3d;
} // end namespace /*@}*/
#endif
} // end namespace
#endif