Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
Tool to facilitate spatial location of a point in a mesh. More...
#include <SpatialLocator.hpp>
Public Member Functions | |
SpatialLocator (Interface *impl, Range &elems, Tree *tree=NULL, ElemEvaluator *eval=NULL) | |
virtual | ~SpatialLocator () |
ErrorCode | add_elems (Range &elems) |
BoundBox & | local_box () |
const BoundBox & | local_box () const |
ErrorCode | locate_points (Range &vertices, EntityHandle *ents, double *params, int *is_inside=NULL, const double rel_iter_tol=1.0e-10, const double abs_iter_tol=1.0e-10, const double inside_tol=1.0e-6) |
ErrorCode | locate_points (const double *pos, int num_points, EntityHandle *ents, double *params, int *is_inside=NULL, const double rel_iter_tol=1.0e-10, const double abs_iter_tol=1.0e-10, const double inside_tol=1.0e-6) |
ErrorCode | locate_points (Range &ents, const double rel_iter_tol=1.0e-10, const double abs_iter_tol=1.0e-10, const double inside_tol=1.0e-6) |
ErrorCode | locate_points (const double *pos, int num_points, const double rel_iter_tol=1.0e-10, const double abs_iter_tol=1.0e-10, const double inside_tol=1.0e-6) |
int | local_num_located () |
int | remote_num_located () |
Interface * | moab () |
Return the MOAB interface associated with this locator. | |
ErrorCode | locate_point (const double *pos, EntityHandle &ent, double *params, int *is_inside=NULL, const double rel_iter_tol=1.0e-10, const double abs_iter_tol=1.0e-10, const double inside_tol=1.0e-6) |
Tree * | get_tree () |
TupleList & | loc_table () |
const TupleList & | loc_table () const |
TupleList & | par_loc_table () |
const TupleList & | par_loc_table () const |
ElemEvaluator * | elem_eval () |
const ElemEvaluator * | elem_eval () const |
void | elem_eval (ElemEvaluator *eval) |
SpatialLocatorTimes & | sl_times () |
Get spatial locator times object. | |
const SpatialLocatorTimes & | sl_times () const |
Get spatial locator times object. | |
Private Member Functions | |
void | create_tree () |
Private Attributes | |
Interface * | mbImpl |
Range | myElems |
int | myDim |
Tree * | myTree |
ElemEvaluator * | elemEval |
bool | iCreatedTree |
TupleList | locTable |
TupleList | parLocTable |
BoundBox | localBox |
BoundBox | globalBox |
CartVect | regDeltaXYZ |
int | regNums [3] |
std::map< int, BoundBox > | srcProcBoxes |
SpatialLocatorTimes | myTimes |
CpuTimer | myTimer |
bool | timerInitialized |
Tool to facilitate spatial location of a point in a mesh.
SpatialLocator facilitates searching for points in or performing ray traces on collections of mesh entities in 2D or 3D. This searching is facilitated by a tree-based decomposition of the mesh. Various types of trees are implemented in MOAB and can be used by this tool, but by default it uses AdaptiveKDTree (see child classes of Tree for which others are available). Parallel and serial searching are both supported.
SpatialLocator can either cache the search results for points or pass back this information in arguments. Cached information is kept in locTable, indexed in the same order as search points passed in. This information consists of the entity handle containing the point and the parametric coordinates inside that element. Information about the points searched, e.g. the entities from which those points are derived, can be stored in the calling application if desired.
In parallel, there is a separation between the proc deciding which points to search for (the "target" proc), and the proc locating the point in its local mesh (the "source" proc). On the source proc, location information is cached in locTable, as in the serial case. By default, this location information (handle and parametric coords) is not returned to the target proc, since it would be of no use there. Instead, the rank of the source proc locating the point, and the index of that location info in the source proc's locTable, is returned; this information is stored on the target proc in this class's parLocTable variable. Again, information about the points searched should be stored in the calling application, if desired.
This class uses the ElemEvaluator class for specification and evaluation of basis functions (used for computing parametric coords within an entity). See documentation and examples for that class for usage information.
Definition at line 56 of file SpatialLocator.hpp.
moab::SpatialLocator::SpatialLocator | ( | Interface * | impl, |
Range & | elems, | ||
Tree * | tree = NULL , |
||
ElemEvaluator * | eval = NULL |
||
) |
Definition at line 18 of file SpatialLocator.cpp.
References moab::Tree::build_tree(), create_tree(), moab::Interface::dimension_from_handle(), moab::Range::empty(), ErrorCode, moab::Tree::get_bounding_box(), localBox, MB_SUCCESS, mbImpl, myDim, myElems, myTree, moab::Range::rbegin(), and regNums.
: mbImpl( impl ), myElems( elems ), myDim( -1 ), myTree( tree ), elemEval( eval ), iCreatedTree( false ), timerInitialized( false ) { create_tree(); if( !elems.empty() ) { myDim = mbImpl->dimension_from_handle( *elems.rbegin() ); ErrorCode rval = myTree->build_tree( myElems ); if( MB_SUCCESS != rval ) throw rval; rval = myTree->get_bounding_box( localBox ); if( MB_SUCCESS != rval ) throw rval; } regNums[0] = regNums[1] = regNums[2] = 0; }
moab::SpatialLocator::~SpatialLocator | ( | ) | [inline, virtual] |
Definition at line 346 of file SpatialLocator.hpp.
References iCreatedTree, and myTree.
{ if( iCreatedTree && myTree ) delete myTree; }
ErrorCode moab::SpatialLocator::add_elems | ( | Range & | elems | ) |
Definition at line 51 of file SpatialLocator.cpp.
References moab::Range::begin(), moab::Tree::build_tree(), moab::Interface::dimension_from_handle(), moab::Range::empty(), ErrorCode, mbImpl, myDim, myElems, myTree, and moab::Range::rbegin().
{ if( elems.empty() || mbImpl->dimension_from_handle( *elems.begin() ) != mbImpl->dimension_from_handle( *elems.rbegin() ) ) return MB_FAILURE; myDim = mbImpl->dimension_from_handle( *elems.begin() ); myElems = elems; ErrorCode rval = myTree->build_tree( myElems ); return rval; }
void moab::SpatialLocator::create_tree | ( | ) | [private] |
Create a tree Tree type depends on what's in myElems: if empty or all vertices, creates a kdtree, otherwise creates a BVHTree.
Definition at line 37 of file SpatialLocator.cpp.
References moab::Range::empty(), iCreatedTree, mbImpl, MBVERTEX, myElems, myTree, moab::Range::rbegin(), and moab::Interface::type_from_handle().
Referenced by SpatialLocator().
{ if( myTree ) return; if( myElems.empty() || mbImpl->type_from_handle( *myElems.rbegin() ) == MBVERTEX ) // create a kdtree if only vertices myTree = new AdaptiveKDTree( mbImpl ); else // otherwise a BVHtree, since it performs better for elements myTree = new BVHTree( mbImpl ); iCreatedTree = true; }
ElemEvaluator* moab::SpatialLocator::elem_eval | ( | ) | [inline] |
Definition at line 208 of file SpatialLocator.hpp.
References elemEval.
Referenced by moab::DataCoupler::DataCoupler(), moab::DataCoupler::interpolate(), and moab::DataCoupler::~DataCoupler().
{ return elemEval; }
const ElemEvaluator* moab::SpatialLocator::elem_eval | ( | ) | const [inline] |
void moab::SpatialLocator::elem_eval | ( | ElemEvaluator * | eval | ) | [inline] |
Definition at line 220 of file SpatialLocator.hpp.
References elemEval, myTree, and moab::Tree::set_eval().
Tree* moab::SpatialLocator::get_tree | ( | ) | [inline] |
Definition at line 174 of file SpatialLocator.hpp.
References myTree.
Referenced by DeformMeshRemap::execute().
{ return myTree; }
TupleList& moab::SpatialLocator::loc_table | ( | ) | [inline] |
Definition at line 181 of file SpatialLocator.hpp.
References locTable.
Referenced by moab::DataCoupler::interpolate().
{ return locTable; }
const TupleList& moab::SpatialLocator::loc_table | ( | ) | const [inline] |
BoundBox& moab::SpatialLocator::local_box | ( | ) | [inline] |
Definition at line 69 of file SpatialLocator.hpp.
References localBox.
Referenced by main().
{ return localBox; }
const BoundBox& moab::SpatialLocator::local_box | ( | ) | const [inline] |
Definition at line 499 of file SpatialLocator.cpp.
References moab::TupleList::get_n(), locTable, nl, and moab::TupleList::vul_rd.
Referenced by DeformMeshRemap::execute().
{ int num_located = locTable.get_n() - std::count( locTable.vul_rd, locTable.vul_rd + locTable.get_n(), 0 ); if( num_located != (int)locTable.get_n() ) { Ulong* nl = std::find( locTable.vul_rd, locTable.vul_rd + locTable.get_n(), 0 ); if( nl ) { int idx = nl - locTable.vul_rd; if( idx ) { } } } return num_located; }
ErrorCode moab::SpatialLocator::locate_point | ( | const double * | pos, |
EntityHandle & | ent, | ||
double * | params, | ||
int * | is_inside = NULL , |
||
const double | rel_iter_tol = 1.0e-10 , |
||
const double | abs_iter_tol = 1.0e-10 , |
||
const double | inside_tol = 1.0e-6 |
||
) | [inline] |
Definition at line 351 of file SpatialLocator.hpp.
References locate_points().
Referenced by main().
{ return locate_points( pos, 1, &ent, params, is_inside, rel_iter_tol, abs_iter_tol, inside_tol ); }
ErrorCode moab::SpatialLocator::locate_points | ( | Range & | vertices, |
EntityHandle * | ents, | ||
double * | params, | ||
int * | is_inside = NULL , |
||
const double | rel_iter_tol = 1.0e-10 , |
||
const double | abs_iter_tol = 1.0e-10 , |
||
const double | inside_tol = 1.0e-6 |
||
) |
Definition at line 412 of file SpatialLocator.cpp.
References moab::Range::empty(), ErrorCode, moab::Interface::get_coords(), MB_SUCCESS, mbImpl, MBVERTEX, myTimer, myTimes, moab::Range::rbegin(), moab::Range::size(), moab::SpatialLocatorTimes::slTimes, moab::SpatialLocatorTimes::SRC_SEARCH, moab::CpuTimer::time_elapsed(), timerInitialized, and moab::Interface::type_from_handle().
Referenced by locate_point(), locate_points(), and moab::DataCoupler::locate_points().
{ bool i_initialized = false; if( !timerInitialized ) { myTimer.time_elapsed(); timerInitialized = true; i_initialized = true; } assert( !verts.empty() && mbImpl->type_from_handle( *verts.rbegin() ) == MBVERTEX ); std::vector< double > pos( 3 * verts.size() ); ErrorCode rval = mbImpl->get_coords( verts, &pos[0] ); if( MB_SUCCESS != rval ) return rval; rval = locate_points( &pos[0], verts.size(), ents, params, is_inside, rel_iter_tol, abs_iter_tol, inside_tol ); // only call this if I'm the top-level function, since it resets the last time called if( i_initialized ) myTimes.slTimes[SpatialLocatorTimes::SRC_SEARCH] = myTimer.time_elapsed(); return rval; }
ErrorCode moab::SpatialLocator::locate_points | ( | const double * | pos, |
int | num_points, | ||
EntityHandle * | ents, | ||
double * | params, | ||
int * | is_inside = NULL , |
||
const double | rel_iter_tol = 1.0e-10 , |
||
const double | abs_iter_tol = 1.0e-10 , |
||
const double | inside_tol = 1.0e-6 |
||
) |
Definition at line 440 of file SpatialLocator.cpp.
References moab::debug, elemEval, ErrorCode, moab::Tree::get_eval(), MB_SUCCESS, myTimer, myTimes, myTree, moab::Tree::point_search(), moab::Tree::set_eval(), moab::SpatialLocatorTimes::slTimes, moab::SpatialLocatorTimes::SRC_SEARCH, moab::CpuTimer::time_elapsed(), and timerInitialized.
{ bool i_initialized = false; if( !timerInitialized ) { myTimer.time_elapsed(); timerInitialized = true; i_initialized = true; } /* double tmp_abs_iter_tol = abs_iter_tol; if (rel_iter_tol && !tmp_abs_iter_tol) { // relative epsilon given, translate to absolute epsilon using box dimensions tmp_abs_iter_tol = rel_iter_tol * localBox.diagonal_length(); } */ if( elemEval && myTree->get_eval() != elemEval ) myTree->set_eval( elemEval ); ErrorCode rval = MB_SUCCESS; for( int i = 0; i < num_points; i++ ) { int i3 = 3 * i; ErrorCode tmp_rval = myTree->point_search( pos + i3, ents[i], abs_iter_tol, inside_tol, NULL, NULL, (CartVect*)( params + i3 ) ); if( MB_SUCCESS != tmp_rval ) { rval = tmp_rval; continue; } if( debug && !ents[i] ) { std::cout << "Point " << i << " not found; point: (" << pos[i3] << "," << pos[i3 + 1] << "," << pos[i3 + 2] << ")" << std::endl; } if( is_inside ) is_inside[i] = ( ents[i] ? true : false ); } // only call this if I'm the top-level function, since it resets the last time called if( i_initialized ) myTimes.slTimes[SpatialLocatorTimes::SRC_SEARCH] = myTimer.time_elapsed(); return rval; }
ErrorCode moab::SpatialLocator::locate_points | ( | Range & | ents, |
const double | rel_iter_tol = 1.0e-10 , |
||
const double | abs_iter_tol = 1.0e-10 , |
||
const double | inside_tol = 1.0e-6 |
||
) |
Definition at line 356 of file SpatialLocator.cpp.
References moab::Range::empty(), ErrorCode, moab::Interface::get_coords(), locate_points(), MB_SUCCESS, mbImpl, MBVERTEX, myTimer, myTimes, moab::Range::rbegin(), moab::Range::size(), moab::SpatialLocatorTimes::slTimes, moab::SpatialLocatorTimes::SRC_SEARCH, moab::CpuTimer::time_elapsed(), timerInitialized, and moab::Interface::type_from_handle().
{ bool i_initialized = false; if( !timerInitialized ) { myTimer.time_elapsed(); timerInitialized = true; i_initialized = true; } assert( !verts.empty() && mbImpl->type_from_handle( *verts.rbegin() ) == MBVERTEX ); std::vector< double > pos( 3 * verts.size() ); ErrorCode rval = mbImpl->get_coords( verts, &pos[0] ); if( MB_SUCCESS != rval ) return rval; rval = locate_points( &pos[0], verts.size(), rel_iter_tol, abs_iter_tol, inside_tol ); if( MB_SUCCESS != rval ) return rval; // only call this if I'm the top-level function, since it resets the last time called if( i_initialized ) myTimes.slTimes[SpatialLocatorTimes::SRC_SEARCH] = myTimer.time_elapsed(); return MB_SUCCESS; }
ErrorCode moab::SpatialLocator::locate_points | ( | const double * | pos, |
int | num_points, | ||
const double | rel_iter_tol = 1.0e-10 , |
||
const double | abs_iter_tol = 1.0e-10 , |
||
const double | inside_tol = 1.0e-6 |
||
) |
Definition at line 382 of file SpatialLocator.cpp.
References moab::TupleList::enableWriteAccess(), ErrorCode, moab::TupleList::initialize(), locate_points(), locTable, MB_SUCCESS, myTimer, myTimes, moab::TupleList::set_n(), moab::SpatialLocatorTimes::slTimes, moab::SpatialLocatorTimes::SRC_SEARCH, moab::CpuTimer::time_elapsed(), timerInitialized, moab::TupleList::vi_wr, moab::TupleList::vr_wr, and moab::TupleList::vul_wr.
{ bool i_initialized = false; if( !timerInitialized ) { myTimer.time_elapsed(); timerInitialized = true; i_initialized = true; } // initialize to tuple structure (p_ui, hs_ul, r[3]_d) (see header comments for locTable) locTable.initialize( 1, 0, 1, 3, num_points ); locTable.enableWriteAccess(); // pass storage directly into locate_points, since we know those arrays are contiguous ErrorCode rval = locate_points( pos, num_points, (EntityHandle*)locTable.vul_wr, locTable.vr_wr, NULL, rel_iter_tol, abs_iter_tol, inside_tol ); std::fill( locTable.vi_wr, locTable.vi_wr + num_points, 0 ); locTable.set_n( num_points ); if( MB_SUCCESS != rval ) return rval; // only call this if I'm the top-level function, since it resets the last time called if( i_initialized ) myTimes.slTimes[SpatialLocatorTimes::SRC_SEARCH] = myTimer.time_elapsed(); return MB_SUCCESS; }
Interface* moab::SpatialLocator::moab | ( | ) | [inline] |
Return the MOAB interface associated with this locator.
Definition at line 159 of file SpatialLocator.hpp.
References mbImpl.
{ return mbImpl; }
TupleList& moab::SpatialLocator::par_loc_table | ( | ) | [inline] |
Definition at line 195 of file SpatialLocator.hpp.
References parLocTable.
Referenced by moab::DataCoupler::interpolate().
{ return parLocTable; }
const TupleList& moab::SpatialLocator::par_loc_table | ( | ) | const [inline] |
Definition at line 521 of file SpatialLocator.cpp.
References moab::TupleList::get_n(), parLocTable, and moab::TupleList::vi_rd.
{ int located = 0; for( unsigned int i = 0; i < parLocTable.get_n(); i++ ) if( parLocTable.vi_rd[2 * i] != -1 ) located++; return located; }
SpatialLocatorTimes& moab::SpatialLocator::sl_times | ( | ) | [inline] |
Get spatial locator times object.
Definition at line 227 of file SpatialLocator.hpp.
References myTimes.
{ return myTimes; }
const SpatialLocatorTimes& moab::SpatialLocator::sl_times | ( | ) | const [inline] |
Get spatial locator times object.
Definition at line 233 of file SpatialLocator.hpp.
References myTimes.
{ return myTimes; }
ElemEvaluator* moab::SpatialLocator::elemEval [private] |
Definition at line 285 of file SpatialLocator.hpp.
Referenced by elem_eval(), and locate_points().
BoundBox moab::SpatialLocator::globalBox [private] |
Definition at line 318 of file SpatialLocator.hpp.
bool moab::SpatialLocator::iCreatedTree [private] |
Definition at line 288 of file SpatialLocator.hpp.
Referenced by create_tree(), and ~SpatialLocator().
BoundBox moab::SpatialLocator::localBox [private] |
Definition at line 314 of file SpatialLocator.hpp.
Referenced by local_box(), and SpatialLocator().
TupleList moab::SpatialLocator::locTable [private] |
Definition at line 297 of file SpatialLocator.hpp.
Referenced by loc_table(), local_num_located(), and locate_points().
Interface* moab::SpatialLocator::mbImpl [private] |
Definition at line 273 of file SpatialLocator.hpp.
Referenced by add_elems(), create_tree(), locate_points(), moab(), and SpatialLocator().
int moab::SpatialLocator::myDim [private] |
Definition at line 279 of file SpatialLocator.hpp.
Referenced by add_elems(), and SpatialLocator().
Range moab::SpatialLocator::myElems [private] |
Definition at line 276 of file SpatialLocator.hpp.
Referenced by add_elems(), create_tree(), and SpatialLocator().
CpuTimer moab::SpatialLocator::myTimer [private] |
Definition at line 339 of file SpatialLocator.hpp.
Referenced by locate_points().
Definition at line 335 of file SpatialLocator.hpp.
Referenced by locate_points(), and sl_times().
Tree* moab::SpatialLocator::myTree [private] |
Definition at line 282 of file SpatialLocator.hpp.
Referenced by add_elems(), create_tree(), elem_eval(), get_tree(), locate_points(), SpatialLocator(), and ~SpatialLocator().
TupleList moab::SpatialLocator::parLocTable [private] |
Definition at line 310 of file SpatialLocator.hpp.
Referenced by par_loc_table(), and remote_num_located().
CartVect moab::SpatialLocator::regDeltaXYZ [private] |
Definition at line 322 of file SpatialLocator.hpp.
int moab::SpatialLocator::regNums[3] [private] |
Definition at line 326 of file SpatialLocator.hpp.
Referenced by SpatialLocator().
std::map< int, BoundBox > moab::SpatialLocator::srcProcBoxes [private] |
Definition at line 331 of file SpatialLocator.hpp.
bool moab::SpatialLocator::timerInitialized [private] |
Definition at line 343 of file SpatialLocator.hpp.
Referenced by locate_points().