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 94a930b..bfe00a4 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 6a89a9e..64b4702 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -276,6 +276,7 @@ copy $(TargetPath) \EgtProg\Dll64 + 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) {