//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : SurfTriMesh.h Data : 26.03.14 Versione : 1.5c9 // Contenuto : Dichiarazione della classe Superfici 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 "/EgtDev/Include/EgtNumCollection.h" //---------------------------------------------------------------------------- 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 ; } ; //---------------------------------------------------------------------------- class StmTria { public : StmTria( void) : vtN(), nTFlag( 0), nEFlag( 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(), nTFlag( 0), nEFlag( 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), nTFlag( nTF), nEFlag( nEF) { 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 nTFlag ; int nEFlag ; } ; //---------------------------------------------------------------------------- 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) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) 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() ; } public : // ISurf virtual bool IsSimple( void) const { return true ; } virtual bool IsClosed( void) const { return m_bClosed ; } virtual bool Invert( void) ; public : // ISurfTriMesh virtual bool CopyFrom( const IGeoObj* pGObjSrc) ; virtual bool Init( int nNumVert, int nNumTria) ; virtual void SetLinearTolerance( double dLinTol) { m_dLinTol = std::max( dLinTol, EPS_SMALL) ; } 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 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 int GetFirstVertex( Point3d& ptP) const ; virtual int GetNextVertex( int nId, Point3d& ptP) const ; virtual int GetFirstTriangle( Triangle3d& Tria) const ; virtual int GetNextTriangle( int nId, Triangle3d& Tria) const ; virtual bool GetTriangleSmoothNormals( int nId, TriNormals3d& TNrms) const ; public : // IGeoObjRW virtual int GetNgeId( void) const ; virtual bool Save( NgeWriter& ngeOut) const ; virtual bool Load( NgeReader& ngeIn) ; public : SurfTriMesh( void) ; const SurfTriMesh& operator =( const SurfTriMesh& stSrc) { if ( ! CopyFrom( stSrc)) LOG_ERROR( GetEGkLogger(), "SurfTriMesh : copy error") return *this ; } private : bool CopyFrom( const SurfTriMesh& clSrc) ; bool Validate( void) ; bool AdjustAdjacencies( void) ; bool AdjustOrientations( int nLev, bool& bSomeWrong) ; bool TestClosure( 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 GetAllTriaAroundVertex( int nV, INTVECTOR& vT, bool& bCirc) 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]) ; private : enum Status { ERR = 0, OK = 1, TO_VERIFY = 2} ; private : typedef std::vector VERTVECTOR ; typedef std::vector TRIAVECTOR ; private : ObjGraphicsMgr m_OGrMgr ; // gestore grafica dell'oggetto Status m_nStatus ; // stato double m_dLinTol ; // tolleranza lineare di costruzione double m_dSmoothAng ; // angolo limite per mediare le normali (in gradi) double m_dCosSmAng ; // coseno dell'angolo precedente bool m_bClosed ; // la superficie racchiude un volume VERTVECTOR m_vVert ; // vettore dei vertici TRIAVECTOR m_vTria ; // vettore dei triangoli } ;