Files
EgtGeomKernel/CurveLine.cpp
T
Dario Sassi 4ebb43bf1e EgtGeomKernel 1.5a6 : prima versione di scalatura non uniforme,
aggiunto comando COUNTER in tsc.
2014-01-19 11:19:56 +00:00

420 lines
10 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : CurveLine.cpp Data : 16.04.13 Versione : 1.1d1
// Contenuto : Implementazione della classe Segmento di Linea.
//
//
//
// Modifiche : 16.04.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "CurveLine.h"
#include "GeoObjFactory.h"
#include "\EgtDev\Include\EGnStringUtils.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( CRV_LINE, "C_LIN", CurveLine) ;
//----------------------------------------------------------------------------
CurveLine::CurveLine( void)
: m_nStatus( TO_VERIFY), m_PtStart(), m_PtEnd()
{
}
//----------------------------------------------------------------------------
CurveLine::~CurveLine( void)
{
}
//----------------------------------------------------------------------------
bool
CurveLine::Set( const Point3d& ptStart, const Point3d& ptEnd)
{
m_PtStart = ptStart ;
m_PtEnd = ptEnd ;
m_nStatus = TO_VERIFY ;
return Validate() ;
}
//----------------------------------------------------------------------------
CurveLine*
CurveLine::Clone( void) const
{
CurveLine* pCrv ;
// alloco oggetto
pCrv = new(nothrow) CurveLine ;
if ( pCrv != nullptr)
*pCrv = *(const_cast<CurveLine*>(this)) ;
return pCrv ;
}
//----------------------------------------------------------------------------
const string&
CurveLine::GetKey( void) const
{
return GEOOBJ_GETKEY( CurveLine) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Save( ostream& osOut) const
{
// parametri : punti iniziale e finale
osOut << ToString( m_PtStart) ;
osOut << ";" << ToString( m_PtEnd) << ";" << endl ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Load( Scanner& TheScanner)
{
string sLine ;
STRVECTOR vsParams ;
// leggo la prossima linea
if ( ! TheScanner.GetLine( sLine))
return false ;
// la divido in parametri
Tokenize( sLine, ";", vsParams) ;
// 2 parametri : punto iniziale e punto finale
if ( vsParams.size() != 2)
return false ;
// recupero il punto iniziale
if ( ! FromString( vsParams[0], m_PtStart))
return false ;
// recupero il punto finale
if ( ! FromString( vsParams[1], m_PtEnd))
return false ;
// eseguo validazione
return Validate() ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetLocalBBox( BBox3d& b3Loc) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// assegno il box in locale
b3Loc.Set( m_PtStart, m_PtEnd) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// verifico validità del frame
if ( frRef.GetType() == Frame3d::ERR)
return false ;
// porto gli estremi nel riferimento passato
Point3d ptFrStart = m_PtStart ;
ptFrStart.ToGlob( frRef) ;
Point3d ptFrEnd = m_PtEnd ;
ptFrEnd.ToGlob( frRef) ;
// assegno il box nel riferimento
b3Ref.Set( ptFrStart, ptFrEnd) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Validate( void)
{
if ( m_nStatus == TO_VERIFY)
m_nStatus = ( ( SqDist( m_PtStart, m_PtEnd) > EPS_SMALL * EPS_SMALL) ? OK : ERR) ;
return ( m_nStatus == OK) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetStartPoint( Point3d& ptStart) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// assegno il punto
ptStart = m_PtStart ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetEndPoint( Point3d& ptEnd) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// assegno il punto
ptEnd = m_PtEnd ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetPointD1D2( double dU, Side nS, Point3d& ptPos, Vector3d* pvtDer1, Vector3d* pvtDer2) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// il parametro U deve essere compreso tra 0 e 1
if ( dU < 0)
dU = 0 ;
else if ( dU > 1)
dU = 1 ;
// calcolo del punto
ptPos = Media( m_PtStart, m_PtEnd, dU) ;
// calcolo della derivata prima
if ( pvtDer1 != nullptr)
*pvtDer1 = m_PtEnd - m_PtStart ;
// derivata seconda nulla
if ( pvtDer2 != nullptr && pvtDer1 != nullptr)
pvtDer2->Set( 0, 0, 0) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetLength( double& dLen) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// la lunghezza è la distanza tra gli estremi
dLen = Dist( m_PtStart, m_PtEnd) ;
return ( dLen > EPS_SMALL) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::ApproxWithLines( double dLinTol, double dAngTolDeg, PolyLine& PL) const
{
// la curva deve essere validata
if ( m_nStatus != OK)
return false ;
// inserisco gli estremi
PL.AddUPoint( 0, m_PtStart) ;
PL.AddUPoint( 1, m_PtEnd) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Invert( void)
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// inverto i punti estremi
swap( m_PtStart, m_PtEnd) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::TrimStartAtParam( double dUTrim)
{
double dLen ;
// riporto i parametri nel loro range
dUTrim = ( ( dUTrim < 0) ? 0 : (( dUTrim > 1) ? 1 : dUTrim)) ;
// recupero lunghezza
if ( ! GetLength( dLen))
return false ;
// utilizzo il trim sulle lunghezze
return TrimStartAtLen( dUTrim * dLen) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::TrimEndAtParam( double dUTrim)
{
double dLen ;
// riporto i parametri nel loro range
dUTrim = ( ( dUTrim < 0) ? 0 : (( dUTrim > 1) ? 1 : dUTrim)) ;
// recupero lunghezza
if ( ! GetLength( dLen))
return false ;
// utilizzo il trim sulle lunghezze
return TrimEndAtLen( dUTrim * dLen) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::TrimStartAtLen( double dLenTrim)
{
double dLen ;
// lunghezze negative vengono considerate nulle
dLenTrim = __max( dLenTrim, 0) ;
// verifico che sia abbastanza lunga
if ( ! GetLength( dLen))
return false ;
if ( ( dLen - dLenTrim) < EPS_SMALL)
return false ;
// eseguo il trim
if ( dLenTrim > EPS_ZERO)
m_PtStart = Media( m_PtStart, m_PtEnd, ( dLenTrim / dLen)) ;
// con i controlli sopra fatti rimane validata
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::TrimEndAtLen( double dLenTrim)
{
double dLen ;
// lunghezze negative vengono considerate nulle
dLenTrim = __max( dLenTrim, 0) ;
// verifico che sia abbastanza lunga
if ( ! GetLength( dLen))
return false ;
if ( dLenTrim < EPS_SMALL)
return false ;
// eseguo il trim
if ( ( dLen - dLenTrim) > EPS_ZERO)
m_PtEnd = Media( m_PtStart, m_PtEnd, ( dLenTrim / dLen)) ;
// con i controlli sopra fatti rimane validata
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Translate( const Vector3d& vtMove)
{
// traslo i punti estremi
m_PtStart.Translate( vtMove) ;
m_PtEnd.Translate( vtMove) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
{
// verifico validità dell'asse di rotazione
if ( vtAx.IsSmall())
return false ;
// ruoto i punti estremi
m_PtStart.Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
m_PtEnd.Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
{
// verifico non sia nulla
if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO)
return false ;
// scalo i punti estremi
m_PtStart.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ;
m_PtEnd.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ;
m_nStatus = TO_VERIFY ;
return Validate() ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
{
// verifico validità del piano di specchiatura
if ( vtNorm.IsSmall())
return false ;
// specchio i punti estremi
m_PtStart.Mirror( ptOn, vtNorm) ;
m_PtEnd.Mirror( ptOn, vtNorm) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::ToGlob( const Frame3d& frRef)
{
// verifico validità del frame
if ( frRef.GetType() == Frame3d::ERR)
return false ;
// trasformo i punti estremi
m_PtStart.ToGlob( frRef) ;
m_PtEnd.ToGlob( frRef) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::ToLoc( const Frame3d& frRef)
{
// verifico validità del frame
if ( frRef.GetType() == Frame3d::ERR)
return false ;
// trasformo i punti estremi
m_PtStart.ToLoc( frRef) ;
m_PtEnd.ToLoc( frRef) ;
return true ;
}