Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
moab::SpatialLocator Class Reference

Tool to facilitate spatial location of a point in a mesh. More...

#include <SpatialLocator.hpp>

+ Collaboration diagram for moab::SpatialLocator:

Public Member Functions

 SpatialLocator (Interface *impl, Range &elems, Tree *tree=NULL, ElemEvaluator *eval=NULL)
 
virtual ~SpatialLocator ()
 
ErrorCode add_elems (Range &elems)
 
BoundBoxlocal_box ()
 
const BoundBoxlocal_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 ()
 
Interfacemoab ()
 Return the MOAB interface associated with this locator. More...
 
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)
 
Treeget_tree ()
 
TupleListloc_table ()
 
const TupleListloc_table () const
 
TupleListpar_loc_table ()
 
const TupleListpar_loc_table () const
 
ElemEvaluatorelem_eval ()
 
const ElemEvaluatorelem_eval () const
 
void elem_eval (ElemEvaluator *eval)
 
SpatialLocatorTimessl_times ()
 Get spatial locator times object. More...
 
const SpatialLocatorTimessl_times () const
 Get spatial locator times object. More...
 

Private Member Functions

void create_tree ()
 

Private Attributes

InterfacembImpl
 
Range myElems
 
int myDim
 
TreemyTree
 
ElemEvaluatorelemEval
 
bool iCreatedTree
 
TupleList locTable
 
TupleList parLocTable
 
BoundBox localBox
 
BoundBox globalBox
 
CartVect regDeltaXYZ
 
int regNums [3]
 
std::map< int, BoundBoxsrcProcBoxes
 
SpatialLocatorTimes myTimes
 
CpuTimer myTimer
 
bool timerInitialized
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SpatialLocator()

moab::SpatialLocator::SpatialLocator ( Interface impl,
Range elems,
Tree tree = NULL,
ElemEvaluator eval = NULL 
)

Definition at line 18 of file SpatialLocator.cpp.

19  : mbImpl( impl ), myElems( elems ), myDim( -1 ), myTree( tree ), elemEval( eval ), iCreatedTree( false ),
20  timerInitialized( false )
21 {
22  create_tree();
23 
24  if( !elems.empty() )
25  {
26  myDim = mbImpl->dimension_from_handle( *elems.rbegin() );
28  if( MB_SUCCESS != rval ) throw rval;
29 
30  rval = myTree->get_bounding_box( localBox );
31  if( MB_SUCCESS != rval ) throw rval;
32  }
33 
34  regNums[0] = regNums[1] = regNums[2] = 0;
35 }

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.

◆ ~SpatialLocator()

moab::SpatialLocator::~SpatialLocator ( )
inlinevirtual

Definition at line 346 of file SpatialLocator.hpp.

347 {
348  if( iCreatedTree && myTree ) delete myTree;
349 }

References iCreatedTree, and myTree.

Member Function Documentation

◆ add_elems()

ErrorCode moab::SpatialLocator::add_elems ( Range elems)

Definition at line 51 of file SpatialLocator.cpp.

52 {
53  if( elems.empty() ||
54  mbImpl->dimension_from_handle( *elems.begin() ) != mbImpl->dimension_from_handle( *elems.rbegin() ) )
55  return MB_FAILURE;
56 
57  myDim = mbImpl->dimension_from_handle( *elems.begin() );
58  myElems = elems;
59 
61  return rval;
62 }

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().

◆ create_tree()

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.

38 {
39  if( myTree ) return;
40 
42  // create a kdtree if only vertices
43  myTree = new AdaptiveKDTree( mbImpl );
44  else
45  // otherwise a BVHtree, since it performs better for elements
46  myTree = new BVHTree( mbImpl );
47 
48  iCreatedTree = true;
49 }

References moab::Range::empty(), iCreatedTree, mbImpl, MBVERTEX, myElems, myTree, moab::Range::rbegin(), and moab::Interface::type_from_handle().

Referenced by SpatialLocator().

