2c159d7ce6
- aggiunta funzione di raffinamento dei punti di intersezione per Bezier.
136 lines
5.0 KiB
C++
136 lines
5.0 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"
|
|
#include "/EgtDev/Extern/Eigen/Dense"
|
|
|
|
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 ) {
|
|
// devo raffinare i parametri lungo la curva, l'angolo e i punti di intersezione
|
|
double dUU, dUU2, dCos ;
|
|
Point3d ptI, ptI2 ;
|
|
// devo trovare le intersezioni
|
|
Point3d ptSP, ptSP2 ;
|
|
RefinePoints( pSurfTm, InfoTm.nILTT, InfoTm.nT, ptI, ptI2,ptSP, ptSP2) ;
|
|
IntLinSbzInfo InfoBz( InfoTm.nILTT, dUU, dUU2, InfoTm.nT, dCos, InfoTm.ptI, InfoTm.ptI2, 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 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// raffino i punti di intersezione e recupero le rispettive coordinate nello spazio parametrico
|
|
bool
|
|
RefinePoints( const ISurfTriMesh* pSurfTm ,int nIL, int nT, Point3d& ptI, Point3d& ptI2, Point3d& ptSP, Point3d& ptSP2) {
|
|
int nVert[3] ;
|
|
pSurfTm->GetTriangle( nT, nVert) ;
|
|
double dU0, dV0, dU1, dV1,dU2, dV2 ;
|
|
pSurfTm->GetVertexParam( nVert[0], dU0, dV0) ;
|
|
pSurfTm->GetVertexParam( nVert[1], dU1, dV1) ;
|
|
pSurfTm->GetVertexParam( nVert[2], dU2, dV2) ;
|
|
Point3d pt0, pt1, pt2 ;
|
|
pSurfTm->GetVertex( nVert[0], pt0) ;
|
|
pSurfTm->GetVertex( nVert[1], pt1) ;
|
|
pSurfTm->GetVertex( nVert[2], pt2) ;
|
|
Eigen::Matrix3d m3x3 ;
|
|
//m3x3 << pt0.x, pt1.x, pt2.x, pt0.y, pt1.y, pt2.y, pt0.z, pt1.z, pt2.z ;
|
|
m3x3.col(0) << pt0.x, pt0.y , pt0.z ;
|
|
m3x3.col(1) << pt1.x, pt1.y , pt1.z ;
|
|
m3x3.col(2) << pt2.x, pt2.y , pt2.z ;
|
|
Eigen::Vector3d b ( ptI.x, ptI.y, ptI.z) ;
|
|
Eigen::Vector3d x = m3x3.fullPivLu().solve(b) ;
|
|
|
|
} |