From 06b8c000fd6fa513074cae1b389f186e66aef30e Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 11 Dec 2018 09:24:42 +0000 Subject: [PATCH] EgtGeomKernel 1.9l2 : - aggiunta DistPointSurfTm - corretta IntersLineSurfTm - migliorato IdManager in UpdateMaxId. --- DistPointSurfTm.cpp | 116 ++++++++++++++++++++++++++++++++++ DistPointTria.cpp | 2 +- EgtGeomKernel.rc | Bin 11718 -> 11718 bytes EgtGeomKernel.vcxproj | 1 + EgtGeomKernel.vcxproj.filters | 3 + IdManager.h | 4 ++ IntersLineSurfTm.cpp | 2 +- 7 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 DistPointSurfTm.cpp diff --git a/DistPointSurfTm.cpp b/DistPointSurfTm.cpp new file mode 100644 index 0000000..5114be3 --- /dev/null +++ b/DistPointSurfTm.cpp @@ -0,0 +1,116 @@ +//---------------------------------------------------------------------------- +// EgalTech 2018-2018 +//---------------------------------------------------------------------------- +// File : EGkDistPointTria.h Data : 11.12.18 Versione : 1.9l2 +// Contenuto : Implementazione della classe distanza Punto da Trimesh. +// +// +// +// Modifiche : 07.12.18 LM Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "stdafx.h" +#include "SurfTriMesh.h" +#include "/EgtDev/Include/EGkTriangle3d.h" +#include "/EgtDev/Include/EGkDistPointTria.h" +#include "/EgtDev/Include/EGkDistPointSurfTm.h" +#include + +using namespace std ; + +//---------------------------------------------------------------------------- +DistPointSurfTm::DistPointSurfTm( const Point3d& ptP, const ISurfTriMesh& tmSurf) +{ + // Trimesh non valida + if ( &tmSurf == nullptr || ! tmSurf.IsValid()) { + m_dDist = - 1. ; + return ; + } + // Calcolo la distanza + Calculate( ptP, tmSurf) ; +} + +//---------------------------------------------------------------------------- +void +DistPointSurfTm::Calculate( const Point3d& ptP, const ISurfTriMesh& tmSurf) +{ + // Box locale della superficie + BBox3d boxS ; + boxS = tmSurf.GetAllTriaBox() ; + if ( boxS.IsEmpty()) { + m_dDist = - 1. ; + return ; + } + + // Determino i triangoli vicini + Point3d ptMin, ptMax ; + boxS.GetMinMax( ptMin, ptMax) ; + double dDeltaLen = min( min( ptMax.x - ptMin.x, ptMax.y - ptMin.y), ptMax.z - ptMin.z) / 10. ; + double dBoxHalfLenX = min( abs( ptP.x - ptMin.x), abs( ptP.x - ptMax.x)) + dDeltaLen ; + double dBoxHalfLenY = min( abs( ptP.y - ptMin.y), abs( ptP.y - ptMax.y)) + dDeltaLen ; + double dBoxHalfLenZ = min( abs( ptP.z - ptMin.z), abs( ptP.z - ptMax.z)) + dDeltaLen ; + BBox3d boxP( ptP, dBoxHalfLenX, dBoxHalfLenY, dBoxHalfLenZ) ; + INTVECTOR vnIds ; + while ( ! tmSurf.GetAllTriaOverlapBox( boxP, vnIds)) + boxP.Expand( dDeltaLen) ; + + // Fra i triangoli vicini cerco quello di minima distanza + double dDist = DBL_MAX ; + int nMinDistIndex = SVT_NULL ; + Point3d ptMinDistPoint ; + for ( size_t t = 0 ; t < vnIds.size() ; ++ t) { + Triangle3d trCurTria ; + tmSurf.GetTriangle( vnIds[t], trCurTria) ; + DistPointTriangle DistPointTria( ptP, trCurTria) ; + double dCurDist ; + if ( DistPointTria.GetDist( dCurDist)) { + if ( dCurDist < dDist) { + dDist = dCurDist ; + nMinDistIndex = vnIds[t] ; + DistPointTria.GetMinDistPoint( ptMinDistPoint) ; + } + } + } + + m_dDist = dDist ; + m_nMinDistTriaIndex = nMinDistIndex ; + m_ptMinDistPoint = ptMinDistPoint ; +} + +//---------------------------------------------------------------------------- +bool +DistPointSurfTm::GetDist( double& dDist) +{ + // Distanza non valida + if ( m_dDist < -EPS_ZERO) + return false ; + // Distanza valida + dDist = m_dDist ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +DistPointSurfTm::GetMinDistPoint( Point3d& ptMinDistPoint) +{ + // Distanza non valida + if ( m_dDist < -EPS_ZERO) + return false ; + // Distanza valida + ptMinDistPoint = m_ptMinDistPoint ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +DistPointSurfTm::GetMinDistTriaIndex( int& nMinDistIndex) +{ + // Distanza non valida + if ( m_dDist < -EPS_ZERO) + return false ; + // Distanza valida + nMinDistIndex = m_nMinDistTriaIndex ; + return true ; +} diff --git a/DistPointTria.cpp b/DistPointTria.cpp index 087baaf..272eb00 100644 --- a/DistPointTria.cpp +++ b/DistPointTria.cpp @@ -50,7 +50,7 @@ DistPointTriangle::Calculate( const Point3d& ptP, const Triangle3d& Tria) // Determino la minima distanza dai tre lati for ( int i = 0 ; i < 3 ; ++ i) { - DistPointLine dstPL( ptQ, Tria.GetP( i), Tria.GetP( ( i + 1) % 3)) ; + DistPointLine dstPL( ptP, Tria.GetP( i), Tria.GetP( ( i + 1) % 3)) ; double dSqDist ; if ( dstPL.GetSqDist( dSqDist) && ( m_dSqDist < 0 || dSqDist < m_dSqDist)) { m_dSqDist = dSqDist ; diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 94a930b045a3aecb29b68d368a456506392b659c..bfe00a4392112675be6cc7c01ca7eb395ef63768 100644 GIT binary patch delta 110 zcmX>WeJpyzA2vp#&G-4vGfl1&(wY2&Q;pGRvZAo=W*@FeEMOU1X1ItOWeJpyzA2vqA&G-4vGfl1&(wY2&Q;pGZvZAo=W*@FeEMOU1X1ItO + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 7f3ff20..d182915 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -390,6 +390,9 @@ File di origine\GeoInters + + File di origine\GeoDist + diff --git a/IdManager.h b/IdManager.h index 15f7ea0..8921530 100644 --- a/IdManager.h +++ b/IdManager.h @@ -57,6 +57,10 @@ class IdManager m_nMaxId = nId ; } void UpdateMaxId( void) { int nMaxId = 0 ; + if ( m_GdbIdMap.find( m_nMaxId - 1) != m_GdbIdMap.end()) { + -- m_nMaxId ; + return ; + } for (const auto& Igdbo : m_GdbIdMap) nMaxId = std::max( nMaxId, Igdbo.first) ; m_nMaxId = nMaxId ; } diff --git a/IntersLineSurfTm.cpp b/IntersLineSurfTm.cpp index c09556b..a05edd0 100644 --- a/IntersLineSurfTm.cpp +++ b/IntersLineSurfTm.cpp @@ -96,7 +96,7 @@ IntersLineSurfTm( const Point3d& ptL, const Vector3d& vtL, double dLen, const IS Vector3d vtStep = dLenEff / nStep * vtL ; INTVECTOR vPrevT ; for ( int i = 0 ; i < nStep ; ++ i) { - BBox3d b3Box( ptL + i * vtStep, ptL + ( i + 1) * vtStep) ; + BBox3d b3Box( ptStart + i * vtStep, ptStart + ( i + 1) * vtStep) ; INTVECTOR vT ; if ( Stm.GetAllTriaOverlapBox( b3Box, vT)) { for ( auto nT : vT) {