moab
moab::SpatialLocator Class Reference

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

#include <SpatialLocator.hpp>

List of all members.

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.
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.
const SpatialLocatorTimessl_times () const
 Get spatial locator times object.

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 52 of file SpatialLocator.hpp.


Constructor & Destructor Documentation

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

Definition at line 19 of file SpatialLocator.cpp.

            : 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;
      }
    }

Definition at line 286 of file SpatialLocator.hpp.

    {
      if (iCreatedTree && myTree) delete myTree;
    }

Member Function Documentation

Definition at line 49 of file SpatialLocator.cpp.

    {
      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;
    }

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 35 of file SpatialLocator.cpp.

    {
      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;
    }

Definition at line 164 of file SpatialLocator.hpp.

{return elemEval;}

Definition at line 167 of file SpatialLocator.hpp.

{return elemEval;}

Definition at line 170 of file SpatialLocator.hpp.

{elemEval = eval; if (myTree) myTree->set_eval(eval);}

Definition at line 145 of file SpatialLocator.hpp.

{return myTree;}

Definition at line 149 of file SpatialLocator.hpp.

{return locTable;}
const TupleList& moab::SpatialLocator::loc_table ( ) const [inline]

Definition at line 153 of file SpatialLocator.hpp.

{return locTable;}

Definition at line 65 of file SpatialLocator.hpp.

{return localBox;}
const BoundBox& moab::SpatialLocator::local_box ( ) const [inline]

Definition at line 68 of file SpatialLocator.hpp.

{return localBox;}

Definition at line 469 of file SpatialLocator.cpp.

    {
      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()) {
        unsigned long *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 291 of file SpatialLocator.hpp.

    {
      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 393 of file SpatialLocator.cpp.

    {
      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 418 of file SpatialLocator.cpp.

    {
      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 339 of file SpatialLocator.cpp.

    {
      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 364 of file SpatialLocator.cpp.

    {
      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;
    }

Return the MOAB interface associated with this locator.

Definition at line 136 of file SpatialLocator.hpp.

{ return mbImpl; }

Definition at line 157 of file SpatialLocator.hpp.

{return parLocTable;}

Definition at line 161 of file SpatialLocator.hpp.

{return parLocTable;}

Definition at line 487 of file SpatialLocator.cpp.

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

Get spatial locator times object.

Definition at line 173 of file SpatialLocator.hpp.

{return myTimes;}

Get spatial locator times object.

Definition at line 176 of file SpatialLocator.hpp.

{return myTimes;}

Member Data Documentation

Definition at line 224 of file SpatialLocator.hpp.

Definition at line 258 of file SpatialLocator.hpp.

Definition at line 227 of file SpatialLocator.hpp.

Definition at line 254 of file SpatialLocator.hpp.

Definition at line 237 of file SpatialLocator.hpp.

Definition at line 212 of file SpatialLocator.hpp.

Definition at line 218 of file SpatialLocator.hpp.

Definition at line 215 of file SpatialLocator.hpp.

Definition at line 279 of file SpatialLocator.hpp.

Definition at line 221 of file SpatialLocator.hpp.

Definition at line 250 of file SpatialLocator.hpp.

Definition at line 262 of file SpatialLocator.hpp.

Definition at line 266 of file SpatialLocator.hpp.

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

Definition at line 271 of file SpatialLocator.hpp.

Definition at line 283 of file SpatialLocator.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines