//---------------------------------------------------------------------------- // 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 #include //---------------------------------------------------------------------------- // Classe Vertice class StmVert { public : StmVert( void) : ptP(), nIdTria( SVT_NULL), nFlag( 0) {} StmVert( const Point3d& ptQ) : ptP( ptQ), nIdTria( SVT_NULL), nFlag( 0) {} StmVert( const Point3d& ptQ, int nIdT, int nF) : ptP( ptQ), nIdTria( nIdT), nFlag( nF) {} public : Point3d ptP ; int nIdTria ; int nFlag ; } ; //---------------------------------------------------------------------------- // 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 virtual ~SurfTriMesh( void) ; virtual SurfTriMesh* Clone( void) const ; virtual GeoObjType GetType( void) const ; virtual bool IsValid( void) const { return ( m_nStatus == OK) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; virtual bool GetLocalBBox( BBox3d& b3Loc, int nFlag = BBF_STANDARD) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_STANDARD) const ; virtual bool Translate( const Vector3d& vtMove) ; virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) { double dAngRad = dAngDeg * DEGTORAD ; return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ; virtual bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) ; virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) ; virtual bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) ; virtual bool ToGlob( const Frame3d& frRef) ; virtual bool ToLoc( const Frame3d& frRef) ; virtual bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) ; virtual void SetObjGraphics( IObjGraphics* pOGr) { m_OGrMgr.SetObjGraphics( pOGr) ; } virtual IObjGraphics* GetObjGraphics( void) { return m_OGrMgr.GetObjGraphics() ; } virtual const IObjGraphics* GetObjGraphics( void) const { return m_OGrMgr.GetObjGraphics() ; } virtual void SetTempProp( int nProp) { m_nTempProp = nProp ; } virtual int GetTempProp( void) { return m_nTempProp ; } public : // ISurf virtual bool IsSimple( void) const { return true ; } virtual bool IsClosed( void) const { return m_bClosed ; } virtual bool GetArea( double& dArea) const ; virtual bool GetVolume( double& dVolume) const ; virtual bool GetCentroid( Point3d& ptCen) const ; virtual bool Invert( void) ; public : // ISurfTriMesh virtual bool CopyFrom( const IGeoObj* pGObjSrc) ; virtual bool Init( int nNumVert, int nNumTria, int nNumFacet = 0) ; virtual void SetLinearTolerance( double dLinTol) { m_dLinTol = (std::max)( dLinTol, EPS_SMALL) ; } virtual void SetBoundaryAngle( double dBoundaryAngDeg) { m_dBoundaryAng = (std::max)( dBoundaryAngDeg, EPS_ANG_SMALL) ; m_dCosBndAng = cos( m_dBoundaryAng * DEGTORAD) ; m_OGrMgr.Reset() ; } virtual void SetSmoothAngle( double dSmoothAngDeg) { m_dSmoothAng = (std::max)( dSmoothAngDeg, EPS_ANG_SMALL) ; m_dCosSmAng = cos( m_dSmoothAng * DEGTORAD) ; m_OGrMgr.Reset() ; } virtual int AddVertex( const Point3d& ptVert) ; virtual int AddTriangle( const int nIdVert[3]) ; virtual bool AdjustTopology( void) ; virtual bool CreateByFlatContour( const PolyLine& PL) ; virtual bool CreateByRegion( const POLYLINEVECTOR& vPL) ; virtual bool CreateByExtrusion( const PolyLine& PL, const Vector3d& vtExtr) ; virtual bool CreateByTwoCurves( const PolyLine& PL1, const PolyLine& PL2) ; virtual bool CreateByRevolution( const PolyLine& PL, const Point3d& ptAx, const Vector3d& vtAx, double dAngRot, double dStepRot) ; virtual bool CreateByScrewing( const PolyLine& PL, const Point3d& ptAx, const Vector3d& vtAx, double dAngRot, double dStepRot, double dMove) ; virtual bool DoCompacting( void) ; virtual bool DoSewing( const ISurfTriMesh& stmOther, const Frame3d& frOther = GLOB_FRM) ; virtual int GetVertexNum( void) const ; virtual int GetTriangleNum( void) const ; virtual int GetVertexSize( void) const { return int( m_vVert.size()) ; } virtual int GetTriangleSize( void) const { return int( m_vTria.size()) ; } virtual double GetLinearTolerance( void) { return m_dLinTol ; } virtual double GetSmoothAngle( void) { return m_dSmoothAng ; } virtual bool GetVertex( int nId, Point3d& ptP) const ; virtual int GetFirstVertex( Point3d& ptP) const ; virtual int GetNextVertex( int nId, Point3d& ptP) const ; virtual bool GetTriangle( int nId, int nIdVert[3]) const ; virtual int GetFirstTriangle( int nIdVert[3]) const ; virtual int GetNextTriangle( int nId, int nIdVert[3]) const ; virtual bool GetTriangle( int nId, Triangle3d& Tria) const ; virtual int GetFirstTriangle( Triangle3d& Tria) const ; virtual int GetNextTriangle( int nId, Triangle3d& Tria) const ; virtual int GetAllTriaAroundVertex( int nV, INTVECTOR& vT, bool& bCirc) const ; virtual bool GetVertexSmoothNormal( int nV, int nT, Vector3d& vtN) const ; virtual bool GetTriangleBoundaryEdges( int nId, TriFlags3d& TFlags) const ; virtual bool GetTriangleSmoothNormals( int nId, TriNormals3d& TNrms) const ; virtual int GetFacetNum( void) const ; virtual int GetFacetSize( void) const { return int( m_vFacet.size()) ; } virtual int GetFacetFromTria( int nT) const ; virtual bool GetAllTriaInFacet( int nF, INTVECTOR& vT) const ; virtual bool GetFacetLoops( int nF, POLYLINEVECTOR& vPL) const ; virtual bool GetFacetNearestEndPoint( int nF, const Point3d& ptNear, Point3d& ptEnd, Vector3d& vtN) const ; virtual bool GetFacetNearestMidPoint( int nF, const Point3d& ptNear, Point3d& ptMid, Vector3d& vtN) const ; virtual bool GetFacetCenter( int nF, Point3d& ptCen, Vector3d& vtN) const ; virtual bool GetFacetNormal( int nF, Vector3d& vtN) const ; public : // IGeoObjRW virtual int GetNgeId( void) const ; virtual bool Save( NgeWriter& ngeOut) const ; virtual bool Load( NgeReader& ngeIn) ; 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 VERTVECTOR ; typedef std::vector TRIAVECTOR ; typedef std::deque TRINTDEQUE ; private : enum Status { ERR = 0, OK = 1, TO_VERIFY = 2} ; private : bool CopyFrom( const SurfTriMesh& clSrc) ; bool Validate( 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 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 MarchAlongLoop( int nF, int nT, int nV, int nTimeStamp, PolyLine& PL) const ; bool MarchOneTria( 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 } ;