◆ elem_eval() [1/3]

ElemEvaluator* moab::SpatialLocator::elem_eval ( )
inline

Definition at line 208 of file SpatialLocator.hpp.

209  {
210  return elemEval;
211  }

References elemEval.

Referenced by moab::DataCoupler::DataCoupler(), moab::DataCoupler::interpolate(), and moab::DataCoupler::~DataCoupler().

◆ elem_eval() [2/3]

const ElemEvaluator* moab::SpatialLocator::elem_eval ( ) const
inline

Definition at line 214 of file SpatialLocator.hpp.

215  {
216  return elemEval;
217  }

References elemEval.

◆ elem_eval() [3/3]

void moab::SpatialLocator::elem_eval ( ElemEvaluator eval)
inline

Definition at line 220 of file SpatialLocator.hpp.

221  {
222  elemEval = eval;
223  if( myTree ) myTree->set_eval( eval );
224  }

References elemEval, myTree, and moab::Tree::set_eval().

◆ get_tree()

Tree* moab::SpatialLocator::get_tree ( )
inline

Definition at line 174 of file SpatialLocator.hpp.

175  {
176  return myTree;
177  }

References myTree.

Referenced by DeformMeshRemap::execute().

◆ loc_table() [1/2]

TupleList& moab::SpatialLocator::loc_table ( )
inline

Definition at line 181 of file SpatialLocator.hpp.

182  {
183  return locTable;
184  }

References locTable.

Referenced by moab::DataCoupler::interpolate().

◆ loc_table() [2/2]

const TupleList& moab::SpatialLocator::loc_table ( ) const
inline

Definition at line 188 of file SpatialLocator.hpp.

189  {
190  return locTable;
191  }

References locTable.

◆ local_box() [1/2]

BoundBox& moab::SpatialLocator::local_box ( )
inline

Definition at line 69 of file SpatialLocator.hpp.

70  {
71  return localBox;
72  }

References localBox.

Referenced by main().

◆ local_box() [2/2]

const BoundBox& moab::SpatialLocator::local_box ( ) const
inline

Definition at line 75 of file SpatialLocator.hpp.

76  {
77  return localBox;
78  }

References localBox.

◆ local_num_located()

int moab::SpatialLocator::local_num_located ( )

Definition at line 499 of file SpatialLocator.cpp.

500 {
501  int num_located = locTable.get_n() - std::count( locTable.vul_rd, locTable.vul_rd + locTable.get_n(), 0 );
502  if( num_located != (int)locTable.get_n() )
503  {
504  Ulong* nl = std::find( locTable.vul_rd, locTable.vul_rd + locTable.get_n(), 0 );
505  if( nl )
506  {
507  int idx = nl - locTable.vul_rd;
508  if( idx )
509  {
510  }
511  }
512  }
513  return num_located;
514 }

References moab::TupleList::get_n(), locTable, nl, and moab::TupleList::vul_rd.

Referenced by DeformMeshRemap::execute().

◆ locate_point()

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.

358 {
359  return locate_points( pos, 1, &ent, params, is_inside, rel_iter_tol, abs_iter_tol, inside_tol );
360 }

References locate_points().

Referenced by main().

◆ locate_points() [1/4]

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.

387 {
388  bool i_initialized = false;
389  if( !timerInitialized )
390  {
392  timerInitialized = true;
393  i_initialized = true;
394  }
395  // initialize to tuple structure (p_ui, hs_ul, r[3]_d) (see header comments for locTable)
396  locTable.initialize( 1, 0, 1, 3, num_points );
398 
399  // pass storage directly into locate_points, since we know those arrays are contiguous
400  ErrorCode rval = locate_points( pos, num_points, (EntityHandle*)locTable.vul_wr, locTable.vr_wr, NULL, rel_iter_tol,
401  abs_iter_tol, inside_tol );
402  std::fill( locTable.vi_wr, locTable.vi_wr + num_points, 0 );
403  locTable.set_n( num_points );
404  if( MB_SUCCESS != rval ) return rval;
405 
406  // only call this if I'm the top-level function, since it resets the last time called
408 
409  return MB_SUCCESS;
410 }

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.

