//---------------------------------------------------------------------------- // EgalTech 2018-2018 //---------------------------------------------------------------------------- // File : EXE_GeoDist.cpp Data : 15.12.18 Versione : 1.9l // Contenuto : Funzioni di distanza tra oggetto geometrici per EXE. // // // // Modifiche : 15.12.18 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Const.h" #include "EXE_Macro.h" #include "AuxTools.h" #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkDistPointCurve.h" #include "/EgtDev/Include/EGkDistPointSurfTm.h" #include "/EgtDev/Include/EGkDistPointSurfBz.h" using namespace std ; //---------------------------------------------------------------------------- bool ExePointCurveDist( const Point3d& ptP, int nCurveId, int nRefType, double* pdDist, Point3d& ptMin, double* pdU) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico il primo parametro di ritorno obbligatorio if ( pdDist == nullptr) return false ; // recupero la curva ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nCurveId)) ; if ( pCurve == nullptr) return false ; // recupero il suo riferimento globale Frame3d frCurve ; if ( ! pGeomDB->GetGlobFrame( nCurveId, frCurve)) return false ; // porto il punto nel riferimento della curva Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frCurve) ; // calcolo la minima distanza DistPointCurve distPC( ptPL, *pCurve) ; // recupero i risultati if ( ! distPC.GetDist( *pdDist)) return false ; MinDistPCInfo aInfo ; if ( ! distPC.GetMinDistInfo( 0, aInfo)) return false ; if ( &ptMin != nullptr) ptMin = GetPointInRef( pGeomDB, aInfo.ptQ, frCurve, nRefType) ; if ( pdU != nullptr) *pdU = aInfo.dPar ; return true ; } //---------------------------------------------------------------------------- bool ExePointCurveDistSide( const Point3d& ptP, int nCurveId, const Vector3d& vtN, int nRefType, double* pdDist, Point3d& ptMin, int* pnSide) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico i parametri di ritorno if ( pdDist == nullptr || &ptMin == nullptr || pnSide == nullptr) return false ; // recupero la curva ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nCurveId)) ; if ( pCurve == nullptr) return false ; // recupero il suo riferimento globale Frame3d frCurve ; if ( ! pGeomDB->GetGlobFrame( nCurveId, frCurve)) return false ; // porto il punto e la normale nel riferimento della curva Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frCurve) ; Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frCurve) ; // calcolo la minima distanza DistPointCurve distPC( ptPL, *pCurve) ; // recupero i risultati if ( ! distPC.GetDist( *pdDist)) return false ; Point3d ptMinL ; int nFlag ; if ( ! distPC.GetMinDistPoint( 0, ptMinL, nFlag)) return false ; ptMin = GetPointInRef( pGeomDB, ptMinL, frCurve, nRefType) ; return distPC.GetSideAtMinDistPoint( 0, vtNL, *pnSide) ; } //---------------------------------------------------------------------------- bool ExePointSurfTmDist( const Point3d& ptP, int nStmId, int nRefType, double* pdDist, Point3d& ptMin, int* pnTria) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico il primo parametro di ritorno obbligatorio if ( pdDist == nullptr) return false ; // recupero la superficie trimesh ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nStmId)) ; if ( pStm == nullptr) return false ; // recupero il suo riferimento globale Frame3d frStm ; if ( ! pGeomDB->GetGlobFrame( nStmId, frStm)) return false ; // porto il punto nel riferimento della superficie Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frStm) ; // recupero i risultati DistPointSurfTm distPS( ptPL, *pStm) ; if ( ! distPS.GetDist( *pdDist)) return false ; Point3d ptMinL ; if ( ! distPS.GetMinDistPoint( ptMinL)) return false ; ptMin = GetPointInRef( pGeomDB, ptMinL, frStm, nRefType) ; return distPS.GetMinDistTriaIndex( *pnTria) ; } //---------------------------------------------------------------------------- bool ExePointSurfBzDist( const Point3d& ptP, int nSbzId, int nRefType, double* pdDist, Point3d& ptMin, Vector3d& vtN) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico il primo parametro di ritorno obbligatorio if ( pdDist == nullptr) return false ; // recupero la superficie bezier ISurfBezier* pSbz = GetSurfBezier( pGeomDB->GetGeoObj( nSbzId)) ; if ( pSbz == nullptr) return false ; // recupero il suo riferimento globale Frame3d frSbz ; if ( ! pGeomDB->GetGlobFrame( nSbzId, frSbz)) return false ; // porto il punto nel riferimento della superficie Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frSbz) ; // recupero i risultati DistPointSurfBz distPS( ptPL, *pSbz) ; if ( ! distPS.GetDist( *pdDist)) return false ; Point3d ptMinL ; if ( ! distPS.GetMinDistPoint( ptMinL)) return false ; ptMin = GetPointInRef( pGeomDB, ptMinL, frSbz, nRefType) ; Vector3d vtNL ; if ( ! distPS.GetNorm( vtNL)) return false ; vtN = GetVectorInRef( pGeomDB, vtNL, frSbz, nRefType) ; return true ; }