Files
EgtGeomKernel/CurveLine.cpp
T

292 lines
7.2 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 <new>
#include "\EgtDev\Include\EGnStringUtils.h"
#include "CurveLine.h"
#include "GeoObjFactory.h"
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( CRV_LINE, "C_LIN", CurveLine) ;
//----------------------------------------------------------------------------
CurveLine::CurveLine( void)
{
m_PtStart.Set( 0, 0, 0) ;
m_PtEnd.Set( 0, 0, 0) ;
m_nStatus = TO_VERIFY ;
}
//----------------------------------------------------------------------------
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::Validate( void)
{
if ( m_nStatus == TO_VERIFY)
m_nStatus = ( ( DistSq( 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::GetDomain( double& dStart, double& dEnd) const
{
// verifico lo stato
if ( m_nStatus != OK)
return false ;
// assegno gli estremi del dominio
dStart = 0 ;
dEnd = 1 ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetPointD1D2( double dU, Point3d& ptPos, Vector3d& vtDer1, Vector3d& vtDer2) 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
vtDer1 = m_PtEnd - m_PtStart ;
// derivata seconda nulla
vtDer2.Set( 0, 0, 0) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CurveLine::GetLength( double& dLen) const
{
dLen = Dist( m_PtStart, m_PtEnd) ;
return ( dLen > EPS_SMALL) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Reverse( void)
{
// inverto i punti estremi
swap( m_PtStart, m_PtEnd) ;
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 Point3d& ptCen, 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( ptCen, dCoeffX, dCoeffY, dCoeffZ) ;
m_PtEnd.Scale( ptCen, 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 ;
}