Merge branch 'master' into NewMakeUniform
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2026
|
||||
//----------------------------------------------------------------------------
|
||||
// File : CalcDerivate.cpp Data : 03.02.26 Versione : 1.5h1
|
||||
// Contenuto : Funzioni per calcolo derivate secondo Bessel e Akima.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 03.02.26 DB Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CalcDerivate.h"
|
||||
#include "/EgtDev/Include/EGkPoint3d.h"
|
||||
#include "/EgtDev/Include/EgtNumCollection.h"
|
||||
#include "/EgtDev/Include/EGkGeoCollection.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ComputeAkimaTangents( bool bDetectCorner, const DBLVECTOR& vPar, const PNTVECTOR& vPnt, VCT3DVECTOR& vPrevDer, VCT3DVECTOR& vNextDer)
|
||||
{
|
||||
// pulisco i vettori dei parametri e delle tangenti
|
||||
vPrevDer.clear() ;
|
||||
vNextDer.clear() ;
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return false ;
|
||||
|
||||
// calcolo le derivate
|
||||
vPrevDer.reserve( nSize) ;
|
||||
vNextDer.reserve( nSize) ;
|
||||
// se ci sono solo 2 punti, le tangenti devono essere dirette lungo la linea che li unisce
|
||||
if ( nSize == 2) {
|
||||
// non esiste derivata prima del primo punto
|
||||
vPrevDer.emplace_back( 0, 0, 0) ;
|
||||
vNextDer.push_back( ( vPnt[1] - vPnt[0]) / ( vPar[1] - vPar[0])) ;
|
||||
vPrevDer.push_back( vNextDer[0]) ;
|
||||
// non esiste derivata dopo il secondo e ultimo punto
|
||||
vNextDer.emplace_back( 0, 0, 0) ;
|
||||
return true ;
|
||||
}
|
||||
// verifico se curva chiusa (primo e ultimo punto coincidono)
|
||||
bool bClosed = AreSamePointApprox( vPnt.front(), vPnt.back()) ;
|
||||
// calcolo le derivate
|
||||
for ( int i = 0 ; i < nSize ; ++ i) {
|
||||
Vector3d vtPrevDer ;
|
||||
Vector3d vtNextDer ;
|
||||
// primo punto
|
||||
if ( i == 0) {
|
||||
// se curva chiusa, come precedente uso il penultimo punto
|
||||
if ( bClosed) {
|
||||
// se non ci sono almeno 5 punti
|
||||
if ( nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( vPar[nSize-2] - vPar[nSize-1], vPnt[nSize-2], vPar[i], vPnt[i],
|
||||
vPar[i+1], vPnt[i+1], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = vtNextDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( vPar[nSize-3] - vPar[nSize-1], vPnt[nSize-3], vPar[nSize-2] - vPar[nSize-1], vPnt[nSize-2],
|
||||
vPar[i], vPnt[i], vPar[i+1], vPnt[i+1],
|
||||
vPar[i+2], vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// altrimenti, uso arco sui primi tre punti
|
||||
else {
|
||||
if ( ! CalcCircleStartDer( vPar[i], vPnt[i], vPar[i+1], vPnt[i+1],
|
||||
vPar[i+2], vPnt[i+2], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// ultimo punto
|
||||
else if ( i == nSize - 1) {
|
||||
// se curva chiusa, le tg devono coincidere con quelle del primo
|
||||
if ( bClosed) {
|
||||
vtPrevDer = vPrevDer[0] ;
|
||||
vtNextDer = vNextDer[0] ;
|
||||
}
|
||||
// altrimenti, uso arco sugli ultimi tre punti
|
||||
else {
|
||||
if ( ! CalcCircleEndDer( vPar[i-2], vPnt[i-2], vPar[i-1], vPnt[i-1],
|
||||
vPar[i], vPnt[i], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// punti intermedi
|
||||
else {
|
||||
// se secondo punto
|
||||
if ( i == 1) {
|
||||
// se curva aperta o non ci sono almeno 5 punti
|
||||
if ( ! bClosed || nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( vPar[i-1], vPnt[i-1], vPar[i], vPnt[i],
|
||||
vPar[i+1], vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( vPar[nSize-2] - vPar[nSize-1], vPnt[nSize-2], vPar[i-1], vPnt[i-1],
|
||||
vPar[i], vPnt[i], vPar[i+1], vPnt[i+1],
|
||||
vPar[i+2], vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// se penultimo punto
|
||||
else if ( i == nSize - 2) {
|
||||
// se curva aperta o non ci sono almeno 5 punti
|
||||
if ( ! bClosed || nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( vPar[i-1], vPnt[i-1], vPar[i], vPnt[i],
|
||||
vPar[i+1], vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( vPar[i-2], vPnt[i-2], vPar[i-1], vPnt[i-1],
|
||||
vPar[i], vPnt[i], vPar[i+1], vPnt[i+1],
|
||||
vPar[1] + vPar[i+1], vPnt[1], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( vPar[i-2], vPnt[i-2], vPar[i-1], vPnt[i-1],
|
||||
vPar[i], vPnt[i], vPar[i+1], vPnt[i+1],
|
||||
vPar[i+2], vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// salvo la derivata
|
||||
vPrevDer.push_back( vtPrevDer) ;
|
||||
vNextDer.push_back( vtNextDer) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ComputeBesselTangents( const DBLVECTOR& vPar, const PNTVECTOR& vPnt, VCT3DVECTOR& vPrevDer, VCT3DVECTOR& vNextDer)
|
||||
{
|
||||
// pulisco i vettori dei parametri e delle tangenti
|
||||
vPrevDer.clear() ;
|
||||
vNextDer.clear() ;
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return false ;
|
||||
|
||||
// calcolo le derivate
|
||||
vPrevDer.reserve( nSize) ;
|
||||
vNextDer.reserve( nSize) ;
|
||||
// se ci sono solo 2 punti, le tangenti devono essere dirette lungo la linea che li unisce
|
||||
if ( nSize == 2) {
|
||||
// non esiste derivata prima del primo punto
|
||||
vPrevDer.emplace_back( 0, 0, 0) ;
|
||||
vNextDer.push_back( ( vPnt[1] - vPnt[0]) / ( vPar[1] - vPar[0])) ;
|
||||
vPrevDer.push_back( vNextDer[0]) ;
|
||||
// non esiste derivata dopo il secondo e ultimo punto
|
||||
vNextDer.emplace_back( 0, 0, 0) ;
|
||||
return true ;
|
||||
}
|
||||
// verifico se curva chiusa (primo e ultimo punto coincidono)
|
||||
bool bClosed = AreSamePointApprox( vPnt.front(), vPnt.back()) ;
|
||||
// calcolo le derivate
|
||||
for ( int i = 0 ; i < nSize ; ++ i) {
|
||||
Vector3d vtPrevDer ;
|
||||
Vector3d vtNextDer ;
|
||||
// primo punto
|
||||
if ( i == 0) {
|
||||
// se curva chiusa, come precedente uso il penultimo punto
|
||||
if ( bClosed) {
|
||||
if ( ! CalcBesselMidDer( vPar[nSize-2] - vPar[nSize-1], vPnt[nSize-2], vPar[i], vPnt[i],
|
||||
vPar[i+1], vPnt[i+1], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = vtNextDer ;
|
||||
}
|
||||
// altrimenti, uso i primi tre punti
|
||||
else {
|
||||
if ( ! CalcBesselStartDer( vPar[i], vPnt[i], vPar[i+1], vPnt[i+1],
|
||||
vPar[i+2], vPnt[i+2], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// ultimo punto
|
||||
else if ( i == nSize - 1) {
|
||||
// se curva chiusa, le tg devono coincidere con quelle del primo
|
||||
if ( bClosed) {
|
||||
vtPrevDer = vPrevDer[0] ;
|
||||
vtNextDer = vNextDer[0] ;
|
||||
}
|
||||
// altrimenti, uso gli ultimi tre punti
|
||||
else {
|
||||
if ( ! CalcBesselEndDer( vPar[i-2], vPnt[i-2], vPar[i-1], vPnt[i-1],
|
||||
vPar[i], vPnt[i], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// punti intermedi
|
||||
else {
|
||||
if ( ! CalcBesselMidDer( vPar[i-1], vPnt[i-1], vPar[i], vPnt[i],
|
||||
vPar[i+1], vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// salvo la derivata
|
||||
vPrevDer.push_back( vtPrevDer) ;
|
||||
vNextDer.push_back( vtNextDer) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "/EgtDev/Include/EGkPoint3d.h"
|
||||
#include "/EgtDev/Include/EgtNumCollection.h"
|
||||
#include "/EgtDev/Include/EGkGeoCollection.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -179,3 +181,6 @@ CalcAkimaMidDer( double dU0, const Point3d& ptP0, double dU1, const Point3d& ptP
|
||||
}
|
||||
return ( ! vtPrevDer.IsZero() && ! vtNextDer.IsZero()) ;
|
||||
}
|
||||
|
||||
bool ComputeAkimaTangents( bool bDetectCorner, const DBLVECTOR& vPar, const PNTVECTOR& vPnt, VCT3DVECTOR& vPrevDer, VCT3DVECTOR& vNextDer) ;
|
||||
bool ComputeBesselTangents( const DBLVECTOR& vPar, const PNTVECTOR& vPnt, VCT3DVECTOR& vPrevDer, VCT3DVECTOR& vNextDer) ;
|
||||
+243
-70
@@ -722,7 +722,7 @@ AssignFeedSpiral( ICurveComposite* pCrv, const ISurfFlatRegion* pSrfRemoved, boo
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
AssignFeedSpiralOpt( const int nOptType, const PocketParams& PockParams, ICurveComposite* pCrv )
|
||||
AssignFeedSpiralOpt( int nOptType, const PocketParams& PockParams, ICurveComposite* pCrv )
|
||||
{
|
||||
// controllo della curva corrente
|
||||
if ( pCrv == nullptr || ! pCrv->IsValid() || pCrv->GetCurveCount() == 0)
|
||||
@@ -732,24 +732,24 @@ AssignFeedSpiralOpt( const int nOptType, const PocketParams& PockParams, ICurveC
|
||||
if ( ! PockParams.bCalcFeed)
|
||||
return AssignMaxFeed( pCrv, PockParams) ;
|
||||
|
||||
switch ( PockParams.nType) {
|
||||
case POCKET_SPIRALIN :
|
||||
if ( nOptType == 0) { // Spirale dall'Esterno
|
||||
for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u) {
|
||||
if ( u == 0) // prima circonferenza
|
||||
pCrv->SetCurveTempParam( 0, GetMinFeed( PockParams), 0) ;
|
||||
else // semi cerchi in tangenza
|
||||
pCrv->SetCurveTempParam( u, GetMaxFeed( PockParams), 0) ;
|
||||
}
|
||||
if ( PockParams.nType == POCKET_SPIRALIN || PockParams.nType == POCKET_CONFORMAL_ZIGZAG ||
|
||||
PockParams.nType == POCKET_CONFORMAL_ONEWAY) {
|
||||
if ( nOptType == 0) { // Spirale dall'Esterno
|
||||
for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u) {
|
||||
if ( u == 0) // prima circonferenza
|
||||
pCrv->SetCurveTempParam( 0, GetMinFeed( PockParams), 0) ;
|
||||
else // semi cerchi in tangenza
|
||||
pCrv->SetCurveTempParam( u, GetMaxFeed( PockParams), 0) ;
|
||||
}
|
||||
else if ( nOptType == 1) { // Trapezoidi
|
||||
for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u)
|
||||
pCrv->SetCurveTempParam( u, GetMinFeed( PockParams), 0) ;
|
||||
}
|
||||
break ;
|
||||
}
|
||||
else if ( nOptType == 1) { // Trapezoidi
|
||||
for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u)
|
||||
pCrv->SetCurveTempParam( u, GetMinFeed( PockParams), 0) ;
|
||||
}
|
||||
}
|
||||
/* NB. Essendo la funzione CalcSpiral richiamata sia per lo SpiralIN che per lo SpiralOUT le curve sono sempre
|
||||
orientate nello stesso modo, solamente alla fine viene invertita la curva finale per la svuotatura... */
|
||||
case POCKET_SPIRALOUT :
|
||||
else {
|
||||
if ( nOptType == 0) { // Spiral verso l'esterno
|
||||
for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u) {
|
||||
if ( u > pCrv->GetCurveCount() - 3) // prime semi circonferenze
|
||||
@@ -762,9 +762,6 @@ AssignFeedSpiralOpt( const int nOptType, const PocketParams& PockParams, ICurveC
|
||||
for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u)
|
||||
pCrv->SetCurveTempParam( u, GetMinFeed( PockParams), 0) ;
|
||||
}
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
@@ -3444,18 +3441,18 @@ CalcTrapezoidSpiral( ICurveComposite* pCrvPocket, const Frame3d& frTrap, double
|
||||
Vector3d vtX ; pCrvPocket->GetCurve( 1)->GetStartDir( vtX) ;
|
||||
Frame3d frDim ; frDim.Set( ptOrig, Z_AX, vtX) ; frDim.Invert() ;
|
||||
BBox3d b3Dim ; pCrvPocket->GetBBox( frDim, b3Dim, BBF_EXACT) ;
|
||||
dMaxLarg = ( vnProp[0] != 0 ? b3Dim.GetDimY() : dPocketSize) ;
|
||||
dMaxLarg = ( vnProp[0] != TEMP_PROP_CLOSE_EDGE ? b3Dim.GetDimY() : dPocketSize) ;
|
||||
}
|
||||
|
||||
// calcolo percorso di svuotatura
|
||||
// se lati obliqui sono entrambi chiusi e dimensione svuotatura è maggiore di diametro fresa e minore del doppio gestione speciale
|
||||
if ( ( bRealTrap && dMaxLarg > PockParams.dRad * 2 + 10 * EPS_SMALL) &&
|
||||
if ( ( bRealTrap && dMaxLarg > dDiam + 10. * EPS_SMALL) &&
|
||||
( ( ( vnProp[0] != TEMP_PROP_CLOSE_EDGE && vnProp[2] != TEMP_PROP_CLOSE_EDGE) &&
|
||||
( vnProp[3] == TEMP_PROP_CLOSE_EDGE && vnProp[1] == TEMP_PROP_CLOSE_EDGE) &&
|
||||
( max( dLen0, dLen2) < 2 * dDiam + EPS_SMALL)) ||
|
||||
( max( dLen0, dLen2) < 2. * dDiam + EPS_SMALL)) ||
|
||||
( ( vnProp[1] != TEMP_PROP_CLOSE_EDGE && vnProp[3] != TEMP_PROP_CLOSE_EDGE) &&
|
||||
( vnProp[0] == TEMP_PROP_CLOSE_EDGE && vnProp[2] == TEMP_PROP_CLOSE_EDGE) &&
|
||||
( max( dLen1, dLen3) < 2 * dDiam + EPS_SMALL)))) {
|
||||
( max( dLen0, dLen2) < 2. * dDiam + EPS_SMALL)))) {
|
||||
if ( ! SpecialAdjustTrapezoidSpiralForAngles( pMCrv, ( vnProp[0] == TEMP_PROP_CLOSE_EDGE), pCrvPocket, PockParams, ptRef)) {
|
||||
pMCrv->Clear() ;
|
||||
return false ;
|
||||
@@ -3608,14 +3605,8 @@ CalcTrapezoidSpiral( ICurveComposite* pCrvPocket, const Frame3d& frTrap, double
|
||||
|
||||
if ( pMCrv->GetCurveCount() == 0)
|
||||
return true ;
|
||||
|
||||
pMCrv->ToGlob( frTrap) ;
|
||||
|
||||
if ( PockParams.bInvert) {
|
||||
pMCrv->Invert() ;
|
||||
// inverto le proprietà in modo che nProp3 sia sempre legata al punto iniziale e nProp1 a quello finale
|
||||
swap( vnProp[1], vnProp[3]) ;
|
||||
}
|
||||
// segno i lati aperti come temp prop della curva
|
||||
int nOpenEdges = vnProp[0] + vnProp[1] * 2 + vnProp[2] * 4 + vnProp[3] * 8 ;
|
||||
pMCrv->SetTempProp( nOpenEdges, 0) ;
|
||||
@@ -3625,6 +3616,193 @@ CalcTrapezoidSpiral( ICurveComposite* pCrvPocket, const Frame3d& frTrap, double
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
IsForcedStepTrapezoid( const ICurveComposite* pCrvTrap, const PocketParams& PockParam,
|
||||
int nBase, int nSecondBase, bool& bForced)
|
||||
{
|
||||
bForced = false ;
|
||||
// se la curva non è valida, allora non può essere forzato
|
||||
if ( pCrvTrap == nullptr || ! pCrvTrap->IsValid())
|
||||
return false ;
|
||||
|
||||
// scorro la curva e ricavo le TempProps
|
||||
array<int, 4> vnProps ;
|
||||
int nClose = 0 ;
|
||||
for ( int i = 0 ; i < 4 ; ++ i) {
|
||||
if ( ! pCrvTrap->GetCurveTempProp( i, vnProps[i], 0))
|
||||
return false ;
|
||||
if ( vnProps[i] == TEMP_PROP_CLOSE_EDGE)
|
||||
++ nClose ;
|
||||
}
|
||||
|
||||
double dDiam = 2. * PockParam.dRad ;
|
||||
switch ( nClose) {
|
||||
// se trapezio tutto aperto, allora non è forzato
|
||||
case 0 :
|
||||
bForced = false ;
|
||||
break ;
|
||||
// se ho un lato chiuso, non è forzato
|
||||
case 1 :
|
||||
bForced = false ;
|
||||
break ;
|
||||
// se ho due lati chiusi
|
||||
case 2 : {
|
||||
if ( nBase < 0 || nBase > 4 || nSecondBase < 0 || nSecondBase > 4)
|
||||
return false ;
|
||||
// se entrambe le basi sono chiuse, è forzato
|
||||
if ( vnProps[nBase] == TEMP_PROP_CLOSE_EDGE && vnProps[nSecondBase] == TEMP_PROP_CLOSE_EDGE)
|
||||
bForced = true ;
|
||||
// se entrambe le basi sono aperte
|
||||
else if ( vnProps[nBase] == TEMP_PROP_OPEN_EDGE && vnProps[nSecondBase] == TEMP_PROP_OPEN_EDGE) {
|
||||
const ICurve* pCrvOpenBase = pCrvTrap->GetCurve( nBase) ;
|
||||
const ICurve* pCrvOpenSecondBase = pCrvTrap->GetCurve( nSecondBase) ;
|
||||
if ( pCrvOpenBase == nullptr || ! pCrvOpenBase->IsValid() ||
|
||||
pCrvOpenSecondBase == nullptr || ! pCrvOpenSecondBase->IsValid())
|
||||
return false ;
|
||||
double dLenOpenBase ; pCrvOpenBase->GetLength( dLenOpenBase) ;
|
||||
double dLenSecondOpenBase ; pCrvOpenSecondBase->GetLength( dLenSecondOpenBase) ;
|
||||
bForced = ( dLenOpenBase < dDiam + 10. * EPS_SMALL &&
|
||||
dLenSecondOpenBase < dDiam + 10. * EPS_SMALL) ;
|
||||
}
|
||||
// se alternate, non forzo
|
||||
else
|
||||
bForced = false ;
|
||||
}
|
||||
break ;
|
||||
// se ho tre lati chiusi
|
||||
case 3 : {
|
||||
// diventa forzato se il lato aperto non è grande
|
||||
double dLenOpen = 0. ;
|
||||
for ( int i = 0 ; i < 4 ; ++ i) {
|
||||
if ( vnProps[i] == TEMP_PROP_OPEN_EDGE) {
|
||||
const ICurve* pCrvOpen = pCrvTrap->GetCurve( i) ;
|
||||
if ( pCrvOpen == nullptr || ! pCrvOpen->IsValid())
|
||||
return false ;
|
||||
pCrvOpen->GetLength( dLenOpen) ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
bForced = ( dLenOpen < dDiam + 10. * EPS_SMALL) ;
|
||||
}
|
||||
break ;
|
||||
// se tutto chiuso, è forzato
|
||||
case 4 :
|
||||
bForced = true ;
|
||||
break ;
|
||||
default :
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
AdjustTrapeziodLeadIn( ICurveComposite* pCrvRes, const PocketParams& PockParam,
|
||||
const ISurfFlatRegion* pSfrChunk)
|
||||
{
|
||||
// recupero la TempProp
|
||||
int nTmpProp = pCrvRes->GetTempProp( 0) ;
|
||||
// se esiste almeno un aperto
|
||||
if ( nTmpProp > 0) {
|
||||
// se solo lato3 aperto
|
||||
bool bCheckHead = ( nTmpProp != 8 && nTmpProp != 2) ;
|
||||
if ( nTmpProp == 2)
|
||||
pCrvRes->Invert() ; // entro dall'unico aperto
|
||||
if ( bCheckHead) {
|
||||
// recupero gli estremi della curva corrente e la inverto in base alla Testa
|
||||
Point3d ptS ; pCrvRes->GetStartPoint( ptS) ;
|
||||
Point3d ptE ; pCrvRes->GetEndPoint( ptE) ;
|
||||
Point3d ptSGlob = GetToGlob( ptS, PockParam.frLocXY) ;
|
||||
Point3d ptEGlob = GetToGlob( ptE, PockParam.frLocXY) ;
|
||||
if ( ( PockParam.bAboveHead && ptEGlob.z > ptSGlob.z) ||
|
||||
( ! PockParam.bAboveHead && ptEGlob.z < ptSGlob.z))
|
||||
pCrvRes->Invert() ;
|
||||
}
|
||||
}
|
||||
|
||||
// Assegno la Feed
|
||||
AssignFeedSpiralOpt( 1, PockParam, pCrvRes) ;
|
||||
// Se curva da invertire, inverto
|
||||
if ( PockParam.bInvert)
|
||||
pCrvRes->Invert() ;
|
||||
|
||||
// se esiste almeno un aperto, provo ad estendere il percorso
|
||||
if ( nTmpProp > 0) {
|
||||
// Calcolo eventuale entrata da fuori
|
||||
Vector3d vtRef ; pCrvRes->GetStartDir( vtRef) ;
|
||||
vtRef.Invert() ;
|
||||
bool bIsStartExtended = false ;
|
||||
if ( ! ExtendPath( pCrvRes, pSfrChunk, PockParam, vtRef, false, PockParam.dRad + PockParam.dOpenMinSafe, bIsStartExtended))
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
GetZigZagOptimizedCurves( const ISurfFlatRegion* pSfrChunk, const PocketParams& PockParam,
|
||||
ICurveComposite* pCrvRes)
|
||||
{
|
||||
// controllo dei parametri
|
||||
if ( pSfrChunk == nullptr || ! pSfrChunk->IsValid())
|
||||
return false ;
|
||||
pCrvRes->Clear() ;
|
||||
|
||||
// ricavo la curva di bordo del chunk corrente
|
||||
PtrOwner<ICurveComposite> pCrvBorder( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, 0))) ;
|
||||
if ( IsNull( pCrvBorder) || ! pCrvBorder->IsValid())
|
||||
return false ;
|
||||
pCrvBorder->MergeCurves( 10. * EPS_SMALL, 10. * EPS_ANG_SMALL, true, true) ;
|
||||
pCrvBorder->SetExtrusion( pSfrChunk->GetNormVersor()) ;
|
||||
|
||||
/* TRAPEZI
|
||||
- E' richiesto che una dimensione del box della curva sia compatibile con il primo Offset, il
|
||||
quale sarebbe una singola curva aperta
|
||||
*/
|
||||
PtrOwner<ICurveComposite> pCrvTrap( CreateCurveComposite()) ;
|
||||
if ( IsNull( pCrvTrap))
|
||||
return false ;
|
||||
Frame3d frTrap ;
|
||||
double dPocketSize ;
|
||||
int nBase, nSecondBase ;
|
||||
bool bOkTrap = GetTrapezoidFromShape( pCrvBorder, pCrvTrap, frTrap, PockParam, dPocketSize, nBase, nSecondBase) ;
|
||||
if ( bOkTrap && pCrvTrap->IsValid()) {
|
||||
// verifico se il trapezio ottenuto deve o meno rispettare il SideStep
|
||||
bool bForcedTrap = false ;
|
||||
IsForcedStepTrapezoid( pCrvTrap, PockParam, nBase, nSecondBase, bForcedTrap) ;
|
||||
if ( ! bForcedTrap)
|
||||
bOkTrap = ( dPocketSize < PockParam.dMaxOptSize + 10. * EPS_SMALL) ;
|
||||
}
|
||||
if ( bOkTrap && pCrvTrap->IsValid()) {
|
||||
pCrvTrap->SetExtrusion( Z_AX) ;
|
||||
CalcTrapezoidSpiral( pCrvTrap, frTrap, dPocketSize, nBase, nSecondBase, PockParam, pCrvRes, bOkTrap) ;
|
||||
if ( bOkTrap) {
|
||||
// verifico che tale curva non interferisca con la regione limite
|
||||
if ( PockParam.SfrLimit.IsValid()) {
|
||||
double dOffsCheck = PockParam.dRad + PockParam.dRadialOffset - 50. * EPS_SMALL ; // restrittivo per sicurezza
|
||||
PtrOwner<ISurfFlatRegion> pSfrToolShape( GetSurfFlatRegionFromFatCurve( pCrvRes->Clone(), dOffsCheck, false, false)) ;
|
||||
bOkTrap = ( ! IsNull( pSfrToolShape) && pSfrToolShape->IsValid()) ;
|
||||
if ( bOkTrap) {
|
||||
bOkTrap = ( pSfrToolShape->Intersect( PockParam.SfrLimit) &&
|
||||
! pSfrToolShape->IsValid()) ;
|
||||
if ( ! bOkTrap)
|
||||
pCrvRes->Clear() ;
|
||||
}
|
||||
}
|
||||
if ( bOkTrap) {
|
||||
AdjustTrapeziodLeadIn( pCrvRes, PockParam, pSfrChunk) ;
|
||||
// imposto il flag di curva singola
|
||||
pCrvRes->SetTempProp( TEMP_PROP_OPT_TRAPEZOID, 0) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
GetSpiralOptimizedCurves( const ISurfFlatRegion* pSfrChunk, const PocketParams& PockParam,
|
||||
@@ -3673,7 +3851,7 @@ GetSpiralOptimizedCurves( const ISurfFlatRegion* pSfrChunk, const PocketParams&
|
||||
ssize( ccClass) == 1 && ccClass[0].nClass == CRVC_OUT) ;
|
||||
// NB. una versione più complessa dovrebbe verificare se la sottrazione tra la
|
||||
// superficie dell'utensile e la regione limite non genera un'altra circonferenza...
|
||||
// In questo caso si la sottrazione potrebbe essere trattata come una circonferenza
|
||||
// In questo caso la sottrazione potrebbe essere trattata come una circonferenza
|
||||
// chiusa ed essere ancora svotata a spirale...
|
||||
}
|
||||
}
|
||||
@@ -3714,8 +3892,14 @@ GetSpiralOptimizedCurves( const ISurfFlatRegion* pSfrChunk, const PocketParams&
|
||||
Frame3d frTrap ;
|
||||
double dPocketSize ;
|
||||
int nBase, nSecondBase ;
|
||||
bool bOkTrap = ( GetTrapezoidFromShape( pCrvBorder, pCrvTrap, frTrap, PockParam, dPocketSize, nBase, nSecondBase) &&
|
||||
dPocketSize < PockParam.dMaxOptSize + 10. * EPS_SMALL) ;
|
||||
bool bOkTrap = GetTrapezoidFromShape( pCrvBorder, pCrvTrap, frTrap, PockParam, dPocketSize, nBase, nSecondBase) ;
|
||||
if ( bOkTrap && pCrvTrap->IsValid()) {
|
||||
// verifico se il trapezio ottenuto deve o meno rispettare il SideStep
|
||||
bool bForcedTrap = false ;
|
||||
IsForcedStepTrapezoid( pCrvTrap, PockParam, nBase, nSecondBase, bForcedTrap) ;
|
||||
if ( ! bForcedTrap)
|
||||
bOkTrap = ( dPocketSize < PockParam.dMaxOptSize + 10. * EPS_SMALL) ;
|
||||
}
|
||||
if ( bOkTrap && pCrvTrap->IsValid()) {
|
||||
pCrvTrap->SetExtrusion( Z_AX) ;
|
||||
CalcTrapezoidSpiral( pCrvTrap, frTrap, dPocketSize, nBase, nSecondBase, PockParam, pCrvRes, bOkTrap) ;
|
||||
@@ -3733,29 +3917,9 @@ GetSpiralOptimizedCurves( const ISurfFlatRegion* pSfrChunk, const PocketParams&
|
||||
}
|
||||
}
|
||||
if ( bOkTrap) {
|
||||
// calcolo eventuali uscite e ingressi
|
||||
if ( pCrvRes->GetTempProp( 0) > 0) {
|
||||
// Recupero gli estremi della curva corrente e la inverto in base alla Testa
|
||||
Point3d ptS ; pCrvRes->GetStartPoint( ptS) ;
|
||||
Point3d ptE ; pCrvRes->GetEndPoint( ptE) ;
|
||||
Point3d ptSGlob = GetToGlob( ptS, PockParam.frLocXY) ;
|
||||
Point3d ptEGlob = GetToGlob( ptE, PockParam.frLocXY) ;
|
||||
if ( ( PockParam.bAboveHead && ptEGlob.z > ptSGlob.z) ||
|
||||
( ! PockParam.bAboveHead && ptEGlob.z < ptSGlob.z))
|
||||
pCrvRes->Invert() ;
|
||||
if ( PockParam.bInvert)
|
||||
pCrvRes->Invert() ;
|
||||
// Calcolo eventuale entrata da fuori
|
||||
Vector3d vtRef ; pCrvRes->GetStartDir( vtRef) ;
|
||||
vtRef.Invert() ;
|
||||
bool bIsStartExtended = false ;
|
||||
if ( ! ExtendPath( pCrvRes, pSfrChunk, PockParam, vtRef, false, PockParam.dRad + PockParam.dOpenMinSafe, bIsStartExtended))
|
||||
return false ;
|
||||
}
|
||||
else {
|
||||
if ( PockParam.bInvert)
|
||||
pCrvRes->Invert() ;
|
||||
}
|
||||
AdjustTrapeziodLeadIn( pCrvRes, PockParam, pSfrChunk) ;
|
||||
// imposto il flag di curva singola
|
||||
pCrvRes->SetTempProp( TEMP_PROP_OPT_TRAPEZOID, 0) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3798,23 +3962,31 @@ GetPocketingOptimizedCurves( ISurfFlatRegion* pSfr, const PocketParams& PockPara
|
||||
PockParam.nType == POCKET_CONFORMAL_ZIGZAG || PockParam.nType == POCKET_CONFORMAL_ONEWAY) {
|
||||
// curva da resituire
|
||||
PtrOwner<ICurveComposite> pCrvOptSpiral( CreateCurveComposite()) ;
|
||||
if ( IsNull( pCrvOptSpiral) ||
|
||||
! GetSpiralOptimizedCurves( pSfrChunk, PockParam, pCrvOptSpiral))
|
||||
if ( IsNull( pCrvOptSpiral) ||
|
||||
! GetSpiralOptimizedCurves( pSfrChunk, PockParam, pCrvOptSpiral))
|
||||
return false ;
|
||||
// se ho ricavato una curva ottimizzata
|
||||
if ( ! IsNull( pCrvOptSpiral) && pCrvOptSpiral->IsValid() && pCrvOptSpiral->GetCurveCount() > 0) {
|
||||
vCrvOptCurves.emplace_back( Release( pCrvOptSpiral)) ;
|
||||
vCrvOptCurves.emplace_back( Release( pCrvOptSpiral)) ;
|
||||
pSfr->EraseChunk( nCurrChunk) ;
|
||||
}
|
||||
else
|
||||
++ nCurrChunk ;
|
||||
}
|
||||
else if ( PockParam.nType == POCKET_ZIGZAG || PockParam.nType == POCKET_ONEWAY) {
|
||||
// curva da restituire
|
||||
PtrOwner<ICurveComposite> pCrvOptZigZag( CreateCurveComposite()) ;
|
||||
if ( IsNull( pCrvOptZigZag) ||
|
||||
! GetZigZagOptimizedCurves( pSfrChunk, PockParam, pCrvOptZigZag))
|
||||
return false ;
|
||||
// se ho ricavato una curva ottimizzata
|
||||
if ( ! IsNull( pCrvOptZigZag) && pCrvOptZigZag->IsValid() && pCrvOptZigZag->GetCurveCount() > 0) {
|
||||
vCrvOptCurves.emplace_back( Release( pCrvOptZigZag)) ;
|
||||
pSfr->EraseChunk( nCurrChunk) ;
|
||||
}
|
||||
else
|
||||
++ nCurrChunk ;
|
||||
}
|
||||
// else if ( PockParam.nType == POCKET_ZIGZAG)
|
||||
// ;
|
||||
// else if ( PockParam.nType == POCKET_ONEWAY)
|
||||
// ;
|
||||
// else if ( PockParam.nType == POCKET_CONFORMAL_ONEWAY || PockParam.nType == POCKET_CONFORMAL_ZIGZAG)
|
||||
// ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
@@ -8916,14 +9088,14 @@ CalcSpiralPocketing( const ISurfFlatRegion* pSfr, int nType, const PocketParams&
|
||||
// il tipo può essere solo SpiralIn o SpiralOut
|
||||
if ( nType != POCKET_SPIRALIN && nType != POCKET_SPIRALOUT)
|
||||
return false ;
|
||||
PtrOwner<ISurfFlatRegion> pSfrLimit( PockParams.SfrLimit.IsValid() ? PockParams.SfrLimit.Clone() : CreateSurfFlatRegion()) ;
|
||||
// calcolo il percorso di svuotatura spiral
|
||||
return ( CalcPocketing( pSfr, PockParams.dRad, PockParams.dRadialOffset, PockParams.dSideStep,
|
||||
PockParams.dAngle, PockParams.dOpenMinSafe, nType, PockParams.bSmooth,
|
||||
PockParams.bCalcUnclearedRegs, PockParams.bInvert, PockParams.bAvoidOpt,
|
||||
PockParams.bAllowZigZagOneWayBorders, PockParams.bCalcFeed, PockParams.ptStart,
|
||||
PockParams.SfrLimit.IsValid() ? PockParams.SfrLimit.Clone() : CreateSurfFlatRegion(),
|
||||
PockParams.bAvoidOpt, PockParams.dMaxOptSize, PockParams.dLiTang, PockParams.nLiType,
|
||||
vCrvCompoRes)) ;
|
||||
pSfrLimit, PockParams.bAvoidOpt, PockParams.dMaxOptSize, PockParams.dLiTang,
|
||||
PockParams.nLiType, vCrvCompoRes)) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -9218,9 +9390,10 @@ SmoothExtensionLinesByIntersection( ICRVCOMPOPOVECTOR& vCrvPaths, const PocketPa
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CalcPocketing( const ISurfFlatRegion* pSfr, double dRad, double dRadOffs, double dStep, double dAngle,
|
||||
double dOpenMinSafe, int nType, bool bSmooth, bool bCalcUnclReg, bool bInvert, bool bAvoidOpt, bool bAllowZigZagOneWayBorders,
|
||||
bool bCalcFeed, const Point3d& ptEndPrec, const ISurfFlatRegion* pSfrLimit, bool bAllOffs,
|
||||
double dMaxOptSize, double dLiTang, int nLiType, ICRVCOMPOPOVECTOR& vCrvCompoRes)
|
||||
double dOpenMinSafe, int nType, bool bSmooth, bool bCalcUnclReg, bool bInvert, bool bAvoidOpt,
|
||||
bool bAllowZigZagOneWayBorders, bool bCalcFeed, const Point3d& ptEndPrec,
|
||||
const ISurfFlatRegion* pSfrLimit, bool bAllOffs, double dMaxOptSize, double dLiTang,
|
||||
int nLiType, ICRVCOMPOPOVECTOR& vCrvCompoRes)
|
||||
{
|
||||
// controllo dei parametri
|
||||
if ( pSfr == nullptr || ! pSfr->IsValid() ||
|
||||
|
||||
+366
-59
@@ -13,6 +13,8 @@
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "CalcDerivate.h"
|
||||
#include "Bernstein.h"
|
||||
#include "CurveAux.h"
|
||||
#include "GeoConst.h"
|
||||
#include "CurveLine.h"
|
||||
@@ -23,6 +25,7 @@
|
||||
#include "IntersLineLine.h"
|
||||
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
||||
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EGkUiUnits.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include "/EgtDev/Include/EGkCurveByInterp.h"
|
||||
@@ -30,6 +33,14 @@
|
||||
#define EIGEN_NO_IO
|
||||
#include "/EgtDev/Extern/Eigen/Dense"
|
||||
|
||||
#define SAVEAPPROX 0
|
||||
#define SAVECURVEPASSED 0
|
||||
#define SAVELINEARAPPROX 0
|
||||
#if SAVEAPPROX || SAVECURVEPASSED || SAVELINEARAPPROX
|
||||
static int nCrvPassed = 0 ;
|
||||
#include "/EgtDev/Include/EGkGeoObjSave.h"
|
||||
#endif
|
||||
|
||||
using namespace std ;
|
||||
|
||||
static bool FindSpan( double dU, int nDeg, const DBLVECTOR& vKnots, int& nSpan) ;
|
||||
@@ -523,9 +534,9 @@ LineToBezierCurve( const ICurveLine* pCrvLine, int nDeg, bool bMakeRatOrNot)
|
||||
return nullptr ;
|
||||
|
||||
PtrOwner<ICurveBezier> pCrvBezier( CreateCurveBezier()) ;
|
||||
// rendo tutte le curve di grado 2 e razionali così posso convertire anche archi e avere tutte curve dello stesso grado e razionali
|
||||
pCrvBezier->Init( nDeg, true) ;
|
||||
pCrvBezier->FromLine( *pCrvLine) ;
|
||||
pCrvBezier->Init( nDeg, false) ;
|
||||
if ( ! pCrvBezier->FromLine( *pCrvLine))
|
||||
return nullptr ;
|
||||
if ( bMakeRatOrNot)
|
||||
pCrvBezier->MakeRational() ;
|
||||
return Release( pCrvBezier) ;
|
||||
@@ -578,6 +589,13 @@ ArcToBezierCurve( const ICurveArc* pArc, int nDeg, bool bMakeRatOrNot)
|
||||
PtrOwner<ICurveBezier> pCrvBez( CreateBasicCurveBezier()) ;
|
||||
if ( IsNull( pCrvBez) || ! pCrvBez->FromArc( cArc))
|
||||
return nullptr ;
|
||||
if ( ! bMakeRatOrNot) {
|
||||
Point3d ptCen = pArc->GetCenter() ;
|
||||
Vector3d vtN = pArc->GetNormVersor() ;
|
||||
pCrvBez.Set( ApproxArcCurveBezierWithSingleCubic( pCrvBez, ptCen, vtN)) ;
|
||||
}
|
||||
if ( IsNull( pCrvBez))
|
||||
return nullptr ;
|
||||
// aumento il grado della curva come richiesto
|
||||
while ( pCrvBez->GetDegree() < nDeg)
|
||||
pCrvBez.Set( BezierIncreaseDegree( pCrvBez)) ;
|
||||
@@ -1136,7 +1154,7 @@ FindSpan( double dU, int nDeg, const DBLVECTOR& vKnots, int& nSpan)
|
||||
return true ;
|
||||
}
|
||||
// trovo a quale span appartiene il parametro dU
|
||||
int nKnots = int( vKnots.size()) ;
|
||||
int nKnots = ssize( vKnots) ;
|
||||
if ( abs( dU - vKnots[nKnots-1]) < EPS_SMALL) {
|
||||
nSpan = nKnots - 1 - nDeg ;
|
||||
return true ;
|
||||
@@ -1162,7 +1180,7 @@ static bool
|
||||
CalcBasisFunc( double dU, int nSpan, int nDeg, const DBLVECTOR& vKnots, DBLVECTOR& vBasis)
|
||||
{
|
||||
// mi aspetto che il vettore vBasis sia di lunghezza nDeg + 1
|
||||
if ( vBasis.size() != nDeg + 1)
|
||||
if ( ssize( vBasis) != nDeg + 1)
|
||||
return false ;
|
||||
|
||||
vBasis[0] = 1 ;
|
||||
@@ -1187,7 +1205,8 @@ CalcBasisFunc( double dU, int nSpan, int nDeg, const DBLVECTOR& vKnots, DBLVECTO
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICurve*
|
||||
InterpolatePointSetWithBezierNoIntermedLines( const PNTVECTOR& vPnt, int nStart, int nEnd, int nDeg, const DBLVECTOR& vLen, double dLenTot)
|
||||
InterpolatePointSetWithBezierNoIntermedLines( const PNTVECTOR& vPnt, int nStart, int nEnd, int nDeg, const DBLVECTOR& vLen, double dLenTot,
|
||||
const Vector3d& vtStartDir = V_NULL, const Vector3d& vtEndDir = V_NULL)
|
||||
{
|
||||
PtrOwner<ICurve> pCrvInt ;
|
||||
|
||||
@@ -1216,6 +1235,8 @@ InterpolatePointSetWithBezierNoIntermedLines( const PNTVECTOR& vPnt, int nStart,
|
||||
return nullptr ;
|
||||
}
|
||||
|
||||
bool bUseStartEndDir = vtStartDir.IsValid() && vtEndDir.IsValid() ;
|
||||
|
||||
DBLVECTOR vPntParam ;
|
||||
vPntParam.resize( nPoints) ;
|
||||
vPntParam[0] = 0 ;
|
||||
@@ -1224,13 +1245,15 @@ InterpolatePointSetWithBezierNoIntermedLines( const PNTVECTOR& vPnt, int nStart,
|
||||
vPntParam[i] = vPntParam[i-1] + vLen[i-1] / dLenTot ;
|
||||
|
||||
DBLVECTOR vKnots ;
|
||||
vKnots.resize( nPoints + nDeg - 1) ;
|
||||
int nKnots = bUseStartEndDir ? nPoints + nDeg - 1 + 2 : nPoints + nDeg - 1 ;
|
||||
vKnots.resize( nKnots) ;
|
||||
for ( int i = 0 ; i < nDeg ; ++i) {
|
||||
vKnots[i] = 0 ;
|
||||
vKnots.end()[-i-1] = 1 ;
|
||||
}
|
||||
|
||||
for ( int i = nDeg ; i < nPoints - 1 ; ++i) {
|
||||
int nKnotsToEdit = bUseStartEndDir ? nPoints + 1 : nPoints - 1 ;
|
||||
for ( int i = nDeg ; i < nKnotsToEdit ; ++i) {
|
||||
double dKnot = 0 ;
|
||||
for ( int j = i + 1 ; j < i + nDeg + 1 ; ++j)
|
||||
dKnot += vPntParam[j - nDeg] ;
|
||||
@@ -1238,13 +1261,14 @@ InterpolatePointSetWithBezierNoIntermedLines( const PNTVECTOR& vPnt, int nStart,
|
||||
vKnots[i] = dKnot ;
|
||||
}
|
||||
|
||||
Eigen::MatrixXd mA( nPoints, nPoints) ;
|
||||
int nEq = bUseStartEndDir ? nPoints + 2 : nPoints ;
|
||||
Eigen::MatrixXd mA( nEq, nEq) ;
|
||||
mA.fill( 0) ;
|
||||
for ( int i = 0 ; i < nPoints ; ++i) {
|
||||
for ( int i = 0 ; i < nEq ; ++i) {
|
||||
if ( i == 0)
|
||||
mA.row(0).col(0) << 1 ;
|
||||
else if ( i == nPoints - 1)
|
||||
mA.row(i).col(nPoints - 1) << 1 ;
|
||||
else if ( i == nEq - 1)
|
||||
mA.row(i).col( nEq - 1) << 1 ;
|
||||
else {
|
||||
int nSpan = 0 ; FindSpan( vPntParam[i], nDeg, vKnots, nSpan) ;
|
||||
DBLVECTOR vBasis ; vBasis.resize( nDeg + 1) ;
|
||||
@@ -1295,7 +1319,7 @@ InterpolatePointSetWithBezier( const PNTVECTOR& vPnt, double dLinTol, double dMa
|
||||
int nItCount = 0 ;
|
||||
while ( dErr > dLinTol && nItCount < 10) {
|
||||
pCrvInt->Clear() ;
|
||||
int nPoints = int( vPnt.size()) ;
|
||||
int nPoints = ssize( vPnt) ;
|
||||
int nDeg = 3 ;
|
||||
if ( nPoints < 2)
|
||||
return nullptr ;
|
||||
@@ -1311,7 +1335,7 @@ InterpolatePointSetWithBezier( const PNTVECTOR& vPnt, double dLinTol, double dMa
|
||||
else if ( nPoints == 3) {
|
||||
// se ho solo tre punti uso un altro algoritmo
|
||||
CurveByInterp cbi ;
|
||||
for ( int i = 0 ; i < int( vPnt.size()) ; ++i)
|
||||
for ( int i = 0 ; i < ssize( vPnt) ; ++i)
|
||||
cbi.AddPoint( vPnt[i]) ;
|
||||
pCrvInt->AddCurve( cbi.GetCurve( CurveByInterp::AKIMA_CORNER, CurveByInterp::CUBIC_BEZIERS)) ;
|
||||
if ( ! IsNull( pCrvInt) && pCrvInt->IsValid())
|
||||
@@ -1343,10 +1367,16 @@ InterpolatePointSetWithBezier( const PNTVECTOR& vPnt, double dLinTol, double dMa
|
||||
}
|
||||
}
|
||||
|
||||
if ( vLen.size() != 0) {
|
||||
if ( ! vLen.empty()) {
|
||||
if ( nEnd == 0)
|
||||
nEnd = nPoints - 1 ;
|
||||
pCrvInt->AddCurve( InterpolatePointSetWithBezierNoIntermedLines( vPnt, nStart, nEnd, nDeg, vLen, dLenTot)) ;
|
||||
Vector3d vtStartDir = V_INVALID ;
|
||||
Vector3d vtEndDir = V_INVALID ;
|
||||
//if ( nStart != 0 && nEnd != nPoints - 1) {
|
||||
// pCrvInt->GetEndDir( vtStartDir) ;
|
||||
// vtEndDir =
|
||||
//}
|
||||
pCrvInt->AddCurve( InterpolatePointSetWithBezierNoIntermedLines( vPnt, nStart, nEnd, nDeg, vLen, dLenTot, vtStartDir, vtEndDir)) ;
|
||||
}
|
||||
|
||||
if ( bFoundLine) {
|
||||
@@ -1358,6 +1388,7 @@ InterpolatePointSetWithBezier( const PNTVECTOR& vPnt, double dLinTol, double dMa
|
||||
nStart = nEnd ;
|
||||
}
|
||||
|
||||
//dErr = 0 ;
|
||||
CalcApproxError( pCrvOri, pCrvInt, dErr) ;
|
||||
if ( dErr > dLinTol && dMaxLen > 200 * EPS_SMALL)
|
||||
dMaxLen /= 2 ;
|
||||
@@ -1372,42 +1403,318 @@ InterpolatePointSetWithBezier( const PNTVECTOR& vPnt, double dLinTol, double dMa
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICurve*
|
||||
ApproxCurveWithBezier( const ICurve* pCrv , double dTol, int nType)
|
||||
static bool
|
||||
ParamByLen( const PNTVECTOR& vPnt, DBLVECTOR& vParam, int nFirst, int nLast)
|
||||
{
|
||||
PolyLine plApprox ;
|
||||
double dAngTolFine = 2 ;
|
||||
pCrv->ApproxWithLines( dTol, dAngTolFine, ICurve::APL_STD, plApprox) ;
|
||||
int nPoints = nLast - nFirst + 1 ;
|
||||
if ( nPoints < 2)
|
||||
return false ;
|
||||
if ( vParam.empty())
|
||||
vParam.resize( nPoints) ;
|
||||
if ( vParam[nFirst] == 0 && vParam[nLast] == 1)
|
||||
return true ;
|
||||
vParam[nFirst] = 0 ;
|
||||
for ( int i = nFirst + 1 ; i <= nLast ; ++i) {
|
||||
double dDist = Dist( vPnt[i], vPnt[i-1]) ;
|
||||
vParam[i] = vParam[i- 1] + dDist ;
|
||||
}
|
||||
for ( int i = nFirst + 1 ; i < nLast ; ++i)
|
||||
vParam[i] /= vParam[nLast] ;
|
||||
vParam[nLast] = 1 ;
|
||||
|
||||
PNTVECTOR vPnt ;
|
||||
Point3d pt ; plApprox.GetFirstPoint( pt) ;
|
||||
do {
|
||||
vPnt.push_back( pt) ;
|
||||
} while ( plApprox.GetNextPoint( pt)) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
// campiono punti lungo la curva e poi li interpolo
|
||||
//----------------------------------------------------------------------------
|
||||
ICurveBezier*
|
||||
ApproxPointSetWithSingleBezier( const PNTVECTOR& vPnt, int nFirst, int nLast,
|
||||
const Vector3d& vtStartDir, const Vector3d& vtEndDir, const DBLVECTOR& vParam)
|
||||
{
|
||||
// cerco di approssimare un set di punti con una sola bezier cubica non razionale
|
||||
int nPoints = nLast - nFirst + 1 ;
|
||||
// se ho solo quattro punti allora costruisco direttamente la curva
|
||||
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
||||
int nDeg = 3 ;
|
||||
bool bRat = false ;
|
||||
pCrvBez->Init( nDeg, bRat) ;
|
||||
const Point3d& pt0 = vPnt[nFirst] ;
|
||||
const Point3d& pt3 = vPnt[nLast] ;
|
||||
pCrvBez->SetControlPoint( 0, pt0) ;
|
||||
pCrvBez->SetControlPoint( 3, pt3) ;
|
||||
Eigen::Vector2d mA ;
|
||||
if ( nPoints > 4) {
|
||||
// risoluzione sistema
|
||||
Eigen::Matrix2d mC ; mC.setZero() ;
|
||||
Eigen::Vector2d mX ; mX.setZero() ;
|
||||
for ( int i = nFirst ; i <= nLast ; ++i) {
|
||||
double dU = vParam[i] ;
|
||||
DBLVECTOR vBern(4) ;
|
||||
GetAllBernstein( dU, 3, vBern) ;
|
||||
|
||||
PtrOwner<ICurve> pCC( InterpolatePointSetWithBezier( vPnt, dTol, 100)) ;
|
||||
if ( ! IsNull( pCC) && pCC->IsValid())
|
||||
return Release( pCC) ;
|
||||
else
|
||||
return nullptr ;
|
||||
Vector3d A1 = vtStartDir * vBern[1] ;
|
||||
Vector3d A2 = vtEndDir * vBern[2] ;
|
||||
|
||||
Vector3d tmp = vPnt[i] - ( pt0 * ( vBern[0] + vBern[1])) - (( pt3 * ( vBern[2] + vBern[3])) - ORIG) ; // ORIG serve solo per trasformare l'ultimo termine in un vettore
|
||||
|
||||
mC(0,0) += A1 * A1 ;
|
||||
mC(0,1) += A1 * A2 ;
|
||||
mC(1,0) += A1 * A2 ;
|
||||
mC(1,1) += A2 * A2 ;
|
||||
|
||||
mX(0) += A1 * tmp ;
|
||||
mX(1) += A2 * tmp ;
|
||||
}
|
||||
mA = mC.fullPivLu().solve(mX) ;
|
||||
}
|
||||
// l'algoritmo è fatto in modo che alpha1 e alpha2 siano positivi ( se tutto va bene)
|
||||
// io invece ho tenuto le tangenti con la direzione originale, quindi il primo dovrebbe essere positivo e il secondo negativo
|
||||
if ( mA(0) < 0 || mA(1) > 0 || nPoints < 4) {
|
||||
if ( mA(0) < 0 || mA(1) > 0)
|
||||
LOG_DBG_ERR( GetEGkLogger(), "valori di alfa sballati, potrebbe essere la spaziatura dismogenea tra punti")
|
||||
double dDistCorr = Dist( pt3, pt0) / 3 ;
|
||||
mA(0) = dDistCorr ;
|
||||
mA(1) = - dDistCorr ;
|
||||
}
|
||||
|
||||
Point3d pt1 = pt0 + vtStartDir * mA(0) ;
|
||||
Point3d pt2 = pt3 + vtEndDir * mA(1) ;
|
||||
pCrvBez->SetControlPoint( 1, pt1) ;
|
||||
pCrvBez->SetControlPoint( 2, pt2) ;
|
||||
return Release( pCrvBez) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CalcPointSetApproxError( const PNTVECTOR& vPntOrig, const DBLVECTOR& vParam,
|
||||
int nFirst, int nLast, const ICurve* pCrvNew, double& dErr, int& nPointMaxErr)
|
||||
{
|
||||
dErr = 0 ;
|
||||
// calcolo l'errore di approssimazione
|
||||
for ( int i = nFirst ; i <= nLast ; ++i) {
|
||||
Point3d ptBez ; pCrvNew->GetPointD1D2( vParam[i], ICurve::Side::FROM_MINUS, ptBez) ;
|
||||
double dErrTemp = Dist( vPntOrig[i], ptBez) ;
|
||||
if ( dErrTemp > dErr) {
|
||||
dErr = dErrTemp ;
|
||||
nPointMaxErr = i ;
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICurve*
|
||||
ApproxPointSetWithBezier( const ICurve* pCrv, double dTol)
|
||||
FitWithBezier( const ICurve* pCrvOrig, const PNTVECTOR& vPnt, DBLVECTOR& vParam,
|
||||
int nFirst, int nLast, const VCT3DVECTOR& vPrevDer, const VCT3DVECTOR& vNextDer, double dTol, bool bLimitSplit = false)
|
||||
{
|
||||
// campiono punti lungo la curva e poi li interpolo
|
||||
ParamByLen( vPnt, vParam, nFirst, nLast) ;
|
||||
PtrOwner<ICurveComposite> pCrvFit( CreateCurveComposite()) ;
|
||||
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
||||
double dErr = INFINITO ;
|
||||
double dErrPrec = INFINITO ;
|
||||
double dErrSplit = dTol * 25 ;
|
||||
int nIter = 0 ;
|
||||
while ( dErr > dTol && nIter < 10) {
|
||||
if ( dErr < INFINITO) {
|
||||
// riparametrizzo i punti
|
||||
for ( int i = nFirst + 1 ; i < nLast ; ++i) {
|
||||
// questo potrebbe diventare un while appena capisco di quanto si aggiusta il parametro ad ogni iterazione
|
||||
double dCorr = 1 ;
|
||||
do {
|
||||
Vector3d vtDer1, vtDer2 ;
|
||||
Point3d ptBez ; pCrvBez->GetPointD1D2( vParam[i], ICurve::Side::FROM_MINUS, ptBez, &vtDer1, &vtDer2) ;
|
||||
Vector3d vtLink = ptBez - vPnt[i] ;
|
||||
double dNum = vtLink * vtDer1 ;
|
||||
double dDen = vtLink * vtDer2 + vtDer1 * vtDer1 ;
|
||||
dCorr = dDen > EPS_ZERO ? dNum / dDen : 0 ;
|
||||
vParam[i] = vParam[i] - dCorr ;
|
||||
} while ( abs( dCorr) > EPS_ZERO) ;
|
||||
Clamp( vParam[i], 0., 1.) ;
|
||||
}
|
||||
}
|
||||
|
||||
PtrOwner<ICurveComposite> pCC( CreateBasicCurveComposite()) ;
|
||||
return Release( pCC) ;
|
||||
// fit della curva
|
||||
Vector3d vtStartDir, vtEndDir ;
|
||||
if ( bLimitSplit) {
|
||||
vtStartDir = vNextDer[nFirst / 3] ;
|
||||
vtEndDir = vPrevDer[nLast / 3] ;
|
||||
}
|
||||
else {
|
||||
vtStartDir = vNextDer[nFirst] ;
|
||||
vtEndDir = vPrevDer[nLast] ;
|
||||
}
|
||||
pCrvBez.Set( ApproxPointSetWithSingleBezier( vPnt, nFirst, nLast, vtStartDir, vtEndDir, vParam)) ;
|
||||
if ( IsNull( pCrvBez) || ! pCrvBez->IsValid())
|
||||
return nullptr ;
|
||||
#if SAVEAPPROX
|
||||
SaveGeoObj( pCrvBez->Clone(), "D:\\Temp\\bezier\\approxWithBezier\\"+ToString(nCrvPassed) + "first_approx.nge") ;
|
||||
#endif
|
||||
|
||||
int nPointMaxErr = 0 ;
|
||||
CalcPointSetApproxError( vPnt, vParam, nFirst, nLast, pCrvBez, dErr, nPointMaxErr) ;
|
||||
// se sto unendo due punti consecutivi e l'errore è oltre quello richiesto allora restituisco un segmento che unisce i punti
|
||||
if ( ((nLast - nFirst == 1) || ( bLimitSplit && nLast - nFirst == 3)) && dErr > dTol) {
|
||||
CurveLine CL ; CL.Set( vPnt[nFirst], vPnt[nLast]) ;
|
||||
pCrvBez.Set( GetCurveBezier( CurveToBezierCurve( &CL))) ;
|
||||
dErr = 0 ;
|
||||
}
|
||||
|
||||
if ( bLimitSplit && nPointMaxErr % 3 != 0) {
|
||||
nPointMaxErr = 3 * int( round( nPointMaxErr / 3.)) ;
|
||||
if ( nPointMaxErr == nFirst)
|
||||
nPointMaxErr += 3 ;
|
||||
else if( nPointMaxErr == nLast)
|
||||
nPointMaxErr -= 3 ;
|
||||
}
|
||||
|
||||
++nIter ;
|
||||
bool bSplit = false ;
|
||||
if ( ( nIter == 10 && dErr > dTol) || dErr > dErrPrec || dErrPrec - dErr < dErrPrec / 20)
|
||||
bSplit = true ;
|
||||
dErrPrec = dErr ;
|
||||
// se la curva di approssimazione è ancora molto lontana dalla curva originale allora divido il set di punti in due
|
||||
if ( dErr > dErrSplit || bSplit) {
|
||||
if ( nLast - nFirst > 1 && nPointMaxErr - nFirst > 1 && nLast - nPointMaxErr > 1) {
|
||||
if ( ! pCrvFit->AddCurve( FitWithBezier( pCrvOrig, vPnt, vParam, nFirst, nPointMaxErr, vPrevDer, vNextDer,dTol, bLimitSplit)) ||
|
||||
! pCrvFit->AddCurve( FitWithBezier( pCrvOrig, vPnt, vParam, nPointMaxErr, nLast, vPrevDer, vNextDer, dTol, bLimitSplit)))
|
||||
return nullptr ;
|
||||
break ;
|
||||
}
|
||||
else
|
||||
return nullptr ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pCrvFit->GetCurveCount() > 0)
|
||||
return Release( pCrvFit) ;
|
||||
else if ( dErr < dTol && ! IsNull( pCrvBez) && pCrvBez->IsValid())
|
||||
return Release( pCrvBez) ;
|
||||
else
|
||||
return nullptr ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICurve*
|
||||
ApproxCurveWithBezier( const ICurve* pCrv , double dTol)
|
||||
{
|
||||
|
||||
#if SAVECURVEPASSED
|
||||
SaveGeoObj( pCrv->Clone(), "D:\\Temp\\bezier\\approxWithBezier\\CurveDaApprossimare\\"+ToString(nCrvPassed) + ".nge") ;
|
||||
++nCrvPassed ;
|
||||
#endif
|
||||
|
||||
//// uso l'algoritmo di Schneider in Grafic Gems I
|
||||
// mi aspetto che non ci siano angoli ( discontinuità della derivata prima) nel risultato desiderato
|
||||
PolyLine plApprox ;
|
||||
double dAngTolFine = 1 ;
|
||||
double dLinTolFine = 0.05 ;
|
||||
pCrv->ApproxWithLines( dLinTolFine, dAngTolFine, ICurve::APL_STD, plApprox) ;
|
||||
|
||||
#if SAVELINEARAPPROX
|
||||
CurveComposite CC ; CC.FromPolyLine(plApprox) ;
|
||||
SaveGeoObj( CC.Clone(), "D:\\Temp\\bezier\\approxWithBezier\\approssimazione_lineare.nge") ;
|
||||
#endif
|
||||
|
||||
PNTVECTOR vPnt ;
|
||||
PNTVECTOR vPntOverSampling ;
|
||||
Point3d pt ; plApprox.GetFirstPoint( pt) ;
|
||||
do {
|
||||
if ( ! vPntOverSampling.empty()) {
|
||||
vPntOverSampling.push_back( Media( vPnt.back(), pt,1./3.)) ;
|
||||
vPntOverSampling.push_back( Media( vPnt.back(), pt,2./3.)) ;
|
||||
}
|
||||
vPntOverSampling.push_back( pt) ;
|
||||
vPnt.push_back( pt) ;
|
||||
} while ( plApprox.GetNextPoint( pt)) ;
|
||||
|
||||
// calcolo la curvatura nei vari punti per identificare zone a curvatura costante
|
||||
DBLVECTOR vRad ( ssize( vPnt)) ;
|
||||
for ( int i = 1 ; i < ssize( vPnt) - 1 ; ++i) {
|
||||
Vector3d vtA = vPnt[i] - vPnt[i-1] ;
|
||||
Vector3d vtB = vPnt[i+1] - vPnt[i-1] ;
|
||||
double dR = ( vtA.Len() * vtB.Len() * ( vtA - vtB).Len()) / ( 2 * ( vtA ^ vtB).Len()) ;
|
||||
vRad[i] = dR ;
|
||||
}
|
||||
vRad[0] = vRad[1] ;
|
||||
vRad.back() = vRad.end()[-2] ;
|
||||
// identifico le zone a curvatura costante // primo e ultimo punto degli intervalli non devono avere curvatura uguale agli altri perché sono di frontiera
|
||||
INTINTVECTOR vConstCurv ;
|
||||
double dRadPrec = vRad[0] ;
|
||||
int nStart = 0 ;
|
||||
int nEnd = 1 ;
|
||||
double dRatio = 1.5 ;
|
||||
while ( nStart < ssize( vPnt) - 1) {
|
||||
double dRadTol = max( max( vRad[nEnd], dRadPrec) / 10 , 1.) ;
|
||||
if ( dRadPrec > dRatio * vRad[nEnd] || dRatio * dRadPrec < vRad[nEnd])
|
||||
dRadTol = 0 ;
|
||||
while ( nEnd < ssize( vPnt) - 1 && abs( vRad[nEnd] - dRadPrec) < dRadTol) {
|
||||
dRadPrec = vRad[nEnd] ;
|
||||
++nEnd ;
|
||||
}
|
||||
vConstCurv.emplace_back( nStart * 3, nEnd * 3) ;
|
||||
nStart = nEnd ;
|
||||
dRadPrec = vRad[nEnd] ;
|
||||
++nEnd ;
|
||||
}
|
||||
if ( vConstCurv.empty())
|
||||
vConstCurv.emplace_back( 0, ssize( vPnt) - 1) ;
|
||||
|
||||
int nPoints = ssize( vPnt) ;
|
||||
DBLVECTOR vParam( nPoints) ;
|
||||
int nFirst = 0 ;
|
||||
int nLast = ssize( vPnt) - 1 ;
|
||||
ParamByLen( vPnt, vParam, nFirst, nLast) ;
|
||||
|
||||
VCT3DVECTOR vPrevDer ;
|
||||
VCT3DVECTOR vNextDer ;
|
||||
ComputeAkimaTangents( false, vParam, vPnt, vPrevDer, vNextDer) ;
|
||||
|
||||
int nOverSampling = ssize( vPntOverSampling) ;
|
||||
vParam.resize( nOverSampling) ;
|
||||
nFirst = 0 ;
|
||||
nLast = nOverSampling - 1 ;
|
||||
ParamByLen( vPntOverSampling, vParam, nFirst, nLast) ;
|
||||
|
||||
//normalizzo tutte le derivate
|
||||
for ( int i = 0 ; i < ssize( vPrevDer) ; ++i) {
|
||||
vPrevDer[i].Normalize() ;
|
||||
vNextDer[i].Normalize() ;
|
||||
}
|
||||
|
||||
// potrei verificare prima se un tratto è retto e aggiustare le tangenti del tratto precedente e successivo prima di approssimare
|
||||
PtrOwner<ICurveComposite> pCCApproxTot( CreateCurveComposite()) ;
|
||||
for ( INTINT iiSE : vConstCurv) {
|
||||
nFirst = iiSE.first ;
|
||||
nLast = iiSE.second ;
|
||||
// riconosco se ho un tratto retto
|
||||
int nPnt = nFirst / 3 ;
|
||||
if ( nLast - nFirst == 3 && ( nPnt > 0 && vRad[nPnt] > dRatio * vRad[nPnt - 1]) && ( nPnt < ssize( vRad) && vRad[nPnt]> dRatio * vRad[nPnt + 1])) {
|
||||
CurveLine CL ; CL.Set( vPntOverSampling[nFirst], vPntOverSampling[nLast]) ;
|
||||
PtrOwner<ICurveBezier> pCApprox( LineToBezierCurve( &CL, 3, false)) ;
|
||||
if ( ! pCCApproxTot->AddCurve( Release( pCApprox)))
|
||||
return nullptr ;
|
||||
}
|
||||
else {
|
||||
//definisco la bezier che vado a raffinare iterativamente
|
||||
PtrOwner<ICurve> pCApprox( FitWithBezier( pCrv, vPntOverSampling, vParam, nFirst, nLast, vPrevDer, vNextDer, dTol, true)) ;
|
||||
if ( IsNull( pCApprox) || ! pCApprox->IsValid())
|
||||
return nullptr ;
|
||||
if ( ! pCCApproxTot->AddCurve( Release( pCApprox)))
|
||||
return nullptr ;
|
||||
}
|
||||
}
|
||||
|
||||
return Release( pCCApproxTot) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CalcApproxError( const ICurve* pCrvOri, const ICurve* pCrvNew, double& dErr, int nPoints)
|
||||
{
|
||||
if ( pCrvOri == nullptr || ! pCrvOri->IsValid() || pCrvNew == nullptr || ! pCrvNew->IsValid()){
|
||||
dErr = INFINITO ;
|
||||
return false ;
|
||||
}
|
||||
// controllo l'errore effettivo campionando più finemente
|
||||
double dLenOri = 0 ; pCrvOri->GetLength( dLenOri) ;
|
||||
double dLenNew = 0 ; pCrvNew->GetLength( dLenNew) ;
|
||||
@@ -1489,7 +1796,7 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
{
|
||||
// se con nodi extra
|
||||
if ( cnData.bExtraKnotes) {
|
||||
int nKnotesNbr = int( cnData.vU.size()) ;
|
||||
int nKnotesNbr = ssize( cnData.vU) ;
|
||||
if ( nKnotesNbr < 4)
|
||||
return false ;
|
||||
cnData.bExtraKnotes = false ;
|
||||
@@ -1503,7 +1810,7 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
bool bAlreadyChecked = false ;
|
||||
// se la curva è peridica verifco che effettivamente ci sia un numero di punti ripetituti uguale al grado della curva
|
||||
// wrap della curva su se stessa
|
||||
if ( cnData.bPeriodic && (int(cnData.vU.size()) > int(cnData.vCP.size()) + cnData.nDeg - 1)) {
|
||||
if ( cnData.bPeriodic && ( ssize( cnData.vU) > ssize( cnData.vCP) + cnData.nDeg - 1)) {
|
||||
bool bRepeated = true ;
|
||||
for ( int i = 0 ; i < cnData.nDeg ; ++i) {
|
||||
if ( ! AreSamePointApprox( cnData.vCP[i], cnData.vCP.end()[-cnData.nDeg + i]) ) {
|
||||
@@ -1512,11 +1819,11 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
}
|
||||
}
|
||||
bool bFirstAddedAtEnd = false ;
|
||||
if ( ! bRepeated || (bRepeated && AreSamePointApprox( cnData.vCP[0],cnData.vCP[cnData.nDeg]))){
|
||||
if ( ! bRepeated || ( bRepeated && AreSamePointApprox( cnData.vCP[0], cnData.vCP[cnData.nDeg]))) {
|
||||
// salvo il vettore dei nodi in caso mi accorga di avere tra le mani una curva unclamped
|
||||
DBLVECTOR vU = cnData.vU ;
|
||||
// se effettivamente ho dei nodi in più da togliere allora li tolgo ed eventualmente aggiungo punti di controllo
|
||||
if ( int(cnData.vU.size()) > int(cnData.vCP.size()) + cnData.nDeg - 1 ) {
|
||||
if ( ssize( cnData.vU) > ssize( cnData.vCP) + cnData.nDeg - 1 ) {
|
||||
// se il primo e l'ultimo punto non coincidono allora aggiungo il primo punto in fondo al vettore dei punti di controllo
|
||||
if ( ! AreSamePointApprox( cnData.vCP[0], cnData.vCP.back())) {
|
||||
bFirstAddedAtEnd = true ;
|
||||
@@ -1528,11 +1835,11 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
cnData.vU = DBLVECTOR( cnData.vU.begin(), cnData.vU.end() - cnData.nDeg) ;
|
||||
// controllo eventualmente anche i nodi extra
|
||||
// se ne ho due in più ne tolgo uno in cima e uno in fondo
|
||||
if ( cnData.vU.size() == int( cnData.vCP.size()) + cnData.nDeg + 1 ) { // significa che ci sono due nodi extra, uno all'inizio e uno alla fine, da togliere
|
||||
if ( ssize( cnData.vU) == ssize( cnData.vCP) + cnData.nDeg + 1) { // significa che ci sono due nodi extra, uno all'inizio e uno alla fine, da togliere
|
||||
cnData.vU = vector<double>( cnData.vU.begin() + 1, cnData.vU.end() - 1) ;
|
||||
}
|
||||
// se ne ho solo uno in più lo tolgo in cima
|
||||
else if ( cnData.vU.size() == int( cnData.vCP.size()) + cnData.nDeg) {
|
||||
else if ( ssize( cnData.vU) == ssize( cnData.vCP) + cnData.nDeg) {
|
||||
cnData.vU = vector<double>( cnData.vU.begin() + 1, cnData.vU.end()) ;
|
||||
}
|
||||
}
|
||||
@@ -1559,7 +1866,7 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
// recupero il vettore dei nodi
|
||||
cnData.vU = vU ;
|
||||
// verifico se ho nodi extra
|
||||
if ( cnData.vU.size() == int( cnData.vCP.size()) + cnData.nDeg + 1 ) {
|
||||
if ( ssize( cnData.vU) == ssize( cnData.vCP) + cnData.nDeg + 1 ) {
|
||||
// significa che ci sono due nodi extra:
|
||||
// se la curva ha grado maggiore di 1 e i primi due nodi sono uguali allora tolgo quelli
|
||||
if ( cnData.nDeg > 1 && abs(cnData.vU[1] - cnData.vU[0]) < EPS_SMALL) {
|
||||
@@ -1570,7 +1877,7 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
cnData.vU = vector<double>( cnData.vU.begin() + 1, cnData.vU.end() - 1) ;
|
||||
}
|
||||
// se ne ho solo uno in più lo tolgo in cima
|
||||
else if ( cnData.vU.size() == int( cnData.vCP.size()) + cnData.nDeg)
|
||||
else if ( ssize( cnData.vU) == ssize( cnData.vCP) + cnData.nDeg)
|
||||
cnData.vU = vector<double>( cnData.vU.begin() + 1, cnData.vU.end()) ;
|
||||
}
|
||||
bAlreadyChecked = true ;
|
||||
@@ -1595,7 +1902,7 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
// qui aggiungo un controllo se la curva è collassata in un punto ( ho un polo), lascio stare
|
||||
bool bCollapsed = true ;
|
||||
Point3d ptFirst = cnData.vCP.front() ;
|
||||
for ( int i = 1 ; i < int( cnData.vCP.size()) ; ++i) {
|
||||
for ( int i = 1 ; i < ssize( cnData.vCP) ; ++i) {
|
||||
if ( ! AreSamePointApprox( ptFirst, cnData.vCP[i])) {
|
||||
bCollapsed = false ;
|
||||
break ;
|
||||
@@ -1612,7 +1919,7 @@ NurbsCurveCanonicalize( CNurbsData& cnData)
|
||||
// agli indici perché uso u_p-1 e u_(m-p+1), anziché u_p e u_m-p
|
||||
|
||||
// comincio ad aumentare la molteplictià del nodo u_m-p+1
|
||||
int nCP = int( cnData.vCP.size()) ;
|
||||
int nCP = ssize( cnData.vCP) ;
|
||||
int nU = nCP + cnData.nDeg - 1 ;
|
||||
int nDeg = cnData.nDeg ;
|
||||
PNTVECTOR vBC ;
|
||||
@@ -1808,9 +2115,9 @@ NurbsToBezierCurve( const CNurbsData& cnData)
|
||||
if ( cnData.bPeriodic || cnData.bExtraKnotes)
|
||||
return nullptr ;
|
||||
// numero dei nodi
|
||||
int nU = int( cnData.vCP.size()) + cnData.nDeg - 1 ;
|
||||
int nU = ssize( cnData.vCP) + cnData.nDeg - 1 ;
|
||||
// controllo relazione nodi - punti di controllo
|
||||
if ( nU != int( cnData.vU.size()))
|
||||
if ( nU != ssize( cnData.vU))
|
||||
return nullptr ;
|
||||
// numero degli intervalli
|
||||
int nInt = nU - 2 * cnData.nDeg + 1 ;
|
||||
@@ -2180,7 +2487,7 @@ CalcCurvesVoronoiDiagram( const CICURVEPVECTOR& vCrvC, ICURVEPOVECTOR& vCrvs, in
|
||||
PtrOwner<Voronoi> pVoronoiObj( new( std::nothrow) Voronoi()) ;
|
||||
if ( pVoronoiObj == nullptr)
|
||||
return false ;
|
||||
for ( int i = 0 ; i < int( vCrvC.size()) ; i ++) {
|
||||
for ( int i = 0 ; i < ssize( vCrvC) ; i ++) {
|
||||
if ( ! pVoronoiObj->AddCurve( vCrvC[i]))
|
||||
return false ;
|
||||
}
|
||||
@@ -2207,7 +2514,7 @@ CalcCurvesMedialAxis( const CICURVEPVECTOR& vCrvC, ICURVEPOVECTOR& vCrvs, int nS
|
||||
PtrOwner<Voronoi> pVoronoiObj( new( std::nothrow) Voronoi()) ;
|
||||
if ( pVoronoiObj == nullptr)
|
||||
return false ;
|
||||
for ( int i = 0 ; i < int( vCrvC.size()) ; i ++) {
|
||||
for ( int i = 0 ; i < ssize( vCrvC) ; i ++) {
|
||||
if ( ! pVoronoiObj->AddCurve( vCrvC[i]))
|
||||
return false ;
|
||||
}
|
||||
@@ -2268,7 +2575,7 @@ bool CalcOffsetCurves( const ICURVEPVECTOR& vpCrvs, ICURVEPOVECTOR& vCrvs, doubl
|
||||
PtrOwner<Voronoi> pVoronoiObj( new( std::nothrow) Voronoi()) ;
|
||||
if ( pVoronoiObj == nullptr)
|
||||
return false ;
|
||||
for ( int i = 0 ; i < int( vpCrvs.size()) ; i ++) {
|
||||
for ( int i = 0 ; i < ssize( vpCrvs) ; i ++) {
|
||||
if ( ! pVoronoiObj->AddCurve( vpCrvs[i]))
|
||||
return false ;
|
||||
}
|
||||
@@ -2298,7 +2605,7 @@ bool CalcFatOffsetCurves( const ICURVEPVECTOR& vpCrvs, ICURVEPOVECTOR& vCrvs, do
|
||||
PtrOwner<Voronoi> pVoronoiObj( new( std::nothrow) Voronoi()) ;
|
||||
if ( pVoronoiObj == nullptr)
|
||||
return false ;
|
||||
for ( int i = 0 ; i < int( vpCrvs.size()) ; i ++) {
|
||||
for ( int i = 0 ; i < ssize( vpCrvs) ; i ++) {
|
||||
if ( ! pVoronoiObj->AddCurve( vpCrvs[i]))
|
||||
return false ;
|
||||
}
|
||||
@@ -2332,7 +2639,7 @@ ResetCurveVoronoi( const ICurve& crvC)
|
||||
bool
|
||||
GetChainedCurves( ICRVCOMPOPOVECTOR& vCrv, double dChainTol, bool bAllowInvert)
|
||||
{
|
||||
if( ssize( vCrv) == 1)
|
||||
if ( ssize( vCrv) == 1)
|
||||
return true ;
|
||||
ChainCurves chainCrv ;
|
||||
// modifico direttamente le curve passate in input
|
||||
@@ -2352,22 +2659,22 @@ GetChainedCurves( ICRVCOMPOPOVECTOR& vCrv, double dChainTol, bool bAllowInvert)
|
||||
ICurveComposite* pFirstCrv = vCrv[abs(vIds[0]) - 1] ;
|
||||
for ( int nId : vIds) {
|
||||
bool bInvert = false ;
|
||||
if( nId < 0)
|
||||
if ( nId < 0)
|
||||
bInvert = true ;
|
||||
nId = abs( nId) - 1 ;
|
||||
if( bInvert)
|
||||
if ( bInvert)
|
||||
vCrv[nId]->Invert() ;
|
||||
if( ! pFirstCrv->AddCurve( Release( vCrv[nId]), true, dChainTol))
|
||||
if ( ! pFirstCrv->AddCurve( Release( vCrv[nId]), true, dChainTol))
|
||||
return false ;
|
||||
}
|
||||
pFirstCrv->GetEndPoint( ptStart) ;
|
||||
}
|
||||
// elimino gli elementi del vettore che non contengono più curve
|
||||
int c = ssize( vCrv) ;
|
||||
while( c > -1) {
|
||||
if( IsNull( vCrv[c]))
|
||||
while ( c > -1) {
|
||||
if ( IsNull( vCrv[c]))
|
||||
vCrv.erase( vCrv.begin() + c) ;
|
||||
--c ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -275,20 +275,19 @@ CurveBezier::FromLine( const ICurveLine& crLine)
|
||||
{
|
||||
if ( m_nStatus != OK || ! crLine.IsValid())
|
||||
return false ;
|
||||
double dWeight = 1 ;
|
||||
int nCount = 0 ;
|
||||
Point3d ptStart ; crLine.GetStartPoint( ptStart) ;
|
||||
SetControlPoint( nCount, ptStart, dWeight) ;
|
||||
SetControlPoint( nCount, ptStart) ;
|
||||
++nCount ;
|
||||
double dPart = 1. / m_nDeg ;
|
||||
for ( int i = 1 ; i < m_nDeg ; ++i) {
|
||||
double dU = i * dPart ;
|
||||
Point3d ptMid ; crLine.GetPointD1D2( dU, ICurve::FROM_MINUS, ptMid) ;
|
||||
SetControlPoint( nCount, ptMid, dWeight) ;
|
||||
SetControlPoint( nCount, ptMid) ;
|
||||
++nCount ;
|
||||
}
|
||||
Point3d ptEnd ; crLine.GetEndPoint( ptEnd) ;
|
||||
SetControlPoint( nCount, ptEnd, dWeight) ;
|
||||
SetControlPoint( nCount, ptEnd) ;
|
||||
++nCount ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
+2
-201
@@ -202,213 +202,14 @@ CurveByApprox::CalcParameterization( void)
|
||||
bool
|
||||
CurveByApprox::CalcAkimaTangents( bool bDetectCorner)
|
||||
{
|
||||
// pulisco i vettori delle tangenti
|
||||
m_vPrevDer.clear() ;
|
||||
m_vNextDer.clear() ;
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( m_vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return false ;
|
||||
|
||||
// calcolo le derivate
|
||||
m_vPrevDer.reserve( nSize) ;
|
||||
m_vNextDer.reserve( nSize) ;
|
||||
// se ci sono solo 2 punti, le tangenti devono essere dirette lungo la linea che li unisce
|
||||
if ( nSize == 2) {
|
||||
// non esiste derivata prima del primo punto
|
||||
m_vPrevDer.emplace_back( 0, 0, 0) ;
|
||||
m_vNextDer.push_back( ( m_vPnt[1] - m_vPnt[0]) / ( m_vPar[1] - m_vPar[0])) ;
|
||||
m_vPrevDer.push_back( m_vNextDer[0]) ;
|
||||
// non esiste derivata dopo il secondo e ultimo punto
|
||||
m_vNextDer.emplace_back( 0, 0, 0) ;
|
||||
return true ;
|
||||
}
|
||||
// verifico se curva chiusa (primo e ultimo punto coincidono)
|
||||
bool bClosed = AreSamePointApprox( m_vPnt.front(), m_vPnt.back()) ;
|
||||
// calcolo le derivate
|
||||
for ( int i = 0 ; i < nSize ; ++ i) {
|
||||
Vector3d vtPrevDer ;
|
||||
Vector3d vtNextDer ;
|
||||
// primo punto
|
||||
if ( i == 0) {
|
||||
// se curva chiusa, come precedente uso il penultimo punto
|
||||
if ( bClosed) {
|
||||
// se non ci sono almeno 5 punti
|
||||
if ( nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = vtNextDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[nSize-3] - m_vPar[nSize-1], m_vPnt[nSize-3], m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// altrimenti, uso arco sui primi tre punti
|
||||
else {
|
||||
if ( ! CalcCircleStartDer( m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// ultimo punto
|
||||
else if ( i == nSize - 1) {
|
||||
// se curva chiusa, le tg devono coincidere con quelle del primo
|
||||
if ( bClosed) {
|
||||
vtPrevDer = m_vPrevDer[0] ;
|
||||
vtNextDer = m_vNextDer[0] ;
|
||||
}
|
||||
// altrimenti, uso arco sugli ultimi tre punti
|
||||
else {
|
||||
if ( ! CalcCircleEndDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// punti intermedi
|
||||
else {
|
||||
// se secondo punto
|
||||
if ( i == 1) {
|
||||
// se curva aperta o non ci sono almeno 5 punti
|
||||
if ( ! bClosed || nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( m_vPar[i-1], m_vPnt[i-1], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// se penultimo punto
|
||||
else if ( i == nSize - 2) {
|
||||
// se curva aperta o non ci sono almeno 5 punti
|
||||
if ( ! bClosed || nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( m_vPar[i-1], m_vPnt[i-1], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[1] + m_vPar[i+1], m_vPnt[1], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// salvo la derivata
|
||||
m_vPrevDer.push_back( vtPrevDer) ;
|
||||
m_vNextDer.push_back( vtNextDer) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return ComputeAkimaTangents( bDetectCorner, m_vPar, m_vPnt, m_vPrevDer, m_vNextDer) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveByApprox::CalcBesselTangents( void)
|
||||
{
|
||||
// pulisco i vettori delle tangenti
|
||||
m_vPrevDer.clear() ;
|
||||
m_vNextDer.clear() ;
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( m_vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return false ;
|
||||
|
||||
// calcolo le derivate
|
||||
m_vPrevDer.reserve( nSize) ;
|
||||
m_vNextDer.reserve( nSize) ;
|
||||
// se ci sono solo 2 punti, le tangenti devono essere dirette lungo la linea che li unisce
|
||||
if ( nSize == 2) {
|
||||
// non esiste derivata prima del primo punto
|
||||
m_vPrevDer.emplace_back( 0, 0, 0) ;
|
||||
m_vNextDer.push_back( ( m_vPnt[1] - m_vPnt[0]) / ( m_vPar[1] - m_vPar[0])) ;
|
||||
m_vPrevDer.push_back( m_vNextDer[0]) ;
|
||||
// non esiste derivata dopo il secondo e ultimo punto
|
||||
m_vNextDer.emplace_back( 0, 0, 0) ;
|
||||
return true ;
|
||||
}
|
||||
// verifico se curva chiusa (primo e ultimo punto coincidono)
|
||||
bool bClosed = AreSamePointApprox( m_vPnt.front(), m_vPnt.back()) ;
|
||||
// calcolo le derivate
|
||||
for ( int i = 0 ; i < nSize ; ++ i) {
|
||||
Vector3d vtPrevDer ;
|
||||
Vector3d vtNextDer ;
|
||||
// primo punto
|
||||
if ( i == 0) {
|
||||
// se curva chiusa, come precedente uso il penultimo punto
|
||||
if ( bClosed) {
|
||||
if ( ! CalcBesselMidDer( m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = vtNextDer ;
|
||||
}
|
||||
// altrimenti, uso i primi tre punti
|
||||
else {
|
||||
if ( ! CalcBesselStartDer( m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// ultimo punto
|
||||
else if ( i == nSize - 1) {
|
||||
// se curva chiusa, le tg devono coincidere con quelle del primo
|
||||
if ( bClosed) {
|
||||
vtPrevDer = m_vPrevDer[0] ;
|
||||
vtNextDer = m_vNextDer[0] ;
|
||||
}
|
||||
// altrimenti, uso gli ultimi tre punti
|
||||
else {
|
||||
if ( ! CalcBesselEndDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// punti intermedi
|
||||
else {
|
||||
if ( ! CalcBesselMidDer( m_vPar[i-1], m_vPnt[i-1], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// salvo la derivata
|
||||
m_vPrevDer.push_back( vtPrevDer) ;
|
||||
m_vNextDer.push_back( vtNextDer) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return ComputeBesselTangents( m_vPar, m_vPnt, m_vPrevDer, m_vNextDer) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
+35
-236
@@ -50,12 +50,42 @@ CurveByInterp::AddPoint( const Point3d& ptP)
|
||||
ICurve*
|
||||
CurveByInterp::GetCurve( int nMethod, int nType)
|
||||
{
|
||||
// calcolo le tangenti
|
||||
// se richieste curve di Bezier cubiche (ottenute da interpolazione con Nurbs)
|
||||
if ( nType == CUBIC_BEZIERS_LONG) {
|
||||
// creo la curva composita
|
||||
PtrOwner<ICurve> pCrv ;
|
||||
//pCrv.Set( InterpolatePointSetWithBezier( m_vPnt, 50 * EPS_SMALL, 50)) ;
|
||||
//debug
|
||||
pCrv.Set( InterpolatePointSetWithBezier( m_vPnt, 0.1, 100)) ;
|
||||
if ( IsNull(pCrv) || ! pCrv->IsValid())
|
||||
return nullptr ;
|
||||
return Release( pCrv) ;
|
||||
}
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( m_vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return nullptr ;
|
||||
|
||||
// calcolo le distanze tra i punti per derivarne i parametri
|
||||
m_vPar.reserve( nSize) ;
|
||||
double dPar = 0 ;
|
||||
m_vPar.push_back( dPar) ;
|
||||
|
||||
for ( int i = 1 ; i < nSize ; ++ i) {
|
||||
double dDist = Dist( m_vPnt[i-1], m_vPnt[i]) ;
|
||||
dPar += dDist ;
|
||||
m_vPar.push_back( dPar) ;
|
||||
}
|
||||
|
||||
// calcolo le tangenti
|
||||
if ( nMethod == BESSEL) {
|
||||
if ( ! CalcBesselTangents())
|
||||
return nullptr ;
|
||||
}
|
||||
else if ( nType != CUBIC_BEZIERS_LONG) {
|
||||
else {
|
||||
if ( ! CalcAkimaTangents( nMethod == AKIMA_CORNER))
|
||||
return nullptr ;
|
||||
}
|
||||
@@ -103,16 +133,6 @@ CurveByInterp::GetCurve( int nMethod, int nType)
|
||||
return ::Release( pCrvCompo) ;
|
||||
}
|
||||
|
||||
// se richieste curve di Bezier cubiche (ottenute da interpolazione con Nurbs)
|
||||
if ( nType == CUBIC_BEZIERS_LONG) {
|
||||
// creo la curva composita
|
||||
PtrOwner<ICurve> pCrv ;
|
||||
pCrv.Set( InterpolatePointSetWithBezier( m_vPnt, 50 * EPS_SMALL, 50)) ;
|
||||
if ( IsNull(pCrv) || ! pCrv->IsValid())
|
||||
return nullptr ;
|
||||
return Release( pCrv) ;
|
||||
}
|
||||
|
||||
return nullptr ;
|
||||
}
|
||||
|
||||
@@ -120,233 +140,12 @@ CurveByInterp::GetCurve( int nMethod, int nType)
|
||||
bool
|
||||
CurveByInterp::CalcAkimaTangents( bool bDetectCorner)
|
||||
{
|
||||
// pulisco i vettori dei parametri e delle tangenti
|
||||
m_vPar.clear() ;
|
||||
m_vPrevDer.clear() ;
|
||||
m_vNextDer.clear() ;
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( m_vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return false ;
|
||||
|
||||
// calcolo le distanze tra i punti per derivarne i parametri
|
||||
m_vPar.reserve( nSize) ;
|
||||
double dPar = 0 ;
|
||||
m_vPar.push_back( dPar) ;
|
||||
for ( int i = 1 ; i < nSize ; ++ i) {
|
||||
double dDist = Dist( m_vPnt[i-1], m_vPnt[i]) ;
|
||||
dPar += dDist ;
|
||||
m_vPar.push_back( dPar) ;
|
||||
}
|
||||
|
||||
// calcolo le derivate
|
||||
m_vPrevDer.reserve( nSize) ;
|
||||
m_vNextDer.reserve( nSize) ;
|
||||
// se ci sono solo 2 punti, le tangenti devono essere dirette lungo la linea che li unisce
|
||||
if ( nSize == 2) {
|
||||
// non esiste derivata prima del primo punto
|
||||
m_vPrevDer.emplace_back( 0, 0, 0) ;
|
||||
m_vNextDer.push_back( ( m_vPnt[1] - m_vPnt[0]) / ( m_vPar[1] - m_vPar[0])) ;
|
||||
m_vPrevDer.push_back( m_vNextDer[0]) ;
|
||||
// non esiste derivata dopo il secondo e ultimo punto
|
||||
m_vNextDer.emplace_back( 0, 0, 0) ;
|
||||
return true ;
|
||||
}
|
||||
// verifico se curva chiusa (primo e ultimo punto coincidono)
|
||||
bool bClosed = AreSamePointApprox( m_vPnt.front(), m_vPnt.back()) ;
|
||||
// calcolo le derivate
|
||||
for ( int i = 0 ; i < nSize ; ++ i) {
|
||||
Vector3d vtPrevDer ;
|
||||
Vector3d vtNextDer ;
|
||||
// primo punto
|
||||
if ( i == 0) {
|
||||
// se curva chiusa, come precedente uso il penultimo punto
|
||||
if ( bClosed) {
|
||||
// se non ci sono almeno 5 punti
|
||||
if ( nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = vtNextDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[nSize-3] - m_vPar[nSize-1], m_vPnt[nSize-3], m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// altrimenti, uso arco sui primi tre punti
|
||||
else {
|
||||
if ( ! CalcCircleStartDer( m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// ultimo punto
|
||||
else if ( i == nSize - 1) {
|
||||
// se curva chiusa, le tg devono coincidere con quelle del primo
|
||||
if ( bClosed) {
|
||||
vtPrevDer = m_vPrevDer[0] ;
|
||||
vtNextDer = m_vNextDer[0] ;
|
||||
}
|
||||
// altrimenti, uso arco sugli ultimi tre punti
|
||||
else {
|
||||
if ( ! CalcCircleEndDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// punti intermedi
|
||||
else {
|
||||
// se secondo punto
|
||||
if ( i == 1) {
|
||||
// se curva aperta o non ci sono almeno 5 punti
|
||||
if ( ! bClosed || nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( m_vPar[i-1], m_vPnt[i-1], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// se penultimo punto
|
||||
else if ( i == nSize - 2) {
|
||||
// se curva aperta o non ci sono almeno 5 punti
|
||||
if ( ! bClosed || nSize < 5) {
|
||||
if ( ! CalcCircleMidDer( m_vPar[i-1], m_vPnt[i-1], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[1] + m_vPar[i+1], m_vPnt[1], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
if ( ! CalcAkimaMidDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], bDetectCorner,
|
||||
vtPrevDer, vtNextDer))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
// salvo la derivata
|
||||
m_vPrevDer.push_back( vtPrevDer) ;
|
||||
m_vNextDer.push_back( vtNextDer) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return ComputeAkimaTangents( bDetectCorner, m_vPar, m_vPnt, m_vPrevDer, m_vNextDer) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveByInterp::CalcBesselTangents( void)
|
||||
{
|
||||
// pulisco i vettori dei parametri e delle tangenti
|
||||
m_vPar.clear() ;
|
||||
m_vPrevDer.clear() ;
|
||||
m_vNextDer.clear() ;
|
||||
|
||||
// numero di punti
|
||||
int nSize = int( m_vPnt.size()) ;
|
||||
|
||||
// sono necessari almeno due punti
|
||||
if ( nSize < 2)
|
||||
return false ;
|
||||
|
||||
// calcolo le distanze tra i punti per derivarne i parametri
|
||||
m_vPar.reserve( nSize) ;
|
||||
double dPar = 0 ;
|
||||
m_vPar.push_back( dPar) ;
|
||||
for ( int i = 1 ; i < nSize ; ++ i) {
|
||||
double dDist = Dist( m_vPnt[i-1], m_vPnt[i]) ;
|
||||
dPar += dDist ;
|
||||
m_vPar.push_back( dPar) ;
|
||||
}
|
||||
|
||||
// calcolo le derivate
|
||||
m_vPrevDer.reserve( nSize) ;
|
||||
m_vNextDer.reserve( nSize) ;
|
||||
// se ci sono solo 2 punti, le tangenti devono essere dirette lungo la linea che li unisce
|
||||
if ( nSize == 2) {
|
||||
// non esiste derivata prima del primo punto
|
||||
m_vPrevDer.emplace_back( 0, 0, 0) ;
|
||||
m_vNextDer.push_back( ( m_vPnt[1] - m_vPnt[0]) / ( m_vPar[1] - m_vPar[0])) ;
|
||||
m_vPrevDer.push_back( m_vNextDer[0]) ;
|
||||
// non esiste derivata dopo il secondo e ultimo punto
|
||||
m_vNextDer.emplace_back( 0, 0, 0) ;
|
||||
return true ;
|
||||
}
|
||||
// verifico se curva chiusa (primo e ultimo punto coincidono)
|
||||
bool bClosed = AreSamePointApprox( m_vPnt.front(), m_vPnt.back()) ;
|
||||
// calcolo le derivate
|
||||
for ( int i = 0 ; i < nSize ; ++ i) {
|
||||
Vector3d vtPrevDer ;
|
||||
Vector3d vtNextDer ;
|
||||
// primo punto
|
||||
if ( i == 0) {
|
||||
// se curva chiusa, come precedente uso il penultimo punto
|
||||
if ( bClosed) {
|
||||
if ( ! CalcBesselMidDer( m_vPar[nSize-2] - m_vPar[nSize-1], m_vPnt[nSize-2], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = vtNextDer ;
|
||||
}
|
||||
// altrimenti, uso i primi tre punti
|
||||
else {
|
||||
if ( ! CalcBesselStartDer( m_vPar[i], m_vPnt[i], m_vPar[i+1], m_vPnt[i+1],
|
||||
m_vPar[i+2], m_vPnt[i+2], vtNextDer))
|
||||
return false ;
|
||||
vtPrevDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// ultimo punto
|
||||
else if ( i == nSize - 1) {
|
||||
// se curva chiusa, le tg devono coincidere con quelle del primo
|
||||
if ( bClosed) {
|
||||
vtPrevDer = m_vPrevDer[0] ;
|
||||
vtNextDer = m_vNextDer[0] ;
|
||||
}
|
||||
// altrimenti, uso gli ultimi tre punti
|
||||
else {
|
||||
if ( ! CalcBesselEndDer( m_vPar[i-2], m_vPnt[i-2], m_vPar[i-1], m_vPnt[i-1],
|
||||
m_vPar[i], m_vPnt[i], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = Vector3d( 0, 0, 0) ;
|
||||
}
|
||||
}
|
||||
// punti intermedi
|
||||
else {
|
||||
if ( ! CalcBesselMidDer( m_vPar[i-1], m_vPnt[i-1], m_vPar[i], m_vPnt[i],
|
||||
m_vPar[i+1], m_vPnt[i+1], vtPrevDer))
|
||||
return false ;
|
||||
vtNextDer = vtPrevDer ;
|
||||
}
|
||||
// salvo la derivata
|
||||
m_vPrevDer.push_back( vtPrevDer) ;
|
||||
m_vNextDer.push_back( vtNextDer) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
return ComputeBesselTangents( m_vPar, m_vPnt, m_vPrevDer, m_vNextDer) ;
|
||||
}
|
||||
+15
-2
@@ -116,6 +116,7 @@ PolishMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve,
|
||||
vtDiff = ptQ - ptP ;
|
||||
// angolo tra vettore e tangente
|
||||
dTemp = vtDer1 * vtDiff ;
|
||||
bool bEquiverse = dTemp > 0 ;
|
||||
if ( abs( dTemp) > EPS_ZERO)
|
||||
dSqCosA = dTemp * dTemp / ( vtDer1.SqLen() * vtDiff.SqLen()) ;
|
||||
else
|
||||
@@ -123,8 +124,20 @@ PolishMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve,
|
||||
// stima prossimo valore del parametro (Newton : Unext = U - F(U) / F'(U))
|
||||
dPrevPar = dPar ;
|
||||
dTemp = vtDer2 * vtDiff + vtDer1.SqLen() ;
|
||||
if ( abs( dTemp) > EPS_ZERO)
|
||||
dPar = dPrevPar - ( vtDer1 * vtDiff) / dTemp ;
|
||||
|
||||
// se il coseno tra questi due vettori è troppo grande potrei aver avuto una cattiva stima iniziale
|
||||
// provo quindi ad aggiustare a mano, anziché usare il segno suggerito da newton, che con queste premesse potrebbe divergere
|
||||
double dCos75 = 0.2588 ;
|
||||
if ( abs( dTemp) > EPS_ZERO) {
|
||||
double dDelta = ( vtDer1 * vtDiff) / dTemp ;
|
||||
if ( dSqCosA > dCos75) {
|
||||
if ( ( bEquiverse && dDelta > 0) || ( ! bEquiverse && dDelta < 0))
|
||||
dDelta *= -1 ;
|
||||
dPar = dPrevPar + dDelta ;
|
||||
}
|
||||
else
|
||||
dPar = dPrevPar - dDelta ;
|
||||
}
|
||||
// clipping parametro
|
||||
if ( dPar < approxMin.dParMin) {
|
||||
if ( approxMin.bParMinSing && ! bClampedFromSing) {
|
||||
|
||||
+12
-1
@@ -26,7 +26,7 @@ DistPointCrvBezier::DistPointCrvBezier( const Point3d& ptP, const ICurveBezier&
|
||||
// distanza non calcolata
|
||||
m_dDist = - 1 ;
|
||||
|
||||
if ( &CrvBez == nullptr || ! CrvBez.IsValid())
|
||||
if ( ! CrvBez.IsValid())
|
||||
return ;
|
||||
|
||||
// determino tolleranza di approssimazione in base a ingombro curva
|
||||
@@ -42,6 +42,17 @@ DistPointCrvBezier::DistPointCrvBezier( const Point3d& ptP, const ICurveBezier&
|
||||
if ( ! CrvBez.ApproxWithLines( dLinTol, ANG_TOL_APPROX_DEG, ICurve::APL_STD, PL))
|
||||
return ;
|
||||
|
||||
int nDeg = CrvBez.GetDegree() ;
|
||||
if ( PL.GetPointNbr() < nDeg + 1) {
|
||||
// costruisco una polilinea con un numero di curve scelto in base al grado della curva
|
||||
PL.Clear() ;
|
||||
for ( int i = 0 ; i <= nDeg + 1 ; ++i) {
|
||||
double dU = double(i) / (nDeg + 1) ;
|
||||
Point3d ptBez ;
|
||||
CrvBez.GetPointD1D2( dU, ICurve::Side::FROM_MINUS, ptBez) ;
|
||||
PL.AddUPoint( dU, ptBez) ;
|
||||
}
|
||||
}
|
||||
// cerco la minima distanza per la polilinea
|
||||
MDCVECTOR vApproxMin ;
|
||||
if ( ! CalcMinDistPointPolyLine( ptP, PL, dLinTol, vApproxMin))
|
||||
|
||||
+11
-10
@@ -23,10 +23,10 @@ using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
DistPointSurfBz::DistPointSurfBz( const Point3d& ptP, const ISurfBezier& pSrfBz)
|
||||
: m_dDist( -1), m_bIsInside( false)
|
||||
: m_dDist( -1), m_bIsInside( false), m_bIsSurfClosed( false)
|
||||
{
|
||||
// Bezier non valida
|
||||
if ( &pSrfBz == nullptr || ! pSrfBz.IsValid())
|
||||
if ( ! pSrfBz.IsValid())
|
||||
return ;
|
||||
// Calcolo la distanza
|
||||
Calculate( ptP, pSrfBz) ;
|
||||
@@ -37,9 +37,9 @@ void
|
||||
DistPointSurfBz::Calculate( const Point3d& ptP, const ISurfBezier& srfBz)
|
||||
{
|
||||
// Inizializzo distanza non calcolata
|
||||
m_dDist = - 1. ;
|
||||
m_dDist = -1 ;
|
||||
|
||||
// Controllo se la superficie è chiusa
|
||||
// Controllo se la superficie è chiusa
|
||||
m_bIsSurfClosed = srfBz.IsClosed() ;
|
||||
|
||||
// Lavoro con l'oggetto superficie trimesh di base
|
||||
@@ -49,17 +49,17 @@ DistPointSurfBz::Calculate( const Point3d& ptP, const ISurfBezier& srfBz)
|
||||
|
||||
DistPointSurfTm dpst( ptP, *pStmRef) ;
|
||||
|
||||
//recupero il punto a distanza minima sulla trimesh e lo raffino, prima di restituire distanza e punto minimo
|
||||
// recupero il punto a distanza minima sulla trimesh e lo raffino, prima di restituire distanza e punto minimo
|
||||
Point3d ptMinTm ; dpst.GetMinDistPoint( ptMinTm) ;
|
||||
int nT ; dpst.GetMinDistTriaIndex( nT) ;
|
||||
//salvo il punto corrispondente nel parametrico
|
||||
// salvo il punto corrispondente nel parametrico
|
||||
srfBz.UnprojectPointFromStm( nT, ptMinTm, m_ptParam) ;
|
||||
// salvo il punto a minima distanza sulla superficie e la normale alla superficie in quel punto
|
||||
srfBz.GetPointNrmD1D2( m_ptParam.x, m_ptParam.y, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, m_ptMinDistPoint, m_vtN) ;
|
||||
|
||||
// salvo la distanza minima
|
||||
m_dDist = Dist( ptP, m_ptMinDistPoint) ;
|
||||
// se il punto è sulla superficie
|
||||
// se il punto è sulla superficie
|
||||
if ( m_dDist < EPS_SMALL) {
|
||||
m_bIsInside = false ;
|
||||
return ;
|
||||
@@ -96,13 +96,14 @@ DistPointSurfBz::GetMinDistPoint( Point3d& ptMinDistPoint) const
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
DistPointSurfBz::GetParamPoint( Point3d& ptParamPoint) const
|
||||
DistPointSurfBz::GetParamsAtMinDistPoint( double& dU, double& dV) const
|
||||
{
|
||||
// Distanza non valida
|
||||
if ( m_dDist < -EPS_ZERO)
|
||||
return false ;
|
||||
// Distanza valida
|
||||
ptParamPoint = m_ptParam ;
|
||||
dU = m_ptParam.x ;
|
||||
dV = m_ptParam.y ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -116,4 +117,4 @@ DistPointSurfBz::GetNorm( Vector3d& vtN) const
|
||||
// Distanza valida
|
||||
vtN = m_vtN ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -281,6 +281,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClCompile Include="BBox3d.cpp" />
|
||||
<ClCompile Include="BiArcs.cpp" />
|
||||
<ClCompile Include="CalcPocketing.cpp" />
|
||||
<ClCompile Include="CalcDerivate.cpp" />
|
||||
<ClCompile Include="CAvSilhouetteSurfTm.cpp" />
|
||||
<ClCompile Include="CAvSimpleSurfFrMove.cpp" />
|
||||
<ClCompile Include="CAvToolSurfTm.cpp" />
|
||||
|
||||
@@ -567,6 +567,9 @@
|
||||
<ClCompile Include="Trimming.cpp">
|
||||
<Filter>File di origine\GeoStriping</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CalcDerivate.cpp">
|
||||
<Filter>File di origine\Geo</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
|
||||
@@ -296,8 +296,8 @@ int
|
||||
IntersCurveCurve::GetInters3DCount( void)
|
||||
{
|
||||
int nCount = 0 ;
|
||||
for( int i = 0 ; i < m_nIntersCount ; ++i) {
|
||||
if( ! m_Info[i].bOverlap || ( m_Info[i].bOverlap && m_Info[i].bCBOverEq)) {
|
||||
for ( int i = 0 ; i < m_nIntersCount ; ++i) {
|
||||
if ( ! m_Info[i].bOverlap || ( m_Info[i].bOverlap && m_Info[i].bCBOverEq)) {
|
||||
if ( abs( m_Info[i].IciA[0].ptI.z - m_Info[i].IciB[0].ptI.z) < EPS_SMALL)
|
||||
++nCount ;
|
||||
}
|
||||
@@ -365,8 +365,8 @@ IntersCurveCurve::GetInt3DCrvCrvInfo( int nInd, IntCrvCrvInfo& aInfo)
|
||||
if ( nInd < 0 || nInd >= GetInters3DCount())
|
||||
return false ;
|
||||
int nCount = - 1 ;
|
||||
for( int i = 0 ; i < m_nIntersCount ; ++i) {
|
||||
if( ! m_Info[i].bOverlap || ( m_Info[i].bOverlap && m_Info[i].bCBOverEq)) {
|
||||
for ( int i = 0 ; i < m_nIntersCount ; ++i) {
|
||||
if ( ! m_Info[i].bOverlap || ( m_Info[i].bOverlap && m_Info[i].bCBOverEq)) {
|
||||
if ( abs( m_Info[i].IciA[0].ptI.z - m_Info[i].IciB[0].ptI.z) < EPS_SMALL)
|
||||
++nCount ;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ IntersCurveCurve::GetInt3DCrvCrvInfo( int nInd, IntCrvCrvInfo& aInfo)
|
||||
if ( abs( m_Info[i].IciA[0].ptI.z - m_Info[i].IciB[1].ptI.z) < EPS_SMALL)
|
||||
++nCount ;
|
||||
}
|
||||
if( nCount == nInd) {
|
||||
if ( nCount == nInd) {
|
||||
aInfo = m_Info[nInd] ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -139,8 +139,6 @@ IntersCurvePlane::CalcIntersLinePlane( const Plane3d& plPlane, const ICurve& Cur
|
||||
void
|
||||
IntersCurvePlane::OrderAndCompleteIntersections()
|
||||
{
|
||||
if ( m_Info.size() < 2)
|
||||
return ;
|
||||
// cancello le interesezioni puntuali adiacenti a tratti di sovrapposizione
|
||||
// riempio le info PrevTy e NexyTy
|
||||
sort( m_Info.begin(), m_Info.end(), []( IntCrvPlnInfo& icpA, IntCrvPlnInfo& icpB) { return icpA.Ici[0].dU < icpA.Ici[0].dU ;}) ;
|
||||
|
||||
+99
-52
@@ -19,6 +19,7 @@
|
||||
#include "/EgtDev/Include/EGkDistPointLine.h"
|
||||
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
||||
#include "/EgtDev/Include/EGkDistPointSurfTm.h"
|
||||
#include "/EgtDev/Include/EGkDistPointSurfBz.h"
|
||||
#include "/EgtDev/Include/EGkIntersPlanePlane.h"
|
||||
#include "/EgtDev/Include/EGkIntersLinePlane.h"
|
||||
#include "/EgtDev/Include/EGkIntersLineSurfTm.h"
|
||||
@@ -92,6 +93,8 @@ AddPointsOnCorners( PNT5AXVECTOR& vPt5ax)
|
||||
Pt5ax.ptP = ptInt - vtLine1 / dLen1 * 2 * EPS_SMALL ;
|
||||
Pt5ax.vtDir1 = vPt5ax[j].vtDir1 ;
|
||||
Pt5ax.vtDir2 = vPt5ax[j].vtDir2 ;
|
||||
Pt5ax.vtDirU = vPt5ax[j].vtDirU ;
|
||||
Pt5ax.vtDirV = vPt5ax[j].vtDirV ;
|
||||
Pt5ax.dPar = ( vPt5ax[i].dPar + vPt5ax[j].dPar) / 2 ;
|
||||
Pt5ax.nFlag = P5AX_CVEX ;
|
||||
vPt5ax.insert( vPt5ax.begin() + i, Pt5ax) ;
|
||||
@@ -104,6 +107,8 @@ AddPointsOnCorners( PNT5AXVECTOR& vPt5ax)
|
||||
Pt5ax.ptP = ptInt + vtLine2 / dLen2 * 2 * EPS_SMALL ;
|
||||
Pt5ax.vtDir1 = vPt5ax[i].vtDir1 ;
|
||||
Pt5ax.vtDir2 = vPt5ax[i].vtDir2 ;
|
||||
Pt5ax.vtDirU = vPt5ax[i].vtDirU ;
|
||||
Pt5ax.vtDirV = vPt5ax[i].vtDirV ;
|
||||
Pt5ax.dPar = ( vPt5ax[i].dPar + vPt5ax[j].dPar) / 2 ;
|
||||
Pt5ax.nFlag = P5AX_CVEX ;
|
||||
vPt5ax.insert( vPt5ax.begin() + i, Pt5ax) ;
|
||||
@@ -118,6 +123,8 @@ AddPointsOnCorners( PNT5AXVECTOR& vPt5ax)
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = Media( vPt5ax[i].vtDir1, vPt5ax[j].vtDir1) ; Pt5ax.vtDir1.Normalize() ;
|
||||
Pt5ax.vtDir2 = Media( vPt5ax[i].vtDir2, vPt5ax[j].vtDir2) ; Pt5ax.vtDir2.Normalize() ;
|
||||
Pt5ax.vtDirU = Media( vPt5ax[i].vtDirU, vPt5ax[j].vtDirU) ; Pt5ax.vtDirU.Normalize() ;
|
||||
Pt5ax.vtDirV = Media( vPt5ax[i].vtDirV, vPt5ax[j].vtDirV) ; Pt5ax.vtDirV.Normalize() ;
|
||||
Pt5ax.dPar = ( vPt5ax[i].dPar + vPt5ax[j].dPar) / 2 ;
|
||||
Pt5ax.nFlag = P5AX_CONC ;
|
||||
vPt5ax.insert( vPt5ax.begin() + i, Pt5ax) ;
|
||||
@@ -233,23 +240,55 @@ RemovePointsInExcess( PNT5AXVECTOR& vPt5ax, double dLinTol, double dMaxSegmLen,
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
ProjectPointOnSurf( const Point3d& ptP, const CISRFTMPVECTOR& vpStm, double dPar, Point5ax& Pt5ax)
|
||||
static const SurfTriMesh*
|
||||
MyGetAuxSurf( const ISurf* pSrf)
|
||||
{
|
||||
// punto sulle supefici a minima distanza
|
||||
if ( pSrf == nullptr)
|
||||
return nullptr ;
|
||||
switch ( pSrf->GetType()) {
|
||||
case SRF_TRIMESH :
|
||||
return GetBasicSurfTriMesh( pSrf) ;
|
||||
case SRF_FLATRGN :
|
||||
return GetBasicSurfFlatRegion( pSrf)->GetAuxSurf() ;
|
||||
case SRF_BEZIER :
|
||||
return GetBasicSurfBezier( pSrf)->GetAuxSurf() ;
|
||||
default :
|
||||
return nullptr ;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
ProjectPointOnSurf( const Point3d& ptP, const CISURFPVECTOR& vpSurf, double dPar, Point5ax& Pt5ax)
|
||||
{
|
||||
// punto sulle superfici a minima distanza
|
||||
int nSurfMin = -1 ;
|
||||
int nTriaMin ;
|
||||
int nTriaMin = -1 ;
|
||||
double dUMin = -1, dVMin = -1 ;
|
||||
Point3d ptMin ;
|
||||
double dMinDist ;
|
||||
for ( int i = 0 ; i < ssize( vpStm) ; ++ i) {
|
||||
double dMinDist = NAN ;
|
||||
for ( int i = 0 ; i < ssize( vpSurf) ; ++ i) {
|
||||
// punto sulla superficie a minima distanza
|
||||
DistPointSurfTm dPS( ptP, *vpStm[i]) ;
|
||||
double dDist ;
|
||||
if ( dPS.GetDist( dDist) && ( nSurfMin == -1 || dDist < dMinDist)) {
|
||||
nSurfMin = i ;
|
||||
dPS.GetMinDistPoint( ptMin) ;
|
||||
dPS.GetMinDistTriaIndex ( nTriaMin) ;
|
||||
dMinDist = dDist ;
|
||||
int nSrfType = ( vpSurf[i] != nullptr ? vpSurf[i]->GetType() : GEO_NONE) ;
|
||||
if ( nSrfType == SRF_TRIMESH || nSrfType == SRF_FLATRGN) {
|
||||
DistPointSurfTm dPS( ptP, *MyGetAuxSurf( vpSurf[i])) ;
|
||||
double dDist ;
|
||||
if ( dPS.GetDist( dDist) && ( nSurfMin == -1 || dDist < dMinDist)) {
|
||||
nSurfMin = i ;
|
||||
dPS.GetMinDistPoint( ptMin) ;
|
||||
dPS.GetMinDistTriaIndex ( nTriaMin) ;
|
||||
dMinDist = dDist ;
|
||||
}
|
||||
}
|
||||
else if ( nSrfType == SRF_BEZIER) {
|
||||
DistPointSurfBz dPS( ptP, *GetBasicSurfBezier( vpSurf[i])) ;
|
||||
double dDist ;
|
||||
if ( dPS.GetDist( dDist) && ( nSurfMin == -1 || dDist < dMinDist)) {
|
||||
nSurfMin = i ;
|
||||
dPS.GetMinDistPoint( ptMin) ;
|
||||
dPS.GetParamsAtMinDistPoint( dUMin, dVMin) ;
|
||||
dMinDist = dDist ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,19 +296,44 @@ ProjectPointOnSurf( const Point3d& ptP, const CISRFTMPVECTOR& vpStm, double dPar
|
||||
if ( nSurfMin >= 0) {
|
||||
// assegno il punto
|
||||
Point3d ptInt = ptMin ;
|
||||
// calcolo la normale (si calcola smooth, in caso di errore si prende quella del triangolo)
|
||||
Triangle3dEx trTria ;
|
||||
if ( ! vpStm[nSurfMin]->GetTriangle( nTriaMin, trTria))
|
||||
return false ;
|
||||
Vector3d vtN ;
|
||||
if ( ! CalcNormal( ptMin, trTria, vtN))
|
||||
vtN = trTria.GetN() ;
|
||||
// assegno valori al punto 5assi
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = vtN ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
// calcolo gli altri dati
|
||||
int nSrfType = ( vpSurf[nSurfMin] != nullptr ? vpSurf[nSurfMin]->GetType() : GEO_NONE) ;
|
||||
if ( nSrfType == SRF_TRIMESH || nSrfType == SRF_FLATRGN) {
|
||||
// recupero superficie trimesh
|
||||
const SurfTriMesh* pSurfTm = MyGetAuxSurf( vpSurf[nSurfMin]) ;
|
||||
// calcolo la normale (si calcola smooth, in caso di errore si prende quella del triangolo)
|
||||
Triangle3dEx trTria ;
|
||||
if ( ! pSurfTm->GetTriangle( nTriaMin, trTria))
|
||||
return false ;
|
||||
Vector3d vtN ;
|
||||
if ( ! CalcNormal( ptMin, trTria, vtN))
|
||||
vtN = trTria.GetN() ;
|
||||
// assegno valori al punto 5assi
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = vtN ;
|
||||
Pt5ax.vtDirU = V_NULL ;
|
||||
Pt5ax.vtDirV = V_NULL ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
}
|
||||
else if ( nSrfType == SRF_BEZIER) {
|
||||
Point3d ptSB ;
|
||||
Vector3d vtN, vtDerU, vtDerV ;
|
||||
if ( ! GetBasicSurfBezier( vpSurf[nSurfMin])->GetPointNrmD1D2( dUMin, dVMin, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS,
|
||||
ptSB, vtN, &vtDerU, &vtDerV))
|
||||
return false ;
|
||||
vtDerU.Normalize() ;
|
||||
vtDerV.Normalize() ;
|
||||
// assegno valori al punto 5assi
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = vtN ;
|
||||
Pt5ax.vtDirU = vtDerU ;
|
||||
Pt5ax.vtDirV = vtDerV ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
}
|
||||
// ritorno con successo
|
||||
return true ;
|
||||
}
|
||||
@@ -282,31 +346,6 @@ bool
|
||||
ProjectCurveOnSurf( const ICurve& crCrv, const CISURFPVECTOR& vpSurf,
|
||||
double dLinTol, double dMaxSegmLen, bool bSharpEdges, PNT5AXVECTOR& vPt5ax)
|
||||
{
|
||||
// sistemazioni per tipo di superficie
|
||||
CISRFTMPVECTOR vpSurfTm ;
|
||||
for ( int i = 0 ; i < ssize( vpSurf) ; ++ i) {
|
||||
const SurfTriMesh* pSurfTm = nullptr ;
|
||||
switch ( vpSurf[i]->GetType()) {
|
||||
case SRF_TRIMESH :
|
||||
pSurfTm = GetBasicSurfTriMesh( vpSurf[i]) ;
|
||||
break ;
|
||||
case SRF_BEZIER :
|
||||
{ double dOldLinTol = GetSurfBezierAuxSurfRefinedTol() ;
|
||||
SetSurfBezierAuxSurfRefinedTol( GetSurfBezierTol( dLinTol)) ;
|
||||
pSurfTm = GetBasicSurfBezier( vpSurf[i])->GetAuxSurfRefined() ;
|
||||
SetSurfBezierAuxSurfRefinedTol( dOldLinTol) ;
|
||||
} break ;
|
||||
case SRF_FLATRGN :
|
||||
pSurfTm = GetBasicSurfFlatRegion( vpSurf[i])->GetAuxSurf() ;
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
if ( pSurfTm == nullptr)
|
||||
return false ;
|
||||
vpSurfTm.emplace_back( pSurfTm) ;
|
||||
}
|
||||
|
||||
// controllo le tolleranze
|
||||
dLinTol = max( dLinTol, LIN_TOL_MIN) ;
|
||||
dMaxSegmLen = max( dMaxSegmLen, 10 * EPS_SMALL) ;
|
||||
@@ -331,7 +370,7 @@ ProjectCurveOnSurf( const ICurve& crCrv, const CISURFPVECTOR& vpSurf,
|
||||
while ( bFound) {
|
||||
// se trovo proiezione, la salvo
|
||||
Point5ax Pt5ax ;
|
||||
if ( ProjectPointOnSurf( ptP, vpSurfTm, dPar, Pt5ax))
|
||||
if ( ProjectPointOnSurf( ptP, vpSurf, dPar, Pt5ax))
|
||||
vPt5ax.emplace_back( Pt5ax) ;
|
||||
// passo al successivo
|
||||
bFound = PL.GetNextUPoint( &dPar, &ptP) ;
|
||||
@@ -403,6 +442,8 @@ ProjectPointOnSurf( const Point3d& ptP, const CISRFTMPVECTOR& vpStm, const Frame
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = frRefLine.VersZ() ;
|
||||
Pt5ax.vtDirU = V_NULL ;
|
||||
Pt5ax.vtDirV = V_NULL ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
// ritorno con successo
|
||||
@@ -557,6 +598,8 @@ ProjectPointOnSurf( const Point3d& ptP, const CISRFTMPVECTOR& vpStm, const IGeoP
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = vtLine ;
|
||||
Pt5ax.vtDirU = V_NULL ;
|
||||
Pt5ax.vtDirV = V_NULL ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
// ritorno con successo
|
||||
@@ -696,6 +739,8 @@ ProjectPointOnSurf( const Point3d& ptP, const CISRFTMPVECTOR& vpStm, const ICurv
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = vtLine ;
|
||||
Pt5ax.vtDirU = V_NULL ;
|
||||
Pt5ax.vtDirV = V_NULL ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
// ritorno con successo
|
||||
@@ -852,6 +897,8 @@ ProjectPointOnSurf( const Point3d& ptP, const CISRFTMPVECTOR& vpStm, const SurfT
|
||||
Pt5ax.ptP = ptInt ;
|
||||
Pt5ax.vtDir1 = vtN ;
|
||||
Pt5ax.vtDir2 = vtN2 ;
|
||||
Pt5ax.vtDirU = V_NULL ;
|
||||
Pt5ax.vtDirV = V_NULL ;
|
||||
Pt5ax.dPar = dPar ;
|
||||
Pt5ax.nFlag = P5AX_STD ;
|
||||
// ritorno con successo
|
||||
|
||||
+108
-105
@@ -877,7 +877,7 @@ SurfBezier::CopyFrom( const SurfBezier& sbSrc)
|
||||
m_pTrimReg = sbSrc.m_pTrimReg->Clone() ;
|
||||
}
|
||||
#ifndef SAVEFAILEDTRIANGULATION
|
||||
if( sbSrc.GetAuxSurf() != nullptr)
|
||||
if ( sbSrc.GetAuxSurf() != nullptr)
|
||||
m_pSTM = sbSrc.GetAuxSurf()->Clone() ;
|
||||
#endif
|
||||
for ( int i = 0 ; i < int( sbSrc.m_mCCEdge.size()) ; ++i) {
|
||||
@@ -1075,7 +1075,7 @@ SurfBezier::Load( NgeReader& ngeIn)
|
||||
ICURVEPOVECTOR vCrv ;
|
||||
GetAllPatchesIsocurves( false, vCrv) ;
|
||||
vector<IGeoObj*> vGeo ;
|
||||
for( int i = 0 ; i < ssize(vCrv) ; ++i)
|
||||
for ( int i = 0 ; i < ssize(vCrv) ; ++i)
|
||||
vGeo.push_back( vCrv[i]->Clone()) ;
|
||||
SaveGeoObj( vGeo, "D:\\Temp\\bezier\\ruled\\rebuild\\isoCrv.nge") ;
|
||||
#endif
|
||||
@@ -1820,7 +1820,7 @@ SurfBezier::GetAuxSurf( void) const
|
||||
}
|
||||
}
|
||||
// eseguo calcolo
|
||||
m_pSTM = GetApproxSurf( s_dAuxSurfTol, 100 * EPS_SMALL, false) ;
|
||||
m_pSTM = GetApproxSurf( s_dAuxSurfTol, 10 * EPS_SMALL, false) ;
|
||||
++nSurf ;
|
||||
if ( m_pSTM != nullptr)
|
||||
m_pSTM->SetTempParam( s_dAuxSurfTol) ;
|
||||
@@ -1855,7 +1855,7 @@ SurfBezier::GetAuxSurfRefined( void) const
|
||||
}
|
||||
}
|
||||
// eseguo calcolo
|
||||
m_pSTMRefined = GetApproxSurf( s_dAuxSurfRefinedTol, 100 * EPS_SMALL, true) ;
|
||||
m_pSTMRefined = GetApproxSurf( s_dAuxSurfRefinedTol, 10 * EPS_SMALL, true) ;
|
||||
if ( m_pSTMRefined != nullptr)
|
||||
m_pSTMRefined->SetTempParam( s_dAuxSurfRefinedTol) ;
|
||||
return m_pSTMRefined ;
|
||||
@@ -1898,7 +1898,7 @@ SurfBezier::GetApproxSurf( double dTol, double dSideMin, bool bUpdateEdges) cons
|
||||
Point3d ptMin = get<0>( vTrees[i]) ;
|
||||
Point3d ptMax = get<1>( vTrees[i]) ;
|
||||
Tree.SetSurf( this, ptMin, ptMax) ;
|
||||
if( ! Tree.BuildTree( dTol, dSideMin)) {
|
||||
if ( ! Tree.BuildTree( dTol, dSideMin)) {
|
||||
LOG_DBG_ERR( GetEGkLogger(), "ERROR : Bezier Surface parametric space couldn't be split in cells") ;
|
||||
return nullptr ;
|
||||
}
|
||||
@@ -3029,10 +3029,10 @@ SurfBezier::UnprojectPointFromStm( int nT, const Point3d& ptI, Point3d& ptSP, in
|
||||
dPtStm.GetMinDistTriaIndex( nTriaIndex) ;
|
||||
// se ho trovato un nuovo triangolo, controllo che questo fosse nella lista dei triangoli equidistanti dal punto originale
|
||||
// sennò ripeto il conto con meno scostamento
|
||||
if( nTriaOld != nTriaIndex) {
|
||||
if ( nTriaOld != nTriaIndex) {
|
||||
auto iter = find( vnT.begin(), vnT.end(),nTriaIndex) ;
|
||||
int nIdTria = distance( vnT.begin(), iter) ;
|
||||
if( nIdTria > ssize( vnT) - 1) {
|
||||
if ( nIdTria > ssize( vnT) - 1) {
|
||||
ptI2 = ptI + ( ptIPrevOrNext - ptI) * 5 * EPS_SMALL ;
|
||||
DistPointSurfTm dPtStm2( ptI2, *pSurfTm) ;
|
||||
dPtStm2.GetMinDistTriaIndex( nTriaIndex) ;
|
||||
@@ -4059,6 +4059,9 @@ SurfBezier::CreateByFlatContour( const PolyLine& PL)
|
||||
bool
|
||||
SurfBezier::CreateByRegion( const POLYLINEVECTOR& vPL)
|
||||
{
|
||||
// la regione passata è riferita al parametrico di una superficie quadrata.
|
||||
// La superficie viene creata come se fosse una flatregion a partire dai loop passati.
|
||||
|
||||
// le polyline in input devono essere già ordinate per area e orientate con il verso giusto ( tenendo conto di chunk e isole)
|
||||
// la prima polyline quindi è il loop esterno del chunk più grande
|
||||
Plane3d plPlane ;
|
||||
@@ -4126,39 +4129,37 @@ SurfBezier::CreateByRegion( const POLYLINEVECTOR& vPL)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
SurfBezier::CreateByExtrusion( const ICurve* pCrv, const Vector3d& vtExtr, bool bDeg3orDeg2)
|
||||
SurfBezier::CreateByExtrusion( const ICurve* pCrv, const Vector3d& vtExtr)
|
||||
{
|
||||
if ( pCrv == nullptr)
|
||||
return false ;
|
||||
// verifico che la curva passata sia una bezier semplice o una composita di bezier
|
||||
if ( pCrv->GetType() != CRV_COMPO && pCrv->GetType() != CRV_BEZIER)
|
||||
return false ;
|
||||
// se composita verifico che curve siano con lo stesso grado e uniformi come tipo
|
||||
|
||||
CurveComposite CC ;
|
||||
CC.AddCurve( pCrv->Clone()) ;
|
||||
// se composita verifico che curve siano con lo stesso grado e uniformi come tipo
|
||||
bool bRat = false ;
|
||||
int nDegU = 1 ;
|
||||
for ( int i = 0 ; i < CC.GetCurveCount() ; ++i) {
|
||||
if ( CC.GetCurve( i)->GetType() != CRV_BEZIER)
|
||||
return false ;
|
||||
const ICurveBezier* pCrvBez = GetCurveBezier( CC.GetCurve( i)) ;
|
||||
if ( i == 0 ) {
|
||||
bRat = pCrvBez->IsRational() ;
|
||||
nDegU = pCrvBez->GetDegree() ;
|
||||
}
|
||||
else {
|
||||
if ( pCrvBez->GetDegree() != nDegU || pCrvBez->IsRational() != bRat)
|
||||
return false ;
|
||||
int nDegU = 3 ;
|
||||
if ( pCrv->GetType() != CRV_COMPO) {
|
||||
CC.AddCurve( CurveToBezierCurve( pCrv, nDegU, bRat)) ;
|
||||
}
|
||||
else {
|
||||
const ICurveComposite* pCCOrig = GetCurveComposite( pCrv) ;
|
||||
for ( int i = 0 ; i < pCCOrig->GetCurveCount() ; ++i) {
|
||||
if ( pCCOrig->GetCurve( i)->GetType() != CRV_BEZIER)
|
||||
CC.AddCurve( CurveToBezierCurve( pCCOrig->GetCurve(i), nDegU, bRat)) ;
|
||||
else
|
||||
CC.AddCurve( EditBezierCurve( GetCurveBezier( pCCOrig->GetCurve(i)), nDegU, bRat)) ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( CC.GetCurveCount() == 0 || ! CC.IsValid())
|
||||
return false ;
|
||||
|
||||
// riempio la matrice dei punti di controllo
|
||||
// parto dalla curva che sto estrudendo e mi alzo progressivamente seguendo il vettore vtExtr
|
||||
int nDegV = bDeg3orDeg2 ? 3 : 2 ;
|
||||
int nDegV = 1 ;
|
||||
int nSpanU = CC.GetCurveCount() ;
|
||||
int nSpanV = 1 ;
|
||||
Init(nDegU, nDegV, nSpanU, nSpanV, bRat) ;
|
||||
Init( nDegU, nDegV, nSpanU, nSpanV, bRat) ;
|
||||
|
||||
for ( int k = 0 ; k < nSpanU ; ++k) {
|
||||
const ICurveBezier* pCrvBezier = GetCurveBezier( CC.GetCurve( k)) ;
|
||||
@@ -5070,7 +5071,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
if ( j == vMatch1.size())
|
||||
bAdvance1 = false ;
|
||||
// se trovo che ho uno spigolo allora procedo con la gestione spigoli
|
||||
if( vEdgeSplit0[c+1] && vEdgeSplit1[j+1]) {
|
||||
if ( vEdgeSplit0[c+1] && vEdgeSplit1[j+1]) {
|
||||
// se ho uno spigolo su entrambe le curve forzo l'accoppiamento
|
||||
bAdvance0 = true ;
|
||||
bPerfectMatch = true ;
|
||||
@@ -5079,7 +5080,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
ptJoint0 = vPnt1[j+1] ;
|
||||
ptJoint1 = vPnt0[c+1] ;
|
||||
}
|
||||
else if ( (vEdgeSplit0[c+1] && ! bAdvance1) || (vEdgeSplit1[j+1] && ! bAdvance0)) {
|
||||
else if (( vEdgeSplit0[c+1] && ! bAdvance1) || (vEdgeSplit1[j+1] && ! bAdvance0)) {
|
||||
bAdvance0 = false ;
|
||||
bAdvance1 = false ;
|
||||
}
|
||||
@@ -5240,28 +5241,28 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
// bAdvance0 = true ;
|
||||
// bAdvance1 = true ;
|
||||
// int nParam0, nParam1 ;
|
||||
// while( bAdvance0) {
|
||||
// while ( bAdvance0) {
|
||||
// dParam0 = vMatch0[c_temp].second ;
|
||||
// nParam0 = int( round( dParam0)) ;
|
||||
// dParam1 = vMatch1[nParam0].second ;
|
||||
// nParam1 = int( round( dParam1)) ;
|
||||
// if( abs( nParam1 - c_temp) <= 2)
|
||||
// if ( abs( nParam1 - c_temp) <= 2)
|
||||
// bAdvance0 = false ;
|
||||
// else
|
||||
// ++ c_temp ;
|
||||
// }
|
||||
// while( bAdvance1) {
|
||||
// while ( bAdvance1) {
|
||||
// dParam1 = vMatch1[j_temp].second ;
|
||||
// nParam1 = int( round( dParam1)) ;
|
||||
// dParam0 = vMatch0[nParam1].second ;
|
||||
// nParam0 = int( round( dParam0)) ;
|
||||
// if( abs( nParam0 - j_temp) <= 2)
|
||||
// if ( abs( nParam0 - j_temp) <= 2)
|
||||
// bAdvance1 = false ;
|
||||
// else
|
||||
// ++ j_temp ;
|
||||
// }
|
||||
// // se non sono avanzato, allora mi basta accoppiare i due punti in questione
|
||||
// if( c_temp == c || j_temp == j) {
|
||||
// if ( c_temp == c || j_temp == j) {
|
||||
// ++c ;
|
||||
// ++j ;
|
||||
// vPairs.emplace_back( c + nSplit0, j + nSplit1) ;
|
||||
@@ -5291,13 +5292,13 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
// PtrOwner<ICurve> pCC1 ;
|
||||
// int nPointsBetween0 = 0 ;
|
||||
// int nPointsBetween1 = 0 ;
|
||||
// if( bAdvance0 && bAdvance1) {
|
||||
// if ( bAdvance0 && bAdvance1) {
|
||||
// pCC0.Set( CrvU0.CopyParamRange( dLastParamMatch1, c_temp + 1)) ;
|
||||
// pCC1.Set( CrvU1.CopyParamRange( dLastParamMatch0, j_temp + 1)) ;
|
||||
// nPointsBetween0 = c_temp - c ;
|
||||
// nPointsBetween1 = j_temp - j ;
|
||||
// }
|
||||
// else if( bAdvance0){
|
||||
// else if ( bAdvance0) {
|
||||
// pCC0.Set( CrvU0.CopyParamRange( dLastParamMatch1, c_temp + 1)) ;
|
||||
// pCC1.Set( CrvU1.CopyParamRange( dLastParamMatch0, dParam0)) ;
|
||||
// nPointsBetween0 = c_temp - c ;
|
||||
@@ -5305,7 +5306,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
// if ( bIntParam0)
|
||||
// nPointsBetween1 -= 1 ;
|
||||
// }
|
||||
// else if( bAdvance1){
|
||||
// else if ( bAdvance1) {
|
||||
// pCC0.Set( CrvU0.CopyParamRange( dLastParamMatch1, dParam1)) ;
|
||||
// pCC1.Set( CrvU1.CopyParamRange( dLastParamMatch0, j_temp + 1)) ;
|
||||
// nPointsBetween0 = int( dParam1) - ( c + 1) ;
|
||||
@@ -5336,7 +5337,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
// int nJBefore = j ;
|
||||
// //debug
|
||||
// while ( bSplitToAdd) {
|
||||
// if ( c0 > ssize( vdParamPos0) - 1 && c1 > ssize( vdParamPos1) - 1) {
|
||||
// if ( c0 > ssize( vdParamPos0) - 1 && c1 > ssize( vdParamPos1) - 1) {
|
||||
// LOG_DBG_ERR( GetEGkLogger(), "Surf Bez Ruled Guided: error 1 while reparametrizing some section") ;
|
||||
// return false ;
|
||||
// }
|
||||
@@ -5383,13 +5384,13 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
// bSplitToAdd = ! ( c0 == ssize( vdParamPos0) - 1 && c1 == ssize( vdParamPos1) - 1) ;
|
||||
// }
|
||||
// // aggiorno i dati dell'ultima aggiunta
|
||||
// if( bAdvance0 && ! bAdvance1) {
|
||||
// if ( bAdvance0 && ! bAdvance1) {
|
||||
// ptLastPointMatch0 = vMatch0[c_temp].first ;
|
||||
// dLastParamMatch0 = vMatch0[c_temp].second ;
|
||||
// ptLastPointMatch1 = vPnt0[c_temp] ;
|
||||
// dLastParamMatch0 = c_temp ;
|
||||
// }
|
||||
// else if( ! bAdvance0 && bAdvance1) {
|
||||
// else if ( ! bAdvance0 && bAdvance1) {
|
||||
// ptLastPointMatch0 = vPnt1[j_temp] ;
|
||||
// dLastParamMatch0 = j_temp ;
|
||||
// ptLastPointMatch1 = vMatch1[j_temp].first ;
|
||||
@@ -5405,7 +5406,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
// }
|
||||
}
|
||||
}
|
||||
bAdvance = ! (c >= int(vMatch0.size()) - 1 && j >= int(vMatch1.size()) - 1) ;
|
||||
bAdvance = ! ( c >= ssize( vMatch0) - 1 && j >= ssize( vMatch1) - 1) ;
|
||||
}
|
||||
|
||||
// applico effettivamente gli split
|
||||
@@ -5500,7 +5501,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int
|
||||
vector<IGeoObj*> vGeo ;
|
||||
ICURVEPOVECTOR vCrv ;
|
||||
GetAllPatchesIsocurves( false, vCrv) ;
|
||||
for( int i = 0 ; i < ssize( vCrv) ; ++i) {
|
||||
for ( int i = 0 ; i < ssize( vCrv) ; ++i) {
|
||||
vGeo.push_back( vCrv[i]->Clone()) ;
|
||||
}
|
||||
vector<Color> vCol( ssize( vCrv)) ;
|
||||
@@ -5882,8 +5883,8 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c
|
||||
{
|
||||
// vCrv è il vettore delle isocurve (nel parametro V) che si vogliono forzare per la creazione della rigata tra Curve0 e Curve1
|
||||
|
||||
//controllo che siano entrambe chiuse o entrambe aperte
|
||||
if( pCurve0->IsClosed() ^ pCurve1->IsClosed())
|
||||
// controllo che siano entrambe chiuse o entrambe aperte
|
||||
if ( pCurve0->IsClosed() != pCurve1->IsClosed())
|
||||
return false ;
|
||||
|
||||
bool bClosed = pCurve0->IsClosed() ;
|
||||
@@ -5933,8 +5934,9 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c
|
||||
Point3d ptU1 = vCrv[i].second ;
|
||||
double dParam0 ; CrvU0.GetParamAtPoint( ptU0, dParam0) ;
|
||||
double dParam1 ; CrvU1.GetParamAtPoint( ptU1, dParam1) ;
|
||||
if( bClosed && (dParam0 < EPS_SMALL || nSpanU0 - dParam0 < EPS_SMALL) && (dParam1 < EPS_SMALL || nSpanU1 - dParam1 < EPS_SMALL)) {
|
||||
if( ! bFirstAdded) {
|
||||
if ( bClosed && ( dParam0 < EPS_SMALL || nSpanU0 - dParam0 < EPS_SMALL) &&
|
||||
( dParam1 < EPS_SMALL || nSpanU1 - dParam1 < EPS_SMALL)) {
|
||||
if ( ! bFirstAdded) {
|
||||
dParam0 = 0 ;
|
||||
dParam1 = 0 ;
|
||||
bFirstAdded = true ;
|
||||
@@ -5964,7 +5966,7 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c
|
||||
|
||||
dLastParam0 = 0 ;
|
||||
dLastParam1 = 0 ;
|
||||
if( vIso[0].dParam0 > 0 || vIso[0].dParam1 > 0)
|
||||
if ( vIso[0].dParam0 > 0 || vIso[0].dParam1 > 0)
|
||||
vPairs.emplace_back( 0, 0) ;
|
||||
for ( int i = 0 ; i < ssize( vIso) ; ++i) {
|
||||
const BIPOINT& pCrv = vCrv[vIso[i].nCrv] ;
|
||||
@@ -6124,8 +6126,9 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c
|
||||
|
||||
nSpanU0 = CrvU0.GetCurveCount() ;
|
||||
nSpanU1 = CrvU1.GetCurveCount() ;
|
||||
// aggiungo l'ultima coppia
|
||||
vPairs.emplace_back( nSpanU0, nSpanU1) ;
|
||||
// aggiungo l'ultima coppia se necessario
|
||||
if ( vPairs.back().first != nSpanU0 && vPairs.back().second != nSpanU1)
|
||||
vPairs.emplace_back( nSpanU0, nSpanU1) ;
|
||||
|
||||
// trovo il numero di span che dovrà avere la superficie
|
||||
int nSpanU = int(vPairs.size()) - 1 ;
|
||||
@@ -6185,7 +6188,7 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c
|
||||
vector<IGeoObj*> vGeo ;
|
||||
ICURVEPOVECTOR vCrvIso ;
|
||||
GetAllPatchesIsocurves( false, vCrvIso) ;
|
||||
for( int i = 0 ; i < ssize( vCrvIso) ; ++i) {
|
||||
for ( int i = 0 ; i < ssize( vCrvIso) ; ++i) {
|
||||
vGeo.push_back( vCrvIso[i]->Clone()) ;
|
||||
}
|
||||
vector<Color> vCol( ssize( vCrvIso)) ;
|
||||
@@ -6207,36 +6210,36 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
SurfBezier::RemoveCollapsedSpans()
|
||||
SurfBezier::RemoveCollapsedSpans( void)
|
||||
{
|
||||
double dTol = EPS_SMALL ;
|
||||
//controllo se ho delle span collassate e le rimuovo
|
||||
if( m_nSpanU > 1 || m_nSpanV > 1) {
|
||||
if ( m_nSpanU > 1 || m_nSpanV > 1) {
|
||||
CalcPoles() ;
|
||||
if( ! m_vbPole[2]) {
|
||||
if ( ! m_vbPole[2]) {
|
||||
// scorro i punti della prima riga
|
||||
INTVECTOR vnCollapsedSpan ;
|
||||
for( int i = 0 ; i < m_nSpanU ; ++i) {
|
||||
for ( int i = 0 ; i < m_nSpanU ; ++i) {
|
||||
bool bSamePoint = true ;
|
||||
Point3d ptFirst = m_vPtCtrl[m_nDegU * i] ;
|
||||
// cerco se trovo tutti i punti in U coincidenti in una delle Span
|
||||
for( int j = 1 ; j < m_nDegU + 1 && bSamePoint ; ++j) {
|
||||
if( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[m_nDegU * i + j], dTol))
|
||||
for ( int j = 1 ; j < m_nDegU + 1 && bSamePoint ; ++j) {
|
||||
if ( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[m_nDegU * i + j], dTol))
|
||||
bSamePoint = false ;
|
||||
}
|
||||
if( bSamePoint) {
|
||||
if ( bSamePoint) {
|
||||
// se trovo un'altra riga collassata do per scontato che tutta span sia collassata
|
||||
ptFirst = m_vPtCtrl[GetInd( m_nDegU * i, 1)] ;
|
||||
for( int j = 1 ; j < m_nDegU + 1 && bSamePoint ; ++j) {
|
||||
if( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[GetInd( m_nDegU * i + j, 1)], dTol))
|
||||
for ( int j = 1 ; j < m_nDegU + 1 && bSamePoint ; ++j) {
|
||||
if ( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[GetInd( m_nDegU * i + j, 1)], dTol))
|
||||
bSamePoint = false ;
|
||||
}
|
||||
if( bSamePoint)
|
||||
if ( bSamePoint)
|
||||
vnCollapsedSpan.push_back( i) ;
|
||||
}
|
||||
}
|
||||
int nOldSpanU = m_nSpanU ;
|
||||
if( ! vnCollapsedSpan.empty()) {
|
||||
if ( ! vnCollapsedSpan.empty()) {
|
||||
// cancello le span che risultano collassate
|
||||
int nNewSpanU = m_nSpanU - ssize( vnCollapsedSpan) ;
|
||||
int nNewDim = ( m_nDegU * nNewSpanU + 1) * ( m_nDegV * m_nSpanV + 1) ;
|
||||
@@ -6244,21 +6247,21 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
DBLVECTOR vNewWeight( nNewDim) ;
|
||||
int nCurrSkipInd = -1 ;
|
||||
int nCurrSkip = -1 ;
|
||||
for( int nIndV = 0 ; nIndV < m_nSpanV * m_nDegV + 1 ; ++nIndV) {
|
||||
for ( int nIndV = 0 ; nIndV < m_nSpanV * m_nDegV + 1 ; ++nIndV) {
|
||||
nCurrSkipInd = 0 ;
|
||||
nCurrSkip = vnCollapsedSpan[nCurrSkipInd] ;
|
||||
for( int i = 0 ; i < m_nSpanU ; ++i) {
|
||||
if( i != nCurrSkip) {
|
||||
for( int j = ( i - nCurrSkipInd) ==0 ? 0 : 1 ; j < m_nDegU + 1 ; ++j) {
|
||||
for ( int i = 0 ; i < m_nSpanU ; ++i) {
|
||||
if ( i != nCurrSkip) {
|
||||
for ( int j = ( i - nCurrSkipInd) ==0 ? 0 : 1 ; j < m_nDegU + 1 ; ++j) {
|
||||
vNewCtrlPnt[nIndV * ( m_nDegU * nNewSpanU + 1) + (i - nCurrSkipInd) * m_nDegU + j] = m_vPtCtrl[GetInd( m_nDegU * i + j, nIndV)] ;
|
||||
if( m_bRat) {
|
||||
if ( m_bRat) {
|
||||
vNewWeight[nIndV * ( m_nDegU * nNewSpanU + 1) + (i - nCurrSkipInd) * m_nDegU + j] = m_vWeCtrl[GetInd( m_nDegU * i + j, nIndV)] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
++nCurrSkipInd ;
|
||||
if( nCurrSkipInd > ssize( vnCollapsedSpan) - 1)
|
||||
if ( nCurrSkipInd > ssize( vnCollapsedSpan) - 1)
|
||||
nCurrSkip = -1 ;
|
||||
else
|
||||
nCurrSkip = vnCollapsedSpan[nCurrSkipInd] ;
|
||||
@@ -6269,32 +6272,32 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
// vettori dei punti e numero di span
|
||||
ISurfFlatRegion* pSFRTrim = nullptr ;
|
||||
bool bTrimmed = m_bTrimmed ;
|
||||
if( bTrimmed) {
|
||||
if ( bTrimmed) {
|
||||
pSFRTrim = GetTrimRegion() ;
|
||||
m_pTrimReg = nullptr ;
|
||||
}
|
||||
Init( m_nDegU, m_nDegV, nNewSpanU, m_nSpanV, m_bRat) ;
|
||||
m_vPtCtrl = vNewCtrlPnt ;
|
||||
if( m_bRat)
|
||||
if ( m_bRat)
|
||||
m_vWeCtrl = vNewWeight ;
|
||||
if( bTrimmed) {
|
||||
if ( bTrimmed) {
|
||||
// elimino le span di troppo dallo spazio parametrico
|
||||
PtrOwner<ISurfFlatRegion> pNewTrim( pSFRTrim->Clone()) ;
|
||||
for( int i = ssize( vnCollapsedSpan) - 1 ; i >= 0 ; --i) {
|
||||
for ( int i = ssize( vnCollapsedSpan) - 1 ; i >= 0 ; --i) {
|
||||
int nSpan = vnCollapsedSpan[i] ;
|
||||
// tolgo tutta la parte a destra della colonna da togliere
|
||||
PtrOwner<ISurfFlatRegion> pSFRCut ( GetSurfFlatRegionRectangle( ( nOldSpanU - nSpan) * SBZ_TREG_COEFF, m_nSpanV * SBZ_TREG_COEFF + 2)) ;
|
||||
if( nSpan != 0) {
|
||||
if ( nSpan != 0) {
|
||||
pSFRCut->Translate( Vector3d( nSpan * SBZ_TREG_COEFF, -1)) ;
|
||||
pNewTrim->Subtract( *pSFRCut) ;
|
||||
}
|
||||
if( pNewTrim->IsValid()) {
|
||||
if ( pNewTrim->IsValid()) {
|
||||
// ritaglio dal parametrico originale la parte a destra della colonna da eliminare e la incollo alla parte a sinistra
|
||||
PtrOwner<ISurfFlatRegion> pRightPart( pSFRTrim->Clone()) ;
|
||||
pSFRCut.Set( GetSurfFlatRegionRectangle( ( nSpan + 1) * SBZ_TREG_COEFF, m_nSpanV * SBZ_TREG_COEFF + 2)) ;
|
||||
pSFRCut->Translate( Vector3d( nSpan * SBZ_TREG_COEFF, -1)) ;
|
||||
if( pRightPart->Subtract( *pSFRCut) && pRightPart->IsValid()) {
|
||||
if( ! pNewTrim->Add( *pRightPart) || ! pNewTrim->IsValid())
|
||||
if ( pRightPart->Subtract( *pSFRCut) && pRightPart->IsValid()) {
|
||||
if ( ! pNewTrim->Add( *pRightPart) || ! pNewTrim->IsValid())
|
||||
break ;
|
||||
}
|
||||
}
|
||||
@@ -6306,30 +6309,30 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
}
|
||||
}
|
||||
|
||||
if( ! m_vbPole[1]) {
|
||||
if ( ! m_vbPole[1]) {
|
||||
// scorro i punti della prima colonna
|
||||
INTVECTOR vnCollapsedSpan ;
|
||||
for( int i = 0 ; i < m_nSpanV ; ++i) {
|
||||
for ( int i = 0 ; i < m_nSpanV ; ++i) {
|
||||
bool bSamePoint = true ;
|
||||
Point3d ptFirst = m_vPtCtrl[GetInd( 0, i * m_nDegV)] ;
|
||||
// cerco se trovo tutti i punti in U coincidenti in una delle Span
|
||||
for( int j = 1 ; j < m_nDegV + 1 && bSamePoint ; ++j) {
|
||||
if( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[GetInd( 0, i * m_nDegV + j)], dTol))
|
||||
for ( int j = 1 ; j < m_nDegV + 1 && bSamePoint ; ++j) {
|
||||
if ( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[GetInd( 0, i * m_nDegV + j)], dTol))
|
||||
bSamePoint = false ;
|
||||
}
|
||||
if( bSamePoint) {
|
||||
if ( bSamePoint) {
|
||||
// se trovo un'altra colonna collassata do per scontato che tutta span sia collassata
|
||||
ptFirst = m_vPtCtrl[GetInd( 1, i * m_nDegV)] ;
|
||||
for( int j = 1 ; j < m_nDegV + 1 && bSamePoint ; ++j) {
|
||||
if( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[GetInd( 1, i * m_nDegV + j)], dTol))
|
||||
for ( int j = 1 ; j < m_nDegV + 1 && bSamePoint ; ++j) {
|
||||
if ( ! AreSamePointEpsilon( ptFirst, m_vPtCtrl[GetInd( 1, i * m_nDegV + j)], dTol))
|
||||
bSamePoint = false ;
|
||||
}
|
||||
if( bSamePoint)
|
||||
if ( bSamePoint)
|
||||
vnCollapsedSpan.push_back( i) ;
|
||||
}
|
||||
}
|
||||
int nOldSpanV = m_nSpanV ;
|
||||
if( ! vnCollapsedSpan.empty()) {
|
||||
if ( ! vnCollapsedSpan.empty()) {
|
||||
// cancello le span che risultano collassate
|
||||
int nNewSpanV = m_nSpanV - ssize( vnCollapsedSpan) ;
|
||||
int nNewDim = ( m_nDegU * m_nSpanU + 1) * ( m_nDegV * nNewSpanV + 1) ;
|
||||
@@ -6337,12 +6340,12 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
DBLVECTOR vNewWeight( nNewDim) ;
|
||||
int nCurrSkipInd = 0 ;
|
||||
int nCurrSkip = vnCollapsedSpan[nCurrSkipInd] ;
|
||||
for( int nIndV = 0 ; nIndV < m_nSpanV * m_nDegV + 1 ; ++nIndV) {
|
||||
if( nIndV / m_nDegV != nCurrSkip) {
|
||||
for( int i = 0 ; i < m_nSpanU ; ++i) {
|
||||
for( int j = i==0 ? 0 : 1 ; j < m_nDegU + 1 ; ++j) {
|
||||
for ( int nIndV = 0 ; nIndV < m_nSpanV * m_nDegV + 1 ; ++nIndV) {
|
||||
if ( nIndV / m_nDegV != nCurrSkip) {
|
||||
for ( int i = 0 ; i < m_nSpanU ; ++i) {
|
||||
for ( int j = i==0 ? 0 : 1 ; j < m_nDegU + 1 ; ++j) {
|
||||
vNewCtrlPnt[( nIndV - ( nCurrSkipInd * m_nDegV)) * ( m_nDegU * m_nSpanU + 1) + i * m_nDegU + j] = m_vPtCtrl[GetInd( m_nDegU * i + j, nIndV)] ;
|
||||
if( m_bRat) {
|
||||
if ( m_bRat) {
|
||||
vNewWeight[( nIndV - ( nCurrSkipInd * m_nDegV)) * ( m_nDegU * m_nSpanU + 1) + i * m_nDegU + j] = m_vWeCtrl[GetInd( m_nDegU * i + j, nIndV)] ;
|
||||
}
|
||||
}
|
||||
@@ -6351,7 +6354,7 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
else {
|
||||
nIndV += m_nDegV - 1 ;
|
||||
++nCurrSkipInd ;
|
||||
if( nCurrSkipInd > ssize( vnCollapsedSpan) - 1)
|
||||
if ( nCurrSkipInd > ssize( vnCollapsedSpan) - 1)
|
||||
nCurrSkip = -1 ;
|
||||
else
|
||||
nCurrSkip = vnCollapsedSpan[nCurrSkipInd] ;
|
||||
@@ -6361,32 +6364,32 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
// vettori dei punti e numero di span
|
||||
ISurfFlatRegion* pSFRTrim = nullptr ;
|
||||
bool bTrimmed = m_bTrimmed ;
|
||||
if( bTrimmed) {
|
||||
if ( bTrimmed) {
|
||||
pSFRTrim = GetTrimRegion() ;
|
||||
m_pTrimReg = nullptr ;
|
||||
}
|
||||
Init( m_nDegU, m_nDegV, m_nSpanU, nNewSpanV, m_bRat) ;
|
||||
m_vPtCtrl = vNewCtrlPnt ;
|
||||
if( m_bRat)
|
||||
if ( m_bRat)
|
||||
m_vWeCtrl = vNewWeight ;
|
||||
if( bTrimmed) {
|
||||
if ( bTrimmed) {
|
||||
// elimino le span di troppo dallo spazio parametrico
|
||||
PtrOwner<ISurfFlatRegion> pNewTrim( pSFRTrim->Clone()) ;
|
||||
for( int i = ssize( vnCollapsedSpan) - 1 ; i >= 0 ; --i) {
|
||||
for ( int i = ssize( vnCollapsedSpan) - 1 ; i >= 0 ; --i) {
|
||||
int nSpan = vnCollapsedSpan[i] ;
|
||||
// tolgo tutta la parte a sopra la riga da togliere
|
||||
PtrOwner<ISurfFlatRegion> pSFRCut ( GetSurfFlatRegionRectangle( m_nSpanU * SBZ_TREG_COEFF + 2, ( nOldSpanV - nSpan) * SBZ_TREG_COEFF)) ;
|
||||
if( nSpan != 0) {
|
||||
if ( nSpan != 0) {
|
||||
pSFRCut->Translate( Vector3d( -1, nSpan * SBZ_TREG_COEFF)) ;
|
||||
pNewTrim->Subtract( *pSFRCut) ;
|
||||
}
|
||||
if( pNewTrim->IsValid()) {
|
||||
if ( pNewTrim->IsValid()) {
|
||||
// ritaglio dal parametrico originale la parte sopra la riga da eliminare e la incollo alla parte sotto la riga
|
||||
PtrOwner<ISurfFlatRegion> pUpperPart( pSFRTrim->Clone()) ;
|
||||
pSFRCut.Set( GetSurfFlatRegionRectangle( m_nSpanU * SBZ_TREG_COEFF + 2, ( nSpan + 1) * SBZ_TREG_COEFF)) ;
|
||||
pSFRCut->Translate( Vector3d( -1, nSpan * SBZ_TREG_COEFF)) ;
|
||||
if( pUpperPart->Subtract( *pSFRCut) && pUpperPart->IsValid()) {
|
||||
if( ! pNewTrim->Add( *pUpperPart) || ! pNewTrim->IsValid())
|
||||
if ( pUpperPart->Subtract( *pSFRCut) && pUpperPart->IsValid()) {
|
||||
if ( ! pNewTrim->Add( *pUpperPart) || ! pNewTrim->IsValid())
|
||||
break ;
|
||||
}
|
||||
}
|
||||
@@ -6404,7 +6407,7 @@ SurfBezier::RemoveCollapsedSpans()
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
SurfBezier::SwapParameters()
|
||||
SurfBezier::SwapParameters( void)
|
||||
{
|
||||
// inverto il parametro U con il parametro V
|
||||
// salvo i vecchi dati
|
||||
@@ -6414,7 +6417,7 @@ SurfBezier::SwapParameters()
|
||||
int nDegV = m_nDegU ;
|
||||
bool bTrimmed = m_bTrimmed ;
|
||||
PtrOwner<ISurfFlatRegion> pSFRTRim ;
|
||||
if( m_bTrimmed) {
|
||||
if ( m_bTrimmed) {
|
||||
pSFRTRim.Set( GetTrimRegion()) ;
|
||||
m_pTrimReg = nullptr ;
|
||||
}
|
||||
@@ -6422,16 +6425,16 @@ SurfBezier::SwapParameters()
|
||||
// creo il vettore dei punti di controllo
|
||||
PNTVECTOR vNewCtrlPt( GetDim()) ;
|
||||
DBLVECTOR vNewWeight( GetDim()) ;
|
||||
for( int j = 0 ; j < m_nDegV * m_nSpanV + 1 ; ++j) {
|
||||
for( int i = 0 ; i < m_nDegU * m_nSpanU + 1 ; ++ i) {
|
||||
for ( int j = 0 ; j < m_nDegV * m_nSpanV + 1 ; ++j) {
|
||||
for ( int i = 0 ; i < m_nDegU * m_nSpanU + 1 ; ++ i) {
|
||||
vNewCtrlPt[i * ( nDegU * nSpanU + 1) + j] = m_vPtCtrl[GetInd(i,j)] ;
|
||||
if( m_bRat)
|
||||
if ( m_bRat)
|
||||
vNewWeight[i * ( nDegU * nSpanU + 1) + j] = m_vWeCtrl[GetInd(i,j)] ;
|
||||
}
|
||||
}
|
||||
|
||||
Init( nDegU, nDegV, nSpanU, nSpanV, m_bRat) ;
|
||||
if( bTrimmed) {
|
||||
if ( bTrimmed) {
|
||||
pSFRTRim->Mirror( ORIG, Vector3d(1,-1)) ;
|
||||
SetTrimRegion( *pSFRTRim) ;
|
||||
}
|
||||
@@ -6439,4 +6442,4 @@ SurfBezier::SwapParameters()
|
||||
m_vWeCtrl = vNewWeight ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -116,7 +116,7 @@ class SurfBezier : public ISurfBezier, public IGeoObjRW
|
||||
bool GetControlCurveOnV( int nIndU, PolyLine& plCtrlV) const override ;
|
||||
const SurfTriMesh* GetAuxSurf( void) const override ;
|
||||
const SurfTriMesh* GetAuxSurfRefined( void) const override ;
|
||||
SurfTriMesh* GetApproxSurf( double dTol, double dSideMin = 100 * EPS_SMALL, bool bUpdateEdges = false) const override ;
|
||||
SurfTriMesh* GetApproxSurf( double dTol, double dSideMin = 10 * EPS_SMALL, bool bUpdateEdges = false) const override ;
|
||||
// funzione per ottenere la suddivisione dello spazio parametrico nelle celle utilizzate per la triangolazione.
|
||||
bool GetLeaves( std::vector<std::tuple<int, Point3d, Point3d>>& vLeaves) const override ;
|
||||
bool GetTriangles2D( std::vector<std::tuple<int,Point3d, Point3d, Point3d>>& vTria2D) const override ;
|
||||
@@ -143,7 +143,7 @@ class SurfBezier : public ISurfBezier, public IGeoObjRW
|
||||
bool IsPlanar( void) const override ;
|
||||
bool CreateByFlatContour( const PolyLine& PL) override ;
|
||||
bool CreateByRegion( const POLYLINEVECTOR& vPL) override ;
|
||||
bool CreateByExtrusion( const ICurve* pCurve, const Vector3d& vtExtr, bool bDeg3OrDeg2 = false) override ;
|
||||
bool CreateByExtrusion( const ICurve* pCurve, const Vector3d& vtExtr) override ;
|
||||
bool CreateByScrewing( const ICurve* pCurve, const Point3d& ptAx, const Vector3d& vtAx, double dAngRotDeg, double dMove) override ;
|
||||
bool CreateByPointCurve( const Point3d& pt, const ICurve* pCurve) override ;
|
||||
bool CreateByTwoCurves( const ICurve* pCurve1, const ICurve* pCurve2, int nType) override ;
|
||||
@@ -151,8 +151,8 @@ class SurfBezier : public ISurfBezier, public IGeoObjRW
|
||||
PNTVECTOR GetAllControlPoints( void) const ;
|
||||
bool GetAllPatchesIsocurves( bool bUorV, ICURVEPOVECTOR& vCrv) const ;
|
||||
bool CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, const BIPNTVECTOR& vCrv) ;
|
||||
bool RemoveCollapsedSpans() override ;
|
||||
bool SwapParameters() ;
|
||||
bool RemoveCollapsedSpans( void) override ;
|
||||
bool SwapParameters( void) ;
|
||||
|
||||
public : // IGeoObjRW
|
||||
int GetNgeId( void) const override ;
|
||||
|
||||
@@ -36,25 +36,25 @@ class Tool
|
||||
bool SetAdditiveTool( const std::string& sToolName, double dH, double dR, double dRc, int nToolNum) ;
|
||||
bool SetToolNum( int nToolNum)
|
||||
{ m_nCurrentNum = nToolNum ; return true ; }
|
||||
int GetType() const
|
||||
int GetType( void) const
|
||||
{ return m_nType ; }
|
||||
int GetToolNum() const
|
||||
int GetToolNum( void) const
|
||||
{ return m_nCurrentNum ; }
|
||||
double GetHeigth() const
|
||||
double GetHeigth( void) const
|
||||
{ return m_dHeight ; }
|
||||
double GetTipHeigth() const
|
||||
double GetTipHeigth( void) const
|
||||
{ return m_dTipHeight ; }
|
||||
double GetRadius() const
|
||||
double GetRadius( void) const
|
||||
{ return m_dRadius ; }
|
||||
double GetTipRadius() const
|
||||
double GetTipRadius( void) const
|
||||
{ return m_dTipRadius ; }
|
||||
double GetCornRadius() const
|
||||
double GetCornRadius( void) const
|
||||
{ return m_dRCorner ; }
|
||||
double GetRefRadius() const
|
||||
double GetRefRadius( void) const
|
||||
{ return m_dRefRadius ; }
|
||||
double GetMrtChsWidth() const
|
||||
double GetMrtChsWidth( void) const
|
||||
{ return m_dMrtChsWidth ; }
|
||||
double GetMrtChsThickness() const
|
||||
double GetMrtChsThickness( void) const
|
||||
{ return m_dMrtChsThickness ; }
|
||||
const CurveComposite& GetOutline( void) const
|
||||
{ return ( m_Outline) ; }
|
||||
|
||||
@@ -461,8 +461,8 @@ Tree::Split( int nId, double dSplitValue)
|
||||
dSplitValue < cToSplit.GetTopRight().y - 10 * EPS_SMALL ;
|
||||
Point3d ptP00, ptP01, ptP10, ptP11 ;
|
||||
|
||||
if( bGoodSplitVert) {
|
||||
if( cToSplit.GetBottomRight().x - dSplitValue > dSplitValue - cToSplit.GetBottomLeft().x) {
|
||||
if ( bGoodSplitVert) {
|
||||
if ( cToSplit.GetBottomRight().x - dSplitValue > dSplitValue - cToSplit.GetBottomLeft().x) {
|
||||
GetPoint( cToSplit.GetBottomLeft().x, cToSplit.GetBottomLeft().y, ptP00) ;
|
||||
GetPoint( dSplitValue, cToSplit.GetBottomRight().y, ptP10) ;
|
||||
GetPoint( cToSplit.GetTopLeft().x, cToSplit.GetTopLeft().y, ptP01) ;
|
||||
@@ -474,12 +474,13 @@ Tree::Split( int nId, double dSplitValue)
|
||||
GetPoint( dSplitValue, cToSplit.GetTopLeft().y, ptP01) ;
|
||||
GetPoint( cToSplit.GetTopRight().x, cToSplit.GetTopRight().y, ptP11) ;
|
||||
}
|
||||
if( AreSamePointApprox( ptP00, ptP10) && AreSamePointApprox( ptP01, ptP11) &&
|
||||
( cToSplit.GetBottomRight().x - dSplitValue < SBZ_TREG_COEFF - EPS_SMALL || dSplitValue - cToSplit.GetBottomLeft().x < SBZ_TREG_COEFF - EPS_SMALL))
|
||||
if ( AreSamePointApprox( ptP00, ptP10) && AreSamePointApprox( ptP01, ptP11) &&
|
||||
( cToSplit.GetBottomRight().x - dSplitValue < SBZ_TREG_COEFF - EPS_SMALL ||
|
||||
dSplitValue - cToSplit.GetBottomLeft().x < SBZ_TREG_COEFF - EPS_SMALL))
|
||||
bGoodSplitVert = false ;
|
||||
}
|
||||
if( bGoodSplitHoriz) {
|
||||
if( cToSplit.GetTopLeft().y - dSplitValue > dSplitValue - cToSplit.GetBottomLeft().y) {
|
||||
if ( bGoodSplitHoriz) {
|
||||
if ( cToSplit.GetTopLeft().y - dSplitValue > dSplitValue - cToSplit.GetBottomLeft().y) {
|
||||
GetPoint( cToSplit.GetBottomLeft().x, cToSplit.GetBottomLeft().y, ptP00) ;
|
||||
GetPoint( cToSplit.GetBottomRight().x, cToSplit.GetBottomRight().y, ptP10) ;
|
||||
GetPoint( cToSplit.GetTopLeft().x, dSplitValue, ptP01) ;
|
||||
@@ -491,8 +492,9 @@ Tree::Split( int nId, double dSplitValue)
|
||||
GetPoint( cToSplit.GetTopLeft().x, cToSplit.GetTopLeft().y, ptP01) ;
|
||||
GetPoint( cToSplit.GetTopRight().x, cToSplit.GetTopRight().y, ptP11) ;
|
||||
}
|
||||
if( AreSamePointApprox( ptP00, ptP01) && AreSamePointApprox( ptP10, ptP11) &&
|
||||
( cToSplit.GetTopLeft().y - dSplitValue < SBZ_TREG_COEFF - EPS_SMALL || dSplitValue - cToSplit.GetBottomLeft().y < SBZ_TREG_COEFF - EPS_SMALL))
|
||||
if ( AreSamePointApprox( ptP00, ptP01) && AreSamePointApprox( ptP10, ptP11) &&
|
||||
( cToSplit.GetTopLeft().y - dSplitValue < SBZ_TREG_COEFF - EPS_SMALL ||
|
||||
dSplitValue - cToSplit.GetBottomLeft().y < SBZ_TREG_COEFF - EPS_SMALL))
|
||||
bGoodSplitHoriz = false ;
|
||||
}
|
||||
|
||||
@@ -662,8 +664,18 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax)
|
||||
}
|
||||
}
|
||||
|
||||
// calcolo se la parte di superficie nella cella è piatta
|
||||
PolyLine PL ;
|
||||
PL.AddUPoint( 0, ptP00) ;
|
||||
PL.AddUPoint( 1, ptP10) ;
|
||||
PL.AddUPoint( 2, ptP11) ;
|
||||
PL.AddUPoint( 3, ptP01) ;
|
||||
PL.AddUPoint( 4, ptCen) ;
|
||||
Plane3d plPlane ;
|
||||
bool bIsFlat = PL.IsFlat( plPlane, dLinTol) ;
|
||||
|
||||
// su isoparametriche in U e V
|
||||
if ( dSagU < dLinTol && dSagV < dLinTol) {
|
||||
if ( dSagU < dLinTol && dSagV < dLinTol && ! bIsFlat) {
|
||||
// step di verifica in U e in V
|
||||
int nStepU = ( dLenParU > 1. / m_nDegU ? m_nDegU + 1 : 2) ;
|
||||
int nStepV = ( dLenParV > 1. / m_nDegV ? m_nDegV + 1 : 2) ;
|
||||
@@ -724,6 +736,73 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax)
|
||||
//{ string sLog = " Da Isoparam : FrecciaU=" + ToString( dSagU, 3) + " FrecciaV=" + ToString( dSagV, 3) ;
|
||||
// LOG_DBG_INFO( GetEGkLogger(), sLog.c_str())}
|
||||
}
|
||||
else if ( dSagU < dLinTol && dSagV < dLinTol && bIsFlat) {
|
||||
// se la cella è piatta devo verificare che i bordi siano dei tratti retti, altrimenti potrei commettere un errore di approssimazione
|
||||
|
||||
// bordo inferiore e superiore
|
||||
double dMaxDist = 0 ;
|
||||
for ( int i = 0 ; i < 2 ; ++i) {
|
||||
CurveLine clU ;
|
||||
if ( i == 0)
|
||||
clU.Set( ptP00, ptP10) ;
|
||||
else if ( i == 1)
|
||||
clU.Set( ptP01, ptP11) ;
|
||||
double dV = 0 ;
|
||||
if ( i == 0)
|
||||
dV = pcToSplit->GetBottomLeft().y ;
|
||||
else if ( i == 1)
|
||||
dV = pcToSplit->GetTopRight().y ;
|
||||
|
||||
|
||||
int nStepU = 4 ;
|
||||
for ( int j = 1 ; j < nStepU ; ++ j) {
|
||||
// parametro U
|
||||
double dCoeffU = double( j) / nStepU ;
|
||||
double dU = ( 1 - dCoeffU) * pcToSplit->GetBottomLeft().x + dCoeffU * pcToSplit->GetTopRight().x ;
|
||||
Point3d ptBez ;
|
||||
GetPoint( dU, dV, ptBez) ;
|
||||
DistPointCurve dpc( ptBez, clU) ;
|
||||
double dDist = 0 ;
|
||||
dpc.GetDist( dDist) ;
|
||||
if ( dDist > dMaxDist)
|
||||
dMaxDist = dDist ;
|
||||
}
|
||||
}
|
||||
if ( dMaxDist > dLinTol)
|
||||
dSagU = dMaxDist ;
|
||||
|
||||
// bordo sinistro e destro
|
||||
dMaxDist = 0 ;
|
||||
for ( int i = 0 ; i < 2 ; ++i) {
|
||||
CurveLine clV ;
|
||||
if ( i == 0)
|
||||
clV.Set( ptP00, ptP01) ;
|
||||
else if ( i == 1)
|
||||
clV.Set( ptP10, ptP11) ;
|
||||
double dU = 0 ;
|
||||
if ( i == 0)
|
||||
dU = pcToSplit->GetBottomLeft().x ;
|
||||
else if ( i == 1)
|
||||
dU = pcToSplit->GetTopRight().x ;
|
||||
|
||||
int nStepV = 4 ;
|
||||
for ( int j = 1 ; j < nStepV ; ++ j) {
|
||||
// parametro in V
|
||||
double dCoeffV = double( j) / nStepV ;
|
||||
double dV = ( 1 - dCoeffV) * pcToSplit->GetBottomLeft().y + dCoeffV * pcToSplit->GetTopRight().y ;
|
||||
Point3d ptBez ;
|
||||
GetPoint( dU, dV, ptBez) ;
|
||||
DistPointCurve dpc( ptBez, clV) ;
|
||||
double dDist = 0 ;
|
||||
dpc.GetDist( dDist) ;
|
||||
if ( dDist > dMaxDist)
|
||||
dMaxDist = dDist ;
|
||||
}
|
||||
}
|
||||
if ( dMaxDist > dLinTol)
|
||||
dSagV = dMaxDist ;
|
||||
}
|
||||
|
||||
|
||||
// per lo split scelgo la direzione che è più vicina alla superficie originale nel punto di maggior distanza
|
||||
// misura approssimativa della curvatura in una direzione
|
||||
@@ -734,7 +813,8 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax)
|
||||
bVert = false ;
|
||||
else
|
||||
bVert = ( dSagV <= dSagU) ;
|
||||
pcToSplit->SetSplitDirVert( bVert) ;
|
||||
bool bFirstTry = true ;
|
||||
retry :
|
||||
// verifico che la cella sia da splittare e che eventualmente sia abbastanza grande da poterlo fare
|
||||
double dSideMinVal = 0 ;
|
||||
double dLengMinVal = 0 ;
|
||||
@@ -776,6 +856,11 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax)
|
||||
}
|
||||
else if ( dSagV > dLinTol || dSagU > dLinTol) {
|
||||
bSplit = bDimOk ;
|
||||
if ( ! bSplit && bFirstTry) {
|
||||
bFirstTry = false ;
|
||||
bVert = ! bVert ;
|
||||
goto retry ;
|
||||
}
|
||||
//if ( bSplit)
|
||||
// LOG_DBG_INFO( GetEGkLogger(), " Split by SagittaUV")
|
||||
}
|
||||
@@ -1455,7 +1540,7 @@ Tree::GetPolygons( POLYLINEMATRIX& vvPolygons, POLYLINEMATRIX& vvPolygons3d, vec
|
||||
++ nPolyInd ;
|
||||
continue ;
|
||||
}
|
||||
else if( m_mTree[nId].m_nCollapsed != Cell::Collapsed::NO_COLLAPSE)
|
||||
else if ( m_mTree[nId].m_nCollapsed != Cell::Collapsed::NO_COLLAPSE)
|
||||
continue ;
|
||||
else {
|
||||
// vettore in cui salvo il chunk di appartenenza di ogni loop che attraversa la cella
|
||||
@@ -1980,7 +2065,7 @@ Tree::FindCell( const Point3d& ptToAssign, const CurveLine& cl, INTVECTOR vCells
|
||||
nCells.push_back( nCell) ;
|
||||
nEdge = -2 ;
|
||||
}
|
||||
if( ssize( nCells) == 1)
|
||||
if ( ssize( nCells) == 1)
|
||||
return nCells ;
|
||||
|
||||
Vector3d vtDir ;
|
||||
@@ -2009,14 +2094,14 @@ Tree::FindCell( const Point3d& ptToAssign, const CurveLine& cl, INTVECTOR vCells
|
||||
if ( abs(vtDir.x) < 1 - EPS_SMALL/100 && abs(vtDir.y) < 1 - EPS_SMALL/100 )
|
||||
ptIntersPlus = ptIntersPlus + vtDir * EPS_SMALL ;
|
||||
// altrimenti ruoto a destra
|
||||
else if( ( nEdge == 4 && vtDir.x > 1 - EPS_SMALL / 100) || ( nEdge == 6 && vtDir.x < - 1 + EPS_SMALL / 100) ||
|
||||
else if (( nEdge == 4 && vtDir.x > 1 - EPS_SMALL / 100) || ( nEdge == 6 && vtDir.x < - 1 + EPS_SMALL / 100) ||
|
||||
( nEdge == 5 && vtDir.y > 1 - EPS_SMALL / 100) || ( nEdge == 7 && vtDir.y < - 1 + EPS_SMALL / 100)) {
|
||||
Vector3d vtDirDX = vtDir ; vtDirDX.Rotate( Z_AX, -45) ;
|
||||
ptIntersPlus = ptIntersPlus + vtDirDX * EPS_SMALL ;
|
||||
}
|
||||
// altrimenti ruoto a sinistra
|
||||
else /*if( ( nEdge == 4 && vtDir.y < - 1 + EPS_SMALL / 100) || ( nEdge == 6 && vtDir.y < 1 - EPS_SMALL / 100) ||
|
||||
( nEdge == 5 && vtDir.x > 1 - EPS_SMALL / 100) || ( nEdge == 7 && vtDir.x < - 1 + EPS_SMALL / 100)) // + tutti gli altri casi */ {
|
||||
else /*if (( nEdge == 4 && vtDir.y < - 1 + EPS_SMALL / 100) || ( nEdge == 6 && vtDir.y < 1 - EPS_SMALL / 100) ||
|
||||
( nEdge == 5 && vtDir.x > 1 - EPS_SMALL / 100) || ( nEdge == 7 && vtDir.x < - 1 + EPS_SMALL / 100)) // + tutti gli altri casi */ {
|
||||
Vector3d vtDirDX = vtDir ; vtDirDX.Rotate( Z_AX, 45) ;
|
||||
ptIntersPlus = ptIntersPlus + vtDirDX * EPS_SMALL ;
|
||||
}
|
||||
@@ -2138,7 +2223,7 @@ Tree::TraceLoopLabelCell( const POLYLINEVECTOR& vplPolygons)
|
||||
bool bLoopInside = true ;
|
||||
Point3d ptCurr ;
|
||||
int nIdPolygon = - 1;
|
||||
if( ! pCell->m_vnPolyId.empty())
|
||||
if ( ! pCell->m_vnPolyId.empty())
|
||||
nIdPolygon = pCell->m_vnPolyId[0] ;
|
||||
else
|
||||
return false ;
|
||||
@@ -2178,9 +2263,9 @@ Tree::TraceLoopLabelCell( const POLYLINEVECTOR& vplPolygons)
|
||||
}
|
||||
// se l'intersezione e la stessa della precedente allora potrei essere entrato in un loop infinito
|
||||
// se per più volte il punto di intersezione resta più o meno lo stesso allora blocco tutto
|
||||
if( AreSamePointEpsilon( vptInters.back(), ptLastInters, 10 * EPS_SMALL)) {
|
||||
if ( AreSamePointEpsilon( vptInters.back(), ptLastInters, 10 * EPS_SMALL)) {
|
||||
++ nInfiniteLoopCount ;
|
||||
if( nInfiniteLoopCount == 4) {
|
||||
if ( nInfiniteLoopCount == 4) {
|
||||
LOG_ERROR( GetEGkLogger(), "Error Triangulating SurfBezier: infinte while loop occured in Tree::TraceLoopLabelCell")
|
||||
return false ;
|
||||
}
|
||||
@@ -2189,7 +2274,7 @@ Tree::TraceLoopLabelCell( const POLYLINEVECTOR& vplPolygons)
|
||||
// aggiorno il puntatore alla cella
|
||||
pCell = &m_mTree[nId] ;
|
||||
// recupero l'indice del poligono base associato alla cella
|
||||
if( ! pCell->m_vnPolyId.empty())
|
||||
if ( ! pCell->m_vnPolyId.empty())
|
||||
nIdPolygon = pCell->m_vnPolyId[0] ;
|
||||
else
|
||||
return false ;
|
||||
@@ -4025,7 +4110,8 @@ Tree::OnWhichEdge( int nId, const Point3d& ptToAssign, int& nEdge) const
|
||||
Point3d ptTl ( ptBL.x, ptTR.y) ;
|
||||
Point3d ptBr ( ptTR.x, ptBL.y) ;
|
||||
|
||||
if( ptToAssign.y < ptBL.y - EPS_SMALL || ptToAssign.y > ptTR.y + EPS_SMALL || ptToAssign.x < ptBL.x - EPS_SMALL || ptToAssign.x > ptTR.x + EPS_SMALL)
|
||||
if ( ptToAssign.y < ptBL.y - EPS_SMALL || ptToAssign.y > ptTR.y + EPS_SMALL ||
|
||||
ptToAssign.x < ptBL.x - EPS_SMALL || ptToAssign.x > ptTR.x + EPS_SMALL)
|
||||
return false ;
|
||||
else if ( AreSamePointXYApprox( ptToAssign, ptTR))
|
||||
nEdge = 7 ;
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include <utility>
|
||||
|
||||
struct PairHashInt64 {
|
||||
size_t operator()(const std::pair<int64_t, int64_t>& key) const {
|
||||
size_t
|
||||
operator()( const std::pair<int64_t, int64_t>& key) const {
|
||||
size_t h1 = std::hash<int64_t>{}(key.first) ;
|
||||
size_t h2 = std::hash<int64_t>{}(key.second) ;
|
||||
return h1 ^ (h2 << 1); // Combine hashes
|
||||
@@ -33,14 +34,20 @@ struct PairHashInt64 {
|
||||
//----------------------------------------------------------------------------
|
||||
struct Inters {
|
||||
int nIn ;
|
||||
PNTVECTOR vpt ;
|
||||
int nOut ;
|
||||
PNTVECTOR vpt ;
|
||||
bool bCCW ;
|
||||
int nChunk ;
|
||||
bool bSortedbyStart ;
|
||||
// riordino le intersezioni per lato in senso antiorario dal top
|
||||
// se ho più intersezioni che entrano in un lato le riordino considerando che percorro i lati in senso antiorario a partire da ptTR
|
||||
bool operator < ( Inters& b)
|
||||
|
||||
// nIn e nOut sono flag che indicano da quale lato ho l'ingresso e l'uscita a partire dal lato top in senso antiorario
|
||||
// oltre il 3 sono le celle adiacenti in diagonale al vertice-> 4 corrisponde al ptTl e da lì in senso antiorario
|
||||
// -1 se la curva è sempre dentro la cella
|
||||
|
||||
// riordino le intersezioni per lato in senso antiorario dal top
|
||||
// se ho più intersezioni che entrano in un lato le riordino considerando che percorro i lati in senso antiorario a partire da ptTR
|
||||
bool
|
||||
operator < ( Inters& b)
|
||||
{
|
||||
// trovo in che ordine stanno i due start, tenendo conto anche della possibilità che siano vertici
|
||||
INTVECTOR vEdges = { 7, 0, 4, 1, 5, 2, 6, 3} ;
|
||||
@@ -75,7 +82,8 @@ struct Inters {
|
||||
( bEqIn && nEdgeIn == 3 && vpt[0].y < b.vpt[0].y)) ;
|
||||
}
|
||||
|
||||
static bool FirstEncounter( Inters& a, Inters& b)
|
||||
static bool
|
||||
FirstEncounter( Inters& a, Inters& b)
|
||||
{
|
||||
// riordino in base al lato toccato, o dall'uscita o dall'ingresso, che viene prima.
|
||||
// ottengo l'ordine che avrei percorrendo il bordo da ptTR e considerando i loop che incontro, indipendentemente se li incontro nel punto di uscita o ingresso
|
||||
@@ -135,18 +143,18 @@ struct Inters {
|
||||
( nPos1 == 3 && a.vpt[nFirstA].y < b.vpt[nFirstB].y) ;
|
||||
}
|
||||
|
||||
bool operator == ( Inters& b)
|
||||
bool
|
||||
operator == ( Inters& b)
|
||||
{
|
||||
return AreSamePointExact( vpt[0], b.vpt[0]) ;
|
||||
}
|
||||
bool operator != ( Inters& b)
|
||||
|
||||
bool
|
||||
operator != ( Inters& b)
|
||||
{
|
||||
return ! AreSamePointExact( vpt[0], b.vpt[0]) ;
|
||||
}
|
||||
} ;
|
||||
// nIn e nOut sono flag che indicano da quale lato ho l'ingresso e l'uscita a partire dal lato top in senso antiorario
|
||||
// oltre il 3 sono le celle adiacenti in diagonale al vertice-> 4 corrisponde al ptTl e da lì in senso antiorario
|
||||
// -1 se la curva è sempre dentro la cella
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class Cell
|
||||
@@ -160,11 +168,12 @@ class Cell
|
||||
// | |
|
||||
// |_________________|
|
||||
// Edge 5 ( SW) Edge 2 (Bottom) Edge 6 ( SE)
|
||||
public:
|
||||
enum Collapsed { TO_VERIFY = -1, // da verificare
|
||||
NO_COLLAPSE = 0, // non ho coppie di lati collassati
|
||||
VERT_EDGES = 1, // coppia di lati verticali(1-3) sono collassati
|
||||
HORIZ_EDGES = 2} ; // coppia di lati verticali(0-2) sono collassati
|
||||
|
||||
public :
|
||||
enum Collapsed { TO_VERIFY = -1, // da verificare
|
||||
NO_COLLAPSE = 0, // non ho coppie di lati collassati
|
||||
VERT_EDGES = 1, // coppia di lati verticali(1-3) sono collassati
|
||||
HORIZ_EDGES = 2} ; // coppia di lati verticali(0-2) sono collassati
|
||||
|
||||
public :
|
||||
~Cell( void) {}
|
||||
@@ -336,4 +345,4 @@ class Tree
|
||||
INTVECTOR m_vnParents ; // vettore delle celle ottenute dalla divisione preliminare in singole patch
|
||||
ICRVCOMPOPOVECTOR m_vCCLoop2D ; // vettore che contiene le CurveCompo che rappresentano i loop di trim tenendo conto della divisione in celle
|
||||
std::vector<std::pair<BIPNTVECTOR, ChainCurves>> m_vCEdge2D ; // vettore che le chain che rappresentano ciò che resta degli edge originali, tenendo conto dei trim.
|
||||
} ;
|
||||
} ;
|
||||
|
||||
+1294
-777
File diff suppressed because it is too large
Load Diff
+3
-4
@@ -1585,7 +1585,6 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
|
||||
Vector3d vtDirTip = ptP2T - ptP1T ;
|
||||
bool bTopIsPivot = vtDirTop.IsSmall() ;
|
||||
bool bTipIsPivot = vtDirTip.IsSmall() ;
|
||||
bool bTopAndTipAreEquiverse = vtDirTop * vtDirTip > 0 ;
|
||||
|
||||
// box dell'intero volume spazzato, nel riferimento object oriented
|
||||
BBox3d bbVol ;
|
||||
@@ -1602,9 +1601,9 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
|
||||
PNTVECTOR vPntTopStartBack(3) ;
|
||||
PNTVECTOR vPntTopEndBack(3) ;
|
||||
if ( nSub > 1) {
|
||||
if( bTopIsPivot)
|
||||
if ( bTopIsPivot)
|
||||
vtDirTop = vtDirTip ;
|
||||
if( bTipIsPivot)
|
||||
if ( bTipIsPivot)
|
||||
vtDirTip = vtDirTop ;
|
||||
// determino in che modo collegare il cilindro iniziale con quello finale
|
||||
Vector3d vtTopBaseEnd = vtDirTop - (( vtDirTop * vtLe) * vtLe) ;
|
||||
@@ -1813,7 +1812,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
|
||||
}
|
||||
}
|
||||
|
||||
if( ! bTopIsPivot) {
|
||||
if ( ! bTopIsPivot) {
|
||||
// superiori
|
||||
if ( dSide > 0) {
|
||||
PNTVECTOR vPntTop01 = cBezTopStartF1->GetAllControlPoints();
|
||||
|
||||
Reference in New Issue
Block a user