b4058ad363
- aggiunta delle intersezioni tra linee e SupBez.
108 lines
3.6 KiB
C++
108 lines
3.6 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2024
|
|
//----------------------------------------------------------------------------
|
|
// File : IntersLineSurfBez.cpp Data : 06.02.24 Versione : 2.6b1
|
|
// Contenuto : Implementazione della intersezione linea/superficie bezier.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 06.02.24 DB Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "IntersLineBox.h"
|
|
#include "/EgtDev/Include/EGkIntersLineTria.h"
|
|
#include "/EgtDev/Include/EGkIntersLineSurfTm.h"
|
|
#include "/EgtDev/Include/EGkIntersLineSurfBez.h"
|
|
#include "/EgtDev/Include/EGkSurfBezier.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Intersezione di una linea con una superficie TriMesh
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
IntersLineSurfBz( const Point3d& ptL, const Vector3d& vtL, double dLen, const ISurfBezier& SBz,
|
|
ILSBIVECTOR& vInfo, bool bFinite)
|
|
{
|
|
// verifico linea
|
|
Vector3d vtDir = vtL ;
|
|
if ( ! vtDir.Normalize( EPS_ZERO))
|
|
return false ;
|
|
// verifico superficie
|
|
if ( &SBz == nullptr)
|
|
return false ;
|
|
// verifico parametro di ritorno
|
|
if ( &vInfo == nullptr)
|
|
return false ;
|
|
vInfo.clear() ;
|
|
|
|
// trovo le intersezioni con la trimesh ausiliaria
|
|
const ISurfTriMesh* pSurfTm = SBz.GetAuxSurf() ;
|
|
ILSIVECTOR vInfoTm ;
|
|
if ( ! IntersLineSurfTm( ptL, vtL, dLen, *pSurfTm, vInfoTm, bFinite))
|
|
return false ;
|
|
|
|
// ricavo le intersezioni con la superficie di Bezier
|
|
for ( IntLinStmInfo InfoTm : vInfoTm ) {
|
|
int nIL, nTT ;
|
|
double dUU, dUU2, dCos ;
|
|
Point3d ptP, ptP2, ptSP, ptSP2 ;
|
|
IntLinSbzInfo InfoBz( InfoTm.nILTT, dUU, dUU2, nTT, dCos, ptP, ptP2, ptSP, ptSP2) ;
|
|
vInfo.emplace_back( InfoBz) ;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////// interlineSurfTm
|
|
|
|
|
|
// limito la linea al box dei triangoli della superficie
|
|
BBox3d b3Stm = Stm.GetAllTriaBox() ;
|
|
if ( b3Stm.IsEmpty())
|
|
return false ;
|
|
// lo ingrandisco per non avere problemi con faccia piana su piani canonici
|
|
b3Stm.Expand( 10 * EPS_SMALL) ;
|
|
double dU1, dU2 ;
|
|
if ( ! IntersLineBox( ptL, vtL, b3Stm.GetMin() , b3Stm.GetMax(), dU1, dU2))
|
|
return true ;
|
|
if ( bFinite) {
|
|
dU1 = max( dU1, 0.) ;
|
|
dU2 = min( dU2, dLen) ;
|
|
if ( dU2 - dU1 < EPS_SMALL)
|
|
return true ;
|
|
}
|
|
Point3d ptStart = ptL + dU1 * vtL ;
|
|
double dLenEff = dU2 - dU1 ;
|
|
// cerco i triangoli intersecati dalla linea
|
|
const double BOX_STEP = 10 ;
|
|
int nStep = int( ceil( dLenEff / BOX_STEP)) ;
|
|
Vector3d vtStep = dLenEff / nStep * vtL ;
|
|
INTVECTOR vPrevT ;
|
|
for ( int i = 0 ; i < nStep ; ++ i) {
|
|
BBox3d b3Box( ptStart + i * vtStep, ptStart + ( i + 1) * vtStep) ;
|
|
INTVECTOR vT ;
|
|
if ( Stm.GetAllTriaOverlapBox( b3Box, vT)) {
|
|
for ( auto nT : vT) {
|
|
if ( find( vPrevT.begin(), vPrevT.end(), nT) == vPrevT.end()) {
|
|
vPrevT.emplace_back( nT) ;
|
|
Triangle3d Tria ;
|
|
Stm.GetTriangle( nT, Tria) ;
|
|
// aggiorno info con intersezione
|
|
UpdateInfoIntersLineSurfTm( ptL, vtDir, dLen, nT, Tria, vInfo, bFinite) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ordino il vettore delle eventuali intersezioni secondo il senso crescente del parametro di linea
|
|
OrderInfoIntersLineSurfTm( vInfo) ;
|
|
|
|
return true ;
|
|
|
|
//////////////////////////////////////////////////////// interlineSurfTm
|
|
|
|
|
|
return true ;
|
|
} |