EgtGeomKernel 1.9l2 :
- aggiunta DistPointSurfTm - corretta IntersLineSurfTm - migliorato IdManager in UpdateMaxId.
This commit is contained in:
@@ -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 <cmath>
|
||||
|
||||
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 ;
|
||||
}
|
||||
Reference in New Issue
Block a user