Files
EgtGeomKernel/SurfTriMesh.h
T
Dario Sassi 1b85e111dc EgtGeomKernel 1.6b7 :
- aggiunto calcolo baricentro di Curve
- migliorata gestione richiesta nuovo Id
- aggiunta intersezione linea-piano e linea-triangolo
- corretto errore in PointGrid3d con 1 solo punto (non faceva alcunchè)
- aggiunte funzioni di accesso a dati di SurfTM.
2015-02-24 22:47:10 +00:00

206 lines
10 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>
//----------------------------------------------------------------------------
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, 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 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 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 ;
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 :
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 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<StmVert> VERTVECTOR ;
typedef std::vector<StmTria> TRIAVECTOR ;
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_bClosed ; // la superficie racchiude un volume
VERTVECTOR m_vVert ; // vettore dei vertici
TRIAVECTOR m_vTria ; // vettore dei triangoli
int m_nTempProp ; // proprietà temporanea
} ;