Files
EgtGeomKernel/SurfTriMesh.h
T
Dario Sassi c8a38f5aae EgtGeomKernel 1.8h3 :
- migliorie e correzioni su Zmap
- aggiunta a PointGrid3d nuova FindNearest
- migliorie a TriMesh.
2017-08-31 07:43:41 +00:00

271 lines
14 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : SurfTriMesh.h Data : 26.03.14 Versione : 1.5c9
// Contenuto : Dichiarazione della classe Superficie TriMesh.
//
//
//
// Modifiche : 26.03.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "ObjGraphicsMgr.h"
#include "DllMain.h"
#include "GeoObjRW.h"
#include "/EgtDev/Include/EGkSurfTriMesh.h"
#include <algorithm>
#include <deque>
//----------------------------------------------------------------------------
// Classe Vertice
class StmVert
{
public :
StmVert( void) : ptP(), nIdTria( SVT_NULL), nFlag( 0), nTemp( 0) {}
StmVert( const Point3d& ptQ) : ptP( ptQ), nIdTria( SVT_NULL), nFlag( 0), nTemp( 0) {}
StmVert( const Point3d& ptQ, int nIdT, int nF) : ptP( ptQ), nIdTria( nIdT), nFlag( nF), nTemp( 0) {}
public :
Point3d ptP ;
int nIdTria ;
int nFlag ;
mutable int nTemp ;
} ;
//----------------------------------------------------------------------------
// Classe Triangolo
class StmTria
{
public :
StmTria( void) : vtN(), nIdFacet( SVT_NULL), nTFlag( 0), nEFlag( 0), nTemp( 0)
{ nIdVert[0] = SVT_NULL ; nIdVert[1] = SVT_NULL ; nIdVert[2] = SVT_NULL ;
nIdAdjac[0] = SVT_NULL ; nIdAdjac[1] = SVT_NULL ; nIdAdjac[2] = SVT_NULL ; }
StmTria( const int nIdV[3]) : vtN(), nIdFacet( SVT_NULL), nTFlag( 0), nEFlag( 0), nTemp( 0)
{ nIdVert[0] = nIdV[0] ; nIdVert[1] = nIdV[1] ; nIdVert[2] = nIdV[2] ;
nIdAdjac[0] = SVT_NULL ; nIdAdjac[1] = SVT_NULL ; nIdAdjac[2] = SVT_NULL ; }
StmTria( const int nIdV[3], const int nIdA[3], const Vector3d& vtV, int nTF, int nEF)
: vtN( vtV), nIdFacet( SVT_NULL), nTFlag( nTF), nEFlag( nEF), nTemp( 0)
{ nIdVert[0] = nIdV[0] ; nIdVert[1] = nIdV[1] ; nIdVert[2] = nIdV[2] ;
nIdAdjac[0] = nIdA[0] ; nIdAdjac[1] = nIdA[1] ; nIdAdjac[2] = nIdA[2] ; }
public :
int nIdVert[3] ;
int nIdAdjac[3] ;
Vector3d vtN ;
int nIdFacet ;
int nTFlag ;
int nEFlag ;
mutable int nTemp ;
} ;
//----------------------------------------------------------------------------
// Classe di tre interi per code di elaborazione sui triangoli (senza iterazioni)
struct Stm3Int {
Stm3Int( int nI, int nJ, int nK) : nI1( nI), nI2( nJ), nI3( nK) {}
int nI1 ; int nI2 ; int nI3 ;
} ;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class SurfTriMesh : public ISurfTriMesh, public IGeoObjRW
{
public : // IGeoObj
~SurfTriMesh( void) override ;
SurfTriMesh* Clone( void) const override ;
GeoObjType GetType( void) const override ;
bool IsValid( void) const override
{ return ( m_nStatus == OK) ; }
const std::string& GetTitle( void) const override ;
bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const override ;
bool GetLocalBBox( BBox3d& b3Loc, int nFlag = BBF_STANDARD) const override ;
bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_STANDARD) const override ;
bool Translate( const Vector3d& vtMove) override ;
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) override
{ double dAngRad = dAngDeg * DEGTORAD ;
return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; }
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) override ;
bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) override ;
bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) override ;
bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) override ;
bool ToGlob( const Frame3d& frRef) override ;
bool ToLoc( const Frame3d& frRef) override ;
bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) override ;
void SetObjGraphics( IObjGraphics* pOGr) override
{ m_OGrMgr.SetObjGraphics( pOGr) ; }
IObjGraphics* GetObjGraphics( void) override
{ return m_OGrMgr.GetObjGraphics() ; }
const IObjGraphics* GetObjGraphics( void) const override
{ return m_OGrMgr.GetObjGraphics() ; }
void SetTempProp( int nProp) override
{ m_nTempProp = nProp ; }
int GetTempProp( void) override
{ return m_nTempProp ; }
public : // ISurf
bool IsSimple( void) const override
{ return true ; }
bool IsClosed( void) const override
{ return m_bClosed ; }
bool GetArea( double& dArea) const override ;
bool GetVolume( double& dVolume) const override ;
bool GetCentroid( Point3d& ptCen) const override ;
bool Invert( void) override ;
public : // ISurfTriMesh
bool CopyFrom( const IGeoObj* pGObjSrc) override ;
bool Init( int nNumVert, int nNumTria, int nNumFacet = 0) ;
void SetLinearTolerance( double dLinTol) override
{ m_dLinTol = (std::max)( dLinTol, EPS_SMALL) ; }
void SetBoundaryAngle( double dBoundaryAngDeg) override
{ m_dBoundaryAng = (std::max)( dBoundaryAngDeg, EPS_ANG_SMALL) ;
m_dCosBndAng = cos( m_dBoundaryAng * DEGTORAD) ;
m_OGrMgr.Reset() ; }
void SetSmoothAngle( double dSmoothAngDeg) override
{ m_dSmoothAng = (std::max)( dSmoothAngDeg, EPS_ANG_SMALL) ;
m_dCosSmAng = cos( m_dSmoothAng * DEGTORAD) ;
m_OGrMgr.Reset() ; }
int AddVertex( const Point3d& ptVert) override ;
int AddTriangle( const int nIdVert[3]) override ;
bool RemoveTriangle( int nId) override ;
bool AdjustTopology( void) override ;
bool CreateByFlatContour( const PolyLine& PL) override ;
bool CreateByRegion( const POLYLINEVECTOR& vPL) override ;
bool CreateByExtrusion( const PolyLine& PL, const Vector3d& vtExtr) override ;
bool CreateByPointCurve( const Point3d& ptP, const PolyLine& PL) override ;
bool CreateByTwoCurves( const PolyLine& PL1, const PolyLine& PL2) override ;
bool CreateByRevolution( const PolyLine& PL, const Point3d& ptAx, const Vector3d& vtAx,
double dAngRot, double dStepRot) override ;
bool CreateByScrewing( const PolyLine& PL, const Point3d& ptAx, const Vector3d& vtAx,
double dAngRot, double dStepRot, double dMove) override ;
bool DoCompacting( void) override ;
bool DoSewing( const ISurfTriMesh& stmOther, const Frame3d& frOther = GLOB_FRM) override ;
int GetVertexCount( void) const override ;
int GetTriangleCount( void) const override ;
int GetVertexSize( void) const override
{ return int( m_vVert.size()) ; }
int GetTriangleSize( void) const override
{ return int( m_vTria.size()) ; }
double GetLinearTolerance( void) override
{ return m_dLinTol ; }
double GetSmoothAngle( void) override
{ return m_dSmoothAng ; }
bool GetVertex( int nId, Point3d& ptP) const override ;
int GetFirstVertex( Point3d& ptP) const override ;
int GetNextVertex( int nId, Point3d& ptP) const override ;
bool GetTriangle( int nId, int nIdVert[3]) const override ;
int GetFirstTriangle( int nIdVert[3]) const override ;
int GetNextTriangle( int nId, int nIdVert[3]) const override ;
bool GetTriangle( int nId, Triangle3d& Tria) const override ;
int GetFirstTriangle( Triangle3d& Tria) const override ;
int GetNextTriangle( int nId, Triangle3d& Tria) const override ;
int GetAllTriaAroundVertex( int nV, INTVECTOR& vT, bool& bCirc) const override ;
bool GetVertexSmoothNormal( int nV, int nT, Vector3d& vtN) const override ;
bool GetTriangleBoundaryEdges( int nId, TriFlags3d& TFlags) const override ;
bool GetTriangleSmoothNormals( int nId, TriNormals3d& TNrms) const override ;
bool GetLoops( POLYLINEVECTOR& vPL) const override ;
bool GetSilhouette( const Vector3d& vtDir, POLYLINEVECTOR& vPL) const override ;
int GetFacetCount( void) const override ;
int GetFacetSize( void) const override
{ return int( m_vFacet.size()) ; }
int GetFacetFromTria( int nT) const override ;
bool GetAllTriaInFacet( int nF, INTVECTOR& vT) const override ;
bool GetFacetLoops( int nF, POLYLINEVECTOR& vPL) const override ;
bool GetFacetAdjacencies( int nF, INTMATRIX& vAdj) const override ;
bool GetFacetNearestEndPoint( int nF, const Point3d& ptNear, Point3d& ptEnd, Vector3d& vtN) const override ;
bool GetFacetNearestMidPoint( int nF, const Point3d& ptNear, Point3d& ptMid, Vector3d& vtN) const override ;
bool GetFacetCenter( int nF, Point3d& ptCen, Vector3d& vtN) const override ;
bool GetFacetNormal( int nF, Vector3d& vtN) const override ;
bool GetFacetArea( int nF, double& dArea) const override ;
bool GetFacetsContact( int nF1, int nF2, bool& bAdjac, Point3d& ptP1, Point3d& ptP2, double& dAng) const override ;
SurfTriMesh* CloneFacet( int nF) const override ;
bool Cut( const Plane3d& plPlane, bool bSaveOnEq) override ;
public : // IGeoObjRW
int GetNgeId( void) const override ;
bool Save( NgeWriter& ngeOut) const override ;
bool Load( NgeReader& ngeIn) override ;
public :
SurfTriMesh( void) ;
SurfTriMesh( const SurfTriMesh& stSrc)
{ if ( ! CopyFrom( stSrc))
LOG_ERROR( GetEGkLogger(), "SurfTriMesh : copy constructor error") }
SurfTriMesh& operator =( const SurfTriMesh& stSrc)
{ if ( ! CopyFrom( stSrc))
LOG_ERROR( GetEGkLogger(), "SurfTriMesh : copy error")
return *this ; }
private :
typedef std::vector<StmVert> VERTVECTOR ;
typedef std::vector<StmTria> TRIAVECTOR ;
typedef std::deque<Stm3Int> TRINTDEQUE ;
private :
enum Status { ERR = 0, OK = 1, TO_VERIFY = 2} ;
private :
bool CopyFrom( const SurfTriMesh& clSrc) ;
bool Validate( bool bCorrect = false) ;
bool AdjustVertices( void) ;
bool AdjustAdjacencies( void) ;
bool AdjustOrientations( void) ;
bool AdjustTriaOrientation( TRINTDEQUE& S3iQ) ;
bool TestSealing( void) ;
bool SetVertex( int nInd, const StmVert& vV) ;
bool SetTriangle( int nInd, const StmTria& tT) ;
bool CalcTriangleNormal( int nT) ;
bool InvertTriangle( int nT) ;
int Next( int i) const
{ return (( i + 1) % 3) ; }
int Prev( int i) const
{ return (( i + 2) % 3) ; }
bool FindVertexInTria( int nV, int nT, int& nK) const ;
int NextIndAroundVertex( int nInd, int nSize, bool bCirc) const ;
int PrevIndAroundVertex( int nInd, int nSize, bool bCirc) const ;
bool GetTriangleSmoothNormal( int nT, int nV, Vector3d& vtN) const ;
bool MarchAlongLoop( int nT, int nV, int nTimeStamp, PolyLine& PL) const ;
bool MarchOneTria( int& nT, int& nV, int nTimeStamp, PolyLine& PL, bool& bEnd) const ;
bool VerifyPolylinesForTwoCurves( const PolyLine& PL1, const PolyLine& PL2) const ;
bool VeryfyPolylineForRevolution( const PolyLine& PL, const Point3d& ptAx, const Vector3d& vtAx) const ;
bool AddBiTriangle( const int nIdVert[4]) ;
bool ResetFaceting( void) ;
bool VerifyFaceting( void) const ;
bool UpdateFaceting( void) ;
bool UpdateTriaFaceting( int nRefT, int nFacet, const Plane3d& plPlane, int nT) ;
bool SetFacet( int nInd, int nT) ;
bool VerifyAdjacTriaFacet( int nT, INTVECTOR& vT) const ;
bool MarchAlongFacetLoop( int nF, int nT, int nV, int nTimeStamp, PolyLine& PL) const ;
bool MarchOneFacetTria( int nF, int& nT, int& nV, int nTimeStamp, PolyLine& PL, bool& bEnd) const ;
private :
ObjGraphicsMgr m_OGrMgr ; // gestore grafica dell'oggetto
Status m_nStatus ; // stato
double m_dLinTol ; // tolleranza lineare di costruzione
double m_dBoundaryAng ; // angolo limite per considerare un lato un contorno (in gradi)
double m_dCosBndAng ; // coseno dell'angolo limite per considerare un lato un contorno
double m_dSmoothAng ; // angolo limite per mediare le normali (in gradi)
double m_dCosSmAng ; // coseno dell'angolo limite per mediare le normali
bool m_bOriented ; // la superficie è orientata consistentemente in tutte le sue parti
bool m_bClosed ; // la superficie racchiude un volume
bool m_bFaceted ; // flag di validità della sfaccettatura
VERTVECTOR m_vVert ; // vettore dei vertici
TRIAVECTOR m_vTria ; // vettore dei triangoli
INTVECTOR m_vFacet ; // vettore delle sfaccettature
mutable int m_nTimeStamp ; // orologio locale
int m_nTempProp ; // proprietà temporanea
} ;
//-----------------------------------------------------------------------------
inline SurfTriMesh* CreateBasicSurfTriMesh( void)
{ return (static_cast<SurfTriMesh*>( CreateGeoObj( SRF_TRIMESH))) ; }
inline SurfTriMesh* CloneBasicSurfTriMesh( const IGeoObj* pGObj)
{ if ( pGObj == nullptr || pGObj->GetType() != SRF_TRIMESH)
return nullptr ;
return (static_cast<SurfTriMesh*>(pGObj->Clone())) ; }
inline const SurfTriMesh* GetBasicSurfTriMesh( const IGeoObj* pGObj)
{ return (dynamic_cast<const SurfTriMesh*>(pGObj)) ; }
inline SurfTriMesh* GetBasicSurfTriMesh( IGeoObj* pGObj)
{ return (dynamic_cast<SurfTriMesh*>(pGObj)) ; }