EgtGeomKernel :
- aggiunta HashGrids3d a SurfTm con lazy evaluation - in CAvTool aggiunta verifica utensile ben definito.
This commit is contained in:
+51
-19
@@ -1,7 +1,7 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2015
|
||||
// EgalTech 2015-2018
|
||||
//----------------------------------------------------------------------------
|
||||
// File : HashGrids2d.cpp Data : 04.07.15 Versione : 1.6g1
|
||||
// File : HashGrids2d.cpp Data : 07.12.18 Versione : 1.9l1
|
||||
// Contenuto : Funzioni della classe HashGrids2d.
|
||||
//
|
||||
//
|
||||
@@ -13,8 +13,9 @@
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "HashGrids2d.h"
|
||||
#include "DllMain.h"
|
||||
#include "/EgtDev/Include/EGkHashGrids2d.h"
|
||||
#include "/EgtDev/Include/EgnStringUtils.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std ;
|
||||
@@ -24,7 +25,7 @@ const size_t xCellCount = 16 ;
|
||||
const size_t yCellCount = 16 ;
|
||||
const size_t cellVectorSize = 16 ;
|
||||
const size_t occupiedCellsVectorSize = 256 ;
|
||||
const size_t minimalGridDensity = 8 ;
|
||||
const size_t minimalGridDensity = 1 ;
|
||||
const size_t gridActivationThreshold = 64 ;
|
||||
const double hierarchyFactor = 2 ;
|
||||
const double MIN_CELL_SIZE = 5.0 ;
|
||||
@@ -86,6 +87,8 @@ class HashGrid2d
|
||||
size_t m_objCount ; // Numero di oggetti presenti in questa griglia
|
||||
|
||||
int m_stdNeighborOffset[9] ; // Array degli offset standard per le adiacenze
|
||||
|
||||
BBox3d m_b3Grid ; // Box totale degli oggetti inseriti in questa griglia
|
||||
} ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -145,8 +148,10 @@ HashGrid2d::Add( HashGrids2d::ObjData& obj)
|
||||
// ... insert the body into the corresponding cell.
|
||||
Cell* pCell = m_cell + h ;
|
||||
Add( obj, pCell) ;
|
||||
|
||||
++ m_objCount ;
|
||||
|
||||
// Aggiorno box di griglia
|
||||
m_b3Grid.Add( obj.box) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -157,7 +162,6 @@ HashGrid2d::Remove( HashGrids2d::ObjData& obj)
|
||||
// cell from which this body will be removed.
|
||||
Cell* pCell = m_cell + obj.nHash ;
|
||||
Remove( obj, pCell) ;
|
||||
|
||||
-- m_objCount ;
|
||||
}
|
||||
|
||||
@@ -184,25 +188,38 @@ HashGrid2d::Update( HashGrids2d::ObjData& obj)
|
||||
// ... stored in the cell that corresponds to the new hash value.
|
||||
pCell = m_cell + newHash ;
|
||||
Add( obj, pCell) ;
|
||||
|
||||
// Aggiorno box di griglia
|
||||
m_b3Grid.Add( obj.box) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
HashGrid2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
{
|
||||
// recupero gli estremi del box
|
||||
// Limito il box a quello di griglia
|
||||
BBox3d b3Int ;
|
||||
if ( ! b3Test.FindIntersectionXY( m_b3Grid, b3Int))
|
||||
return ;
|
||||
|
||||
// Recupero gli estremi del box
|
||||
Point3d ptMin ;
|
||||
double dXDim, dYDim, dZDim ;
|
||||
if ( ! b3Test.GetMinDim( ptMin, dXDim, dYDim, dZDim))
|
||||
if ( ! b3Int.GetMinDim( ptMin, dXDim, dYDim, dZDim))
|
||||
return ;
|
||||
// sposto p.to minimo in meno di una cella (oggetti possono occupare 2 celle) e allargo tutto di EPS_SMALL
|
||||
// Sposto p.to minimo in meno di una cella (oggetti possono occupare 2 celle) e allargo tutto di EPS_SMALL
|
||||
ptMin -= Vector3d( 1, 1, 0) * ( m_dCellSpan + EPS_SMALL) ;
|
||||
dXDim += m_dCellSpan + 2 * EPS_SMALL ;
|
||||
dYDim += m_dCellSpan + 2 * EPS_SMALL ;
|
||||
// numero di celle da esplorare sui 3 assi
|
||||
|
||||
// Numero di celle da esplorare sui 3 assi
|
||||
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
|
||||
|
||||
//string sOut = "Celle=" + ToString( int( m_xyCellCount)) + " Occupate=" + ToString( int(m_occupiedCells.size())) + " Span=" + ToString( nXSpan * nYSpan) ;
|
||||
//LOG_INFO( GetEGkLogger(), sOut.c_str()) ;
|
||||
|
||||
// Se conviene verificare queste celle
|
||||
if ( nXSpan * nYSpan < 5 * int( m_occupiedCells.size())) {
|
||||
// cella di base
|
||||
int nX = static_cast<int>( Hash( ptMin)) ;
|
||||
@@ -212,7 +229,7 @@ HashGrid2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
// inserisco in lista gli oggetti della cella
|
||||
if ( m_cell[nY].m_Objs != nullptr) {
|
||||
for ( auto pObj : *( m_cell[nY].m_Objs)) {
|
||||
if ( b3Test.OverlapsXY( pObj->box))
|
||||
if ( b3Int.OverlapsXY( pObj->box))
|
||||
vnIds.push_back( pObj->nId) ;
|
||||
}
|
||||
}
|
||||
@@ -223,13 +240,15 @@ HashGrid2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
nX += m_cell[nX].m_neighborOffset[5] ;
|
||||
}
|
||||
}
|
||||
|
||||
// altrimenti verifico direttamente tutte e sole quelle occupate
|
||||
else {
|
||||
// ciclo sulle celle occupate
|
||||
for ( auto cell : m_occupiedCells) {
|
||||
// inserisco in lista gli oggetti della cella
|
||||
if ( cell->m_Objs != nullptr) {
|
||||
for ( auto pObj : *(cell->m_Objs)) {
|
||||
if ( b3Test.OverlapsXY( pObj->box))
|
||||
if ( b3Int.OverlapsXY( pObj->box))
|
||||
vnIds.push_back( pObj->nId) ;
|
||||
}
|
||||
}
|
||||
@@ -247,6 +266,7 @@ HashGrid2d::Clear( void)
|
||||
}
|
||||
m_occupiedCells.clear() ;
|
||||
m_objCount = 0 ;
|
||||
m_b3Grid.Reset() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -509,6 +529,9 @@ HashGrids2d::Add( int nObjId, const BBox3d& box)
|
||||
// bodies stored in 'm_objsToAdd' are finally inserted into the data structure.
|
||||
m_objsToAdd.push_back( &(m_ObjsList.back())) ;
|
||||
|
||||
// Aggiorno il box complessivo
|
||||
m_b3Objs.Add( box) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
catch(...) {
|
||||
@@ -521,7 +544,7 @@ HashGrids2d::Add( int nObjId, const BBox3d& box)
|
||||
bool
|
||||
HashGrids2d::Modify( int nObjId, const BBox3d& box)
|
||||
{
|
||||
// cerco l'oggetto con l'Id voluto
|
||||
// Cerco l'oggetto con l'Id voluto
|
||||
auto iIter = m_ObjsMap.find( nObjId) ;
|
||||
if ( iIter == m_ObjsMap.end())
|
||||
return false ;
|
||||
@@ -529,9 +552,12 @@ HashGrids2d::Modify( int nObjId, const BBox3d& box)
|
||||
if ( pObj == nullptr)
|
||||
return false ;
|
||||
|
||||
// modifico il suo box
|
||||
// Modifico il suo box
|
||||
pObj->box = box ;
|
||||
|
||||
// Aggiorno il box complessivo
|
||||
m_b3Objs.Add( box) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -635,21 +661,26 @@ HashGrids2d::Update( void)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
HashGrids2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
HashGrids2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds) const
|
||||
{
|
||||
// pulisco il risultato
|
||||
vnIds.clear() ;
|
||||
vnIds.reserve( 128) ;
|
||||
|
||||
// limito con box globale
|
||||
BBox3d b3Int ;
|
||||
if ( ! b3Test.FindIntersectionXY( m_b3Objs, b3Int))
|
||||
return false ;
|
||||
|
||||
// ricerca nelle griglie
|
||||
if ( m_bGridActive) {
|
||||
for ( auto pGrid : m_GridList)
|
||||
pGrid->Find( b3Test, vnIds) ;
|
||||
pGrid->Find( b3Int, vnIds) ;
|
||||
}
|
||||
|
||||
// ricerca negli oggetti fuori griglia
|
||||
for ( auto pObj : m_nonGridObjs) {
|
||||
if ( b3Test.OverlapsXY( pObj->box))
|
||||
if ( b3Int.OverlapsXY( pObj->box))
|
||||
vnIds.push_back( pObj->nId) ;
|
||||
}
|
||||
|
||||
@@ -660,7 +691,6 @@ HashGrids2d::Find( const BBox3d& b3Test, INTVECTOR& vnIds)
|
||||
return ( vnIds.size() > 0) ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
HashGrids2d::Clear( void)
|
||||
@@ -675,6 +705,8 @@ HashGrids2d::Clear( void)
|
||||
m_nonGridObjs.clear() ;
|
||||
|
||||
m_objsToAdd.clear() ;
|
||||
|
||||
m_b3Objs.Reset() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user