Translated a number of comments and corrected a small bug (adding a null box does nothing also for transformed box)

This commit is contained in:
Paolo Cignoni 2016-10-20 12:40:01 +02:00
parent be72f858e4
commit 73d84303de
1 changed files with 33 additions and 37 deletions

View File

@ -72,35 +72,36 @@ public:
{ {
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. /** Offset of a vector (s,s,s)
@param s Valore scalare che indica di quanto deve variare il bounding box
*/ */
void Offset( const BoxScalarType s ) void Offset( const BoxScalarType s )
{ {
Offset( Point3<BoxScalarType> (s,s,s)); Offset( Point3<BoxScalarType> (s,s,s));
} }
/** Varia le dimensioni del bounding box del valore fornito attraverso il parametro. /** Offset the two corner of the box of a vector delta.
@param delta Point in 3D space * adding delta to max and -delta to min.
@param delta offset vector
*/ */
void Offset( const Point3<BoxScalarType> & delta ) void Offset( const Point3<BoxScalarType> & delta )
{ {
min -= delta; min -= delta;
max += delta; max += delta;
} }
/// Initializing the bounding box /// Initializing the bounding box
void Set( const Point3<BoxScalarType> & p ) void Set( const Point3<BoxScalarType> & p )
{ {
min = max = p; min = max = p;
} }
/// Set the bounding box to a null value
/// Set the bounding box to a null value
void SetNull() void SetNull()
{ {
min.X()= 1; max.X()= -1; min.X()= 1; max.X()= -1;
min.Y()= 1; max.Y()= -1; min.Y()= 1; max.Y()= -1;
min.Z()= 1; max.Z()= -1; min.Z()= 1; max.Z()= -1;
} }
/** Function to add two bounding box /** Modify the current bbox to contain also the passed box.
@param b Il bounding box che si vuole aggiungere * Adding a null bounding box does nothing
*/ */
void Add( Box3<BoxScalarType> const & b ) void Add( Box3<BoxScalarType> const & b )
{ {
@ -117,9 +118,7 @@ public:
if(max.Z() < b.max.Z()) max.Z() = b.max.Z(); if(max.Z() < b.max.Z()) max.Z() = b.max.Z();
} }
} }
/** Funzione per aggiungere un punto al bounding box. Il bounding box viene modificato se il punto /** Modify the current bbox to contain also the passed point
cade fuori da esso.
@param p The point 3D
*/ */
void Add( const Point3<BoxScalarType> & p ) void Add( const Point3<BoxScalarType> & p )
{ {
@ -136,9 +135,7 @@ public:
} }
} }
/** Function to add a sphere (a point + radius) to a bbox /** Modify the current bbox to contain also the passed sphere
@param p The point 3D
@param radius the radius of the sphere centered on p
*/ */
void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius ) void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
{ {
@ -154,19 +151,22 @@ void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
max.Z() = std::max(max.Z(),p.Z()+radius); max.Z() = std::max(max.Z(),p.Z()+radius);
} }
} }
// Aggiunge ad un box un altro box trasformato secondo la matrice m /** Modify the current bbox to contain also the box b trasformed according to the matrix m
*/
void Add( const Matrix44<BoxScalarType> &m, const Box3<BoxScalarType> & b ) void Add( const Matrix44<BoxScalarType> &m, const Box3<BoxScalarType> & b )
{ {
const Point3<BoxScalarType> &mn= b.min; if(b.IsNull()) return; // Adding a null bbox should do nothing
const Point3<BoxScalarType> &mx= b.max;
const Point3<BoxScalarType> &mn= b.min;
const Point3<BoxScalarType> &mx= b.max;
Add(m*(Point3<BoxScalarType>(mn[0],mn[1],mn[2]))); Add(m*(Point3<BoxScalarType>(mn[0],mn[1],mn[2])));
Add(m*(Point3<BoxScalarType>(mx[0],mn[1],mn[2]))); Add(m*(Point3<BoxScalarType>(mx[0],mn[1],mn[2])));
Add(m*(Point3<BoxScalarType>(mn[0],mx[1],mn[2]))); Add(m*(Point3<BoxScalarType>(mn[0],mx[1],mn[2])));
Add(m*(Point3<BoxScalarType>(mx[0],mx[1],mn[2]))); Add(m*(Point3<BoxScalarType>(mx[0],mx[1],mn[2])));
Add(m*(Point3<BoxScalarType>(mn[0],mn[1],mx[2]))); Add(m*(Point3<BoxScalarType>(mn[0],mn[1],mx[2])));
Add(m*(Point3<BoxScalarType>(mx[0],mn[1],mx[2]))); Add(m*(Point3<BoxScalarType>(mx[0],mn[1],mx[2])));
Add(m*(Point3<BoxScalarType>(mn[0],mx[1],mx[2]))); Add(m*(Point3<BoxScalarType>(mn[0],mx[1],mx[2])));
Add(m*(Point3<BoxScalarType>(mx[0],mx[1],mx[2]))); Add(m*(Point3<BoxScalarType>(mx[0],mx[1],mx[2])));
} }
/** Calcola l'intersezione tra due bounding box. Al bounding box viene assegnato il valore risultante. /** Calcola l'intersezione tra due bounding box. Al bounding box viene assegnato il valore risultante.
@param b Il bounding box con il quale si vuole effettuare l'intersezione @param b Il bounding box con il quale si vuole effettuare l'intersezione
@ -191,9 +191,7 @@ void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
min += p; min += p;
max += p; max += p;
} }
/** Verifica se un punto appartiene ad un bounding box. /** true if the point belong to the closed box
@param p The point 3D
@return True se p appartiene al bounding box, false altrimenti
*/ */
bool IsIn( Point3<BoxScalarType> const & p ) const bool IsIn( Point3<BoxScalarType> const & p ) const
{ {
@ -203,9 +201,8 @@ void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
min.Z() <= p.Z() && p.Z() <= max.Z() min.Z() <= p.Z() && p.Z() <= max.Z()
); );
} }
/** Verifica se un punto appartiene ad un bounding box aperto sul max. /** true if the point belong to the open box (open on the max side)
@param p The point 3D * e.g. if p in [min,max)
@return True se p appartiene al bounding box, false altrimenti
*/ */
bool IsInEx( Point3<BoxScalarType> const & p ) const bool IsInEx( Point3<BoxScalarType> const & p ) const
{ {
@ -234,15 +231,14 @@ void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
b.min.Y()<max.Y() && b.max.Y()>min.Y() && b.min.Y()<max.Y() && b.max.Y()>min.Y() &&
b.min.Z()<max.Z() && b.max.Z()>min.Z() ; b.min.Z()<max.Z() && b.max.Z()>min.Z() ;
} }
/** Controlla se il bounding box e' nullo. /**
@return True se il bounding box e' nullo, false altrimenti return true if the box is null (e.g. invalid or not initialized);
*/ */
bool IsNull() const { return min.X()>max.X() || min.Y()>max.Y() || min.Z()>max.Z(); } bool IsNull() const { return min.X()>max.X() || min.Y()>max.Y() || min.Z()>max.Z(); }
/** Controlla se il bounding box e' vuoto. /** return true if the box is empty (e.g. if min == max)
@return True se il bounding box e' vuoto, false altrimenti
*/ */
bool IsEmpty() const { return min==max; } bool IsEmpty() const { return min==max; }
/// Restituisce la lunghezza della diagonale del bounding box. /// Return the lenght of the diagonal of the box .
BoxScalarType Diag() const BoxScalarType Diag() const
{ {
return Distance(min,max); return Distance(min,max);
@ -252,7 +248,7 @@ void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
{ {
return SquaredDistance(min,max); return SquaredDistance(min,max);
} }
/// Calcola il centro del bounding box. /// Return the center of the box.
Point3<BoxScalarType> Center() const Point3<BoxScalarType> Center() const
{ {
return (min+max)/2; return (min+max)/2;
@ -277,7 +273,7 @@ void Add( const Point3<BoxScalarType> & p, const BoxScalarType radius )
(p[2]-min[2])/(max[2]-min[2]) (p[2]-min[2])/(max[2]-min[2])
); );
} }
/// Calcola il volume del bounding box. /// Return the volume of the box.
BoxScalarType Volume() const BoxScalarType Volume() const
{ {
return (max.X()-min.X())*(max.Y()-min.Y())*(max.Z()-min.Z()); return (max.X()-min.X())*(max.Y()-min.Y())*(max.Z()-min.Z());