◆ locate_points() [2/4]

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.

448 {
449  bool i_initialized = false;
450  if( !timerInitialized )
451  {
453  timerInitialized = true;
454  i_initialized = true;
455  }
456 
457  /*
458  double tmp_abs_iter_tol = abs_iter_tol;
459  if (rel_iter_tol && !tmp_abs_iter_tol) {
460  // relative epsilon given, translate to absolute epsilon using box dimensions
461  tmp_abs_iter_tol = rel_iter_tol * localBox.diagonal_length();
462  }
463  */
464 
466 
467  ErrorCode rval = MB_SUCCESS;
468  for( int i = 0; i < num_points; i++ )
469  {
470  int i3 = 3 * i;
471  ErrorCode tmp_rval =
472  myTree->point_search( pos + i3, ents[i], abs_iter_tol, inside_tol, NULL, NULL, (CartVect*)( params + i3 ) );
473  if( MB_SUCCESS != tmp_rval )
474  {
475  rval = tmp_rval;
476  continue;
477  }
478 
479  if( debug && !ents[i] )
480  {
481  std::cout << "Point " << i << " not found; point: (" << pos[i3] << "," << pos[i3 + 1] << "," << pos[i3 + 2]
482  << ")" << std::endl;
483  }
484 
485  if( is_inside ) is_inside[i] = ( ents[i] ? true : false );
486  }
487 
488  // only call this if I'm the top-level function, since it resets the last time called
490 
491  return rval;
492 }

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.

◆ locate_points() [3/4]

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.

360 {
361  bool i_initialized = false;
362  if( !timerInitialized )
363  {
365  timerInitialized = true;
366  i_initialized = true;
367  }
368 
369  assert( !verts.empty() && mbImpl->type_from_handle( *verts.rbegin() ) == MBVERTEX );
370  std::vector< double > pos( 3 * verts.size() );
371  ErrorCode rval = mbImpl->get_coords( verts, &pos[0] );
372  if( MB_SUCCESS != rval ) return rval;
373  rval = locate_points( &pos[0], verts.size(), rel_iter_tol, abs_iter_tol, inside_tol );
374  if( MB_SUCCESS != rval ) return rval;
375 
376  // only call this if I'm the top-level function, since it resets the last time called
378 
379  return MB_SUCCESS;
380 }

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().

◆ locate_points() [4/4]

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.

419 {
420  bool i_initialized = false;
421  if( !timerInitialized )
422  {
424  timerInitialized = true;
425  i_initialized = true;
426  }
427 
428  assert( !verts.empty() && mbImpl->type_from_handle( *verts.rbegin() ) == MBVERTEX );
429  std::vector< double > pos( 3 * verts.size() );
430  ErrorCode rval = mbImpl->get_coords( verts, &pos[0] );
431  if( MB_SUCCESS != rval ) return rval;
432  rval = locate_points( &pos[0], verts.size(), ents, params, is_inside, rel_iter_tol, abs_iter_tol, inside_tol );
433 
434  // only call this if I'm the top-level function, since it resets the last time called
436 
437  return rval;
438 }

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().

◆ moab()

Interface* moab::SpatialLocator::moab ( )
inline

Return the MOAB interface associated with this locator.

Definition at line 159 of file SpatialLocator.hpp.

160  {
161  return mbImpl;
162  }

References mbImpl.

◆ par_loc_table() [1/2]

TupleList& moab::SpatialLocator::par_loc_table ( )
inline

Definition at line 195 of file SpatialLocator.hpp.

196  {
197  return parLocTable;
198  }

References parLocTable.

Referenced by moab::DataCoupler::interpolate().

◆ par_loc_table() [2/2]

const TupleList& moab::SpatialLocator::par_loc_table ( ) const
inline

