1b97ec5310
- in PocketingNT, SurfFinishing e SurfRoughing aggiunto flag per Conventional Milling per curve di svuotatura singole.
6856 lines
296 KiB
C++
6856 lines
296 KiB
C++
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
// EgalTech 2019-2019
|
|
//----------------------------------------------------------------------------
|
|
// File : SurfFinishing.cpp Data : 28.05.19 Versione : 2.1e5
|
|
// Contenuto : Implementazione gestione finitura superfici.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.05.19 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "MachMgr.h"
|
|
#include "DllMain.h"
|
|
#include "SurfFinishing.h"
|
|
#include "OperationConst.h"
|
|
#include "OperUserNotesConst.h"
|
|
#include "GeoConst.h"
|
|
#include "/EgtDev/Include/EGkCurveLine.h"
|
|
#include "/EgtDev/Include/EGkCurveArc.h"
|
|
#include "/EgtDev/Include/EGkCurveComposite.h"
|
|
#include "/EgtDev/Include/EGkArcSpecial.h"
|
|
#include "/EgtDev/Include/EGkChainCurves.h"
|
|
#include "/EgtDev/Include/EGkOffsetCurve.h"
|
|
#include "/EgtDev/Include/EGkSurfBezier.h"
|
|
#include "/EgtDev/Include/EGkIntersCurves.h"
|
|
#include "/EgtDev/Include/EGkCurveAux.h"
|
|
#include "/EgtDev/Include/EGkSfrCreate.h"
|
|
#include "/EgtDev/Include/EGkSurfLocal.h"
|
|
#include "/EgtDev/Include/EGkStmFromTriangleSoup.h"
|
|
#include "/EgtDev/Include/EGkStmFromCurves.h"
|
|
#include "/EgtDev/Include/EGkSurfTriMeshAux.h"
|
|
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
|
#include "/EgtDev/Include/EGkDistPointSurfFr.h"
|
|
#include "/EgtDev/Include/EGkCAvToolSurfTm.h"
|
|
#include "/EgtDev/Include/EGkCAvSilhouetteSurfTm.h"
|
|
#include "/EgtDev/Include/EGkCalcPocketing.h"
|
|
#include "/EgtDev/Include/EGkIntervals.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
#include "/EgtDev/Include/EGkUserObjFactory.h"
|
|
#include "/EgtDev/Include/EXeCmdLogOff.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
#include "/EgtDev/Include/EGnStringKeyVal.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
#include "/EgtDev/Include/EGkDistPointSurfTm.h"
|
|
#include "/EgtDev/Include/EGkPolygon3d.h"
|
|
#include "/EgtDev/Include/EGkPolygonElevation.h"
|
|
#include <thread>
|
|
#include <future>
|
|
// per far dimenticare macro di WinUser.h
|
|
#undef GetClassName
|
|
|
|
using namespace std ;
|
|
|
|
//------------------------------ Errors --------------------------------------
|
|
// 3101 = "Error in SurfFinishing : UpdateToolData failed"
|
|
// 3102 = "Error in SurfFinishing : Tool loading failed"
|
|
// 3103 = "Error in SurfFinishing : Chaining failed"
|
|
// 3104 = "Error in SurfFinishing : Open Contour"
|
|
// 3105 = "Error in SurfFinishing : Contour Not Flat"
|
|
// 3106 = "Error in SurfFinishing : Tool Dir not perpendicular to Flat Area"
|
|
// 3107 = "Error in SurfFinishing : Empty RawBox"
|
|
// 3108 = "Error in SurfFinishing : Depth not computable"
|
|
// 3109 = "Error in SurfFinishing : Offset not computable"
|
|
// 3110 = "Error in SurfFinishing : Toolpath not computable"
|
|
// 3111 = "Error in SurfFinishing : Approach not computable"
|
|
// 3112 = "Error in SurfFinishing : Link not computable"
|
|
// 3113 = "Error in SurfFinishing : LeadIn not computable"
|
|
// 3114 = "Error in SurfFinishing : LeadOut not computable"
|
|
// 3115 = "Error in SurfFinishing : Retract not computable"
|
|
// 3116 = "Error in SurfFinishing : axes values not calculable"
|
|
// 3117 = "Error in SurfFinishing : outstroke xx"
|
|
// 3118 = "Error in SurfFinishing : link movements not calculable"
|
|
// 3119 = "Error in SurfFinishing : link outstroke"
|
|
// 3120 = "Error in SurfFinishing : post apply not calculable"
|
|
// 3121 = "Error in SurfFinishing : Linear Approx not computable"
|
|
// 3122 = "Error in SurfFinishing : aggregate from bottom not allowed"
|
|
// 3123 = "Error in SurfFinishing : missing surfaces"
|
|
// 3124 = "Error in SurfFinishing : region not computable"
|
|
// 3125 = "Error in SurfFinishing : CalcPocketing failed"
|
|
// 3126 = "Error in SurfFinishing : Computing ZConst Curves failed"
|
|
// 3127 = "Error in SurfFinishing : Computing ZConst Paths failed"
|
|
// 3128 = "Error in SurfFinishing : Curves with different extrusion"
|
|
// 3129 = "Error in SurfFinishing : Splitting surfaces failed"
|
|
// 3130 = "Error in SurfFinishing : Computing tool region failed"
|
|
// 3131 = "Error in SurfFinishing : Computing Surface Offset failed"
|
|
// 3132 = "Error in SurfFinishing : Computing Offset Edges failed"
|
|
// 3133 = "Error in SurfFinishing : Projecting curves on Surface failed"
|
|
// 3134 = "Error in SurfFinishing : Projecting Path failed"
|
|
// 3135 = "Error in SurfFinishing : Calc Region Elvation failed"
|
|
// 3136 = "Error in SurfFinishing : special apply not calculable"
|
|
// 3151 = "Warning in SurfFinishing : Skipped entity (xx)"
|
|
// 3152 = "Warning in SurfFinishing : No machinable path"
|
|
// 3153 = "Warning in SurfFinishing : Tool name changed (xx)"
|
|
// 3154 = "Warning in SurfFinishing : Tool data changed (xx)"
|
|
// 3155 = "Warning in SurfFinishing : Pencil path not completed"
|
|
|
|
//----------------------------------------------------------------------------
|
|
static string KEY_THICK = "THICK" ;
|
|
static string SRF_SUPP_LAYER_NAME = "SUPP" ;
|
|
const double SILH_SAMPLING = 1. ;
|
|
const double SUPP_SURF_RADIAL_OFFS = 5. ;
|
|
enum {
|
|
PENCIL_CORNER = 0,
|
|
PENCIL_FAT_CORNER = 1,
|
|
PENCIL_REGION = 2
|
|
} ;
|
|
|
|
#define DEBUG 0
|
|
#define DEBUG_SFR 0
|
|
#define ENABLE_ZCONST_DEBUG 0
|
|
#define ENABLE_ZCONST_PATH_DEBUG 0
|
|
#define ENABLE_OPTIMAL_DEBUG 0
|
|
#define ENABLE_OPTIMAL_SOFT_DEBUG 0
|
|
#define ENABLE_OPTIMAL_FINAL_CURVES_DEBUG 0
|
|
#define ENABLE_PENCIL_DEBUG 0
|
|
#define ENABLE_LINK_DEBUG 0
|
|
#if DEBUG || DEBUG_SFR || ENABLE_ZCONST_DEBUG || ENABLE_ZCONST_PATH_DEBUG || ENABLE_OPTIMAL_DEBUG || ENABLE_OPTIMAL_SOFT_DEBUG || ENABLE_PENCIL_DEBUG || ENABLE_OPTIMAL_FINAL_CURVES_DEBUG || ENABLE_LINK_DEBUG
|
|
#include "/EgtDev/Include/EGkGeoPoint3d.h"
|
|
#include "/EgtDev/Include/EGkGeoVector3d.h"
|
|
#include "/EgtDev/Include/EgtPerfCounter.h"
|
|
#endif
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
USEROBJ_REGISTER( GetOperationClass( OPER_SURFFINISHING), SurfFinishing) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
const string&
|
|
SurfFinishing::GetClassName( void) const
|
|
{
|
|
return USEROBJ_GETNAME( SurfFinishing) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
SurfFinishing*
|
|
SurfFinishing::Clone( void) const
|
|
{
|
|
// alloco oggetto
|
|
SurfFinishing* pSrF = new(nothrow) SurfFinishing ;
|
|
// eseguo copia dei dati
|
|
if ( pSrF != nullptr) {
|
|
try {
|
|
pSrF->m_vId = m_vId ;
|
|
pSrF->m_pMchMgr = m_pMchMgr ;
|
|
pSrF->m_nPhase = m_nPhase ;
|
|
pSrF->m_Params = m_Params ;
|
|
pSrF->m_TParams = m_TParams ;
|
|
pSrF->m_dTHoldBase = m_dTHoldBase ;
|
|
pSrF->m_dTHoldLen = m_dTHoldLen ;
|
|
pSrF->m_dTHoldDiam = m_dTHoldDiam ;
|
|
pSrF->m_nStatus = m_nStatus ;
|
|
pSrF->m_nPaths = m_nPaths ;
|
|
}
|
|
catch( ...) {
|
|
delete pSrF ;
|
|
return nullptr ;
|
|
}
|
|
}
|
|
// ritorno l'oggetto
|
|
return pSrF ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Dump( string& sOut, bool bMM, const char* szNewLine) const
|
|
{
|
|
sOut += GetClassName() + "[mm]" + szNewLine ;
|
|
sOut += KEY_PHASE + EQUAL + ToString( m_nPhase) + szNewLine ;
|
|
sOut += KEY_IDS + EQUAL + ToString( m_vId) + szNewLine ;
|
|
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i)
|
|
sOut += m_Params.ToString( i) + szNewLine ;
|
|
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i)
|
|
sOut += m_TParams.ToString( i) + szNewLine ;
|
|
sOut += KEY_NUM + EQUAL + ToString( m_nPaths) + szNewLine ;
|
|
sOut += KEY_STAT + EQUAL + ToString( m_nStatus) + szNewLine ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Save( int nBaseId, STRVECTOR& vString) const
|
|
{
|
|
try {
|
|
int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 3 ;
|
|
vString.insert( vString.begin(), nSize, "") ;
|
|
int k = - 1 ;
|
|
if ( ! SetVal( KEY_IDS, m_vId, vString[++k]))
|
|
return false ;
|
|
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i)
|
|
vString[++k] = m_Params.ToString( i) ;
|
|
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i)
|
|
vString[++k] = m_TParams.ToString( i) ;
|
|
if ( ! SetVal( KEY_PHASE, m_nPhase, vString[++k]))
|
|
return false ;
|
|
if ( ! SetVal( KEY_NUM, m_nPaths, vString[++k]))
|
|
return false ;
|
|
if ( ! SetVal( KEY_STAT, m_nStatus, vString[++k]))
|
|
return false ;
|
|
}
|
|
catch( ...) {
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Load( const STRVECTOR& vString, int nBaseGdbId)
|
|
{
|
|
int nSize = int( vString.size()) ;
|
|
// lista identificativi geometrie da lavorare
|
|
int k = - 1 ;
|
|
if ( k >= nSize - 1 || ! GetVal( vString[++k], KEY_IDS, m_vId))
|
|
return false ;
|
|
for ( auto& Sel : m_vId)
|
|
Sel.nId += nBaseGdbId ;
|
|
// parametri lavorazione
|
|
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i) {
|
|
int nKey ;
|
|
if ( k >= nSize - 1 || ! m_Params.FromString( vString[++k], nKey) || nKey != i) {
|
|
if ( m_Params.IsOptional( i))
|
|
-- k ;
|
|
else
|
|
return false ;
|
|
}
|
|
}
|
|
// parametri utensile
|
|
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) {
|
|
int nKey ;
|
|
if ( k >= nSize - 1 || ! m_TParams.FromString( vString[++k], nKey) || nKey != i)
|
|
return false ;
|
|
}
|
|
// parametri di stato
|
|
while ( k < nSize - 1) {
|
|
// separo chiave da valore
|
|
string sKey, sVal ;
|
|
SplitFirst( vString[++k], "=", sKey, sVal) ;
|
|
// leggo
|
|
if ( sKey == KEY_PHASE) {
|
|
if ( ! FromString( sVal, m_nPhase))
|
|
return false ;
|
|
}
|
|
else if ( sKey == KEY_NUM) {
|
|
if ( ! FromString( sVal, m_nPaths))
|
|
return false ;
|
|
}
|
|
else if ( sKey == KEY_STAT) {
|
|
if ( ! FromString( sVal, m_nStatus))
|
|
return false ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
SurfFinishing::SurfFinishing( void)
|
|
{
|
|
m_Params.m_sName = "*" ;
|
|
m_Params.m_sToolName = "*" ;
|
|
m_TParams.m_sName = "*" ;
|
|
m_TParams.m_sHead = "*" ;
|
|
m_dTHoldBase = 0 ;
|
|
m_dTHoldLen = 0 ;
|
|
m_dTHoldDiam = 0 ;
|
|
m_nStatus = MCH_ST_TO_VERIFY ;
|
|
m_nPaths = 0 ;
|
|
m_bRunning = false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Prepare( const string& sSawName)
|
|
{
|
|
// verifico il gestore lavorazioni
|
|
if ( m_pMchMgr == nullptr)
|
|
return false ;
|
|
// recupero il gestore DB utensili della macchina corrente
|
|
ToolsMgr* pTMgr = m_pMchMgr->GetCurrToolsMgr() ;
|
|
if ( pTMgr == nullptr)
|
|
return false ;
|
|
// recupero il gestore DB lavorazioni della macchina corrente
|
|
MachiningsMgr* pMMgr = m_pMchMgr->GetCurrMachiningsMgr() ;
|
|
if ( pMMgr == nullptr)
|
|
return false ;
|
|
// ricerca della lavorazione di libreria con il nome indicato
|
|
const SurfFinishingData* pDdata = GetSurfFinishingData( pMMgr->GetMachining( sSawName)) ;
|
|
if ( pDdata == nullptr)
|
|
return false ;
|
|
m_Params = *pDdata ;
|
|
// ricerca dell'utensile usato dalla lavorazione
|
|
const ToolData* pTdata = pTMgr->GetTool( m_Params.m_ToolUuid) ;
|
|
if ( pTdata == nullptr)
|
|
return false ;
|
|
m_TParams = *pTdata ;
|
|
m_Params.m_sToolName = m_TParams.m_sName ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SetParam( int nType, bool bVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_INVERT :
|
|
if ( bVal != m_Params.m_bInvert)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_bInvert = bVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SetParam( int nType, int nVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_SUBTYPE :
|
|
if ( ! m_Params.VerifySubType( nVal))
|
|
return false ;
|
|
if ( nVal != m_Params.m_nSubType)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_nSubType = nVal ;
|
|
return true ;
|
|
case MPA_LEADINTYPE :
|
|
if ( ! m_Params.VerifyLeadInType( nVal))
|
|
return false ;
|
|
if ( nVal != m_Params.m_nLeadInType)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_nLeadInType = nVal ;
|
|
return true ;
|
|
case MPA_LEADOUTTYPE :
|
|
if ( ! m_Params.VerifyLeadOutType( nVal))
|
|
return false ;
|
|
if ( nVal != m_Params.m_nLeadOutType)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_nLeadOutType = nVal ;
|
|
return true ;
|
|
case MPA_SCC :
|
|
if ( ! m_Params.VerifySolCh( nVal))
|
|
return false ;
|
|
if ( nVal != m_Params.m_nSolCh)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_nSolCh = nVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SetParam( int nType, double dVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_SPEED :
|
|
if ( ! m_TParams.VerifySpeed( dVal))
|
|
return false ;
|
|
if ( AreSameAngValue( dVal, m_TParams.m_dSpeed))
|
|
dVal = 0 ;
|
|
m_Params.m_dSpeed = dVal ;
|
|
return true ;
|
|
case MPA_FEED :
|
|
if ( AreSameLenValue( dVal, m_TParams.m_dFeed))
|
|
dVal = 0 ;
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dFeed))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dFeed = dVal ;
|
|
return true ;
|
|
case MPA_STARTFEED :
|
|
if ( AreSameLenValue( dVal, m_TParams.m_dStartFeed))
|
|
dVal = 0 ;
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dStartFeed))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dStartFeed = dVal ;
|
|
return true ;
|
|
case MPA_ENDFEED :
|
|
if ( AreSameLenValue( dVal, m_TParams.m_dEndFeed))
|
|
dVal = 0 ;
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dEndFeed))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dEndFeed = dVal ;
|
|
return true ;
|
|
case MPA_TIPFEED :
|
|
if ( AreSameLenValue( dVal, m_TParams.m_dTipFeed))
|
|
dVal = 0 ;
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dTipFeed))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dTipFeed = dVal ;
|
|
return true ;
|
|
case MPA_OFFSR :
|
|
if ( AreSameLenValue( dVal, m_TParams.m_dOffsR))
|
|
dVal = UNKNOWN_PAR ;
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dOffsR))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dOffsR = dVal ;
|
|
return true ;
|
|
case MPA_DEPTH: {
|
|
string sVal = ToString( dVal) ;
|
|
if ( sVal != m_Params.m_sDepth)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sDepth = sVal ;
|
|
} return true ;
|
|
case MPA_STARTPOS :
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dStartPos))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dStartPos = dVal ;
|
|
return true ;
|
|
case MPA_OVERL :
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dOverlap))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dOverlap = dVal ;
|
|
return true ;
|
|
case MPA_SIDESTEP :
|
|
if ( ! AreSameLenValue( dVal, m_Params.m_dSideStep))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dSideStep = dVal ;
|
|
return true ;
|
|
case MPA_SIDEANGLE :
|
|
if ( abs( dVal - m_Params.m_dSideAngle) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dSideAngle = dVal ;
|
|
return true ;
|
|
case MPA_LITANG :
|
|
if ( abs( dVal - m_Params.m_dLiTang) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dLiTang = dVal ;
|
|
return true ;
|
|
case MPA_LIPERP :
|
|
if ( abs( dVal - m_Params.m_dLiPerp) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dLiPerp = dVal ;
|
|
return true ;
|
|
case MPA_LOTANG :
|
|
if ( abs( dVal - m_Params.m_dLoTang) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dLoTang = dVal ;
|
|
return true ;
|
|
case MPA_LOPERP :
|
|
if ( abs( dVal - m_Params.m_dLoPerp) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dLoPerp = dVal ;
|
|
return true ;
|
|
case MPA_APPROX :
|
|
if ( abs( dVal - m_Params.m_dApprox) > EPS_SMALL)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dApprox = dVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SetParam( int nType, const string& sVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_TOOL : {
|
|
const ToolData* pTdata ;
|
|
if ( ! m_Params.VerifyTool( m_pMchMgr->GetCurrToolsMgr(), sVal, pTdata))
|
|
return false ;
|
|
if ( ! SameTool( m_TParams, *pTdata))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sToolName = sVal ;
|
|
m_Params.m_ToolUuid = pTdata->m_Uuid ;
|
|
m_TParams = *pTdata ;
|
|
} return true ;
|
|
case MPA_DEPTH_STR :
|
|
if ( sVal != m_Params.m_sDepth)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sDepth = sVal ;
|
|
return true ;
|
|
case MPA_SYSNOTES :
|
|
if ( sVal != m_Params.m_sSysNotes)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sSysNotes = sVal ;
|
|
return true ;
|
|
case MPA_USERNOTES :
|
|
if ( sVal != m_Params.m_sUserNotes)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sUserNotes = sVal ;
|
|
return true ;
|
|
case MPA_INITANGS :
|
|
if ( sVal != m_Params.m_sInitAngs)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sInitAngs = sVal ;
|
|
return true ;
|
|
case MPA_BLOCKEDAXIS :
|
|
if ( sVal != m_Params.m_sBlockedAxis)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sBlockedAxis = sVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SetGeometry( const SELVECTOR& vIds)
|
|
{
|
|
// verifico validità gestore DB geometrico
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// copia temporanea e reset della geometria corrente
|
|
SELVECTOR vOldId = m_vId ;
|
|
m_vId.clear() ;
|
|
// verifico che gli identificativi rappresentino delle entità ammissibili
|
|
for ( const auto& Id : vIds) {
|
|
// test sull'entità
|
|
int nSubs ;
|
|
if ( ! VerifyGeometry( Id, nSubs)) {
|
|
string sInfo = "Warning in SurfFinishing : Skipped entity " + ToString( Id) ;
|
|
m_pMchMgr->SetWarning( 3151, sInfo) ;
|
|
continue ;
|
|
}
|
|
// posso aggiungere alla lista
|
|
m_vId.emplace_back( Id) ;
|
|
}
|
|
// aggiorno lo stato
|
|
if ( m_vId != vOldId)
|
|
m_nStatus |= MCH_ST_GEO_MODIF ;
|
|
// restituisco presenza geometria da lavorare
|
|
return ( ! m_vId.empty()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Preview( bool bRecalc)
|
|
{
|
|
// non esiste preview, si fa apply
|
|
return Apply( bRecalc, false) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Apply( bool bRecalc, bool bPostApply)
|
|
{
|
|
// se calcoli già in corso, esco
|
|
if ( m_bRunning) {
|
|
LOG_DBG_INFO( GetEMkLogger(), "SurfFinishing::Apply already running") ;
|
|
return true ;
|
|
}
|
|
m_bRunning = true ;
|
|
bool bOk = MyApply( bRecalc, bPostApply) ;
|
|
m_bRunning = false ;
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::MyApply( bool bRecalc, bool bPostApply)
|
|
{
|
|
// reset numero percorsi di finitura generati
|
|
int nCurrPaths = m_nPaths ;
|
|
m_nPaths = 0 ;
|
|
|
|
// verifico validità gestore DB geometrico e Id del gruppo
|
|
if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId))
|
|
return false ;
|
|
|
|
// aggiorno dati geometrici dell'utensile
|
|
if ( ! UpdateToolData()) {
|
|
m_pMchMgr->SetLastError( 3101, "Error in SurfFinishing : UpdateToolData failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// non è prevista finitura superficie con aggregato da sotto
|
|
if ( IsAggrBottom( m_TParams.m_sHead)) {
|
|
m_pMchMgr->SetLastError( 3122, "Error in SurfFinishing : aggregate from bottom not allowed") ;
|
|
return false ;
|
|
}
|
|
|
|
// se modificata geometria, necessario ricalcolo
|
|
if ( ( m_nStatus & MCH_ST_GEO_MODIF) != 0)
|
|
bRecalc = true ;
|
|
|
|
// verifico se necessario continuare nell'aggiornamento
|
|
if ( ! bRecalc && ( m_nStatus == MCH_ST_OK || m_nStatus == MCH_ST_NO_POSTAPPL)) {
|
|
// confermo i percorsi di lavorazione
|
|
m_nPaths = nCurrPaths ;
|
|
string sLog = string( "SurfFinishing apply skipped : status ") + ( m_nStatus == MCH_ST_OK ? "already ok" : "no postapply") ;
|
|
LOG_DBG_INFO( GetEMkLogger(), sLog.c_str()) ;
|
|
// eseguo aggiornamento assi macchina e collegamento con operazione precedente
|
|
if ( ! Update( bPostApply))
|
|
return false ;
|
|
m_nStatus = ( bPostApply ? MCH_ST_OK : MCH_ST_NO_POSTAPPL) ;
|
|
LOG_DBG_INFO( GetEMkLogger(), "Update done") ;
|
|
// esco con successo
|
|
return true ;
|
|
}
|
|
m_nStatus = MCH_ST_TO_VERIFY ;
|
|
|
|
// recupero gruppo per geometria ausiliaria
|
|
int nAuxId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_AUX) ;
|
|
bool bChain = false ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nAuxId == GDB_ID_NULL) {
|
|
nAuxId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nAuxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nAuxId, MCH_AUX) ;
|
|
m_pGeomDB->SetStatus( nAuxId, GDB_ST_OFF) ;
|
|
bChain = true ;
|
|
}
|
|
// altrimenti, se chiesto ricalcolo, lo svuoto
|
|
else if ( bRecalc) {
|
|
m_pGeomDB->EmptyGroup( nAuxId) ;
|
|
bChain = true ;
|
|
}
|
|
else {
|
|
// altrimenti, controllo esistenza delle regioni (per compatibilità)
|
|
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
|
|
while ( nPathId != GDB_ID_NULL && ! bChain) {
|
|
int nGeoId = m_pGeomDB->GetFirstInGroup( nPathId) ;
|
|
while ( nGeoId != GDB_ID_NULL && ! bChain) {
|
|
if ( m_Params.m_nSubType == SURFFIN_SUB_ZIGZAG || m_Params.m_nSubType == SURFFIN_SUB_ONEWAY ||
|
|
m_Params.m_nSubType == SURFFIN_SUB_SPIRALIN || m_Params.m_nSubType == SURFFIN_SUB_SPIRALOUT ||
|
|
m_Params.m_nSubType == SURFFIN_SUB_Z_CONST || m_Params.m_nSubType == SURFFIN_SUB_OPTIMAL ||
|
|
m_Params.m_nSubType == SURFFIN_SUB_PENCIL)
|
|
bChain = ( m_pGeomDB->GetGeoType( nGeoId) != SRF_FLATRGN) ;
|
|
else if ( m_Params.m_nSubType == SURFFIN_SUB_PROJECT)
|
|
bChain = ( m_pGeomDB->GetGeoType( nPathId) != CRV_COMPO) ;
|
|
nGeoId = m_pGeomDB->GetNext( nGeoId) ;
|
|
}
|
|
nPathId = m_pGeomDB->GetNextGroup( nPathId) ;
|
|
}
|
|
if ( bChain)
|
|
m_pGeomDB->EmptyGroup( nAuxId) ;
|
|
}
|
|
|
|
// rendo corrente l'utensile usato nella lavorazione
|
|
if ( ! m_pMchMgr->SetCalcTool( m_TParams.m_sName, m_TParams.m_sHead, m_TParams.m_nExit)) {
|
|
m_pMchMgr->SetLastError( 3102, "Error in SurfFinishing : Tool loading failed") ;
|
|
return false ;
|
|
}
|
|
// recupero i dati del portautensile
|
|
int nToolId = m_pMchMgr->GetCalcTool() ;
|
|
m_dTHoldBase = 0 ;
|
|
m_pGeomDB->GetInfo( nToolId, TTH_BASE, m_dTHoldBase) ;
|
|
m_dTHoldLen = 0 ;
|
|
m_pGeomDB->GetInfo( nToolId, TTH_LEN, m_dTHoldLen) ;
|
|
m_dTHoldDiam = 0 ;
|
|
m_pGeomDB->GetInfo( nToolId, TTH_DIAM, m_dTHoldDiam) ;
|
|
|
|
// se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria
|
|
if ( bChain && ! Chain( nAuxId)) {
|
|
m_pMchMgr->SetLastError( 3103, "Error in SurfFinishing : Chaining failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// recupero gruppo per geometria di lavorazione (Cutter Location)
|
|
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nClId == GDB_ID_NULL) {
|
|
nClId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nClId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nClId, MCH_CL) ;
|
|
}
|
|
// altrimenti lo svuoto
|
|
else
|
|
m_pGeomDB->EmptyGroup( nClId) ;
|
|
|
|
// lavoro ogni singola regione piana
|
|
if ( m_Params.m_nSubType == SURFFIN_SUB_ZIGZAG || m_Params.m_nSubType == SURFFIN_SUB_ONEWAY ||
|
|
m_Params.m_nSubType == SURFFIN_SUB_SPIRALIN || m_Params.m_nSubType == SURFFIN_SUB_SPIRALOUT ||
|
|
m_Params.m_nSubType == SURFFIN_SUB_Z_CONST || m_Params.m_nSubType == SURFFIN_SUB_OPTIMAL ||
|
|
m_Params.m_nSubType == SURFFIN_SUB_PENCIL) {
|
|
bool bOk = true ;
|
|
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
|
|
while ( nPathId != GDB_ID_NULL) {
|
|
if ( ! ProcessSfr( nPathId, GDB_ID_NULL, nClId))
|
|
bOk = false ;
|
|
nPathId = m_pGeomDB->GetNextGroup( nPathId) ;
|
|
}
|
|
if ( ! bOk)
|
|
return false ;
|
|
}
|
|
// lavoro ogni singola curva composita
|
|
else if ( m_Params.m_nSubType == SURFFIN_SUB_PROJECT) {
|
|
bool bOk = true ;
|
|
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
|
|
while ( nPathId != GDB_ID_NULL) {
|
|
if ( ! ProcessCrvCompo( nPathId, GDB_ID_NULL, nClId))
|
|
bOk = false ;
|
|
nPathId = m_pGeomDB->GetNextGroup( nPathId) ;
|
|
}
|
|
if ( ! bOk)
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
|
|
// assegno ingombri dei vari percorsi di lavorazione e della lavorazione nel suo complesso
|
|
CalcAndSetBBox( nClId) ;
|
|
|
|
// eseguo aggiornamento assi macchina e collegamento con operazione precedente
|
|
if ( ! Update( bPostApply))
|
|
return false ;
|
|
|
|
// aggiorno stato della lavorazione
|
|
m_nStatus = ( bPostApply ? MCH_ST_OK : MCH_ST_NO_POSTAPPL) ;
|
|
// dichiaro successiva da aggiornare
|
|
UpdateFollowingOperationsStatus( MCH_ST_OTH_MODIF) ;
|
|
|
|
LOG_DBG_INFO( GetEMkLogger(), "SurfFinishing apply done") ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Update( bool bPostApply)
|
|
{
|
|
// verifico validità gestore DB geometrico e Id del gruppo
|
|
if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId))
|
|
return false ;
|
|
|
|
// se lavorazione vuota, esco
|
|
if ( m_nPaths == 0) {
|
|
m_pMchMgr->SetWarning( 3152, "Warning in SurfFinishing : No machinable path") ;
|
|
return true ;
|
|
}
|
|
|
|
// elimino le entità CLIMB, RISE e HOME della lavorazione, potrebbero falsare i calcoli degli assi (in ogni casi vengono riaggiunte dopo)
|
|
RemoveClimbRiseHome() ;
|
|
|
|
// imposto eventuale asse bloccato da lavorazione
|
|
SetBlockedRotAxis( m_Params.m_sBlockedAxis) ;
|
|
|
|
// calcolo gli assi macchina
|
|
string sHint = ExtractHint( m_Params.m_sUserNotes) ;
|
|
if ( ! m_Params.m_sInitAngs.empty())
|
|
sHint = m_Params.m_sInitAngs ;
|
|
if ( ! CalculateAxesValues( sHint)) {
|
|
string sInfo = m_pMchMgr->GetOutstrokeInfo() ;
|
|
if ( sInfo.empty())
|
|
m_pMchMgr->SetLastError( 3116, "Error in SurfFinishing : axes values not calculable") ;
|
|
else
|
|
m_pMchMgr->SetLastError( 3117, "Error in SurfFinishing : outstroke ") ;
|
|
return false ;
|
|
}
|
|
|
|
// assegno estremi degli assi dei vari percorsi di lavorazione e della lavorazione nel suo complesso
|
|
CalcAndSetAxesBBox() ;
|
|
|
|
// esecuzione eventuali personalizzazioni speciali
|
|
string sSpecErr ;
|
|
if ( bPostApply && ! SpecialApply( sSpecErr)) {
|
|
if ( ! IsEmptyOrSpaces( sSpecErr))
|
|
m_pMchMgr->SetLastError( 3136, sSpecErr) ;
|
|
else
|
|
m_pMchMgr->SetLastError( 3136, "Error in SurfFinishing : special apply not calculable") ;
|
|
return false ;
|
|
}
|
|
|
|
// gestione movimenti all'inizio di ogni singolo percorso di lavorazione e alla fine della lavorazione
|
|
if ( ! AdjustStartEndMovements()) {
|
|
string sInfo = m_pMchMgr->GetOutstrokeInfo() ;
|
|
if ( sInfo.empty())
|
|
m_pMchMgr->SetLastError( 3118, "Error in SurfFinishing : link movements not calculable") ;
|
|
else
|
|
m_pMchMgr->SetLastError( 3119, "Error in SurfFinishing : link outstroke ") ;
|
|
return false ;
|
|
}
|
|
|
|
// esecuzione eventuali personalizzazioni finali
|
|
string sPostErr ;
|
|
if ( bPostApply && ! PostApply( sPostErr)) {
|
|
if ( ! IsEmptyOrSpaces( sPostErr))
|
|
m_pMchMgr->SetLastError( 3120, sPostErr) ;
|
|
else
|
|
m_pMchMgr->SetLastError( 3120, "Error in SurfFinishing : post apply not calculable") ;
|
|
return false ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetParam( int nType, bool& bVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_INVERT :
|
|
bVal = m_Params.m_bInvert ;
|
|
return true ;
|
|
}
|
|
bVal = false ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetParam( int nType, int& nVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_TYPE :
|
|
nVal = MT_SURFFINISHING ;
|
|
return true ;
|
|
case MPA_SUBTYPE :
|
|
nVal = m_Params.m_nSubType ;
|
|
return true ;
|
|
case MPA_LEADINTYPE :
|
|
nVal = m_Params.m_nLeadInType ;
|
|
return true ;
|
|
case MPA_LEADOUTTYPE :
|
|
nVal = m_Params.m_nLeadOutType ;
|
|
return true ;
|
|
case MPA_SCC :
|
|
nVal = m_Params.m_nSolCh ;
|
|
return true ;
|
|
}
|
|
nVal = 0 ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetParam( int nType, double& dVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_SPEED :
|
|
dVal = GetSpeed() ;
|
|
return true ;
|
|
case MPA_FEED :
|
|
dVal = GetFeed() ;
|
|
return true ;
|
|
case MPA_STARTFEED :
|
|
dVal = GetStartFeed() ;
|
|
return true ;
|
|
case MPA_ENDFEED :
|
|
dVal = GetEndFeed() ;
|
|
return true ;
|
|
case MPA_TIPFEED :
|
|
dVal = GetTipFeed() ;
|
|
return true ;
|
|
case MPA_OFFSR :
|
|
dVal =GetOffsR() ;
|
|
return true ;
|
|
case MPA_STARTPOS :
|
|
dVal = m_Params.m_dStartPos ;
|
|
return true ;
|
|
case MPA_OVERL :
|
|
dVal = m_Params.m_dOverlap ;
|
|
return true ;
|
|
case MPA_SIDESTEP :
|
|
dVal = m_Params.m_dSideStep ;
|
|
return true ;
|
|
case MPA_SIDEANGLE :
|
|
dVal = m_Params.m_dSideAngle ;
|
|
return true ;
|
|
case MPA_LITANG :
|
|
dVal = m_Params.m_dLiTang ;
|
|
return true ;
|
|
case MPA_LIPERP :
|
|
dVal = m_Params.m_dLiPerp ;
|
|
return true ;
|
|
case MPA_LOTANG :
|
|
dVal = m_Params.m_dLoTang ;
|
|
return true ;
|
|
case MPA_LOPERP :
|
|
dVal = m_Params.m_dLoPerp ;
|
|
return true ;
|
|
case MPA_APPROX :
|
|
dVal = m_Params.m_dApprox ;
|
|
return true ;
|
|
}
|
|
dVal = 0 ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetParam( int nType, string& sVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_NAME :
|
|
sVal = m_Params.m_sName ;
|
|
return true ;
|
|
case MPA_TOOL :
|
|
sVal = m_Params.m_sToolName ;
|
|
return true ;
|
|
case MPA_DEPTH_STR :
|
|
sVal = m_Params.m_sDepth ;
|
|
return true ;
|
|
case MPA_TUUID :
|
|
sVal = ToString( m_Params.m_ToolUuid) ;
|
|
return true ;
|
|
case MPA_UUID :
|
|
sVal = ToString( m_Params.m_Uuid) ;
|
|
return true ;
|
|
case MPA_SYSNOTES :
|
|
sVal = m_Params.m_sSysNotes ;
|
|
return true ;
|
|
case MPA_USERNOTES :
|
|
sVal = m_Params.m_sUserNotes ;
|
|
return true ;
|
|
case MPA_INITANGS :
|
|
sVal = m_Params.m_sInitAngs ;
|
|
return true ;
|
|
case MPA_BLOCKEDAXIS :
|
|
sVal = m_Params.m_sBlockedAxis ;
|
|
return true ;
|
|
}
|
|
sVal = "" ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
const ToolData&
|
|
SurfFinishing::GetToolData( void) const
|
|
{
|
|
return m_TParams ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::UpdateToolData( void)
|
|
{
|
|
// recupero il gestore DB utensili della macchina corrente
|
|
ToolsMgr* pTMgr = m_pMchMgr->GetCurrToolsMgr() ;
|
|
if ( pTMgr == nullptr)
|
|
return false ;
|
|
// recupero l'utensile nel DB utensili (se fallisce con UUID provo con il nome)
|
|
const ToolData* pTdata = pTMgr->GetTool( m_Params.m_ToolUuid) ;
|
|
if ( pTdata == nullptr) {
|
|
pTdata = pTMgr->GetTool( m_Params.m_sToolName) ;
|
|
if ( pTdata == nullptr)
|
|
return false ;
|
|
m_Params.m_ToolUuid = m_TParams.m_Uuid ;
|
|
}
|
|
// salvo posizione TC, testa e uscita originali
|
|
string sOrigTcPos = m_TParams.m_sTcPos ;
|
|
string sOrigHead = m_TParams.m_sHead ;
|
|
int nOrigExit = m_TParams.m_nExit ;
|
|
// verifico se sono diversi (ad esclusione di nome, posizione TC, testa e uscita)
|
|
bool bChanged = ( ! SameTool( m_TParams, *pTdata, false)) ;
|
|
// aggiorno comunque i parametri
|
|
m_TParams = *pTdata ;
|
|
// se definito attrezzaggio, aggiorno i parametri che ne possono derivare
|
|
string sTcPos ; string sHead ; int nExit ;
|
|
if ( m_pMchMgr->GetCurrSetupMgr().GetToolData( m_TParams.m_sName, sTcPos, sHead, nExit)) {
|
|
if ( sOrigTcPos != sTcPos ||
|
|
sOrigHead != sHead ||
|
|
nOrigExit != nExit)
|
|
bChanged = true ;
|
|
m_TParams.m_sTcPos = sTcPos ;
|
|
m_TParams.m_sHead = sHead ;
|
|
m_TParams.m_nExit = nExit ;
|
|
}
|
|
else {
|
|
if ( sOrigTcPos != pTdata->m_sTcPos ||
|
|
sOrigHead != pTdata->m_sHead ||
|
|
nOrigExit != pTdata->m_nExit)
|
|
bChanged = true ;
|
|
}
|
|
// eventuali segnalazioni
|
|
if ( ! EqualNoCase( m_Params.m_sToolName, m_TParams.m_sName)) {
|
|
string sInfo = "Warning in SurfFinishing : tool name changed (" +
|
|
m_Params.m_sToolName + "->" + m_TParams.m_sName + ")" ;
|
|
m_pMchMgr->SetWarning( 3153, sInfo) ;
|
|
m_Params.m_sToolName = m_TParams.m_sName ;
|
|
}
|
|
if ( bChanged) {
|
|
string sInfo = "Warning in SurfFinishing : tool data changed (" +
|
|
m_Params.m_sToolName + ")" ;
|
|
m_pMchMgr->SetWarning( 3154, sInfo) ;
|
|
}
|
|
// se modificato, aggiusto lo stato
|
|
if ( bChanged)
|
|
m_nStatus = MCH_ST_TO_VERIFY ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetGeometry( SELVECTOR& vIds) const
|
|
{
|
|
// restituisco l'elenco delle entità
|
|
vIds = m_vId ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) const
|
|
{
|
|
// compenso il raggio dell'utensile
|
|
ptP += pCamData->GetCorrDir() * ( m_TParams.m_dDiam / 2) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::VerifyGeometry( SelData Id, int& nSubs)
|
|
{
|
|
// ammessi : curve o superfici
|
|
const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
const ICurve* pCurve = nullptr ;
|
|
// se direttamente la curva
|
|
if ( Id.nSub == SEL_SUB_ALL) {
|
|
pCurve = ::GetCurve( pGObj) ;
|
|
if ( pCurve != nullptr) {
|
|
if ( pCurve->GetType() == CRV_COMPO)
|
|
nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ;
|
|
else
|
|
nSubs = 0 ;
|
|
}
|
|
}
|
|
// altrimenti sottocurva di composita
|
|
else {
|
|
const ICurveComposite* pCompo = GetCurveComposite( pGObj) ;
|
|
if ( pCompo != nullptr)
|
|
pCurve = pCompo->GetCurve( Id.nSub) ;
|
|
nSubs = 0 ;
|
|
}
|
|
return ( pCurve != nullptr) ;
|
|
}
|
|
// se altrimenti è superficie trimesh
|
|
else if ( pGObj->GetType() == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pSurf = ::GetSurfTriMesh( pGObj) ;
|
|
return ( pSurf != nullptr && pSurf->GetFacetCount() >= 1) ;
|
|
}
|
|
// se altrimenti è superficie Bezier
|
|
else if ( pGObj->GetType() == SRF_BEZIER) {
|
|
const ISurfBezier* pSurf = ::GetSurfBezier( pGObj) ;
|
|
return ( pSurf != nullptr && pSurf->IsValid()) ;
|
|
}
|
|
// altrimenti errore
|
|
else
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetCurves( SelData Id, ICURVEPLIST& lstPC)
|
|
{
|
|
// ammessi : curve, superfici TriMesh e superfici Bezier
|
|
const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// ne recupero il riferimento globale
|
|
Frame3d frGlob ;
|
|
if ( ! m_pGeomDB->GetGlobFrame( Id.nId, frGlob))
|
|
return false ;
|
|
// recupero il tipo
|
|
int nType = pGObj->GetType() ;
|
|
// se curva
|
|
if ( ( nType & GEO_CURVE) != 0) {
|
|
PtrOwner<ICurve> pCurve ;
|
|
// se direttamente curva
|
|
if ( Id.nSub == SEL_SUB_ALL) {
|
|
// recupero la curva
|
|
const ICurve* pOriCurve = ::GetCurve( pGObj) ;
|
|
if ( pOriCurve == nullptr)
|
|
return false ;
|
|
// la duplico
|
|
pCurve.Set( pOriCurve->Clone()) ;
|
|
// se estrusione mancante, imposto default
|
|
Vector3d vtExtr ;
|
|
if ( ! pCurve->GetExtrusion( vtExtr) || vtExtr.IsSmall())
|
|
pCurve->SetExtrusion( Z_AX) ;
|
|
}
|
|
// altrimenti sottocurva di composita
|
|
else {
|
|
// recupero la composita
|
|
const ICurveComposite* pCompo = GetCurveComposite( pGObj) ;
|
|
if ( pCompo == nullptr)
|
|
return false ;
|
|
// recupero la curva semplice
|
|
const ICurve* pOriCurve = ::GetCurve( pCompo->GetCurve( Id.nSub)) ;
|
|
if ( pOriCurve == nullptr)
|
|
return false ;
|
|
// la duplico
|
|
pCurve.Set( pOriCurve->Clone()) ;
|
|
// recupero estrusione e spessore
|
|
Vector3d vtExtr ;
|
|
if ( ! pCompo->GetExtrusion( vtExtr) || vtExtr.IsSmall())
|
|
vtExtr = Z_AX ;
|
|
pCurve->SetExtrusion( vtExtr) ;
|
|
double dThick ;
|
|
if ( pCompo->GetThickness( dThick))
|
|
pCurve->SetThickness( dThick) ;
|
|
}
|
|
if ( IsNull( pCurve))
|
|
return false ;
|
|
// la porto in globale
|
|
pCurve->ToGlob( frGlob) ;
|
|
// la restituisco
|
|
lstPC.emplace_back( Release( pCurve)) ;
|
|
return true ;
|
|
}
|
|
// se superficie TriMesh
|
|
else if ( nType == SRF_TRIMESH)
|
|
return true ;
|
|
// se superficie Bezier
|
|
else if ( nType == SRF_BEZIER)
|
|
return true ;
|
|
// altrimenti errore
|
|
else
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::Chain( int nGrpDestId)
|
|
{
|
|
|
|
// vettore puntatori alle curve
|
|
ICURVEPOVECTOR vpCrvs ;
|
|
vpCrvs.reserve( m_vId.size()) ;
|
|
// vettore selettori delle curve originali
|
|
SELVECTOR vInds ;
|
|
// recupero tutte le curve e le porto in globale
|
|
for ( const auto& Id : m_vId) {
|
|
// prendo le curve
|
|
ICURVEPLIST lstPC ;
|
|
if ( ! GetCurves( Id, lstPC)) {
|
|
string sInfo = "Warning in SurfFinishing : Skipped entity " + ToString( Id) ;
|
|
m_pMchMgr->SetWarning( 3151, sInfo) ;
|
|
}
|
|
for ( auto pCrv : lstPC) {
|
|
vpCrvs.emplace_back( pCrv) ;
|
|
vInds.emplace_back( Id) ;
|
|
}
|
|
}
|
|
|
|
// se finitura a proiezione di curve
|
|
if ( m_Params.m_nSubType == SURFFIN_SUB_PROJECT) {
|
|
int nGroupName = -1 ;
|
|
for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) {
|
|
// creo nuovo gruppo
|
|
int nPathId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpDestId, Frame3d()) ;
|
|
if ( nPathId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPathId, MCH_PATH + ToString( ++ nGroupName)) ;
|
|
m_pGeomDB->SetInfo( nPathId, KEY_IDS, ToString( nGroupName)) ;
|
|
// definisco la curva composita associata
|
|
PtrOwner<ICurveComposite> pCrvCompo( ConvertCurveToComposite( Release( vpCrvs[i]))) ;
|
|
if ( IsNull( pCrvCompo) || ! pCrvCompo->IsValid())
|
|
return false ;
|
|
int nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::CloneCurveComposite( pCrvCompo)) ;
|
|
if ( nNewId == GDB_ID_NULL)
|
|
return false ;
|
|
// memorizzo la Thickness e l'Estrusione nelle Info del gruppo
|
|
double dThick ; pCrvCompo->GetThickness( dThick) ;
|
|
Vector3d vtExtr ; pCrvCompo->GetExtrusion( vtExtr) ;
|
|
m_pGeomDB->SetInfo( nNewId, KEY_THICK, dThick) ;
|
|
m_pGeomDB->SetInfo( nNewId, KEY_EXTR, vtExtr) ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
// preparo i dati per il concatenamento
|
|
Vector3d vtExtr = Z_AX ;
|
|
bool bFirst = true ;
|
|
Point3d ptNear = ORIG ;
|
|
double dToler = 10 * EPS_SMALL ;
|
|
ChainCurves chainC ;
|
|
chainC.Init( true, dToler, int( vpCrvs.size())) ;
|
|
for ( size_t i = 0 ; i < vpCrvs.size() ; ++ i) {
|
|
// recupero la curva e il suo riferimento
|
|
ICurve* pCrv = vpCrvs[i] ;
|
|
if ( pCrv == nullptr)
|
|
continue ;
|
|
// recupero i dati della curva necessari al concatenamento e li assegno
|
|
Point3d ptStart, ptEnd ;
|
|
Vector3d vtStart, vtEnd ;
|
|
if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) ||
|
|
! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd))
|
|
return false ;
|
|
if ( ! chainC.AddCurve( int( i + 1), ptStart, vtStart, ptEnd, vtEnd))
|
|
return false ;
|
|
// se prima curva, assegno inizio della ricerca
|
|
if ( bFirst) {
|
|
pCrv->GetExtrusion( vtExtr) ;
|
|
ptNear = ptStart + 10 * EPS_SMALL * vtStart ;
|
|
bFirst = false ;
|
|
}
|
|
// altrimenti
|
|
else {
|
|
Vector3d vtTmpExtr ; pCrv->GetExtrusion( vtTmpExtr) ;
|
|
if ( ! AreSameVectorApprox( vtTmpExtr, vtExtr)) {
|
|
m_pMchMgr->SetLastError( 3128, "Error in SurfFinishing : Curves with different extrusion") ;
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
// recupero i percorsi concatenati e definisco la regione piana di svuotatura
|
|
SurfFlatRegionByContours SfrByC ;
|
|
INTVECTOR vnId2 ;
|
|
while ( chainC.GetChainFromNear( ptNear, false, vnId2)) {
|
|
// creo una curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return false ;
|
|
// estrusione e spessore
|
|
Vector3d vtExtr = Z_AX ;
|
|
double dThick = 0 ;
|
|
// vettore Id originali
|
|
SELVECTOR vId2 ;
|
|
vId2.reserve( vnId2.size()) ;
|
|
// recupero le curve semplici e le inserisco nella curva composita
|
|
for ( size_t i = 0 ; i < vnId2.size() ; ++ i) {
|
|
int nId = abs( vnId2[i]) - 1 ;
|
|
bool bInvert = ( vnId2[i] < 0) ;
|
|
vId2.emplace_back( vInds[nId]) ;
|
|
// recupero la curva
|
|
ICurve* pCrv = vpCrvs[nId] ;
|
|
// se necessario, la inverto
|
|
if ( bInvert)
|
|
pCrv->Invert() ;
|
|
// recupero eventuali estrusione e spessore
|
|
Vector3d vtTemp ;
|
|
if ( pCrv->GetExtrusion( vtTemp)) {
|
|
vtExtr = vtTemp ;
|
|
double dTemp ;
|
|
if ( pCrv->GetThickness( dTemp) && abs( dTemp) > abs( dThick))
|
|
dThick = dTemp ;
|
|
}
|
|
// la aggiungo alla curva composta
|
|
if ( ! pCrvCompo->AddCurve( ::Release( vpCrvs[nId]), true, dToler))
|
|
return false ;
|
|
}
|
|
// se non sono state inserite curve, vado oltre
|
|
if ( pCrvCompo->GetCurveCount() == 0)
|
|
continue ;
|
|
// imposto estrusione e spessore
|
|
pCrvCompo->SetExtrusion( vtExtr) ;
|
|
pCrvCompo->SetThickness( dThick) ;
|
|
// verifico sia piana e se necessario la appiattisco
|
|
PtrOwner<ICurve> pFlatCrv( FlattenCurve( *pCrvCompo, 50 * EPS_SMALL, 50 * EPS_ANG_SMALL, FLTCRV_USE_EXTR)) ;
|
|
if ( IsNull( pFlatCrv)) {
|
|
Plane3d plPlane ;
|
|
if ( ! pCrvCompo->IsFlat( plPlane, true, 50 * EPS_SMALL))
|
|
m_pMchMgr->SetLastError( 2403, "Error in SurfFinishing : Contour Not Flat") ;
|
|
else
|
|
m_pMchMgr->SetLastError( 2404, "Error in SurfFinishing : Tool Not Perpendicular to Flat Area") ;
|
|
return false ;
|
|
}
|
|
pFlatCrv->GetExtrusion( vtExtr) ;
|
|
pCrvCompo->Clear() ;
|
|
pCrvCompo->AddCurve( Release( pFlatCrv)) ;
|
|
// salvo vettore estrusione
|
|
pCrvCompo->SetExtrusion( vtExtr) ;
|
|
// salvo la thickness come seconda temp prop ( la Sfr rimuove la thick delle curve)
|
|
pCrvCompo->SetTempParam( dThick, 1) ;
|
|
// aggiorno il nuovo punto vicino
|
|
pCrvCompo->GetEndPoint( ptNear) ;
|
|
// se utile, approssimo con archi
|
|
if ( ! ApproxWithArcsIfUseful( pCrvCompo))
|
|
return false ;
|
|
// inserisco la curva nella regione piana
|
|
SfrByC.AddCurve( Release( pCrvCompo)) ;
|
|
}
|
|
|
|
// scorro le regioni piane ricavate dalle curve
|
|
int nGroupName = -1 ;
|
|
PtrOwner<ISurfFlatRegion> pSfrCurr( SfrByC.GetSurf()) ;
|
|
while ( ! IsNull( pSfrCurr) && pSfrCurr->IsValid()) {
|
|
// la normale del Chunk deve essere coerente con l'estrusione ricavata
|
|
if ( AreOppositeVectorApprox( pSfrCurr->GetNormVersor(), vtExtr))
|
|
pSfrCurr->Invert() ;
|
|
// per ogni Chunk
|
|
for ( int nC = 0 ; nC < pSfrCurr->GetChunkCount() ; ++ nC) {
|
|
// creo nuovo gruppo
|
|
int nPathId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpDestId, Frame3d()) ;
|
|
if ( nPathId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPathId, MCH_PATH + ToString( ++ nGroupName)) ;
|
|
m_pGeomDB->SetInfo( nPathId, KEY_IDS, ToString( nGroupName)) ;
|
|
// recupero il Chunk corrente
|
|
PtrOwner<ISurfFlatRegion> pSfrChunk( pSfrCurr->CloneChunk( nC)) ;
|
|
if ( IsNull( pSfrChunk) || ! pSfrChunk->IsValid())
|
|
return false ;
|
|
int nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::CloneSurfFlatRegion( pSfrChunk)) ;
|
|
if ( nNewId == GDB_ID_NULL)
|
|
return false ;
|
|
// salvo eventuali lati aperti per il Chunk corrente
|
|
for ( int nL = 0 ; nL < pSfrChunk->GetLoopCount( 0) ; ++ nL) {
|
|
// recupero il Loop
|
|
PtrOwner<ICurveComposite> pCrvLoop( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, nL))) ;
|
|
if ( IsNull( pCrvLoop) || ! pCrvLoop->IsValid())
|
|
return false ;
|
|
// memorizzo le proprietà di lato aperto nelle Info del gruppo
|
|
INTVECTOR vIndOpen ;
|
|
for ( int nU = 0 ; nU < pCrvLoop->GetCurveCount() ; ++ nU) {
|
|
int nTmpProp0 = TEMP_PROP_INVALID ;
|
|
if ( pCrvLoop->GetCurveTempProp( nU, nTmpProp0, 0) && nTmpProp0 == TEMP_PROP_OPEN_EDGE)
|
|
vIndOpen.emplace_back( nU) ;
|
|
}
|
|
// memorizzo la Thickness e l'Estrusione nelle Info del gruppo
|
|
if ( nL == 0) {
|
|
double dThick = pCrvLoop->GetTempParam( 1) ;
|
|
m_pGeomDB->SetInfo( nNewId, KEY_THICK, dThick) ;
|
|
m_pGeomDB->SetInfo( nNewId, KEY_EXTR, vtExtr) ;
|
|
}
|
|
}
|
|
}
|
|
// aggiorno la regione piana con la successiva calcolata
|
|
pSfrCurr.Set( SfrByC.GetSurf()) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetSurfacesByIds( SURFLOCALVECTOR& vSrfLoc, SURFLOCALVECTOR& vSrfSuppLoc, Frame3d& frSurf)
|
|
{
|
|
// funzione che restituisce le superfici attive, le superfici di supporto e il frame di riferimento
|
|
vSrfLoc.clear() ;
|
|
vSrfSuppLoc.clear() ;
|
|
// recupero le superfici attive e le superfici nel Layer di supporto
|
|
INTVECTOR vSurfId, vSurfSuppId ;
|
|
GetActiveSurfaces( vSurfId, vSurfSuppId) ;
|
|
// porto tutte le superfici nel riferimento della prima
|
|
for ( int& nSurfId : vSurfId) {
|
|
if ( vSrfLoc.empty()) {
|
|
if ( ! m_pGeomDB->GetGlobFrame( nSurfId, frSurf))
|
|
return false ;
|
|
}
|
|
vSrfLoc.emplace_back( m_pGeomDB, nSurfId, frSurf) ;
|
|
}
|
|
if ( ! frSurf.IsValid())
|
|
return false ;
|
|
for ( int& nSrfSuppId : vSurfSuppId)
|
|
vSrfSuppLoc.emplace_back( m_pGeomDB, nSrfSuppId, frSurf) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcRegionElevation( const ISurfFlatRegion* pSfr, const Vector3d& vtTool,
|
|
double dRad, double dLen, double& dElev) const
|
|
{
|
|
// controllo dei parametri
|
|
if ( pSfr == nullptr || ! pSfr->IsValid())
|
|
return false ;
|
|
// inizializzo l'elevazione
|
|
dElev = 0. ;
|
|
|
|
// recupero tutti i loop della regione
|
|
for ( int nC = 0 ; nC < pSfr->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) ; ++ nL) {
|
|
// recupero la curva
|
|
PtrOwner<ICurveComposite> pCrvLoop( ConvertCurveToComposite( pSfr->GetLoop( nC, nL))) ;
|
|
if ( IsNull( pCrvLoop) || ! pCrvLoop->IsValid())
|
|
return false ;
|
|
// se isola inverto
|
|
if ( nL > 0)
|
|
pCrvLoop->Invert() ;
|
|
// approssimo la curva con una polilinea che uso per creare il poligono equivalente
|
|
PolyLine PL ;
|
|
if ( ! pCrvLoop->ApproxWithLines( LIN_TOL_RAW, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL))
|
|
return false ;
|
|
Polygon3d pgFacet ;
|
|
if ( ! pgFacet.FromPolyLine( PL))
|
|
return false ;
|
|
// inizializzo l'elevazione corrente
|
|
double dMyElev = 0. ;
|
|
|
|
// inizializzo elevazioni per ogni grezzo
|
|
INTDBLVECTOR vRawElev ;
|
|
// ciclo sui grezzi della fase
|
|
int nRawId = m_pMchMgr->GetFirstRawPart() ;
|
|
while ( nRawId != GDB_ID_NULL) {
|
|
// verifico che il grezzo compaia nella fase
|
|
if ( m_pMchMgr->VerifyRawPartPhase( nRawId, m_nPhase)) {
|
|
// recupero la trimesh del grezzo
|
|
int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ;
|
|
if ( pStm != nullptr) {
|
|
// recupero il riferimento della trimesh
|
|
Frame3d frStm ;
|
|
m_pGeomDB->GetGlobFrame( nStmId, frStm) ;
|
|
// porto il poligono in questo riferimento
|
|
Polygon3d pgFacetL = pgFacet ;
|
|
pgFacetL.ToLoc( frStm) ;
|
|
// calcolo l'elevazione
|
|
double dCurrElev ;
|
|
if ( ! PolygonElevationInClosedSurfTm( pgFacetL, *pStm, true, dCurrElev))
|
|
return false ;
|
|
if ( dCurrElev > EPS_SMALL)
|
|
vRawElev.emplace_back( nStmId, dCurrElev) ;
|
|
}
|
|
}
|
|
// passo al grezzo successivo
|
|
nRawId = m_pMchMgr->GetNextRawPart( nRawId) ;
|
|
}
|
|
// se trovate elevazioni
|
|
if ( ! vRawElev.empty()) {
|
|
// ordino il vettore secondo l'elevazione crescente
|
|
sort( vRawElev.begin(), vRawElev.end(), []( const INTDBL& a, const INTDBL& b) {
|
|
return a.second < b.second ;
|
|
}) ;
|
|
// box dell'insieme delle posizioni utensile all'inizio
|
|
const double MAX_DIST_RAW = 200.0 ;
|
|
BBox3d b3Tool ;
|
|
pgFacet.GetLocalBBox( b3Tool) ;
|
|
b3Tool.Add( b3Tool.GetMin() + dLen * vtTool) ;
|
|
b3Tool.Add( b3Tool.GetMax() + dLen * vtTool) ;
|
|
if ( vtTool.IsX())
|
|
b3Tool.Expand( 0, dRad, dRad) ;
|
|
else if ( vtTool.IsY())
|
|
b3Tool.Expand( dRad, 0, dRad) ;
|
|
else if ( vtTool.IsZ())
|
|
b3Tool.Expand( dRad, dRad, 0) ;
|
|
else {
|
|
double dExpandX = dRad * sqrt( 1 - vtTool.x * vtTool.x) ;
|
|
double dExpandY = dRad * sqrt( 1 - vtTool.y * vtTool.y) ;
|
|
double dExpandZ = dRad * sqrt( 1 - vtTool.z * vtTool.z) ;
|
|
b3Tool.Expand( dExpandX, dExpandY, dExpandZ) ;
|
|
}
|
|
b3Tool.Expand( MAX_DIST_RAW) ;
|
|
// verifico la reale interferenza dell'utensile con i diversi grezzi
|
|
for ( int i = 0 ; i < int( vRawElev.size()) ; ++ i) {
|
|
// box del grezzo
|
|
BBox3d b3Raw ;
|
|
m_pGeomDB->GetGlobalBBox( vRawElev[i].first, b3Raw) ;
|
|
// confronto con il box dell'utensile nella posizione precedente
|
|
BBox3d b3CurrTool = b3Tool ;
|
|
b3CurrTool.Translate( dMyElev * vtTool) ;
|
|
if ( b3Raw.Overlaps( b3CurrTool))
|
|
dMyElev = vRawElev[i].second ;
|
|
}
|
|
}
|
|
dElev = max( dElev, dMyElev) ;
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SetCAvTlStmForSurfaces( ICAvToolSurfTm* pCAvTlStm, const ISurfFlatRegion* pSfrCnt, double dDepth,
|
|
double dToolLen, double dToolDiam, double dToolCornRad,
|
|
double dToolSideAng, double dToolMaxMat, double dMachOffsR,
|
|
const SURFLOCALVECTOR& vSurfLoc, const SURFLOCALVECTOR& vSurfSuppLoc)
|
|
{
|
|
// controllo dei parametri
|
|
if ( pCAvTlStm == nullptr || vSurfLoc.empty())
|
|
return false ;
|
|
|
|
// definisco l'ambiente di correzione dei percorsi utensili
|
|
if ( abs( dToolSideAng) < EPS_ANG_SMALL)
|
|
pCAvTlStm->SetStdTool( dToolLen + dMachOffsR, dToolDiam / 2. + dMachOffsR, dToolCornRad + dMachOffsR) ;
|
|
else {
|
|
double dDeltaRad ;
|
|
double dSideAngRad = dToolSideAng * DEGTORAD ;
|
|
if ( dToolSideAng > 0) {
|
|
if ( dToolCornRad < EPS_SMALL)
|
|
dDeltaRad = dToolMaxMat * tan( dSideAngRad) ;
|
|
else
|
|
dDeltaRad = dToolCornRad * cos( dSideAngRad) +
|
|
( dToolMaxMat + dToolCornRad * ( sin( dSideAngRad) - 1)) * tan( dSideAngRad) ;
|
|
}
|
|
else
|
|
dDeltaRad = tan( dSideAngRad) * dToolMaxMat ;
|
|
double dStemRad = dToolDiam / 2. + dDeltaRad ;
|
|
double dTipRad = dToolDiam / 2. ;
|
|
pCAvTlStm->SetAdvTool( dToolLen + dMachOffsR, dStemRad + dMachOffsR,
|
|
dToolMaxMat, dTipRad + dMachOffsR, dToolCornRad + dMachOffsR) ;
|
|
}
|
|
|
|
// aggiungo tutte le superfici di lavoro
|
|
for ( int i = 0 ; i < int( vSurfLoc.size()) ; ++ i) {
|
|
// superfici ammesse : TriMesh, Bezier
|
|
const ISurf* pSurf = GetSurf( vSurfLoc[i].Get()) ;
|
|
if ( pSurf != nullptr && pSurf->IsValid()) {
|
|
int nType = pSurf->GetType() ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pSurf) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) {
|
|
if ( i == 0)
|
|
pCAvTlStm->SetSurfTm( *pStm) ;
|
|
else
|
|
pCAvTlStm->AddSurfTm( *pStm) ;
|
|
}
|
|
}
|
|
// se Bezier
|
|
else if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurf) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pStm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) {
|
|
if ( i == 0)
|
|
pCAvTlStm->SetSurfTm( *pStm) ;
|
|
else
|
|
pCAvTlStm->AddSurfTm( *pStm) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// aggiungo le superfici di supporto
|
|
if ( ! vSurfSuppLoc.empty()) {
|
|
/* Se considero interamente la superficie di supporto ho diversi svantaggi :
|
|
1) Incrementa notevolmente il Box complessivo delle superfici di lavoro
|
|
=> Ho molti più punti nelle griglie di campionamento per Silhouette o percorsi di collisione
|
|
2) Calcolo l'Offset di TriMesh di parti "lontane" dalla regione corrente di lavoro
|
|
=> Più tempo computazionale per Offset
|
|
=> Superfici con più triangoli
|
|
*/
|
|
// definisco una superficie di contenimento ; L'Offset verrà fatto solo sulle parti di Stm interne ad essa
|
|
PtrOwner<ISurfTriMesh> pStmContainment( CreateSurfTriMesh()) ;
|
|
if ( IsNull( pStmContainment))
|
|
return false ;
|
|
if ( pSfrCnt != nullptr && pSfrCnt->IsValid() && abs( dDepth) > 10 * EPS_SMALL) {
|
|
// considero la regione complessiva di lavoro dell'utensile all'interno della quale non può uscire
|
|
double dOffs = dToolDiam / 2. + m_Params.m_dOverlap + SUPP_SURF_RADIAL_OFFS + 50 * EPS_SMALL ;
|
|
PtrOwner<ISurfFlatRegion> pSfrFreeMove( pSfrCnt->CreateOffsetSurf( dOffs, ICurve::OFF_FILLET)) ;
|
|
if ( IsNull( pSfrFreeMove) || ! pSfrFreeMove->IsValid())
|
|
return false ;
|
|
// definisco una TriMesh di estrusione da questa regione
|
|
pSfrFreeMove->Translate( - dDepth * pSfrCnt->GetNormVersor()) ;
|
|
CICURVEPVECTOR vpCrv ;
|
|
for ( int nC = 0 ; nC < pSfrFreeMove->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pSfrFreeMove->GetLoopCount( nC) ; ++ nL)
|
|
vpCrv.emplace_back( pSfrFreeMove->GetLoop( nC, nL)) ;
|
|
}
|
|
pStmContainment.Set( GetSurfTriMeshByRegionExtrusion( vpCrv, ( dDepth + dToolLen) * pSfrCnt->GetNormVersor())) ;
|
|
}
|
|
|
|
// definisco la tolleranza lineare per Offset
|
|
double dLinTol = 2. ;
|
|
// recupero le superfici singole ( più veloce che calcolare Offset complessivo)
|
|
for ( const SurfLocal& SurfSupp : vSurfSuppLoc) {
|
|
// le superfici di supporto devono essere ben definite ed avere un volume chiuso
|
|
const ISurf* pSurfSupp = GetSurf( SurfSupp.Get()) ;
|
|
if ( pSurfSupp == nullptr || ! pSurfSupp->IsValid())
|
|
continue ;
|
|
int nType = pSurfSupp->GetType() ;
|
|
PtrOwner<ISurfTriMesh> pTruncStm ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pSurfSupp) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) {
|
|
if ( ! pTruncStm.Set( CloneSurfTriMesh( pStm)))
|
|
continue ;
|
|
}
|
|
}
|
|
// se Bezier
|
|
else if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurfSupp) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pStm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) {
|
|
if ( ! pTruncStm.Set( CloneSurfTriMesh( pStm)))
|
|
continue ;
|
|
}
|
|
}
|
|
}
|
|
// tengo la la tengo la parte di superficie
|
|
if ( IsNull( pTruncStm) || ! pTruncStm->IsValid())
|
|
return false ;
|
|
if ( ! IsNull( pStmContainment) && pStmContainment->IsValid() &&
|
|
pStmContainment->GetTriangleCount() > 0 && pStmContainment->IsClosed()) {
|
|
PtrOwner<ISurfTriMesh> pStmTemp( CloneSurfTriMesh( pTruncStm)) ;
|
|
if ( IsNull( pStmTemp) || ! pStmTemp->IsValid())
|
|
return false ;
|
|
if ( pStmTemp->Intersect( *pStmContainment) && pStmTemp->IsClosed())
|
|
pTruncStm.Set( Release( pStmTemp)) ;
|
|
}
|
|
// calcolo l'Offset
|
|
if ( ! IsNull( pTruncStm) && pTruncStm->IsValid()) {
|
|
PtrOwner<ISurfTriMesh> pStmSuppOffs( CreateSurfTriMeshOffset( pTruncStm, SUPP_SURF_RADIAL_OFFS, dLinTol)) ;
|
|
if ( ! IsNull( pStmSuppOffs) && pStmSuppOffs->IsValid() && pStmSuppOffs->GetTriangleCount() > 0)
|
|
pCAvTlStm->AddSurfTm( *Release( pStmSuppOffs)) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::EraseMaxDownSurf( const SURFLOCALVECTOR& vSurfLoc, const Frame3d& frSurf, const Vector3d& vtTool,
|
|
double dDepth, ISurfFlatRegion* pSfrCnt)
|
|
{
|
|
// controllo dei parametri
|
|
if ( vSurfLoc.empty() || pSfrCnt == nullptr || ! pSfrCnt->IsValid())
|
|
return true ;
|
|
|
|
// calcolo silhouette dell'insieme di superfici
|
|
CISURFTMPVECTOR vpStm ; vpStm.reserve( vSurfLoc.size()) ;
|
|
for ( int i = 0 ; i < int( vSurfLoc.size()) ; ++ i) {
|
|
// recupero la superficie
|
|
const ISurf* pSurf = GetSurf( vSurfLoc[i].Get()) ;
|
|
if ( pSurf == nullptr || ! pSurf->IsValid())
|
|
continue ;
|
|
int nType = pSurf->GetType() ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pSurf) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
// se Bezier
|
|
else if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurf) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pStm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
}
|
|
}
|
|
// determino il frame locale delle superfici analizzando la prima
|
|
Frame3d frPocket ;
|
|
Point3d ptCen ; pSfrCnt->GetCentroid( ptCen) ;
|
|
frPocket.Set( ptCen, vtTool) ;
|
|
frPocket.ToLoc( frSurf) ;
|
|
const double SILH_TOL = 1. ;
|
|
PtrOwner<ICAvParSilhouettesSurfTm> pCavParSilh( CreateCAvParSilhouettesSurfTm()) ;
|
|
if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vpStm, frPocket, SILH_TOL))
|
|
return false ;
|
|
POLYLINEVECTOR vPL ;
|
|
if ( ! pCavParSilh->GetSilhouette( - dDepth, vPL))
|
|
return false ;
|
|
// creazione della regione piana dalle PolyLine ricavate dalla Silhouette
|
|
const double SILH_ARC_TOL = SILH_TOL / 10. ;
|
|
const double SILH_ARC_FEA_MAX = 100. ;
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( auto& PL : vPL) {
|
|
// recupero la curva dalla silhouette
|
|
PtrOwner<ICurveComposite> pSilCrv( CreateCurveComposite()) ;
|
|
if ( IsNull( pSilCrv))
|
|
return false ;
|
|
pSilCrv->FromPolyLine( PL) ;
|
|
// approssimo con archi
|
|
PolyArc PA ;
|
|
if ( pSilCrv->ApproxWithArcsEx( SILH_ARC_TOL, ANG_TOL_STD_DEG, SILH_ARC_FEA_MAX, PA)) {
|
|
PtrOwner<ICurveComposite> pTempCrv( CreateCurveComposite()) ;
|
|
if ( ! IsNull( pTempCrv) &&
|
|
pTempCrv->FromPolyArc( PA) &&
|
|
pTempCrv->RemoveSmallDefects( SILH_ARC_TOL / 2., ANG_TOL_STD_DEG) &&
|
|
pTempCrv->MergeCurves( SILH_ARC_TOL / 2., ANG_TOL_STD_DEG))
|
|
pSilCrv.Set( pTempCrv) ;
|
|
}
|
|
// aggiungo per regione
|
|
if ( ! SfrMaker.AddCurve( Release( pSilCrv)))
|
|
return false ;
|
|
}
|
|
PtrOwner<ISurfFlatRegion> pSfrSil( SfrMaker.GetSurf()) ;
|
|
if ( ! IsNull( pSfrSil)) {
|
|
pSfrSil->ToGlob( frSurf) ;
|
|
double dPockRadOffs = SILH_ARC_TOL ;
|
|
pSfrSil->Offset( dPockRadOffs, ICurve::OFF_CHAMFER) ;
|
|
// intersezione tra contorno e regione
|
|
if ( ! pSfrCnt->Intersect( *pSfrSil)) {
|
|
// ricreo la regione originale
|
|
PtrOwner<ISurfFlatRegion> pSfrCntCopy( CloneSurfFlatRegion( pSfrCnt)) ;
|
|
if ( IsNull( pSfrCntCopy) || ! pSfrCntCopy->IsValid())
|
|
return false ;
|
|
pSfrCnt->Clear() ;
|
|
pSfrCnt->CopyFrom( pSfrCntCopy) ;
|
|
}
|
|
// azzero le proprietà delle curve semplici dei contorni delle regioni ( se 1 lato aperto)
|
|
for ( int nC = 0 ; nC < pSfrCnt->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pSfrCnt->GetLoopCount( nC) ; ++ nL) {
|
|
for ( int nCrv = 0 ; ; ++ nCrv) {
|
|
if ( ! pSfrCnt->SetCurveTempProp( nC, nL, nCrv, TEMP_PROP_CLOSE_EDGE, 0) ||
|
|
! pSfrCnt->SetCurveTempProp( nC, nL, nCrv, TEMP_PROP_CLOSE_EDGE, 1))
|
|
break ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::ProcessCrvCompo( int nPathId, int nPvId, int nClId)
|
|
{
|
|
// recupero gruppo per geometria temporanea
|
|
const string GRP_TEMP = "Temp" ;
|
|
int nTempId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, GRP_TEMP) ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nTempId == GDB_ID_NULL) {
|
|
nTempId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nTempId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nTempId, GRP_TEMP) ;
|
|
}
|
|
// altrimenti lo svuoto
|
|
else
|
|
m_pGeomDB->EmptyGroup( nTempId) ;
|
|
// in ogni caso lo dichiaro temporaneo e non visibile
|
|
m_pGeomDB->SetLevel( nTempId, GDB_LV_TEMP) ;
|
|
m_pGeomDB->SetStatus( nTempId, GDB_ST_OFF) ;
|
|
|
|
// recupero la curva composita dal database geometrico
|
|
int nCrvCompoId = m_pGeomDB->GetFirstInGroup( nPathId) ;
|
|
if ( m_pGeomDB->GetGeoType( nCrvCompoId) != CRV_COMPO)
|
|
return false ;
|
|
|
|
// copio la curva composits da elaborare
|
|
int nCopyId = m_pGeomDB->CopyGlob( nCrvCompoId, GDB_ID_NULL, nTempId) ;
|
|
if ( nCopyId == GDB_ID_NULL)
|
|
return false ;
|
|
const ICurveComposite* pCrvCompoGDB( GetCurveComposite( m_pGeomDB->GetGeoObj( nCopyId))) ;
|
|
if ( ! pCrvCompoGDB->IsValid())
|
|
return false ;
|
|
|
|
// recupero estrusione e spessore
|
|
Vector3d vtExtr = Z_AX ;
|
|
if ( m_pGeomDB->ExistsInfo( nCrvCompoId, KEY_EXTR))
|
|
m_pGeomDB->GetInfo( nCrvCompoId, KEY_EXTR, vtExtr) ;
|
|
double dThick = 0. ;
|
|
if ( m_pGeomDB->ExistsInfo( nCrvCompoId, KEY_THICK))
|
|
m_pGeomDB->GetInfo( nCrvCompoId, KEY_THICK, dThick) ;
|
|
|
|
// valuto l'espressione dell'affondamento
|
|
ExeLuaSetGlobNumVar( "TH", abs( dThick)) ;
|
|
double dDepth ;
|
|
string sMyDepth = m_Params.m_sDepth ;
|
|
if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) {
|
|
m_pMchMgr->SetLastError( 3108, "Error in SurfFinishing : Depth not computable") ;
|
|
return false ;
|
|
}
|
|
// se spessore positivo, lo sottraggo al risultato
|
|
if ( dThick > 0)
|
|
dDepth -= dThick ;
|
|
|
|
// verifico che la curva sia piana
|
|
Plane3d plPlane ;
|
|
if ( ! pCrvCompoGDB->IsFlat( plPlane)) {
|
|
m_pMchMgr->SetLastError( 3005, "Error in SurfFinishing : Contour Not Flat") ;
|
|
return false ;
|
|
}
|
|
|
|
// recupero nome del path
|
|
string sPathName ;
|
|
m_pGeomDB->GetName( nPathId, sPathName) ;
|
|
|
|
// assegno il versore fresa
|
|
Vector3d vtTool = vtExtr ;
|
|
|
|
// se richiesta lavorazione
|
|
if ( nClId != GDB_ID_NULL) {
|
|
// creo gruppo per geometria di lavorazione del percorso
|
|
int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nClId, Frame3d()) ;
|
|
if ( nPxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPxId, sPathName) ;
|
|
m_pGeomDB->SetMaterial( nPxId, BLUE) ;
|
|
|
|
// verifico se archi vanno approssimati con segmenti di retta
|
|
bool bSplitArcs = GetSplitArcs( vtTool) ;
|
|
|
|
// recupero le superfici di lavoro e di supporto
|
|
SURFLOCALVECTOR vSrfLoc, vSrfLocSupp ;
|
|
Frame3d frSurf ;
|
|
if ( ! GetSurfacesByIds( vSrfLoc, vSrfLocSupp, frSurf)) {
|
|
m_pMchMgr->SetLastError( 3123, "Error in SurfFinishing : missing surfaces") ;
|
|
return false ;
|
|
}
|
|
|
|
// predispongo l'ambiente di correzione dei percorsi utensili
|
|
PtrOwner<ICAvToolSurfTm> pCAvTlStm( CreateCAvToolSurfTm()) ;
|
|
if ( IsNull( pCAvTlStm) ||
|
|
! SetCAvTlStmForSurfaces( pCAvTlStm, nullptr, dDepth, m_TParams.m_dLen, m_TParams.m_dDiam,
|
|
m_TParams.m_dCornRad, m_TParams.m_dSideAng, m_TParams.m_dMaxMat,
|
|
GetOffsR(), vSrfLoc, vSrfLocSupp)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
|
|
// Imposto dati comuni
|
|
SetPathId( nPxId) ;
|
|
SetToolDir( vtTool) ;
|
|
Vector3d vtAux ;
|
|
if ( GetValInNotes( m_Params.m_sUserNotes, UN_VTAUXDIR, vtAux))
|
|
vtAux.Normalize() ;
|
|
SetAuxDir( vtAux) ;
|
|
|
|
|
|
// assegno il vettore estrusione al gruppo del percorso
|
|
m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ;
|
|
|
|
// Eseguo la lavorazione a seconda del tipo
|
|
double dElev = dDepth ;
|
|
|
|
switch ( m_Params.m_nSubType) {
|
|
case SURFFIN_SUB_PROJECT :
|
|
if ( ! AddProjection( pCAvTlStm, vSrfLoc, frSurf, pCrvCompoGDB, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
break ;
|
|
}
|
|
}
|
|
|
|
// incremento numero di percorsi
|
|
++ m_nPaths ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::ProcessSfr( int nPathId, int nPvId, int nClId)
|
|
{
|
|
// recupero gruppo per geometria temporanea
|
|
const string GRP_TEMP = "Temp" ;
|
|
int nTempId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, GRP_TEMP) ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nTempId == GDB_ID_NULL) {
|
|
nTempId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nTempId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nTempId, GRP_TEMP) ;
|
|
}
|
|
// altrimenti lo svuoto
|
|
else
|
|
m_pGeomDB->EmptyGroup( nTempId) ;
|
|
// in ogni caso lo dichiaro temporaneo e non visibile
|
|
m_pGeomDB->SetLevel( nTempId, GDB_LV_TEMP) ;
|
|
m_pGeomDB->SetStatus( nTempId, GDB_ST_OFF) ;
|
|
|
|
// recupero la regione piana dal database geometrico
|
|
int nSfrId = m_pGeomDB->GetFirstInGroup( nPathId) ;
|
|
if ( m_pGeomDB->GetGeoType( nSfrId) != SRF_FLATRGN)
|
|
return false ;
|
|
|
|
// copio la regione piana da elaborare
|
|
int nCopyId = m_pGeomDB->CopyGlob( nSfrId, GDB_ID_NULL, nTempId) ;
|
|
if ( nCopyId == GDB_ID_NULL)
|
|
return false ;
|
|
const ISurfFlatRegion* pSfrGDB( GetSurfFlatRegion( m_pGeomDB->GetGeoObj( nCopyId))) ;
|
|
if ( ! pSfrGDB->IsValid())
|
|
return false ;
|
|
|
|
// recupero estrusione e spessore
|
|
Vector3d vtExtr = Z_AX ;
|
|
if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_EXTR))
|
|
m_pGeomDB->GetInfo( nSfrId, KEY_EXTR, vtExtr) ;
|
|
double dThick = 0. ;
|
|
if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_THICK))
|
|
m_pGeomDB->GetInfo( nSfrId, KEY_THICK, dThick) ;
|
|
|
|
// valuto l'espressione dell'affondamento
|
|
ExeLuaSetGlobNumVar( "TH", abs( dThick)) ;
|
|
double dDepth ;
|
|
string sMyDepth = m_Params.m_sDepth ;
|
|
if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) {
|
|
m_pMchMgr->SetLastError( 3108, "Error in SurfFinishing : Depth not computable") ;
|
|
return false ;
|
|
}
|
|
// se spessore positivo, lo sottraggo al risultato
|
|
if ( dThick > 0)
|
|
dDepth -= dThick ;
|
|
|
|
// recupero il Loop esterno della regione da svuotatare
|
|
PtrOwner<ICurve> pCrvExt( pSfrGDB->GetLoop( 0, 0)) ;
|
|
if ( IsNull( pCrvExt) || ! pCrvExt->IsValid())
|
|
return false ;
|
|
|
|
// verifico sia piana e sistemo senso antiorario visto dalla direzione di estrusione
|
|
Plane3d plPlane ; double dArea ;
|
|
if ( ! pCrvExt->GetArea( plPlane, dArea)) {
|
|
m_pMchMgr->SetLastError( 3005, "Error in SurfFinishing : Contour Not Flat") ;
|
|
return false ;
|
|
}
|
|
if ( abs( plPlane.GetVersN() * vtExtr) < cos( 10 * EPS_ANG_SMALL)) {
|
|
m_pMchMgr->SetLastError( 3006, "Error in SurfFinishing : Tool Dir not perpendicular to Flat Area") ;
|
|
return false ;
|
|
}
|
|
if ( plPlane.GetVersN() * vtExtr * dArea < 0)
|
|
pCrvExt->Invert() ;
|
|
|
|
// recupero nome del path
|
|
string sPathName ;
|
|
m_pGeomDB->GetName( nPathId, sPathName) ;
|
|
|
|
// assegno il versore fresa
|
|
Vector3d vtTool = vtExtr ;
|
|
|
|
// se richiesta lavorazione
|
|
if ( nClId != GDB_ID_NULL) {
|
|
// creo gruppo per geometria di lavorazione del percorso
|
|
int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nClId, Frame3d()) ;
|
|
if ( nPxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPxId, sPathName) ;
|
|
m_pGeomDB->SetMaterial( nPxId, BLUE) ;
|
|
|
|
// verifico se archi vanno approssimati con segmenti di retta
|
|
bool bSplitArcs = GetSplitArcs( vtTool) ;
|
|
|
|
// recupero le superfici di lavoro e di supporto
|
|
SURFLOCALVECTOR vSrfLoc, vSrfLocSupp ;
|
|
Frame3d frSurf ;
|
|
if ( ! GetSurfacesByIds( vSrfLoc, vSrfLocSupp, frSurf)) {
|
|
m_pMchMgr->SetLastError( 3123, "Error in SurfFinishing : missing surfaces") ;
|
|
return false ;
|
|
}
|
|
|
|
// determino la regione da lavorare
|
|
PtrOwner<ISurfFlatRegion> pSfrCnt( CreateSurfFlatRegion()) ;
|
|
if ( IsNull( pSfrCnt) || ! pSfrCnt->AddExtLoop( *pCrvExt)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
for ( int nL = 1 ; nL < pSfrGDB->GetLoopCount( 0) ; ++ nL) {
|
|
// recupero l'isola
|
|
PtrOwner<ICurve> pCrvIsl( pSfrGDB->GetLoop( 0, nL)) ;
|
|
if ( IsNull( pCrvIsl) || ! pCrvIsl->IsValid() ||
|
|
! pSfrCnt->AddIntLoop( Release( pCrvIsl))) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
}
|
|
// se regione non valida, non faccio nulla
|
|
if ( ! pSfrCnt->IsValid())
|
|
return true ;
|
|
|
|
// calcolo l'elevazione al di sopra della curva
|
|
double dElev = 0. ;
|
|
if ( ! CalcRegionElevation( pSfrCnt, vtTool, m_TParams.m_dDiam / 2., m_TParams.m_dLen, dElev)) {
|
|
m_pMchMgr->SetLastError( 3135, "Error in SurfFinishing : Calc Region Elvation failed") ;
|
|
return false ;
|
|
}
|
|
// posiziono la superficie a quella quota (top del grezzo)
|
|
if ( dElev > EPS_SMALL) {
|
|
pSfrCnt->Translate( vtTool * dElev) ;
|
|
dDepth += dElev ;
|
|
}
|
|
// controllo di non scendere al di sotto del grezzo con la depth
|
|
double dInvElev = 0. ;
|
|
pSfrCnt->Invert() ;
|
|
if ( ! CalcRegionElevation( pSfrCnt, vtTool, m_TParams.m_dDiam / 2., m_TParams.m_dLen, dInvElev)) {
|
|
m_pMchMgr->SetLastError( 3135, "Error in SurfFinishing : Calc Region Elvation failed") ;
|
|
return false ;
|
|
}
|
|
pSfrCnt->Invert() ;
|
|
if ( dDepth > dInvElev - EPS_SMALL) {
|
|
double dToolDepth = m_TParams.m_dMaxMat ;
|
|
if ( m_TParams.m_nType != TT_COMPO && abs( m_TParams.m_dSideAng) < EPS_SMALL)
|
|
dToolDepth = m_TParams.m_dCornRad ;
|
|
dDepth = dInvElev + dToolDepth ;
|
|
}
|
|
|
|
#if DEBUG_SFR
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "FlatRegions") ;
|
|
int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLay, "Sfr_by_curves") ;
|
|
int nSfr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pSfrCnt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nSfr, Color( 0., 1., 0., .5)) ;
|
|
#endif
|
|
|
|
// predispongo l'ambiente di correzione dei percorsi utensili
|
|
PtrOwner<ICAvToolSurfTm> pCAvTlStm( CreateCAvToolSurfTm()) ;
|
|
PtrOwner<ISurfFlatRegion> pSfrCntLoc( CloneSurfFlatRegion( pSfrCnt)) ;
|
|
if ( IsNull( pCAvTlStm) ||
|
|
IsNull( pSfrCntLoc) || ! pSfrCntLoc->IsValid() ||
|
|
! pSfrCntLoc->ToLoc( frSurf) ||
|
|
! SetCAvTlStmForSurfaces( pCAvTlStm, pSfrCntLoc, dDepth, m_TParams.m_dLen, m_TParams.m_dDiam,
|
|
m_TParams.m_dCornRad, m_TParams.m_dSideAng, m_TParams.m_dMaxMat,
|
|
GetOffsR(), vSrfLoc, vSrfLocSupp)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
|
|
// alla regione di contorno applico un Offset stabilito dal parametro di Overlap
|
|
if ( ! pSfrCnt->Offset( m_Params.m_dOverlap + GetOffsR(), ICurve::OFF_FILLET)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
// se non valida, non faccio nulla
|
|
if ( ! pSfrCnt->IsValid())
|
|
return true ;
|
|
|
|
// tengo una copia della regione attuale, nel caso di finitura Optimal
|
|
PtrOwner<ISurfFlatRegion> pSfrCntOrig( CloneSurfFlatRegion( pSfrCnt)) ;
|
|
if ( IsNull( pSfrCntOrig) || ! pSfrCntOrig->IsValid())
|
|
return false ;
|
|
|
|
// se richiesto, elimino le parti al massimo affondamento
|
|
bool bSkipMaxDown = true ;
|
|
GetValInNotes( m_Params.m_sUserNotes, UN_SKIPMAXDOWN, bSkipMaxDown) ;
|
|
if ( bSkipMaxDown && m_Params.m_nSubType != SURFFIN_SUB_Z_CONST &&
|
|
m_Params.m_nSubType != SURFFIN_SUB_PENCIL) {
|
|
PtrOwner<ISurfFlatRegion> pSfrMaxDown( CloneSurfFlatRegion( pSfrCnt)) ;
|
|
if ( IsNull( pSfrMaxDown) || ! pSfrMaxDown->IsValid() ||
|
|
! EraseMaxDownSurf( vSrfLoc, frSurf, vtTool, dDepth, pSfrMaxDown)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
// se non valida, non faccio nulla
|
|
if ( ! pSfrMaxDown->IsValid())
|
|
return true ;
|
|
// questa regione deve essere lavorata a SideStep
|
|
double dSideStepLowerBound = max( 0.5, m_Params.m_dSideStep) ; // per tolleranza di campionamento
|
|
if ( ! pSfrMaxDown->Offset( m_TParams.m_dDiam - dSideStepLowerBound + GetOffsR(), ICurve::OFF_FILLET))
|
|
return false ;
|
|
// la regione la lavorare è l'intersezione tra quest'ultima e il contorno
|
|
pSfrCnt->Intersect( *pSfrMaxDown) ;
|
|
}
|
|
// se regione risultante vuota, non devo fare altro
|
|
if ( ! pSfrCnt->IsValid())
|
|
return true ;
|
|
// la regione viene considerata con lati tutti chiusi
|
|
for ( int nC = 0 ; nC < pSfrCnt->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pSfrCnt->GetLoopCount( nC) ; ++ nL) {
|
|
for ( int nU = 0 ; nU < pSfrCnt->GetLoopCurveCount( nC, nL) ; ++ nU) {
|
|
pSfrCnt->SetCurveTempProp( nC, nL, nU, TEMP_PROP_CLOSE_EDGE, 0) ;
|
|
pSfrCnt->SetCurveTempProp( nC, nL, nU, TEMP_PROP_CLOSE_EDGE, 1) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
#if DEBUG_SFR
|
|
int nLay3 = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLay3, "Sfr_Final") ;
|
|
int nSfrF = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay3, pSfrCnt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nSfrF, LIME) ;
|
|
#endif
|
|
|
|
// Imposto dati comuni
|
|
SetPathId( nPxId) ;
|
|
SetToolDir( vtTool) ;
|
|
Vector3d vtAux ;
|
|
if ( GetValInNotes( m_Params.m_sUserNotes, UN_VTAUXDIR, vtAux))
|
|
vtAux.Normalize() ;
|
|
SetAuxDir( vtAux) ;
|
|
|
|
// assegno il vettore estrusione al gruppo del percorso
|
|
m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ;
|
|
|
|
// inserisco le superfici di supporto tra le superfici locali
|
|
for ( SurfLocal& SurfLocSupp : vSrfLocSupp)
|
|
vSrfLoc.emplace_back( SurfLocSupp) ;
|
|
|
|
// Eseguo la lavorazione a seconda del tipo
|
|
dElev = dDepth ;
|
|
|
|
switch ( m_Params.m_nSubType) {
|
|
case SURFFIN_SUB_ZIGZAG :
|
|
if ( ! AddZigZag( pCAvTlStm, frSurf, pSfrCnt, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
break ;
|
|
case SURFFIN_SUB_ONEWAY :
|
|
if ( ! AddOneWay( pCAvTlStm, frSurf, pSfrCnt, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
break ;
|
|
case SURFFIN_SUB_SPIRALIN :
|
|
if ( ! AddSpiral( pCAvTlStm, frSurf, pSfrCnt, vtTool, dDepth, dElev, bSplitArcs, true))
|
|
return false ;
|
|
break ;
|
|
case SURFFIN_SUB_SPIRALOUT :
|
|
if ( ! AddSpiral( pCAvTlStm, frSurf, pSfrCnt, vtTool, dDepth, dElev, bSplitArcs, false))
|
|
return false ;
|
|
break ;
|
|
case SURFFIN_SUB_Z_CONST :
|
|
if ( ! AddZConst( pCAvTlStm, vSrfLoc, frSurf, pSfrCnt, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
break ;
|
|
case SURFFIN_SUB_OPTIMAL :
|
|
if ( ! AddOptimal( pCAvTlStm, vSrfLoc, frSurf, pSfrCnt, pSfrCntOrig, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
break ;
|
|
case SURFFIN_SUB_PENCIL :
|
|
if ( ! AddPencil( pCAvTlStm, vSrfLoc, frSurf, pSfrCnt, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
break ;
|
|
}
|
|
}
|
|
|
|
// incremento numero di percorsi
|
|
++ m_nPaths ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SimplifyCurve( ICurveComposite* pCompo, const Frame3d& frLocXY, double dMergeLinTol, double dMergeAndTolDeg,
|
|
double dSmallDefLinTol, double dSmallDefAngTolDeg,
|
|
double dArcApproxLinTol, double dArcApproxAngTolDeg) const
|
|
{
|
|
// controllo dei parametri
|
|
if ( pCompo == nullptr || ! pCompo->IsValid())
|
|
return false ;
|
|
|
|
// eseguo le modifiche su una copia della curva originale in locale al frame XY
|
|
PtrOwner<ICurveComposite> pCompoLoc( CloneCurveComposite( pCompo)) ;
|
|
if ( IsNull( pCompoLoc))
|
|
return false ;
|
|
pCompoLoc->ToLoc( frLocXY) ;
|
|
|
|
// ricavo il punto iniziale e finale
|
|
Point3d ptStart ; pCompoLoc->GetStartPoint( ptStart) ;
|
|
Point3d ptEnd ; pCompoLoc->GetEndPoint( ptEnd) ;
|
|
|
|
// merge per uniformità
|
|
bool bOk = pCompoLoc->MergeCurves( dMergeLinTol, dMergeAndTolDeg, false) ;
|
|
// rimozione Spikes o Curve Z
|
|
bOk = bOk && pCompoLoc->RemoveSmallDefects( dSmallDefLinTol, dSmallDefAngTolDeg, true) ;
|
|
// interpolazione mediante linee ed archi
|
|
PolyArc PA ;
|
|
bOk = bOk && pCompoLoc->ApproxWithArcsEx( dArcApproxLinTol, dArcApproxAngTolDeg, LIN_FEA_STD, PA) &&
|
|
pCompoLoc->Clear() && pCompoLoc->FromPolyArc( PA) ;
|
|
// controllo aggiuntivo sui punti iniziali e finali che siano gli stessi
|
|
Point3d ptNewStart, ptNewEnd ;
|
|
bOk = bOk && pCompoLoc->GetStartPoint( ptNewStart) && pCompoLoc->GetEndPoint( ptNewEnd) &&
|
|
AreSamePointApprox( ptNewStart, ptStart) && AreSamePointApprox( ptNewEnd, ptEnd) ;
|
|
|
|
// controllo che non si siano create auto-intersezioni
|
|
SelfIntersCurve SIC( *pCompoLoc) ;
|
|
bOk = bOk && ( SIC.GetCrossIntersCount() == 0) ;
|
|
|
|
// se tutto bene, sostiuisco la curva originale con la modificata
|
|
if ( bOk) {
|
|
pCompoLoc->ToGlob( frLocXY) ;
|
|
pCompo->CopyFrom( pCompoLoc) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetActiveSurfaces( INTVECTOR& vSurfId, INTVECTOR& vSurfSuppId) const
|
|
{
|
|
// NB.
|
|
// - vSrufInd contiene gli Id delle superfici selezionate ( nel caso non ci siano superfici
|
|
// selezionate, allora vengono considerate tutte le superfici presenti nei grezzi attivi della fase)
|
|
// - vSurfSupp contiene gli Id delle superfici di supporto, quindi quelle superici da cui si vuole
|
|
// mantenere una certa distanza con l'utensile ( senza che siano selezionate)
|
|
|
|
// pulisco vettore superfici
|
|
vSurfId.clear() ;
|
|
vSurfSuppId.clear() ;
|
|
// verifiche
|
|
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
|
|
return false ;
|
|
// cerco tra gli oggetti selezionati
|
|
for ( const auto& Id : m_vId) {
|
|
int nEntId = Id.nId ;
|
|
int nType = m_pGeomDB->GetGeoType( nEntId) ;
|
|
if ( nType == SRF_TRIMESH || nType == SRF_BEZIER)
|
|
vSurfId.emplace_back( nEntId) ;
|
|
}
|
|
// controllo se sono state trovate delle superfici
|
|
bool bNoSurfId = ( vSurfId.empty()) ;
|
|
// scorro tutte le superfici dei pezzi nei grezzi attivi della fase
|
|
int nRawId = m_pMchMgr->GetFirstRawPart() ;
|
|
while ( nRawId != GDB_ID_NULL) {
|
|
if ( m_pMchMgr->VerifyRawPartPhase(nRawId, m_nPhase)) {
|
|
// ciclo sui pezzi del grezzo
|
|
int nPartId = m_pMchMgr->GetFirstPartInRawPart( nRawId) ;
|
|
while ( nPartId != GDB_ID_NULL) {
|
|
// ciclo sui layer dei pezzi
|
|
int nLayId = m_pGeomDB->GetFirstGroupInGroup( nPartId) ;
|
|
while ( nLayId != GDB_ID_NULL) {
|
|
// ciclo sulle entità del layer
|
|
int nEntId = m_pGeomDB->GetFirstInGroup( nLayId) ;
|
|
while ( nEntId != GDB_ID_NULL) {
|
|
// se entità superficie e visibile, la aggiungo
|
|
int nStat ;
|
|
if ( ( m_pGeomDB->GetGeoType( nEntId) == SRF_TRIMESH ||
|
|
m_pGeomDB->GetGeoType( nEntId) == SRF_BEZIER) &&
|
|
m_pGeomDB->GetCalcStatus( nEntId, nStat) && nStat != GDB_ST_OFF) {
|
|
// se non sono state selezionate superfici precedentemente, memorizzo tale id
|
|
if ( bNoSurfId)
|
|
vSurfId.emplace_back( nEntId) ;
|
|
// verifico se è presente una superficie di controllo
|
|
string sLayIdName ;
|
|
if ( m_pGeomDB->GetName( nLayId, sLayIdName) && EqualNoCase( sLayIdName, SRF_SUPP_LAYER_NAME))
|
|
vSurfSuppId.emplace_back( nEntId) ;
|
|
}
|
|
// passo alla entità successiva
|
|
nEntId = m_pGeomDB->GetNext( nEntId) ;
|
|
}
|
|
nLayId = m_pGeomDB->GetNextGroup( nLayId) ;
|
|
}
|
|
nPartId = m_pMchMgr->GetNextPartInRawPart( nPartId) ;
|
|
}
|
|
}
|
|
nRawId = m_pMchMgr->GetNextRawPart( nRawId) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CorrectPathByCollision( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, const Vector3d& vtTool,
|
|
double dDepth, ICRVCOMPOPOVECTOR& vpCrvs)
|
|
{
|
|
// se non ho curve, non faccio nulla
|
|
if ( vpCrvs.empty())
|
|
return true ;
|
|
|
|
// se classe di calcolo per collisioni valida
|
|
if ( pCAvTlStm != nullptr) {
|
|
|
|
// porto i dati geometrici in locale alle superfici
|
|
Vector3d vtAxL = vtTool ;
|
|
vtAxL.ToLoc( frSurf) ;
|
|
Vector3d vtMoveL = vtAxL ;
|
|
|
|
// scorro le curve
|
|
double dProgCoeff = 1. / max( int( vpCrvs.size()), 1) ;
|
|
for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) {
|
|
|
|
// controllo che la curva sia valida
|
|
if ( IsNull( vpCrvs[i]) || ! vpCrvs[i]->IsValid())
|
|
continue ;
|
|
// approssimo la curva con una polilinea
|
|
PolyLine PL ;
|
|
if ( ! vpCrvs[i]->ApproxWithLines( LIN_TOL_STD, ANG_TOL_STD_DEG, ICurve::APL_SPECIAL, PL))
|
|
return false ;
|
|
// eventuale aggiunta di punti per garantire max distanza
|
|
const double MIN_DIST = 1. ;
|
|
const double MAX_DIST = 50. ;
|
|
double dDist = Clamp( m_TParams.m_dDiam / 2, MIN_DIST, MAX_DIST) ;
|
|
if ( ! PL.AdjustForMaxSegmentLen( dDist))
|
|
return false ;
|
|
// porto nel riferimento delle superfici
|
|
PL.ToLoc( frSurf) ;
|
|
// traslo della lunghezza utensile diminuita dell'affondamento
|
|
PL.Translate( vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
// eseguo CAv
|
|
if ( ! pCAvTlStm->TestPath( PL.GetUPointList(), vtAxL, vtMoveL, m_Params.m_dApprox, ( i + 1) * dProgCoeff))
|
|
return false ;
|
|
// contro-traslo della lunghezza utensile
|
|
PL.Translate( - vtAxL * m_TParams.m_dLen) ;
|
|
// riporto la polilinea nel riferimento della curva
|
|
PL.ToGlob( frSurf) ;
|
|
// elimino i punti allineati
|
|
PL.RemoveAlignedPoints( 0.8 * m_Params.m_dApprox) ;
|
|
// creo una curva composita a partire dalla polilinea
|
|
PtrOwner< ICurveComposite> pCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCompo) || ! pCompo->FromPolyLine( PL))
|
|
return false ;
|
|
// sostituisco la vecchia curva con la nuova
|
|
vpCrvs[i].Set( pCompo) ;
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddZigZag( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, const ISurfFlatRegion* pSfrCnt,
|
|
const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs)
|
|
{
|
|
// calcolo lo ZigZag
|
|
ICRVCOMPOPOVECTOR vpCrvs ;
|
|
if ( ! CalcPocketing( pSfrCnt, m_TParams.m_dDiam / 2., 0., m_Params.m_dSideStep, m_Params.m_dSideAngle, 5.,
|
|
POCKET_ZIGZAG, false, false, false, true, true, false, false, P_INVALID, nullptr, true, m_Params.m_dSideStep,
|
|
GetLeadInType(), m_Params.m_dLiTang, 0., GetLeadOutType(), m_Params.m_dLoTang, false, 0., 0., vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3125, "Error in SurfFinishing : CalcPocketing failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// correggo i percorsi mediante collisione con le supercici
|
|
if ( ! CorrectPathByCollision( pCAvTlStm, frSurf, vtTool, dDepth, vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3134, "Error in SurfFinishing : Projecting Path failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// aggiungo i percorsi di finitura calcolati
|
|
if ( ! AddFinishing( pSfrCnt, pCAvTlStm, frSurf, vpCrvs, vtTool, dElev, dDepth, bSplitArcs))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddOneWay( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, const ISurfFlatRegion* pSfrCnt,
|
|
const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs)
|
|
{
|
|
|
|
// calcolo OneWay
|
|
ICRVCOMPOPOVECTOR vpCrvs ;
|
|
if ( ! CalcPocketing( pSfrCnt, m_TParams.m_dDiam / 2., 0., m_Params.m_dSideStep, m_Params.m_dSideAngle, 5.,
|
|
POCKET_ONEWAY, false, false, false, true, true, false, false, P_INVALID, nullptr, true, m_Params.m_dSideStep,
|
|
GetLeadInType(), m_Params.m_dLiTang, 0., GetLeadOutType(), m_Params.m_dLoTang, false, 0., 0., vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3125, "Error in SurfFinishing : CalcPocketing failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// correggo i percorsi mediante collisione con le supercici
|
|
if ( ! CorrectPathByCollision( pCAvTlStm, frSurf, vtTool, dDepth, vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3134, "Error in SurfFinishing : Projecting Path failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// aggiungo i percorsi di finitura calcolati
|
|
if ( ! AddFinishing( pSfrCnt, pCAvTlStm, frSurf, vpCrvs, vtTool, dElev, dDepth, bSplitArcs))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddSpiral( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, const ISurfFlatRegion* pSfrCnt,
|
|
const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs, bool bInVsOut)
|
|
{
|
|
// calcolo la spirale
|
|
int nType = ( bInVsOut ? POCKET_SPIRALIN : POCKET_SPIRALOUT) ;
|
|
ICRVCOMPOPOVECTOR vpCrvs ;
|
|
if ( ! CalcPocketing( pSfrCnt, m_TParams.m_dDiam / 2., 0., m_Params.m_dSideStep, m_Params.m_dSideAngle, 5.,
|
|
nType, false, false, false, true, true, false, false, P_INVALID, nullptr, true, m_Params.m_dSideStep,
|
|
GetLeadInType(), m_Params.m_dLiTang, 0., GetLeadOutType(), m_Params.m_dLoTang, false, 0., 0., vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3125, "Error in SurfFinishing : CalcPocketing failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// correggo i percorsi mediante collisione con le supercici
|
|
if ( ! CorrectPathByCollision( pCAvTlStm, frSurf, vtTool, dDepth, vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3134, "Error in SurfFinishing : Projecting Path failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// aggiungo i percorsi di finitura calcolati
|
|
if ( ! AddFinishing( pSfrCnt, pCAvTlStm, frSurf, vpCrvs, vtTool, dElev, dDepth, bSplitArcs))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetZConstQuotesInsideSfrParallelToTool( const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf,
|
|
const ISurfFlatRegion* pSfr, const Vector3d& vtTool,
|
|
set<double>& setZAmbiguos) const
|
|
{
|
|
// controllo dei parametri
|
|
setZAmbiguos.clear() ;
|
|
if ( pSfr == nullptr || ! pSfr->IsValid())
|
|
return false ;
|
|
|
|
// creo un frame centrato sulla superficie piana
|
|
Frame3d frSfr ;
|
|
Point3d ptC ; pSfr->GetCentroid( ptC) ;
|
|
if ( ! frSfr.Set( ptC, pSfr->GetNormVersor()) || ! frSfr.IsValid())
|
|
return false ;
|
|
// porto una copia della superficie in questo frame
|
|
PtrOwner<ISurfFlatRegion> pSfrLoc( CloneSurfFlatRegion( pSfr)) ;
|
|
if ( IsNull( pSfrLoc) || ! pSfrLoc->IsValid() || ! pSfrLoc->ToLoc( frSfr))
|
|
return false ;
|
|
|
|
// scorro le superfici trimesh selezionate
|
|
for ( int nS = 0 ; nS < int( vSrfLoc.size()) ; ++ nS) {
|
|
// recupero la superficie
|
|
const ISurf* pSurf = GetSurf( vSrfLoc[nS].Get()) ;
|
|
if ( pSurf == nullptr || ! pSurf->IsValid())
|
|
continue ;
|
|
int nType = pSurf->GetType() ;
|
|
PtrOwner<ISurfTriMesh> pStm ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pSurftm = GetSurfTriMesh( pSurf) ;
|
|
if ( pSurftm != nullptr && pSurftm->IsValid() && pSurftm->GetTriangleCount() > 0) {
|
|
if ( ! pStm.Set( CloneSurfTriMesh( pStm)))
|
|
continue ;
|
|
}
|
|
}
|
|
// se Bezier
|
|
else if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurf) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pSurftm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
if ( pSurftm != nullptr && pSurftm->IsValid() && pSurftm->GetTriangleCount() > 0) {
|
|
if ( ! pStm.Set( CloneSurfTriMesh( pSurftm)))
|
|
continue ;
|
|
}
|
|
}
|
|
}
|
|
// scorro le facce
|
|
for ( int nF = 0 ; nF < pStm->GetFacetCount() ; ++ nF) {
|
|
// recupero il centro e la normale della faccia
|
|
Point3d ptCenter ;
|
|
Vector3d vtNorm ;
|
|
if ( pStm->GetFacetCenter( nF, ptCenter, vtNorm)) {
|
|
// confronto la normale con la direzione dell'utensile
|
|
vtNorm.ToGlob( frSurf) ;
|
|
if ( AreSameVectorEpsilon( vtNorm, vtTool, 10 * EPS_SMALL)) {
|
|
// recupero i contorni della faccia
|
|
POLYLINEVECTOR vPL ;
|
|
if ( pStm->GetFacetLoops( nF, vPL)) {
|
|
// recupero la superficie piana dalle curve
|
|
SurfFlatRegionByContours SfrByC ;
|
|
for ( int nPL = 0 ; nPL < int( vPL.size()) ; ++ nPL) {
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo) || ! pCrvCompo->FromPolyLine( vPL[nPL]))
|
|
return false ;
|
|
// porto la curva nel riferimento della superficie piana di classificazione
|
|
pCrvCompo->ToLoc( frSfr) ;
|
|
// aggiungo la curva alla FlatRegion
|
|
SfrByC.AddCurve( Release( pCrvCompo)) ;
|
|
}
|
|
ptCenter.ToLoc( frSfr) ;
|
|
// recupero la superficie
|
|
PtrOwner<ISurfFlatRegion> pSfrFace( SfrByC.GetSurf()) ;
|
|
if ( IsNull( pSfrFace) || ! pSfrFace->IsValid()) {
|
|
// in questo caso potrei avere geometrie complesse per le facce della pStm
|
|
// inserisco la Z del piano locale nell'insieme
|
|
setZAmbiguos.insert( ptCenter.z) ;
|
|
continue ;
|
|
}
|
|
// se esiste intersezione tra pSfrFace e pSfr allora salvo la Z locale
|
|
pSfrFace->Intersect( *pSfrLoc) ;
|
|
if ( ! IsNull( pSfrFace) && pSfrFace->IsValid())
|
|
setZAmbiguos.insert( ptCenter.z) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
ISurfFlatRegion*
|
|
SurfFinishing::GetSfrSilhouette( const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frLvl0, double dDepth) const
|
|
{
|
|
// inizializzo vettore di puntatori a superfici costanti
|
|
CISURFTMPVECTOR vpStm ; vpStm.reserve( vSrfLoc.size()) ;
|
|
// scorro le superfici
|
|
for ( int i = 0 ; i < int( vSrfLoc.size()) ; ++ i) {
|
|
// recupero la superficie TriMesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( vSrfLoc[i].Get()) ;
|
|
// se valida, la memorizzo
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
|
|
// inizializzo classe di calcolo della silhouette
|
|
const double SILH_TOL = 1.0 ;
|
|
PtrOwner<ICAvParSilhouettesSurfTm> pCavParSilh( CreateCAvParSilhouettesSurfTm()) ;
|
|
if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vpStm, frLvl0, SILH_TOL))
|
|
return nullptr ;
|
|
// vettore di PolyLine
|
|
POLYLINEVECTOR vPL ;
|
|
if ( ! pCavParSilh->GetSilhouette( dDepth, vPL))
|
|
return nullptr ;
|
|
// creo la regione piana dalle PolyLine ricavate dalla Silhouette
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( auto& PL : vPL) {
|
|
// recupero la curva dalla silhouette
|
|
PtrOwner<ICurveComposite> pSilCrv( CreateCurveComposite()) ;
|
|
if ( IsNull( pSilCrv))
|
|
return nullptr ;
|
|
pSilCrv->FromPolyLine( PL) ;
|
|
// approssimo con archi
|
|
const double SILH_ARC_TOL = 100 * EPS_SMALL ;
|
|
const double SILH_ARC_FEA_MAX = 100. ;
|
|
PolyArc PA ;
|
|
if ( pSilCrv->ApproxWithArcsEx( SILH_ARC_TOL, ANG_TOL_STD_DEG, SILH_ARC_FEA_MAX, PA)) {
|
|
PtrOwner<ICurveComposite> pTempCrv( CreateCurveComposite()) ;
|
|
if ( ! IsNull( pTempCrv) &&
|
|
pTempCrv->FromPolyArc( PA) &&
|
|
pTempCrv->RemoveSmallDefects( SILH_ARC_TOL / 2, ANG_TOL_STD_DEG) &&
|
|
pTempCrv->MergeCurves( SILH_ARC_TOL / 2, ANG_TOL_STD_DEG))
|
|
pSilCrv.Set( pTempCrv) ;
|
|
}
|
|
|
|
// aggiungo per regione
|
|
if ( ! SfrMaker.AddCurve( Release( pSilCrv)))
|
|
return nullptr ;
|
|
}
|
|
|
|
return ( SfrMaker.GetSurf()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcZConstSilCrv( ICAvParSilhouettesSurfTm* pCavParSilh, const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf,
|
|
const ISurfFlatRegion* pSfrClass, const Vector3d& vtTool, double dDepth, vector<ICRVCOMPOPOVECTOR>& vCrvCompo) const
|
|
{
|
|
// funzione per calcolare le curve singole di finitura mediante Silhouette e le regioni da non rovinare
|
|
// NB. Come primo TempParam delle curve viene memorizzata la distanza tra essa e il piano della pSfrClass
|
|
|
|
// controllo che la regione piana sia definita correttamente
|
|
vCrvCompo.clear() ;
|
|
if ( pSfrClass == nullptr || ! pSfrClass->IsValid())
|
|
return false ;
|
|
|
|
// definisco un frame implicito rispetto alla superficie di classificazione
|
|
Frame3d frLocXY ;
|
|
Point3d ptC ; pSfrClass->GetCentroid( ptC) ;
|
|
frLocXY.Set( ptC, pSfrClass->GetNormVersor()) ;
|
|
|
|
// NB. Essendo una finitura a Z costante, devo controllare che i piani di finitura non facciano
|
|
// overlap con facce delle TriMesh selezionate con normale simile a vtTool
|
|
set<double> setZAmbiguos ;
|
|
PtrOwner<ISurfFlatRegion> pSfrZAmb( CloneSurfFlatRegion( pSfrClass)) ;
|
|
if ( IsNull( pSfrZAmb) || ! pSfrZAmb->IsValid() ||
|
|
! pSfrZAmb->Offset( m_TParams.m_dDiam / 2. + abs( m_Params.m_dOverlap), ICurve::OFF_FILLET))
|
|
return false ;
|
|
if ( ! GetZConstQuotesInsideSfrParallelToTool( vSrfLoc, frSurf, pSfrZAmb, vtTool, setZAmbiguos))
|
|
return false ;
|
|
|
|
// aggiorno la ProgressBar al 40%
|
|
ExeProcessEvents( 40, 0) ;
|
|
|
|
// calcolo la silhouette sui diversi piani
|
|
for ( int nPlane = 1 ; nPlane * m_Params.m_dSideStep < dDepth + EPS_SMALL ; ++ nPlane) {
|
|
// riservo lo spazio nel vettore delle curve
|
|
vCrvCompo.resize( vCrvCompo.size() + 1) ;
|
|
// definisco la Zlocale per il calcolo della silhouette
|
|
double dZLoc = - nPlane * m_Params.m_dSideStep ;
|
|
for ( set<double>::iterator it = setZAmbiguos.begin() ; it != setZAmbiguos.end() ; ++ it) {
|
|
if ( abs( *it - dZLoc) < 5 * EPS_SMALL)
|
|
dZLoc += ( nPlane == 1 ? - 10 * EPS_SMALL : + 10 * EPS_SMALL) ;
|
|
}
|
|
// calcolo vettore di PolyLine ottenute al piano corrente
|
|
POLYLINEVECTOR vPL ;
|
|
if ( ! pCavParSilh->GetSilhouette( dZLoc, vPL))
|
|
return false ;
|
|
// classifico le PolyLine in base alla regione
|
|
POLYLINEVECTOR vPLInsideSfr ;
|
|
for ( auto& PL : vPL) {
|
|
// porto la PolyLine a contatto con la regione
|
|
PL.Translate( - dZLoc * pSfrClass->GetNormVersor()) ;
|
|
// converto in curva composita
|
|
PtrOwner<ICurveComposite> pCrvPL( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvPL) || ! pCrvPL->FromPolyLine( PL))
|
|
return false ;
|
|
// classifico la curva con la superficie
|
|
CRVCVECTOR ccClass ;
|
|
if ( ! pSfrClass->GetCurveClassification( *pCrvPL, EPS_SMALL, ccClass))
|
|
return false ;
|
|
// tengo tutti i tratti non esterni alla superficie
|
|
for ( int i = 0 ; i < int( ccClass.size()) ; ++ i) {
|
|
if ( ccClass[i].nClass != CRVC_OUT) {
|
|
PtrOwner<ICurveComposite> pCrvCompoPartIn( ConvertCurveToComposite( pCrvPL->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE))) ;
|
|
if ( ! IsNull( pCrvCompoPartIn) && pCrvCompoPartIn->IsValid()) {
|
|
vPLInsideSfr.emplace_back( PolyLine()) ;
|
|
// riporto la curva alla quota giusta
|
|
pCrvCompoPartIn->Translate( dZLoc * pSfrClass->GetNormVersor()) ;
|
|
pCrvCompoPartIn->ApproxWithLines( 0, 0, ICurve::APL_SPECIAL, vPLInsideSfr.back()) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
swap( vPL, vPLInsideSfr) ;
|
|
for ( auto& PL : vPL) {
|
|
// recupero la curva dalla silhouette
|
|
PtrOwner<ICurveComposite> pSilCrv( CreateCurveComposite()) ;
|
|
if ( IsNull( pSilCrv))
|
|
return false ;
|
|
pSilCrv->FromPolyLine( PL) ;
|
|
// approssimo con archi
|
|
const double SILH_ARC_TOL = 0.1 * SILH_SAMPLING ;
|
|
const double SILH_ARC_FEA_MAX = 100. ;
|
|
PolyArc PA ;
|
|
if ( pSilCrv->ApproxWithArcsEx( SILH_ARC_TOL, ANG_TOL_STD_DEG, SILH_ARC_FEA_MAX, PA)) {
|
|
PtrOwner<ICurveComposite> pTempCrv( CreateCurveComposite()) ;
|
|
if ( ! IsNull( pTempCrv) &&
|
|
pTempCrv->FromPolyArc( PA) &&
|
|
pTempCrv->RemoveSmallDefects( SILH_ARC_TOL / 2., ANG_TOL_STD_DEG) &&
|
|
pTempCrv->MergeCurves( SILH_ARC_TOL / 2., ANG_TOL_STD_DEG))
|
|
pSilCrv.Set( pTempCrv) ;
|
|
}
|
|
SimplifyCurve( pSilCrv, frLocXY) ;
|
|
vCrvCompo.back().emplace_back( Release( pSilCrv)) ;
|
|
}
|
|
// controllo validità delle curve
|
|
for ( int i = 0 ; i < int( vCrvCompo.back().size()) ; ++ i)
|
|
if ( vCrvCompo.back()[i] == nullptr || ! vCrvCompo.back()[i]->IsValid())
|
|
return false ;
|
|
// preparo i dati per il concatenamento
|
|
bool bFirst = true ;
|
|
Point3d ptNear = ORIG ;
|
|
double dToler = 500 * EPS_SMALL ;
|
|
ChainCurves chainC ;
|
|
chainC.Init( false, dToler, int( vCrvCompo.back().size())) ;
|
|
for ( int i = 0 ; i < int( vCrvCompo.back().size()) ; ++ i) {
|
|
// recupero i dati della curva necessari al concatenamento e li assegno
|
|
Point3d ptStart, ptEnd ;
|
|
Vector3d vtStart, vtEnd ;
|
|
if ( ! vCrvCompo.back()[i]->GetStartPoint( ptStart) || ! vCrvCompo.back()[i]->GetStartDir( vtStart) ||
|
|
! vCrvCompo.back()[i]->GetEndPoint( ptEnd) || ! vCrvCompo.back()[i]->GetEndDir( vtEnd))
|
|
return false ;
|
|
if ( ! chainC.AddCurve( int( i + 1), ptStart, vtStart, ptEnd, vtEnd))
|
|
return false ;
|
|
// se prima curva, assegno inizio della ricerca
|
|
if ( bFirst) {
|
|
ptNear = ptStart + 10 * EPS_SMALL * vtStart ;
|
|
bFirst = false ;
|
|
}
|
|
}
|
|
// vettore delle curve composite risultante
|
|
ICRVCOMPOPOVECTOR vCrvCompoChained ;
|
|
// recupero i percorsi concatenati
|
|
INTVECTOR vnInd ;
|
|
while ( chainC.GetChainFromNear( ptNear, true, vnInd)) {
|
|
// creo una curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return false ;
|
|
// recupero le curve semplici e le inserisco nella curva composita
|
|
for ( size_t i = 0 ; i < vnInd.size() ; ++ i) {
|
|
int nId = abs( vnInd[i]) - 1 ;
|
|
// la aggiungo alla curva composta
|
|
if ( ! pCrvCompo->AddCurve( CloneCurveComposite( vCrvCompo.back()[nId]), true, dToler))
|
|
return false ;
|
|
}
|
|
// aggiorno il nuovo punto vicino
|
|
if ( pCrvCompo->GetCurveCount() > 0) {
|
|
pCrvCompo->GetEndPoint( ptNear) ;
|
|
vCrvCompoChained.emplace_back( Release( pCrvCompo)) ;
|
|
}
|
|
}
|
|
swap( vCrvCompoChained, vCrvCompo.back()) ;
|
|
// salvo lo Step come primo temp param della curva e inverto se necessario
|
|
for ( int i = 0 ; i < int( vCrvCompo.back().size()) ; ++ i) {
|
|
vCrvCompo.back()[i]->SetTempParam( - nPlane * m_Params.m_dSideStep, 0) ;
|
|
if ( m_Params.m_bInvert)
|
|
vCrvCompo.back()[i]->Invert() ;
|
|
}
|
|
|
|
// aggiorno la ProgressBar
|
|
ExeProcessEvents( 40 + int( 40 / ( dDepth / max( 0.1, m_Params.m_dSideStep)) * ( nPlane - 1)), 0) ;
|
|
}
|
|
|
|
// controllo la validità di tutte le curve trovate
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
for ( int j = 0 ; j < int( vCrvCompo[i].size()) ; ++ j) {
|
|
if ( vCrvCompo[i][j] == nullptr || ! vCrvCompo[i][j]->IsValid())
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CreateZConstPaths( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf,
|
|
vector<ICRVCOMPOPOVECTOR>& vCrvCompo, const Vector3d& vtTool, const ISurfFlatRegion* pSfr,
|
|
double dDepth, ICRVCOMPOPOVECTOR& vCrvPath) const
|
|
{
|
|
// funzione per collegare le curve trovate creando quindi i percorsi di lavoro
|
|
// NB. Nel primo TempParam deve essere memorizzata la distanza del piano della curva con il piano della Sfr
|
|
|
|
// controllo dei parametri
|
|
if ( pSfr == nullptr || ! pSfr->IsValid())
|
|
return false ;
|
|
|
|
// porto il tool nel frame della superficie
|
|
Vector3d vtToolLoc = GetToLoc( vtTool, frSurf) ;
|
|
|
|
// porto tutte le curve nel piano XY locale alla pSfr e, per ognuna di esse, definisco la regione
|
|
// piana di proiezione del materiale rimosso orientato a sinistra della curva
|
|
Frame3d frXY ;
|
|
Point3d ptCenter ; pSfr->GetCentroid( ptCenter) ;
|
|
if ( ! frXY.Set( ptCenter, vtToolLoc))
|
|
return false ;
|
|
vector<ISURFFRPOVECTOR> vSfrRemMatCol ; vSfrRemMatCol.resize( vCrvCompo.size()) ; // RemovedMaterialColumn
|
|
double dRadSignOffs = m_Params.m_bInvert ? m_TParams.m_dDiam / 2. : - m_TParams.m_dDiam / 2. ;
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "Crv & Sfr") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_OFF) ;
|
|
#endif
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
vSfrRemMatCol[i].resize( vCrvCompo[i].size()) ;
|
|
for ( int j = 0 ; j < int( vCrvCompo[i].size()) ; ++ j) {
|
|
// --- Frame locale XY
|
|
vCrvCompo[i][j]->ToLoc( frXY) ;
|
|
vCrvCompo[i][j]->SetExtrusion( m_Params.m_bInvert ? - Z_AX : Z_AX) ;
|
|
SurfFlatRegionByContours SfrBC ;
|
|
// --- Se curva chiusa
|
|
if ( vCrvCompo[i][j]->IsClosed()) {
|
|
SfrBC.AddCurve( CloneCurveComposite( vCrvCompo[i][j])) ;
|
|
OffsetCurve OffsCrv ;
|
|
OffsCrv.Make( vCrvCompo[i][j], dRadSignOffs, ICurve::OFF_FILLET) ;
|
|
PtrOwner<ICurve> pCrvIsl( OffsCrv.GetLongerCurve()) ;
|
|
while ( ! IsNull( pCrvIsl)) {
|
|
SfrBC.AddCurve( Release( pCrvIsl)) ;
|
|
pCrvIsl.Set( OffsCrv.GetLongerCurve()) ;
|
|
}
|
|
}
|
|
// --- Se curva aperta
|
|
else {
|
|
OffsetCurve OffsCrv ;
|
|
OffsCrv.Make( vCrvCompo[i][j], dRadSignOffs, ICurve::OFF_FILLET) ;
|
|
// [euristico, migliorabile/da_correggere]
|
|
PtrOwner<ICurve> pCrvInt( OffsCrv.GetLongerCurve()) ;
|
|
if ( ! IsNull( pCrvInt)) {
|
|
pCrvInt->Invert() ;
|
|
Point3d ptS ; pCrvInt->GetStartPoint( ptS) ;
|
|
Point3d ptE ; vCrvCompo[i][j]->GetStartPoint( ptE) ;
|
|
PtrOwner<ICurveComposite> pSfrLoop( CreateCurveComposite()) ;
|
|
if ( IsNull( pSfrLoop))
|
|
return false ;
|
|
pSfrLoop->AddCurve( CloneCurveComposite( vCrvCompo[i][j])) ;
|
|
pSfrLoop->AddLine( ptS) ;
|
|
pSfrLoop->AddCurve( Release( pCrvInt)) ;
|
|
pSfrLoop->AddLine( ptE) ;
|
|
SfrBC.AddCurve( Release( pSfrLoop)) ;
|
|
}
|
|
}
|
|
vSfrRemMatCol[i][j].Set( SfrBC.GetSurf()) ;
|
|
if ( IsNull( vSfrRemMatCol[i][j]) || ! vSfrRemMatCol[i][j]->IsValid())
|
|
vSfrRemMatCol[i][j].Set( GetSurfFlatRegionFromFatCurve( vCrvCompo[i][j]->Clone(), m_TParams.m_dDiam / 2., false, false)) ;
|
|
// tutte rivolte come Z_AX ( vtTool locale)
|
|
if ( AreOppositeVectorApprox( vSfrRemMatCol[i][j]->GetNormVersor(), Z_AX))
|
|
vSfrRemMatCol[i][j]->Invert() ;
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
Color myCol = Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.) ;
|
|
int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLay, ToString( vCrvCompo[i][j]->GetTempParam( 0))) ;
|
|
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, vCrvCompo[i][j]->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nId, myCol) ;
|
|
nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, vSfrRemMatCol[i][j]->Clone()) ;
|
|
myCol.SetAlpha( .25) ;
|
|
m_pGeomDB->SetMaterial( nId, myCol) ;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
// definisco le relazioni delle curve mediante le superfici create
|
|
int nRowSize = int( vCrvCompo.size()) ;
|
|
int nColSize = 0 ;
|
|
for ( int i = 0 ; i < nRowSize ; ++ i)
|
|
nColSize = max( nColSize, int( vCrvCompo[i].size())) ;
|
|
unordered_map<int, INTINTVECTOR> MapLock ;
|
|
unordered_map<int, INTINTVECTOR> MapUnlock ;
|
|
for ( int nR = int( vCrvCompo.size()) - 1 ; nR >= 1 ; -- nR) {
|
|
for ( int nC = 0 ; nC < int( vCrvCompo[nR].size()) ; ++ nC) {
|
|
for ( int nCol = 0 ; nCol < int( vCrvCompo[nR - 1].size()) ; ++ nCol) {
|
|
PtrOwner<ISurfFlatRegion> pSfrCheck( CloneSurfFlatRegion( vSfrRemMatCol[nR][nC])) ;
|
|
if ( ! IsNull( pSfrCheck)) {
|
|
pSfrCheck->Intersect( *vSfrRemMatCol[nR - 1][nCol]) ;
|
|
if ( pSfrCheck->IsValid() && pSfrCheck->GetChunkCount() > 0) {
|
|
int nKeyLock = nR * nColSize + nC ;
|
|
int nKeyUnLock = ( nR - 1) * nColSize + nCol ;
|
|
MapLock[nKeyLock].emplace_back( make_pair( nR - 1, nCol)) ;
|
|
MapUnlock[nKeyUnLock].emplace_back( make_pair( nR, nC)) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// definisco i gruppi di curve indpendenti; Un insieme di curve risulta indipendente da un altro
|
|
// insieme se l'ordine di esecuzione di essi è indifferente ;
|
|
// [non esiste alcuna curva nel gruppo A che interferisce con una curva del gruppo B)
|
|
vector<ICRVCOMPOPOVECTOR> vIndependentCurveGroup ;
|
|
bool bGroup = true ;
|
|
int nCont = 0 ;
|
|
while ( bGroup && nCont < nRowSize * nColSize) {
|
|
++ nCont ;
|
|
bGroup = false ;
|
|
// cerco la prima curva non ancora inserita in un gruppo
|
|
for ( int nR = int( vCrvCompo.size()) - 1 ; nR >= 0 && ! bGroup ; -- nR) {
|
|
// scorro sulle colonne ( dalla prima all'ultima) [ordine casuale]
|
|
for ( int nC = 0 ; nC < int( vCrvCompo[nR].size()) && ! bGroup ; ++ nC) {
|
|
// se la curva attuale già in un gruppo ( quindi nullptr), passo alla successiva
|
|
if ( vCrvCompo[nR][nC] == nullptr)
|
|
continue ;
|
|
// se trovo una curva, allora ho un nuovo gruppo da analizzare
|
|
bGroup = true ;
|
|
// creazione spazio per un nuovo gruppo
|
|
vIndependentCurveGroup.resize( vIndependentCurveGroup.size() + 1) ;
|
|
INTINTVECTOR vMapIndCheck = { make_pair( nR, nC)} ;
|
|
// finchè ho indici di riga-colonna da verificare
|
|
while ( ! vMapIndCheck.empty()) {
|
|
// memorizzo gli indici correnti
|
|
int nCurrRow = vMapIndCheck.back().first ;
|
|
int nCurrCol = vMapIndCheck.back().second ;
|
|
// tolgo l'elemento ( non devo ricontrollarlo all'iterazione successiva)
|
|
vMapIndCheck.pop_back() ;
|
|
// aggiungo la curva al percorso corrente
|
|
vIndependentCurveGroup.back().emplace_back( Release( vCrvCompo[nCurrRow][nCurrCol])) ;
|
|
// --- se la curva non è bloccata da nessun'altra
|
|
auto itLock = MapLock.find( nCurrRow * nColSize + nCurrCol) ;
|
|
if ( itLock == MapLock.end()) {
|
|
; // non faccio nulla ( ultimo piano locale)
|
|
}
|
|
// --- altrimenti
|
|
else {
|
|
// --- scorro le curve che bloccano quella corrente
|
|
for ( int i = 0 ; i < int( itLock->second.size()) ; ++ i) {
|
|
int nBR = itLock->second[i].first ;
|
|
int nBC = itLock->second[i].second ;
|
|
INTINT Key = make_pair( nBR, nBC) ;
|
|
auto itUnLock = MapUnlock.find( nBR * nColSize + nBC) ;
|
|
// verifico che non ci siano altre curve bloccate
|
|
bool bLock = false ;
|
|
for ( int j = 0 ; j < int( itUnLock->second.size()) && ! bLock ; ++ j)
|
|
bLock = ( vCrvCompo[itUnLock->second[j].first][itUnLock->second[j].second] != nullptr) ;
|
|
if ( ! bLock)
|
|
vMapIndCheck.emplace_back( Key) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "Independent Groups") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_OFF) ;
|
|
vector<Color> vCol ;
|
|
vector<int> vLay ;
|
|
for ( int nPath = 0 ; nPath < int( vIndependentCurveGroup.size()) ; ++ nPath) {
|
|
int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
vLay.emplace_back( nLay) ;
|
|
Color myCol = Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.) ;
|
|
vCol.emplace_back( myCol) ;
|
|
for ( auto& pCrv : vIndependentCurveGroup[nPath]) {
|
|
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, CloneCurveComposite( pCrv)) ;
|
|
m_pGeomDB->SetMaterial( nId, myCol) ;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// definisco il piano locale della regione piana ( frXY è centrato su di essa)
|
|
Plane3d plProjection ;
|
|
if ( ! plProjection.Set( ORIG, Z_AX))
|
|
return false ;
|
|
|
|
// ordino i gruppi di curve indipendenti
|
|
typedef pair<int, pair<double, double>> INTDBLDBL ; // <Ind, <ZMax, ZMin>>
|
|
vector<INTDBLDBL> vMapGrpZLoc ;
|
|
vMapGrpZLoc.reserve( vIndependentCurveGroup.size()) ;
|
|
for ( int i = 0 ; i < int( vIndependentCurveGroup.size()) ; ++ i) {
|
|
// scorro le curve del gruppo cercando quella più in alto ( rispetto alla Zlocale di frXY)
|
|
double dZMax = - INFINITO ;
|
|
double dZMin = INFINITO ;
|
|
for ( auto& pCrv : vIndependentCurveGroup[i]) {
|
|
double dCurrZ = pCrv->GetTempParam( 0) ;
|
|
dZMax = max( dZMax, dCurrZ) ;
|
|
dZMin = min( dZMin, dCurrZ) ;
|
|
}
|
|
vMapGrpZLoc.emplace_back( make_pair( i, make_pair( dZMax, dZMin))) ;
|
|
}
|
|
// ordino
|
|
sort( vMapGrpZLoc.begin(), vMapGrpZLoc.end(), []( const INTDBLDBL& GrpA, const INTDBLDBL& GrpB) {
|
|
// Se ZMax coincidenti, viene prima quello con ZMin superiore
|
|
if ( abs( GrpA.second.first - GrpB.second.first) < 10 * EPS_SMALL)
|
|
return ( GrpA.second.second > GrpB.second.second) ;
|
|
// Se diffeenti, viene prima quello con ZMax superiore
|
|
return ( GrpA.second > GrpB.second) ;
|
|
}) ;
|
|
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "Ordered Independent Groups") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_OFF) ;;
|
|
vLay.clear() ;
|
|
for ( int nPath = 0 ; nPath < int( vMapGrpZLoc.size()) ; ++ nPath) {
|
|
int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
vLay.emplace_back( nLay) ;
|
|
for ( auto& pCrv : vIndependentCurveGroup[vMapGrpZLoc[nPath].first]) {
|
|
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, CloneCurveComposite( pCrv)) ;
|
|
m_pGeomDB->SetMaterial( nId, vCol[vMapGrpZLoc[nPath].first]) ;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// tengo una copia dei bordi della regione ( servono per limitare i collegamenti tra le curve dei Path)
|
|
PtrOwner<ISurfFlatRegion> pSfrClass( CloneSurfFlatRegion( pSfr)) ;
|
|
if ( IsNull( pSfrClass) || ! pSfrClass->IsValid() || ! pSfrClass->ToLoc( frXY))
|
|
return false ;
|
|
ICRVCOMPOPOVECTOR vCrvSfrLoops ;
|
|
for ( int nC = 0 ; nC < pSfrClass->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pSfrClass->GetLoopCount( nC) ; ++ nL) {
|
|
PtrOwner<ICurveComposite> pCrvLoop( ConvertCurveToComposite( pSfrClass->GetLoop( nC, nL))) ;
|
|
if ( IsNull( pCrvLoop) || ! pCrvLoop->IsValid())
|
|
return false ;
|
|
// tutti i loop sono orientati come il loop esterno
|
|
// NB. Per classificare i collegamenti si usa la regione, non queste curve !
|
|
// [ Vengono utilizzate per non inizializzare ogni volta una curva corrispondente al bordo
|
|
// della superficie di classificazione]
|
|
if ( nL > 0)
|
|
pCrvLoop->Invert() ;
|
|
vCrvSfrLoops.emplace_back( Release( pCrvLoop)) ;
|
|
}
|
|
}
|
|
|
|
// definisco i collegamenti tra i percorsi
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "Paths") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_OFF) ;
|
|
#endif
|
|
const double LINK_TOL = 25. * EPS_SMALL ;
|
|
Point3d ptRef = P_INVALID ;
|
|
for ( int i = 0 ; i < int( vMapGrpZLoc.size()) ; ++ i) {
|
|
// recupero l'indice ordinato del percorso
|
|
int nPath = vMapGrpZLoc[i].first ;
|
|
// inverto il vettore delle curve di bordo del percorso corrente
|
|
reverse( vIndependentCurveGroup[nPath].begin(), vIndependentCurveGroup[nPath].end()) ;
|
|
// definisco il vettore dei collegamenti creati tra le curve
|
|
// NB. Un collegamento potrebbe non essere valido e non realizzabile
|
|
// NB. Il collegamento i-esimo collega la curva di bordo (i-1)-esima con la curva di bordo i-esima
|
|
ICRVCOMPOPOVECTOR vCompoLink ;
|
|
vCompoLink.resize( vIndependentCurveGroup[nPath].size()) ; // nullptr per ogni Link
|
|
|
|
// --- se non ho curve, passo al gruppo successivo
|
|
if ( vIndependentCurveGroup[nPath].empty())
|
|
continue ;
|
|
|
|
// --- se ho una sola curva, allora controllo se posso cambiare il suo punto d'inizio
|
|
// nel caso non sia la prima in assoluto [ -> controllo ptRef]
|
|
if ( int( vIndependentCurveGroup[nPath].size()) == 1) {
|
|
if ( ptRef.IsValid()) {
|
|
// --- se la curva di bordo singola è aperta
|
|
if ( ! vIndependentCurveGroup[nPath][0]->IsClosed()) {
|
|
// ... se necessario la inverto per recuperare l'estremo più vicino a ptRef
|
|
// [ per ora le curve aperte possono essere invertite nelle finiture a ZLevel]
|
|
Point3d ptS ; vIndependentCurveGroup[nPath][0]->GetStartPoint( ptS) ;
|
|
Point3d ptE ; vIndependentCurveGroup[nPath][0]->GetEndPoint( ptE) ;
|
|
if ( SqDist( ptE, ptRef) < SqDist( ptS, ptRef))
|
|
vIndependentCurveGroup[nPath][0]->Invert() ;
|
|
}
|
|
// --- se la curva di bordo singola è chiusa
|
|
else {
|
|
// cerco il punto a minima distanza da ptRef ( non inverto, tengo il senso di lavorazione)
|
|
double dMinPar = 0. ;
|
|
int nFlag = 0 ;
|
|
DistPointCurve( ptRef, *vIndependentCurveGroup[nPath][0]).GetParamAtMinDistPoint( 0., dMinPar, nFlag) ;
|
|
vIndependentCurveGroup[nPath][0]->ChangeStartPoint( dMinPar) ;
|
|
}
|
|
}
|
|
// inserisco la curva nel percorso
|
|
vCrvPath.emplace_back( Release( vIndependentCurveGroup[nPath][0])) ;
|
|
// aggiorno il punto di riferimento
|
|
vCrvPath.back()->GetEndPoint( ptRef) ;
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLay, "Single") ;
|
|
Color myCol = Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.) ;
|
|
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, CloneCurveComposite( vCrvPath.back())) ;
|
|
m_pGeomDB->SetMaterial( nId, myCol) ;
|
|
#endif
|
|
continue ;
|
|
}
|
|
|
|
// --- se ho più curve di bordo, scorro le curve a due a due per creare i collegamenti
|
|
for ( int nCompo = 0 ; nCompo < int( vIndependentCurveGroup[nPath].size()) - 1 ; ++ nCompo) {
|
|
// se prima curva di bordo e ho un punto di riferimento valido
|
|
if ( nCompo == 0 && ptRef.IsValid()) {
|
|
// --- se la prima curva di bordo è aperta
|
|
if ( ! vIndependentCurveGroup[nPath][0]->IsClosed()) {
|
|
// ... se necessario la inverto per recuperare l'estremo più vicino a ptRef
|
|
// [ per ora le curve aperte possono essere invertite nelle finiture a ZLevel]
|
|
Point3d ptS ; vIndependentCurveGroup[nPath][0]->GetStartPoint( ptS) ;
|
|
Point3d ptE ; vIndependentCurveGroup[nPath][0]->GetEndPoint( ptE) ;
|
|
if ( SqDist( ptE, ptRef) < SqDist( ptS, ptRef))
|
|
vIndependentCurveGroup[nPath][0]->Invert() ;
|
|
}
|
|
// --- se la prima curva di bordo è chiusa
|
|
else {
|
|
// cerco il punto a minima distanza da ptRef ( non inverto, tengo il senso di lavorazione)
|
|
double dMinPar = 0. ;
|
|
int nFlag = 0 ;
|
|
DistPointCurve( ptRef, *vIndependentCurveGroup[nPath][0]).GetParamAtMinDistPoint( 0., dMinPar, nFlag) ;
|
|
vIndependentCurveGroup[nPath][0]->ChangeStartPoint( dMinPar) ;
|
|
}
|
|
}
|
|
// come riferimento imposto inizialmente il punto finale della curva corrente
|
|
vIndependentCurveGroup[nPath][nCompo]->GetEndPoint( ptRef) ;
|
|
// --- se la curva di bordo successiva è aperta...
|
|
if ( ! vIndependentCurveGroup[nPath][nCompo + 1]->IsClosed()) {
|
|
// ... se necessario la inverto per recuperare l'estremo più vicino a quello corrente
|
|
// [ per ora le curve aperte possono essere invertite nelle finiture a ZLevel]
|
|
Point3d ptS ; vIndependentCurveGroup[nPath][nCompo + 1]->GetStartPoint( ptS) ;
|
|
Point3d ptE ; vIndependentCurveGroup[nPath][nCompo + 1]->GetEndPoint( ptE) ;
|
|
if ( SqDist( ptE, ptRef) < SqDist( ptS, ptRef))
|
|
vIndependentCurveGroup[nPath][nCompo + 1]->Invert() ;
|
|
}
|
|
// --- se la curva successiva è chiusa
|
|
else {
|
|
// cerco il punto a minima distanza ( non inverto, tengo il senso di lavorazione)
|
|
double dMinPar = 0. ;
|
|
int nFlag = 0 ;
|
|
DistPointCurve( ptRef, *vIndependentCurveGroup[nPath][nCompo + 1]).GetParamAtMinDistPoint( 0., dMinPar, nFlag) ;
|
|
vIndependentCurveGroup[nPath][nCompo + 1]->ChangeStartPoint( dMinPar) ;
|
|
}
|
|
|
|
// definisco il collegamento diretto come tratto lineare
|
|
Point3d ptStartLink ; vIndependentCurveGroup[nPath][nCompo]->GetEndPoint( ptStartLink) ;
|
|
Point3d ptEndLink ; vIndependentCurveGroup[nPath][nCompo + 1]->GetStartPoint( ptEndLink) ;
|
|
PtrOwner<ICurveLine> pLineLink( CreateCurveLine()) ;
|
|
if ( IsNull( pLineLink) || ! pLineLink->Set( ptStartLink, ptEndLink) || ! pLineLink->IsValid())
|
|
continue ; // il Link rimane nullptr
|
|
|
|
// --- se il Link è parallelo a vtTool ( Z_AX in locale), allora ho una parete verticale ( localemente)
|
|
Vector3d vtDirLink ; pLineLink->GetStartDir( vtDirLink) ;
|
|
if ( AreSameOrOppositeVectorEpsilon( vtDirLink, Z_AX, 100 * EPS_SMALL)) {
|
|
// la proiezione del Link è automaticamente all'interno della superficie di classificazione
|
|
vCompoLink[nCompo + 1].Set( ConvertCurveToComposite( Release( pLineLink))) ;
|
|
}
|
|
// --- se il tratto lineare è troppo lungo, non considero il collegamento come valido
|
|
else {
|
|
if ( SqDist( ptStartLink, ptEndLink) > 4. * m_TParams.m_dDiam * m_TParams.m_dDiam)
|
|
continue ; // il Link rimane nullptr
|
|
|
|
// proietto la curva nel piano locale della superficie di classificazione ( Z=0 ; Z_AX)
|
|
PtrOwner<ICurve> pLineLinkProj( ProjectCurveOnPlane( *pLineLink, plProjection)) ;
|
|
if ( IsNull( pLineLinkProj) || ! pLineLinkProj->IsValid())
|
|
return false ;
|
|
// effettuo la classificazione
|
|
CRVCVECTOR ccClass ;
|
|
if ( ! pSfrClass->GetCurveClassification( *pLineLinkProj, EPS_SMALL, ccClass))
|
|
continue ; // il Link rimane nullptr
|
|
|
|
// inizializzo il link come curva vuota e scorro le classificazioni ottenute
|
|
vCompoLink[nCompo + 1].Set( CreateCurveComposite()) ;
|
|
for ( int i = 0 ; i < int( ccClass.size()) ; ++ i) {
|
|
// recupero il tratto di curve corrente
|
|
PtrOwner<ICurve> pSubCrv( pLineLinkProj->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE)) ;
|
|
if ( IsNull( pSubCrv) || ! pSubCrv->IsValid()) // troppo piccolo...
|
|
continue ; // passo al tratto di classificazione successivo
|
|
// --- se la curva non è esterna alla regione, la conservo
|
|
if ( ccClass[i].nClass != CRVC_OUT) {
|
|
if ( ! vCompoLink[nCompo + 1]->AddCurve( Release( pSubCrv), true, LINK_TOL))
|
|
return false ;
|
|
}
|
|
// --- se la curva è esterna, devo seguire il bordo della regione di classificazione
|
|
else {
|
|
// recupero gli estremi del segmento di classificazione esterno alla pSfrClass
|
|
Point3d ptS_sfr ; pLineLinkProj->GetPointD1D2( ccClass[i].dParS, ICurve::FROM_MINUS, ptS_sfr) ;
|
|
Point3d ptE_sfr ; pLineLinkProj->GetPointD1D2( ccClass[i].dParE, ICurve::FROM_MINUS, ptE_sfr) ;
|
|
// scorro tutti i loop della regione di classificazione
|
|
for ( int j = 0 ; j < int( vCrvSfrLoops.size()) ; ++ j) {
|
|
// se i punti trovati sono sul loop corrente
|
|
if ( vCrvSfrLoops[j]->IsPointOn( ptS_sfr, LINK_TOL) &&
|
|
vCrvSfrLoops[j]->IsPointOn( ptE_sfr, LINK_TOL)) {
|
|
// devo orientare la SubCrv secondo il giusto verso di percorrenza
|
|
double dUS ; vCrvSfrLoops[j]->GetParamAtPoint( ptS_sfr, dUS, LINK_TOL) ;
|
|
double dUE ; vCrvSfrLoops[j]->GetParamAtPoint( ptE_sfr, dUE, LINK_TOL) ;
|
|
PtrOwner<ICurve> pCrvA( ( vCrvSfrLoops[j]->CopyParamRange( dUS, dUE))) ;
|
|
PtrOwner<ICurve> pCrvB( ( vCrvSfrLoops[j]->CopyParamRange( dUE, dUS))) ;
|
|
double dLenA = INFINITO ; double dLenB = INFINITO ;
|
|
if ( ! IsNull( pCrvA) && pCrvA->IsValid())
|
|
pCrvA->GetLength( dLenA) ;
|
|
if ( ! IsNull( pCrvB) && pCrvB->IsValid()) {
|
|
// sempre percorsa in senso opposto
|
|
pCrvB->Invert() ;
|
|
pCrvB->GetLength( dLenB) ;
|
|
}
|
|
// aggiungo la curva
|
|
if ( ! vCompoLink[nCompo + 1]->AddCurve( dLenA < dLenB ? Release( pCrvA) : Release( pCrvB), true, LINK_TOL))
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// se il link trovato non è valido, passo al successivo
|
|
if ( ! vCompoLink[nCompo + 1]->IsValid())
|
|
continue ; // il link rimane inizializzato e non valido ( 0 curve)
|
|
|
|
// porto il link sul piano della curva più in alto tra le due
|
|
Point3d ptCheck ;
|
|
vIndependentCurveGroup[nPath][nCompo + 1]->GetStartPoint( ptCheck) ;
|
|
double dSfrDistNext = DistPointPlane( ptCheck, plProjection) ;
|
|
vIndependentCurveGroup[nPath][nCompo]->GetStartPoint( ptCheck) ;
|
|
double dSfrDistCurr = DistPointPlane( ptCheck, plProjection) ;
|
|
vCompoLink[nCompo + 1]->Translate( Z_AX * min( dSfrDistCurr, dSfrDistNext)) ;
|
|
// proietto tale Link sulla superficie
|
|
if ( ! CalcZConstProjectedLink( pCAvTlStm, frXY, frSurf, vtTool, dDepth, ptStartLink, ptEndLink, vCompoLink[nCompo + 1]))
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
// calcolo il percorso unendo le curve di bordo con i Link ricavati
|
|
const double PATH_TOL = 1500. * EPS_SMALL ;
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
int nLay = GDB_ID_NULL ;
|
|
Color myCol = INVISIBLE ;
|
|
#endif
|
|
for ( int nCompo = 0 ; nCompo < int( vIndependentCurveGroup[nPath].size()) - 1 ; ++ nCompo) {
|
|
if ( IsNull( vCompoLink[nCompo]) || ! vCompoLink[nCompo]->IsValid()) {
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
myCol = Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.) ;
|
|
#endif
|
|
if ( ! vCrvPath.emplace_back( CreateCurveComposite()))
|
|
return false ;
|
|
}
|
|
else {
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, CloneCurveComposite( vCompoLink[nCompo])) ;
|
|
m_pGeomDB->SetMaterial( nId, myCol) ;
|
|
#endif
|
|
vCrvPath.back()->AddCurve( Release( vCompoLink[nCompo]), true, PATH_TOL) ;
|
|
}
|
|
#if ENABLE_ZCONST_PATH_DEBUG
|
|
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, CloneCurveComposite( vIndependentCurveGroup[nPath][nCompo])) ;
|
|
m_pGeomDB->SetMaterial( nId, myCol) ;
|
|
#endif
|
|
vCrvPath.back()->AddCurve( Release( vIndependentCurveGroup[nPath][nCompo]), true, PATH_TOL) ;
|
|
}
|
|
}
|
|
|
|
// riporto i percorsi nel frame originale
|
|
for ( int i = 0 ; i < int( vCrvPath.size()) ; ++ i)
|
|
vCrvPath[i]->ToGlob( frXY) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcZConstProjectedLink( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frPocket,
|
|
const Frame3d& frSurf, const Vector3d& vtTool, double dDepth,
|
|
const Point3d ptStart_forced, const Point3d ptEnd_forced,
|
|
ICurveComposite* pCrv) const
|
|
{
|
|
// funzione per proiettare una curva su una supericie trimesh passando per la silhouette
|
|
// controllo dei parametri
|
|
if ( pCAvTlStm == nullptr || pCrv == nullptr || ! pCrv->IsValid())
|
|
return false ;
|
|
// approssimo la curva con una polilinea
|
|
PolyLine PL ;
|
|
if ( ! pCrv->ApproxWithLines( m_Params.m_dApprox, ANG_TOL_STD_DEG, ICurve::APL_SPECIAL, PL))
|
|
return false ;
|
|
// eventuale aggiunta di punti per garantire max distanza
|
|
const double MIN_DIST = 1. ;
|
|
const double MAX_DIST = 50. ;
|
|
double dDist = Clamp( m_TParams.m_dDiam / 2, MIN_DIST, MAX_DIST) ;
|
|
if ( ! PL.AdjustForMaxSegmentLen( dDist))
|
|
return false ;
|
|
// porto nel riferimento delle superfici
|
|
PL.ToGlob( frPocket) ;
|
|
// porto i dati geometrici in locale alle superfici
|
|
Vector3d vtAxL = GetToLoc( vtTool, frSurf) ;
|
|
Vector3d vtMoveL = vtAxL ;
|
|
// traslo della lunghezza utensile diminuita dell'affondamento
|
|
PL.Translate( vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
// eseguo il test del percorso
|
|
if ( ! pCAvTlStm->TestPath( PL.GetUPointList(), vtAxL, vtMoveL, m_Params.m_dApprox))
|
|
return false ;
|
|
// contro-traslo della lunghezza utensile
|
|
PL.Translate( - vtAxL * m_TParams.m_dLen) ;
|
|
// riporto la polilinea nel riferimento della curva
|
|
PL.ToLoc( frPocket) ;
|
|
// elimino i punti allineati
|
|
PL.RemoveAlignedPoints( 0.8 * m_Params.m_dApprox) ;
|
|
// sostituisco primo ed ultimo punto con quelli forzati
|
|
PL.EraseFirstUPoint() ;
|
|
PL.EraseLastUPoint() ;
|
|
PL.AddUPoint( 0, ptStart_forced, false) ;
|
|
PL.AddUPoint( PL.GetPointNbr(), ptEnd_forced, true) ;
|
|
// controllo di non essere sceso oltre la depth (il link non per forza è vicino ad una curva di livello)
|
|
PNTULIST& myPtUList = PL.GetUPointList() ;
|
|
for ( POINTU& myPtU : myPtUList) {
|
|
#if ENABLE_ZCONST_DEBUG
|
|
PtrOwner<IGeoPoint3d> myPt( CreateGeoPoint3d()) ;
|
|
myPt->Set( myPtU.first) ;
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, myPt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( a, WHITE) ;
|
|
#endif // ENABLE_OPTIMAL_DEBUG
|
|
|
|
if ( myPtU.first.z < - dDepth)
|
|
myPtU.first.z = - dDepth ;
|
|
}
|
|
// creo una curva composita a partire dalla polilinea
|
|
PtrOwner< ICurveComposite> pCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCompo) || ! pCompo->FromPolyLine( PL))
|
|
return false ;
|
|
// sostituisco la vecchia curva con la nuova
|
|
pCrv->CopyFrom( pCompo) ;
|
|
return true ;
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddZConst( ICAvToolSurfTm* pCAvTlStm, const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf, const ISurfFlatRegion* pSfrCnt,
|
|
const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs)
|
|
{
|
|
|
|
// controllo che la regione sia definita correttamente
|
|
if ( pSfrCnt == nullptr || ! pSfrCnt->IsValid())
|
|
return false ;
|
|
|
|
// aggiorno la ProgressBar del 5% per simulare l'inizio della funzione
|
|
ExeProcessEvents( 5, 0) ;
|
|
|
|
// definisco un frame implicito dalla superficie
|
|
Frame3d frSfr ;
|
|
Point3d ptC ; pSfrCnt->GetCentroid( ptC) ;
|
|
if ( ! frSfr.Set( ptC, pSfrCnt->GetNormVersor()))
|
|
return false ;
|
|
frSfr.ToLoc( frSurf) ; // in locale alle SrfLoc
|
|
|
|
// aggiusto la regione a seconda dei parametri e la porto nel frame locale delle superfici
|
|
PtrOwner<ISurfFlatRegion> pSfrClass( CloneSurfFlatRegion( pSfrCnt)) ;
|
|
if ( IsNull( pSfrClass) || ! pSfrClass->IsValid() || ! pSfrClass->ToLoc( frSurf))
|
|
return false ;
|
|
|
|
// inizializzo la classe di calcolo delle silhouette
|
|
CISURFTMPVECTOR vpStm ; vpStm.reserve( vSrfLoc.size()) ;
|
|
// scorro le superfici
|
|
for ( int i = 0 ; i < int( vSrfLoc.size()) ; ++ i) {
|
|
// recupero la superficie
|
|
const ISurf* pSurf = GetSurf( vSrfLoc[i].Get()) ;
|
|
if ( pSurf == nullptr || ! pSurf->IsValid())
|
|
continue ;
|
|
int nType = pSurf->GetType() ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pSurf) ;
|
|
// se valida, memorizzo
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
// se Bezier
|
|
if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurf) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pStm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
// se valida, memorizzo
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
}
|
|
}
|
|
const double TOL_SAMPLING = 1. ;
|
|
PtrOwner<ICAvParSilhouettesSurfTm> pCavParSilh( CreateCAvParSilhouettesSurfTm()) ;
|
|
if ( IsNull( pCavParSilh) ||
|
|
! pCavParSilh->SetData( vpStm, frSfr, TOL_SAMPLING, m_TParams.m_dSideAng, m_TParams.m_dDiam,
|
|
m_TParams.m_dCornRad, m_TParams.m_dMaxMat, GetOffsR(), dDepth))
|
|
return false ;
|
|
|
|
// aggiorno la ProgressBar al 30%
|
|
ExeProcessEvents( 30, 0) ;
|
|
|
|
// recupero le curve singole definite dal bordo della Silhouette
|
|
vector<ICRVCOMPOPOVECTOR> vCrvCompo ;
|
|
if ( ! CalcZConstSilCrv( pCavParSilh, vSrfLoc, frSurf, pSfrClass, vtTool, dDepth, vCrvCompo)) {
|
|
m_pMchMgr->SetLastError( 3126, "Error in SurfFinishing : Computing ZConst Curves failed") ;
|
|
return false ;
|
|
}
|
|
// se non ho curve, esco
|
|
bool bNoCrv = true ;
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) && bNoCrv ; ++ i)
|
|
bNoCrv = ( vCrvCompo[i].empty()) ;
|
|
if ( bNoCrv)
|
|
return true ;
|
|
|
|
// collego tra loro le curve trovate
|
|
ICRVCOMPOPOVECTOR vCrvPath ;
|
|
if ( ! CreateZConstPaths( pCAvTlStm, frSurf, vCrvCompo, vtTool, pSfrClass, dDepth, vCrvPath)) {
|
|
m_pMchMgr->SetLastError( 3127, "Error in SurfFinishing : Computing ZConst Paths failed") ;
|
|
return false ;
|
|
}
|
|
// se non ho percorsi, errore
|
|
if ( vCrvPath.empty())
|
|
return false ;
|
|
ExeProcessEvents( 90, 0) ;
|
|
|
|
// porto tutti i percorsi in Globale
|
|
for ( int i = 0 ; i < int( vCrvPath.size()) ; ++ i)
|
|
vCrvPath[i]->ToGlob( frSurf) ;
|
|
|
|
// aggiungo i percorsi di finitura calcolati
|
|
if ( ! AddFinishing( pSfrCnt, pCAvTlStm, frSurf, vCrvPath, vtTool, dElev, dDepth, bSplitArcs))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::ApproxSilhouetteClosedPLForOptimal( PolyLine& PL, double dSampleTol, double dMaxLinTol, double dAngTol, double dLinFeaTol,
|
|
ICurveComposite* pCompoPL)
|
|
{
|
|
// approssimazione di una polyline di Silhouette per rimuovere Spikes di proiezione
|
|
// controllo dei parametri
|
|
if ( pCompoPL == nullptr)
|
|
return false ;
|
|
pCompoPL->Clear() ;
|
|
// se aperta errore
|
|
Plane3d plPL ;
|
|
double dArea ;
|
|
if ( ! PL.IsClosedAndFlat( plPL, dArea))
|
|
return false ;
|
|
// semplifico rimuovendo i punti allineati
|
|
PL.RemoveAlignedPoints( dSampleTol + 10 * EPS_SMALL) ;
|
|
// essendo chiusa, se presenti meno di 4 punti, non faccio nulla
|
|
int nPts = PL.GetPointNbr() ;
|
|
if ( nPts < 4)
|
|
return true ;
|
|
// porto la PolyLine nel frame LocaleXY
|
|
Frame3d frLoc ;
|
|
if ( ! frLoc.Set( plPL.GetPoint(), plPL.GetVersN()))
|
|
return false ;
|
|
PL.ToLoc( frLoc) ;
|
|
|
|
// --------------------------- scelta del punto iniziale ------------------------------
|
|
|
|
// creo un vettore contenente tutti i punti ( cerco nel mentre il segmento più lungo)
|
|
PNTVECTOR vPt ; vPt.reserve( nPts) ;
|
|
int nLongEdge = -1 ;
|
|
double dMaxSqLen = 0. ;
|
|
Point3d myPt ;
|
|
if ( ! PL.GetFirstPoint( myPt))
|
|
return false ;
|
|
vPt.emplace_back( myPt) ;
|
|
while ( PL.GetNextPoint( myPt)) {
|
|
double dCurrSqDist = SqDist( vPt.back(), myPt) ;
|
|
if ( dCurrSqDist > dMaxSqLen) {
|
|
dMaxSqLen = dCurrSqDist ;
|
|
nLongEdge = int( vPt.size()) - 1 ;
|
|
}
|
|
vPt.emplace_back( myPt) ;
|
|
}
|
|
if ( nLongEdge < 0 || nLongEdge > nPts - 2)
|
|
return false ;
|
|
// calcolo il punto iniziale come punto medio del segmento più lungo
|
|
Point3d ptStart = Media( vPt[nLongEdge], vPt[nLongEdge + 1]) ;
|
|
ChangePolyLineStart( PL, ptStart, 10 * EPS_SMALL) ;
|
|
nPts = PL.GetPointNbr() ;
|
|
|
|
// ---------------------- modifica dei punti Spike ---------------------------------
|
|
|
|
// creo un vettore di punti a partire dai punti della PolyLine
|
|
PNTVECTOR vPts ; vPts.reserve( nPts) ;
|
|
PL.GetFirstPoint( myPt) ;
|
|
vPts.emplace_back( myPt) ;
|
|
while ( PL.GetNextPoint( myPt))
|
|
vPts.emplace_back( myPt) ;
|
|
|
|
// dichiaro i versori tangenti consecutivi per il percorso della PolyLinea
|
|
Vector3d vtTanPrev, vtTan, vtTanAfter ;
|
|
// recupero il cosendo della tolleranza angolare
|
|
double dCosAngTol = abs( cos( dAngTol * DEGTORAD)) ;
|
|
// calcolo il quadrato della tolleranza lineare
|
|
double dSqMaxLinTol = dMaxLinTol * dMaxLinTol ;
|
|
// ciclo tutti i punti della PolyLine
|
|
for ( int i = 2 ; i < int( vPts.size()) - 1 ; ++ i) {
|
|
// se distanza tra punto attuale e precedente sopra al tolleranza, passo ai successivi
|
|
if ( SqDist( vPts[i], vPts[i-1]) > dSqMaxLinTol)
|
|
continue ;
|
|
// calcolo il versore tangente del segmento pecedente
|
|
vtTanPrev = vPts[i-1] - vPts[i-2] ;
|
|
vtTanPrev.Normalize() ;
|
|
// calcolo versore tangente attuale
|
|
vtTan = vPts[i] - vPts[i-1] ;
|
|
vtTan.Normalize() ;
|
|
// recupero la direzione successia
|
|
vtTanAfter = vPts[i+1] - vPts[i] ;
|
|
vtTanAfter.Normalize() ;
|
|
// controllo se l'angolo tra la direzione attuale e precedente supera la tolleranza
|
|
if ( abs( vtTanPrev * vtTan) > dCosAngTol && abs( vtTan * vtTanAfter) > dCosAngTol)
|
|
continue ; // se uno dei due sotto la tolleranza, analizzo segmento successivo
|
|
// se Spike individuato, modifico il punto corrente con il punto medio del segmento attuale
|
|
vPts[i] = Media( vPts[i], vPts[i-1]) ;
|
|
// il punto precedente diventa uguale all' i-2-esimo
|
|
vPts[i-1] = vPts[i-2] ;
|
|
}
|
|
|
|
// a partire da questi punti, creo la PolyLine
|
|
double dPar = -1 ;
|
|
PolyLine myPL ;
|
|
myPL.AddUPoint( ++ dPar, vPts[0]) ; // il primo punto è automaticamente inserito
|
|
Point3d myLastPtInPL = vPts[0] ;
|
|
for ( int i = 1 ; i < int( vPts.size()) ; ++ i) {
|
|
// se il punto corrente è già inserito nella PolyLine, passo al successivo
|
|
if ( AreSamePointApprox( vPts[i], myLastPtInPL))
|
|
continue ;
|
|
// altrimenti inserisco il punto nella Polyline e aggiorno il punto finale
|
|
myPL.AddUPoint( ++ dPar, vPts[i]) ;
|
|
myLastPtInPL = vPts[i] ;
|
|
}
|
|
// chiudo la PolyLine per sicurezza
|
|
myPL.Close() ;
|
|
|
|
// swap
|
|
swap( PL, myPL) ;
|
|
|
|
// recupero la curva composita dalla polyLine
|
|
if ( ! pCompoPL->FromPolyLine( PL) || ! pCompoPL->IsValid())
|
|
return false ;
|
|
|
|
// approssimo con archi
|
|
PolyArc PA ;
|
|
double dMyLinFea = dLinFeaTol ;
|
|
double dMyAngTol = dAngTol ;
|
|
if ( dMaxLinTol > LIN_TOL_STD) {
|
|
double dCoeff = ( dMaxLinTol - LIN_TOL_STD) / LIN_TOL_STD ;
|
|
dMyLinFea = min( LIN_FEA_STD + 1.0 * dCoeff * LIN_FEA_STD, 400.) ;
|
|
dMyAngTol = min( ANG_TOL_STD_DEG + 0.2 * dCoeff * ANG_TOL_STD_DEG, 60.) ;
|
|
}
|
|
if ( pCompoPL->ApproxWithArcsEx( dMaxLinTol, dMyAngTol, dMyLinFea, PA)) {
|
|
PtrOwner<ICurveComposite> pTempCrv( CreateCurveComposite()) ;
|
|
if ( ! IsNull( pTempCrv) &&
|
|
pTempCrv->FromPolyArc( PA) &&
|
|
pTempCrv->RemoveSmallDefects( dMaxLinTol, ANG_TOL_STD_DEG) &&
|
|
pTempCrv->MergeCurves( dMaxLinTol, ANG_TOL_STD_DEG)) {
|
|
pCompoPL->CopyFrom( pTempCrv) ;
|
|
}
|
|
}
|
|
// riporto la curva nel frame di partenza
|
|
pCompoPL->ToGlob( frLoc) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetSfrBySilhouette( ICAvParSilhouettesSurfTm* pCavParSilh, double dDepth,
|
|
double dSilTolSamp, double dSilTolLin,
|
|
double dSilTolAng, ISurfFlatRegion* pSfrSil)
|
|
{
|
|
// funzione per resitutire una regione piana data la classe di calcolo per silhouette
|
|
// controllo dei parametri
|
|
if ( pSfrSil == nullptr)
|
|
return false ;
|
|
pSfrSil->Clear() ;
|
|
// recupero il vettore di PolyLine della silhouette
|
|
POLYLINEVECTOR vPL ;
|
|
if ( ! pCavParSilh->GetSilhouette( - dDepth, vPL))
|
|
return false ;
|
|
// creo la regione piana dalle PolyLine ricavate dalla Silhouette
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( auto& PL : vPL) {
|
|
// recupero la curva in base alla polyLine
|
|
PtrOwner<ICurveComposite> pSilCrv( CreateCurveComposite()) ;
|
|
if ( IsNull( pSilCrv))
|
|
return false ;
|
|
if ( ! ApproxSilhouetteClosedPLForOptimal( PL, dSilTolSamp, dSilTolLin, ANG_TOL_STD_DEG, LIN_FEA_STD, pSilCrv))
|
|
return false ;
|
|
// aggiungo per regione
|
|
if ( ! SfrMaker.AddCurve( Release( pSilCrv)))
|
|
return false ;
|
|
}
|
|
// definisco la regione piana
|
|
PtrOwner<ISurfFlatRegion> pSfrTmp( SfrMaker.GetSurf()) ;
|
|
if ( ! IsNull( pSfrTmp) && pSfrTmp->IsValid())
|
|
pSfrSil->CopyFrom( pSfrTmp) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::SplitStmTrianglesByClippingAngle( const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf, const ISurfFlatRegion* pSfrCnt,
|
|
const Vector3d& vtTool, double dDepth, double dClippingAngle, double dTolerAngle,
|
|
ISURFTMPOVECTOR& vpStm1, ISURFTMPOVECTOR& vpStm2, double& dMaxFrontTriaRad) const
|
|
{
|
|
// Funzione per ciclare i triangoli di una TriMesh (*pStm)
|
|
// I triangoli che formano un angolo, in valore assoluto con vtTool, maggiore di dClippingAngle
|
|
// vengono inseriti nella zuppa TriaSoupZConst, gli altri in TriaSoupSpiral
|
|
// dMaxFrontTriaRad è il raggio massimo dei triangoli con normale che si discosta da vtTool per
|
|
// meno di dTolerAngle (triangoli frontalieri)
|
|
|
|
// definisco il piano di taglio alla profondità massima
|
|
Point3d ptCenter ; pSfrCnt->GetCentroid( ptCenter) ;
|
|
Plane3d plClipping ;
|
|
Point3d ptPlCl = GetToLoc( ptCenter, frSurf) ;
|
|
Vector3d vtNCl = GetToLoc( vtTool, frSurf) ;
|
|
if ( ! plClipping.Set( ptPlCl - vtNCl * ( dDepth + 25 * EPS_SMALL), - vtNCl))
|
|
return false ;
|
|
|
|
// porto il versore utensile nel riferimento locale
|
|
Vector3d vtToolLoc = vtTool ; vtToolLoc.ToLoc( frSurf) ;
|
|
// aggiusto i parametri
|
|
dClippingAngle = Clamp( dClippingAngle, 30., 60.) ; // [30°,60°]
|
|
dTolerAngle = Clamp( dTolerAngle, 1., 5.) ; // [1°,5°]
|
|
|
|
// definizione delle costanti
|
|
double dCosLimit = cos( dClippingAngle * DEGTORAD) ;
|
|
double dCosLimSup = cos( ( dClippingAngle - dTolerAngle) * DEGTORAD) ;
|
|
double dCosLimInf = cos( max( 0., ( dClippingAngle + dTolerAngle)) * DEGTORAD) ;
|
|
|
|
// scorro le superfici locali
|
|
for ( int i = 0 ; i < int( vSrfLoc.size()) ; ++ i) {
|
|
// recupero la regione come superficie trimesh (controllo la sua validità)
|
|
PtrOwner<ISurfTriMesh> pStm( CloneSurfTriMesh( GetSurfTriMesh( vSrfLoc[i].Get()))) ;
|
|
if ( IsNull( pStm) || ! pStm->IsValid())
|
|
continue ;
|
|
// NB. devo tagliare la supericie con un piano diretto come vtTool a profondità dDepth
|
|
// ( altrimenti rischio di calcolare regioni piane inutili)
|
|
if ( ! pStm->Cut( plClipping, false))
|
|
return false ;
|
|
// se non rimane nulla, passo alla successiva
|
|
if ( IsNull( pStm) || ! pStm->IsValid() || pStm->GetTriangleCount() == 0)
|
|
continue ;
|
|
// definizione delle sue zuppe di triangoli
|
|
StmFromTriangleSoup StmSoup1, StmSoup2 ;
|
|
StmSoup1.Start() ; StmSoup2.Start() ;
|
|
// scorro i triangoli della superficie
|
|
for ( int nT = 0 ; nT < pStm->GetTriangleCount() ; ++ nT) {
|
|
// recupero il triangolo corrente (controllo la sua validità)
|
|
Triangle3d Tria ; pStm->GetTriangle( nT, Tria) ;
|
|
if ( ! Tria.IsValid())
|
|
continue ;
|
|
// recupero la normale del triangolo
|
|
Vector3d vtN_tria = Tria.GetN() ;
|
|
// recupero il valore coseno dell'angolo
|
|
double dCos = vtN_tria * vtToolLoc ;
|
|
// se coseno negativo scarto il triangolo, non si lavorano i sottosquadra
|
|
if ( dCos < - EPS_SMALL)
|
|
continue ;
|
|
// se triangolo è forntaliero, lo inserisco nel vettore
|
|
if ( dCos < dCosLimSup && dCos > dCosLimInf) {
|
|
// recupero il raggio della sfera che contine il triangolo
|
|
BBox3d BBoxTria ;
|
|
double dRad ;
|
|
if ( ! Tria.GetLocalBBox( BBoxTria) || ! BBoxTria.GetRadius( dRad))
|
|
return false ;
|
|
// se raggio più grande del limite superiore, aggiorno
|
|
if ( dRad > dMaxFrontTriaRad)
|
|
dMaxFrontTriaRad = dRad ;
|
|
}
|
|
// se la normale del triangolo è sotto la tolleranza, lo inserisco nella zuppa ZConst
|
|
// più il prodottoscalare tende a 0, più i versori sono distanti
|
|
if ( ( abs( dCos) < dCosLimit + EPS_ANG_ZERO))
|
|
StmSoup1.AddTriangle( Tria.GetP( 0), Tria.GetP( 1), Tria.GetP( 2)) ;
|
|
else
|
|
StmSoup2.AddTriangle( Tria.GetP( 0), Tria.GetP( 1), Tria.GetP( 2)) ;
|
|
}
|
|
// fine scorrimento dei triangoli
|
|
StmSoup1.End() ; StmSoup2.End() ;
|
|
// recupero le superfici trimesh per ZCosnt (stmSoup1)
|
|
PtrOwner<ISurfTriMesh> pStmCurr( StmSoup1.GetSurf()) ;
|
|
while ( ! IsNull( pStmCurr) && pStmCurr->IsValid() && ( pStmCurr->GetTriangleCount() > 0)) {
|
|
// rimuovo le parti di superficie troppo piccole
|
|
for ( int nP = 0 ; nP < pStmCurr->GetPartCount() ; ++ nP) {
|
|
double dArea ;
|
|
if ( pStmCurr->GetPartArea( nP, dArea) && dArea < EPS_SMALL) {
|
|
pStmCurr->RemovePart( nP) ;
|
|
-- nP ;
|
|
}
|
|
}
|
|
// se rimane una superficie valida, allora la memorizzo
|
|
if ( pStmCurr->IsValid() && ( pStmCurr->GetTriangleCount() > 0))
|
|
vpStm1.emplace_back( Release( pStmCurr)) ;
|
|
// recupero eventuale altra superficie TriMesh
|
|
pStmCurr.Set( StmSoup1.GetSurf()) ;
|
|
} ;
|
|
|
|
// recupero le superfici trimesh per Spiral (stmSoup2)
|
|
pStmCurr.Set( StmSoup2.GetSurf()) ;
|
|
while ( ! IsNull( pStmCurr) && pStmCurr->IsValid() && ( pStmCurr->GetTriangleCount() > 0)) {
|
|
// rimuovo le parti di superficie troppo piccole
|
|
for ( int nP = 0 ; nP < pStmCurr->GetPartCount() ; ++ nP) {
|
|
double dArea ;
|
|
if ( pStmCurr->GetPartArea( nP, dArea) && dArea < EPS_SMALL) {
|
|
pStmCurr->RemovePart( nP) ;
|
|
-- nP ;
|
|
}
|
|
}
|
|
// se rimane una superficie valida, allora la memorizzo
|
|
if ( pStmCurr->IsValid() && ( pStmCurr->GetTriangleCount() > 0))
|
|
vpStm2.emplace_back( Release( pStmCurr)) ;
|
|
// recupero eventuale altra superficie TriMesh
|
|
pStmCurr.Set( StmSoup2.GetSurf()) ;
|
|
} ;
|
|
}
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
for ( int i = 0 ; i < int( vpStm1.size()) ; ++ i) { // ZConst -> Viola
|
|
PtrOwner<ISurfTriMesh> pStmToDraw( CloneSurfTriMesh( vpStm1[i])) ;
|
|
pStmToDraw->ToGlob( frSurf) ;
|
|
int _o = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmToDraw->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _o, PURPLE) ;
|
|
}
|
|
for ( int i = 0 ; i < int( vpStm2.size()) ; ++ i) { // Spiral -> Verde
|
|
PtrOwner<ISurfTriMesh> pStmToDraw( CloneSurfTriMesh( vpStm2[i])) ;
|
|
pStmToDraw->ToGlob( frSurf) ;
|
|
int _o = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmToDraw->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _o, GREEN) ;
|
|
}
|
|
#endif
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::OrderOptimalPathsByZLoc( const ISurfFlatRegion* pSfrCntZConst, const ISurfFlatRegion* pSfrCntZigZag,
|
|
VECTORPATHS& vCrvPaths) const
|
|
{
|
|
// le curve devono essere tutte valide
|
|
for ( auto& path : vCrvPaths) {
|
|
if ( path.pCrvPath == nullptr || ! path.pCrvPath->IsValid())
|
|
return false ;
|
|
}
|
|
// se ho meno di due percorsi, non faccio nulla
|
|
if ( int( vCrvPaths.size()) <= 1)
|
|
return true ;
|
|
|
|
// determino il piano contenente la superficie di lavoro ( identico per pSfrCntZigZag e pSfrCntZConst)
|
|
Point3d ptCenter ;
|
|
Vector3d vtN ;
|
|
if ( pSfrCntZigZag != nullptr && pSfrCntZigZag->IsValid()) {
|
|
pSfrCntZigZag->GetCentroid( ptCenter) ;
|
|
vtN = pSfrCntZigZag->GetNormVersor() ;
|
|
}
|
|
else if ( pSfrCntZConst != nullptr && pSfrCntZigZag->IsValid()) {
|
|
pSfrCntZConst->GetCentroid( ptCenter) ;
|
|
vtN = pSfrCntZConst->GetNormVersor() ;
|
|
}
|
|
Plane3d plSfr ;
|
|
if ( ! plSfr.Set( ptCenter, vtN))
|
|
return false ;
|
|
|
|
// definisco una mappa [indice curva, ZStart rispetto plSfr, ZEnd rispetto plSfr]
|
|
typedef tuple<int, double, double> BoundaryMap ;
|
|
vector<BoundaryMap> vBoundaryMap ; vBoundaryMap.reserve( vCrvPaths.size()) ;
|
|
for ( int i = 0 ; i < int( vCrvPaths.size()) ; ++ i) {
|
|
// recupero gli estremi della curva
|
|
Point3d ptS ; vCrvPaths[i].pCrvPath->GetStartPoint( ptS) ;
|
|
Point3d ptE ; vCrvPaths[i].pCrvPath->GetEndPoint( ptE) ;
|
|
// determino la Z dei punti rispetto al piano
|
|
double dZStart = abs( ( DistPointPlane( ptS, plSfr))) ;
|
|
double dZEnd = abs( ( DistPointPlane( ptE, plSfr))) ;
|
|
// memorizzo i risultati
|
|
vBoundaryMap.emplace_back( make_tuple( i, dZStart, dZEnd)) ;
|
|
}
|
|
|
|
// Regole per ordinamento delle curve ricavate
|
|
// --- Ordino le curve in base a ptStart crescente rispetto al piano plSfr
|
|
// --- A parità di ptStart ordino per ptEnd crescente
|
|
sort( vBoundaryMap.begin(), vBoundaryMap.end(), []( const BoundaryMap& MapA, const BoundaryMap& MapB) {
|
|
if ( abs( get<1>( MapA) - get<1>( MapB)) < 10 * EPS_SMALL)
|
|
return ( get<2>( MapA) < get<2>( MapB)) ;
|
|
return ( get<1>( MapA) < get<1>( MapB)) ;
|
|
}) ;
|
|
VECTORPATHS vCrvPathsTmp ; vCrvPathsTmp.resize( vCrvPaths.size()) ;
|
|
for ( int i = 0 ; i < int( vBoundaryMap.size()) ; ++ i) {
|
|
vCrvPathsTmp[i].pCrvPath.Set( Release( vCrvPaths[get<0>( vBoundaryMap[i])].pCrvPath)) ;
|
|
vCrvPathsTmp[i].nType = vCrvPaths[get<0>( vBoundaryMap[i])].nType ;
|
|
}
|
|
swap( vCrvPathsTmp, vCrvPaths) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::ChooseFinishingForOptimal( const ISurfFlatRegion* pSfr, int nChunk, bool& bSpiral,
|
|
double& dSideAng)
|
|
{
|
|
// controllo dei parametri
|
|
if ( pSfr == nullptr || ! pSfr->IsValid())
|
|
return false ;
|
|
// controllo valore di nChunk
|
|
if ( nChunk < 0 || nChunk >= pSfr->GetChunkCount())
|
|
return false ;
|
|
// informazioni sul Chunk
|
|
int nLines = 0 ; double dMaxLineLen = 0. ; Vector3d vtTanMaxLine ;
|
|
int nArcs = 0 ; double dMaxArcLen = 0. ;
|
|
BBox3d BBox ; Vector3d vtX ;
|
|
for ( int nL = 0 ; nL < pSfr->GetLoopCount( nChunk) ; ++ nL) {
|
|
// recupero il loop come curva composita
|
|
PtrOwner<ICurveComposite> pCompoLoop( ConvertCurveToComposite( pSfr->GetLoop( nChunk, nL))) ;
|
|
if ( IsNull( pCompoLoop) || ! pCompoLoop->IsValid())
|
|
return false ;
|
|
// se loop esterno calcolo il Box
|
|
if ( nL == 0) {
|
|
PolyLine PL ;
|
|
if ( ! pCompoLoop->ApproxWithLines( 100 * EPS_SMALL, ANG_TOL_STD_DEG, ICurve::APL_STD, PL))
|
|
return false ;
|
|
Point3d ptCenter ;
|
|
double dLen ; double dHeight ;
|
|
if ( ! PL.GetMinAreaRectangleXY( ptCenter, vtX, dLen, dHeight))
|
|
return false ;
|
|
}
|
|
// scorro le curve del Loop
|
|
for ( int nU = 0 ; nU < pCompoLoop->GetCurveCount() ; ++ nU) {
|
|
const ICurve* pCurve = pCompoLoop->GetCurve( nU) ;
|
|
if ( pCurve == nullptr || ! pCurve->IsValid())
|
|
return false ;
|
|
// se arco
|
|
if ( pCurve->GetType() == CRV_ARC) {
|
|
++ nArcs ;
|
|
double dLen ; pCurve->GetLength( dLen) ;
|
|
if ( dLen > dMaxArcLen)
|
|
dMaxArcLen = dLen ;
|
|
}
|
|
// se linea
|
|
else if ( pCurve->GetType() == CRV_LINE) {
|
|
++ nLines ;
|
|
double dLen ; pCurve->GetLength( dLen) ;
|
|
if ( dLen > dMaxLineLen) {
|
|
dMaxLineLen = dLen ;
|
|
pCurve->GetStartDir( vtTanMaxLine) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// di base lavorazione Spiral
|
|
bSpiral = true ;
|
|
// se l'entità più lunga è la linea
|
|
if ( dMaxLineLen > dMaxArcLen) {
|
|
// se ci sono in genere più linee che archi (60% linee)
|
|
if ( nLines / ( nLines + nArcs + 1) > .6) {
|
|
// se la direzione principale della linea concide con la direzione massima del box minimo
|
|
if ( AreSameOrOppositeVectorApprox( vtTanMaxLine, vtX)) {
|
|
bSpiral = false ; // ZigZag
|
|
X_AX.GetAngle( vtX, dSideAng) ;
|
|
dSideAng = abs( dSideAng) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
ISurfTriMesh*
|
|
SurfFinishing::SplitStmTriaUnderClippingAngle( const SurfLocal SrfLoc, const Vector3d& vtTest, double dClippingAngle,
|
|
double dFrontTriaTolerAng, double& dMaxFrontTriaRad) const
|
|
{
|
|
// definisco le tolleranze
|
|
double dCosLimit = cos( dClippingAngle * DEGTORAD) ;
|
|
double dCosLimSup = cos( ( dClippingAngle - dFrontTriaTolerAng) * DEGTORAD) ;
|
|
double dCosLimInf = cos( max( 0., ( dClippingAngle + dFrontTriaTolerAng)) * DEGTORAD) ;
|
|
|
|
// recupero una superficie formata solo dai triangoli la cui normale ha un angolo minore di CLIPPING_EDGE
|
|
// rispetto al versore utensile
|
|
// scorro le superfici
|
|
StmFromTriangleSoup SpiralSoup ; SpiralSoup.Start() ;
|
|
// recupero la TriMesh ( solo la parte sopra alla dDepth)
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( SrfLoc.Get()) ;
|
|
if ( pStm == nullptr || ! pStm->IsValid())
|
|
return nullptr ;
|
|
// scorro i triangoli
|
|
for ( int nT = 0 ; nT < pStm->GetTriangleCount() ; ++ nT) {
|
|
// recupero il triangolo corrente (controllo la sua validità)
|
|
Triangle3d Tria ; pStm->GetTriangle( nT, Tria) ;
|
|
if ( ! Tria.IsValid())
|
|
continue ;
|
|
// recupero la normale del triangolo
|
|
Vector3d vtN_tria = Tria.GetN() ;
|
|
// recupero il valore coseno dell'angolo
|
|
double dCos = vtN_tria * vtTest ;
|
|
// se coseno negativo scarto il triangolo, non si lavorano i sottosquadra
|
|
if ( dCos < - EPS_SMALL)
|
|
continue ;
|
|
// se triangolo è forntaliero, lo inserisco nel vettore
|
|
if ( dCos < dCosLimSup && dCos > dCosLimInf) {
|
|
// recupero il raggio della sfera che contine il triangolo
|
|
BBox3d BBoxTria ;
|
|
double dRad ;
|
|
if ( ! Tria.GetLocalBBox( BBoxTria) || ! BBoxTria.GetRadius( dRad))
|
|
return nullptr ;
|
|
// se raggio più grande del limite superiore, aggiorno
|
|
if ( dRad > dMaxFrontTriaRad)
|
|
dMaxFrontTriaRad = dRad ;
|
|
}
|
|
// se la normale del triangolo è sopra la tolleranza, lo inserisco nella zuppa Spiral
|
|
// più il prodottoscalare tende a 0, più i versori sono distanti
|
|
if ( ( abs( dCos) > dCosLimit + EPS_ANG_ZERO))
|
|
SpiralSoup.AddTriangle( Tria.GetP( 0), Tria.GetP( 1), Tria.GetP( 2)) ;
|
|
}
|
|
SpiralSoup.End() ;
|
|
|
|
// recupero la superficie trimesh dalla zuppa
|
|
PtrOwner<ISurfTriMesh> pStmLoc( SpiralSoup.GetSurf()) ;
|
|
if ( ! IsNull( pStmLoc) && pStmLoc->IsValid() && pStmLoc->GetTriangleCount() > 0) {
|
|
pStmLoc->Repair() ; // rimozione possibili T-Junctions
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int _o = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmLoc->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _o, PURPLE) ;
|
|
#endif
|
|
}
|
|
|
|
return Release( pStmLoc) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
ISurfFlatRegion*
|
|
SurfFinishing::GetSfrProjectedStmLoops( const ISURFTMPOVECTOR& vStm, const ISurfFlatRegion* pSfrContour,
|
|
const DBLVECTOR& vdLinFeaTol, const DBLVECTOR& vdAngTol, const DBLVECTOR& vdMaxLinTol) const
|
|
{
|
|
// controllo della regione di controllo
|
|
if ( pSfrContour == nullptr)
|
|
return nullptr ;
|
|
PtrOwner<ISurfFlatRegion> pSfr( CreateSurfFlatRegion()) ;
|
|
if ( IsNull( pSfr))
|
|
return nullptr ;
|
|
if ( ! pSfrContour->IsValid())
|
|
return Release( pSfr) ;
|
|
|
|
// definisco piano di proiezione dalla regione
|
|
Plane3d plProj ;
|
|
Point3d ptC ; pSfrContour->GetCentroid( ptC) ;
|
|
if ( ! plProj.Set( ptC, pSfrContour->GetNormVersor()))
|
|
return nullptr ;
|
|
// frame per classificazione delle curve (planeXY)
|
|
Frame3d frXY ;
|
|
if ( ! frXY.Set( ptC, pSfrContour->GetNormVersor()))
|
|
return nullptr ;
|
|
|
|
// per ogni superficie trimesh ...
|
|
for ( int nS = 0 ; nS < int( vStm.size()) ; ++ nS) {
|
|
// se non è valida allora passo alla successiva (potrebbe essere tutta associata a ZConst)
|
|
if ( vStm[nS] == nullptr || ! vStm[nS]->IsValid())
|
|
continue ;
|
|
// recupero le parti che la compongono
|
|
for ( int nP = 0 ; nP < vStm[nS]->GetPartCount() ; ++ nP) {
|
|
// se la Part corrente è piccola, la salto
|
|
double dArea = 0. ;
|
|
if ( vStm[nS]->GetPartArea( nP, dArea) && dArea < EPS_SMALL)
|
|
continue ;
|
|
// recupero i Loop della parte corrente
|
|
POLYLINEVECTOR vPL ;
|
|
if ( ! vStm[nS]->GetPartLoops( nP, vPL))
|
|
return nullptr ;
|
|
// recupero un vettore di curve composite (in 3d)
|
|
ICRVCOMPOPOVECTOR vCompoLoops ; vCompoLoops.reserve( vPL.size()) ;
|
|
for ( int nL = 0 ; nL < int( vPL.size()) ; ++ nL) {
|
|
if ( vPL[nL].IsClosed()) {
|
|
PtrOwner<ICurveComposite> pCompoLoop( CreateCurveComposite()) ;
|
|
if ( IsNull( pCompoLoop) || ! pCompoLoop->FromPolyLine( vPL[nL]) || ! pCompoLoop->IsValid())
|
|
return nullptr ;
|
|
// memorizzo la curva
|
|
vCompoLoops.emplace_back( Release( pCompoLoop)) ;
|
|
}
|
|
}
|
|
// creo un vettore di curve proiettate approssimate per la creazione della regione
|
|
SurfFlatRegionByContours SfrPart ;
|
|
for ( int nL = 0 ; nL < int( vCompoLoops.size()) ; ++ nL) {
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
//int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCompoLoops[nL]->Clone()) ;
|
|
//m_pGeomDB->SetMaterial( _a, WHITE) ;
|
|
#endif
|
|
// la proietto sul piano di proiezione
|
|
PtrOwner<ICurve> pCompoProj( ProjectCurveOnPlane( *vCompoLoops[nL], plProj)) ;
|
|
if ( IsNull( pCompoProj) || ! pCompoProj->IsValid())
|
|
continue ;
|
|
pCompoProj->ToLoc( frXY) ;
|
|
SelfIntersCurve SIC( *pCompoProj) ;
|
|
if ( SIC.GetIntersCount() > 0)
|
|
continue ;
|
|
pCompoProj->ToGlob( frXY) ;
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
//int _b = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompoProj->Clone()) ;
|
|
//m_pGeomDB->SetMaterial( _b, AQUA) ;
|
|
#endif
|
|
SfrPart.AddCurve( Release( pCompoProj)) ;
|
|
}
|
|
PtrOwner<ISurfFlatRegion> pSfrPart( SfrPart.GetSurf()) ;
|
|
if ( ! IsNull( pSfrPart) && pSfrPart->IsValid()) {
|
|
// controllo che sia orientata corretamente
|
|
if ( AreOppositeVectorApprox( pSfrContour->GetNormVersor(), pSfrPart->GetNormVersor()))
|
|
pSfrPart->Invert() ;
|
|
// aggiungo alla regione *pSfr
|
|
if ( pSfr->IsValid()) {
|
|
if ( ! pSfr->Add( *pSfrPart))
|
|
return nullptr ;
|
|
}
|
|
else
|
|
pSfr.Set( pSfrPart) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
Color myColor = AQUA ; myColor.SetAlpha( .25) ;
|
|
int _b = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfr->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _b, myColor) ;
|
|
#endif
|
|
|
|
return Release( pSfr) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
Point3d
|
|
SurfFinishing::CalcShapedPoint( const PNTUVVECT& myInfoStart, const PNTUVVECT& myInfoEnd, int nType, const Vector3d& vtAxL,
|
|
const Vector3d& vtMoveL, double dCosSplitAngle, double dLimInfCosSplitAng,
|
|
double dLimSupCosSplitAng, ICAvToolSurfTm* pCAvTlStm, int _nInd_debug) const
|
|
{
|
|
// recupero il tipo di ShapedPoint richiesto
|
|
if ( nType != 0 && nType != 1 && nType != 2)
|
|
return P_INVALID ;
|
|
bool bSpiral = ( nType == 0) ;
|
|
bool bZConst = ( nType == 1) ;
|
|
bool bBorder = ( nType == 2) ;
|
|
|
|
// metodo id bisezione
|
|
const int MAX_ITER = 10 ;
|
|
int nCount = 0 ;
|
|
PNTUVVECT ptU_vt1 = make_tuple( get<0>( myInfoStart), get<1>( myInfoStart), get<2>( myInfoStart)) ;
|
|
PNTUVVECT ptU_vt2 = make_tuple( get<0>( myInfoEnd), get<1>( myInfoEnd), get<2>( myInfoEnd)) ;
|
|
Point3d ptMid = Media( get<0>( ptU_vt1), get<0>( ptU_vt2)) ;
|
|
while ( nCount < MAX_ITER) {
|
|
// se estremi coincidenti, allora mi fermo
|
|
if ( SqDist( get<0>( ptU_vt1), get<0>( ptU_vt2)) < 4 * SQ_EPS_SMALL)
|
|
return ptMid ;
|
|
// verifica del punto medio
|
|
Point3d ptTest = ptMid ;
|
|
double dMove = 0. ;
|
|
VCT3DVECTOR vVtN ;
|
|
if ( ! pCAvTlStm->TestPositionAdv( ptTest, vtAxL, vtMoveL, dMove, vVtN))
|
|
return P_INVALID ;
|
|
// collisione nel punto medio
|
|
bool bMidColl = false ;
|
|
for ( int nV = 0 ; nV < int( vVtN.size()) && ! bMidColl ; ++ nV) {
|
|
double dAbsCos = abs( vVtN[nV] * vtAxL) ;
|
|
bMidColl = ( bSpiral ? dAbsCos > dCosSplitAngle + EPS_ANG_ZERO :
|
|
bZConst ? dAbsCos < dCosSplitAngle + EPS_ANG_ZERO :
|
|
bBorder ? dAbsCos > dLimInfCosSplitAng + EPS_ANG_ZERO &&
|
|
dAbsCos < dLimSupCosSplitAng + EPS_ANG_ZERO : false) ;
|
|
}
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
PtrOwner<IGeoPoint3d> myPt( CreateGeoPoint3d()) ;
|
|
myPt->Set( ptMid) ;
|
|
int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, _nInd_debug, myPt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _a, bMidColl ? ORANGE : AQUA) ;
|
|
#endif
|
|
// collisione nel punto 1 di riferimento
|
|
bool b1Coll = false ;
|
|
for ( int nV = 0 ; nV < int( get<2>( ptU_vt1).size()) && ! b1Coll ; ++ nV) {
|
|
double dAbsCos = abs( get<2>( ptU_vt1)[nV] * vtAxL) ;
|
|
b1Coll = ( bSpiral ? dAbsCos > dCosSplitAngle + EPS_ANG_ZERO :
|
|
bZConst ? dAbsCos < dCosSplitAngle + EPS_ANG_ZERO :
|
|
bBorder ? dAbsCos > dLimInfCosSplitAng + EPS_ANG_ZERO &&
|
|
dAbsCos < dLimSupCosSplitAng + EPS_ANG_ZERO : false) ;
|
|
}
|
|
// definizione del nuovo intervallo per interpolazione
|
|
if ( b1Coll != bMidColl)
|
|
ptU_vt2 = make_tuple( ptMid, dMove, vVtN) ;
|
|
else
|
|
ptU_vt1 = make_tuple( ptMid, dMove, vVtN) ;
|
|
ptMid = Media( get<0>( ptU_vt1), get<0>( ptU_vt2)) ;
|
|
++ nCount ;
|
|
}
|
|
|
|
return ptMid ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
SurfFinishing::ProcessSquare( int nFlag, double dLevel, double dQPt0, double dQpt1, double dQpt2, double dQpt3,
|
|
int& nI1s, int& nI1e, int& nI2s, int& nI2e) const
|
|
{
|
|
// Quadrato (C=corner E=edge) :
|
|
//
|
|
// C3 - E2 - C2
|
|
// | * * |
|
|
// E3 * E1
|
|
// | * * |
|
|
// C0 - E0 - C1
|
|
|
|
static int LineTable[16][4] = { { 0, -1, -1, -1}, // ( 0)
|
|
{ 2, 0, 5, 3}, // ( 1)
|
|
{ 2, 1, 4, 0}, // ( 2)
|
|
{ 1, 1, 3, -1}, // ( 3)
|
|
{ 2, 2, 5, 1}, // ( 4)
|
|
{ -1, -1, -1, -1}, // ( 5) -> ambiguo
|
|
{ 1, 2, 0, -1}, // ( 6)
|
|
{ 2, 2, 4, 3}, // ( 7)
|
|
{ 2, 3, 4, 2}, // ( 8)
|
|
{ 1, 0, 2, -1}, // ( 9)
|
|
{ -1, -1, -1, -1}, // ( 10) -> ambiguo
|
|
{ 2, 1, 5, 2}, // ( 11)
|
|
{ 1, 3, 1, -1}, // ( 12)
|
|
{ 2, 0, 4, 1}, // ( 13)
|
|
{ 2, 3, 5, 0}, // ( 14)
|
|
{ 0, -1, -1, -1} } ; // ( 15)
|
|
static int LineTableAmbiguos[4][5] = { { 2, 2, 1, 0, 3}, // ( 5-split)
|
|
{ 2, 2, 3, 0, 1}, // ( 5-stick)
|
|
{ 2, 1, 0, 3, 2}, // ( 10-split)
|
|
{ 2, 1, 2, 3, 0} } ; // ( 10-stick)
|
|
|
|
// flag fuori dai limiti
|
|
if ( nFlag < 0 || nFlag > 15)
|
|
return -1 ;
|
|
// nessuna linea
|
|
if ( LineTable[nFlag][0] == 0)
|
|
return 0 ;
|
|
int nLines = LineTable[nFlag][0] ;
|
|
// se almeno una linea
|
|
if ( nLines > 0) {
|
|
nI1s = LineTable[nFlag][1] ;
|
|
nI1e = LineTable[nFlag][2] ;
|
|
}
|
|
// se due linee
|
|
if ( nLines == 2) {
|
|
nI2s = LineTable[nFlag][2] ;
|
|
nI2e = LineTable[nFlag][3] ;
|
|
}
|
|
// se ambiguo
|
|
if ( nLines == -1) {
|
|
nLines = 2 ;
|
|
int nJump = ( nFlag == 5 ? 0 : 2) ;
|
|
int nShift = ( ( dQPt0 - dLevel) * ( dQpt2 - dLevel) > ( dQpt1 - dLevel) * ( dQpt3 - dLevel) ? 1 : 0) ;
|
|
nI1s = LineTableAmbiguos[nJump + nShift][1] ;
|
|
nI1e = LineTableAmbiguos[nJump + nShift][2] ;
|
|
nI2s = LineTableAmbiguos[nJump + nShift][3] ;
|
|
nI2e = LineTableAmbiguos[nJump + nShift][4] ;
|
|
}
|
|
|
|
return nLines ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::TestSubEdges( unordered_map<int, Point3d>& umEdgePnt, const INTVECTOR& vEdgeInd, int nType, int nFirst, int nLast,
|
|
const VECTORCOLLISIONSFR& vPntM, int nStepX, const Vector3d vtAxL, const Vector3d& vtMoveL,
|
|
double dCosSplitAng, double dLimInfCosSplitAng, double dLimSupCosSplitAng, ICAvToolSurfTm* pCAvTlStm, int _nInd_debug) const
|
|
{
|
|
for ( int k = nFirst ; k <= nLast ; ++ k) {
|
|
// recupero i differenti indici
|
|
int nKey = vEdgeInd[k] ;
|
|
int nInd = nKey / 4 ;
|
|
int nIndS, nIndE ;
|
|
int nMod = nKey % 4 ;
|
|
switch ( nMod)
|
|
{
|
|
case ( 0) :
|
|
nIndS = nInd ;
|
|
nIndE = nInd + 1 ;
|
|
break ;
|
|
case ( 1) :
|
|
nIndS = nInd ;
|
|
nIndE = nInd + nStepX + 1 ;
|
|
break ;
|
|
case ( 2) :
|
|
nIndS = nInd + 1 ;
|
|
nIndE = nInd + nStepX + 1 ;
|
|
break ;
|
|
case ( 3) :
|
|
nIndS = nInd ;
|
|
nIndE = nInd + nStepX + 2 ;
|
|
break ;
|
|
}
|
|
// calcolo il punto
|
|
Point3d ptQ = CalcShapedPoint( vPntM[nIndS].CollisionInfo, vPntM[nIndE].CollisionInfo, nType,
|
|
vtAxL, vtMoveL, dCosSplitAng, dLimInfCosSplitAng, dLimSupCosSplitAng, pCAvTlStm, _nInd_debug) ;
|
|
if ( ! ptQ.IsValid())
|
|
return false ;
|
|
umEdgePnt[nKey] = ptQ ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::MarchingSquares( const VECTORCOLLISIONSFR& vPntM, int nType, double dOffsTol, int nStepX, int nStepY, double dClippingAngle,
|
|
double dLimInfClippingAng, double dLimSupClippingAng, const Vector3d& vtAxL, const Vector3d& vtMoveL, ICAvToolSurfTm* pCAvTlStm,
|
|
ICRVCOMPOPOVECTOR& vCrvCompo) const
|
|
{
|
|
int _nInd_debug = GDB_ID_NULL ;
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "_marchingsquare") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_ON) ;
|
|
int nLyS = GDB_ID_NULL ;
|
|
int nLyZC = GDB_ID_NULL ;
|
|
int nLyBo = GDB_ID_NULL ;
|
|
if ( nType == 0) {
|
|
nLyS = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyS, "_spiral") ;
|
|
m_pGeomDB->SetStatus( nLyS, GDB_ST_OFF) ;
|
|
_nInd_debug = nLyS ;
|
|
}
|
|
else if ( nType == 1) {
|
|
nLyZC = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyZC, "_zconst") ;
|
|
m_pGeomDB->SetStatus( nLyZC, GDB_ST_OFF) ;
|
|
_nInd_debug = nLyZC ;
|
|
}
|
|
else if ( nType == 2) {
|
|
nLyBo = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyBo, "_border") ;
|
|
m_pGeomDB->SetStatus( nLyBo, GDB_ST_OFF) ;
|
|
_nInd_debug = nLyBo ;
|
|
}
|
|
#endif
|
|
|
|
// definisco il tipo di contorno richiesto
|
|
if ( nType != 0 && nType != 1 && nType != 2)
|
|
return false ;
|
|
bool bSpiral = ( nType == 0) ;
|
|
bool bZConst = ( nType == 1) ;
|
|
bool bBorder = ( nType == 2) ;
|
|
|
|
// Analizzo gli edge da cui passano le curve cercate
|
|
vCrvCompo.clear() ;
|
|
unordered_map<int, Point3d> umEdgePnt( 6 * ( nStepX + nStepY)) ;
|
|
INTVECTOR vEdgeInd ;
|
|
vEdgeInd.reserve( 6 * ( nStepX + nStepY)) ;
|
|
double dCosSplitAngle = cos( dClippingAngle * DEGTORAD) ;
|
|
double dLimInfCosSplitAngle = cos( dLimInfClippingAng * DEGTORAD) ;
|
|
double dLimSupCosSplitAngle = cos( dLimSupClippingAng * DEGTORAD) ;
|
|
// Ciclo sui quadrati da analizzare
|
|
for ( int j = 0 ; j < nStepY ; ++ j) {
|
|
for ( int i = 0 ; i < nStepX ; ++ i) {
|
|
// indici dei vertici nella griglia
|
|
int nInd0 = i + j * ( nStepX + 1) ;
|
|
int nInd1 = ( i + 1) + j * ( nStepX + 1) ;
|
|
int nInd2 = ( i + 1) + ( j + 1) * ( nStepX + 1) ;
|
|
int nInd3 = i + ( j + 1) * ( nStepX + 1) ;
|
|
// flag del quadrato
|
|
bool bUp0 = ( bSpiral ? vPntM[nInd0].bInSpiral :
|
|
bZConst ? vPntM[nInd0].bInZConst :
|
|
bBorder ? vPntM[nInd0].bOnBorder : false) ;
|
|
bool bUp1 = ( bSpiral ? vPntM[nInd1].bInSpiral :
|
|
bZConst ? vPntM[nInd1].bInZConst :
|
|
bBorder ? vPntM[nInd1].bOnBorder : false) ;
|
|
bool bUp2 = ( bSpiral ? vPntM[nInd2].bInSpiral :
|
|
bZConst ? vPntM[nInd2].bInZConst :
|
|
bBorder ? vPntM[nInd2].bOnBorder : false) ;
|
|
bool bUp3 = ( bSpiral ? vPntM[nInd3].bInSpiral :
|
|
bZConst ? vPntM[nInd3].bInZConst :
|
|
bBorder ? vPntM[nInd3].bOnBorder : false) ;
|
|
// se tutti uguali, passo al successivo
|
|
if ( bUp0 == bUp1 && bUp0 == bUp2 && bUp0 == bUp3)
|
|
continue ;
|
|
// verifico Edge da calcolare
|
|
if ( bUp0 != bUp1) {
|
|
int nKey = 4 * nInd0 ;
|
|
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
|
|
umEdgePnt[nKey] = P_INVALID ;
|
|
vEdgeInd.emplace_back( nKey) ;
|
|
}
|
|
}
|
|
if ( bUp3 != bUp2) {
|
|
int nKey = 4 * nInd3 ;
|
|
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
|
|
umEdgePnt[nKey] = P_INVALID ;
|
|
vEdgeInd.emplace_back( nKey) ;
|
|
}
|
|
}
|
|
if ( bUp0 != bUp3) {
|
|
int nKey = 4 * nInd0 + 1 ;
|
|
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
|
|
umEdgePnt[nKey] = P_INVALID ;
|
|
vEdgeInd.emplace_back( nKey) ;
|
|
}
|
|
}
|
|
if ( bUp1 != bUp2) {
|
|
int nKey = 4 * nInd1 + 1 ;
|
|
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
|
|
umEdgePnt[nKey] = P_INVALID ;
|
|
vEdgeInd.emplace_back( nKey) ;
|
|
}
|
|
}
|
|
int nFlag = ( bSpiral ? ( ( vPntM[nInd0].bInSpiral ? 1 : 0) + ( vPntM[nInd1].bInSpiral ? 2 : 0) +
|
|
( vPntM[nInd2].bInSpiral ? 4 : 0) + ( vPntM[nInd3].bInSpiral ? 8 : 0)) :
|
|
bZConst ? ( ( vPntM[nInd0].bInZConst ? 1 : 0) + ( vPntM[nInd1].bInZConst ? 2 : 0) +
|
|
( vPntM[nInd2].bInZConst ? 4 : 0) + ( vPntM[nInd3].bInZConst ? 8 : 0)) :
|
|
bBorder ? ( ( vPntM[nInd0].bOnBorder ? 1 : 0) + ( vPntM[nInd1].bOnBorder ? 2 : 0) +
|
|
( vPntM[nInd2].bOnBorder ? 4 : 0) + ( vPntM[nInd3].bOnBorder ? 8 : 0)) : 0) ;
|
|
if ( nFlag == 1 || nFlag == 2 || nFlag == 4 || nFlag == 7 || nFlag == 8 || nFlag == 11 ||
|
|
nFlag == 13 || nFlag == 14) {
|
|
if ( bUp1 != bUp3) {
|
|
int nKey = 4 * nInd0 + 2 ;
|
|
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
|
|
umEdgePnt[nKey] = P_INVALID ;
|
|
vEdgeInd.emplace_back( nKey) ;
|
|
}
|
|
}
|
|
if ( bUp0 != bUp2) {
|
|
int nKey = 4 * nInd0 + 3 ;
|
|
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
|
|
umEdgePnt[nKey] = P_INVALID ;
|
|
vEdgeInd.emplace_back( nKey) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Numero di edge da valutare
|
|
int nEdgeCnt = int( vEdgeInd.size()) ;
|
|
// Recupero il numero massimo di thread concorrenti
|
|
int nThreadMax = ( thread::hardware_concurrency()) / 2 ;
|
|
bool bOk = true ;
|
|
// Se un solo thread o pochi punti
|
|
if ( nThreadMax <= 1 || nEdgeCnt < 50)
|
|
TestSubEdges( umEdgePnt, vEdgeInd, nType, 0, nEdgeCnt - 1, vPntM, nStepX, vtAxL, vtMoveL,
|
|
dCosSplitAngle, dLimInfCosSplitAngle, dLimSupCosSplitAngle, pCAvTlStm, _nInd_debug) ;
|
|
// altrimenti
|
|
else {
|
|
const int MAX_PARTS = 32 ;
|
|
INTINTVECTOR vFstLst( MAX_PARTS) ;
|
|
// calcolo le parti del vettore
|
|
int nPartCnt = min( nThreadMax, MAX_PARTS) ;
|
|
int nPartDim = nEdgeCnt / nPartCnt + 1 ;
|
|
for ( int i = 0 ; i < nPartCnt ; ++ i) {
|
|
vFstLst[i].first = i * nPartDim ;
|
|
vFstLst[i].second = min( ( i + 1) * nPartDim, nEdgeCnt) - 1 ;
|
|
}
|
|
// processo le parti
|
|
future<bool> vRes[MAX_PARTS] ;
|
|
for ( int i = 0 ; i < nPartCnt ; ++ i)
|
|
vRes[i] = async( launch::async, &SurfFinishing::TestSubEdges, this, ref( umEdgePnt), cref( vEdgeInd),
|
|
nType, vFstLst[i].first, vFstLst[i].second, cref( vPntM), nStepX, cref( vtAxL),
|
|
cref( vtMoveL), dCosSplitAngle, dLimInfCosSplitAngle, dLimSupCosSplitAngle, ref( pCAvTlStm), _nInd_debug) ;
|
|
// attendo i risultati
|
|
int nFin = 0 ;
|
|
while ( nFin < nPartCnt) {
|
|
for ( int i = 0 ; i < nPartCnt ; ++ i) {
|
|
if ( vRes[i].valid() && vRes[i].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) {
|
|
bOk = vRes[i].get() && bOk ;
|
|
++ nFin ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Predispongo il concatenamento
|
|
BIPNTVECTOR vBiPnt ;
|
|
vBiPnt.reserve( 2 * ( nStepX + nStepY)) ;
|
|
ChainCurves chainC ;
|
|
chainC.Init( false, EPS_SMALL, 2 * ( nStepX + nStepY)) ;
|
|
// Ciclo sui quadrati da analizzare
|
|
for ( int j = 0 ; j < nStepY ; ++ j) {
|
|
for ( int i = 0 ; i < nStepX ; ++ i) {
|
|
// indici dei vertici nella griglia
|
|
int nInd0 = i + j * ( nStepX + 1) ;
|
|
int nInd1 = ( i + 1) + j * ( nStepX + 1) ;
|
|
int nInd2 = ( i + 1) + ( j + 1) * ( nStepX + 1) ;
|
|
int nInd3 = i + ( j + 1) * ( nStepX + 1) ;
|
|
// flag del quadrato
|
|
int nFlag = ( bSpiral ? ( ( vPntM[nInd0].bInSpiral ? 1 : 0) + ( vPntM[nInd1].bInSpiral ? 2 : 0) +
|
|
( vPntM[nInd2].bInSpiral ? 4 : 0) + ( vPntM[nInd3].bInSpiral ? 8 : 0)) :
|
|
bZConst ? ( ( vPntM[nInd0].bInZConst ? 1 : 0) + ( vPntM[nInd1].bInZConst ? 2 : 0) +
|
|
( vPntM[nInd2].bInZConst ? 4 : 0) + ( vPntM[nInd3].bInZConst ? 8 : 0)) :
|
|
bBorder ? ( ( vPntM[nInd0].bOnBorder ? 1 : 0) + ( vPntM[nInd1].bOnBorder ? 2 : 0) +
|
|
( vPntM[nInd2].bOnBorder ? 4 : 0) + ( vPntM[nInd3].bOnBorder ? 8 : 0)) : 0) ;
|
|
// se quadrato con vertici tutti dello stesso tipo, passo al successivo
|
|
if ( nFlag == 0 || nFlag == 15)
|
|
continue ;
|
|
// chiavi
|
|
int vKey[6] = { 4 * nInd0, 4 * nInd1 + 1, 4 * nInd3, 4 * nInd0 + 1, 4 * nInd0 + 2, 4 * nInd0 + 3} ;
|
|
// calcolo segmenti da inserire
|
|
int nI1s, nI1e, nI2s, nI2e ;
|
|
double dLevel = .25 * ( get<1>( vPntM[nInd0].CollisionInfo) + get<1>( vPntM[nInd1].CollisionInfo) +
|
|
get<1>( vPntM[nInd2].CollisionInfo) + get<1>( vPntM[nInd3].CollisionInfo)) ;
|
|
int nSegCnt = ProcessSquare( nFlag, dLevel, get<1>( vPntM[nInd0].CollisionInfo), get<1>( vPntM[nInd1].CollisionInfo),
|
|
get<1>( vPntM[nInd1].CollisionInfo), get<1>( vPntM[nInd3].CollisionInfo), nI1s, nI1e, nI2s, nI2e) ;
|
|
if ( nSegCnt == -1)
|
|
return false ;
|
|
else if ( nSegCnt > 0) {
|
|
// inserisco il primo
|
|
Point3d ptL1s = umEdgePnt.find( vKey[nI1s])->second ;
|
|
Point3d ptL1e = umEdgePnt.find( vKey[nI1e])->second ;
|
|
vBiPnt.emplace_back( ptL1s, ptL1e) ;
|
|
Vector3d vtDir1 = ptL1e - ptL1s ; vtDir1.Normalize() ;
|
|
chainC.AddCurve( int( vBiPnt.size()), ptL1s, vtDir1, ptL1e, vtDir1) ;
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
PtrOwner<ICurveLine> pMyLine( CreateCurveLine()) ;
|
|
pMyLine->Set( ptL1s, ptL1e) ;
|
|
pMyLine->SetExtrusion( vtAxL) ;
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, _nInd_debug , Release( pMyLine)) ;
|
|
m_pGeomDB->SetMaterial( a, GREEN) ;
|
|
#endif
|
|
// inserisco il secondo se esiste
|
|
if ( nSegCnt == 2) {
|
|
Point3d ptL2s = umEdgePnt.find( vKey[nI2s])->second ;
|
|
Point3d ptL2e = umEdgePnt.find( vKey[nI2e])->second ;
|
|
vBiPnt.emplace_back( ptL2s, ptL2e) ;
|
|
Vector3d vtDir2 = ptL2e - ptL2s ; vtDir2.Normalize() ;
|
|
chainC.AddCurve( int( vBiPnt.size()), ptL2s, vtDir2, ptL2e, vtDir2) ;
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
PtrOwner<ICurveLine> pMyLine( CreateCurveLine()) ;
|
|
pMyLine->Set( ptL2s, ptL2e) ;
|
|
pMyLine->SetExtrusion( vtAxL) ;
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, _nInd_debug, Release( pMyLine)) ;
|
|
m_pGeomDB->SetMaterial( a, YELLOW) ;
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Recupero i contorni
|
|
INTVECTOR vnId ;
|
|
while ( chainC.GetChainFromNear( ORIG, false, vnId)) {
|
|
// creo la curva
|
|
vCrvCompo.emplace_back( CreateCurveComposite()) ;
|
|
vCrvCompo.back()->AddPoint( vBiPnt[vnId[0]-1].first) ;
|
|
for ( int i = 0 ; i < int( vnId.size()) ; ++ i)
|
|
vCrvCompo.back()->AddLine( vBiPnt[vnId[i]-1].second) ;
|
|
if ( ! vCrvCompo.back()->IsClosed())
|
|
vCrvCompo.pop_back() ;
|
|
else {
|
|
// controllo se sufficientemente estesa
|
|
double dMaxOffs ;
|
|
if ( CalcCurveLimitOffset( *vCrvCompo.back(), dMaxOffs) && dMaxOffs < dOffsTol)
|
|
vCrvCompo.pop_back() ;
|
|
}
|
|
}
|
|
// abbellisco le curve trovate
|
|
const double SILH_ARC_TOL = 0.1 ;
|
|
const double SILH_ARC_FEA_MAX = 100. ;
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, _nInd_debug, vCrvCompo[i]->Clone()) ;
|
|
m_pGeomDB->SetMaterial( a, BLACK) ;
|
|
#endif
|
|
PolyArc PA ;
|
|
if ( vCrvCompo[i]->ApproxWithArcsEx( SILH_ARC_TOL, ANG_TOL_STD_DEG, SILH_ARC_FEA_MAX, PA)) {
|
|
PtrOwner<ICurveComposite> pTempCrv( CreateCurveComposite()) ;
|
|
if ( ! IsNull( pTempCrv) &&
|
|
pTempCrv->FromPolyArc( PA) &&
|
|
pTempCrv->RemoveSmallDefects( SILH_ARC_TOL / 2., ANG_TOL_STD_DEG) &&
|
|
pTempCrv->MergeCurves( SILH_ARC_TOL / 2., ANG_TOL_STD_DEG)) {
|
|
vCrvCompo[i].Set( pTempCrv) ;
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, _nInd_debug, vCrvCompo[i]->Clone()) ;
|
|
m_pGeomDB->SetMaterial( a, PURPLE) ;
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetOptimalSfr( ICAvToolSurfTm* pCAvTlStm, const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf, const ISurfFlatRegion* pSfrLoc, const Vector3d& vtTool,
|
|
double dDepth, double dElev, ISurfFlatRegion* pSfrSpiral, ISurfFlatRegion* pSfrZConst) const
|
|
{
|
|
// controllo dei parametri
|
|
if ( pSfrLoc == nullptr || ! pSfrLoc->IsValid())
|
|
return false ;
|
|
pSfrSpiral->Clear() ;
|
|
pSfrZConst->Clear() ;
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
for ( int i = 0 ; i < int( vSrfLoc.size()) ; ++ i) {
|
|
int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vSrfLoc[i]->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _a, YELLOW) ;
|
|
}
|
|
#endif
|
|
|
|
// versore utensile e di movimento longitudinali in frame locale
|
|
Vector3d vtAxL = GetToLoc( vtTool, frSurf) ;
|
|
Vector3d vtMoveL = vtAxL ;
|
|
// tolleranza angolare
|
|
double dSplitAngleTol = 5. ;
|
|
// angolo di scelta per divisione dei triangoli
|
|
double dSplitAngle = 45. ;
|
|
double dLimInfSplitAng = dSplitAngle + dSplitAngleTol ;
|
|
double dLimSupSplitAng = dSplitAngle - dSplitAngleTol ;
|
|
GetValInNotes( m_Params.m_sUserNotes, UN_SPLITANGLE, dSplitAngle) ;
|
|
double dCosClipping = cos( ( dSplitAngle) * DEGTORAD) ;
|
|
double dLimInfCosClipping = cos( dLimInfSplitAng * DEGTORAD) ;
|
|
double dLimSupCosClipping = cos( dLimSupSplitAng * DEGTORAD) ;
|
|
|
|
// costanti
|
|
const double TOL_SAMPLE = 1. ;
|
|
double dExtraXY = 0. ;
|
|
if ( m_TParams.m_dSideAng < EPS_ANG_SMALL)
|
|
dExtraXY += m_TParams.m_dDiam / 2. ;
|
|
else {
|
|
double dDeltaRad ;
|
|
double dSideAngRad = m_TParams.m_dSideAng * DEGTORAD ;
|
|
if ( m_TParams.m_dSideAng > 0) {
|
|
if ( m_TParams.m_dCornRad < EPS_SMALL)
|
|
dDeltaRad = m_TParams.m_dMaxMat * tan( dSideAngRad) ;
|
|
else
|
|
dDeltaRad = ( m_TParams.m_dCornRad * cos( dSideAngRad) +
|
|
( m_TParams.m_dMaxMat + m_TParams.m_dCornRad * ( sin( dSideAngRad) - 1)) * tan( dSideAngRad)) ;
|
|
}
|
|
else
|
|
dDeltaRad = tan( dSideAngRad) * m_TParams.m_dMaxMat ;
|
|
dExtraXY += m_TParams.m_dDiam / 2. + dDeltaRad ;
|
|
}
|
|
const double EXTRA_XY = dExtraXY + 2.5 * TOL_SAMPLE ;
|
|
|
|
// frame pianoXY
|
|
Frame3d frXY ;
|
|
Point3d ptC ; pSfrLoc->GetCentroid( ptC) ;
|
|
if ( ! frXY.Set( ptC, pSfrLoc->GetNormVersor()))
|
|
return false ;
|
|
// considero il frame inverso
|
|
Frame3d frXYInv = frXY ; frXYInv.Invert() ;
|
|
|
|
// calcolo il Box della regione rispetto al frame XY invertito (quindi il box su XY locale alla pSfr)
|
|
BBox3d BBoxLoc ;
|
|
if ( ! pSfrLoc->GetBBox( frXYInv, BBoxLoc))
|
|
return false ;
|
|
// lo espendo
|
|
BBoxLoc.Expand( EXTRA_XY, EXTRA_XY, 0.) ;
|
|
// definisco il numero di punti lungo asse X e Y
|
|
int nStepX = int( ceil( BBoxLoc.GetDimX() / TOL_SAMPLE)) ;
|
|
int nStepY = int( ceil( BBoxLoc.GetDimY() / TOL_SAMPLE)) ;
|
|
frXY.ChangeOrig( GetToGlob( BBoxLoc.GetMin(), frXY)) ;
|
|
|
|
// definisco una griglia di <punto, movimento, vtN(s)> ( sempre in FrLoc)
|
|
PNTUVVECTVECTOR vPntM( ( nStepX + 1) * ( nStepY + 1)) ; // per TestPath con collisioni
|
|
INTVECTOR vIndPerimeter ; // indici di bordo
|
|
for ( int j = 0 ; j <= nStepY ; ++ j) {
|
|
for ( int i = 0 ; i <= nStepX ; ++ i) {
|
|
int nInd = i + j * ( nStepX + 1) ;
|
|
Point3d ptTest = GetToGlob( Point3d( i * TOL_SAMPLE, j * TOL_SAMPLE, 0.), frXY) ;
|
|
if ( i == 0 || j == 0 || i == nStepX || j == nStepY)
|
|
vIndPerimeter.push_back( nInd) ;
|
|
// controtraslo i punti della lunghezza utensile
|
|
ptTest.Translate( vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
vPntM[nInd] = ( make_tuple( ptTest, 0., VCT3DVECTOR{V_NULL})) ;
|
|
}
|
|
}
|
|
|
|
// effettuo verifica Collisione avanzata ( i versori normali sono solo quelli ad alzata massima dalle superfici)
|
|
if ( ! pCAvTlStm->TestSeriesAdv( vPntM, vtAxL, vtMoveL))
|
|
return false ;
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "_debug_grid") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_ON) ;
|
|
int nLyS = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyS, "_spiral") ;
|
|
m_pGeomDB->SetStatus( nLyS, GDB_ST_OFF) ;
|
|
int nLyZC = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyZC, "_zconst") ;
|
|
m_pGeomDB->SetStatus( nLyZC, GDB_ST_OFF) ;
|
|
int nLyBO = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyBO, "_border") ;
|
|
m_pGeomDB->SetStatus( nLyBO, GDB_ST_OFF) ;
|
|
int nLyN = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLyN, "_normals") ;
|
|
m_pGeomDB->SetStatus( nLyN, GDB_ST_OFF) ;
|
|
#endif
|
|
|
|
// definisco nuovi parametri per marching Square
|
|
VECTORCOLLISIONSFR vCollision( vPntM.size()) ;
|
|
for ( int j = 0 ; j <= nStepY ; ++ j) {
|
|
for ( int i = 0 ; i <= nStepX ; ++ i) {
|
|
int nInd = i + j * ( nStepX + 1) ;
|
|
get<0>( vCollision[nInd].CollisionInfo) = get<0>( vPntM[nInd]) ;
|
|
bool bOnPerimeter = ( find( vIndPerimeter.begin(), vIndPerimeter.end(), nInd) != vIndPerimeter.end()) ;
|
|
get<1>( vCollision[nInd].CollisionInfo) = ( bOnPerimeter ? INFINITO : get<1>( vPntM[nInd])) ;
|
|
vCollision[nInd].bInSpiral = false ;
|
|
vCollision[nInd].bInZConst = false ;
|
|
vCollision[nInd].bOnBorder = false ;
|
|
for ( int nV = 0 ; nV < int( get<2>( vPntM[nInd]).size()) ; ++ nV) {
|
|
if ( ! bOnPerimeter) {
|
|
double dAbsCos = abs( get<2>( vPntM[nInd])[nV] * vtAxL) ;
|
|
if ( ! vCollision[nInd].bInZConst)
|
|
vCollision[nInd].bInZConst = ( dAbsCos < dCosClipping + EPS_ANG_ZERO) ; // theta <= ClippingAng
|
|
if ( ! vCollision[nInd].bInSpiral)
|
|
vCollision[nInd].bInSpiral = ( dAbsCos > dCosClipping + EPS_ANG_ZERO) ; // theta > ClippingAng
|
|
if ( ! vCollision[nInd].bOnBorder)
|
|
vCollision[nInd].bOnBorder = ( dAbsCos > dLimInfCosClipping + EPS_ANG_ZERO &&
|
|
dAbsCos < dLimSupCosClipping + EPS_ANG_ZERO) ; // LimInfClippingAng <= theta <= LimSupClippingAng
|
|
}
|
|
get<2>( vCollision[nInd].CollisionInfo).push_back( get<2>( vPntM[nInd])[nV]) ;
|
|
}
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
PtrOwner<IGeoPoint3d> pt( CreateGeoPoint3d()) ;
|
|
pt->Set( get<0>( vCollision[nInd].CollisionInfo) - vtAxL * ( m_TParams.m_dLen - get<1>( vCollision[nInd].CollisionInfo))) ;
|
|
int _pS = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLyS, pt->Clone()) ;
|
|
int _pZC = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLyZC, pt->Clone()) ;
|
|
int _pBo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLyBO, pt->Clone()) ;
|
|
Color myColS = ( vCollision[nInd].bInSpiral ? RED : BLUE) ;
|
|
Color myColZC = ( vCollision[nInd].bInZConst ? RED : BLUE) ;
|
|
Color myColBord = ( vCollision[nInd].bOnBorder ? RED : BLUE) ;
|
|
m_pGeomDB->SetMaterial( _pS, myColS) ;
|
|
m_pGeomDB->SetMaterial( _pZC, myColZC) ;
|
|
m_pGeomDB->SetMaterial( _pBo, myColBord) ;
|
|
for ( int nV = 0 ; nV < int( get<2>( vCollision[nInd].CollisionInfo).size()) ; ++ nV) {
|
|
PtrOwner<IGeoVector3d> vt( CreateGeoVector3d()) ;
|
|
vt->Set( get<2>( vCollision[nInd].CollisionInfo)[nV]) ;
|
|
vt->Translate( pt->GetPoint() - ORIG) ;
|
|
int _vN = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLyN, vt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _vN, Color( abs( vt->GetVector().x), abs( vt->GetVector().y), abs( vt->GetVector().z))) ;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
|
|
ICRVCOMPOPOVECTOR vCrvSpiral, vCrvZConst, vCrvAmbiguous ;
|
|
int nThreadMax = thread::hardware_concurrency() ;
|
|
if ( nThreadMax <= 1) {
|
|
// recupero le curve di contorno per la superficie Spiral
|
|
ICRVCOMPOPOVECTOR vCrvSpiral ;
|
|
if ( ! MarchingSquares( vCollision, 0, TOL_SAMPLE / 2., nStepX, nStepY, dSplitAngle, dLimInfSplitAng,
|
|
dLimSupSplitAng, vtAxL, vtMoveL, pCAvTlStm, vCrvSpiral))
|
|
return false ;
|
|
// recupero le curve di contorno per la superficie ZConst
|
|
ICRVCOMPOPOVECTOR vCrvZConst ;
|
|
if ( ! MarchingSquares( vCollision, 1, TOL_SAMPLE / 2., nStepX, nStepY, dSplitAngle, dLimInfSplitAng,
|
|
dLimSupSplitAng, vtAxL, vtMoveL, pCAvTlStm, vCrvZConst))
|
|
return false ;
|
|
// recupero le curve di bordo per la superficie Ambigua
|
|
if ( ! MarchingSquares( vCollision, 2, TOL_SAMPLE / 2., nStepX, nStepY, dSplitAngle, dLimInfSplitAng,
|
|
dLimSupSplitAng, vtAxL, vtMoveL, pCAvTlStm, vCrvAmbiguous))
|
|
return false ;
|
|
}
|
|
else {
|
|
future<bool> vRes[3] ;
|
|
vRes[0] = async( launch::async, &SurfFinishing::MarchingSquares, this, cref( vCollision), 0,
|
|
TOL_SAMPLE / 2., nStepX, nStepY, dSplitAngle, dLimInfSplitAng, dLimSupSplitAng,
|
|
cref( vtAxL), cref( vtMoveL), ref( pCAvTlStm), ref( vCrvSpiral)) ;
|
|
vRes[1] = async( launch::async, &SurfFinishing::MarchingSquares, this, cref( vCollision), 1,
|
|
TOL_SAMPLE / 2., nStepX, nStepY, dSplitAngle, dLimInfSplitAng, dLimSupSplitAng,
|
|
cref( vtAxL), cref( vtMoveL), ref( pCAvTlStm), ref( vCrvZConst)) ;
|
|
vRes[2] = async( launch::async, &SurfFinishing::MarchingSquares, this, cref( vCollision), 2,
|
|
TOL_SAMPLE / 2., nStepX, nStepY, dSplitAngle, dLimInfSplitAng, dLimSupSplitAng,
|
|
cref( vtAxL), cref( vtMoveL), ref( pCAvTlStm), ref( vCrvAmbiguous)) ;
|
|
int nFin = 0 ;
|
|
bool bOk = true ;
|
|
while ( nFin < 2) {
|
|
for ( int i = 0 ; i < 2 ; ++ i) {
|
|
if ( vRes[i].valid() && vRes[i].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) {
|
|
bOk = vRes[i].get() && bOk ;
|
|
++ nFin ;
|
|
}
|
|
}
|
|
}
|
|
if ( ! bOk)
|
|
return false ;
|
|
}
|
|
|
|
// costruisco la regione ZConst
|
|
if ( ! vCrvZConst.empty()) {
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( int i = 0 ; i < int( vCrvZConst.size()) ; ++ i)
|
|
SfrMaker.AddCurve( Release( vCrvZConst[i])) ;
|
|
PtrOwner<ISurfFlatRegion> pSfrZC( SfrMaker.GetSurf()) ;
|
|
if ( ! IsNull( pSfrZC) && pSfrZC->IsValid()) {
|
|
pSfrZConst->CopyFrom( pSfrZC) ;
|
|
pSfrZConst->Translate( - vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
if ( AreOppositeVectorApprox( pSfrZConst->GetNormVersor(), pSfrLoc->GetNormVersor()))
|
|
pSfrZConst->Invert() ;
|
|
// Offset di correzione per le regioni ZConst
|
|
pSfrZConst->Offset( TOL_SAMPLE + EPS_SMALL, ICurve::OFF_FILLET) ;
|
|
// Offset di correzione
|
|
#if ENABLE_OPTIMAL_SOFT_DEBUG
|
|
int _pSZC = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrZConst->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _pSZC, Color( 0., 1., 0., .65)) ;
|
|
#endif
|
|
}
|
|
}
|
|
// costruisco la regione Spiral
|
|
if ( ! vCrvSpiral.empty()) {
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( int i = 0 ; i < int( vCrvSpiral.size()) ; ++ i)
|
|
SfrMaker.AddCurve( Release( vCrvSpiral[i])) ;
|
|
PtrOwner<ISurfFlatRegion> pSfrS( SfrMaker.GetSurf()) ;
|
|
if ( ! IsNull( pSfrS) && pSfrS->IsValid()) {
|
|
pSfrSpiral->CopyFrom( pSfrS) ;
|
|
pSfrSpiral->Translate( - vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
if ( AreOppositeVectorApprox( pSfrSpiral->GetNormVersor(), pSfrLoc->GetNormVersor()))
|
|
pSfrSpiral->Invert() ;
|
|
// Offset di correzione per le regioni Spiral
|
|
pSfrSpiral->Offset( - TOL_SAMPLE / 10., ICurve::OFF_FILLET) ;
|
|
#if ENABLE_OPTIMAL_SOFT_DEBUG
|
|
int _pSS = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrSpiral->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _pSS, Color( 1., 0., 0., .65)) ;
|
|
#endif
|
|
}
|
|
}
|
|
// Costruisco la regine Ambigua
|
|
if ( ! vCrvAmbiguous.empty()) {
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( int i = 0 ; i < int( vCrvAmbiguous.size()) ; ++ i)
|
|
SfrMaker.AddCurve( Release( vCrvAmbiguous[i])) ;
|
|
PtrOwner<ISurfFlatRegion> pSfrAmb( SfrMaker.GetSurf()) ;
|
|
if ( ! IsNull( pSfrAmb) && pSfrAmb->IsValid()) {
|
|
pSfrAmb->Translate( - vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
if ( AreOppositeVectorApprox( pSfrAmb->GetNormVersor(), pSfrLoc->GetNormVersor()))
|
|
pSfrAmb->Invert() ;
|
|
// Offset di correzione per le regioni Spiral
|
|
pSfrAmb->Offset( - TOL_SAMPLE / 10., ICurve::OFF_FILLET) ;
|
|
#if ENABLE_OPTIMAL_SOFT_DEBUG
|
|
int _pSS = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrAmb->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _pSS, Color( 1., .5, .25, .65)) ;
|
|
#endif
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
ICURVEPOVECTOR vCrvMedAxis ;
|
|
pSfrAmb->CalcMedialAxis( vCrvMedAxis) ;
|
|
for ( int i = 0 ; i < int( vCrvMedAxis.size()) ; ++ i) {
|
|
int _pSS = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvMedAxis[i]->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _pSS, ORANGE) ;
|
|
}
|
|
int _pSS = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrAmb->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _pSS, Color( 1., .5, .25, .65)) ;
|
|
#endif
|
|
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::OrderAndConnectPencilCurves( ICRVCOMPOPOVECTOR& vCrvCompo, double dLinkTol) const
|
|
{
|
|
// elimino tutte le curve invalide
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
if ( vCrvCompo[i] == nullptr || ! vCrvCompo[i]->IsValid() || vCrvCompo[i]->GetCurveCount() == 0) {
|
|
vCrvCompo.erase( vCrvCompo.begin() + i) ;
|
|
-- i ;
|
|
}
|
|
}
|
|
// se ho meno di 2 curve da ordinare, non faccio nulla
|
|
if ( int( vCrvCompo.size()) < 2)
|
|
return true ;
|
|
|
|
// vettore dei quadrati delle distanze
|
|
DBLVECTOR vdMinSqDist( vCrvCompo.size(), INFINITO) ;
|
|
|
|
// ---- ordino le curve in base al punto iniziale della corrente ----
|
|
// NB. punto iniziale, non finale !
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) - 1 ; ++ i) {
|
|
Point3d ptRef ; vCrvCompo[i]->GetStartPoint( ptRef) ;
|
|
int nMinInd = i + 1 ;
|
|
for ( int j = i + 1 ; j < int( vCrvCompo.size()) ; ++ j) {
|
|
// se chiusa, cambio il suo punto iniziale in quello più vicino alla curva corrente
|
|
if ( vCrvCompo[j]->IsClosed()) {
|
|
double dU ;
|
|
int nFlag = 0 ;
|
|
if ( DistPointCurve( ptRef, *vCrvCompo[j]).GetParamAtMinDistPoint( 0., dU, nFlag))
|
|
vCrvCompo[j]->ChangeStartPoint( dU) ;
|
|
}
|
|
Point3d ptCheck ; vCrvCompo[j]->GetStartPoint( ptCheck) ;
|
|
double dSqDist = SqDist( ptRef, ptCheck) ;
|
|
if ( dSqDist < vdMinSqDist[i]) {
|
|
vdMinSqDist[i] = dSqDist ;
|
|
nMinInd = j ;
|
|
}
|
|
}
|
|
swap( vCrvCompo[i + 1], vCrvCompo[nMinInd]) ;
|
|
}
|
|
|
|
// controllo la distanza tra le curve ordinate, se accettabile, collegamento lineare
|
|
ICRVCOMPOPOVECTOR vCrvCompoOrdered ; vCrvCompoOrdered.reserve( vCrvCompo.size()) ;
|
|
bool bNewPath = true ;
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
if ( bNewPath) {
|
|
vCrvCompoOrdered.emplace_back( Release( vCrvCompo[i])) ;
|
|
bNewPath = false ;
|
|
}
|
|
else {
|
|
Point3d ptCurr ; vCrvCompo[i]->GetStartPoint( ptCurr) ;
|
|
vCrvCompoOrdered.back()->AddLine( ptCurr) ;
|
|
vCrvCompoOrdered.back()->AddCurve( Release( vCrvCompo[i])) ;
|
|
}
|
|
bNewPath = ( vdMinSqDist[i] > dLinkTol * dLinkTol) ;
|
|
}
|
|
swap( vCrvCompo, vCrvCompoOrdered) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetOffsetCurvesFromPencilProjection( const ICRVCOMPOPOVECTOR& vCrvCompo, const ISurfFlatRegion* pSfrClass,
|
|
double dOffs, int nPencilType, ICRVCOMPOPOVECTOR& vCrvCompoRes) const
|
|
{
|
|
// se non ho curve, non faccio nulla
|
|
if ( vCrvCompo.empty())
|
|
return true ;
|
|
// se non ho una superficie di classificazione non faccio nulla
|
|
if ( pSfrClass == nullptr || ! pSfrClass->IsValid())
|
|
return true ;
|
|
|
|
// se pencil Singola o multipla
|
|
if ( nPencilType == PENCIL_CORNER || nPencilType == PENCIL_FAT_CORNER) {
|
|
// calcolo le curve di Offset
|
|
ICURVEPVECTOR vCrv ; vCrv.reserve( vCrvCompo.size()) ;
|
|
for ( const auto& pCompo : vCrvCompo) {
|
|
// considero la curva solo se valida
|
|
if ( pCompo != nullptr && pCompo->IsValid() && pCompo->GetCurveCount() > 0)
|
|
if ( ! vCrv.emplace_back( CloneCurveComposite( pCompo))) {
|
|
for ( auto& pCrv : vCrv) { delete( pCrv) ; pCrv = nullptr ;}
|
|
return false ;
|
|
}
|
|
}
|
|
ICURVEPOVECTOR vCrvOffs ;
|
|
if ( nPencilType == PENCIL_CORNER) {
|
|
if ( ! CalcOffsetCurves( vCrv, vCrvOffs, dOffs)) {
|
|
for ( auto& pCrv : vCrv) { delete( pCrv) ; pCrv = nullptr ;}
|
|
return false ;
|
|
}
|
|
}
|
|
else if ( nPencilType == PENCIL_FAT_CORNER) {
|
|
if ( ! CalcFatOffsetCurves( vCrv, vCrvOffs, dOffs, false, false, false)) {
|
|
for ( auto& pCrv : vCrv) { delete( pCrv) ; pCrv = nullptr ;}
|
|
return false ;
|
|
}
|
|
}
|
|
for ( auto& pCrv : vCrv) { delete( pCrv) ; pCrv = nullptr ;}
|
|
for ( auto& pCrv : vCrvOffs)
|
|
vCrvCompoRes.emplace_back( ConvertCurveToComposite( Release( pCrv))) ;
|
|
|
|
// classifico le curve tenendo solo le parti interne alla superficie
|
|
ICRVCOMPOPOVECTOR vCrvCompoInSfr ;
|
|
for ( const auto& pCrvCompo : vCrvCompoRes) {
|
|
// se curva non valida, passo alla successiva
|
|
if ( pCrvCompo == nullptr || ! pCrvCompo->IsValid())
|
|
continue ;
|
|
CRVCVECTOR ccClass ;
|
|
if ( pSfrClass->GetCurveClassification( *pCrvCompo, EPS_SMALL, ccClass)) {
|
|
for ( int i = 0 ; i < int( ccClass.size()) ; ++ i) {
|
|
if ( ccClass[i].nClass != CRVC_OUT) {
|
|
PtrOwner<ICurveComposite> pMyCompo( ConvertCurveToComposite( pCrvCompo->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE))) ;
|
|
if ( ! IsNull( pMyCompo) && pMyCompo->IsValid()) {
|
|
if ( ! vCrvCompoInSfr.emplace_back( Release( pMyCompo)))
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
swap( vCrvCompoInSfr, vCrvCompoRes) ;
|
|
}
|
|
|
|
// se pencil per regione a ZigZag
|
|
else if ( nPencilType == PENCIL_REGION) {
|
|
// definisco la regione di Offset per percorsi a ZigZag
|
|
PtrOwner<ISurfFlatRegion> pSfrZigZag( CreateSurfFlatRegion()) ;
|
|
if ( IsNull( pSfrZigZag))
|
|
return false ;
|
|
// aggiungo le regioni di Fat curve
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
PtrOwner<ISurfFlatRegion> pSfrFat( GetSurfFlatRegionFromFatCurve( vCrvCompo[i]->Clone(), dOffs + m_TParams.m_dDiam / 2., false, false)) ;
|
|
if ( ! IsNull( pSfrFat) && pSfrFat->IsValid()) {
|
|
if ( IsNull( pSfrZigZag) || ! pSfrZigZag->IsValid())
|
|
pSfrZigZag.Set( Release( pSfrFat)) ;
|
|
else
|
|
pSfrZigZag->Add( *pSfrFat) ;
|
|
}
|
|
}
|
|
// limito la superficie con la regione di contenimento
|
|
if ( ! IsNull( pSfrZigZag) && pSfrZigZag->IsValid()) {
|
|
if ( ! pSfrZigZag->Intersect( *pSfrClass))
|
|
return false ;
|
|
}
|
|
// creo le curve di finitura a ZigZag
|
|
if ( ! IsNull( pSfrZigZag) && pSfrZigZag->IsValid()) {
|
|
// scorro i Chunk della regione
|
|
for ( int nC = 0 ; nC < pSfrZigZag->GetChunkCount() ; ++ nC) {
|
|
// recupero il Chunk
|
|
PtrOwner<ISurfFlatRegion> pSfrChunk( pSfrZigZag->CloneChunk( nC)) ;
|
|
if ( IsNull( pSfrChunk) || ! pSfrChunk->IsValid())
|
|
return false ;
|
|
// considero il Chunk come tutto chiuso
|
|
for ( int nL = 0 ; nL < pSfrChunk->GetLoopCount( 0) ; ++ nL) {
|
|
for ( int nU = 0 ; nU < pSfrChunk->GetLoopCurveCount( 0, nL) ; ++ nU)
|
|
pSfrChunk->SetCurveTempProp( 0, nL, nU, TEMP_PROP_CLOSE_EDGE, 0) ;
|
|
}
|
|
// lavoro a ZigZag
|
|
ICRVCOMPOPOVECTOR vCrvZigZag ;
|
|
if ( ! CalcPocketing( pSfrChunk, m_TParams.m_dDiam / 2., 0., m_Params.m_dSideStep, m_Params.m_dSideAngle,
|
|
5., POCKET_SUB_ZIGZAG, false, false, m_Params.m_bInvert, true, true, false,
|
|
false, P_INVALID, nullptr, true, INFINITO, GetLeadInType(), m_Params.m_dLiTang, 0.,
|
|
GetLeadOutType(), m_Params.m_dLoTang, false, 0., 0., vCrvZigZag))
|
|
return false ;
|
|
// inserisco le curve ricavate
|
|
for ( auto& pCompo : vCrvZigZag) {
|
|
if ( pCompo != nullptr && pCompo->IsValid())
|
|
vCrvCompoRes.emplace_back( Release( pCompo)) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::ProjectExposedPencilCurvesOnPlane( ICAvToolSurfTm* pCAvTlStm, const ICRVCOMPOPOVECTOR& vCrvCompo,
|
|
const Plane3d& plProj, const Vector3d& vtAxL, const Vector3d& vtMoveL,
|
|
double dOffs, double dDepth, ICRVCOMPOPOVECTOR& vCrvCompoProj) const
|
|
{
|
|
// se classe di collisione non valida, errore
|
|
if ( pCAvTlStm == nullptr)
|
|
return false ;
|
|
vCrvCompoProj.clear() ;
|
|
// se non ho curve da proeittare, non faccio nulla
|
|
if ( vCrvCompo.empty())
|
|
return true ;
|
|
|
|
// definisco la tolleranza di campionamento
|
|
double dSampleTol = m_Params.m_dApprox ;
|
|
|
|
// scorro le curve
|
|
for ( const auto& pCrvCompo : vCrvCompo) {
|
|
|
|
// se la curva non è valida, passo alla successiva
|
|
if ( pCrvCompo == nullptr || ! pCrvCompo->IsValid())
|
|
continue ;
|
|
|
|
// memorizzo le entità Geometriche
|
|
Vector3d vtExtr ; pCrvCompo->GetExtrusion( vtExtr) ;
|
|
int nProp0 = pCrvCompo->GetTempProp( 0) ;
|
|
int nProp1 = pCrvCompo->GetTempProp( 1) ;
|
|
double dPar0 = pCrvCompo->GetTempParam( 0) ;
|
|
double dPar1 = pCrvCompo->GetTempParam( 1) ;
|
|
|
|
// approssimo, campiono e traslo la curva per calcolare le collisioni
|
|
PolyLine PL ;
|
|
pCrvCompo->ApproxWithLines( LIN_TOL_STD, ANG_TOL_STD_DEG, ICurve::APL_SPECIAL, PL) ;
|
|
PL.AdjustForMaxSegmentLen( dSampleTol) ;
|
|
PL.Translate( vtAxL * m_TParams.m_dLen) ;
|
|
if ( ! pCAvTlStm->TestPath( PL.GetUPointList(), vtAxL, vtMoveL, dSampleTol))
|
|
return false ;
|
|
|
|
#if ENABLE_PENCIL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "pencil_PointCollision") ;
|
|
int nLayId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetStatus( nLayId, GDB_ST_OFF) ;
|
|
// contro-traslo i punti per renderli riportarli in posizione originale
|
|
// ( dU mi dice di quanto alzarli per evitare la collisione con la superficie)
|
|
PolyLine PL_debug = PL ;
|
|
for ( auto& ptU : PL_debug.GetUPointList())
|
|
ptU.first.Translate( - vtAxL * ( m_TParams.m_dLen + ptU.second)) ;
|
|
double dUmin = INFINITO ;
|
|
double dUMax = - INFINITO ;
|
|
for ( POINTU& ptU : PL_debug.GetUPointList()) {
|
|
if ( ptU.second > dUMax)
|
|
dUMax = ptU.second ;
|
|
if ( ptU.second < dUmin)
|
|
dUmin = ptU.second ;
|
|
}
|
|
for ( POINTU& ptU : PL_debug.GetUPointList()) {
|
|
double myAngle = 240 + 120 * ( ptU.second / ( dUMax - dUmin)) ;
|
|
IGeoPoint3d* pt = CreateGeoPoint3d() ; pt->Set( ptU.first) ;
|
|
int nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pt) ;
|
|
m_pGeomDB->SetInfo( nPtId, "dU", ToString( ptU.second)) ;
|
|
m_pGeomDB->SetMaterial( nPtId, Color( GetColorFromHSV( HSV( myAngle, 1., 1.)))) ;
|
|
}
|
|
#endif
|
|
|
|
// elimino tutti i punti che si trovano ad una profondità inferiore di dDepth
|
|
// elimino tutti i punti che presentano un dU > 2 * dOffs
|
|
bool bFirst = true ;
|
|
POLYLINEVECTOR vPLTemp ;
|
|
for ( auto& ptU : PL.GetUPointList()) {
|
|
if ( ptU.second < 2. * dOffs + EPS_SMALL &&
|
|
DistPointPlane( ptU.first - vtAxL * ( m_TParams.m_dLen + ptU.second), plProj) < dDepth + EPS_ZERO) {
|
|
if ( bFirst) {
|
|
vPLTemp.emplace_back( PolyLine()) ;
|
|
bFirst = false ;
|
|
}
|
|
vPLTemp.back().AddUPoint( 0., ptU.first) ;
|
|
}
|
|
else
|
|
bFirst = true ;
|
|
}
|
|
// elimino le PolyLine invalide e proietto i punti sul piano della pSfrCnt
|
|
for ( int i = 0 ; i < int( vPLTemp.size()) ; ++ i) {
|
|
if ( vPLTemp[i].GetPointNbr() < 2) {
|
|
vPLTemp.erase( vPLTemp.begin() + i) ;
|
|
-- i ;
|
|
}
|
|
else {
|
|
for ( auto& ptU : vPLTemp[i].GetUPointList())
|
|
ptU.first = ProjectPointOnPlane( ptU.first, plProj) ;
|
|
}
|
|
}
|
|
|
|
// per le PolyLine rimanenti, definisco le curve
|
|
for ( int i = 0 ; i < int( vPLTemp.size()) ; ++ i) {
|
|
// recupero la PolyLine corrente
|
|
PolyLine& PL = vPLTemp[i] ;
|
|
// rimuovo i punti allineati
|
|
PL.RemoveAlignedPoints( dSampleTol) ;
|
|
// definisco una curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo) || ! pCrvCompo->FromPolyLine( PL)) {
|
|
m_pMchMgr->SetWarning( 3155, "Warning in SurfFinishing : Pencil path not completed") ;
|
|
continue ;
|
|
}
|
|
// se la curva risultate è valida
|
|
if ( pCrvCompo->IsValid()) {
|
|
|
|
// -- TODO -- controllo eventuali auto-intersezioni nel piano (?)
|
|
|
|
// imposto i parametri temporanei
|
|
pCrvCompo->SetExtrusion( vtExtr) ;
|
|
pCrvCompo->SetTempProp( nProp0, 0) ;
|
|
pCrvCompo->SetTempProp( nProp1, 1) ;
|
|
pCrvCompo->SetTempParam( dPar0, 0) ;
|
|
pCrvCompo->SetTempParam( dPar1, 1) ;
|
|
// memorizzo la curva ricavata
|
|
vCrvCompoProj.emplace_back( Release( pCrvCompo)) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
// concateno le curve
|
|
return ( ChainPencilCurves( vCrvCompoProj, 10 * dSampleTol, false)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::WorkPencilCurves( const ICRVCOMPOPOVECTOR& vCrvCompo, const ISurfFlatRegion* pSfrCnt, int nPencilType, double dOffs, int nOffs,
|
|
double dDepth, double dElev, double dLinTol, const Vector3d& vtTool, const SURFLOCALVECTOR& vSrfLoc,
|
|
const Frame3d& frSurf, ICAvToolSurfTm* pCAvTlStm, bool bSplitArcs)
|
|
{
|
|
// se non ho curve da proiettare, non faccio nulla
|
|
if ( vCrvCompo.empty())
|
|
return true ;
|
|
// se regione non valida, errore
|
|
if ( pSfrCnt == nullptr || ! pSfrCnt->IsValid())
|
|
return false ;
|
|
|
|
// porto i dati geometrici in locale alle superfici
|
|
Vector3d vtAxL = vtTool ;
|
|
vtAxL.ToLoc( frSurf) ;
|
|
Vector3d vtMoveL = vtAxL ;
|
|
|
|
// Data l'approssimazione lineare di una TriMesh considero il calcolo delle collisioni con
|
|
// un utensile leggermente più piccolo
|
|
PtrOwner<ICAvToolSurfTm> pCAvTlStm_Smaller( CreateCAvToolSurfTm()) ;
|
|
if ( IsNull( pCAvTlStm_Smaller) ||
|
|
! SetCAvTlStmForSurfaces( pCAvTlStm_Smaller, pSfrCnt, dDepth, m_TParams.m_dLen,
|
|
m_TParams.m_dDiam - 100 * EPS_SMALL, m_TParams.m_dCornRad, m_TParams.m_dSideAng,
|
|
m_TParams.m_dMaxMat, GetOffsR(), vSrfLoc, SURFLOCALVECTOR{}))
|
|
return false ;
|
|
|
|
// definisco il piano di pSfrCnt in locale alle superfici
|
|
Point3d ptCen ; pSfrCnt->GetCentroid( ptCen) ;
|
|
ptCen.ToLoc( frSurf) ;
|
|
Plane3d plProj ;
|
|
if ( ! plProj.Set( ptCen, vtAxL))
|
|
return false ;
|
|
|
|
// proietto le curve visibili dalla pSfrCnt rispetto a vtTool sul piano calcolato
|
|
ICRVCOMPOPOVECTOR vCrvCompoProj ;
|
|
if ( ! ProjectExposedPencilCurvesOnPlane( pCAvTlStm_Smaller, vCrvCompo, plProj, vtAxL, vtMoveL, dOffs, dDepth, vCrvCompoProj))
|
|
return false ;
|
|
// se non ho curve, non faccio nulla
|
|
if ( vCrvCompoProj.empty()) {
|
|
m_pMchMgr->SetWarning( 3152, "Warning in SurfFinishing : No machinable path") ;
|
|
return true ;
|
|
}
|
|
#if ENABLE_PENCIL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "pencil_CompoProj") ;
|
|
int nLayId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetStatus( nLayId, GDB_ST_OFF) ;
|
|
for ( const auto& pCompo : vCrvCompoProj) {
|
|
int nCrvId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pCompo->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nCrvId, LIME) ;
|
|
}
|
|
#endif
|
|
|
|
// definisco la superficie di classificazione delle curve
|
|
double dRegOffs = - m_TParams.m_dDiam / 2. + m_Params.m_dOverlap + 2 * EPS_SMALL ;
|
|
PtrOwner<ISurfFlatRegion> pSfrClass( pSfrCnt->CreateOffsetSurf( dRegOffs, ICurve::OFF_FILLET)) ;
|
|
if ( IsNull( pSfrClass))
|
|
return false ;
|
|
if ( ! pSfrClass->IsValid())
|
|
return true ;
|
|
pSfrClass->ToLoc( frSurf) ;
|
|
|
|
// vettore di Curve pencil proiettate all'interno della regione di classifiazione
|
|
ICRVCOMPOPOVECTOR vCrvCompoInSfr ;
|
|
|
|
// se Pencil singola o multipla
|
|
if ( nPencilType == PENCIL_CORNER || nPencilType == PENCIL_FAT_CORNER) {
|
|
// per ogni step di Offset...
|
|
for ( int i = 0 ; i < nOffs ; ++ i) {
|
|
// calcolo le curve di Offset
|
|
ICRVCOMPOPOVECTOR vCrvCompoInSfrInStep ;
|
|
if ( ! GetOffsetCurvesFromPencilProjection( vCrvCompoProj, pSfrClass, i * m_Params.m_dSideStep, nPencilType, vCrvCompoInSfrInStep))
|
|
return false ;
|
|
// concateno le curve ottenute
|
|
if ( ! ChainPencilCurves( vCrvCompoInSfrInStep, min( m_Params.m_dSideStep / 2., dLinTol), false))
|
|
return false ;
|
|
// memorizzo le curve
|
|
for ( auto& pCrvCompo : vCrvCompoInSfrInStep) {
|
|
if ( pCrvCompo != nullptr && pCrvCompo->IsValid()) {
|
|
if ( ! vCrvCompoInSfr.emplace_back( Release( pCrvCompo)))
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
// concateno ed unisco eventuali Offset
|
|
double dLinkTol = 0 ;
|
|
if ( nOffs > 1)
|
|
dLinkTol = SQRT2 * m_Params.m_dSideStep + 10 * EPS_SMALL ;
|
|
if ( ! OrderAndConnectPencilCurves( vCrvCompoInSfr, dLinkTol))
|
|
return false ;
|
|
}
|
|
// se Pencil per regioni a ZigZag
|
|
else if ( nPencilType == PENCIL_REGION) {
|
|
// calcolo le curve di Offset
|
|
if ( ! GetOffsetCurvesFromPencilProjection( vCrvCompoProj, pSfrClass, nOffs, nPencilType, vCrvCompoInSfr))
|
|
return false ;
|
|
}
|
|
// se nessuna curva rimanente, non faccio nulla
|
|
if ( vCrvCompoInSfr.empty()) {
|
|
m_pMchMgr->SetWarning( 3152, "Warning in SurfFinishing : No machinable path") ;
|
|
return true ;
|
|
}
|
|
|
|
// lavoro le curve
|
|
for ( const auto& pCrvCompo : vCrvCompoInSfr) {
|
|
if ( pCrvCompo != nullptr && pCrvCompo->IsValid()) {
|
|
pCrvCompo->ToGlob( frSurf) ;
|
|
if ( ! AddProjection( pCAvTlStm, vSrfLoc, frSurf, pCrvCompo, vtTool, dDepth, dElev, bSplitArcs))
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::ChainPencilCurves( ICRVCOMPOPOVECTOR& vCrvCompo, double dLinTol, bool bAllowInvert) const
|
|
{
|
|
// se non ho curve da lavorare, non faccio nulla
|
|
if ( vCrvCompo.empty())
|
|
return true ;
|
|
|
|
/* Algoritmo : scorro le curve e se ricavo due estremi più vicini della tolleranza li concatento
|
|
* andando ad aggiungere il punto medio tra i due.
|
|
* Se due curve vengono concatenate, l'algoritmo riparte.
|
|
* Se nessuna curva viene conatenata, l'algoritmo termina.
|
|
* [ numero massimo di iterazioni definito da MAXITER]
|
|
- Ad una curva chiusa non si concatenano altre curve.
|
|
- Se due curve possono essere concatenate, ma l'estremo di una di esse che non
|
|
è coinvolto dal concatenamento tocca l'altra curva, esse non vengono concatenate */
|
|
|
|
bool bFinish = false ;
|
|
const int MAXITER = 10000 ;
|
|
int nIter = 0 ;
|
|
while ( ! bFinish && nIter < MAXITER) {
|
|
// scorro le curve
|
|
bool bJoint = false ;
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) - 1 && ! bJoint ; ++ i) {
|
|
// se curva i-esima chiusa, non faccio nulla
|
|
if ( vCrvCompo[i]->IsClosed())
|
|
continue ;
|
|
// recupero gli estremi della curva i-esima
|
|
Point3d ptStart_i ; vCrvCompo[i]->GetStartPoint( ptStart_i) ;
|
|
Point3d ptEnd_i ; vCrvCompo[i]->GetEndPoint( ptEnd_i) ;
|
|
for ( int j = i + 1 ; j < int( vCrvCompo.size()) && ! bJoint ; ++ j) {
|
|
// se curva j-esima chiusa, non faccio nulla
|
|
if ( vCrvCompo[j]->IsClosed())
|
|
continue ;
|
|
// recupero gli estremi della curva j-esima
|
|
Point3d ptStart_j ; vCrvCompo[j]->GetStartPoint( ptStart_j) ;
|
|
Point3d ptEnd_j ; vCrvCompo[j]->GetEndPoint( ptEnd_j) ;
|
|
// controllo se i punti sono vicino tra loro
|
|
if ( AreSamePointEpsilon( ptStart_i, ptEnd_j, dLinTol)) {
|
|
// controllo che il punto finale della curva i-esima sia distante dalla j-esima
|
|
double dSqDist = 0. ;
|
|
if ( DistPointCurve( ptEnd_i, *vCrvCompo[j]).GetSqDist( dSqDist) &&
|
|
dSqDist < dLinTol * dLinTol)
|
|
continue ;
|
|
Point3d ptMid = Media( ptStart_i, ptEnd_j) ;
|
|
vCrvCompo[i]->ModifyStart( ptMid) ;
|
|
vCrvCompo[j]->ModifyEnd( ptMid) ;
|
|
vCrvCompo[j]->AddCurve( Release( vCrvCompo[i])) ;
|
|
vCrvCompo.erase( vCrvCompo.begin() + i) ;
|
|
bJoint = true ;
|
|
}
|
|
else if ( bAllowInvert && AreSamePointEpsilon( ptStart_i, ptStart_j, dLinTol)) {
|
|
// controllo che il punto finale della curva i-esima sia distante dalla j-esima
|
|
double dSqDist = 0. ;
|
|
if ( DistPointCurve( ptEnd_i, *vCrvCompo[j]).GetSqDist( dSqDist) &&
|
|
dSqDist < dLinTol * dLinTol)
|
|
continue ;
|
|
Point3d ptMid = Media( ptStart_i, ptStart_j) ;
|
|
vCrvCompo[i]->ModifyStart( ptMid) ;
|
|
vCrvCompo[j]->ModifyStart( ptMid) ;
|
|
vCrvCompo[j]->Invert() ;
|
|
vCrvCompo[j]->AddCurve( Release( vCrvCompo[i])) ;
|
|
vCrvCompo.erase( vCrvCompo.begin() + i) ;
|
|
bJoint = true ;
|
|
}
|
|
else if ( bAllowInvert && AreSamePointEpsilon( ptEnd_i, ptEnd_j, dLinTol)) {
|
|
// controllo che il punto inziale della curva i-esima sia distante dalla j-esima
|
|
double dSqDist = 0. ;
|
|
if ( DistPointCurve( ptStart_i, *vCrvCompo[j]).GetSqDist( dSqDist) &&
|
|
dSqDist < dLinTol * dLinTol)
|
|
continue ;
|
|
Point3d ptMid = Media( ptEnd_i, ptEnd_j) ;
|
|
vCrvCompo[i]->ModifyEnd( ptMid) ;
|
|
vCrvCompo[j]->ModifyEnd( ptMid) ;
|
|
vCrvCompo[j]->Invert() ;
|
|
vCrvCompo[i]->AddCurve( Release( vCrvCompo[j])) ;
|
|
vCrvCompo.erase( vCrvCompo.begin() + j) ;
|
|
bJoint = true ;
|
|
}
|
|
else if ( AreSamePointEpsilon( ptEnd_i, ptStart_j, dLinTol)) {
|
|
// controllo che il punto inziale della curva i-esima sia distante dalla j-esima
|
|
double dSqDist = 0. ;
|
|
if ( DistPointCurve( ptStart_i, *vCrvCompo[j]).GetSqDist( dSqDist) &&
|
|
dSqDist < dLinTol * dLinTol)
|
|
continue ;
|
|
Point3d ptMid = Media( ptEnd_i, ptStart_j) ;
|
|
vCrvCompo[i]->ModifyEnd( ptMid) ;
|
|
vCrvCompo[j]->ModifyStart( ptMid) ;
|
|
vCrvCompo[i]->AddCurve( Release( vCrvCompo[j])) ;
|
|
vCrvCompo.erase( vCrvCompo.begin() + j) ;
|
|
bJoint = true ;
|
|
}
|
|
}
|
|
}
|
|
bFinish = ( ! bJoint) ;
|
|
++ nIter ;
|
|
}
|
|
|
|
// controllo se le curve ricavate sono troppo corte e se posso chiuderle
|
|
for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) {
|
|
// se troppo corte le elimino
|
|
double dLen = 0. ;
|
|
vCrvCompo[i]->GetLength( dLen) ;
|
|
if ( dLen < dLinTol + EPS_ZERO) {
|
|
vCrvCompo.erase( vCrvCompo.begin() + i) ;
|
|
-- i ;
|
|
}
|
|
else if ( vCrvCompo[i]->GetCurveCount() > 1) {
|
|
Point3d ptStart ; vCrvCompo[i]->GetStartPoint( ptStart) ;
|
|
Point3d ptEnd ; vCrvCompo[i]->GetEndPoint( ptEnd) ;
|
|
// se estremi vicini, li unisco chiudendo la curva
|
|
if ( AreSamePointEpsilon( ptStart, ptEnd, dLinTol)) {
|
|
Point3d ptMid = Media( ptStart, ptEnd) ;
|
|
vCrvCompo[i]->ModifyStart( ptMid) ;
|
|
vCrvCompo[i]->ModifyEnd( ptMid) ;
|
|
vCrvCompo[i]->Close() ; // non dovrebbe fare nulla
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetSurfTriMeshFromOffset( const SURFLOCALVECTOR& vSrfLoc, double dOffs,
|
|
double dLinTol, ISurfTriMesh* pStmOffs) const
|
|
{
|
|
// controllo dei parametri
|
|
if ( pStmOffs == nullptr)
|
|
return false ;
|
|
// se non ho superfici non faccio nulla
|
|
if ( vSrfLoc.empty())
|
|
return true ;
|
|
|
|
// recupero il vettore di superfici chiuse
|
|
CISURFTMPVECTOR vStmClosed ; vStmClosed.reserve( vSrfLoc.size()) ;
|
|
for ( const SurfLocal& Surf : vSrfLoc) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( Surf.Get()) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->IsClosed())
|
|
vStmClosed.push_back( pStm) ;
|
|
}
|
|
|
|
// Offset della superficie TriMesh
|
|
PtrOwner<ISurfTriMesh> pMyStmOffs( CreateSurfTriMeshesOffset( vStmClosed, dOffs, dLinTol)) ;
|
|
if ( ! IsNull( pMyStmOffs) && pMyStmOffs->IsValid() && pMyStmOffs->GetTriangleCount() > 0)
|
|
pStmOffs->CopyFrom( pMyStmOffs) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetCurvesFromSurfTriMeshesOffset( const ISurfTriMesh* pStmOffs, double dBiTanAng, double dLinTol,
|
|
int nOffs, const ISurfFlatRegion* pSfrCntLoc, ICRVCOMPOPOVECTOR& vCrvCompo)
|
|
{
|
|
// se superficie non valida non faccio nulla
|
|
vCrvCompo.clear() ;
|
|
if ( pStmOffs == nullptr)
|
|
return false ;
|
|
if ( ! pStmOffs->IsValid() || pStmOffs->GetTriangleCount() == 0)
|
|
return true ;
|
|
|
|
// predispongo il concatenamento ( ammettendo inversione dei segmenti)
|
|
ChainCurves chainC ;
|
|
chainC.Init( true, EPS_SMALL, pStmOffs->GetEdgeCount()) ;
|
|
|
|
// definisco una struttura per informazioni geometriche
|
|
struct EdgeInfo {
|
|
int nE ;
|
|
Point3d ptP1, ptP2 ;
|
|
EdgeInfo( int nEdge, const Point3d& PointP1, const Point3d& PointP2)
|
|
: nE( nEdge), ptP1( PointP1), ptP2( PointP2) {}
|
|
} ;
|
|
|
|
// scorro gli Edge della superficie
|
|
vector<EdgeInfo> vEdgeInfo ; vEdgeInfo.reserve( pStmOffs->GetEdgeCount()) ;
|
|
for ( int nE = 0 ; nE < pStmOffs->GetEdgeCount() ; ++ nE) {
|
|
// recupero gli estremi e l'angolo dell'Edge corrente
|
|
Point3d ptP1, ptP2 ;
|
|
double dAng ;
|
|
if ( ! pStmOffs->GetEdge( nE, ptP1, ptP2, dAng))
|
|
return false ;
|
|
// se angolo al di fuori della tolleranza, passo all'Edge successivo
|
|
if ( dAng > - ( ANG_STRAIGHT - dBiTanAng))
|
|
continue ;
|
|
// se triangoli flippati non li considero ( possibili errore su TriMesh di Offset)
|
|
// NB. ---- TODO migliorare ricostruzione TriMesh da VolZMap
|
|
if ( dAng < - ANG_STRAIGHT + EPS_ANG_SMALL || dAng > ANG_STRAIGHT - EPS_ANG_SMALL)
|
|
continue ;
|
|
// se Edge parallelo alla direzione utensile, lo scarto
|
|
Vector3d vtEdgeDir = ptP2 - ptP1 ;
|
|
vtEdgeDir.Normalize() ;
|
|
if ( AreSameOrOppositeVectorEpsilon( vtEdgeDir, pSfrCntLoc->GetNormVersor(), 10 * EPS_SMALL))
|
|
continue ;
|
|
// memorizzo le entità geometriche ricavate
|
|
vEdgeInfo.emplace_back( nE, ptP1, ptP2) ;
|
|
// inserisco i punti estremi e i versori tangenti nel classe di concatenamento
|
|
chainC.AddCurve( int( vEdgeInfo.size()), ptP1, vtEdgeDir, ptP2, vtEdgeDir) ;
|
|
}
|
|
|
|
// inizializzo il piano definito dalla superficie locale di contenimento
|
|
/* NB. I singoli tratti ottenuti analizzando gli Edges della superficie TriMesh sono orientati
|
|
* in base al triangolo preso di riferimento. Riconcatendando questi segmenti in una curva
|
|
* composita singola nello spazio 3d bisogna definire il suo orientamento in modo opportuno.
|
|
* --> Fruttando la superficie di contenimento ( definita quindi con normale pari a vtTool)
|
|
* è possibile proeittare le curve nel piano e definire la loro estrusione ( +/- vtTool)
|
|
e il loro orientamento ( CW/CCW) analizzando le normali dei triangoli della TriMesh */
|
|
Point3d ptSfrC ; pSfrCntLoc->GetCentroid( ptSfrC) ;
|
|
Vector3d vtN = pSfrCntLoc->GetNormVersor() ;
|
|
Plane3d plProj ;
|
|
if ( ! plProj.Set( ptSfrC, vtN))
|
|
return false ;
|
|
|
|
// recupero i contorni ( fermandomi a tutte le biforcazioni nello spazio 3d)
|
|
INTVECTOR vnId ;
|
|
while ( chainC.GetChainFromNear( ORIG, true, vnId)) {
|
|
// creo una composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return false ;
|
|
// scorro i tratti mediante gli indici
|
|
for ( int i = 0 ; i < int( vnId.size()) ; ++ i) {
|
|
int nId = abs( vnId[i]) - 1 ;
|
|
bool bInvert = ( vnId[i] < 0) ;
|
|
if ( bInvert)
|
|
swap( vEdgeInfo[nId].ptP1, vEdgeInfo[nId].ptP2) ;
|
|
// aggiungo il segmento alla composita
|
|
if ( i == 0)
|
|
pCrvCompo->AddPoint( vEdgeInfo[nId].ptP1) ;
|
|
pCrvCompo->AddLine( vEdgeInfo[nId].ptP2) ;
|
|
}
|
|
// se curva valida, la oriento ( CW/CCW)
|
|
if ( pCrvCompo->IsValid() && pCrvCompo->GetCurveCount() > 0) {
|
|
// proietto la curva sul piano definito precedentemente
|
|
PtrOwner<ICurve> pCrvProj( ProjectCurveOnPlane( *pCrvCompo, plProj)) ;
|
|
if ( ! IsNull( pCrvProj) && pCrvProj->IsValid()) {
|
|
/* La curva originaria nello spazio 3d è l'insieme dei tratti lineare definiti dagli
|
|
* Edges della superficie TriMesh che hanno superato il filtro sull'angolo di bitangenza.
|
|
* Dato che un Edge è sempre definito tra due facce della TriMesh, è possibile calcolare
|
|
* il versore medio tra le due normali e, nel riferimento di vtTool, controllare verso che
|
|
* lato punta rispetto alla curva proeittata */
|
|
// numero di segmenti che compongono la curva 3d
|
|
int nSeg = int( vnId.size()) ;
|
|
// numero di segmenti ( dispari) che analizzo per la decisione del verso di percorrenza
|
|
int nSampleEdges = min( 5, nSeg + ( IsEven( nSeg) ? 1 : 0)) ;
|
|
// contatore di posizioni MDS_RIGHT associanti al numero di segmenti scelto
|
|
int nSideRight = 0 ;
|
|
for ( int j = 0 ; j < nSampleEdges ; ++ j) {
|
|
// recupero le geometrie del segmento scelto
|
|
int nInd = ( nSeg + j * nSampleEdges) % nSeg ;
|
|
const EdgeInfo& EdgeRef = vEdgeInfo[abs( vnId[nInd])] ;
|
|
int nV1, nV2 ;
|
|
int nF1, nF2 ;
|
|
double dAng ;
|
|
Vector3d vtN1, vtN2 ;
|
|
if ( ! pStmOffs->GetEdge( EdgeRef.nE, nV1, nV2, nF1, nF2, dAng) ||
|
|
! pStmOffs->GetFacetNormal( nF1, vtN1) ||
|
|
! pStmOffs->GetFacetNormal( nF2, vtN2))
|
|
return false ;
|
|
// calcolo la media tra le normali delle due facce che lo definiscono
|
|
Vector3d vtM = SQRT1_2 * ( vtN1 + vtN2) ;
|
|
// recupero la componente ortogonale a vtTool
|
|
Vector3d vtMProj = OrthoCompo( vtM, vtN) ;
|
|
// prendo il punto medio dell'Edge scelto e lo sposto leggermente lungo vtMProj, proeitto poi
|
|
// tale punto sul piano definito dalla superficie di contenimento ( piano su cui è proiettata
|
|
// la curva 3d in esame)
|
|
// NB. vtMProj è un versore che, osservato dal piano di proiezione, punta verso l'esterno della TriMesh
|
|
Point3d ptCheck = ProjectPointOnPlane( Media( EdgeRef.ptP1, EdgeRef.ptP2) + 50 * EPS_SMALL * vtMProj, plProj) ;
|
|
// se il punto si trova alla sua destra, incremento il contatore
|
|
int nSide ;
|
|
if ( DistPointCurve( ptCheck, *pCrvProj).GetSideAtMinDistPoint( 0., vtN, nSide) &&
|
|
nSide == MDS_RIGHT)
|
|
++ nSideRight ;
|
|
}
|
|
// come estrusione alla curva 3d assegno il versore utensile
|
|
pCrvCompo->SetExtrusion( vtN) ;
|
|
// inverto la curva se i punti di campionamento sono stati trovati alla sua destra
|
|
// NB. La curva 3d deve mantenere la superficie TriMesh alla sua sinistra ( MSD_LEFT)
|
|
if ( nSideRight < int( floor( nSampleEdges / 2.)))
|
|
pCrvCompo->Invert() ;
|
|
// memorizzo la curva3d orientata
|
|
vCrvCompo.emplace_back( Release( pCrvCompo)) ;
|
|
}
|
|
}
|
|
}
|
|
#if ENABLE_PENCIL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "pencil_NOchainedCurves") ;
|
|
int nLayId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetStatus( nLayId, GDB_ST_OFF) ;
|
|
for ( auto& pCompo : vCrvCompo) {
|
|
int nCrvId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pCompo->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nCrvId, Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.)) ;
|
|
}
|
|
#endif
|
|
|
|
// controllo se posso allacciare per vicinanza le curve ( diagonale 3d come tolleranza)
|
|
return ( ChainPencilCurves( vCrvCompo, SQRT3 * dLinTol, false)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddPencil( ICAvToolSurfTm* pCAvTlStm, const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf,
|
|
const ISurfFlatRegion* pSfrCnt, const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs)
|
|
{
|
|
// recupero il tipo di Pencil
|
|
int nPencilType = PENCIL_CORNER ;
|
|
if ( GetValInNotes( m_Params.m_sUserNotes, UN_TYPE, nPencilType)) {
|
|
if ( nPencilType != PENCIL_CORNER && nPencilType != PENCIL_FAT_CORNER &&
|
|
nPencilType != PENCIL_REGION)
|
|
return false ;
|
|
}
|
|
// recupero l'Offset della superficie TriMesh ( e aggiungo una leggera tolleranza)
|
|
double dStmOffs = m_TParams.m_dDiam / 2. + 220. * EPS_SMALL ; // [in base a test, modificabile]
|
|
// recupero la tolleranza lineare per l'Offset [ 0.5, ...]
|
|
double dLinTol = max( 0.5, dStmOffs / 4.) ;
|
|
// recupero il numero di passate richieste [1, 100]
|
|
int nOffs = 1 ;
|
|
if ( GetValInNotes( m_Params.m_sUserNotes, UN_STEPNUMBER, nOffs))
|
|
nOffs = Clamp( nOffs, 1, 100) ;
|
|
// recupero l'angolo di Bitangenza
|
|
double dBiTangAng = 120. ;
|
|
if ( GetValInNotes( m_Params.m_sUserNotes, UN_BITANGANG, dBiTangAng))
|
|
dBiTangAng = Clamp( dBiTangAng, 0., 180.) ;
|
|
|
|
// recupero la superficie di Offset
|
|
PtrOwner<ISurfTriMesh> pStmOffs( CreateSurfTriMesh()) ;
|
|
if ( IsNull( pStmOffs) ||
|
|
! GetSurfTriMeshFromOffset( vSrfLoc, dStmOffs, dLinTol, pStmOffs)) {
|
|
m_pMchMgr->SetLastError( 3131, "Error in SurfFinishing : Computing Surface Offset failed") ;
|
|
return false ;
|
|
}
|
|
#if ENABLE_PENCIL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "pencil_Curves_debug") ;
|
|
int nLayId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetStatus( nLayId, GDB_ST_OFF) ;
|
|
ISurfTriMesh* pStm = CloneSurfTriMesh( pStmOffs) ;
|
|
int nSfrId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pStm->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nSfrId, Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.)) ;
|
|
#endif
|
|
|
|
// recupero le curve da seguire
|
|
ICRVCOMPOPOVECTOR vCrvCompo ;
|
|
PtrOwner<ISurfFlatRegion> pSfrCntLoc( CloneSurfFlatRegion( pSfrCnt)) ;
|
|
if ( IsNull( pSfrCntLoc) || ! pSfrCntLoc->IsValid() || ! pSfrCntLoc->ToLoc( frSurf))
|
|
return false ;
|
|
if ( ! GetCurvesFromSurfTriMeshesOffset( pStmOffs, dBiTangAng, dLinTol, nOffs, pSfrCntLoc, vCrvCompo)) {
|
|
m_pMchMgr->SetLastError( 3132, "Error in SurfFinishing : Computing Offset Edges failed") ;
|
|
return false ;
|
|
}
|
|
// se non ho curve, non faccio nulla
|
|
if ( vCrvCompo.empty()) {
|
|
m_pMchMgr->SetWarning( 3152, "Warning in SurfFinishing : No machinable path") ;
|
|
return true ;
|
|
}
|
|
#if ENABLE_PENCIL_DEBUG
|
|
nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "pencil_chainedCurves") ;
|
|
nLayId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetStatus( nLayId, GDB_ST_OFF) ;
|
|
for ( auto& pCompo : vCrvCompo) {
|
|
int nCrvId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pCompo->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nCrvId, Color( double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, double( rand()) / RAND_MAX, 1.)) ;
|
|
}
|
|
#endif
|
|
|
|
// lavoro le curve ricavate
|
|
if ( ! WorkPencilCurves( vCrvCompo, pSfrCnt, nPencilType, dStmOffs, nOffs, dDepth, dElev, dLinTol, vtTool, vSrfLoc, frSurf, pCAvTlStm, bSplitArcs)) {
|
|
m_pMchMgr->SetLastError( 3133, "Error in SurfFinishing : Projecting curves on Surface failed") ;
|
|
return false ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcOptimalZigZagCurves( const ISurfFlatRegion* pSfrLoc, const Frame3d& frSurf, const Vector3d& vtTool,
|
|
double dDepth, ICAvToolSurfTm* pCAvTlStm, VECTORPATHS& vPaths) const
|
|
{
|
|
// se la superficie non è valida, non restituisco nulla
|
|
if ( pSfrLoc == nullptr || ! pSfrLoc->IsValid())
|
|
return true ;
|
|
|
|
// mi assicuro di non uscire dalla superficie originale
|
|
PtrOwner<ISurfFlatRegion> pMySfrZigZag( CloneSurfFlatRegion( pSfrLoc)) ;
|
|
if ( IsNull( pMySfrZigZag) || ! pMySfrZigZag->IsValid())
|
|
return false ;
|
|
// imposto i lati chiusi
|
|
for ( int nC = 0 ; nC < pMySfrZigZag->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pMySfrZigZag->GetLoopCount( nC) ; ++ nL) {
|
|
for ( int nU = 0 ; nU < pMySfrZigZag->GetLoopCurveCount( nC, nL) ; ++ nU)
|
|
pMySfrZigZag->SetCurveTempProp( nC, nL, nU, 0, TEMP_PROP_CLOSE_EDGE) ;
|
|
}
|
|
}
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "ZigZag") ;
|
|
int nLayCrv = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayCrv, "Curves") ;
|
|
m_pGeomDB->SetStatus( nLayCrv, GDB_ST_OFF) ;
|
|
int nLaySfrProj = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLaySfrProj, "SfrProj") ;
|
|
m_pGeomDB->SetStatus( nLaySfrProj, GDB_ST_OFF) ;
|
|
int nSfrProjId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLaySfrProj, pMySfrZigZag->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nSfrProjId, Color( 1., 0., 0., .5)) ;
|
|
#endif
|
|
|
|
// controllo se richiesto altro tipo di lavorazione
|
|
int nSubType = POCKET_ZIGZAG ;
|
|
if ( GetValInNotes( m_Params.m_sUserNotes, UN_OPTIMALTYPE, nSubType)) {
|
|
// ammessi ZIG_ZAG, SPIRAL_IN, SPIRAL_OUT
|
|
if ( nSubType != POCKET_ZIGZAG && nSubType != POCKET_SPIRALIN && nSubType != POCKET_SPIRALOUT)
|
|
nSubType = POCKET_ZIGZAG ;
|
|
}
|
|
|
|
// per ogni Chunk della superficie a ZigZag, calcolo le curve di lavoro
|
|
ICRVCOMPOPOVECTOR vCrvCompoZigZag ;
|
|
for ( int nC = 0 ; nC < pMySfrZigZag->GetChunkCount() ; ++ nC) {
|
|
// recupero il Chunk corrente
|
|
PtrOwner<ISurfFlatRegion> pSfrChunk( pMySfrZigZag->CloneChunk( nC)) ;
|
|
if ( IsNull( pSfrChunk) || ! pMySfrZigZag->IsValid())
|
|
return false ;
|
|
// recupero la miglior direzione di orientamento per le curve a ZigZag
|
|
// --- approssimo il Loop esterno con una PolyLine
|
|
PolyLine PL ;
|
|
pSfrChunk->ApproxLoopWithLines( 0, 0, EPS_SMALL, ANG_TOL_STD_DEG, ICurve::APL_STD, PL) ;
|
|
// --- porto la PolyLine sul piano locale XY
|
|
Point3d ptC ; pSfrChunk->GetCentroid( ptC) ;
|
|
Frame3d frXY ;
|
|
if ( ! frXY.Set( ptC, pSfrChunk->GetNormVersor()))
|
|
return false ;
|
|
PL.ToLoc( frXY) ;
|
|
pSfrChunk->ToGlob( frSurf) ;
|
|
// eseguo il calcolo della lavorazione ZigZag
|
|
ICRVCOMPOPOVECTOR vpCrvs ;
|
|
if ( ! CalcPocketing( pSfrChunk, m_TParams.m_dDiam / 2., 0., m_Params.m_dSideStep, m_Params.m_dSideAngle, 5.,
|
|
nSubType, false, false, false, true, true, false, false, P_INVALID, nullptr, true, m_Params.m_dSideStep,
|
|
GetLeadInType(), m_Params.m_dLiTang, 0., GetLeadOutType(), m_Params.m_dLoTang, false, 0., 0., vpCrvs)) {
|
|
m_pMchMgr->SetLastError( 3125, "Error in SurfFinishing : CalcPocketing failed") ;
|
|
return false ;
|
|
}
|
|
// memorizzo le curve ricavate
|
|
for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i)
|
|
vCrvCompoZigZag.emplace_back( Release( vpCrvs[i])) ;
|
|
}
|
|
|
|
// porto i dati geometrici in locale alle superfici ( proeittando)
|
|
Vector3d vtAxL = vtTool ;
|
|
vtAxL.ToLoc( frSurf) ;
|
|
Vector3d vtMoveL = vtAxL ;
|
|
const double MIN_DIST = 1. ;
|
|
const double MAX_DIST = 50. ;
|
|
double dDist = Clamp( m_Params.m_dApprox, MIN_DIST, MAX_DIST) ;
|
|
|
|
// ciclo sui percorsi ricavati
|
|
double dProgCoeff = 1. / max( int( vCrvCompoZigZag.size()), 1) ;
|
|
for ( int i = 0 ; i < int( vCrvCompoZigZag.size()) ; ++ i) {
|
|
// se non valida, passo alla successiva
|
|
if ( IsNull( vCrvCompoZigZag[i]) || ! vCrvCompoZigZag[i]->IsValid())
|
|
continue ;
|
|
// correggo il percorso per non interferire con le superfici
|
|
if ( pCAvTlStm != nullptr) {
|
|
// approssimo la curva con una polilinea
|
|
PolyLine PL ;
|
|
if ( ! vCrvCompoZigZag[i]->ApproxWithLines( LIN_TOL_STD, ANG_TOL_STD_DEG, ICurve::APL_SPECIAL, PL) ||
|
|
! PL.AdjustForMaxSegmentLen( dDist))
|
|
return false ;
|
|
PL.ToLoc( frSurf) ;
|
|
// traslo della lunghezza utensile diminuita dell'affondamento
|
|
PL.Translate( vtAxL * ( m_TParams.m_dLen - dDepth)) ;
|
|
// eseguo CAv
|
|
if ( ! pCAvTlStm->TestPath( PL.GetUPointList(), vtAxL, vtMoveL, m_Params.m_dApprox, ( i + 1) * dProgCoeff))
|
|
return false ;
|
|
// contro-traslo della lunghezza utensile
|
|
PL.Translate( - vtAxL * m_TParams.m_dLen) ;
|
|
// elimino i punti allineati
|
|
PL.RemoveAlignedPoints( 0.8 * m_Params.m_dApprox) ;
|
|
// creo una curva composita a partire dalla polilinea
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo) || ! pCrvCompo->FromPolyLine( PL))
|
|
return false ;
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nCrvId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayCrv, CloneCurveComposite( pCrvCompo)) ;
|
|
m_pGeomDB->SetMaterial( nCrvId, RED) ;
|
|
#endif
|
|
|
|
// definisco un nuovo percorso
|
|
vPaths.resize( vPaths.size() + 1) ;
|
|
vPaths.back().nType = SURFFIN_SUB_ZIGZAG ;
|
|
vPaths.back().pCrvPath.Set( pCrvCompo) ;
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcOptimalZConstCurves( const ISurfFlatRegion* pSfrLoc, const SURFLOCALVECTOR& vSrfLoc,
|
|
const Frame3d& frSurf, const Vector3d& vtTool, double dAngDegSplit,
|
|
double dAngDegTol, double dDepth, ICAvToolSurfTm* pCAvTlStm,
|
|
VECTORPATHS& vPaths, ISurfFlatRegion* pSfrProj) const
|
|
{
|
|
// se la superficie non è valida, non restituisco nulla
|
|
if ( pSfrLoc == nullptr || ! pSfrLoc->IsValid())
|
|
return true ;
|
|
pSfrProj->Clear() ;
|
|
|
|
// mi assicuro di non uscire dalla superficie originale
|
|
PtrOwner<ISurfFlatRegion> pMySfrZConst( CloneSurfFlatRegion( pSfrLoc)) ;
|
|
if ( IsNull( pMySfrZConst) || ! pMySfrZConst->IsValid())
|
|
return false ;
|
|
for ( int nC = 0 ; nC < pMySfrZConst->GetChunkCount() ; ++ nC) {
|
|
for ( int nL = 0 ; nL < pMySfrZConst->GetLoopCount( nC) ; ++ nL) {
|
|
for ( int nU = 0 ; nU < pMySfrZConst->GetLoopCurveCount( nC, nL) ; ++ nU)
|
|
pMySfrZConst->SetCurveTempProp( nC, nL, nU, 0, TEMP_PROP_CLOSE_EDGE) ;
|
|
}
|
|
}
|
|
|
|
// inizializzo la classe di calcolo delle silhouette
|
|
CISURFTMPVECTOR vpStm ; vpStm.reserve( vSrfLoc.size()) ;
|
|
// scorro le superfici
|
|
for ( int i = 0 ; i < int( vSrfLoc.size()) ; ++ i) {
|
|
// recupero la superficie
|
|
const ISurf* pSurf = GetSurf( vSrfLoc[i].Get()) ;
|
|
if ( pSurf == nullptr || ! pSurf->IsValid())
|
|
continue ;
|
|
int nType = pSurf->GetType() ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pSurf) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
// se Bezier
|
|
else if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurf) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pStm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0)
|
|
vpStm.emplace_back( pStm) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
// definisco il frame della regione piana
|
|
Frame3d frSfr ;
|
|
Point3d ptC ; pSfrLoc->GetCentroid( ptC) ;
|
|
if ( ! frSfr.Set( ptC, pSfrLoc->GetNormVersor()))
|
|
return false ;
|
|
|
|
// inizializzo classe di calcolo per le curve a ZConst con utensile corrente
|
|
PtrOwner<ICAvParSilhouettesSurfTm> pCavParSilh( CreateCAvParSilhouettesSurfTm()) ;
|
|
if ( IsNull( pCavParSilh) ||
|
|
! pCavParSilh->SetData( vpStm, frSfr, SILH_SAMPLING, m_TParams.m_dSideAng, m_TParams.m_dDiam,
|
|
m_TParams.m_dCornRad, m_TParams.m_dMaxMat, GetOffsR(), dDepth))
|
|
return false ;
|
|
|
|
// recupero le curve singole definite dal bordo della Silhouette
|
|
vector<ICRVCOMPOPOVECTOR> vvCrvCompo ;
|
|
if ( ! CalcZConstSilCrv( pCavParSilh, vSrfLoc, frSurf, pMySfrZConst, vtTool, dDepth, vvCrvCompo)) {
|
|
m_pMchMgr->SetLastError( 3126, "Error in SurfFinishing : Computing ZConst Curves failed") ;
|
|
return false ;
|
|
}
|
|
// se non ho ricato curve, non faccio nulla
|
|
if ( vvCrvCompo.empty())
|
|
return true ;
|
|
|
|
// definisco i parametri e le geometrie locali
|
|
// --- versore direzione utensile e versore direzione movimento
|
|
Vector3d vtAxL = vtTool ;
|
|
vtAxL.ToLoc( frSurf) ;
|
|
Vector3d vtMoveL = vtAxL ;
|
|
// --- tolleranza di campionamento per punti della PolyLine
|
|
const double MIN_DIST = 1. ;
|
|
const double MAX_DIST = 50. ;
|
|
double dDist = Clamp( m_Params.m_dApprox, MIN_DIST, MAX_DIST) ;
|
|
// --- angolo di Split per conservazione o meno dei tratti di PolyLine
|
|
double dCosLimit = cos( dAngDegSplit * DEGTORAD + EPS_ANG_SMALL) ;
|
|
double dCosUpperBound = cos( ( dAngDegSplit - dAngDegTol) * DEGTORAD + EPS_ANG_SMALL) ;
|
|
// --- classificazione punti e PolyLine corrispondenti
|
|
enum { VALID = 0, AMBIGUOUS = 1, DISCARD = 2 } ;
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "Surf") ;
|
|
int nLayStm = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayStm, "Surf") ;
|
|
for ( auto& pStm : vpStm) {
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayStm, CloneSurfTriMesh( pStm)) ;
|
|
m_pGeomDB->SetMaterial( a, YELLOW) ;
|
|
}
|
|
nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "ZConst") ;
|
|
int nLayOrigCrv = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayOrigCrv, "Orig_curves") ;
|
|
m_pGeomDB->SetStatus( nLayOrigCrv, GDB_ST_OFF) ;
|
|
int nLayPt = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayPt, "Sample_pts") ;
|
|
m_pGeomDB->SetStatus( nLayPt, GDB_ST_OFF) ;
|
|
int nLayNorm = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayNorm, "Normals") ;
|
|
m_pGeomDB->SetStatus( nLayNorm, GDB_ST_OFF) ;
|
|
int nLayCrv = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayCrv, "Curves") ;
|
|
m_pGeomDB->SetStatus( nLayCrv, GDB_ST_OFF) ;
|
|
int nLaySfrProj = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLaySfrProj, "SfrProj") ;
|
|
m_pGeomDB->SetStatus( nLaySfrProj, GDB_ST_OFF) ;
|
|
#endif
|
|
|
|
// scorro i piani di ZConst ricavati...
|
|
for ( int i = 0 ; i < int( vvCrvCompo.size()) ; ++ i) {
|
|
// Dalle curve si ricavano le PolyLine corrispondeti e vengono suddivise in 3 categorie :
|
|
// - PolyLine valide : definite da punti di campionamento consecutivi dove esiste una normale di
|
|
// di collisione con angolo rispetto a vtTool > dSplitAngDeg
|
|
// - PolyLine ambigue : definite da punti di campionamento consecutivi dove esiste una normale di
|
|
// di collisione con angolo rispetto a vtTool > dSplitAngDeg con tolleranza
|
|
// - PolyLine invalide : definite da punti di campionamento consecutivi dove non esiste una normale
|
|
// di collisone con angolo rispetto a vtTool > dSplitAngDeg con tolleranza
|
|
vector<pair<int, PolyLine>> vTypePL ; // vettore PolyLine di classificazione
|
|
POLYLINEVECTOR vPL ; // PolyLine risultanti
|
|
bool bStart = true ;
|
|
// la distanza dalla Sfr è memorizzata nel primo TempParam [*]
|
|
double dSfrDist = 0. ;
|
|
|
|
// per il piano corrente scorro le curve di Silhouette ricavate...
|
|
for ( int j = 0 ; j < int( vvCrvCompo[i].size()) ; ++ j) {
|
|
// se curva non valida, passo alla successiva
|
|
if ( IsNull( vvCrvCompo[i][j]) || ! vvCrvCompo[i][j]->IsValid())
|
|
continue ;
|
|
dSfrDist = vvCrvCompo[i][j]->GetTempParam( 0) ; // [*]
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nCrvOrigId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayOrigCrv, vvCrvCompo[i][j]->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nCrvOrigId, ORANGE) ;
|
|
#endif
|
|
|
|
// recupero la PolyLine della curva corrente e la campiono
|
|
PolyLine PL ;
|
|
vvCrvCompo[i][j]->ApproxWithLines( EPS_SMALL, ANG_TOL_STD_DEG, ICurve::APL_STD, PL) ;
|
|
if ( ! PL.AdjustForMaxSegmentLen( dDist))
|
|
return false ;
|
|
|
|
// scorro i punti della PolyLine e li calssifico
|
|
for ( POINTU& ptU : PL.GetUPointList()) {
|
|
// La curva di Silhouette, una volta approssimata, può presentare alcuni punti quel poco
|
|
// che basta più lontani dalla superficie per non ricavare alcuna collisione.
|
|
// NB. le curve ricavate sono approssimate, mergiate e leggermente smussate.
|
|
// --> In questo caso sposto leggermente il punto verso la superficie
|
|
// NB. Le curve di Silhoette per definizione sono orientate lasciando le vStm alla loro destra
|
|
int nPointType = DISCARD ;
|
|
double dPar ;
|
|
Point3d ptShift ;
|
|
Vector3d vtIn ;
|
|
VCT3DVECTOR vVtN ;
|
|
if ( vvCrvCompo[i][j]->GetParamAtPoint( ptU.first, dPar, 10 * EPS_SMALL) &&
|
|
vvCrvCompo[i][j]->GetPointD1D2( dPar, ICurve::FROM_MINUS, ptShift, &vtIn)) {
|
|
ptShift.Translate( - vtAxL * m_TParams.m_dLen) ; // per ricavare la colisione
|
|
vtIn.Normalize() ;
|
|
vtIn.Rotate( vtAxL, ! m_Params.m_bInvert ? ANG_RIGHT : - ANG_RIGHT) ;
|
|
const double MAXSHIFT = SILH_SAMPLING ;
|
|
const int SAMPLETOL = 10 ;
|
|
double dShift = MAXSHIFT / ( 1. * SAMPLETOL) ;
|
|
for ( int i = 1 ; i < SAMPLETOL && vVtN.empty() ; ++ i) {
|
|
ptShift.Translate( vtIn * ( i * dShift)) ; // leggero spostamento del punto
|
|
double dToTDist = 0. ;
|
|
// calcolo la collisione
|
|
if ( ! pCAvTlStm->TestPositionAdv( ptShift, vtAxL, vtMoveL, dToTDist, vVtN))
|
|
return false ;
|
|
// classificazione del punto
|
|
if ( ! vVtN.empty()) {
|
|
for ( Vector3d& vtN : vVtN) {
|
|
if ( abs( vtN * vtAxL) < dCosLimit) {
|
|
nPointType = VALID ;
|
|
break ;
|
|
}
|
|
else if ( abs( vtN * vtAxL) < dCosUpperBound)
|
|
nPointType = AMBIGUOUS ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
PtrOwner<IGeoPoint3d> pt( CreateGeoPoint3d()) ;
|
|
pt->Set( ptU.first) ;
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayPt, Release( pt)) ;
|
|
m_pGeomDB->SetMaterial( a, nPointType == VALID ? GREEN :
|
|
nPointType == AMBIGUOUS ? LIME : BLACK) ;
|
|
for ( Vector3d& vtN : vVtN) {
|
|
PtrOwner<IGeoVector3d> vt( CreateGeoVector3d()) ;
|
|
vt->Set( vtN) ;
|
|
vt->Translate( ptU.first - ORIG) ;
|
|
int _vN = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayNorm, vt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( _vN, Color( abs( vt->GetVector().x), abs( vt->GetVector().y), abs( vt->GetVector().z))) ;
|
|
}
|
|
#endif
|
|
|
|
// inserisco il punto nel tipo di PolyLine corrispondente
|
|
if ( bStart) {
|
|
vTypePL.emplace_back( make_pair( nPointType, PolyLine())) ;
|
|
vTypePL.back().second.AddUPoint( 0., ptU.first) ;
|
|
bStart = false ;
|
|
}
|
|
else {
|
|
if ( vTypePL.back().first == nPointType)
|
|
vTypePL.back().second.AddUPoint( 0., ptU.first) ;
|
|
else {
|
|
vTypePL.emplace_back( make_pair( nPointType, PolyLine())) ;
|
|
vTypePL.back().second.AddUPoint( 0., ptU.first) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
// costruisco le PolyLine definitive
|
|
bool bFirst = true ;
|
|
int nPL = int( vTypePL.size()) ;
|
|
for ( int nInd = 0 ; nInd < nPL ; ++ nInd) {
|
|
// se tratto valido
|
|
if ( vTypePL[nInd].first == VALID) {
|
|
// indice tratto precedente e successivo
|
|
int nPrevInd = ( nPL + nInd - 1) % nPL ;
|
|
int nAfterInd = ( nPL + nInd + 1) % nPL ;
|
|
// nuova PolyLine da definire
|
|
if ( bFirst) {
|
|
vPL.emplace_back( PolyLine()) ;
|
|
bFirst = false ;
|
|
}
|
|
// se tratto precedente ambiguo, lo aggiungo al tratto corrente e lo rendo invalido
|
|
if ( nPL > 1 &&
|
|
( vTypePL[nPrevInd].first == AMBIGUOUS || vTypePL[nPrevInd].first == VALID)) {
|
|
// controllo che i punti siano sufficientemente vicini ( sqrt(2) * dDist))
|
|
Point3d ptBack, ptCurr ;
|
|
vTypePL[nPrevInd].second.GetLastPoint( ptBack) ;
|
|
vTypePL[nInd].second.GetFirstPoint( ptCurr) ;
|
|
if ( AreSamePointEpsilon( ptBack, ptCurr, 2 * dDist * dDist)) {
|
|
for ( auto& ptU : vTypePL[nPrevInd].second.GetUPointList())
|
|
vPL.back().AddUPoint( 0., ptU.first) ;
|
|
vTypePL[nPrevInd].first = DISCARD ;
|
|
}
|
|
}
|
|
// aggiungo il tratto corrente e lo rendo invalido
|
|
for ( auto& ptU : vTypePL[nInd].second.GetUPointList())
|
|
vPL.back().AddUPoint( 0., ptU.first) ;
|
|
vTypePL[nInd].first = DISCARD ;
|
|
// se tratto successivo ambiguo, lo aggiungo al tratto corrente e lo rendo invalido
|
|
if ( vTypePL[nAfterInd].first == AMBIGUOUS) {
|
|
// controllo che i punti siano sufficientemente vicini ( sqrt(2) * dDist))
|
|
Point3d ptForward, ptCurr ;
|
|
vTypePL[nAfterInd].second.GetFirstPoint( ptForward) ;
|
|
vTypePL[nInd].second.GetLastPoint( ptCurr) ;
|
|
if ( AreSamePointEpsilon( ptForward, ptCurr, 2 * dDist * dDist)) {
|
|
for ( auto& ptU : vTypePL[nAfterInd].second.GetUPointList())
|
|
vPL.back().AddUPoint( 0., ptU.first) ;
|
|
vTypePL[nAfterInd].first = DISCARD ;
|
|
++ nInd ;
|
|
}
|
|
}
|
|
}
|
|
// se tratto invalido, allora dovrò definire una nuova PolyLine
|
|
else if ( vTypePL[nInd].first == DISCARD)
|
|
bFirst = true ;
|
|
}
|
|
|
|
}
|
|
|
|
// dalle PolyLine recupero le curve
|
|
vvCrvCompo[i].clear() ;
|
|
for ( PolyLine& PL : vPL) {
|
|
// se PolyLine troppo corta, non la memorizzo ( < 1/4 circonferenza utensile)
|
|
double dLen = 0. ;
|
|
PL.GetLength( dLen) ;
|
|
if ( dLen < ( PIGRECO / 2.) * ( m_TParams.m_dDiam / 2.))
|
|
continue ;
|
|
// definisco la curva e la abbellisco
|
|
PtrOwner<ICurveComposite> pNewCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pNewCrvCompo) || ! pNewCrvCompo->FromPolyLine( PL))
|
|
continue ;
|
|
SimplifyCurve( pNewCrvCompo, frSfr) ;
|
|
vvCrvCompo[i].emplace_back( Release( pNewCrvCompo)) ;
|
|
// memorizzo come primo TempParam la distanza della superficie ( per coerenza)
|
|
vvCrvCompo[i].back()->SetTempParam( dSfrDist, 0) ;
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayCrv, vvCrvCompo[i].back()->Clone()) ;
|
|
m_pGeomDB->SetMaterial( a, GREEN) ;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
// NB. per determinare la regione da lavavorare a ZigZag, devo prima determinare la regione
|
|
// definita dalle curve ZConst.
|
|
// --- determino il piano di proiezione dalla regione originale
|
|
Plane3d plProj ;
|
|
if ( ! plProj.Set( ptC, vtAxL))
|
|
return false ;
|
|
// --- per ogni curva valida, definisco una regione piana Fat sul piano calcolato
|
|
for ( auto& vCrvCompo : vvCrvCompo) {
|
|
for ( auto& pCrvCompo : vCrvCompo) {
|
|
// se curva non valida, passo alla successiva
|
|
if ( IsNull( pCrvCompo) || ! pCrvCompo->IsValid())
|
|
continue ;
|
|
// proeitto la curva sul piano
|
|
PtrOwner<ICurve> pCrvProj( ProjectCurveOnPlane( *pCrvCompo, plProj)) ;
|
|
if ( IsNull( pCrvProj) || ! pCrvProj->IsValid())
|
|
continue ;
|
|
// determino la sua FatRegion
|
|
pCrvProj->SetExtrusion( vtAxL) ; // per coprire eventuali regioni fini
|
|
PtrOwner<ISurfFlatRegion> pSfrFat( GetSurfFlatRegionFromFatCurve( pCrvProj->Clone(), m_Params.m_dSideStep / dCosLimit, false, false)) ;
|
|
if ( IsNull( pSfrFat) || ! pSfrFat->IsValid())
|
|
continue ;
|
|
if ( AreOppositeVectorApprox( pSfrFat->GetNormVersor(), vtAxL))
|
|
pSfrFat->Invert() ;
|
|
// aggiungo questa regione a quella complessiva
|
|
if ( pSfrProj->IsValid() && pSfrProj->GetChunkCount() > 0)
|
|
pSfrProj->Add( *pSfrFat) ;
|
|
else
|
|
pSfrProj->CopyFrom( pSfrFat) ;
|
|
}
|
|
}
|
|
#if ENABLE_OPTIMAL_DEBUG
|
|
int nSfrId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLaySfrProj, pSfrProj->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nSfrId, Color( 0., 1., 0., .5)) ;
|
|
#endif
|
|
|
|
// collego tra loro le curve trovate definendo quindi un percorso
|
|
ICRVCOMPOPOVECTOR vCrv ;
|
|
if ( ! CreateZConstPaths( pCAvTlStm, frSurf, vvCrvCompo, vtTool, pMySfrZConst, dDepth, vCrv)) {
|
|
m_pMchMgr->SetLastError( 3127, "Error in SurfFinishing : Computing ZConst Paths failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// restituisco i percorsi trovati
|
|
for ( int i = 0 ; i < int( vCrv.size()) ; ++ i) {
|
|
vPaths.resize( vPaths.size() + 1) ;
|
|
vPaths.back().pCrvPath.Set( Release( vCrv[i])) ;
|
|
vPaths.back().nType = SURFFIN_SUB_Z_CONST ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddOptimal( ICAvToolSurfTm* pCAvTlStm, const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf,
|
|
const ISurfFlatRegion* pSfrCntZigZag, const ISurfFlatRegion* pSfrCntZConst,
|
|
const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs)
|
|
{
|
|
// vettore dei percorsi da calcolare
|
|
VECTORPATHS vPaths ;
|
|
|
|
// se entrambe le regioni non sono valide, non faccio nulla
|
|
if ( ( pSfrCntZigZag == nullptr || ! pSfrCntZigZag->IsValid()) &&
|
|
( pSfrCntZConst == nullptr || ! pSfrCntZConst->IsValid()))
|
|
return false ;
|
|
|
|
// recupero l'angolo di Split e la rispettiva tolleranza
|
|
double dAngDegSplit = 45 ;
|
|
GetValInNotes( m_Params.m_sUserNotes, UN_SPLITANGLE, dAngDegSplit) ;
|
|
double dAngDegTol = 5 ;
|
|
GetValInNotes( m_Params.m_sUserNotes, UN_ANGLETOL, dAngDegTol) ;
|
|
|
|
// inizializzo l'area di lavoro determinata dalle curve ZigZag
|
|
PtrOwner<ISurfFlatRegion> pSfrZigZagProjLoc ;
|
|
if ( pSfrCntZigZag != nullptr && pSfrCntZigZag->IsValid()) {
|
|
if ( ! pSfrZigZagProjLoc.Set( CloneSurfFlatRegion( pSfrCntZigZag)) ||
|
|
! pSfrCntZigZag->IsValid())
|
|
return false ;
|
|
pSfrZigZagProjLoc->ToLoc( frSurf) ;
|
|
}
|
|
else {
|
|
if ( ! pSfrZigZagProjLoc.Set( CreateSurfFlatRegion()))
|
|
return false ;
|
|
}
|
|
|
|
// se ho una superficie di contorno per ZConst valida
|
|
if ( pSfrCntZConst != nullptr && pSfrCntZConst->IsValid()) {
|
|
|
|
// definizione regione piana di lavoro per curve ZConst
|
|
PtrOwner<ISurfFlatRegion> pSfrZConstLoc( CloneSurfFlatRegion( pSfrCntZConst)) ;
|
|
if ( IsNull( pSfrZConstLoc) || ! pSfrZConstLoc->IsValid() || ! pSfrZConstLoc->ToLoc( frSurf))
|
|
return false ;
|
|
|
|
// recupero le curve dalla regione ZConst
|
|
PtrOwner<ISurfFlatRegion> pSfrZConstProj( CreateSurfFlatRegion()) ;
|
|
if ( IsNull( pSfrZConstProj) ||
|
|
! CalcOptimalZConstCurves( pSfrZConstLoc, vSrfLoc, frSurf, vtTool, dAngDegSplit, dAngDegTol, dDepth, pCAvTlStm, vPaths, pSfrZConstProj)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
|
|
// recupero le curve dalla regione Spiral
|
|
if ( pSfrZConstProj->IsValid() && pSfrZConstProj->GetChunkCount() > 0 &&
|
|
pSfrZigZagProjLoc->IsValid()) {
|
|
PtrOwner<ISurfFlatRegion> pSfrZigZagProjLocClone( CloneSurfFlatRegion( pSfrZigZagProjLoc)) ;
|
|
if ( IsNull( pSfrZigZagProjLocClone) || ! pSfrZigZagProjLocClone->IsValid())
|
|
return false ;
|
|
// alla superficie ZigZag tolgo la regione ZConst
|
|
pSfrZigZagProjLoc->Subtract( *pSfrZConstProj) ;
|
|
// nei pressi dei tratti in comune lo ZigZag deve lavorare a SideStep
|
|
// NB. pSfrZConstProj è ingrandita di SideStep
|
|
pSfrZigZagProjLoc->Offset( m_Params.m_dSideStep + m_TParams.m_dDiam / 2., ICurve::OFF_FILLET) ;
|
|
// la supercicie ZigZag deve comunque essere sempre contenuta in quella definita in originale
|
|
pSfrZigZagProjLoc->Intersect( *pSfrZigZagProjLocClone) ;
|
|
}
|
|
}
|
|
|
|
// se ho una superficie di contorno per ZigZag valida
|
|
if ( ! IsNull( pSfrZigZagProjLoc) && pSfrZigZagProjLoc->IsValid()) {
|
|
if ( ! CalcOptimalZigZagCurves( pSfrZigZagProjLoc, frSurf, vtTool, dDepth, pCAvTlStm, vPaths)) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
// se non ho percorsi, non faccio nulla
|
|
if ( vPaths.empty())
|
|
return true ;
|
|
|
|
// porto tutte le curve in globale
|
|
for ( auto& path : vPaths) {
|
|
if ( IsNull( path.pCrvPath) || ! path.pCrvPath->IsValid())
|
|
continue ;
|
|
path.pCrvPath->ToGlob( frSurf) ;
|
|
}
|
|
|
|
// ordino i percorsi ricavati
|
|
if ( ! OrderOptimalPathsByZLoc( pSfrCntZConst, pSfrCntZigZag, vPaths))
|
|
return false ;
|
|
|
|
#if ENABLE_OPTIMAL_FINAL_CURVES_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "Curves") ;
|
|
int nSpiralLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nSpiralLay, "Spiral") ;
|
|
int nZConstLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nZConstLay, "ZConst") ;
|
|
for ( int i = 0 ; i < int( vPaths.size()) ; ++ i) {
|
|
if ( ! IsNull( vPaths[i].pCrvPath) && vPaths[i].pCrvPath->IsValid()) {
|
|
if ( vPaths[i].nType == SURFFIN_SUB_Z_CONST) {
|
|
int nPathId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nZConstLay, CloneCurveComposite( vPaths[i].pCrvPath)) ;
|
|
m_pGeomDB->SetMaterial( nPathId, GREEN) ;
|
|
}
|
|
else if ( vPaths[i].nType == SURFFIN_SUB_ZIGZAG) {
|
|
int nPathId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nSpiralLay, CloneCurveComposite( vPaths[i].pCrvPath)) ;
|
|
m_pGeomDB->SetMaterial( nPathId, RED) ;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// aggiungo i percorsi di finitura calcolati
|
|
ICRVCOMPOPOVECTOR vCrvCompo ; vCrvCompo.resize( vPaths.size()) ;
|
|
for ( int i = 0 ; i < int( vPaths.size()) ; ++ i)
|
|
vCrvCompo[i].Set( Release( vPaths[i].pCrvPath)) ;
|
|
if ( ! AddFinishing( ( pSfrCntZConst == nullptr || ! pSfrCntZConst->IsValid()) ? pSfrCntZigZag : pSfrCntZConst,
|
|
pCAvTlStm, frSurf, vCrvCompo, vtTool, dElev, dDepth, bSplitArcs))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddProjection( ICAvToolSurfTm* pCAvTlStm, const SURFLOCALVECTOR& vSrfLoc, const Frame3d& frSurf,
|
|
const ICurveComposite* pCrvCompo, const Vector3d& vtTool, double dDepth, double dElev, bool bSplitArcs)
|
|
{
|
|
// controllo che la curva sia valida
|
|
if ( pCrvCompo == nullptr || ! pCrvCompo->IsValid())
|
|
return false ;
|
|
|
|
// definisco un sistema di riferimento locale alla curva
|
|
Point3d ptStart ; pCrvCompo->GetStartPoint( ptStart) ;
|
|
Frame3d frLoc ;
|
|
if ( ! frLoc.Set( ptStart, vtTool))
|
|
return false ;
|
|
// definisco il frame inverso per il calcolo del Box3d
|
|
Frame3d frLocInv = frLoc ;
|
|
if ( ! frLocInv.Invert())
|
|
return false ;
|
|
|
|
// definisco variabili globali
|
|
BBox3d BBox3Loc ; // box totale delle superici rispetto a frLoc
|
|
ISURFTMPOVECTOR vpStm ; // superfici TriMesh selezionate in globale
|
|
ICRVCOMPOPOVECTOR vCrvToProj ; // vettore delle curve da proiettare sulla superficie
|
|
|
|
// scorro il vettore di superfici selezionate
|
|
for ( int i = 0 ; i < int( vSrfLoc.size()) ; ++ i) {
|
|
// recupero la superficie ( TriMesh o Bezier)
|
|
const ISurf* pSurf = GetSurf( vSrfLoc[i].Get()) ;
|
|
if ( pSurf == nullptr || ! pSurf->IsValid())
|
|
continue ;
|
|
int nType = pSurf->GetType() ;
|
|
PtrOwner<ISurfTriMesh> pSurfTm ;
|
|
// se TriMesh
|
|
if ( nType == SRF_TRIMESH) {
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pSurf) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) {
|
|
if ( ! pSurfTm.Set( CloneSurfTriMesh( pStm)))
|
|
continue ;
|
|
}
|
|
}
|
|
// se Bezier
|
|
else if ( nType == SRF_BEZIER) {
|
|
const ISurfBezier* pSBz = GetSurfBezier( pSurf) ;
|
|
if ( pSBz != nullptr && pSBz->IsValid()) {
|
|
double dOldTol = GetSurfBezierAuxSurfRefinedTol() ;
|
|
SetSurfBezierAuxSurfRefinedTol( 5. * EPS_SMALL) ;
|
|
const ISurfTriMesh* pStm = pSBz->GetAuxSurfRefined() ;
|
|
SetSurfBezierAuxSurfRefinedTol( dOldTol) ;
|
|
if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) {
|
|
if ( ! pSurfTm.Set( CloneSurfTriMesh( pStm)))
|
|
continue ;
|
|
}
|
|
}
|
|
}
|
|
// porto la supercicie nel riferimento globale come TriMesh
|
|
if ( IsNull( pSurfTm) || ! pSurfTm->IsValid() || ! pSurfTm->ToGlob( frSurf))
|
|
return false ;
|
|
// calcolo il box rispetto a frLoc e sommo i contributi
|
|
BBox3d BBox ;
|
|
if ( ! pSurfTm->GetBBox( frLocInv, BBox))
|
|
return false ;
|
|
BBox3Loc.Add( BBox) ;
|
|
// memorizzo la superficie nel vettore
|
|
vpStm.emplace_back( Release( pSurfTm)) ;
|
|
}
|
|
|
|
// recupero flag per saltare parti a massimo affondamento
|
|
bool bSkipMaxDown = true ;
|
|
GetValInNotes( m_Params.m_sUserNotes, UN_SKIPMAXDOWN, bSkipMaxDown) ;
|
|
if ( bSkipMaxDown) {
|
|
// definisco i dati di calcolo della Silhouette
|
|
const double SILH_TOL = 1.0 ;
|
|
CISURFTMPVECTOR vSurf ; vSurf.reserve( vpStm.size()) ;
|
|
for ( int i = 0; i < int( vpStm.size()) ; ++ i)
|
|
vSurf.emplace_back( vpStm[i]) ;
|
|
PtrOwner<ICAvParSilhouettesSurfTm> pCavParSilh( CreateCAvParSilhouettesSurfTm()) ;
|
|
if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vSurf, frLoc, SILH_TOL))
|
|
return false ;
|
|
// recupero il vettore di PolyLine della silhouette
|
|
POLYLINEVECTOR vPL ;
|
|
if ( ! pCavParSilh->GetSilhouette( BBox3Loc.GetMin().z , vPL))
|
|
return false ;
|
|
// creo la regione piana dalle PolyLine ricavate dalla Silhouette
|
|
SurfFlatRegionByContours SfrMaker ;
|
|
for ( auto& PL : vPL) {
|
|
// recupero la curva dalla silhouette
|
|
PtrOwner<ICurveComposite> pSilCrv( CreateCurveComposite()) ;
|
|
if ( IsNull( pSilCrv))
|
|
return false ;
|
|
pSilCrv->FromPolyLine( PL) ;
|
|
// approssimo con archi
|
|
const double SILH_ARC_TOL = 0.1 * SILH_TOL ;
|
|
const double SILH_ARC_FEA_MAX = 100. ;
|
|
PolyArc PA ;
|
|
if ( pSilCrv->ApproxWithArcsEx( SILH_ARC_TOL, ANG_TOL_STD_DEG, SILH_ARC_FEA_MAX, PA)) {
|
|
PtrOwner<ICurveComposite> pTempCrv( CreateCurveComposite()) ;
|
|
if ( ! IsNull( pTempCrv) &&
|
|
pTempCrv->FromPolyArc( PA) &&
|
|
pTempCrv->RemoveSmallDefects( SILH_ARC_TOL / 2, ANG_TOL_STD_DEG) &&
|
|
pTempCrv->MergeCurves( SILH_ARC_TOL / 2, ANG_TOL_STD_DEG))
|
|
pSilCrv.Set( pTempCrv) ;
|
|
}
|
|
// aggiungo per regione
|
|
if ( ! SfrMaker.AddCurve( Release( pSilCrv))) {
|
|
m_pMchMgr->SetLastError( 3124, "Error in SurfFinishing : region not computable") ;
|
|
return false ;
|
|
}
|
|
}
|
|
// definisco la regione piana
|
|
PtrOwner<ISurfFlatRegion> pSfrSil( SfrMaker.GetSurf()) ;
|
|
if ( ! IsNull( pSfrSil) && pSfrSil->IsValid()) {
|
|
// Offset alla Silhouette
|
|
double dPockRadOffs = m_TParams.m_dDiam - m_Params.m_dSideStep - m_Params.m_dOverlap ;
|
|
pSfrSil->Offset( dPockRadOffs, ICurve::OFF_CHAMFER) ;
|
|
// porto la curva e la Silhouette nel frame locale per classificazione ( alla stezza zLoc)
|
|
PtrOwner<ICurveComposite> pCrvCompoCL( CloneCurveComposite( pCrvCompo)) ;
|
|
if ( IsNull( pCrvCompoCL) || ! pCrvCompoCL->IsValid())
|
|
return false ;
|
|
pCrvCompoCL->Translate( BBox3Loc.GetMin().z * vtTool) ;
|
|
pCrvCompoCL->ToLoc( frLoc) ;
|
|
pSfrSil->ToLoc( frLoc) ;
|
|
// classifico
|
|
CRVCVECTOR ccClass ;
|
|
if ( pSfrSil->GetCurveClassification( *pCrvCompoCL, EPS_SMALL, ccClass)) {
|
|
for ( int i = 0 ; i < int( ccClass.size()) ; ++ i) {
|
|
// se tratto di curva interno
|
|
if ( ccClass[i].nClass != CRVC_OUT) {
|
|
// recupero la curva
|
|
PtrOwner<ICurve> pCrvInt( pCrvCompo->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE)) ;
|
|
if ( ! IsNull( pCrvInt) && pCrvInt->IsValid())
|
|
vCrvToProj.emplace_back( ConvertCurveToComposite( Release( pCrvInt))) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
vCrvToProj.emplace_back( CloneCurveComposite( pCrvCompo)) ;
|
|
|
|
|
|
// correggo i percorsi mediante collisione con le supercici
|
|
if ( ! CorrectPathByCollision( pCAvTlStm, frSurf, vtTool, dDepth, vCrvToProj)) {
|
|
m_pMchMgr->SetLastError( 3134, "Error in SurfFinishing : Projecting Path failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// aggiungo il percorso di finitura calcolati
|
|
for ( int i = 0 ; i < int( vCrvToProj.size()) ; ++ i) {
|
|
ICRVCOMPOPOVECTOR vCrvSingle ;
|
|
vCrvSingle.emplace_back( Release( vCrvToProj[i])) ;
|
|
if ( ! AddFinishing( nullptr, pCAvTlStm, frSurf, vCrvSingle, vtTool, dElev, dDepth, bSplitArcs))
|
|
return false ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr)
|
|
{
|
|
SetFlag( 1) ;
|
|
// se sopra attacco c'è spazio per sicurezza o approccio
|
|
double dSafeDist = dSafeZ ;
|
|
if ( dElev + max( dSafeDist, dAppr) > 10 * EPS_SMALL) {
|
|
// se distanza di sicurezza minore di distanza di inizio
|
|
if ( dSafeDist < dAppr + 10 * EPS_SMALL) {
|
|
// 1 -> punto sopra inizio
|
|
Point3d ptP1 = ptP + vtTool * ( dElev + dAppr) ;
|
|
if ( AddRapidStart( ptP1) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
else {
|
|
// 1a -> punto sopra inizio
|
|
Point3d ptP1b = ptP + vtTool * ( dElev + dAppr) ;
|
|
Point3d ptP1a = ptP1b + vtTool * ( dSafeDist - dAppr) ;
|
|
if ( ( AddRapidStart( ptP1a) == GDB_ID_NULL))
|
|
return false ;
|
|
// 1b -> punto appena sopra inizio
|
|
if ( ( dElev + dAppr) > EPS_SMALL) {
|
|
SetFlag( 0) ;
|
|
if ( AddRapidMove( ptP1b) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
}
|
|
// affondo al punto iniziale
|
|
SetFlag( 0) ;
|
|
SetFeed( GetTipFeed()) ;
|
|
if ( AddLinearMove( ptP) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
else {
|
|
// affondo diretto al punto iniziale
|
|
SetFlag( 0) ;
|
|
if ( AddRapidStart( ptP) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddLinkApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr)
|
|
{
|
|
// se sopra attacco c'è spazio per approccio
|
|
if ( ( dElev + dAppr) > 10 * EPS_SMALL) {
|
|
// 1b -> punto appena sopra inizio
|
|
Point3d ptP1b = ptP + vtTool * ( dElev + dAppr) ;
|
|
if ( ( dElev + dAppr) > EPS_SMALL) {
|
|
SetFlag( 0) ;
|
|
if ( AddRapidMove( ptP1b) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// affondo al punto iniziale
|
|
SetFlag( 0) ;
|
|
SetFeed( GetTipFeed()) ;
|
|
if ( AddLinearMove( ptP) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
else {
|
|
// affondo diretto al punto iniziale
|
|
SetFlag( 0) ;
|
|
if ( AddRapidMove( ptP) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddLinkRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr)
|
|
{
|
|
// se sopra uscita c'è spazio per approccio
|
|
if ( ( dElev + dAppr) > 10 * EPS_SMALL) {
|
|
// 4 -> movimento di risalita sopra il punto finale
|
|
SetFeed( GetEndFeed()) ;
|
|
Point3d ptP4 = ptP + vtTool * ( dElev + dAppr) ;
|
|
if ( AddLinearMove( ptP4) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr)
|
|
{
|
|
// se sopra uscita c'è spazio per sicurezza o approccio
|
|
double dSafeDist = dSafeZ ;
|
|
if ( dElev + max( dSafeDist, dAppr) > 10 * EPS_SMALL) {
|
|
if ( dSafeDist < dAppr + 10 * EPS_SMALL) {
|
|
// 4 -> movimento di risalita sopra il punto finale
|
|
SetFeed( GetEndFeed()) ;
|
|
Point3d ptP4 = ptP + vtTool * ( dElev + dAppr) ;
|
|
if ( AddLinearMove( ptP4) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
else {
|
|
// 4a -> movimento di risalita appena sopra il punto finale
|
|
Point3d ptP4a = ptP + vtTool * ( dElev + dAppr) ;
|
|
if ( dElev + dAppr > EPS_SMALL) {
|
|
SetFeed( GetEndFeed()) ;
|
|
if ( AddLinearMove( ptP4a) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// 4b -> movimento di risalita sopra il punto finale
|
|
Point3d ptP4b = ptP4a + vtTool * ( dSafeDist - dAppr) ;
|
|
if ( AddRapidMove( ptP4b) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
SurfFinishing::GetLeadInType( void) const
|
|
{
|
|
if ( abs( m_Params.m_dLiTang) < min( 0.1 * m_TParams.m_dDiam, 0.1) &&
|
|
abs( m_Params.m_dLiPerp) < min( 0.1 * m_TParams.m_dDiam, 0.1))
|
|
return SURFFIN_LI_NONE ;
|
|
return m_Params.m_nLeadInType ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtTool,
|
|
const Vector3d& vtNorm, Point3d& ptP1) const
|
|
{
|
|
// Assegno tipo e parametri
|
|
int nType = GetLeadInType() ;
|
|
double dTang = m_Params.m_dLiTang ;
|
|
double dPerp = m_Params.m_dLiPerp ;
|
|
// Calcolo punto iniziale
|
|
switch ( nType) {
|
|
case SURFFIN_LI_NONE :
|
|
ptP1 = ptStart ;
|
|
return true ;
|
|
case SURFFIN_LI_LINEAR :
|
|
case SURFFIN_LI_TANGENT :
|
|
{
|
|
Vector3d vtPerp = vtStart ;
|
|
Vector3d vtRot = OrthoCompo( vtTool, vtStart) ;
|
|
vtPerp.Rotate( vtRot, 0, -1) ;
|
|
if ( vtPerp * vtNorm < -EPS_ZERO)
|
|
vtPerp.Invert() ;
|
|
ptP1 = ptStart - vtStart * dTang + vtPerp * dPerp ;
|
|
}
|
|
return true ;
|
|
default :
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtTool, bool bSplitArcs)
|
|
{
|
|
// Se inizio e fine coincidono, non devo fare alcunchè
|
|
if ( AreSamePointApprox( ptP1, ptStart))
|
|
return true ;
|
|
// Assegno il tipo
|
|
int nType = GetLeadInType() ;
|
|
// Eseguo a seconda del tipo
|
|
switch ( nType) {
|
|
case SURFFIN_LI_NONE :
|
|
return true ;
|
|
case SURFFIN_LI_LINEAR :
|
|
return ( AddLinearMove( ptStart, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ;
|
|
case SURFFIN_LI_TANGENT :
|
|
PtrOwner<ICurve> pCrv( GetArc2PVN( ptStart, ptP1, - vtStart, vtTool)) ;
|
|
if ( IsNull( pCrv))
|
|
return false ;
|
|
pCrv->Invert() ;
|
|
return ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
SurfFinishing::GetLeadOutType( void) const
|
|
{
|
|
if ( abs( m_Params.m_dLoTang) < min( 0.1 * m_TParams.m_dDiam, 0.1) &&
|
|
abs( m_Params.m_dLoPerp) < min( 0.1 * m_TParams.m_dDiam, 0.1) &&
|
|
m_Params.m_nLeadOutType != SURFFIN_LO_AS_LI)
|
|
return SURFFIN_LO_NONE ;
|
|
return m_Params.m_nLeadOutType ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::CalcLeadOutEnd( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d& vtTool, const Vector3d& vtNorm, Point3d& ptP1) const
|
|
{
|
|
// Assegno tipo e parametri
|
|
int nType = GetLeadOutType() ;
|
|
double dTang = m_Params.m_dLoTang ;
|
|
double dPerp = m_Params.m_dLoPerp ;
|
|
// se uscita come ingresso
|
|
if ( nType == SURFFIN_LO_AS_LI) {
|
|
int nLiType = GetLeadInType() ;
|
|
switch ( nLiType) {
|
|
case SURFFIN_LI_LINEAR : nType = SURFFIN_LO_LINEAR ; break ;
|
|
case SURFFIN_LI_TANGENT : nType = SURFFIN_LO_TANGENT ; break ;
|
|
default : nType = SURFFIN_LO_NONE ; break ;
|
|
}
|
|
dTang = m_Params.m_dLiTang ;
|
|
dPerp = m_Params.m_dLiPerp ;
|
|
}
|
|
// Calcolo punto finale
|
|
switch ( nType) {
|
|
case SURFFIN_LO_NONE :
|
|
ptP1 = ptEnd ;
|
|
return true ;
|
|
case SURFFIN_LO_LINEAR :
|
|
case SURFFIN_LO_TANGENT :
|
|
{
|
|
// calcolo punto finale dell'uscita
|
|
Vector3d vtPerp = vtEnd ;
|
|
Vector3d vtRot = OrthoCompo( vtTool, vtEnd) ;
|
|
vtPerp.Rotate( vtRot, 0, -1) ;
|
|
if ( vtPerp * vtNorm < -EPS_ZERO)
|
|
vtPerp.Invert() ;
|
|
ptP1 = ptEnd + vtEnd * dTang + vtPerp * dPerp ;
|
|
}
|
|
return true ;
|
|
default :
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Point3d& ptP1, const Vector3d& vtTool, bool bSplitArcs)
|
|
{
|
|
// Se inizio e fine coincidono, non devo fare alcunchè
|
|
if ( AreSamePointApprox( ptEnd, ptP1))
|
|
return true ;
|
|
// Assegno tipo e parametri
|
|
int nType = GetLeadOutType() ;
|
|
// se uscita come ingresso
|
|
if ( nType == SURFFIN_LO_AS_LI) {
|
|
int nLiType = GetLeadInType() ;
|
|
switch ( nLiType) {
|
|
case SURFFIN_LI_LINEAR : nType = SURFFIN_LO_LINEAR ; break ;
|
|
case SURFFIN_LI_TANGENT : nType = SURFFIN_LO_TANGENT ; break ;
|
|
default : nType = SURFFIN_LO_NONE ; break ;
|
|
}
|
|
}
|
|
// eseguo a seconda del tipo
|
|
switch ( nType) {
|
|
case SURFFIN_LO_NONE :
|
|
return true ;
|
|
case SURFFIN_LO_LINEAR :
|
|
return ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ;
|
|
case SURFFIN_LO_TANGENT :
|
|
// inserisco uscita
|
|
PtrOwner<ICurve> pCrv( GetArc2PVN( ptEnd, ptP1, vtEnd, vtTool)) ;
|
|
if ( IsNull( pCrv))
|
|
return false ;
|
|
// emetto movimento
|
|
return ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetLastGoodPoint( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, const Point3d& ptStart,
|
|
const Point3d& ptEnd, const Vector3d& vtInit, const Vector3d& vtTool,
|
|
bool bLeadInVsOut, Point3d& ptP1) const
|
|
{
|
|
// se inizio e fine coincidono, non faccio nulla
|
|
if ( AreSamePointApprox( ptStart, ptEnd))
|
|
return true ;
|
|
|
|
// porto i punti e il versori nel riferimento superficie
|
|
Point3d ptStartL = GetToLoc( ptStart, frSurf) ;
|
|
Point3d ptEndL = GetToLoc( ptEnd, frSurf) ;
|
|
Vector3d vtInitL = GetToLoc( vtInit, frSurf) ;
|
|
Vector3d vtToolL = GetToLoc( vtTool, frSurf) ;
|
|
// porto i punti dal tip al naso mandrino
|
|
ptStartL += vtToolL * m_TParams.m_dLen ;
|
|
ptEndL += vtToolL * m_TParams.m_dLen ;
|
|
|
|
// definisco la PolyLine del tratto da seguire
|
|
PNTULIST lstPntU ;
|
|
|
|
// --- caso di LeadIn
|
|
if ( bLeadInVsOut) {
|
|
// recupero il tipo di LeadIn
|
|
switch( GetLeadInType()) {
|
|
case SURFFIN_LI_NONE :
|
|
return true ;
|
|
case SURFFIN_LI_LINEAR : {
|
|
// inserisco gli estremi del tratto lineare
|
|
lstPntU = { { ptStartL, 0}, { ptEndL, 1}} ;
|
|
}
|
|
break ;
|
|
case SURFFIN_LI_TANGENT : {
|
|
// definisco la curva ad arco
|
|
PtrOwner<ICurve> pCrv( GetArc2PVN( ptEndL, ptStartL, - vtInitL, vtToolL)) ;
|
|
if ( IsNull( pCrv))
|
|
return false ;
|
|
pCrv->Invert() ;
|
|
// inserisco i punti nella lista, campionandola
|
|
PolyLine PL ;
|
|
pCrv->ApproxWithLines( m_Params.m_dApprox, EPS_ANG_SMALL, ICurve::APL_SPECIAL, PL) ;
|
|
lstPntU = PL.GetUPointList() ;
|
|
}
|
|
break ;
|
|
}
|
|
lstPntU.reverse() ;
|
|
}
|
|
|
|
// --- caso di LeadOut
|
|
else {
|
|
// recupero il tipo di LeadOut
|
|
int nType = GetLeadOutType() ;
|
|
// se uscita come ingresso
|
|
if ( nType == SURFFIN_LO_AS_LI) {
|
|
int nLiType = GetLeadInType() ;
|
|
switch ( nLiType) {
|
|
case SURFFIN_LI_LINEAR : nType = SURFFIN_LO_LINEAR ; break ;
|
|
case SURFFIN_LI_TANGENT : nType = SURFFIN_LO_TANGENT ; break ;
|
|
default : nType = SURFFIN_LO_NONE ; break ;
|
|
}
|
|
}
|
|
// eseguo a seconda del tipo
|
|
switch( nType) {
|
|
case SURFFIN_LO_NONE :
|
|
return true ;
|
|
case SURFFIN_LO_LINEAR : {
|
|
// inserisco gli estremi del tratto lineare
|
|
lstPntU = { { ptStartL, 0}, { ptEndL, 1}} ;
|
|
}
|
|
break ;
|
|
case SURFFIN_LO_TANGENT : {
|
|
// definisco la curva ad arco
|
|
PtrOwner<ICurve> pCrv( GetArc2PVN( ptStartL, ptEndL, vtInitL, vtToolL)) ;
|
|
if ( IsNull( pCrv))
|
|
return false ;
|
|
// inserisco i punti nella lista, campionandola
|
|
PolyLine PL ;
|
|
pCrv->ApproxWithLines( m_Params.m_dApprox, EPS_ANG_SMALL, ICurve::APL_SPECIAL, PL) ;
|
|
lstPntU = PL.GetUPointList() ;
|
|
}
|
|
break ;
|
|
}
|
|
}
|
|
|
|
// se non ho inserito almeno 2 punti nella lista, non faccio nulla
|
|
if ( int( lstPntU.size()) < 2)
|
|
return true ; // per sicurezza...
|
|
|
|
// eseguo controllo collisione
|
|
if ( ! pCAvTlStm->TestPath( lstPntU, vtToolL, vtToolL, m_Params.m_dApprox, 0.))
|
|
return false ;
|
|
|
|
// cerco l'ultimo punto non spostato per evitare collisione
|
|
bool bFound = false ;
|
|
auto currPU = lstPntU.begin() ;
|
|
while ( ! bFound && currPU != lstPntU.end()) {
|
|
auto nextPU = next( currPU) ;
|
|
if ( nextPU == lstPntU.end() || nextPU->second > m_Params.m_dApprox){
|
|
bFound = true ;
|
|
ptP1 = GetToGlob( currPU->first - vtToolL * ( m_TParams.m_dLen + currPU->second), frSurf) ;
|
|
}
|
|
currPU = nextPU ;
|
|
}
|
|
|
|
return bFound ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetLinkFromPaths( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtTool, const ISurfFlatRegion* pSfrCnt,
|
|
double dDepth, double dSafeZ, ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, ICurveComposite* pCrvLink) const
|
|
{
|
|
// controllo dei parametri
|
|
if ( pCAvTlStm == nullptr || pCrvLink == nullptr || pSfrCnt == nullptr)
|
|
return false ;
|
|
// se estremi coincidenti, non faccio nulla
|
|
pCrvLink->Clear() ;
|
|
if ( AreSamePointApprox( ptStart, ptEnd))
|
|
return true ;
|
|
|
|
// porto le entità geometriche nel riferimento delle superfici
|
|
Point3d ptEndL = GetToLoc( ptEnd, frSurf) ;
|
|
Point3d ptStartL = GetToLoc( ptStart, frSurf) ;
|
|
Vector3d vtToolL = GetToLoc( vtTool, frSurf) ;
|
|
// porto i punti dal tip al naso mandrino
|
|
ptEndL += vtToolL * m_TParams.m_dLen ;
|
|
ptStartL += vtToolL * m_TParams.m_dLen ;
|
|
|
|
// mi assicuro che il collegamento non interferica con la superficie
|
|
PNTULIST lstPntU{ { ptEndL, 0.}, { ptStartL, 1.}} ;
|
|
if ( ! pCAvTlStm->TestPath( lstPntU, vtToolL, vtToolL, m_Params.m_dApprox, 0.))
|
|
return false ;
|
|
|
|
// determino un piano al di sotto della lavorazione, orientato come pSfrCnt
|
|
// --- serve per individuare la quota ZLocMax per i Link tra le curve di finitura
|
|
Point3d ptC ; pSfrCnt->GetCentroid( ptC) ;
|
|
Plane3d plZLocMin ;
|
|
if ( ! plZLocMin.Set( ptC, vtTool))
|
|
return false ;
|
|
plZLocMin.Translate( - vtTool * 10 * ( m_TParams.m_dLen + abs( dDepth))) ;
|
|
|
|
// determino il punto con ZLocale più alta
|
|
Point3d ptZMax = ptEnd ;
|
|
double dZMax = 0. ;
|
|
for ( auto& ptU : lstPntU) {
|
|
Point3d ptUGlob = GetToGlob( ptU.first - vtToolL * m_TParams.m_dLen, frSurf) ;
|
|
double dCurrZ = DistPointPlane( ptUGlob, plZLocMin) ;
|
|
if ( dCurrZ > dZMax) {
|
|
dZMax = dCurrZ ;
|
|
ptZMax = ptUGlob ;
|
|
}
|
|
}
|
|
|
|
// determino elevazione sopra a ptEnd
|
|
double dEndElev = dSafeZ + abs( ( ptZMax - ptEnd) * vtTool) ;
|
|
double dStartElev = dSafeZ + abs( ( ptZMax - ptStart) * vtTool) ;
|
|
|
|
// definisco il collegamento
|
|
pCrvLink->AddPoint( ptEnd) ;
|
|
pCrvLink->AddLine( ptEnd + vtTool * dEndElev) ;
|
|
pCrvLink->AddLine( ptStart + vtTool * dStartElev) ;
|
|
pCrvLink->AddLine( ptStart) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::GetSurfaceNormalAtPoint( ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf,
|
|
const Point3d& ptTool, const Vector3d& vtTool, Vector3d& vtNorm) const
|
|
{
|
|
// porto il punto e il versore nel riferimento superficie
|
|
Point3d ptToolL = GetToLoc( ptTool, frSurf) ;
|
|
Vector3d vtToolL = GetToLoc( vtTool, frSurf) ;
|
|
// porto i punti dal tip al naso mandrino
|
|
ptToolL += vtToolL * m_TParams.m_dLen ;
|
|
// affondo di poco il punto per ricavare ultima superficie di contatto e sua normale
|
|
double dMove ;
|
|
Vector3d vtNormL ;
|
|
if ( ! pCAvTlStm->TestPosition( ptToolL - vtToolL, vtToolL, vtToolL, dMove, &vtNormL) || dMove < EPS_SMALL)
|
|
return false ;
|
|
// porto la normale in globale
|
|
vtNorm = GetToGlob( vtNormL, frSurf) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
double
|
|
SurfFinishing::GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool) const
|
|
{
|
|
// Determino i versori
|
|
Vector3d vtM = vtMove ;
|
|
vtM.Normalize() ;
|
|
Vector3d vtT = vtTool ;
|
|
vtT.Normalize() ;
|
|
// Angolo tra movimento e versore utensile
|
|
double dCosMove = vtM * vtT ;
|
|
// Se l'utensile non ha movimento significativo di punta, si restituisce la feed standard
|
|
if ( dCosMove > - COS_ORTO_ANG_SMALL)
|
|
return GetFeed() ;
|
|
// Altrimenti non si deve superare la massima velocità di punta prevista
|
|
return min( GetFeed(), GetTipFeed() / abs( dCosMove)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
double
|
|
SurfFinishing::GetRadiusForStartEndElevation( void) const
|
|
{
|
|
const double DELTA_ELEV_RAD = 4.0 ;
|
|
double dDeltaRad = min( DELTA_ELEV_RAD, 0.5 * m_TParams.m_dTDiam) ;
|
|
return ( 0.5 * m_TParams.m_dTDiam + dDeltaRad) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SurfFinishing::AddFinishing( const ISurfFlatRegion* pSfrCnt, ICAvToolSurfTm* pCAvTlStm, const Frame3d& frSurf, const ICRVCOMPOPOVECTOR& vCrvCompo,
|
|
const Vector3d& vtTool, double dElev, double dDepth, bool bSplitArcs)
|
|
{
|
|
// se non ho curve, non faccio nulla
|
|
if ( vCrvCompo.empty())
|
|
return true ;
|
|
// se classe di calcolo per le collisioni non inizializzata, errore
|
|
if ( pCAvTlStm == nullptr)
|
|
return false ;
|
|
// tutte le curve devono essere valide e ben definite
|
|
for ( const auto& pMCrv : vCrvCompo) {
|
|
if ( pMCrv == nullptr || ! pMCrv->IsValid())
|
|
return false ;
|
|
}
|
|
|
|
// recupero distanze di sicurezza
|
|
double dSafeZ = GetSafeZ() ;
|
|
// lunghezza di approccio/retrazione
|
|
double dAppr = m_Params.m_dStartPos ;
|
|
|
|
#if ENABLE_LINK_DEBUG
|
|
int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nGrp, "movements") ;
|
|
m_pGeomDB->SetStatus( nGrp, GDB_ST_OFF) ;
|
|
int nLayCurve = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayCurve, "curves") ;
|
|
int nLayLink = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayLink, "links") ;
|
|
int nLayLeadInOut = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nLayLeadInOut, "leadInOut") ;
|
|
Vector3d vtToolL = GetToLoc( vtTool, frSurf) ;
|
|
#endif
|
|
|
|
// ciclo sulle curve
|
|
bool bStart = true ;
|
|
double dStElev = dElev ;
|
|
Point3d ptStart, ptP1 ;
|
|
Vector3d vtStart ;
|
|
for ( int nCrv = 0 ; nCrv < int( vCrvCompo.size()) ; ++ nCrv) {
|
|
|
|
#if ENABLE_LINK_DEBUG
|
|
int nIdCrv = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayCurve, CloneCurveComposite( vCrvCompo[nCrv])) ;
|
|
m_pGeomDB->SetMaterial( nIdCrv, PURPLE) ;
|
|
#endif
|
|
|
|
// ciclo sulle curve elementari
|
|
int nMaxInd = vCrvCompo[nCrv]->GetCurveCount() - 1 ;
|
|
for ( int i = 0 ; i <= nMaxInd ; ++ i) {
|
|
|
|
// curva corrente
|
|
const ICurve* pCrvC = vCrvCompo[nCrv]->GetCurve( i) ;
|
|
// copio la curva
|
|
PtrOwner<ICurve> pCurve( pCrvC->Clone()) ;
|
|
if ( IsNull( pCurve))
|
|
return false ;
|
|
|
|
// --- se prima entità in assoluto
|
|
if ( bStart) {
|
|
// dati inizio entità
|
|
pCurve->GetStartPoint( ptStart) ;
|
|
pCurve->GetStartDir( vtStart) ;
|
|
// determino normale della superficie sul punto iniziale
|
|
Vector3d vtNorm ;
|
|
if ( ! GetSurfaceNormalAtPoint( pCAvTlStm, frSurf, ptStart, vtTool, vtNorm)) {
|
|
Point3d ptEnd ; pCurve->GetEndPoint( ptEnd) ;
|
|
if ( ! GetSurfaceNormalAtPoint( pCAvTlStm, frSurf, ptEnd, vtTool, vtNorm))
|
|
vtNorm = V_NULL ;
|
|
}
|
|
// determino inizio attacco
|
|
if ( ! CalcLeadInStart( ptStart, vtStart, vtTool, vtNorm, ptP1))
|
|
return false ;
|
|
#if ENABLE_LINK_DEBUG
|
|
PtrOwner<IGeoPoint3d> pt( CreateGeoPoint3d()) ;
|
|
pt->Set( ptStart) ;
|
|
int nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLeadInOut, pt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nPtId, BLUE) ;
|
|
pt->Set( ptP1) ;
|
|
nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLeadInOut, pt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nPtId, AQUA) ;
|
|
#endif
|
|
// eventuale correzione inizio attacco per evitare interferenze
|
|
if ( ! GetLastGoodPoint( pCAvTlStm, frSurf, ptP1, ptStart, vtStart, vtTool, true, ptP1))
|
|
return false ;
|
|
#if ENABLE_LINK_DEBUG
|
|
pt->Set( ptP1) ;
|
|
nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLeadInOut, pt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nPtId, TEAL) ;
|
|
#endif
|
|
// determino elevazione su inizio attacco
|
|
if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev))
|
|
dStElev = dElev ;
|
|
dStElev -= ( ptP1 - ptStart) * vtTool ;
|
|
// --- approccio globale al punto iniziale
|
|
if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) {
|
|
m_pMchMgr->SetLastError( 3111, "Error in SurfFinishing : Approach not computable") ;
|
|
return false ;
|
|
}
|
|
bStart = false ;
|
|
// --- aggiungo attacco
|
|
SetFeed( GetStartFeed()) ;
|
|
if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, bSplitArcs)) {
|
|
m_pMchMgr->SetLastError( 3113, "Error in SurfFinishing : LeadIn not computable") ;
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
// elaborazioni sulla curva corrente (segmento di retta o arco)
|
|
if ( pCurve->GetType() == CRV_LINE) {
|
|
ICurveLine* pLine = GetCurveLine( pCurve) ;
|
|
Point3d ptP3 = pLine->GetEnd() ;
|
|
Vector3d vtMove ; pLine->GetStartDir( vtMove) ;
|
|
SetFeed( GetRightFeed( vtMove, vtTool)) ;
|
|
if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
else if ( pCurve->GetType() == CRV_ARC) {
|
|
ICurveArc* pArc = GetCurveArc( pCurve) ;
|
|
Vector3d vtMove ; pArc->GetStartDir( vtMove) ;
|
|
SetFeed( GetRightFeed( vtMove, vtTool)) ;
|
|
if ( AddCurveMove( pArc, bSplitArcs) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
|
|
// --- se ultima entità
|
|
if ( i == nMaxInd) {
|
|
// dati fine entità
|
|
Point3d ptEnd ; pCurve->GetEndPoint( ptEnd) ;
|
|
Vector3d vtEnd ; pCurve->GetEndDir( vtEnd) ;
|
|
// --- se ultima entità in assoluto
|
|
if ( nCrv == int( vCrvCompo.size()) - 1) {
|
|
// determino normale della superficie sul punto finale
|
|
Vector3d vtNorm ;
|
|
if ( ! GetSurfaceNormalAtPoint( pCAvTlStm, frSurf, ptEnd, vtTool, vtNorm)) {
|
|
Point3d ptStart ; pCurve->GetStartPoint( ptStart) ;
|
|
if ( ! GetSurfaceNormalAtPoint( pCAvTlStm, frSurf, ptStart, vtTool, vtNorm))
|
|
vtNorm = V_NULL ;
|
|
}
|
|
// determino fine uscita
|
|
if ( ! CalcLeadOutEnd( ptEnd, vtEnd, vtTool, vtNorm, ptP1))
|
|
return false ;
|
|
#if ENABLE_LINK_DEBUG
|
|
PtrOwner<IGeoPoint3d> pt( CreateGeoPoint3d()) ;
|
|
pt->Set( ptEnd) ;
|
|
int nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLeadInOut, pt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nPtId, BLUE) ;
|
|
pt->Set( ptP1) ;
|
|
nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLeadInOut, pt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nPtId, AQUA) ;
|
|
#endif
|
|
// eventuale correzione fine uscita per evitare interferenze
|
|
if ( ! GetLastGoodPoint( pCAvTlStm, frSurf, ptEnd, ptP1, vtEnd, vtTool, false, ptP1))
|
|
return false ;
|
|
#if ENABLE_LINK_DEBUG
|
|
pt->Set( ptP1) ;
|
|
nPtId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLeadInOut, pt->Clone()) ;
|
|
m_pGeomDB->SetMaterial( nPtId, TEAL) ;
|
|
#endif
|
|
// aggiungo uscita
|
|
SetFeed( GetEndFeed()) ;
|
|
if ( ! AddLeadOut( ptEnd, vtEnd, ptP1, vtTool, bSplitArcs)) {
|
|
m_pMchMgr->SetLastError( 3114, "Error in SurfFinishing : LeadOut not computable") ;
|
|
return false ;
|
|
}
|
|
// determino elevazione su fine uscita
|
|
double dEndElev ;
|
|
if ( ! GetElevation( m_nPhase, ptEnd - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dEndElev))
|
|
dEndElev = dElev ;
|
|
dEndElev -= ( ptP1 - ptEnd) * vtTool ;
|
|
// aggiungo retroazione finale
|
|
if ( ! AddRetract( ptP1, vtTool, dSafeZ, dEndElev, dAppr)) {
|
|
m_pMchMgr->SetLastError( 3115, "Error in SurfFinishing : Retract not computable") ;
|
|
return false ;
|
|
}
|
|
}
|
|
// --- se ultima entità di percorso intermedio
|
|
else {
|
|
// punto iniziale entità per la curva successiva
|
|
vCrvCompo[nCrv+1]->GetStartPoint( ptStart) ;
|
|
// se inizio e fine sono coincidenti, non faccio nulla
|
|
if ( AreSamePointApprox( ptEnd, ptStart))
|
|
continue ;
|
|
// definisco il collegamento tra i due percorsi
|
|
PtrOwner<ICurveComposite> pCrvLink( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvLink) ||
|
|
! GetLinkFromPaths( ptStart, ptEnd, vtTool, pSfrCnt, dDepth, dSafeZ, pCAvTlStm, frSurf, pCrvLink))
|
|
return false ;
|
|
#if ENABLE_LINK_DEBUG
|
|
int nIdLink = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayLink, CloneCurveComposite( pCrvLink)) ;
|
|
m_pGeomDB->SetMaterial( nIdLink, RED) ;
|
|
#endif
|
|
SetFeed( GetEndFeed()) ;
|
|
if ( ! AddCurveMove( pCrvLink, bSplitArcs))
|
|
return false ;
|
|
ptP1 = ptStart ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ExeProcessEvents( 100, 0) ;
|
|
return true ;
|
|
}
|