//---------------------------------------------------------------------------- // EgalTech 2020-2020 //---------------------------------------------------------------------------- // File : EXE_CDeObjClosedSurfTm.cpp Data : 09.01.20 Versione : 2.2a2 // Contenuto : Funzioni per verificare collisioni tra // Objects e Closed SurftriMesh. // // // Modifiche : 09.01.20 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" #include "EXE_Const.h" #include "AuxTools.h" #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkCDeBoxClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeCylClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeSpheClosedSurfTm.h" #include "/EgtDev/Include/EGkVolZmap.h" #include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //---------------------------------------------------------------------------- static int MyCDeBoxClosedSurfTm( const Frame3d& frBox, const Vector3d& vtDiag, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // verifico sia chiusa if ( ! pStm->IsClosed()) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il riferimento del box (il vettore è già in questo stesso riferimento) Frame3d frBoxL = GetFrameLocal( pGeomDB, frBox, nRefType, frSurf) ; // verifico la collisione return ( CDeBoxClosedSurfTm( frBoxL, vtDiag, dSafeDist, *pStm) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeCDeBoxClosedSurfTm( const Frame3d& frBox, const Vector3d& vtDiag, int nSurfTmId, double dSafeDist, int nRefType) { int nRes = MyCDeBoxClosedSurfTm( frBox, vtDiag, nSurfTmId, dSafeDist, nRefType) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtCDeBoxClosedSurfTm({{" + ToString( frBox.Orig()) + "},{" + ToString( frBox.VersX()) + "},{" + ToString( frBox.VersY()) + "},{" + ToString( frBox.VersZ()) + "}},{" + ToString( vtDiag) + "}," + IdToString( nSurfTmId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyCDeCylClosedSurfTm( const Frame3d& frCyl, double dH, double dR, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // verifico sia chiusa if ( ! pStm->IsClosed()) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il riferimento del cilindro Frame3d frCylL = GetFrameLocal( pGeomDB, frCyl, nRefType, frSurf) ; // verifico la collisione return ( CDeCylClosedSurfTm( frCylL, dH, dR, dSafeDist, *pStm) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeCDeCylClosedSurfTm( const Frame3d& frCyl, double dH, double dR, int nSurfTmId, double dSafeDist, int nRefType) { int nRes = MyCDeCylClosedSurfTm( frCyl, dH, dR, nSurfTmId, dSafeDist, nRefType) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtCDeCylClosedSurfTm({{" + ToString( frCyl.Orig()) + "},{" + ToString( frCyl.VersX()) + "},{" + ToString( frCyl.VersY()) + "},{" + ToString( frCyl.VersZ()) + "}}," + ToString( dH) + "," + ToString( dR) + "," + IdToString( nSurfTmId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyCDeSpheClosedSurfTm( const Point3d& ptCen, double dR, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // verifico sia chiusa if ( ! pStm->IsClosed()) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il centro della sfera Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frSurf) ; // verifico la collisione return ( CDeSpheClosedSurfTm( ptCenL, dR, dSafeDist, *pStm) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeCDeSpheClosedSurfTm( const Point3d& ptCen, double dR, int nSurfTmId, double dSafeDist, int nRefType) { int nRes = MyCDeSpheClosedSurfTm( ptCen, dR, nSurfTmId, dSafeDist, nRefType) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtCDeSpheClosedSurfTm({" + ToString( ptCen) + "}," + ToString( dR) + "," + IdToString( nSurfTmId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyCDeBoxVolZmap( const Frame3d& frBox, const Vector3d& vtDiag, int nZmapId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero lo Zmap const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nZmapId)) ; if ( pVZM == nullptr) return -1 ; // recupero il riferimento locale Frame3d frLoc ; if ( ! pGeomDB->GetGlobFrame( nZmapId, frLoc)) return -1 ; // porto in locale il riferimento (il vettore è già in locale a questo stesso riferimento) Frame3d frBoxL = GetFrameLocal( pGeomDB, frBox, nRefType, frLoc) ; // verifico la collisione return ( pVZM->AvoidBox( frBoxL, vtDiag, dSafeDist) ? 0 : 1) ; } //---------------------------------------------------------------------------- int ExeCDeBoxVolZmap( const Frame3d& frBox, const Vector3d& vtDiag, int nZmapId, double dSafeDist, int nRefType) { int nRes = MyCDeBoxVolZmap( frBox, vtDiag, nZmapId, dSafeDist, nRefType) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtCDeBoxVolZmap({{" + ToString( frBox.Orig()) + "},{" + ToString( frBox.VersX()) + "},{" + ToString( frBox.VersY()) + "},{" + ToString( frBox.VersZ()) + "}},{" + ToString( vtDiag) + "}," + IdToString( nZmapId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyCDeCylVolZmap( const Frame3d& frCyl, double dL, double dR, int nZmapId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero lo Zmap const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nZmapId)) ; if ( pVZM == nullptr) return -1 ; // recupero il riferimento locale Frame3d frLoc ; if ( ! pGeomDB->GetGlobFrame( nZmapId, frLoc)) return -1 ; // porto in locale il riferimento Frame3d frBoxL = GetFrameLocal( pGeomDB, frCyl, nRefType, frLoc) ; // verifico la collisione return ( pVZM->AvoidCylinder( frBoxL, dL, dR, dSafeDist) ? 0 : 1) ; } //---------------------------------------------------------------------------- int ExeCDeCylVolZmap( const Frame3d& frCyl, double dL, double dR, int nZmapId, double dSafeDist, int nRefType) { int nRes = MyCDeCylVolZmap( frCyl, dL, dR, nZmapId, dSafeDist, nRefType) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtCDeCylVolZmap({{" + ToString( frCyl.Orig()) + "},{" + ToString( frCyl.VersX()) + "},{" + ToString( frCyl.VersY()) + "},{" + ToString( frCyl.VersZ()) + "}}," + ToString( dL) + "," + ToString( dR) + "," + IdToString( nZmapId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyCDeSpheVolZmap( const Point3d& ptCen, double dRad, int nZmapId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero lo Zmap const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nZmapId)) ; if ( pVZM == nullptr) return -1 ; // recupero il riferimento locale Frame3d frLoc ; if ( ! pGeomDB->GetGlobFrame( nZmapId, frLoc)) return -1 ; // porto in locale il centro della sfera Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; // verifico la collisione return ( pVZM->AvoidSphere( ptCenL, dRad, dSafeDist) ? 0 : 1) ; } //---------------------------------------------------------------------------- int ExeCDeSpheVolZmap( const Point3d& ptCen, double dRad, int nZmapId, double dSafeDist, int nRefType) { int nRes = MyCDeSpheVolZmap( ptCen, dRad, nZmapId, dSafeDist, nRefType) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtCDeSpheVolZmap({" + ToString( ptCen) + "}," + ToString( dRad) + "," + IdToString( nZmapId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; }