2cbdfc1db9
- cambiato Load, con uso di NgeReader.
158 lines
6.9 KiB
C++
158 lines
6.9 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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"
|
|
|
|
//----------------------------------------------------------------------------
|
|
const int VT_NULL = - 1 ; // vertice o triangolo nullo
|
|
const int VT_DEL = - 2 ; // vertice o triangolo cancellato
|
|
|
|
//----------------------------------------------------------------------------
|
|
class StmVert
|
|
{
|
|
public :
|
|
StmVert( void) : ptP(), nIdTria( VT_NULL), nFlag( 0) {}
|
|
StmVert( const Point3d& ptQ) : ptP( ptQ), nIdTria( VT_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] = VT_NULL ; nIdVert[1] = VT_NULL ; nIdVert[2] = VT_NULL ;
|
|
nIdAdjac[0] = VT_NULL ; nIdAdjac[1] = VT_NULL ; nIdAdjac[2] = VT_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] = VT_NULL ; nIdAdjac[1] = VT_NULL ; nIdAdjac[2] = VT_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 dCosAng, double dSinAng) ;
|
|
virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad)
|
|
{ return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; }
|
|
virtual bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) ;
|
|
virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) ;
|
|
virtual bool ToGlob( const Frame3d& frRef) ;
|
|
virtual bool ToLoc( const Frame3d& frRef) ;
|
|
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 Copy( const IGeoObj* pGObjSrc) ;
|
|
virtual bool Init( int nNumVert, int nNumTria) ;
|
|
virtual int AddVertex( const Point3d& ptVert) ;
|
|
virtual int AddTriangle( const int nIdVert[3]) ;
|
|
virtual bool AdjustTopology( void) ;
|
|
virtual bool CreateByTriangulation( const PolyLine& PL) ;
|
|
virtual bool CreateByExtrusion( const PolyLine& PL, const Vector3d& vtExtr) ;
|
|
virtual int GetVertexNum( void) const
|
|
{ return int( m_vVert.size()) ; }
|
|
virtual int GetTriangleNum( void) const
|
|
{ return int( m_vTria.size()) ; }
|
|
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 ( ! Copy( stSrc))
|
|
LOG_ERROR( GetEGkLogger(), "SurfTriMesh : copy error")
|
|
return *this ; }
|
|
|
|
private :
|
|
bool Copy( 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) const ;
|
|
bool GetTriangleSmoothNormal( int nT, int nV, Vector3d& vtN) const ;
|
|
|
|
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
|
|
bool m_bClosed ; // la superficie racchiude un volume
|
|
VERTVECTOR m_vVert ; // vettore dei vertici
|
|
TRIAVECTOR m_vTria ; // vettore dei triangoli
|
|
} ;
|