Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
PointInElementSearch.cpp File Reference
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include "moab/Core.hpp"
#include "moab/Interface.hpp"
#include "moab/Range.hpp"
#include "moab/AdaptiveKDTree.hpp"
#include "moab/ElemEvaluator.hpp"
#include "moab/CN.hpp"
#include "moab/SpatialLocator.hpp"
+ Include dependency graph for PointInElementSearch.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

string test_file_name = string( MESH_DIR ) + string( "/mbtest1.vtk" )
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
Examples
PointInElementSearch.cpp.

Definition at line 27 of file PointInElementSearch.cpp.

28 {
29  int num_queries = 1000000;
30 
31  if( argc > 3 )
32  {
33  cout << "Usage: " << argv[0] << " <filename> [num_queries]" << endl;
34  return 0;
35  }
36  else if( argc == 3 )
37  {
38  test_file_name = argv[1];
39  num_queries = atoi( argv[2] );
40  }
41  else
42  {
43  num_queries = 100;
44  }
45 
46  // Instantiate
47  Core mb;
48 
49  // Load the file
50  MB_CHK_SET_ERR( mb.load_file( test_file_name.c_str() ), "Error loading file" );
51 
52  // Get all 3d elements in the file
53  Range elems;
54  MB_CHK_SET_ERR( mb.get_entities_by_dimension( 0, 3, elems ), "Error getting 3d elements" );
55 
56  // Create a tree to use for the location service
57  AdaptiveKDTree tree( &mb );
58 
59  // Specify an evaluator based on linear hexes
60  ElemEvaluator el_eval( &mb );
61 
62  // Build the SpatialLocator
63  SpatialLocator sl( &mb, elems, &tree );
64 
65  // Get the box extents
66  CartVect box_extents, pos;
67  BoundBox box = sl.local_box();
68  box_extents = box.bMax - box.bMin;
69 
70  // Query at random places in the tree
72  int is_inside = 0;
73  int num_inside = 0;
74  EntityHandle elem;
75  for( int i = 0; i < num_queries; i++ )
76  {
77  pos = box.bMin + CartVect( box_extents[0] * .01 * ( rand() % 100 ), box_extents[1] * .01 * ( rand() % 100 ),
78  box_extents[2] * .01 * ( rand() % 100 ) );
79  MB_CHK_ERR( sl.locate_point( pos.array(), elem, params.array(), &is_inside, 0.0, 0.0 ) );
80  if( is_inside ) num_inside++;
81  }
82 
83  cout << "Mesh contains " << elems.size() << " elements of type "
84  << CN::EntityTypeName( mb.type_from_handle( *elems.begin() ) ) << endl;
85  cout << "Bounding box min-max = (" << box.bMin[0] << "," << box.bMin[1] << "," << box.bMin[2] << ")-("
86  << box.bMax[0] << "," << box.bMax[1] << "," << box.bMax[2] << ")" << endl;
87  cout << "Queries inside box = " << num_inside << "/" << num_queries << " = "
88  << 100.0 * ( (double)num_inside ) / num_queries << "%" << endl;
89 
90  return 0;
91 }

References moab::CartVect::array(), moab::Range::begin(), moab::BoundBox::bMax, moab::BoundBox::bMin, moab::CN::EntityTypeName(), moab::Core::get_entities_by_dimension(), moab::Core::load_file(), moab::SpatialLocator::local_box(), moab::SpatialLocator::locate_point(), mb, MB_CHK_ERR, MB_CHK_SET_ERR, moab::params, moab::Range::size(), test_file_name, and moab::Core::type_from_handle().

Variable Documentation

◆ test_file_name

string test_file_name = string( MESH_DIR ) + string( "/mbtest1.vtk" )
Examples
PointInElementSearch.cpp.

Definition at line 25 of file PointInElementSearch.cpp.

Referenced by main().