Merge branch 'master' into MoreBezier

This commit is contained in:
Daniele Bariletti
2024-07-17 16:21:56 +02:00
9 changed files with 178 additions and 29 deletions
+127 -2
View File
@@ -1174,6 +1174,43 @@ ExeCreateSurfTmByRevolve( int nParentId, int nCrvId,
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateSurfBzByPointCurve( int nParentId, int nCrvId, const Point3d& ptTop,
bool bCapEnds, double dLinTol, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero la curva in locale
CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ;
bOk = bOk && ( CrvLoc.Get() != nullptr) ;
// porto in locale punto e vettore asse
Point3d ptTopL = GetPointLocal( pGeomDB, ptTop, nRefType, frLoc) ;
// calcolo la superficie
ISurfBezier* pSTM = ( bOk ? GetSurfBezierRuled( ptTopL, CrvLoc, dLinTol) : nullptr) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfBzByPointCurve(" + IdToString( nParentId) + "," +
ToString( nCrvId) + ",{" +
ToString( ptTop) + "},{" +
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateSurfTmByScrewing( int nParentId, int nCrvId,
@@ -1988,7 +2025,7 @@ ExeCreateSurfBzByRegion( int nParentId, const INTVECTOR& vCrvIds, double dLinTol
//-------------------------------------------------------------------------------
int
ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vector3d& vtExtr,
ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vector3d& vtExtr, bool bCapEnds,
double dLinTol, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
@@ -2001,7 +2038,7 @@ ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vecto
// recupero le curve in locale
CURVELOCALVECTOR vCrvLoc ;
vCrvLoc.reserve( vCrvIds.size()) ;
ICURVEPVECTOR vCrvP ;
CICURVEPVECTOR vCrvP ;
vCrvP.reserve( vCrvIds.size()) ;
for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) {
int nId = (( vCrvIds[i] != GDB_ID_SEL) ? vCrvIds[i] : pGeomDB->GetFirstSelectedObj()) ;
@@ -2026,6 +2063,47 @@ ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vecto
if ( bOk && nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
}
// se richiesta chiusura agli estremi
if ( bCapEnds) {
// verifico che la curva sia chiusa e piatta
Plane3d plPlane ;
double dArea ;
PolyLine plApprox ;
double dAndTolDeg = 5 ;
vCrvP[0]->ApproxWithLines( dLinTol, dAndTolDeg, ICurve::APL_STD, plApprox) ;
if ( plApprox.IsClosedAndFlat( plPlane, dArea, 50 * EPS_SMALL)) {
// componente dell'estrusione perpendicolare al piano della curva
double dOrthoExtr = plPlane.GetVersN() * vtExtr ;
if ( ( abs( dOrthoExtr) > EPS_SMALL)) {
if( vCrvIds.size() == 1) {
PtrOwner<ISurfBezier> pSrfBzTop( CreateSurfBezier()) ;
pSrfBzTop->CreateByFlatContour( plApprox) ;
pSrfBzTop->Translate( vtExtrL) ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzTop)) ;
PtrOwner<ISurfBezier> pSrfBzBottom( CreateSurfBezier()) ;
pSrfBzBottom->CreateByFlatContour( plApprox) ;
pSrfBzBottom->Invert() ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzBottom)) ;
}
else {
// riordino le curve in modo che la prima sia quella esterna e tutte le altre dopo
POLYLINEVECTOR vPL ;
Vector3d vtN ;
if ( ! CalcRegionPolyLines( vCrvP, dLinTol, vPL, vtN))
return nFirstId ;
PtrOwner<ISurfBezier> pSrfBzTop( CreateSurfBezier()) ;
pSrfBzTop->CreateByRegion( vPL) ;
pSrfBzTop->Translate( vtExtrL) ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzTop)) ;
PtrOwner<ISurfBezier> pSrfBzBottom( CreateSurfBezier()) ;
pSrfBzBottom->CreateByRegion( vPL) ;
pSrfBzBottom->Invert() ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzBottom)) ;
}
}
}
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
@@ -2104,6 +2182,53 @@ ExeCreateSurfBzByRevolve( int nParentId, int nCrvId,
Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ;
// calcolo la superficie
ISurfBezier* pSbz = ( bOk ? GetSurfBezierByRevolve( CrvLoc, ptAxL, vtAxL, bCapEnds, dLinTol) : nullptr) ;
// finché non ho le SurfCompo creo qui i cap
if ( bCapEnds) {
// calcola la bbox della superficie
BBox3d bbox3dSurf ;
int nDegU, nDegV, nSpanU, nSpanV ;
bool bTrim, bRat ;
pSbz->GetInfo( nDegU, nDegV, nSpanU, nSpanV, bTrim, bRat) ;
int nPointCount = ( nDegU * nSpanU + 1) * ( nDegV * nSpanV + 1) ;
for ( int p = 0 ; p < nPointCount ; ++p) {
bool bPointOk = true ;
Point3d ptCtrl = pSbz->GetControlPoint( p, &bPointOk) ;
bbox3dSurf.Add( ptCtrl) ;
}
// recupero i loop
ICRVCOMPOPOVECTOR vCCLoop ;
pSbz->GetLoops( vCCLoop, true) ;
// il getLoops per superfici non trimmate restituisce 1 elemento per ogni lato dello spazio parametrico.
// in questo caso la superficie è chiusa lungo il parametro V, quindi i lati 0 e 2 saranno null.
double dAngTolDeg = 5 ;
PolyLine plEdge1 ; vCCLoop[1]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge1) ;
PolyLine plEdge3 ; vCCLoop[3]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge3) ;
plEdge3.Invert() ;
//// devo distinguere tra il loop superiore e quello inferiore
//PolyLine plEdge0 ; vCCLoop[0]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge0) ;
//Plane3d plPlane ; double dArea ;
//bOk = bOk && ! plEdge0.IsClosedAndFlat( plPlane, dArea, 50 * EPS_SMALL) ;
//Vector3d vtN = plPlane.GetVersN() ;
//// vedo come questa normale è orientata rispetto alla bbox della superficie
//Point3d ptCen ; vCCLoop[0]->GetCentroid( ptCen) ;
//ptCen += vtN ;
//PolyLine plEdge1 ; vCCLoop[1]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge1) ;
//// inverto uno dei due bordi
//if ( bbox3dSurf.Encloses( ptCen))
// plEdge0.Invert() ;
//else
// plEdge1.Invert() ;
// creo le superfici e le inserisco nel DB
PtrOwner<ISurfBezier> pSrfBzCap1( CreateSurfBezier()) ;
pSrfBzCap1->CreateByFlatContour( plEdge1) ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzCap1)) ;
PtrOwner<ISurfBezier> pSrfBzCap3( CreateSurfBezier()) ;
pSrfBzCap3->CreateByFlatContour( plEdge3) ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzCap3)) ;
}
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ;
ExeSetModified() ;
+14 -1
View File
@@ -739,12 +739,23 @@ ExeCurveCompoGetTempParam( int nId, DBLVECTOR& vParam, int nParamInd)
//----------------------------------------------------------------------------
int
ExeShowCurveBezierControlPoints( int nCrvId, int* pnCount)
ExeShowCurveBezierControlPoints( int nCrvId, int nDestGrpId, int* pnCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero la curva di bezier
IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nCrvId) ;
if ( pGeoObj->GetType() != CRV_BEZIER)
return GDB_ID_NULL ;
// recupero il riferimento della curva
Frame3d frCrv ;
bool bOk = true ;
bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ;
// recupero il riferimento di destinazione
Frame3d frDest ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ;
if ( ! bOk)
return GDB_ID_NULL ;
int nType = pGeoObj->GetType() ;
if ( nType == CRV_COMPO) {
const ICurveComposite* pCrvCompo = GetCurveComposite( pGeoObj) ;
@@ -769,6 +780,7 @@ ExeShowCurveBezierControlPoints( int nCrvId, int* pnCount)
//else
// pGeoPt->Set( pCrvBezier->GetControlPoint( i) * pCrvBezier->GetControlWeight( i)) ;
pGeoPt->Set( pCrvBezier->GetControlPoint( i)) ;
pGeoPt->LocToLoc( frCrv, frDest) ;
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParent, pGeoPt) ;
if ( nFirstId == GDB_ID_NULL)
nFirstId = nId ;
@@ -797,6 +809,7 @@ ExeShowCurveBezierControlPoints( int nCrvId, int* pnCount)
//else
// pGeoPt->Set( pCrvBezier->GetControlPoint( i) * pCrvBezier->GetControlWeight( i)) ;
pGeoPt->Set( pCrvBezier->GetControlPoint( i)) ;
pGeoPt->LocToLoc( frCrv, frDest) ;
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParent, pGeoPt) ;
if ( nFirstId == GDB_ID_NULL)
nFirstId = nId ;
+12 -4
View File
@@ -1727,15 +1727,23 @@ ExeExtractSurfBezierLoops( int nId, int nDestGrpId, int* pnCount)
//----------------------------------------------------------------------------
int
ExeShowSurfBezierControlPoints( int nSrfId, int* pnCount)
ExeShowSurfBezierControlPoints( int nSrfId, int nDestGrpId, int* pnCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
int nParent = pGeomDB->GetParentId( nSrfId) ;
// recupero la superficie di bezier
IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nSrfId) ;
if ( pGeoObj->GetType() != SRF_BEZIER)
return GDB_ID_NULL ;
// recupero il riferimento della superficie
Frame3d frSurf ;
bool bOk = true ;
bOk = bOk && pGeomDB->GetGlobFrame( nSrfId, frSurf) ;
// recupero il riferimento di destinazione
Frame3d frDest ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ;
if ( ! bOk)
return GDB_ID_NULL ;
int nDegU = - 1, nDegV = - 1, nSpanU = - 1, nSpanV = - 1 ;
bool bRat = false, bTrimmed = false ;
ISurfBezier* pSrfBez = GetSurfBezier( pGeoObj) ;
@@ -1743,10 +1751,10 @@ ExeShowSurfBezierControlPoints( int nSrfId, int* pnCount)
int nFirstId = -1 ;
int nCount = 0 ;
for ( int i = 0 ; i < (nDegU * nSpanU + 1) * ( nDegV * nSpanV + 1) ; ++i) {
bool bOk = true ;
IGeoPoint3d* pGeoPt( CreateGeoPoint3d()) ;
pGeoPt->Set( pSrfBez->GetControlPoint( i, &bOk)) ;
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParent, pGeoPt) ;
pGeoPt->LocToLoc( frSurf, frDest) ;
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, pGeoPt) ;
if ( nFirstId == GDB_ID_NULL)
nFirstId = nId ;
if ( nId != GDB_ID_NULL)
+2 -2
View File
@@ -2921,7 +2921,7 @@ ExeCurveBezierIncreaseDegree( int nCrvId)
// recupero la curva
const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
if ( pCrv == nullptr)
return GDB_ID_NULL ;
return false ;
//// recupero il riferimento della curva
//Frame3d frCrv ;
//if ( ! pGeomDB->GetGlobFrame( nCrvId, frCrv))
@@ -2961,7 +2961,7 @@ ExeCurveBezierDecreaseDegree( int nCrvId, double dTol)
// recupero la curva
const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
if ( pCrv == nullptr)
return GDB_ID_NULL ;
return false ;
//// recupero il riferimento della curva
//Frame3d frCrv ;
//if ( ! pGeomDB->GetGlobFrame( nCrvId, frCrv))
BIN
View File
Binary file not shown.
+13 -12
View File
@@ -1028,22 +1028,24 @@ LuaCreateSurfBzByRegion( lua_State* L)
static int
LuaCreateSurfBzByExtrusion( lua_State* L)
{
// 3 o 4 o 5 parametri : ParentId, CrvIds, vtExtr [, dTol] [, nRefType]
// 4 o 5 o 6 parametri : ParentId, CrvIds, vtExtr, bool bCapEnds [, dTol] [, nRefType]
int nParentId ;
LuaCheckParam( L, 1, nParentId)
INTVECTOR vCrvIds ;
LuaCheckParam( L, 2, vCrvIds)
Vector3d vtExtr ;
LuaCheckParam( L, 3, vtExtr)
bool bCapEnds = false ;
LuaCheckParam( L, 4, bCapEnds)
double dLinTol = LIN_TOL_SRF ;
int nRefType = RTY_DEFAULT ;
if ( LuaGetParam( L, 4, dLinTol))
LuaGetParam( L, 5, nRefType) ;
if ( LuaGetParam( L, 5, dLinTol))
LuaGetParam( L, 6, nRefType) ;
else
LuaGetParam( L, 4, nRefType) ;
LuaGetParam( L, 5, nRefType) ;
LuaClearStack( L) ;
// creo STM estrudendo uno o più percorsi, se piani si possono mettere i tappi
int nId = ExeCreateSurfBzByExtrusion( nParentId, vCrvIds, vtExtr, dLinTol, nRefType) ;
int nId = ExeCreateSurfBzByExtrusion( nParentId, vCrvIds, vtExtr, bCapEnds, dLinTol, nRefType) ;
// restituisco il risultato
if ( nId != GDB_ID_NULL)
LuaSetParam( L, nId) ;
@@ -1128,16 +1130,14 @@ LuaCreateSurfBzByRevolve( lua_State* L)
static int
LuaCreateSurfBzByPointCurve( lua_State* L)
{
// 4 o 5 o 6 o 7 parametri : ParentId, CrvId, ptAx, vtAx [, bCapEnds] [, dTol] [, nRefType]
// 3 o 4 o 5 o 6 parametri : ParentId, CrvId, ptAx, vtAx [, bCapEnds] [, dTol] [, nRefType]
int nParentId ;
LuaCheckParam( L, 1, nParentId)
int nCrvId ;
LuaCheckParam( L, 2, nCrvId)
Point3d ptAx ;
LuaCheckParam( L, 3, ptAx)
Vector3d vtAx ;
LuaCheckParam( L, 4, vtAx)
int nPar = 5 ;
Point3d ptTop ;
LuaCheckParam( L, 3, ptTop)
int nPar = 4 ;
bool bCapEnds = false ;
if ( LuaGetParam( L, nPar, bCapEnds))
++ nPar ;
@@ -1149,7 +1149,7 @@ LuaCreateSurfBzByPointCurve( lua_State* L)
++ nPar ;
LuaClearStack( L) ;
// creo STM riempiendo un contorno piano
int nId = ExeCreateSurfBzByRevolve( nParentId, nCrvId, ptAx, vtAx, bCapEnds, dLinTol, nRefType) ;
int nId = ExeCreateSurfBzByPointCurve( nParentId, nCrvId, ptTop, bCapEnds, dLinTol, nRefType) ;
// restituisco il risultato
if ( nId != GDB_ID_NULL)
LuaSetParam( L, nId) ;
@@ -1228,6 +1228,7 @@ LuaInstallGdbCreateSurf( LuaMgr& luaMgr)
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByExtrusion", LuaCreateSurfBzByExtrusion) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByScrewing", LuaCreateSurfBzByScrewing) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByRevolve", LuaCreateSurfBzByRevolve) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByPointCurve", LuaCreateSurfBzByPointCurve) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzRuled", LuaCreateSurfBzRuled) ;
return bOk ;
}
+5 -3
View File
@@ -588,12 +588,14 @@ LuaCurveCompoGetTempParam( lua_State* L)
static int
LuaShowCurveBezierControlPoints( lua_State* L)
{
// 1 parametro : nCrvId
// 2 parametri : nCrvId, nDestGrpId
int nCrvId ;
LuaCheckParam( L, 1, nCrvId)
LuaClearStack( L) ;
int nDestGrpId ;
LuaCheckParam( L, 2, nDestGrpId)
LuaClearStack( L) ;
int nCount = 0 ;
int nId = ExeShowCurveBezierControlPoints( nCrvId, &nCount) ;
int nId = ExeShowCurveBezierControlPoints( nCrvId, nDestGrpId, &nCount) ;
// restituisco il risultato
if ( nId != GDB_ID_NULL) {
LuaSetParam( L, nId) ;
+5 -3
View File
@@ -1192,12 +1192,14 @@ LuaExtractSurfBezierLoops( lua_State* L)
static int
LuaShowSurfBezierControlPoints( lua_State* L)
{
// 1 parametro : nCrvId
// 2 parametri : nCrvId, nDestGrpId
int nCrvId ;
LuaCheckParam( L, 1, nCrvId)
LuaClearStack( L) ;
int nDestGrpId ;
LuaCheckParam( L, 2, nDestGrpId)
LuaClearStack( L) ;
int nCount = 0 ;
int nId = ExeShowSurfBezierControlPoints( nCrvId, &nCount) ;
int nId = ExeShowSurfBezierControlPoints( nCrvId, nDestGrpId, &nCount) ;
// restituisco il risultato
if ( nId != GDB_ID_NULL) {
LuaSetParam( L, nId) ;
-2
View File
@@ -1174,7 +1174,6 @@ LuaCurveBezierIncreaseDegree( lua_State* L)
LuaCheckParam( L, 1, nId)
LuaClearStack( L) ;
// eseguo
int nCount = 0 ;
bool bOk = ExeCurveBezierIncreaseDegree( nId) ;
LuaSetParam( L, bOk) ;
@@ -1190,7 +1189,6 @@ LuaCurveBezierDecreaseDegree( lua_State* L)
LuaCheckParam( L, 1, nId)
LuaClearStack( L) ;
// eseguo
int nCount = 0 ;
bool bOk = ExeCurveBezierDecreaseDegree( nId) ;
LuaSetParam( L, bOk) ;