Definition at line 202 of file SpatialLocator.hpp.

203  {
204  return parLocTable;
205  }

References parLocTable.

◆ remote_num_located()

int moab::SpatialLocator::remote_num_located ( )

Definition at line 521 of file SpatialLocator.cpp.

522 {
523  int located = 0;
524  for( unsigned int i = 0; i < parLocTable.get_n(); i++ )
525  if( parLocTable.vi_rd[2 * i] != -1 ) located++;
526  return located;
527 }

References moab::TupleList::get_n(), parLocTable, and moab::TupleList::vi_rd.

◆ sl_times() [1/2]

SpatialLocatorTimes& moab::SpatialLocator::sl_times ( )
inline

Get spatial locator times object.

Definition at line 227 of file SpatialLocator.hpp.

228  {
229  return myTimes;
230  }

References myTimes.

◆ sl_times() [2/2]

const SpatialLocatorTimes& moab::SpatialLocator::sl_times ( ) const
inline

Get spatial locator times object.

Definition at line 233 of file SpatialLocator.hpp.

234  {
235  return myTimes;
236  }

References myTimes.

Member Data Documentation

◆ elemEval

ElemEvaluator* moab::SpatialLocator::elemEval
private

Definition at line 285 of file SpatialLocator.hpp.

Referenced by elem_eval(), and locate_points().

◆ globalBox

BoundBox moab::SpatialLocator::globalBox
private

Definition at line 318 of file SpatialLocator.hpp.

◆ iCreatedTree

bool moab::SpatialLocator::iCreatedTree
private

Definition at line 288 of file SpatialLocator.hpp.

Referenced by create_tree(), and ~SpatialLocator().

◆ localBox

BoundBox moab::SpatialLocator::localBox
private

Definition at line 314 of file SpatialLocator.hpp.

Referenced by local_box(), and SpatialLocator().

◆ locTable

TupleList moab::SpatialLocator::locTable
private

Definition at line 297 of file SpatialLocator.hpp.

Referenced by loc_table(), local_num_located(), and locate_points().

◆ mbImpl

Interface* moab::SpatialLocator::mbImpl
private

Definition at line 273 of file SpatialLocator.hpp.

Referenced by add_elems(), create_tree(), locate_points(), moab(), and SpatialLocator().

◆ myDim

int moab::SpatialLocator::myDim
private

Definition at line 279 of file SpatialLocator.hpp.

Referenced by add_elems(), and SpatialLocator().

◆ myElems

Range moab::SpatialLocator::myElems
private

Definition at line 276 of file SpatialLocator.hpp.

Referenced by add_elems(), create_tree(), and SpatialLocator().

◆ myTimer

CpuTimer moab::SpatialLocator::myTimer
private

Definition at line 339 of file SpatialLocator.hpp.

Referenced by locate_points().

◆ myTimes

SpatialLocatorTimes moab::SpatialLocator::myTimes
private

Definition at line 335 of file SpatialLocator.hpp.

Referenced by locate_points(), and sl_times().

◆ myTree

Tree* moab::SpatialLocator::myTree
private

◆ parLocTable

TupleList moab::SpatialLocator::parLocTable
private

Definition at line 310 of file SpatialLocator.hpp.

Referenced by par_loc_table(), and remote_num_located().

◆ regDeltaXYZ

CartVect moab::SpatialLocator::regDeltaXYZ
private

Definition at line 322 of file SpatialLocator.hpp.

◆ regNums

int moab::SpatialLocator::regNums[3]
private

Definition at line 326 of file SpatialLocator.hpp.

Referenced by SpatialLocator().

◆ srcProcBoxes

std::map< int, BoundBox > moab::SpatialLocator::srcProcBoxes
private

Definition at line 331 of file SpatialLocator.hpp.

◆ timerInitialized

bool moab::SpatialLocator::timerInitialized
private

Definition at line 343 of file SpatialLocator.hpp.

Referenced by locate_points().


The documentation for this class was generated from the following files: