MOAB: Mesh Oriented datABase  (version 5.4.1)
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.
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 56 of file SpatialLocator.hpp.


Constructor & Destructor Documentation

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

Definition at line 346 of file SpatialLocator.hpp.

References iCreatedTree, and myTree.

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

Member Function Documentation

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

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

Definition at line 214 of file SpatialLocator.hpp.

References elemEval.

    {
        return elemEval;
    }

Definition at line 220 of file SpatialLocator.hpp.

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

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

Definition at line 174 of file SpatialLocator.hpp.

References myTree.

Referenced by DeformMeshRemap::execute(), and test_locator().

    {
        return myTree;
    }

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]

Definition at line 188 of file SpatialLocator.hpp.

References locTable.

    {
        return locTable;
    }

Definition at line 69 of file SpatialLocator.hpp.

References localBox.

Referenced by main(), and test_locator().

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

Definition at line 75 of file SpatialLocator.hpp.

References localBox.

    {
        return localBox;
    }

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(), moab::DataCoupler::locate_points(), and test_locator().

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

Return the MOAB interface associated with this locator.

Definition at line 159 of file SpatialLocator.hpp.

References mbImpl.

Referenced by test_locator().

    {
        return mbImpl;
    }

Definition at line 195 of file SpatialLocator.hpp.

References parLocTable.

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

    {
        return parLocTable;
    }

Definition at line 202 of file SpatialLocator.hpp.

References parLocTable.

    {
        return parLocTable;
    }

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

Get spatial locator times object.

Definition at line 227 of file SpatialLocator.hpp.

References myTimes.

    {
        return myTimes;
    }

Get spatial locator times object.

Definition at line 233 of file SpatialLocator.hpp.

References myTimes.

    {
        return myTimes;
    }

Member Data Documentation

Definition at line 285 of file SpatialLocator.hpp.

Referenced by elem_eval(), and locate_points().

Definition at line 318 of file SpatialLocator.hpp.

Definition at line 288 of file SpatialLocator.hpp.

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

Definition at line 314 of file SpatialLocator.hpp.

Referenced by local_box(), and SpatialLocator().

Definition at line 279 of file SpatialLocator.hpp.

Referenced by add_elems(), and SpatialLocator().

Definition at line 276 of file SpatialLocator.hpp.

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

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

Definition at line 322 of file SpatialLocator.hpp.

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.

Definition at line 343 of file SpatialLocator.hpp.

Referenced by locate_points().

List of all members.


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