Files
EgtGeomKernel/StringUtils3d.cpp
T
Dario Sassi 01ce6ea4a4 EgtGeomKernel 1.5c5 :
- IGdbIterator può utilizzare un altro IGdbIterator per andare sul gruppo
- aggiunta gestione nomi di colori standard
- Aggiunte ToString e FromString per Color
- TSC ora accetta colori standard da nome.
2014-03-12 21:19:47 +00:00

128 lines
4.3 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : StringUtils3d.cpp Data : 10.03.14 Versione : 1.5c3
// Contenuto : Implementazione delle funzioni di utilità 3d per le stringhe.
//
//
//
// Modifiche : 31.01.14 DS Creazione modulo (preso da EgtGeneral).
// 10.03.14 DS Aggiunta lettura Frame3d.
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "/EgtDEv/Include/EgkStringUtils3d.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
FromString( const string& sVal, Vector3d& vtVal)
{
// divido la stringa in parametri
STRVECTOR vsParams ;
Tokenize( sVal, ",", vsParams) ;
// devono essere 3 parametri : x, y, z
if ( vsParams.size() != 3)
return false ;
// recupero il punto
return ( FromString( vsParams[0], vtVal.x) &&
FromString( vsParams[1], vtVal.y) &&
FromString( vsParams[2], vtVal.z)) ;
}
//----------------------------------------------------------------------------
bool
FromString( const string& sVal, Point3d& ptVal)
{
// divido la stringa in parametri
STRVECTOR vsParams ;
Tokenize( sVal, ",", vsParams) ;
// devono essere 3 parametri : x, y, z
if ( vsParams.size() != 3)
return false ;
// recupero il punto
return ( FromString( vsParams[0], ptVal.x) &&
FromString( vsParams[1], ptVal.y) &&
FromString( vsParams[2], ptVal.z)) ;
}
//----------------------------------------------------------------------------
bool
FromString( const string& sVal, Point3d& ptVal, double& dW)
{
// divido la stringa in parametri
STRVECTOR vsParams ;
Tokenize( sVal, ",", vsParams) ;
// devono essere 4 parametri : x, y, z, w
if ( vsParams.size() != 4)
return false ;
// recupero il punto
return ( FromString( vsParams[0], ptVal.x) &&
FromString( vsParams[1], ptVal.y) &&
FromString( vsParams[2], ptVal.z) &&
FromString( vsParams[3], dW)) ;
}
//----------------------------------------------------------------------------
bool
FromString( const string& sVal, Frame3d& frFrame)
{
// divido la stringa in parametri
STRVECTOR vsParams ;
Tokenize( sVal, ",", vsParams) ;
// devono essere 12 parametri : Ox, Oy, Oz, Xx, Xy, Xz, Yx, Yy, Yz, Zx, Zy, Zz
if ( vsParams.size() != 12)
return false ;
// recupero l'origine
Point3d ptOrig ;
if ( ! FromString( vsParams[0], ptOrig.x) ||
! FromString( vsParams[1], ptOrig.y) ||
! FromString( vsParams[2], ptOrig.z))
return false ;
// recupero il versore X
Vector3d vtDirX ;
if ( ! FromString( vsParams[3], vtDirX.x) ||
! FromString( vsParams[4], vtDirX.y) ||
! FromString( vsParams[5], vtDirX.z))
return false ;
// recupero il versore Y
Vector3d vtDirY ;
if ( ! FromString( vsParams[6], vtDirY.x) ||
! FromString( vsParams[7], vtDirY.y) ||
! FromString( vsParams[8], vtDirY.z))
return false ;
// recupero il versore Z
Vector3d vtDirZ ;
if ( ! FromString( vsParams[9], vtDirZ.x) ||
! FromString( vsParams[10], vtDirZ.y) ||
! FromString( vsParams[11], vtDirZ.z))
return false ;
// imposto il riferimento
return frFrame.Set( ptOrig, vtDirX, vtDirY, vtDirZ) ;
}
//----------------------------------------------------------------------------
bool
FromString( const string& sVal, Color& cCol)
{
// divido la stringa in parametri
STRVECTOR vsParams ;
Tokenize( sVal, ",", vsParams) ;
// devono essere 4 parametri : Red, Green, Blue, Alpha
if ( vsParams.size() != 4)
return false ;
// recupero i parametri
int nRed, nGreen, nBlue, nAlpha ;
if ( ! FromString( vsParams[0], nRed) ||
! FromString( vsParams[1], nGreen) ||
! FromString( vsParams[2], nBlue) ||
! FromString( vsParams[3], nAlpha))
return false ;
// assegno il colore
cCol.Set( nRed, nGreen, nBlue, nAlpha) ;
return true ;
}