EgtExchange 1.5e3 :
- aggiunto fattore di scalatura a ImportStl - uso di PointGrid3d in import STL invece di ordinamento lessicografico.
This commit is contained in:
+51
-51
@@ -19,11 +19,15 @@
|
||||
#include "/EgtDEv/Include/EGnScan.h"
|
||||
#include "/EgtDev/Include/EgnStringUtils.h"
|
||||
#include "/EgtDev/Include/EgnStringConverter.h"
|
||||
#include "/EgtDev/Include/EGkPointGrid3d.h"
|
||||
#include "/EgtDev/Include/EGkGeomDB.h"
|
||||
#include "/EgtDev/Include/EGkSurfTriMesh.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static const int GRID_NUM_BUCKETS = 50000 ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
IImportStl*
|
||||
CreateImportStl( void)
|
||||
@@ -33,13 +37,35 @@ CreateImportStl( void)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ImportStl::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
ImportStl::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup, double dScaleFactor)
|
||||
{
|
||||
// verifico il DB geometrico
|
||||
if ( pGDB == nullptr) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on GeomDB")
|
||||
return false ;
|
||||
}
|
||||
m_pGDB = pGDB ;
|
||||
|
||||
// verifico l'Id di gruppo
|
||||
if ( ! m_pGDB->ExistsObj( nIdGroup)) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on IdGroup")
|
||||
return false ;
|
||||
}
|
||||
m_nIdGroup = nIdGroup ;
|
||||
|
||||
// verifico il fattore di scala
|
||||
if ( dScaleFactor < EPS_SMALL) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on ScaleFactor too small (minimum 0.001).")
|
||||
return false ;
|
||||
}
|
||||
m_dScaleFactor = dScaleFactor ;
|
||||
|
||||
// eseguo l'opportuna importazione
|
||||
switch ( StlType( sFile)) {
|
||||
case STL_ASCII :
|
||||
return ImportASCII( sFile, pGDB, nIdGroup) ;
|
||||
return ImportASCII( sFile) ;
|
||||
case STL_BINARY :
|
||||
return ImportBinary( sFile, pGDB, nIdGroup) ;
|
||||
return ImportBinary( sFile) ;
|
||||
default :
|
||||
return false ;
|
||||
}
|
||||
@@ -78,7 +104,7 @@ ImportStl::StlType( const std::string& sFile)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ImportStl::ImportASCII( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
ImportStl::ImportASCII( const string& sFile)
|
||||
{
|
||||
// inizializzo lo scanner
|
||||
Scanner TheScanner ;
|
||||
@@ -87,20 +113,6 @@ ImportStl::ImportASCII( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
return false ;
|
||||
}
|
||||
|
||||
// verifico il DB geometrico
|
||||
if ( pGDB == nullptr) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on GeomDB")
|
||||
return false ;
|
||||
}
|
||||
m_pGDB = pGDB ;
|
||||
|
||||
// verifico l'Id di gruppo
|
||||
if ( ! m_pGDB->ExistsObj( nIdGroup)) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on IdGroup")
|
||||
return false ;
|
||||
}
|
||||
m_nIdGroup = nIdGroup ;
|
||||
|
||||
// ciclo di lettura degli oggetti
|
||||
bool bOk = true ;
|
||||
bool bEnd = false ;
|
||||
@@ -151,15 +163,15 @@ ImportStl::LoadSolid( Scanner& TheScanner, bool& bEnd)
|
||||
return false ;
|
||||
}
|
||||
|
||||
// Map dei vertici ( lexicographic -> usare epsilon piccoli)
|
||||
CmpPnt comp( EPS_SMALL) ;
|
||||
PntIntMap MapVert( comp) ;
|
||||
// Grid dei vertici
|
||||
PointGrid3d VertGrid ;
|
||||
VertGrid.Init( GRID_NUM_BUCKETS) ;
|
||||
|
||||
// ciclo di lettura dei triangoli
|
||||
bool bOk = true ;
|
||||
bool bTEnd = false ;
|
||||
do {
|
||||
if ( ! LoadTriangle( TheScanner, Get( pSTM), MapVert, bTEnd)) {
|
||||
if ( ! LoadTriangle( TheScanner, Get( pSTM), VertGrid, bTEnd)) {
|
||||
bOk = false ;
|
||||
string sOut = "ImportStl : Error on line " + ToString( TheScanner.GetCurrLineNbr()) ;
|
||||
LOG_ERROR( GetEExLogger(), sOut.c_str())
|
||||
@@ -195,7 +207,7 @@ ImportStl::LoadSolid( Scanner& TheScanner, bool& bEnd)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ImportStl::LoadTriangle( Scanner& TheScanner, ISurfTriMesh* pSTM, PntIntMap& MapVert, bool& bEnd)
|
||||
ImportStl::LoadTriangle( Scanner& TheScanner, ISurfTriMesh* pSTM, PointGrid3d& VertGrid, bool& bEnd)
|
||||
{
|
||||
string sLine ;
|
||||
STRVECTOR vsParams ;
|
||||
@@ -230,7 +242,6 @@ ImportStl::LoadTriangle( Scanner& TheScanner, ISurfTriMesh* pSTM, PntIntMap& Map
|
||||
|
||||
// ciclo sui tre vertici
|
||||
int nIdV[3] ;
|
||||
PntIntMap::iterator Iter ;
|
||||
for ( int i = 0 ; i < 3 ; ++ i) {
|
||||
// recupero una linea
|
||||
if ( ! TheScanner.GetLine( sLine))
|
||||
@@ -249,16 +260,18 @@ ImportStl::LoadTriangle( Scanner& TheScanner, ISurfTriMesh* pSTM, PntIntMap& Map
|
||||
! FromString( vsParams[2], ptP.y) ||
|
||||
! FromString( vsParams[3], ptP.z))
|
||||
return false ;
|
||||
// scalo il vertice
|
||||
ptP *= m_dScaleFactor ;
|
||||
// verifico se vertice già presente
|
||||
Iter = MapVert.find( ptP) ;
|
||||
if ( Iter == MapVert.end()) {
|
||||
int nId ;
|
||||
if ( ! VertGrid.Find( ptP, 2 * EPS_SMALL, nId)) {
|
||||
// aggiungo il vertice
|
||||
if ( ( nIdV[i] = pSTM->AddVertex( ptP)) == SVT_NULL)
|
||||
return false ;
|
||||
MapVert[ptP] = nIdV[i] ;
|
||||
VertGrid.InsertPoint( ptP, nIdV[i]) ;
|
||||
}
|
||||
else
|
||||
nIdV[i] = Iter->second ;
|
||||
nIdV[i] = nId ;
|
||||
}
|
||||
|
||||
// se i vertici sono tutti diversi tra loro, inserisco il triangolo
|
||||
@@ -297,7 +310,7 @@ ImportStl::LoadTriangle( Scanner& TheScanner, ISurfTriMesh* pSTM, PntIntMap& Map
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ImportStl::ImportBinary( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
ImportStl::ImportBinary( const string& sFile)
|
||||
{
|
||||
// apertura del file di ingresso
|
||||
ifstream InFile ;
|
||||
@@ -305,20 +318,6 @@ ImportStl::ImportBinary( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
if ( InFile.fail())
|
||||
return false ;
|
||||
|
||||
// verifico il DB geometrico
|
||||
if ( pGDB == nullptr) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on GeomDB")
|
||||
return false ;
|
||||
}
|
||||
m_pGDB = pGDB ;
|
||||
|
||||
// verifico l'Id di gruppo
|
||||
if ( ! m_pGDB->ExistsObj( nIdGroup)) {
|
||||
LOG_ERROR( GetEExLogger(), "ImportStl : Error on IdGroup")
|
||||
return false ;
|
||||
}
|
||||
m_nIdGroup = nIdGroup ;
|
||||
|
||||
// lettura dei primi ottanta byte (commento da scartare)
|
||||
const int LEN_REM = 80 ;
|
||||
char cRem[LEN_REM] ;
|
||||
@@ -344,9 +343,9 @@ ImportStl::ImportBinary( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
return false ;
|
||||
}
|
||||
|
||||
// Map dei vertici ( lexicographic -> usare epsilon piccoli)
|
||||
CmpPnt comp( EPS_SMALL) ;
|
||||
PntIntMap MapVert( comp) ;
|
||||
// Grid dei vertici
|
||||
PointGrid3d VertGrid ;
|
||||
VertGrid.Init( GRID_NUM_BUCKETS) ;
|
||||
|
||||
// lettura dei triangoli
|
||||
for ( int j = 0 ; j < uTria.i ; ++ j) {
|
||||
@@ -358,7 +357,6 @@ ImportStl::ImportBinary( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
return false ;
|
||||
// ciclo sui tre vertici
|
||||
int nIdV[3] ;
|
||||
PntIntMap::iterator Iter ;
|
||||
for ( int i = 0 ; i < 3 ; ++ i) {
|
||||
const int LEN_3F = 12 ;
|
||||
union { float f[3]; char c[LEN_3F]; } ufP ;
|
||||
@@ -366,16 +364,18 @@ ImportStl::ImportBinary( const string& sFile, IGeomDB* pGDB, int nIdGroup)
|
||||
if ( InFile.gcount() != LEN_3F)
|
||||
return false ;
|
||||
Point3d ptP( ufP.f[0], ufP.f[1], ufP.f[2]) ;
|
||||
// scalo il vertice
|
||||
ptP *= m_dScaleFactor ;
|
||||
// verifico se vertice già presente
|
||||
Iter = MapVert.find( ptP) ;
|
||||
if ( Iter == MapVert.end()) {
|
||||
int nId ;
|
||||
if ( ! VertGrid.Find( ptP, 2 * EPS_SMALL, nId)) {
|
||||
// aggiungo il vertice
|
||||
if ( ( nIdV[i] = pSTM->AddVertex( ptP)) == SVT_NULL)
|
||||
return false ;
|
||||
MapVert[ptP] = nIdV[i] ;
|
||||
VertGrid.InsertPoint( ptP, nIdV[i]) ;
|
||||
}
|
||||
else
|
||||
nIdV[i] = Iter->second ;
|
||||
nIdV[i] = nId ;
|
||||
}
|
||||
|
||||
// se i vertici sono tutti diversi tra loro, inserisco il triangolo
|
||||
|
||||
Reference in New Issue
Block a user