From 8527b5c7bdcbd105ed53bf51cd214047f91b9a7f Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 16 Jan 2014 22:03:21 +0000 Subject: [PATCH] Include : modifiche per BoundingBox. --- EGkBBox3d.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ EGkFrame3d.h | 8 ++++--- EGkGeoConst.h | 5 +++- EGkGeoObj.h | 3 +++ EGkGeomDB.h | 2 ++ EGkPoint3d.h | 2 ++ EGkVector3d.h | 26 +++++++++++++++++++++ 7 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 EGkBBox3d.h diff --git a/EGkBBox3d.h b/EGkBBox3d.h new file mode 100644 index 0000000..b78652b --- /dev/null +++ b/EGkBBox3d.h @@ -0,0 +1,63 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : EGkBBox3d.h Data : 14.01.14 Versione : 1.5a4 +// Contenuto : Dichiarazione della classe axis aligned bounding box BBox3d. +// +// +// +// Modifiche : 14.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGKPoint3d.h" + +//----------------------- Macro per import/export ---------------------------- +#undef EGK_EXPORT +#if defined( I_AM_EGK) // da definirsi solo nella DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//---------------------------------------------------------------------------- +class EGK_EXPORT BBox3d +{ + public : + BBox3d( void) // Box vuoto (min > MAX) + : m_ptMin( +INFINITO, +INFINITO, +INFINITO), + m_ptMax( -INFINITO, -INFINITO, -INFINITO) {} + BBox3d( const Point3d ptP) + : m_ptMin( ptP), m_ptMax( ptP) {} + BBox3d( const Point3d ptP1, const Point3d ptP2) ; + void Reset( void) + { m_ptMin = Point3d( +INFINITO, +INFINITO, +INFINITO) ; + m_ptMax = Point3d( -INFINITO, -INFINITO, -INFINITO) ; } + void Set( const Point3d ptP) + { m_ptMin = ptP ; m_ptMax = ptP ; } + void Set( const Point3d ptP1, const Point3d ptP2) ; + + public : + void Add( const Point3d& ptP) ; + void Add( const BBox3d& b3B) ; + void Expand( double dDelta) ; + void Expand( double dDeltaX, double dDeltaY, double dDeltaZ) ; + bool GetMinMax( Point3d& ptMin, Point3d& ptMax) const ; + bool GetCenterExtent( Point3d& ptCenter, Vector3d& vtExtent) const ; + bool ToGlob( const Frame3d& frRef) ; + bool ToLoc( const Frame3d& frRef) ; + bool Encloses( const Point3d& ptP) const ; + bool Overlaps( const BBox3d& b3B) const ; + bool FindIntersection( const BBox3d& b3B, BBox3d& b3Int) const ; + double SqDistFromPoint( const Point3d& ptP) const ; + + private : + bool IsValid( void) const ; + + private : + Point3d m_ptMin ; + Point3d m_ptMax ; +} ; diff --git a/EGkFrame3d.h b/EGkFrame3d.h index 1490658..8f9d87c 100644 --- a/EGkFrame3d.h +++ b/EGkFrame3d.h @@ -6,7 +6,7 @@ // // // -// Modifiche : 04.01.12 DS Creazione modulo. +// Modifiche : 04.01.13 DS Creazione modulo. // // //---------------------------------------------------------------------------- @@ -30,7 +30,9 @@ class EGK_EXPORT Frame3d enum Type { ERR = 0, TOP = 1, BOTTOM = 2, FRONT = 3, BACK = 4, LEFT = 5, RIGHT = 6, GEN = 7} ; public : - Frame3d( void) ; + Frame3d( void) + : m_nType( TOP), m_nZType( TOP), m_ptOrig( ORIG), + m_vtVersX( X_AX), m_vtVersY( Y_AX), m_vtVersZ( Z_AX) {} bool Set( const Point3d& ptOrig, const Vector3d& vtDirX, const Vector3d& vtDirY, const Vector3d& vtDirZ) ; bool Set( const Point3d& ptOrig, const Point3d& ptOnX, const Point3d& ptNearY) ; @@ -41,6 +43,7 @@ class EGK_EXPORT Frame3d bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) ; // Scale non possibile (non previsti fattori di scala) // Mirror non possibile (cambia il senso destrorso in sinistrorso) + bool Invert( void) ; bool ToGlob( const Frame3d& frRef) ; bool ToLoc( const Frame3d& frRef) ; const Frame3d& operator*=( const Frame3d& frRef) { this->ToGlob( frRef) ; return *this ;} @@ -63,7 +66,6 @@ class EGK_EXPORT Frame3d Vector3d m_vtVersX ; Vector3d m_vtVersY ; Vector3d m_vtVersZ ; - } ; //---------------------------------------------------------------------------- diff --git a/EGkGeoConst.h b/EGkGeoConst.h index a21567f..1059f07 100644 --- a/EGkGeoConst.h +++ b/EGkGeoConst.h @@ -41,6 +41,9 @@ const double COS_ORTO_ANG_ZERO = SIN_EPS_ANG_ZERO ; // tolleranza lineare minima in approssimazioni lineari const double LIN_TOL_MIN = 0.01 ; - // deviazione angolare minima (in gradi) in approssimazioni lineari const double ANG_TOL_MIN_DEG = 0.1 ; +// tolleranza lineare standard in approssimazioni lineari +static const double LIN_TOL_APPROX = 1 ; +// deviazione angolare standard (in gradi) in approssimazioni lineari +static const double ANG_TOL_APPROX_DEG = 45 ; diff --git a/EGkGeoObj.h b/EGkGeoObj.h index 738994f..69503cd 100644 --- a/EGkGeoObj.h +++ b/EGkGeoObj.h @@ -16,6 +16,7 @@ #include "/EgtDev/Include/EGnScan.h" #include "/EgtDev/Include/EGkPoint3d.h" #include "/EgtDev/Include/EGkFrame3d.h" +#include "/EgtDev/Include/EGkBBox3d.h" #include "/EgtDev/Include/EGkGeoObjType.h" #include @@ -38,6 +39,8 @@ class __declspec( novtable) IGeoObj virtual bool IsValid( void) const = 0 ; virtual bool Save( std::ostream& osOut) const = 0 ; virtual bool Load( Scanner& TheScanner) = 0 ; + virtual bool GetLocalBBox( BBox3d& b3Loc) const = 0 ; + virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const = 0 ; virtual bool Translate( const Vector3d& vtMove) = 0 ; virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) = 0 ; virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) = 0 ; diff --git a/EGkGeomDB.h b/EGkGeomDB.h index f1fc9cf..a47b9b5 100644 --- a/EGkGeomDB.h +++ b/EGkGeomDB.h @@ -44,6 +44,8 @@ class __declspec( novtable) IGeomDB virtual bool GetGroupGlobFrame( int nId, Frame3d& frGlob) = 0 ; virtual int GetParentId( int nId) = 0 ; virtual bool GetGlobFrame( int nId, Frame3d& frGlob) = 0 ; + virtual bool GetLocalBBox( int nId, BBox3d& b3Loc) const = 0 ; + virtual bool GetBBox( int nId, const Frame3d& frRef, BBox3d& b3Ref) const = 0 ; virtual int Copy( int nIdSou, int nIdDest, int nParentIdDest) = 0 ; virtual bool Erase( int nId) = 0 ; virtual bool Translate( int nId, const Vector3d& vtMove) = 0 ; diff --git a/EGkPoint3d.h b/EGkPoint3d.h index 2696d90..df930aa 100644 --- a/EGkPoint3d.h +++ b/EGkPoint3d.h @@ -42,6 +42,8 @@ class EGK_EXPORT Point3d public : const Point3d& operator +=( const Vector3d& vtV) { this->x += vtV.x ; this->y += vtV.y ; this->z += vtV.z ; return *this ; } + const Point3d& operator -=( const Vector3d& vtV) + { this->x -= vtV.x ; this->y -= vtV.y ; this->z -= vtV.z ; return *this ; } // questa somma è valida solo se equivalente ad una combinazione baricentrica const Point3d& operator +=( const Point3d& ptP) { this->x += ptP.x ; this->y += ptP.y ; this->z += ptP.z ; return *this ; } diff --git a/EGkVector3d.h b/EGkVector3d.h index 1bafa2f..06fb8e5 100644 --- a/EGkVector3d.h +++ b/EGkVector3d.h @@ -50,6 +50,14 @@ class EGK_EXPORT Vector3d { return ( ( x * x + y * y + z * z) < ( EPS_ZERO * EPS_ZERO)) ; } bool IsNormalized( void) const { return ( fabs( 1.0 - (x * x + y * y + z * z)) < ( 2 * EPS_ZERO)) ; } + bool IsXplus( void) const + { return ( x > EPS_ZERO && fabs( y) < EPS_ZERO && fabs( z) < EPS_ZERO) ; } + bool IsXminus( void) const + { return ( x < - EPS_ZERO && fabs( y) < EPS_ZERO && fabs( z) < EPS_ZERO) ; } + bool IsYplus( void) const + { return ( fabs( x) < EPS_ZERO && y > EPS_ZERO && fabs( z) < EPS_ZERO) ; } + bool IsYminus( void) const + { return ( fabs( x) < EPS_ZERO && y < - EPS_ZERO && fabs( z) < EPS_ZERO) ; } bool IsZplus( void) const { return ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO && z > EPS_ZERO) ; } bool IsZminus( void) const @@ -192,6 +200,24 @@ AreSameVectorExact( const Vector3d& vtV1, const Vector3d& vtV2) return ( ( vtV1 - vtV2).IsZero()) ; } +//---------------------------------------------------------------------------- +// Verifica che due vettori sono quasi opposti (Small error -> Near) +//---------------------------------------------------------------------------- +inline bool +AreOppositeVectorNear( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( ( vtV1 + vtV2).IsSmall()) ; +} + +//---------------------------------------------------------------------------- +// Verifica che due vettori sono esattamente coincidenti (Zero error -> Exact) +//---------------------------------------------------------------------------- +inline bool +AreOppositeVectorExact( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( ( vtV1 + vtV2).IsZero()) ; +} + //---------------------------------------------------------------------------- // Verifica che due versori sono ortogonali (Small error -> Near) //----------------------------------------------------------------------------