From ade2c49443beee39ddc3cd70f1d2172d550f7f03 Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Thu, 25 Mar 2021 18:13:41 +0100 Subject: [PATCH] some cleanups --- vcg/complex/base.h | 4 +- vcg/space/box.h | 2 +- vcg/space/box2.h | 285 +++++++++++++++++----------------- vcg/space/box3.h | 52 +++---- vcg/space/deprecated_point3.h | 2 +- vcg/space/deprecated_point4.h | 6 +- vcg/space/line2.h | 2 +- 7 files changed, 178 insertions(+), 175 deletions(-) diff --git a/vcg/complex/base.h b/vcg/complex/base.h index 4a1e01f9..88de7028 100644 --- a/vcg/complex/base.h +++ b/vcg/complex/base.h @@ -25,6 +25,8 @@ #define __VCG_COMPLEX_BASE #include +#include + #include #include "used_types.h" @@ -599,7 +601,7 @@ template inline bool IsMarked(const MeshType & m,typename MeshT @param m the mesh containing the element @param t tetra pointer */ template -inline bool IsMarked(MeshType &m, typename MeshType::ConstTetraPointer t) { return t->cIMark() == m.imark; } +inline bool IsMarked(const MeshType &m, typename MeshType::ConstTetraPointer t) { return t->cIMark() == m.imark; } /** \brief Set the vertex incremental mark of the vertex to the one of the mesh. @param m the mesh containing the element diff --git a/vcg/space/box.h b/vcg/space/box.h index 8cc66abb..2cb77ab1 100644 --- a/vcg/space/box.h +++ b/vcg/space/box.h @@ -49,7 +49,7 @@ First working release. #ifndef __VCGLIB_BOX #define __VCGLIB_BOX -#include +#include #include #include diff --git a/vcg/space/box2.h b/vcg/space/box2.h index 9f50e625..ad0a5854 100644 --- a/vcg/space/box2.h +++ b/vcg/space/box2.h @@ -2,7 +2,7 @@ * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * -* Copyright(C) 2004-2016 \/)\/ * +* Copyright(C) 2004-2021 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * @@ -36,54 +36,51 @@ template class Segment2; /** \addtogroup space */ /*@{*/ /** - Templated class for a 2D bounding box. It is stored just as two Point2 + Templated class for a 2D bounding box. It is stored just as two Point2 @param BoxScalarType (Template Parameter) Specifies the scalar field. */ template class Box2 { public: - /// The scalar type + /// The scalar type typedef BoxScalarType ScalarType; - typedef Point2 PointType ; + typedef Point2 PointType; - /// min coordinate point - PointType min; - /// max coordinate point - PointType max; - /// Standard constructor + /// min coordinate point + PointType min; + /// max coordinate point + PointType max; + /// Standard constructor inline Box2() { min.X()= 1; max.X()= -1; min.Y()= 1; max.Y()= -1; } - /// Copy constructor - inline Box2( const Box2 & b ) { min=b.min; max=b.max; } - /// Min Max constructor - inline Box2( const Point2 & mi, const Point2 & ma ) { min = mi; max = ma; } + /// Min Max constructor + inline Box2(const Point2 & mi, const Point2 & ma ) { min = mi; max = ma; } - inline Box2(const Point2 & center, const BoxScalarType & radius) { - min = center-Point2(radius,radius); - max = center+Point2(radius,radius); - } + inline Box2(const Point2 & center, const BoxScalarType & radius) + { + min = center-Point2(radius,radius); + max = center+Point2(radius,radius); + } - /// Distructor - inline ~Box2() { } - /// Operator to compare two bounding box + /// Operator to compare two bounding box inline bool operator == ( Box2 const & p ) const { return min==p.min && max==p.max; } - /// Initializing the bounding box with a point + /// Initializing the bounding box with a point void Set( const PointType & p ) { min = max = p; } - Point2 P(const int & i) const + Point2 P(int i) const { - return Point2( - min[0]+ (i%2) * DimX(), + return Point2( + min[0]+ (i%2) * DimX(), min[1]+ ((i / 2)%2) * DimY()); } - // Initializing with the values + // Initializing with the values inline void Set( ScalarType minx, ScalarType miny, ScalarType maxx, ScalarType maxy ) { min[0] = minx; @@ -91,15 +88,15 @@ public: max[0] = maxx; max[1] = maxy; } - /// Set the bounding box to a null value + /// Set the bounding box to a null value void SetNull() { - min.X()= 1; max.X()= -1; min.Y()= 1; max.Y()= -1; + min.X()= 1; max.X()= -1; min.Y()= 1; max.Y()= -1; } - /** Function to add two bounding box - the bounding box expand to include the other bounding box (if necessary) - @param b The bounding box to be added - */ + /** @brief Function to add two bounding box + * the bounding box expand to include the other bounding box (if necessary) + * @param b The bounding box to be added + */ void Add( Box2 const & b ) { if(IsNull()) @@ -116,14 +113,15 @@ public: if(max.Y() < b.max.Y()) max.Y() = b.max.Y(); } } - /** Adds a point to the bouning box. - the bounding box expand to include the new point (if necessary) - @param p The point 2D - */ + /** + * @brief Adds a point to the bouning box. + * the bounding box expand to include the new point (if necessary) + * @param p The point 2D + */ void Add( const PointType & p ) { if(IsNull()) Set(p); - else + else { if(min.X() > p.X()) min.X() = p.X(); if(min.Y() > p.Y()) min.Y() = p.Y(); @@ -133,26 +131,29 @@ public: } } - /** Varies the dimension of the bounding box. - @param delta The size delta (if positive, box is enlarged) - */ - void Offset(const ScalarType s) + /** + * @brief Varies the dimension of the bounding box. + * @param delta The size delta (if positive, box is enlarged) + */ + void Offset(ScalarType s) { Offset(PointType(s, s)); } - /** Varies the dimension of the bounding box. - @param delta The size delta per dimension (if positive, box is enlarged) - */ + /** + * @brief Varies the dimension of the bounding box. + * @param delta The size delta per dimension (if positive, box is enlarged) + */ void Offset(const PointType & delta) { min -= delta; max += delta; } - /** Computes intersection between this and another bounding box - @param b The other bounding box - */ + /** + * @brief Computes intersection between this and another bounding box + * @param b The other bounding box + */ void Intersect( const Box2 & b ) { if(min.X() < b.min.X()) min.X() = b.min.X(); @@ -164,114 +165,118 @@ public: if(min.X()>max.X() || min.Y()>max.Y()) SetNull(); } - /** Translate the bounding box by a vector - @param p The translation vector - */ + /** + * @brief Translate the bounding box by a vector + * @param p The translation vector + */ void Translate( const PointType & p ) { min += p; max += p; } - /** Checks whether a 2D point p is inside the box - @param p The point 2D - @return True iff p inside - */ - bool IsIn( PointType const & p ) const + /** + * @brief Checks whether a 2D point p is inside the box + * @param p The point 2D + * @return True iff p inside + */ + bool IsIn( const PointType & p ) const { return ( min.X() <= p.X() && p.X() <= max.X() && - min.Y() <= p.Y() && p.Y() <= max.Y() - ); + min.Y() <= p.Y() && p.Y() <= max.Y()); } - /** Checks whether a 2D point p is inside the box, closed at min but open at max - @param p The point in 2D - @return True iff p inside - */ - bool IsInEx( PointType const & p ) const + /** + * @brief Checks whether a 2D point p is inside the box, closed at min but open at max + * @param p The point in 2D + * @return True iff p inside + */ + bool IsInEx( const PointType & p ) const { - return ( + return ( min.X() <= p.X() && p.X() < max.X() && - min.Y() <= p.Y() && p.Y() < max.Y() - ); + min.Y() <= p.Y() && p.Y() < max.Y()); } - /** Check bbox collision. - Note: just adjiacent bbox won't collide - @param b A bounding box - @return True iff collision - */ - bool Collide( Box2 const &b ) + /** + * @brief Check bbox collision. + * Note: just adjiacent bbox won't collide + * @param b A bounding box + * @return True iff collision + */ + bool Collide( const Box2 &b ) const { Box2 bb=*this; bb.Intersect(b); return bb.IsValid(); } - /** Check if empty. - @return True iff empty - */ + /** + * Check if empty. + * @return True iff empty + */ inline bool IsNull() const { return min.X()>max.X() || min.Y()>max.Y(); } - /** Check consistency. - @return True iff consistent - */ + /** + * Check consistency. + * @return True iff consistent + */ inline bool IsValid() const { return min.X() @@ -300,36 +305,36 @@ ScalarType DistancePoint2Box2(const Point2 &test, if ((test.X()<=bbox.min.X())&&(test.Y()<=bbox.min.Y())) return ((test-bbox.min).Norm()); else - if ((test.X()>=bbox.min.X())&& - (test.X()<=bbox.max.X())&& - (test.Y()<=bbox.min.Y())) - return (bbox.min.Y()-test.Y()); - else - if ((test.X()>=bbox.max.X())&& - (test.Y()<=bbox.min.Y())) - return ((test-vcg::Point2(bbox.max.X(),bbox.min.Y())).Norm()); - else - if ((test.Y()>=bbox.min.Y())&& - (test.Y()<=bbox.max.Y())&& - (test.X()>=bbox.max.X())) - return (test.X()-bbox.max.X()); - else - if ((test.X()>=bbox.max.X())&&(test.Y()>=bbox.max.Y())) - return ((test-bbox.max).Norm()); - else - if ((test.X()>=bbox.min.X())&& - (test.X()<=bbox.max.X())&& - (test.Y()>=bbox.max.Y())) - return (test.Y()-bbox.max.Y()); - else - if ((test.X()<=bbox.min.X())&& - (test.Y()>=bbox.max.Y())) - return ((test-vcg::Point2(bbox.min.X(),bbox.max.Y())).Norm()); - else - if ((test.X()<=bbox.min.X())&& - (test.Y()<=bbox.max.Y())&& - (test.Y()>=bbox.min.Y())) - return (bbox.min.X()-test.X()); + if ((test.X()>=bbox.min.X())&& + (test.X()<=bbox.max.X())&& + (test.Y()<=bbox.min.Y())) + return (bbox.min.Y()-test.Y()); + else + if ((test.X()>=bbox.max.X())&& + (test.Y()<=bbox.min.Y())) + return ((test-vcg::Point2(bbox.max.X(),bbox.min.Y())).Norm()); + else + if ((test.Y()>=bbox.min.Y())&& + (test.Y()<=bbox.max.Y())&& + (test.X()>=bbox.max.X())) + return (test.X()-bbox.max.X()); + else + if ((test.X()>=bbox.max.X())&&(test.Y()>=bbox.max.Y())) + return ((test-bbox.max).Norm()); + else + if ((test.X()>=bbox.min.X())&& + (test.X()<=bbox.max.X())&& + (test.Y()>=bbox.max.Y())) + return (test.Y()-bbox.max.Y()); + else + if ((test.X()<=bbox.min.X())&& + (test.Y()>=bbox.max.Y())) + return ((test-vcg::Point2(bbox.min.X(),bbox.max.Y())).Norm()); + else + if ((test.X()<=bbox.min.X())&& + (test.Y()<=bbox.max.Y())&& + (test.Y()>=bbox.min.Y())) + return (bbox.min.X()-test.X()); } else { @@ -372,13 +377,13 @@ Point2 ClosestPoint2Box2(const Point2 &test, return closest; } - /// Specificazione di box of short +/// Specificazione di box of short typedef Box2 Box2s; - /// Specificazione di box of int +/// Specificazione di box of int typedef Box2 Box2i; - /// Specificazione di box of float +/// Specificazione di box of float typedef Box2 Box2f; - /// Specificazione di box of double +/// Specificazione di box of double typedef Box2 Box2d; /*@}*/ diff --git a/vcg/space/box3.h b/vcg/space/box3.h index 4fd6de3a..862767db 100644 --- a/vcg/space/box3.h +++ b/vcg/space/box3.h @@ -46,29 +46,27 @@ public: typedef BoxScalarType ScalarType; /// min coordinate point - Point3 min; + Point3 min; /// max coordinate point Point3 max; /// The bounding box constructor inline Box3() { this->SetNull(); } - /// Copy constructor - //inline Box3( const Box3 & b ) { min=b.min; max=b.max; } /// Min Max constructor inline Box3( const Point3 & mi, const Point3 & ma ) { min = mi; max = ma; } /// Point Radius Constructor - inline Box3(const Point3 & center, const BoxScalarType & radius) { - min = center-Point3(radius,radius,radius); - max = center+Point3(radius,radius,radius); - } + inline Box3(const Point3 & center, const BoxScalarType & radius) { + min = center-Point3(radius,radius,radius); + max = center+Point3(radius,radius,radius); + } /// The bounding box distructor inline ~Box3() { } /// Operator to compare two bounding box - inline bool operator == ( Box3 const & p ) const + inline bool operator == ( const Box3 & p ) const { return min==p.min && max==p.max; } /// Operator to dispare two bounding box - inline bool operator != ( Box3 const & p ) const + inline bool operator != ( const Box3 & p ) const { return min!=p.min || max!=p.max; } @@ -103,7 +101,7 @@ public: /** Modify the current bbox to contain also the passed box. * Adding a null bounding box does nothing */ - void Add( Box3 const & b ) + void Add( const Box3 & b ) { if(b.IsNull()) return; // Adding a null bbox should do nothing if(IsNull()) *this=b; @@ -137,20 +135,20 @@ public: /** Modify the current bbox to contain also the passed sphere */ -void Add( const Point3 & p, const BoxScalarType radius ) -{ - if(IsNull()) Set(p); - else + void Add( const Point3 & p, const BoxScalarType radius ) { - min.X() = std::min(min.X(),p.X()-radius); - min.Y() = std::min(min.Y(),p.Y()-radius); - min.Z() = std::min(min.Z(),p.Z()-radius); + if(IsNull()) Set(p); + else + { + min.X() = std::min(min.X(),p.X()-radius); + min.Y() = std::min(min.Y(),p.Y()-radius); + min.Z() = std::min(min.Z(),p.Z()-radius); - max.X() = std::max(max.X(),p.X()+radius); - max.Y() = std::max(max.Y(),p.Y()+radius); - max.Z() = std::max(max.Z(),p.Z()+radius); + max.X() = std::max(max.X(),p.X()+radius); + max.Y() = std::max(max.Y(),p.Y()+radius); + max.Z() = std::max(max.Z(),p.Z()+radius); + } } -} /** Modify the current bbox to contain also the box b transformed according to the matrix m */ void Add( const Matrix44 &m, const Box3 & b ) @@ -193,7 +191,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) } /** true if the point belong to the closed box */ - bool IsIn( Point3 const & p ) const + bool IsIn( const Point3 & p ) const { return ( min.X() <= p.X() && p.X() <= max.X() && @@ -204,7 +202,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) /** true if the point belong to the open box (open on the max side) * e.g. if p in [min,max) */ - bool IsInEx( Point3 const & p ) const + bool IsInEx( const Point3 & p ) const { return ( min.X() <= p.X() && p.X() < max.X() && @@ -225,7 +223,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) return bb.IsValid(); } */ - bool Collide(Box3 const &b) const + bool Collide( const Box3 &b) const { return b.min.X()min.X() && b.min.Y()min.Y() && @@ -259,14 +257,14 @@ void Add( const Point3 & p, const BoxScalarType radius ) return (max-min); } /// Returns global coords of a local point expressed in [0..1]^3 - Point3 LocalToGlobal(Point3 const & p) const{ + Point3 LocalToGlobal(const Point3 & p) const{ return Point3( min[0] + p[0]*(max[0]-min[0]), min[1] + p[1]*(max[1]-min[1]), min[2] + p[2]*(max[2]-min[2])); } /// Returns local coords expressed in [0..1]^3 of a point in 3D - Point3 GlobalToLocal(Point3 const & p) const{ + Point3 GlobalToLocal(const Point3 & p) const{ return Point3( (p[0]-min[0])/(max[0]-min[0]), (p[1]-min[1])/(max[1]-min[1]), @@ -313,7 +311,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) } /// gives the ith box vertex in order: (x,y,z),(X,y,z),(x,Y,z),(X,Y,z),(x,y,Z),(X,y,Z),(x,Y,Z),(X,Y,Z) - Point3 P(const int & i) const { + Point3 P(int i) const { return Point3( min[0]+ (i%2) * DimX(), min[1]+ ((i / 2)%2) * DimY(), diff --git a/vcg/space/deprecated_point3.h b/vcg/space/deprecated_point3.h index dd32ebfd..a5e75494 100644 --- a/vcg/space/deprecated_point3.h +++ b/vcg/space/deprecated_point3.h @@ -253,7 +253,7 @@ public: assert(i>=0 && i<3); return _v[i]; } - inline const P3ScalarType &X() const { return _v[0]; } + inline const P3ScalarType &X() const { return _v[0]; } inline const P3ScalarType &Y() const { return _v[1]; } inline const P3ScalarType &Z() const { return _v[2]; } inline P3ScalarType &X() { return _v[0]; } diff --git a/vcg/space/deprecated_point4.h b/vcg/space/deprecated_point4.h index a932f43d..39b5d135 100644 --- a/vcg/space/deprecated_point4.h +++ b/vcg/space/deprecated_point4.h @@ -97,10 +97,8 @@ public: { _v[0] = p[0]; _v[1]= p[1]; _v[2] = p[2]; _v[3]= p[3]; } - inline Point4 ( const Point4 & p ) - { - _v[0]= p._v[0]; _v[1]= p._v[1]; _v[2]= p._v[2]; _v[3]= p._v[3]; - } + inline Point4 ( const Point4 & p ) = default; + inline void SetZero() { _v[0] = _v[1] = _v[2] = _v[3]= 0; diff --git a/vcg/space/line2.h b/vcg/space/line2.h index 2abeb18d..68314006 100644 --- a/vcg/space/line2.h +++ b/vcg/space/line2.h @@ -167,7 +167,7 @@ public: Line2 (const Line2 &r) { Import(r); }; /// assignment - inline LineType & operator = ( Line2 const &r) + inline LineType & operator = ( const Line2 &r) { Import(r); return *this; }; //@}