diff --git a/EXE_GdbGetSurf.cpp b/EXE_GdbGetSurf.cpp index 2f89b9e..9e117c2 100644 --- a/EXE_GdbGetSurf.cpp +++ b/EXE_GdbGetSurf.cpp @@ -1431,6 +1431,64 @@ ExeSurfTmGetEdges( int nId, int nDestGrpId, bool bSmoothAng, int* pnCount) return nFirstId ; } +//---------------------------------------------------------------------------- +bool +ExeSurfTmGetCurvatures( int nId, int nV, int nType, double& dK1, Vector3d& vtK1, double& dK2, Vector3d& vtK2) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + + // Inzializzo i parametri di ritorno + dK1 = 0. ; dK2 = 0. ; + vtK1 = V_NULL ; vtK2 = V_NULL ; + + // Recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pStm != nullptr) ; + // Recupero il riferimento globale del gruppo cui appartiene + Frame3d frSurf ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frSurf) ; + + // Calcolo la Curvatura + bool bPlanar = false ; + if ( nType == STM_CURVATURE_STD) { + // Se curvatura Standard + Vector3d vtNorm = V_NULL ; + bOk = bOk && pStm->GetCurvature( nV, dK1, vtK1, dK2, vtK2, bPlanar, vtNorm) ; + } + else { + double dMinK = 0., dMaxK = 0. ; + Vector3d vtMinK = V_NULL, vtMaxK = V_NULL ; + if ( nType == STM_CURVATURE_GAUSS) + bOk = bOk && pStm->GetCurvature( nV, dMinK, vtMinK, dMaxK, vtMaxK, bPlanar, vtK1, &dK1) ; + else if ( nType == STM_CURVATURE_MEAN) + bOk = bOk && pStm->GetCurvature( nV, dMinK, vtMinK, dMaxK, vtMaxK, bPlanar, vtK1, nullptr, &dK1) ; + else if ( nType == STM_CURVATURE_NORM) { + bOk = bOk && pStm->GetCurvature( nV, dMinK, vtMinK, dMaxK, vtMaxK, bPlanar, vtK1, nullptr, nullptr, &dK1, &dK2) ; + vtK2 = vtK1 ; + } + } + // Se superficie localmente piana + if ( bPlanar) { + vtK1 = V_NULL ; // Sarebbe un vettore generico parallelo alla superficie ( sempre dK1 circa 0.) + vtK2 = V_NULL ; // Sarebbe un vettore generico parallelo alla superficie e perpendicolare a vtK1 + // ( sempre dK2 circa 0.) + } + + ExeSetModified() ; + // Se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmGetCurvature(" + ToString( nId) + + ToString( nV) + + ToString( nType) + + " -- bOk=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + // Restituisco il risultato + return bOk ; +} + //---------------------------------------------------------------------------- bool ExeSurfBezierGetPoint( int nSurfId, double dU, double dV, int nRefId, Point3d& ptP) diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 2e22e9b..9743bcf 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/LUA_GdbGetSurf.cpp b/LUA_GdbGetSurf.cpp index cee8fbd..6014f2a 100644 --- a/LUA_GdbGetSurf.cpp +++ b/LUA_GdbGetSurf.cpp @@ -977,6 +977,32 @@ LuaSurfTmGetEdges( lua_State* L) return 2 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmGetCurvature( lua_State* L) +{ + // 3 parametri : nStmId, nIndV + int nStmId ; + LuaCheckParam( L, 1, nStmId) ; + int nIndVertex ; + LuaCheckParam( L, 2, nIndVertex) ; + int nType = STM_CURVATURE_STD ; + LuaGetParam( L, 3, nType) ; + LuaClearStack( L) ; + double dK1 = 0., dK2 = 0. ; + Vector3d vtK1 = V_NULL, vtK2 = V_NULL ; + bool bOk = ExeSurfTmGetCurvatures( nStmId, nIndVertex, nType, dK1, vtK1, dK2, vtK2) ; + LuaSetParam( L, bOk) ; + if ( bOk) { + LuaSetParam( L, dK1) ; + LuaSetParam( L, vtK1) ; + LuaSetParam( L, dK2) ; + LuaSetParam( L, vtK2) ; + return 5 ; + } + return 1 ; +} + //---------------------------------------------------------------------------- static int LuaSurfBezierGetPoint( lua_State* L) @@ -1282,6 +1308,7 @@ LuaInstallGdbGetSurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmTriaLoop", LuaExtractSurfTmTriaLoop) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopySurfTmFacet", LuaCopySurfTmFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetEdges", LuaSurfTmGetEdges) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetCurvature", LuaSurfTmGetCurvature) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetPoint", LuaSurfBezierGetPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetPointD1", LuaSurfBezierGetPointD1) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetPointNrmD1", LuaSurfBezierGetPointNrmD1) ;