EgtGeomKernel :
- aggiunta IntersSurfTmSurfTm - correzioni a HashGrids.
This commit is contained in:
+1
-3
@@ -333,9 +333,7 @@ CAvToolSurfTm::PrepareHashGrid( void)
|
||||
// calcolo il BBox del triangolo nel riferimento scelto
|
||||
Tria.ToLoc( m_frMove) ;
|
||||
BBox3d b3Tria ;
|
||||
b3Tria.Add( Tria.GetP( 0)) ;
|
||||
b3Tria.Add( Tria.GetP( 1)) ;
|
||||
b3Tria.Add( Tria.GetP( 2)) ;
|
||||
Tria.GetLocalBBox( b3Tria) ;
|
||||
// inserisco nella griglia
|
||||
if ( ! m_HGrids.Add( nT, b3Tria))
|
||||
return false ;
|
||||
|
||||
@@ -282,6 +282,8 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClCompile Include="IntersPlanePlane.cpp" />
|
||||
<ClCompile Include="IntersPlaneSurfTm.cpp" />
|
||||
<ClCompile Include="IntersPlaneTria.cpp" />
|
||||
<ClCompile Include="IntersSurfTmSurfTm.cpp" />
|
||||
<ClCompile Include="IntersTriaTria.cpp" />
|
||||
<ClCompile Include="OffsetCurve.cpp" />
|
||||
<ClCompile Include="DistPointArc.cpp" />
|
||||
<ClCompile Include="DistPointCrvAux.cpp" />
|
||||
@@ -431,6 +433,8 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClInclude Include="..\Include\EGkIntersPlanePlane.h" />
|
||||
<ClInclude Include="..\Include\EGkIntersPlaneSurfTm.h" />
|
||||
<ClInclude Include="..\Include\EGkIntersPlaneTria.h" />
|
||||
<ClInclude Include="..\Include\EGkIntersSurfTmSurfTm.h" />
|
||||
<ClInclude Include="..\Include\EGkIntersTriaTria.h" />
|
||||
<ClInclude Include="..\Include\EGkIntervals.h" />
|
||||
<ClInclude Include="..\Include\EGkLinePerpTwoCurves.h" />
|
||||
<ClInclude Include="..\Include\EGkLinePntMinDistCurve.h" />
|
||||
|
||||
@@ -384,6 +384,12 @@
|
||||
<ClCompile Include="CAvSimpleSurfFrMove.cpp">
|
||||
<Filter>File di origine\GeoCollision</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IntersSurfTmSurfTm.cpp">
|
||||
<Filter>File di origine\GeoInters</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IntersTriaTria.cpp">
|
||||
<Filter>File di origine\GeoInters</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
@@ -884,6 +890,12 @@
|
||||
<ClInclude Include="..\Include\EGkCDeBoxTria.h">
|
||||
<Filter>File di intestazione\Include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Include\EGkIntersSurfTmSurfTm.h">
|
||||
<Filter>File di intestazione\Include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Include\EGkIntersTriaTria.h">
|
||||
<Filter>File di intestazione\Include</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="EgtGeomKernel.rc">
|
||||
|
||||
+8
-8
@@ -4298,8 +4298,8 @@ GdbExecutor::LineTorusInters( const STRVECTOR& vsParams)
|
||||
if ( ! FromString( vsParams[7], dMaxRad))
|
||||
return false ;
|
||||
|
||||
std::vector<double> vdP ;
|
||||
std::vector<bool> vbT ;
|
||||
DBLVECTOR vdP ;
|
||||
BOOLVECTOR vbT ;
|
||||
int nTypeInt = LineTorus( ptLine, vtLine, ptTorus, vtTorus, dMinRad, dMaxRad, vbT, vdP) ;
|
||||
|
||||
if ( nTypeInt == T_ERROR)
|
||||
@@ -4415,8 +4415,8 @@ GdbExecutor::RayTorusInters( const STRVECTOR& vsParams)
|
||||
if ( ! FromString( vsParams[7], dMaxRad))
|
||||
return false ;
|
||||
|
||||
std::vector<double> vdP ;
|
||||
std::vector<bool> vbT ;
|
||||
DBLVECTOR vdP ;
|
||||
BOOLVECTOR vbT ;
|
||||
int nTypeInt = RayTorus( ptLine, vtLine, ptTorus, vtTorus, dMinRad, dMaxRad, vbT, vdP) ;
|
||||
|
||||
if ( nTypeInt == T_ERROR)
|
||||
@@ -4571,8 +4571,8 @@ GdbExecutor::SegmentTorusInters( const STRVECTOR& vsParams)
|
||||
if ( ! FromString( vsParams[8], dSgLen))
|
||||
return false ;
|
||||
|
||||
std::vector<double> vdP ;
|
||||
std::vector<bool> vbT ;
|
||||
DBLVECTOR vdP ;
|
||||
BOOLVECTOR vbT ;
|
||||
int nTypeInt = SegmentTorus( ptLine, vtLine, dSgLen, ptTorus, vtTorus, dMinRad, dMaxRad, vbT, vdP) ;
|
||||
|
||||
if ( nTypeInt == T_ERROR)
|
||||
@@ -4745,8 +4745,8 @@ GdbExecutor::LinCompTorusPartInters( const STRVECTOR& vsParams)
|
||||
if ( ! FromString( vsParams[9], nLinType))
|
||||
return false ;
|
||||
|
||||
std::vector<double> vdP ;
|
||||
std::vector<bool> vbT ;
|
||||
DBLVECTOR vdP ;
|
||||
BOOLVECTOR vbT ;
|
||||
int nTypeInt = LinCompTorusExtInt( ptLine, vtLine, dSgLen, nLinType, ptTorus, vtTorus, dMinRad, dMaxRad, vbT, vdP) ;
|
||||
|
||||
if ( nTypeInt == T_ERROR)
|
||||
|
||||
+10
-10
@@ -103,7 +103,7 @@ HashGrid2d::HashGrid2d( double dCellSpan)
|
||||
m_enlargementThreshold = m_xyCellCount / minimalGridDensity ;
|
||||
|
||||
// allocazione dell'array lineare che rappresenta lo hash grid.
|
||||
m_cell = new( nothrow) Cell[ m_xyCellCount] ;
|
||||
m_cell = new Cell[ m_xyCellCount] ;
|
||||
|
||||
// ogni cella è già inizializzata come vuota
|
||||
// imposto gli offset ai vicini
|
||||
@@ -203,7 +203,7 @@ HashGrid2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
int nXSpan = min( static_cast<int>( ceil( dXDim * m_dInvCellSpan)), int( m_xCellCount)) ;
|
||||
int nYSpan = min( static_cast<int>( ceil( dYDim * m_dInvCellSpan)), int( m_yCellCount)) ;
|
||||
// verifico se conviene verificare queste celle o direttamente tutte e sole quelle occupate
|
||||
if ( nXSpan < int( m_xCellCount) || nYSpan < int( m_yCellCount)) {
|
||||
if ( nXSpan * nYSpan < 5 * int( m_occupiedCells.size())) {
|
||||
// cella di base
|
||||
int nX = static_cast<int>( Hash( ptMin)) ;
|
||||
for ( int i = 0 ; i <= nXSpan ; ++ i) {
|
||||
@@ -274,7 +274,7 @@ HashGrid2d::InitNeighborOffsets( void)
|
||||
if ( x == 0 || x == (xc - 1) ||
|
||||
y == 0 || y == (yc - 1)) {
|
||||
|
||||
c->m_neighborOffset = new( nothrow) int[9] ;
|
||||
c->m_neighborOffset = new int[9] ;
|
||||
|
||||
i = 0 ;
|
||||
for ( int yy = -xc ; yy <= xc ; yy += xc) {
|
||||
@@ -352,7 +352,7 @@ HashGrid2d::Add( HashGrids2d::ObjData& obj, Cell* cell)
|
||||
// reserved). Furthermore, the cell must be inserted into the grid-global vector 'm_occupiedCells'
|
||||
// in which all cells that are currently occupied by bodies are recorded.
|
||||
else {
|
||||
cell->m_Objs = new( nothrow) HashGrids2d::PtrObjVector ;
|
||||
cell->m_Objs = new HashGrids2d::PtrObjVector ;
|
||||
cell->m_Objs->reserve( cellVectorSize) ;
|
||||
|
||||
obj.nCellId = 0 ;
|
||||
@@ -441,7 +441,7 @@ HashGrid2d::Enlarge( void)
|
||||
m_enlargementThreshold = m_xyCellCount / minimalGridDensity ;
|
||||
|
||||
// ... a new linear array of cells representing this enlarged hash grid is allocated and ...
|
||||
m_cell = new( nothrow) Cell[ m_xyCellCount] ;
|
||||
m_cell = new Cell[ m_xyCellCount] ;
|
||||
|
||||
// ... initialized, and finally ...
|
||||
InitNeighborOffsets() ;
|
||||
@@ -616,8 +616,8 @@ HashGrids2d::Update( void)
|
||||
double dCellSpan = pGrid->GetCellSpan() ;
|
||||
|
||||
if ( dSize >= dCellSpan || dSize < ( dCellSpan / hierarchyFactor)) {
|
||||
pGrid->Remove( Obj) ;
|
||||
addGrid( Obj) ;
|
||||
pGrid->Remove( Obj) ;
|
||||
addGrid( Obj) ;
|
||||
}
|
||||
else {
|
||||
pGrid->Update( Obj) ;
|
||||
@@ -695,7 +695,7 @@ HashGrids2d::addGrid( ObjData& obj)
|
||||
// If no hash grid yet exists in the hierarchy, an initial hash grid is created
|
||||
// based on the body's size.
|
||||
|
||||
pGrid = new( nothrow) HashGrid2d( size * sqrt( hierarchyFactor)) ;
|
||||
pGrid = new HashGrid2d( size * sqrt( hierarchyFactor)) ;
|
||||
}
|
||||
else {
|
||||
// Check the hierarchy for a hash grid with suitably sized cells - if such a grid does not
|
||||
@@ -711,7 +711,7 @@ HashGrids2d::addGrid( ObjData& obj)
|
||||
if ( size < cellSpan ) {
|
||||
while ( size < cellSpan)
|
||||
cellSpan /= hierarchyFactor ;
|
||||
pGrid = new( nothrow) HashGrid2d( cellSpan * hierarchyFactor) ;
|
||||
pGrid = new HashGrid2d( cellSpan * hierarchyFactor) ;
|
||||
m_GridList.insert( g, pGrid) ;
|
||||
}
|
||||
|
||||
@@ -724,7 +724,7 @@ HashGrids2d::addGrid( ObjData& obj)
|
||||
|
||||
while ( size >= cellSpan)
|
||||
cellSpan *= hierarchyFactor ;
|
||||
pGrid = new( nothrow) HashGrid2d( cellSpan) ;
|
||||
pGrid = new HashGrid2d( cellSpan) ;
|
||||
}
|
||||
|
||||
pGrid->Add( obj) ;
|
||||
|
||||
+24
-24
@@ -20,15 +20,15 @@
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const size_t xCellCount = 16 ;
|
||||
const size_t yCellCount = 16 ;
|
||||
const size_t zCellCount = 16 ;
|
||||
const size_t cellVectorSize = 16 ;
|
||||
const size_t occupiedCellsVectorSize = 256 ;
|
||||
const size_t minimalGridDensity = 8 ;
|
||||
const size_t gridActivationThreshold = 64 ;
|
||||
const double hierarchyFactor = 2 ;
|
||||
const double MIN_CELL_SIZE = 50.0 ;
|
||||
const size_t xCellCount = 16 ;
|
||||
const size_t yCellCount = 16 ;
|
||||
const size_t zCellCount = 16 ;
|
||||
const size_t cellVectorSize = 16 ;
|
||||
const size_t occupiedCellsVectorSize = 256 ;
|
||||
const size_t minimalGridDensity = 8 ;
|
||||
const size_t gridActivationThreshold = 64 ;
|
||||
const double hierarchyFactor = 2 ;
|
||||
const double MIN_CELL_SIZE = 25.0 ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// HashGrid3d
|
||||
@@ -110,7 +110,7 @@ HashGrid3d::HashGrid3d( double dCellSpan)
|
||||
m_enlargementThreshold = m_xyzCellCount / minimalGridDensity ;
|
||||
|
||||
// allocazione dell'array lineare che rappresenta lo hash grid.
|
||||
m_cell = new( nothrow) Cell[ m_xyzCellCount] ;
|
||||
m_cell = new Cell[ m_xyzCellCount] ;
|
||||
|
||||
// ogni cella è già inizializzata come vuota
|
||||
// imposto gli offset ai vicini
|
||||
@@ -212,7 +212,7 @@ HashGrid3d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
int nYSpan = min( static_cast<int>( ceil( dYDim * m_dInvCellSpan)), int( m_yCellCount)) ;
|
||||
int nZSpan = min( static_cast<int>( ceil( dZDim * m_dInvCellSpan)), int( m_zCellCount)) ;
|
||||
// verifico se conviene verificare queste celle o direttamente tutte e sole quelle occupate
|
||||
if ( nXSpan < int( m_xCellCount) || nYSpan < int( m_yCellCount) || nZSpan < int( m_zCellCount)) {
|
||||
if ( nXSpan * nYSpan * nZSpan < 5 * int( m_occupiedCells.size())) {
|
||||
// cella di base
|
||||
int nX = static_cast<int>( Hash( ptMin)) ;
|
||||
for ( int i = 0 ; i <= nXSpan ; ++ i) {
|
||||
@@ -243,7 +243,7 @@ HashGrid3d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
// inserisco in lista gli oggetti della cella
|
||||
if ( cell->m_Objs != nullptr) {
|
||||
for ( auto pObj : *(cell->m_Objs)) {
|
||||
if ( b3Test.OverlapsXY( pObj->box))
|
||||
if ( b3Test.Overlaps( pObj->box))
|
||||
vnIds.push_back( pObj->nId) ;
|
||||
}
|
||||
}
|
||||
@@ -294,7 +294,7 @@ HashGrid3d::InitNeighborOffsets( void)
|
||||
y == 0 || y == (yc - 1) ||
|
||||
z == 0 || z == (zc - 1)) {
|
||||
|
||||
c->m_neighborOffset = new( nothrow) int[27] ;
|
||||
c->m_neighborOffset = new int[27] ;
|
||||
|
||||
i = 0 ;
|
||||
for ( int zz = -xyc; zz <= xyc; zz += xyc ) {
|
||||
@@ -485,7 +485,7 @@ HashGrid3d::Enlarge( void)
|
||||
m_enlargementThreshold = m_xyzCellCount / minimalGridDensity ;
|
||||
|
||||
// ... a new linear array of cells representing this enlarged hash grid is allocated and ...
|
||||
m_cell = new( nothrow) Cell[ m_xyzCellCount] ;
|
||||
m_cell = new Cell[ m_xyzCellCount] ;
|
||||
|
||||
// ... initialized, and finally ...
|
||||
InitNeighborOffsets() ;
|
||||
@@ -510,10 +510,10 @@ HashGrid3d::PowerOfTwo( size_t number)
|
||||
HashGrids3d::HashGrids3d( void)
|
||||
{
|
||||
try {
|
||||
// Finchè il numero di oggetti non supera la soglia non si usano le griglie
|
||||
m_nonGridObjs.reserve( gridActivationThreshold) ;
|
||||
m_bActivate = true ;
|
||||
m_bGridActive = false ;
|
||||
// Finchè il numero di oggetti non supera la soglia non si usano le griglie
|
||||
m_nonGridObjs.reserve( gridActivationThreshold) ;
|
||||
m_bActivate = true ;
|
||||
m_bGridActive = false ;
|
||||
}
|
||||
catch(...) {
|
||||
LOG_ERROR( GetEGkLogger(), "Error in HashGrids3d constructor") ;
|
||||
@@ -659,8 +659,8 @@ HashGrids3d::Update( void)
|
||||
double dCellSpan = pGrid->GetCellSpan() ;
|
||||
|
||||
if ( dSize >= dCellSpan || dSize < ( dCellSpan / hierarchyFactor)) {
|
||||
pGrid->Remove( Obj) ;
|
||||
addGrid( Obj) ;
|
||||
pGrid->Remove( Obj) ;
|
||||
addGrid( Obj) ;
|
||||
}
|
||||
else {
|
||||
pGrid->Update( Obj) ;
|
||||
@@ -728,7 +728,7 @@ HashGrids3d::addGrid( ObjData& obj)
|
||||
obj.box.GetDiameter( size) ;
|
||||
|
||||
// If the body is finite in size, it must be assigned to a grid with suitably sized cells.
|
||||
if ( size > 0) {
|
||||
if ( size > - EPS_ZERO) {
|
||||
|
||||
size = max( size, MIN_CELL_SIZE) ;
|
||||
|
||||
@@ -738,7 +738,7 @@ HashGrids3d::addGrid( ObjData& obj)
|
||||
// If no hash grid yet exists in the hierarchy, an initial hash grid is created
|
||||
// based on the body's size.
|
||||
|
||||
pGrid = new( nothrow) HashGrid3d( size * sqrt( hierarchyFactor)) ;
|
||||
pGrid = new HashGrid3d( size * sqrt( hierarchyFactor)) ;
|
||||
}
|
||||
else {
|
||||
// Check the hierarchy for a hash grid with suitably sized cells - if such a grid does not
|
||||
@@ -754,7 +754,7 @@ HashGrids3d::addGrid( ObjData& obj)
|
||||
if ( size < cellSpan ) {
|
||||
while ( size < cellSpan)
|
||||
cellSpan /= hierarchyFactor ;
|
||||
pGrid = new( nothrow) HashGrid3d( cellSpan * hierarchyFactor) ;
|
||||
pGrid = new HashGrid3d( cellSpan * hierarchyFactor) ;
|
||||
m_GridList.insert( g, pGrid) ;
|
||||
}
|
||||
|
||||
@@ -767,7 +767,7 @@ HashGrids3d::addGrid( ObjData& obj)
|
||||
|
||||
while ( size >= cellSpan)
|
||||
cellSpan *= hierarchyFactor ;
|
||||
pGrid = new( nothrow) HashGrid3d( cellSpan) ;
|
||||
pGrid = new HashGrid3d( cellSpan) ;
|
||||
}
|
||||
|
||||
pGrid->Add( obj) ;
|
||||
|
||||
+51
-65
@@ -1,9 +1,9 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2015
|
||||
// EgalTech 2017-2018
|
||||
//----------------------------------------------------------------------------
|
||||
// File : Tool.h Data : 01.12.17 Versione : ???1.6a4
|
||||
// File : IntersLineSurfStd.cpp Data : 01.12.17 Versione : 1.9h3
|
||||
// Contenuto : Implementazione delle funzioni di intersezione
|
||||
// superficie e componente lineare
|
||||
// componente lineare e superficie standard.
|
||||
//
|
||||
//
|
||||
// Modifiche : 22.01.15 DS Creazione modulo.
|
||||
@@ -12,8 +12,10 @@
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "IntersLineSurfStd.h"
|
||||
#include "/EgtDev/Include/EGkFrame3d.h"
|
||||
#include "/EgtDev/Include//ENkPolynomialRoots.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -23,33 +25,27 @@ LineDisc( const Point3d& ptPLine, const Vector3d& vtVLine,
|
||||
const Point3d& ptPDisc, const Vector3d& vtVDisc, double dRad,
|
||||
double& dU1, double& dU2)
|
||||
{
|
||||
int nIntType ;
|
||||
// Se il raggio non è significativamente
|
||||
// maggiore di zero, vi è un errore.
|
||||
if ( dRad < EPS_SMALL) {
|
||||
nIntType = D_ERROR_INT ;
|
||||
return nIntType ;
|
||||
}
|
||||
// Il raggio del disco deve essere non nullo.
|
||||
if ( dRad < EPS_SMALL)
|
||||
return D_ERROR_INT ;
|
||||
// Si richiede che i vettori siano normalizzati
|
||||
if ( ! ( vtVDisc.IsNormalized() && vtVLine.IsNormalized())) {
|
||||
nIntType = D_ERROR_INT ;
|
||||
return nIntType ;
|
||||
}
|
||||
if ( ! vtVDisc.IsNormalized() || ! vtVLine.IsNormalized())
|
||||
return D_ERROR_INT ;
|
||||
|
||||
vector <double> vdCoef(3) ;
|
||||
vector <double> vdRoots ;
|
||||
|
||||
// Setto i coefficienti dell'equazione di itersezione fra retta e sfera,
|
||||
// dallo studio di queste intersezioni e di quella col piano si del disco si deduce
|
||||
// la posizione reciproca fra retta e disco
|
||||
DBLVECTOR vdCoef( 3) ;
|
||||
vdCoef[0] = ( ptPLine - ptPDisc).SqLen() - dRad * dRad ;
|
||||
vdCoef[1] = 2 * ( ptPLine - ptPDisc) * vtVLine ;
|
||||
vdCoef[2] = 1 ;
|
||||
|
||||
// Soluzione dell'equazione
|
||||
DBLVECTOR vdRoots ;
|
||||
int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ;
|
||||
|
||||
// Studio delle soluzioni
|
||||
int nIntType ;
|
||||
// Non vi sono intersezioni
|
||||
if ( nRoot == 0)
|
||||
nIntType = D_NO_INTERS ;
|
||||
@@ -193,14 +189,12 @@ LineSphere( const Point3d& ptPLine, const Vector3d& vtVLine,
|
||||
const Point3d& ptSphC, double dRad,
|
||||
double& dU1, double& dU2)
|
||||
{
|
||||
int nIntType = S_ERROR_INT ;
|
||||
// Se il raggio non è significativamente
|
||||
// maggiore di zero, vi è un errore.
|
||||
// Il raggio della sfera deve essere non nullo.
|
||||
if ( dRad < EPS_SMALL)
|
||||
return nIntType ;
|
||||
return S_ERROR_INT ;
|
||||
// Si richiede che il vettore sia normalizzato
|
||||
if ( ! vtVLine.IsNormalized())
|
||||
return nIntType ;
|
||||
return S_ERROR_INT ;
|
||||
|
||||
// Vettore congiungente il punto della retta con il centro della sfera
|
||||
Vector3d vtR = ( ptSphC - ptPLine) - ( ptSphC - ptPLine) * vtVLine * vtVLine ;
|
||||
@@ -208,6 +202,8 @@ LineSphere( const Point3d& ptPLine, const Vector3d& vtVLine,
|
||||
double dSqRad = dRad * dRad ;
|
||||
// Quadrato della distanza punto retta
|
||||
double dSqDist = vtR * vtR ;
|
||||
// Studio delle soluzioni
|
||||
int nIntType ;
|
||||
// Retta esterna
|
||||
if ( dSqDist > dSqRad + 2 * dRad * EPS_SMALL)
|
||||
nIntType = S_NO_INTERS ;
|
||||
@@ -314,15 +310,14 @@ LineSemiSphere( const Point3d& ptPLine, const Vector3d& vtVLine,
|
||||
double& dU1, double& dU2)
|
||||
{
|
||||
int nIntType = LineSphere( ptPLine, vtVLine, ptSphC, dRad, dU1, dU2) ;
|
||||
if ( nIntType == S_ERROR_INT || ( ! vtSSphOrient.IsNormalized()))
|
||||
if ( nIntType == S_ERROR_INT || ! vtSSphOrient.IsNormalized())
|
||||
return S_ERROR_INT ;
|
||||
// Un punto di tangenza
|
||||
if ( nIntType == S_ONE_INT_TAN) {
|
||||
Point3d ptInt = ptPLine + dU1 * vtVLine ;
|
||||
Vector3d vtInt = ptInt - ptSphC ;
|
||||
vtInt.Normalize() ;
|
||||
// Se il punto di contatto è nella calotta superiore
|
||||
// Scarto la soluzione
|
||||
// Se il punto di contatto è nella calotta superiore : scarto la soluzione
|
||||
if ( vtInt * vtSSphOrient > EPS_ZERO)
|
||||
nIntType = S_NO_INTERS ;
|
||||
}
|
||||
@@ -527,17 +522,17 @@ IntersLineInfiniteCylinder( const Point3d& ptPLine, const Vector3d& vtVLine,
|
||||
return CC_NO_INTERS ;
|
||||
}
|
||||
|
||||
// Caso generico
|
||||
int nIntType ;
|
||||
vector<double> vdCoef(3) ;
|
||||
vector<double> vdRoots ;
|
||||
// Setto i coefficienti dell'equazione
|
||||
DBLVECTOR vdCoef( 3) ;
|
||||
vdCoef[0] = ( ptPLine - ptPCyl).SqLen() - ( ( ptPLine - ptPCyl) * vtVCyl) * ( ( ptPLine - ptPCyl) * vtVCyl)
|
||||
- dCylRad * dCylRad ;
|
||||
vdCoef[1] = 2 * ( ( ptPLine - ptPCyl) * vtVLine - ( ( ptPLine - ptPCyl) * vtVCyl) * ( vtVCyl * vtVLine) ) ;
|
||||
vdCoef[2] = 1 - ( vtVCyl * vtVLine) * ( vtVCyl * vtVLine) ;
|
||||
// Risolvo l'equazione
|
||||
DBLVECTOR vdRoots ;
|
||||
int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ;
|
||||
// Studio delle soluzioni
|
||||
int nIntType ;
|
||||
// Non ci sono intersezioni
|
||||
if ( nRoot == 0)
|
||||
nIntType = CC_NO_INTERS ;
|
||||
@@ -995,26 +990,16 @@ LineInfiniteCone( const Point3d& ptPLine, const Vector3d& vtDLine,
|
||||
const Point3d& ptVCone, const Vector3d& vtDCone, double dConeRad, double dConeHeigth,
|
||||
double& dU1, double& dU2)
|
||||
{
|
||||
int nIntType ;
|
||||
// Raggio e altezza del cono devono essere maggiori di zero
|
||||
if ( ! ( dConeRad > EPS_SMALL && dConeHeigth > EPS_SMALL)) {
|
||||
nIntType = CC_ERROR_INT ;
|
||||
return nIntType ;
|
||||
}
|
||||
// Tangnte dell'angolo semi-apertura del cono
|
||||
double dTanTheta = dConeRad / dConeHeigth ;
|
||||
// Il coseno deve essere positivo
|
||||
if ( ! ( dTanTheta > 0 && dTanTheta * dTanTheta < 1 / ( EPS_SMALL * EPS_SMALL) - 1)) {
|
||||
nIntType = CC_ERROR_INT ;
|
||||
return nIntType ;
|
||||
}
|
||||
|
||||
if ( dConeRad < EPS_SMALL || dConeHeigth < EPS_SMALL)
|
||||
return CC_ERROR_INT ;
|
||||
// Si richiede che i vettori siano normalizzati
|
||||
if ( ! ( vtDCone.IsNormalized() && vtDLine.IsNormalized())) {
|
||||
nIntType = CC_ERROR_INT ;
|
||||
return nIntType ;
|
||||
}
|
||||
|
||||
if ( ! vtDCone.IsNormalized() || ! vtDLine.IsNormalized())
|
||||
return CC_ERROR_INT ;
|
||||
|
||||
// Tangente dell'angolo semi-apertura del cono
|
||||
double dTanTheta = dConeRad / dConeHeigth ;
|
||||
|
||||
// Lunghezze delle componenti parallela e ortogonale del
|
||||
// vettore della retta rispetto all'asse del cilindro.
|
||||
double dDLong = vtDLine * vtDCone ;
|
||||
@@ -1037,8 +1022,7 @@ LineInfiniteCone( const Point3d& ptPLine, const Vector3d& vtDLine,
|
||||
dU1 = - INFINITO ;
|
||||
dU2 = vtOO * vtDLine ;
|
||||
}
|
||||
nIntType = CC_INF_INT ;
|
||||
return nIntType ;
|
||||
return CC_INF_INT ;
|
||||
}
|
||||
// Vertice del cono non sta sulla retta
|
||||
else {
|
||||
@@ -1059,9 +1043,8 @@ LineInfiniteCone( const Point3d& ptPLine, const Vector3d& vtDLine,
|
||||
}
|
||||
}
|
||||
|
||||
vector <double> vdCoef(3) ;
|
||||
vector <double> vdRoots ;
|
||||
// Setto i coefficienti dell'equazione
|
||||
DBLVECTOR vdCoef( 3) ;
|
||||
vdCoef[0] = ( ptPLine - ptVCone) * ( ptPLine - ptVCone) -
|
||||
( 1 + dTanTheta * dTanTheta) * ( ( ptPLine - ptVCone) * vtDCone) * ( ( ptPLine - ptVCone) * vtDCone) ;
|
||||
vdCoef[1] = 2 * ( vtDLine * ( ptPLine - ptVCone) -
|
||||
@@ -1069,8 +1052,11 @@ LineInfiniteCone( const Point3d& ptPLine, const Vector3d& vtDLine,
|
||||
vdCoef[2] = 1 - ( 1 + dTanTheta * dTanTheta) * ( vtDCone * vtDLine) * ( vtDCone * vtDLine) ;
|
||||
|
||||
// Risolvo l'equazione
|
||||
DBLVECTOR vdRoots ;
|
||||
int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ;
|
||||
|
||||
// Studio le soluzioni
|
||||
int nIntType ;
|
||||
if ( nRoot == 0)
|
||||
nIntType = CC_NO_INTERS ;
|
||||
else if ( nRoot == 1) {
|
||||
@@ -1622,28 +1608,26 @@ SegmentTruncatedCone( const Point3d& ptPLine, const Vector3d& vtDLine, double dS
|
||||
int
|
||||
LineTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
vector<bool>& vbType, vector<double>& vdPar)
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar)
|
||||
{
|
||||
int nIntType = T_ERROR ;
|
||||
// Si richiede che i vettori siano normalizzati
|
||||
if ( ! ( vtAxTorus.IsNormalized() && vtLine.IsNormalized()))
|
||||
return nIntType ;
|
||||
// I Raggi devono essere positivi e sufficientemente diversi
|
||||
if ( dMinRad < EPS_SMALL || dMaxRad < dMinRad + EPS_SMALL)
|
||||
return nIntType ;
|
||||
return T_ERROR ;
|
||||
// Si richiede che i vettori siano normalizzati
|
||||
if ( ! vtAxTorus.IsNormalized() || ! vtLine.IsNormalized())
|
||||
return T_ERROR ;
|
||||
|
||||
Point3d ptLn = ptLine ;
|
||||
Vector3d vtLn = vtLine ;
|
||||
// Sistema di riferimento del toro
|
||||
Frame3d frTorusFrame ;
|
||||
frTorusFrame.Set( ptOTorus, vtAxTorus) ;
|
||||
// Porto la retta nel sistema di riferimento del toro
|
||||
Point3d ptLn = ptLine ;
|
||||
ptLn.ToLoc( frTorusFrame) ;
|
||||
Vector3d vtLn = vtLine ;
|
||||
vtLn.ToLoc( frTorusFrame) ;
|
||||
|
||||
vector <double> vdCoef(5) ;
|
||||
vector <double> vdRoots ;
|
||||
// Setto i coefficienti dell'equazione
|
||||
DBLVECTOR vdCoef( 5) ;
|
||||
double dSqDistPO = ptLn.x * ptLn.x + ptLn.y * ptLn.y + ptLn.z * ptLn.z ;
|
||||
double dPtVt = ptLn.x * vtLn.x + ptLn.y * vtLn.y + ptLn.z * vtLn.z ;
|
||||
double dSqMaxR = dMaxRad * dMaxRad ;
|
||||
@@ -1657,6 +1641,7 @@ LineTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
vdCoef[4] = 1 ;
|
||||
|
||||
// Risolvo l'equazione e ridimensiono il vettore dei parametri
|
||||
DBLVECTOR vdRoots ;
|
||||
PolynomialRoots( 4, vdCoef, vdRoots) ;
|
||||
vdPar = vdRoots ;
|
||||
|
||||
@@ -1670,6 +1655,7 @@ LineTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
}
|
||||
|
||||
// Studio le soluzioni
|
||||
int nIntType = T_ERROR ;
|
||||
if ( vdPar.size() == 0)
|
||||
nIntType = T_NO_INT ;
|
||||
else if ( vdPar.size() == 1) {
|
||||
@@ -1775,7 +1761,7 @@ LineTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
int
|
||||
RayTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
vector<bool>& vbType, vector<double>& vdPar)
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar)
|
||||
{
|
||||
int nIntType = LineTorus( ptLine, vtLine, ptOTorus, vtAxTorus, dMinRad, dMaxRad, vbType, vdPar) ;
|
||||
if ( nIntType == T_ERROR || nIntType == T_NO_INT)
|
||||
@@ -1861,7 +1847,7 @@ RayTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
int
|
||||
SegmentTorus( const Point3d& ptLine, const Vector3d& vtLine, double dSgLen,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
vector<bool>& vbType, vector<double>& vdPar)
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar)
|
||||
{
|
||||
int nIntType = LineTorus( ptLine, vtLine, ptOTorus, vtAxTorus, dMinRad, dMaxRad, vbType, vdPar) ;
|
||||
if ( nIntType == T_ERROR || nIntType == T_NO_INT)
|
||||
@@ -1949,7 +1935,7 @@ SegmentTorus( const Point3d& ptLine, const Vector3d& vtLine, double dSgLen,
|
||||
int
|
||||
LinCompTorusExtInt( const Point3d& ptLine, const Vector3d& vtLine, double dSgLen, int nLinType,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
vector<bool>& vbType, vector<double>& vdPar)
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar)
|
||||
{
|
||||
int nIntType ;
|
||||
// Retta
|
||||
|
||||
+5
-9
@@ -13,11 +13,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "/EgtDev/Include/EGkPoint3d.h"
|
||||
#include "/EgtDev/Include/EGkVector3d.h"
|
||||
#include "/EgtDev/Include/EGkFrame3d.h"
|
||||
#include "/EgtDev/Include/ENkPolynomialRoots.h"
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include "/EgtDev//Include/EgtNumCollection.h"
|
||||
|
||||
// In tutte le funzioni dichiarate i punti e i vettori che definiscono gli oggetti geometrici
|
||||
// devono essere espressi nel medesimo sistema di riferimento. I vettori devono essere normalizzati.
|
||||
@@ -270,24 +266,24 @@ enum LinCompTorusIntersType { T_ERROR = - 1, T_NO_INT = 0, T_ONE_TAN = 1, T_ONE_
|
||||
// Punti e vettori devono essere espressi nel medesimo sistema di riferimento.
|
||||
int LineTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
std::vector<bool>& vbType, std::vector<double>& vdPar) ; //double dU1, double dU2, double dU3, double dU4) ;
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar) ; //double dU1, double dU2, double dU3, double dU4) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int RayTorus( const Point3d& ptLine, const Vector3d& vtLine,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
std::vector<bool>& vbType, std::vector<double>& vdPar) ;
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int SegmentTorus( const Point3d& ptLine, const Vector3d& vtLine, double dSgLen,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
std::vector<bool>& vbType, std::vector<double>& vdPar) ;
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Valuta la posizione reciproca fra un componente lineare e la parte inferiore
|
||||
// ed esterna rispetto al centro di una superficie torica.
|
||||
int LinCompTorusExtInt( const Point3d& ptLine, const Vector3d& vtLine, double dSgLen, int nLinType,
|
||||
const Point3d& ptOTorus, const Vector3d& vtAxTorus, double dMinRad, double dMaxRad,
|
||||
std::vector<bool>& vbType, std::vector<double>& vdPar) ;
|
||||
BOOLVECTOR& vbType, DBLVECTOR& vdPar) ;
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ IntersCoplanarLineTria( const Point3d& ptL, const Vector3d& vtL, double dLen, co
|
||||
}
|
||||
}
|
||||
}
|
||||
// altrimenti due vertici giaccio da una parte e uno da quella opposta
|
||||
// altrimenti due vertici giacciono da una parte e uno da quella opposta
|
||||
else {
|
||||
// Determino le intersezioni
|
||||
int nCount = 0 ;
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ IntersPlaneTria( const Plane3d& plPlane, const Triangle3d& trTria, Point3d& ptIn
|
||||
|
||||
// interseco la linea con il triangolo (giace nel suo piano)
|
||||
int nRes = IntersCoplanarLineTria( ptL, vtL, 100.0, trTria, ptInt, ptInt2, false) ;
|
||||
switch( nRes) {
|
||||
switch ( nRes) {
|
||||
case ILTT_NO : return IPTT_NO ;
|
||||
case ILTT_SEGM : return IPTT_YES ;
|
||||
case ILTT_SEGM_ON_EDGE : return IPTT_EDGE ;
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2018-2018
|
||||
//----------------------------------------------------------------------------
|
||||
// File : IntersSurfTmSurfTm.cpp Data : 27.08.18 Versione : 1.9h3
|
||||
// Contenuto : Implementazione della intersezione tra due superfici trimesh.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 27.08.18 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "HashGrids3d.h"
|
||||
#include "DistPointLine.h"
|
||||
#include "IntersLineTria.h"
|
||||
#include "DllMain.h"
|
||||
#include "/EgtDev/Include/EGkIntersSurfTmSurfTm.h"
|
||||
#include "/EgtDev/Include/EGkIntersTriaTria.h"
|
||||
#include "/EgtDev/Include/EGkPointGrid3d.h"
|
||||
#include "/EgtDev/Include/EGkDistPointTria.h"
|
||||
#include "/EgtDev/Include/EgnStringUtils.h"
|
||||
#include <array>
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Intersezione di due superficie TriMesh
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
IntersSurfTmSurfTm( const ISurfTriMesh& Stm1, const ISurfTriMesh& Stm2,
|
||||
PNTVECTOR& vPnt, BIPNTVECTOR& vBpt, TRIA3DVECTOR& vTria)
|
||||
{
|
||||
// verifico superfici
|
||||
if ( &Stm1 == nullptr || ! Stm1.IsValid() || &Stm2 == nullptr || ! Stm2.IsValid())
|
||||
return false ;
|
||||
// verifico parametri di ritorno
|
||||
if ( &vPnt == nullptr || &vBpt == nullptr || &vTria == nullptr)
|
||||
return false ;
|
||||
vPnt.clear() ;
|
||||
vBpt.clear() ;
|
||||
vTria.clear() ;
|
||||
|
||||
// per ricerca veloce di punti ripetuti
|
||||
PointGrid3d PtGrid ;
|
||||
PtGrid.Init( 100) ;
|
||||
|
||||
// per ricerca veloce di linee ripetute
|
||||
HashGrids3d LnGrid ;
|
||||
LnGrid.SetActivationGrid( true) ;
|
||||
|
||||
// per ricerca veloce di triangoli ripetuti
|
||||
HashGrids3d TrGrid ;
|
||||
TrGrid.SetActivationGrid( true) ;
|
||||
|
||||
// creo HashGrids3d per superficie con maggior numero di elementi
|
||||
int nTriaNbr1 = Stm1.GetTriangleCount() ;
|
||||
int nTriaNbr2 = Stm2.GetTriangleCount() ;
|
||||
bool bHash1 = ( nTriaNbr1 > nTriaNbr2) ;
|
||||
HashGrids3d HHGrids ;
|
||||
const int LIM_SRFNBRSQUARED = 4095 ;
|
||||
HHGrids.SetActivationGrid( long long( nTriaNbr1) * long long(nTriaNbr2) > LIM_SRFNBRSQUARED) ;
|
||||
Triangle3d Tria ;
|
||||
int nT = ( bHash1 ? Stm1.GetFirstTriangle( Tria) : Stm2.GetFirstTriangle( Tria)) ;
|
||||
while ( nT != SVT_NULL) {
|
||||
BBox3d boxT ;
|
||||
Tria.GetLocalBBox( boxT) ;
|
||||
if ( ! HHGrids.Add( nT, boxT))
|
||||
return false ;
|
||||
nT = ( bHash1 ? Stm1.GetNextTriangle( nT, Tria) : Stm2.GetNextTriangle( nT, Tria)) ;
|
||||
}
|
||||
if ( ! HHGrids.Update())
|
||||
return false ;
|
||||
|
||||
// cerco i triangoli che si intersecano
|
||||
Triangle3d TriaA ;
|
||||
int nTA = ( bHash1 ? Stm2.GetFirstTriangle( TriaA) : Stm1.GetFirstTriangle( TriaA)) ;
|
||||
while ( nTA != SVT_NULL) {
|
||||
BBox3d boxA ;
|
||||
TriaA.GetLocalBBox( boxA) ;
|
||||
INTVECTOR vnIds ;
|
||||
if ( HHGrids.Find( boxA, vnIds)) {
|
||||
for ( int h = 0 ; h < int( vnIds.size()) ; ++ h) {
|
||||
int nB = vnIds[h] ;
|
||||
Triangle3d TriaB ;
|
||||
if ( bHash1 ? Stm1.GetTriangle( nB, TriaB) : Stm2.GetTriangle( nB, TriaB)) {
|
||||
// intersezione tra i triangoli
|
||||
Point3d ptInt, ptInt2 ;
|
||||
PNTVECTOR vPnt ;
|
||||
int nRes = IntersTriaTria( TriaA, TriaB, ptInt, ptInt2, vPnt) ;
|
||||
// se punto
|
||||
if ( nRes == ITTT_VERT || nRes == ITTT_PNT) {
|
||||
// verifico se punto già inserito
|
||||
int nId ;
|
||||
if ( ! PtGrid.Find( ptInt, 10 * EPS_SMALL, nId)) {
|
||||
vPnt.emplace_back( ptInt) ;
|
||||
PtGrid.InsertPoint( ptInt, int( vPnt.size()) - 1) ;
|
||||
}
|
||||
}
|
||||
// se altrimenti segmento
|
||||
else if ( nRes == ITTT_EDGE || nRes == ITTT_YES) {
|
||||
// se abbastanza lungo
|
||||
if ( ! AreSamePointApprox( ptInt, ptInt2)) {
|
||||
// verifico se già inserito
|
||||
bool bFound = false ;
|
||||
BBox3d b3Line( ptInt, ptInt2) ;
|
||||
INTVECTOR vnIds ;
|
||||
if ( LnGrid.Find( b3Line, vnIds)) {
|
||||
for ( int i = 0 ; i < int( vnIds.size()) ; ++ i) {
|
||||
int nA = vnIds[i] ;
|
||||
const Point3d& ptOth = vBpt[nA].first ;
|
||||
const Point3d& ptOth2 = vBpt[nA].second ;
|
||||
if ( ( AreSamePointEpsilon( ptInt, ptOth, 10 * EPS_SMALL) &&
|
||||
AreSamePointEpsilon( ptInt2, ptOth2, 10 * EPS_SMALL)) ||
|
||||
( AreSamePointEpsilon( ptInt, ptOth2, 10 * EPS_SMALL) &&
|
||||
AreSamePointEpsilon( ptInt2, ptOth, 10 * EPS_SMALL))) {
|
||||
bFound = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
// se non inserito, procedo
|
||||
if ( ! bFound) {
|
||||
vBpt.emplace_back( ptInt, ptInt2) ;
|
||||
LnGrid.Add( int( vBpt.size()) - 1, b3Line) ;
|
||||
LnGrid.Update() ;
|
||||
}
|
||||
}
|
||||
}
|
||||
// se altrimenti sovrapposizione
|
||||
else if ( nRes == ITTT_OVERLAPS) {
|
||||
//// verifico se triangolo già inserito
|
||||
// bool bFound = false ;
|
||||
// BBox3d b3Tria( Tria.GetP( 0), Tria.GetP( 1)) ;
|
||||
// b3Tria.Add( Tria.GetP( 2)) ;
|
||||
// INTVECTOR vnIds ;
|
||||
// if ( TrGrid.Find( b3Tria, vnIds)) {
|
||||
// for ( int i = 0 ; i < int( vnIds.size()) ; ++ i) {
|
||||
// int nA = vnIds[i] ;
|
||||
// const Triangle3d& trOth = vTria[nA] ;
|
||||
// array< bool, 3> bOth = { false, false, false} ;
|
||||
// for ( int j = 0 ; j < 3 ; ++ j) {
|
||||
// for ( int k = 0 ; k < 3 ; ++ k) {
|
||||
// if ( ! bOth[k])
|
||||
// bOth[k] = AreSamePointEpsilon( Tria.GetP( j), trOth.GetP( k), 10 * EPS_SMALL) ;
|
||||
// }
|
||||
// }
|
||||
// if ( bOth[0] && bOth[1] && bOth[2]) {
|
||||
// bFound = true ;
|
||||
// break ;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//// se non inserito, procedo
|
||||
// if ( ! bFound) {
|
||||
// vTria.emplace_back( Tria) ;
|
||||
// TrGrid.Add( int( vTria.size()) - 1, b3Tria) ;
|
||||
// TrGrid.Update() ;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// passo al prossimo triangolo
|
||||
nTA = ( bHash1 ? Stm2.GetNextTriangle( nTA, TriaA) : Stm1.GetNextTriangle( nTA, TriaA)) ;
|
||||
}
|
||||
|
||||
// rimuovo i punti che stanno sui segmenti
|
||||
for ( int i = int( vPnt.size()) - 1 ; i >= 0 ; -- i) {
|
||||
bool bFound = false ;
|
||||
BBox3d b3Pnt( vPnt[i]) ;
|
||||
b3Pnt.Expand( 10 * EPS_SMALL) ;
|
||||
INTVECTOR vnIds ;
|
||||
if ( LnGrid.Find( b3Pnt, vnIds)) {
|
||||
for ( int j = 0 ; j < int( vnIds.size()) ; ++ j) {
|
||||
int nA = vnIds[j] ;
|
||||
double dSqDist ;
|
||||
if ( DistPointLine( vPnt[i], vBpt[nA].first, vBpt[nA].second).GetSqDist( dSqDist) && dSqDist < 100 * SQ_EPS_SMALL) {
|
||||
bFound = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( bFound)
|
||||
vPnt.erase( vPnt.begin() + i) ;
|
||||
}
|
||||
|
||||
// rimuovo i punti che stanno sui triangoli
|
||||
for ( int i = int( vPnt.size()) - 1 ; i >= 0 ; -- i) {
|
||||
bool bFound = false ;
|
||||
BBox3d b3Pnt( vPnt[i]) ;
|
||||
b3Pnt.Expand( 10 * EPS_SMALL) ;
|
||||
INTVECTOR vnIds ;
|
||||
if ( TrGrid.Find( b3Pnt, vnIds)) {
|
||||
for ( int j = 0 ; j < int( vnIds.size()) ; ++ j) {
|
||||
int nA = vnIds[j] ;
|
||||
const Triangle3d& trOth = vTria[nA] ;
|
||||
double dSqDist ;
|
||||
if ( DistPointTriangle( vPnt[i], trOth).GetSqDist( dSqDist) && dSqDist < 100 * SQ_EPS_SMALL) {
|
||||
bFound = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( bFound)
|
||||
vPnt.erase( vPnt.begin() + i) ;
|
||||
}
|
||||
|
||||
// rimuovo i segmenti che stanno sui triangoli
|
||||
for ( int i = int( vBpt.size()) - 1 ; i >= 0 ; -- i) {
|
||||
bool bFound = false ;
|
||||
Point3d ptStart = vBpt[i].first ;
|
||||
Point3d ptEnd = vBpt[i].second ;
|
||||
BBox3d b3Line( ptStart, ptEnd) ;
|
||||
INTVECTOR vnIds ;
|
||||
if ( TrGrid.Find( b3Line, vnIds)) {
|
||||
for ( int j = 0 ; j < int( vnIds.size()) ; ++ j) {
|
||||
int nA = vnIds[j] ;
|
||||
const Triangle3d& trOth = vTria[nA] ;
|
||||
Point3d ptInt, ptInt2 ;
|
||||
if ( IntersLineTria( ptStart, ptEnd, trOth, ptInt, ptInt2) == ILTT_SEGM_ON_EDGE) {
|
||||
bFound = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( bFound)
|
||||
vBpt.erase( vBpt.begin() + i) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2018-2018
|
||||
//----------------------------------------------------------------------------
|
||||
// File : IntersTriaTria.cpp Data : 27.08.18 Versione : 1.9h3
|
||||
// Contenuto : Implementazione della intersezione triangolo/triangolo.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 27.08.18 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "ProjPlane.h"
|
||||
#include "IntersLineTria.h"
|
||||
#include "/EgtDev/Include/EGkIntersTriaTria.h"
|
||||
#include "/EgtDev/Include/EGkIntersPlanePlane.h"
|
||||
#include <array>
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static int IntersCoplanarTriaTria( const Triangle3d& trTria1, const Triangle3d& trTria2, PNTVECTOR& vPnt) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
IntersTriaTria( const Triangle3d& trTria1, const Triangle3d& trTria2, Point3d& ptInt, Point3d& ptInt2, PNTVECTOR& vPnt)
|
||||
{
|
||||
// piano del secondo triangolo
|
||||
Plane3d plTria2 ;
|
||||
plTria2.Set( trTria2.GetCentroid(), trTria2.GetN()) ;
|
||||
// calcolo le distanze dei vertici del primo triangolo dal piano del secondo
|
||||
array< double, 3> vDist1 ;
|
||||
for ( int i = 0 ; i < 3 ; ++i)
|
||||
vDist1[i] = DistPointPlane( trTria1.GetP( i), plTria2) ;
|
||||
// verifico posizione del primo triangolo rispetto al piano del secondo
|
||||
int nVertPos1 = 0 ; int nVertNeg1 = 0 ;
|
||||
for ( const auto& dDist : vDist1) {
|
||||
if ( dDist > EPS_SMALL)
|
||||
++ nVertPos1 ;
|
||||
else if ( dDist < -EPS_SMALL)
|
||||
++ nVertNeg1 ;
|
||||
}
|
||||
// se il triangolo giace tutto da una parte del piano, nessuna intersezione
|
||||
if ( nVertPos1 == 3 || nVertNeg1 == 3)
|
||||
return ITTT_NO ;
|
||||
|
||||
// piano del primo triangolo
|
||||
Plane3d plTria1 ;
|
||||
plTria1.Set( trTria1.GetCentroid(), trTria1.GetN()) ;
|
||||
// calcolo le distanze dei vertici del secondo triangolo dal piano del primo
|
||||
array< double, 3> vDist2 ;
|
||||
for ( int i = 0 ; i < 3 ; ++i)
|
||||
vDist2[i] = DistPointPlane( trTria2.GetP( i), plTria1) ;
|
||||
// verifico posizione del secondo triangolo rispetto al piano del primo
|
||||
int nVertPos2 = 0 ; int nVertNeg2 = 0 ;
|
||||
for ( const auto& dDist : vDist2) {
|
||||
if ( dDist > EPS_SMALL)
|
||||
++ nVertPos2 ;
|
||||
else if ( dDist < -EPS_SMALL)
|
||||
++ nVertNeg2 ;
|
||||
}
|
||||
// se il triangolo giace tutto da una parte del piano, nessuna intersezione
|
||||
if ( nVertPos2 == 3 || nVertNeg2 == 3)
|
||||
return ITTT_NO ;
|
||||
|
||||
// se i triangoli sono complanari
|
||||
if ( ( nVertPos1 == 0 && nVertNeg1 == 0) || ( nVertPos2 == 0 && nVertNeg2 == 0))
|
||||
return IntersCoplanarTriaTria( trTria1, trTria2, vPnt) ;
|
||||
|
||||
// intersezione tra i piani dei due triangoli
|
||||
Point3d ptL1 ; Vector3d vtL1 ;
|
||||
if ( IntersPlanePlane( plTria1, plTria2, ptL1, vtL1) != IPPT_YES)
|
||||
return ITTT_NO ;
|
||||
|
||||
// limito la linea di intersezione con il primo triangolo
|
||||
int nRes1 = IntersCoplanarLineTria( ptL1, vtL1, 100.0, trTria1, ptInt, ptInt2, false) ;
|
||||
switch ( nRes1) {
|
||||
case ILTT_SEGM :
|
||||
case ILTT_SEGM_ON_EDGE :
|
||||
break ;
|
||||
case ILTT_VERT :
|
||||
return ( PointInTria( ptInt, trTria2) ? ITTT_VERT : ITTT_NO) ;
|
||||
default :
|
||||
return ITTT_NO ;
|
||||
}
|
||||
|
||||
// il segmento calcolato va limitato col secondo triangolo
|
||||
Point3d ptL2 = ptInt ;
|
||||
Vector3d vtL2 = ptInt2 - ptInt ;
|
||||
double dLen = vtL2.Len() ;
|
||||
vtL2 /= dLen ;
|
||||
int nRes2 = IntersCoplanarLineTria( ptL2, vtL2, dLen, trTria2, ptInt, ptInt2, true) ;
|
||||
switch( nRes2) {
|
||||
case ILTT_NO : return ITTT_NO ;
|
||||
case ILTT_SEGM : return ITTT_YES ;
|
||||
case ILTT_SEGM_ON_EDGE : return ITTT_EDGE ;
|
||||
case ILTT_VERT : return ITTT_VERT ;
|
||||
case ILTT_EDGE : return ITTT_PNT ;
|
||||
default : return ITTT_NO ;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// interseco il primo triangolo con il piano del secondo
|
||||
Plane3d plPlane2 ;
|
||||
plPlane2.Set( trTria2.GetCentroid(), trTria2.GetN()) ;
|
||||
int nPtRes = IntersPlaneTria( plPlane2, trTria1, ptInt, ptInt2) ;
|
||||
// se non c'è intersezione
|
||||
if ( nPtRes == IPTT_NO)
|
||||
return ITTT_NO ;
|
||||
// se altrimenti complanari
|
||||
else if ( nPtRes == IPTT_OVERLAPS)
|
||||
return IntersCoplanarTriaTria( trTria1, trTria2, vPnt) ;
|
||||
// se intersezione in un vertice
|
||||
else if ( nPtRes == IPTT_VERT) {
|
||||
// se l'intersezione sta anche nel secondo triangolo
|
||||
if ( PointInTria( ptInt, trTria2))
|
||||
return ITTT_VERT ;
|
||||
else
|
||||
return ITTT_NO ;
|
||||
}
|
||||
// altrimenti è un segmento, va limitato col secondo triangolo
|
||||
Point3d ptL = ptInt ;
|
||||
Vector3d vtL = ptInt2 - ptInt ;
|
||||
double dLen = vtL.Len() ;
|
||||
vtL /= dLen ;
|
||||
int nRes = IntersCoplanarLineTria( ptL, vtL, dLen, trTria2, ptInt, ptInt2, true) ;
|
||||
switch( nRes) {
|
||||
case ILTT_NO : return ITTT_NO ;
|
||||
case ILTT_SEGM : return ITTT_YES ;
|
||||
case ILTT_SEGM_ON_EDGE : return ITTT_EDGE ;
|
||||
case ILTT_VERT : return ITTT_VERT ;
|
||||
case ILTT_EDGE : return ITTT_PNT ;
|
||||
default : return ITTT_NO ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
IntersCoplanarTriaTria( const Triangle3d& trTria1, const Triangle3d& trTria2, PNTVECTOR& vPnt)
|
||||
{
|
||||
// !!! PROVVISORIO !!!
|
||||
return ITTT_NO ;
|
||||
}
|
||||
+3
-6
@@ -248,8 +248,7 @@ PolyLine::Split( double dU, PolyLine& PL)
|
||||
// pulisco la polilinea destinazione
|
||||
PL.Clear() ;
|
||||
// ricerca del punto in cui dividere
|
||||
PNTULIST::const_iterator iter ;
|
||||
iter = m_lUPoints.begin() ;
|
||||
auto iter = m_lUPoints.cbegin() ;
|
||||
while ( iter != m_lUPoints.end() && iter->second < ( dU + EPS_PARAM))
|
||||
++ iter ;
|
||||
if ( iter == m_lUPoints.end())
|
||||
@@ -270,10 +269,8 @@ PolyLine::GetLocalBBox( BBox3d& b3Loc) const
|
||||
{
|
||||
// assegno il box in locale, scorrendo tutti i punti
|
||||
b3Loc.Reset() ;
|
||||
for ( PNTULIST::const_iterator iter = m_lUPoints.begin() ;
|
||||
iter != m_lUPoints.end() ;
|
||||
++ iter)
|
||||
b3Loc.Add( iter->first) ;
|
||||
for each ( const auto& UPnt in m_lUPoints)
|
||||
b3Loc.Add( UPnt.first) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
+14
-7
@@ -564,12 +564,20 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d&
|
||||
bool
|
||||
VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs, const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe)
|
||||
{
|
||||
// Controllo definizione vettori direzione
|
||||
if ( vtDs.IsSmall() || vtDe.IsSmall())
|
||||
return false ;
|
||||
// Controllo sull'effettiva esistenza del movimento
|
||||
if ( AreSamePointApprox( ptPs, ptPe) && AreSameVectorApprox( vtDs, vtDe))
|
||||
if ( AreSamePointApprox( ptPs, ptPe) && AreSameVectorApprox( vtDs, vtDe))
|
||||
return true ;
|
||||
// Se utensile chisel o mortise, controllo definizione vettori ausiliari
|
||||
if ( m_Tool.GetType() == Tool::MORTISER || m_Tool.GetType() == Tool::CHISEL) {
|
||||
if ( vtAs.IsSmall() || vtAe.IsSmall())
|
||||
return false ;
|
||||
}
|
||||
|
||||
// Punti nei sistemi di riferimento intrinseci dello Zmap
|
||||
Point3d ptLs[3] ;
|
||||
// Punti nei sistemi di riferimento intrinseci dello Zmap
|
||||
Point3d ptLs[3] ;
|
||||
Point3d ptLe[3] ;
|
||||
|
||||
ptLs[0] = ptPs ;
|
||||
@@ -2961,7 +2969,6 @@ bool
|
||||
VolZmap::Chs_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux)
|
||||
{
|
||||
// Proiezione della traiettoria sul piano dei movimenti possibili
|
||||
Point3d ptSp = ptS ;
|
||||
Vector3d vtMoveOnP = ( ptE - ptS) - ( ptE - ptS) * vtToolDir * vtToolDir ;
|
||||
Point3d ptProjE = ptS + vtMoveOnP ;
|
||||
|
||||
@@ -4690,7 +4697,7 @@ VolZmap::CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double
|
||||
Vector3d vtN1, vtN2 ;
|
||||
|
||||
// Solido nella posizione iniziale
|
||||
if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, ptInt2, vtN1, vtN2)) {
|
||||
if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, ptInt2, vtN1, vtN2)) {
|
||||
double dMin, dMax ;
|
||||
Vector3d vtNmin, vtNmax ;
|
||||
if ( ptInt1.z < ptInt2.z) {
|
||||
@@ -4710,7 +4717,7 @@ VolZmap::CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double
|
||||
}
|
||||
|
||||
// Solido nella posizione finale
|
||||
if ( IntersLineMyPolyhedron( ptC - vtMove, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, ptInt2, vtN1, vtN2)) {
|
||||
if ( IntersLineMyPolyhedron( ptC - vtMove, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, ptInt2, vtN1, vtN2)) {
|
||||
double dMin, dMax ;
|
||||
Vector3d vtNmin, vtNmax ;
|
||||
if ( ptInt1.z < ptInt2.z) {
|
||||
@@ -4730,7 +4737,7 @@ VolZmap::CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double
|
||||
}
|
||||
|
||||
// Volume spazzato nel moto
|
||||
if ( IntersLineMyPolyhedron( ptC, Z_AX, MotionFrame, dDimOrt, dLenZ, dDimLong, dDeltaLong, ptInt1, ptInt2, vtN1, vtN2)) {
|
||||
if ( IntersLineMyPolyhedron( ptC, Z_AX, MotionFrame, dDimOrt, dLenZ, dDimLong, dDeltaLong, ptInt1, ptInt2, vtN1, vtN2)) {
|
||||
double dMin, dMax ;
|
||||
Vector3d vtNmin, vtNmax ;
|
||||
if ( ptInt1.z < ptInt2.z) {
|
||||
|
||||
Reference in New Issue
Block a user