5d09d963e7
- modifiche per lettura/scrittura Zmap con tridexel.
461 lines
14 KiB
C++
461 lines
14 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2016
|
|
//----------------------------------------------------------------------------
|
|
// File : VolZmap.cpp Data : 22.01.15 Versione : 1.6a4
|
|
// Contenuto : Implementazione della classe Volume Zmap (singola griglia)
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 22.01.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "VolZmap.h"
|
|
#include "GeoObjFactory.h"
|
|
#include "NgeWriter.h"
|
|
#include "NgeReader.h"
|
|
#include "GeoConst.h"
|
|
#include "\EgtDev\Include\EGkIntervals.h"
|
|
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
GEOOBJ_REGISTER( VOL_ZMAP, NGE_V_ZMP, VolZmap) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
VolZmap::VolZmap(void)
|
|
: m_nStatus( TO_VERIFY), m_dStep( EPS_SMALL), m_nTempProp( 0), m_dLinTol( LIN_TOL_STD), m_dAngTolDeg( ANG_TOL_APPROX_DEG)
|
|
{
|
|
m_nMapNum = 0 ;
|
|
for ( int i = 0 ; i < N_MAPS ; ++ i) {
|
|
m_nVNx[i] = 0 ;
|
|
m_nVNy[i] = 0 ;
|
|
m_nVDim[i] = 0 ;
|
|
m_dVMinZ[i] = 0 ;
|
|
m_dVMaxZ[i] = 0 ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
VolZmap::~VolZmap( void)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Clear( void)
|
|
{
|
|
m_nStatus = TO_VERIFY ;
|
|
m_nMapNum = 0 ;
|
|
for ( int i = 0 ; i < N_MAPS ; ++ i) {
|
|
m_MapFrame[i].Reset() ;
|
|
m_nVNx[i] = 0 ;
|
|
m_nVNy[i] = 0 ;
|
|
m_nVDim[i] = 0 ;
|
|
m_dVMinZ[i] = 0 ;
|
|
m_dVMaxZ[i] = 0 ;
|
|
m_TriZValues[i].clear() ;
|
|
}
|
|
m_dStep = EPS_SMALL ;
|
|
m_dLinTol = LIN_TOL_STD ;
|
|
m_dAngTolDeg = ANG_TOL_APPROX_DEG;
|
|
|
|
m_nTempProp = 0 ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
VolZmap*
|
|
VolZmap::Clone( void) const
|
|
{
|
|
// alloco oggetto
|
|
VolZmap* pVzm = new(nothrow) VolZmap ;
|
|
if ( pVzm != nullptr) {
|
|
if ( ! pVzm->CopyFrom( *this)) {
|
|
delete pVzm ;
|
|
return nullptr ;
|
|
}
|
|
}
|
|
|
|
return pVzm ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::CopyFrom( const IGeoObj* pGObjSrc)
|
|
{
|
|
const VolZmap* pVzm = dynamic_cast<const VolZmap*>( pGObjSrc) ;
|
|
if ( pVzm == nullptr)
|
|
return false ;
|
|
return CopyFrom( *pVzm) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::CopyFrom( const VolZmap& vzmSrc)
|
|
{
|
|
if ( &vzmSrc == this)
|
|
return true ;
|
|
m_OGrMgr.Reset() ;
|
|
|
|
m_nMapNum = vzmSrc.m_nMapNum ;
|
|
|
|
for ( int i = 0 ; i < int ( m_nMapNum) ; ++ i) {
|
|
|
|
m_MapFrame[i] = vzmSrc.m_MapFrame[i] ;
|
|
|
|
m_nVNx[i] = vzmSrc.m_nVNx[i] ;
|
|
m_nVNy[i] = vzmSrc.m_nVNy[i] ;
|
|
m_nVDim[i] = vzmSrc.m_nVDim[i] ;
|
|
|
|
m_dVMinZ[i] = vzmSrc.m_dVMinZ[i] ;
|
|
m_dVMaxZ[i] = vzmSrc.m_dVMaxZ[i] ;
|
|
|
|
m_TriZValues[i] = vzmSrc.m_TriZValues[i] ;
|
|
}
|
|
|
|
m_dStep = vzmSrc.m_dStep ;
|
|
m_nStatus = vzmSrc.m_nStatus ;
|
|
m_nTempProp = vzmSrc.m_nTempProp ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
GeoObjType
|
|
VolZmap::GetType( void) const
|
|
{
|
|
return static_cast<GeoObjType>( GEOOBJ_GETTYPE( VolZmap)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
const string&
|
|
VolZmap::GetTitle( void) const
|
|
{
|
|
static const string sTitle = "Zmap" ;
|
|
return sTitle ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Dump( string& sOut, bool bMM, const char* szNewLine) const
|
|
{
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
VolZmap::GetNgeId( void) const
|
|
{
|
|
return GEOOBJ_GETNGEID( VolZmap) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Save( NgeWriter& ngeOut) const
|
|
{
|
|
// numero di mappe
|
|
if ( ! ngeOut.WriteInt( m_nMapNum, ";", true))
|
|
return false ;
|
|
// per ogni mappa : sistema di riferimento, numero di passi in X e Y intrinseci
|
|
for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) {
|
|
if ( ! ngeOut.WriteFrame( m_MapFrame[i], ";", true))
|
|
return false ;
|
|
if ( ! ngeOut.WriteInt( m_nVNx[i], ",", false))
|
|
return false ;
|
|
if ( ! ngeOut.WriteInt( m_nVNy[i], ";", true))
|
|
return false ;
|
|
}
|
|
// passo di campionamento (distanza tra spilloni)
|
|
if ( ! ngeOut.WriteDouble( m_dStep, ";", true))
|
|
return false ;
|
|
// ciclo sulle mappe
|
|
for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) {
|
|
// ciclo sui dexel
|
|
for ( unsigned int j = 0 ; j < m_nVDim[i] ; ++ j) {
|
|
// numero di estremi
|
|
unsigned int nDim = unsigned int( m_TriZValues[i][j].size()) ;
|
|
if ( ! ngeOut.WriteInt( nDim, ",", false))
|
|
return false ;
|
|
// se dexel nullo
|
|
if ( nDim == 0) {
|
|
// scrivo un valore dummy
|
|
if ( ! ngeOut.WriteDouble( 0, ";", true))
|
|
return false ;
|
|
}
|
|
// altrimenti
|
|
else {
|
|
for ( unsigned int k = 0 ; k < nDim ; ++ k) {
|
|
bool bEndL = ( k == nDim - 1) ;
|
|
if ( ! ngeOut.WriteDouble( m_TriZValues[i][j][k], ( bEndL ? ";" : ","), bEndL))
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Load( NgeReader& ngeIn)
|
|
{
|
|
Clear() ;
|
|
// numero di mappe
|
|
if ( ! ngeIn.ReadInt( m_nMapNum, ";", true))
|
|
return false ;
|
|
// per ogni mappa : sistema di riferimento, numero di passi in X e Y intrinseci
|
|
for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) {
|
|
if ( ! ngeIn.ReadFrame( m_MapFrame[i], ";", true))
|
|
return false ;
|
|
if ( ! ngeIn.ReadInt( m_nVNx[i], ",", false))
|
|
return false ;
|
|
if ( ! ngeIn.ReadInt( m_nVNy[i], ";", true))
|
|
return false ;
|
|
m_nVDim[i] = m_nVNx[i] * m_nVNy[i] ;
|
|
}
|
|
// passo di campionamento (distanza tra spilloni)
|
|
if ( ! ngeIn.ReadDouble( m_dStep, ";", true))
|
|
return false ;
|
|
// ciclo sulle mappe
|
|
for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) {
|
|
// dimensiono i vettori
|
|
m_TriZValues[i].resize( m_nVDim[i]) ;
|
|
// ciclo sui dexel
|
|
for ( unsigned int j = 0 ; j < m_nVDim[i] ; ++ j) {
|
|
// leggo il numero di estremi nel dexel
|
|
unsigned int nDim ;
|
|
if ( ! ngeIn.ReadInt( nDim, ",", false))
|
|
return false ;
|
|
// devono essere pari
|
|
if ( ( nDim % 2) != 0)
|
|
return false ;
|
|
// se dexel nullo
|
|
if ( nDim == 0) {
|
|
// leggo un valore dummy
|
|
double dDummy ;
|
|
if ( ! ngeIn.ReadDouble( dDummy, ";", true))
|
|
return false ;
|
|
}
|
|
// altrimenti
|
|
else {
|
|
// dimensiono l'array
|
|
m_TriZValues[i][j].resize( nDim) ;
|
|
// leggo i valori
|
|
for ( unsigned int k = 0 ; k < nDim ; ++ k) {
|
|
bool bEndL = ( k == nDim - 1) ;
|
|
if ( ! ngeIn.ReadDouble( m_TriZValues[i][j][k], ( bEndL ? ";" : ","), bEndL))
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
m_nStatus = OK ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::GetLocalBBox( BBox3d& b3Loc, int nFlag) const
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// reset box
|
|
b3Loc.Reset() ;
|
|
// se richiesto approssimato
|
|
if ( ( nFlag & BBF_EXACT) == 0) {
|
|
b3Loc.Add( ORIG) ;
|
|
b3Loc.Add( Point3d( m_nVNx[0] * m_dStep, m_nVNy[0] * m_dStep, m_dVMaxZ[0])) ;
|
|
b3Loc.ToGlob( m_MapFrame[0]) ;
|
|
return true ;
|
|
}
|
|
// calcolo preciso
|
|
// ciclo sui dexel (punti in basso con ciclo aggiunto per punti in alto di ultima riga)
|
|
double dY = 0 ;
|
|
for ( size_t j = 0 ; j <= m_nVNy[0] ; ++ j) {
|
|
size_t jc = ( ( j != m_nVNy[0]) ? j : m_nVNy[0] -1) ;
|
|
double dX = 0 ;
|
|
// punto a sinistra di ogni dexel (aggiungo un ciclo per fare punto a destra di ultimo)
|
|
for ( size_t i = 0 ; i <= m_nVNx[0] ; ++ i) {
|
|
size_t ic = ( ( i != m_nVNx[0]) ? i : m_nVNx[0] -1) ;
|
|
size_t nPos = ic + jc * m_nVNx[0] ;
|
|
if ( m_TriZValues[0][nPos].size() > 0) {
|
|
Point3d ptP = m_MapFrame[0].Orig() + dX * m_MapFrame[0].VersX() + dY * m_MapFrame[0].VersY() ;
|
|
b3Loc.Add( ptP + m_TriZValues[0][nPos][0] * m_MapFrame[0].VersZ()) ;
|
|
b3Loc.Add( ptP + m_TriZValues[0][nPos][m_TriZValues[0][nPos].size()-1] * m_MapFrame[0].VersZ()) ;
|
|
}
|
|
// passo al punto successivo
|
|
dX += m_dStep ;
|
|
}
|
|
// passo alla riga successiva
|
|
dY += m_dStep ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// reset box
|
|
b3Ref.Reset() ;
|
|
// trasformo il riferimento locale tramite quello passato
|
|
Frame3d frUse = m_MapFrame[0] ;
|
|
frUse.ToGlob( frRef) ;
|
|
// se richiesto approssimato
|
|
if ( ( nFlag & BBF_EXACT) == 0) {
|
|
b3Ref.Add( ORIG) ;
|
|
b3Ref.Add( Point3d( m_nVNx[0] * m_dStep, m_nVNy[0] * m_dStep, m_dVMaxZ[0])) ;
|
|
b3Ref.ToGlob( frUse) ;
|
|
return true ;
|
|
}
|
|
// calcolo preciso
|
|
// ciclo sui dexel (punti in basso con ciclo aggiunto per punti in alto di ultima riga)
|
|
double dY = 0 ;
|
|
for ( size_t j = 0 ; j <= m_nVNy[0] ; ++ j) {
|
|
size_t jc = ( ( j != m_nVNy[0]) ? j : m_nVNy[0] -1) ;
|
|
double dX = 0 ;
|
|
// punto a sinistra di ogni dexel (aggiungo un ciclo per fare punto a destra di ultimo)
|
|
for ( size_t i = 0 ; i <= m_nVNx[0] ; ++ i) {
|
|
size_t ic = ( ( i != m_nVNx[0]) ? i : m_nVNx[0] -1) ;
|
|
size_t nPos = ic + jc * m_nVNx[0] ;
|
|
if ( m_TriZValues[0][nPos].size() > 0) {
|
|
Point3d ptP = frUse.Orig() + dX * frUse.VersX() + dY * frUse.VersY() ;
|
|
b3Ref.Add( ptP + m_TriZValues[0][nPos][0] * frUse.VersZ()) ;
|
|
b3Ref.Add( ptP + m_TriZValues[0][nPos][m_TriZValues[0][nPos].size()-1] * frUse.VersZ()) ;
|
|
}
|
|
// passo al punto successivo
|
|
dX += m_dStep ;
|
|
}
|
|
// passo alla riga successiva
|
|
dY += m_dStep ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Translate( const Vector3d& vtMove)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// traslo i riferimenti
|
|
for ( int i = 0 ; i < int( m_nMapNum) ; ++ i)
|
|
m_MapFrame[i].Translate( vtMove) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// ruoto i riferimenti
|
|
for ( int i = 0 ; i < int( m_nMapNum) ; ++ i)
|
|
m_MapFrame[i].Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::ToGlob( const Frame3d& frRef)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// trasformo il riferimento
|
|
for ( int i = 0 ; i < int ( m_nMapNum) ; ++ i)
|
|
m_MapFrame[i].ToGlob( frRef) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::ToLoc( const Frame3d& frRef)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// trasformo il riferimento
|
|
for ( int i = 0 ; i < int( m_nMapNum) ; ++ i)
|
|
m_MapFrame[i].ToLoc( frRef) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
VolZmap::LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
|
|
{
|
|
// verifico lo stato
|
|
if ( m_nStatus != OK)
|
|
return false ;
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// trasformo il riferimento
|
|
for ( int i = 0 ; i < int( m_nMapNum) ; ++ i)
|
|
m_MapFrame[i].LocToLoc( frOri, frDest) ;
|
|
return true ;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|