7cc55217f8
- correzione prototipi.
171 lines
7.5 KiB
C++
171 lines
7.5 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2023
|
|
//----------------------------------------------------------------------------
|
|
// File : EGkBBox3d.h Data : 12.05.23 Versione : 2.5e3
|
|
// Contenuto : Dichiarazione della classe axis aligned bounding box BBox3d.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 14.01.13 DS Creazione modulo.
|
|
// 17.08.22 DS Aggiunte GetDimX, GetDimY, GetDimZ.
|
|
// 12.05.23 DS Aggiunta Overlaps con Box su riferimento.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "/EgtDev/Include/EGkPoint3d.h"
|
|
#include <vector>
|
|
|
|
//----------------------- 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( double dX, double dY, double dZ)
|
|
: m_ptMin( dX, dY, dZ), m_ptMax( dX, dY, dZ) {}
|
|
BBox3d( const Point3d& ptCen, double dDelta)
|
|
: m_ptMin( ptCen.x - abs( dDelta), ptCen.y - abs( dDelta), ptCen.z - abs( dDelta)),
|
|
m_ptMax( ptCen.x + abs( dDelta), ptCen.y + abs( dDelta), ptCen.z + abs( dDelta)) {}
|
|
BBox3d( const Point3d& ptCen, double dDeltaX, double dDeltaY, double dDeltaZ)
|
|
: m_ptMin( ptCen.x - abs( dDeltaX), ptCen.y - abs( dDeltaY), ptCen.z - abs( dDeltaZ)),
|
|
m_ptMax( ptCen.x + abs( dDeltaX), ptCen.y + abs( dDeltaY), ptCen.z + abs( dDeltaZ)) {}
|
|
BBox3d( const Point3d& ptP1, const Point3d& ptP2) ;
|
|
BBox3d( double dX1, double dY1, double dZ1, double dX2, double dY2, double dZ2) ;
|
|
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( double dX, double dY, double dZ)
|
|
{ m_ptMin = Point3d( dX, dY, dZ) ; m_ptMax = m_ptMin ; }
|
|
void Set( const Point3d& ptP1, const Point3d& ptP2) ;
|
|
void Set( double dX1, double dY1, double dZ1, double dX2, double dY2, double dZ2) ;
|
|
|
|
public :
|
|
bool IsEmpty( void) const
|
|
{ return ( ! IsValid()) ; }
|
|
bool IsSmall( void) const ;
|
|
bool IsSmallXY( void) const ;
|
|
bool IsSmallZ( void) const ;
|
|
bool IsEpsilon( double dToler) const ;
|
|
bool IsEpsilonXY( double dToler) const ;
|
|
bool IsEpsilonZ( double dToler) const ;
|
|
void Add( const Point3d& ptP) ;
|
|
void Add( double dX, double dY, double dZ) ;
|
|
void Add( const BBox3d& b3B) ;
|
|
void Add( const std::vector<Point3d>& vPnt) { for ( const Point3d& pt: vPnt){
|
|
Add( pt) ; }}
|
|
void Expand( double dDelta) ;
|
|
void Expand( double dDeltaX, double dDeltaY, double dDeltaZ) ;
|
|
const Point3d& GetMin( void) const
|
|
{ return m_ptMin ; }
|
|
const Point3d& GetMax( void) const
|
|
{ return m_ptMax ; }
|
|
bool GetMinMax( Point3d& ptMin, Point3d& ptMax) const ;
|
|
bool GetMinDim( Point3d& ptMin, double& dDimX, double& dDimY, double& dDimZ) const ;
|
|
double GetDimX( void) const ;
|
|
double GetDimY( void) const ;
|
|
double GetDimZ( void) const ;
|
|
bool GetCenterExtent( Point3d& ptCenter, Vector3d& vtExtent) const ;
|
|
bool GetCenter( Point3d& ptCenter) const ;
|
|
bool GetRadius( double& dRad) const ;
|
|
bool GetDiameter( double& dDiam) const ;
|
|
bool Translate( const Vector3d& vtMove) ;
|
|
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) ;
|
|
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ;
|
|
bool ToGlob( const Frame3d& frRef) ;
|
|
bool ToLoc( const Frame3d& frRef) ;
|
|
bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) ;
|
|
bool Encloses( const Point3d& ptP) const ;
|
|
bool EnclosesXY( const Point3d& ptP) const ;
|
|
bool Encloses( const BBox3d& b3Box) const ;
|
|
bool EnclosesXY( const BBox3d& b3Box) const ;
|
|
bool Overlaps( const BBox3d& b3Box) const ;
|
|
bool OverlapsXY( const BBox3d& b3Box) const ;
|
|
bool Overlaps( const Frame3d& frBox, const BBox3d& b3Box) const ;
|
|
bool FindIntersection( const BBox3d& b3Box, BBox3d& b3Int) const ;
|
|
bool FindIntersectionXY( const BBox3d& b3Box, BBox3d& b3Int) const ;
|
|
double SqDistFromPoint( const Point3d& ptP) const ;
|
|
double SqDistFromPointXY( const Point3d& ptP) const ;
|
|
double DistFromPoint( const Point3d& ptP) const
|
|
{ double dSqDist = SqDistFromPoint( ptP) ;
|
|
if ( dSqDist < EPS_ZERO)
|
|
return 0 ;
|
|
return sqrt( dSqDist) ; }
|
|
double DistFromPointXY( const Point3d& ptP) const
|
|
{ double dSqDist = SqDistFromPointXY( ptP) ;
|
|
if ( dSqDist < EPS_ZERO)
|
|
return 0 ;
|
|
return sqrt( dSqDist) ; }
|
|
double SqMaxDistFromPoint( const Point3d& ptP) const ;
|
|
double SqMaxDistFromPointXY( const Point3d& ptP) const ;
|
|
double MaxDistFromPoint( const Point3d& ptP) const
|
|
{ double dSqDist = SqMaxDistFromPoint( ptP) ;
|
|
if ( dSqDist < EPS_ZERO)
|
|
return 0 ;
|
|
return sqrt( dSqDist) ; }
|
|
double MaxDistFromPointXY( const Point3d& ptP) const
|
|
{ double dSqDist = SqMaxDistFromPointXY( ptP) ;
|
|
if ( dSqDist < EPS_ZERO)
|
|
return 0 ;
|
|
return sqrt( dSqDist) ; }
|
|
|
|
private :
|
|
bool IsValid( void) const ;
|
|
|
|
private :
|
|
Point3d m_ptMin ;
|
|
Point3d m_ptMax ;
|
|
} ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
//! Restituisce una copia in locale del box passato
|
|
//----------------------------------------------------------------------------
|
|
inline const BBox3d
|
|
GetToLoc( const BBox3d& b3Box, const Frame3d& frRef)
|
|
{
|
|
BBox3d b3New = b3Box ;
|
|
b3New.ToLoc( frRef) ;
|
|
return b3New ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
//! Restituisce una copia in globale del box passato
|
|
//----------------------------------------------------------------------------
|
|
inline const BBox3d
|
|
GetToGlob( const BBox3d& b3Box, const Frame3d& frRef)
|
|
{
|
|
BBox3d b3New = b3Box ;
|
|
b3New.ToGlob( frRef) ;
|
|
return b3New ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
//! Restituisce una copia dal primo al secondo riferimento del box passato
|
|
//----------------------------------------------------------------------------
|
|
inline const BBox3d
|
|
GetLocToLoc( const BBox3d& b3Box, const Frame3d& frOri, const Frame3d& frDest)
|
|
{
|
|
BBox3d b3New = b3Box ;
|
|
b3New.LocToLoc( frOri, frDest) ;
|
|
return b3New ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
inline bool Overlaps( const BBox3d& bbA, const Frame3d& frA, const BBox3d& bbB, const Frame3d& frB)
|
|
{
|
|
return bbA.Overlaps( GetToLoc( frB, frA), bbB) ;
|
|
} |