From b4058ad363290a6f2f25804bfc7b2c4990fc5203 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Thu, 8 Feb 2024 09:28:49 +0100 Subject: [PATCH] EgtGeomKernel : - aggiunta delle intersezioni tra linee e SupBez. --- EgtGeomKernel.vcxproj | 2 + IntersLineSurfBez.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++ IntersLineSurfBez.h | 1 + SurfTriMesh.h | 2 - 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 IntersLineSurfBez.cpp create mode 100644 IntersLineSurfBez.h diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 8c884bb..ebcb8d6 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -309,6 +309,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -449,6 +450,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/IntersLineSurfBez.cpp b/IntersLineSurfBez.cpp new file mode 100644 index 0000000..080d110 --- /dev/null +++ b/IntersLineSurfBez.cpp @@ -0,0 +1,108 @@ +//---------------------------------------------------------------------------- +// 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 ; +} \ No newline at end of file diff --git a/IntersLineSurfBez.h b/IntersLineSurfBez.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/IntersLineSurfBez.h @@ -0,0 +1 @@ +#pragma once diff --git a/SurfTriMesh.h b/SurfTriMesh.h index 12e4efe..e78f3f5 100644 --- a/SurfTriMesh.h +++ b/SurfTriMesh.h @@ -257,9 +257,7 @@ class SurfTriMesh : public ISurfTriMesh, public IGeoObjRW bool GetVertex( int nId, Point3d& ptP) const override ; bool GetVertexParam( int nId, double& dU, double& dV) const override ; int GetFirstVertex( Point3d& ptP) const override ; - int GetFirstVertexParam( int nId, double& dU, double& dV) const override ; int GetNextVertex( int nId, Point3d& ptP) const override ; - int GetNextVertexParam( int nId, double& dU, double& dV) const override ; bool GetTriangle( int nId, int nIdVert[3]) const override ; int GetFirstTriangle( int nIdVert[3]) const override ; int GetNextTriangle( int nId, int nIdVert[3]) const override ;