MOAB: Mesh Oriented datABase  (version 5.5.0)
bsp_tree_test.cpp File Reference
#include "moab/Core.hpp"
#include "TestUtil.hpp"
#include "moab/BSPTree.hpp"
#include "moab/CartVect.hpp"
#include "moab/BSPTreePoly.hpp"
#include "moab/Range.hpp"
#include <algorithm>
+ Include dependency graph for bsp_tree_test.cpp:

Go to the source code of this file.

Macros

#define CHECK_RAY_XSECTS(PT, DIR, T_IN, T_OUT)
 

Functions

void test_set_plane ()
 
void test_iterator ()
 
void test_box_iterator ()
 
void test_tree_create ()
 
void test_box_tree_create ()
 
void test_leaf_containing_point_bounded_tree ()
 
void test_leaf_containing_point_unbounded_tree ()
 
void test_merge_leaf ()
 
void test_box_iter_neighbors ()
 
void test_leaf_sibling ()
 
void test_leaf_volume (bool box)
 
void test_leaf_volume_box ()
 
void test_leaf_volume_gen ()
 
void test_leaf_splits_intersects ()
 
void test_leaf_intersects_ray_common (bool box)
 
void test_box_leaf_intersects_ray ()
 
void test_gen_leaf_intersects_ray ()
 
void test_leaf_polyhedron ()
 
int main ()
 
void check_equal (const BSPTree::Plane &p1, const BSPTree::Plane &p2, const char *exp1, const char *exp2, int line, const char *file)
 
bool compare_hexes (const double expected[8][3], const double actual[8][3], double epsilon)
 
static void aabox_corners (const double min[3], const double max[3], double corners[8][3])
 
static void aabox_corners (double min_x, double min_y, double min_z, double max_x, double max_y, double max_z, double corners[8][3])
 
static std::vector< int > neighbors (const BSPTreeBoxIter &iter, const EntityHandle leaves[8], BSPTreeBoxIter::SideBits side, double epsilon)
 
static void box (const double pts[], int num_pts, double minpt[3], double maxpt[3])
 
static EntityHandle build_tree (const double points[], int num_points, BSPTree &tool)
 

Macro Definition Documentation

◆ CHECK_RAY_XSECTS

#define CHECK_RAY_XSECTS (   PT,
  DIR,
  T_IN,
  T_OUT 
)
Value:
do \
{ \
CHECK( iter.intersect_ray( ( PT ), ( DIR ), t_in, t_out ) ); \
CHECK_REAL_EQUAL( ( T_IN ), t_in, 1e-6 ); \
CHECK_REAL_EQUAL( ( T_OUT ), t_out, 1e-6 ); \
} while( false )

Definition at line 1515 of file bsp_tree_test.cpp.

Function Documentation

◆ aabox_corners() [1/2]

static void aabox_corners ( const double  min[3],
const double  max[3],
double  corners[8][3] 
)
static

Definition at line 222 of file bsp_tree_test.cpp.

223 {
224  const double expt[8][3] = { { min[0], min[1], min[2] }, { max[0], min[1], min[2] }, { max[0], max[1], min[2] },
225  { min[0], max[1], min[2] }, { min[0], min[1], max[2] }, { max[0], min[1], max[2] },
226  { max[0], max[1], max[2] }, { min[0], max[1], max[2] } };
227  memcpy( corners, expt, sizeof( expt ) );
228 }

Referenced by aabox_corners(), test_box_iterator(), test_box_tree_create(), test_leaf_containing_point_bounded_tree(), and test_merge_leaf().

◆ aabox_corners() [2/2]

static void aabox_corners ( double  min_x,
double  min_y,
double  min_z,
double  max_x,
double  max_y,
double  max_z,
double  corners[8][3] 
)
static

Definition at line 230 of file bsp_tree_test.cpp.

237 {
238  double min[] = { min_x, min_y, min_z };
239  double max[] = { max_x, max_y, max_z };
240  aabox_corners( min, max, corners );
241 }

References aabox_corners().

◆ box()

static void box ( const double  pts[],
int  num_pts,
double  minpt[3],
double  maxpt[3] 
)
static
Examples
DeformMeshRemap.cpp, and StructuredMeshSimple.cpp.

Definition at line 1668 of file bsp_tree_test.cpp.

1669 {
1670  minpt[0] = maxpt[0] = pts[0];
1671  minpt[1] = maxpt[1] = pts[1];
1672  minpt[2] = maxpt[2] = pts[2];
1673  for( int i = 1; i < num_pts; ++i )
1674  {
1675  for( int d = 0; d < 3; ++d )
1676  {
1677  if( pts[3 * i + d] < minpt[d] ) minpt[d] = pts[3 * i + d];
1678  if( pts[3 * i + d] > maxpt[d] ) maxpt[d] = pts[3 * i + d];
1679  }
1680  }
1681 }

Referenced by access_adjacencies(), moab::ScdInterface::add_box(), moab::ScdInterface::assign_global_ids(), moab::common_tree::box_contains_point(), moab::BVHTree::bruteforce_find(), moab::Bvh_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::bucket_index(), moab::BVHTree::Bucket::bucket_index(), build_tree(), moab::Bvh_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::build_tree(), moab::AdaptiveKDTree::build_tree(), moab::BVHTree::build_tree(), moab::AxisBox::calculate(), moab::common_tree::compute_box_center(), moab::Element_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::compute_split(), moab::common_tree::construct_element_map(), moab::BVHTree::construct_element_vec(), DeformMeshRemap::deform_master(), moab::Element_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::determine_split(), moab::AdaptiveKDTree::distance_search(), moab::BVHTree::distance_search(), do_closest_point_test(), do_ray_fire_test(), moab::Bvh_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::establish_buckets(), moab::BVHTree::establish_buckets(), moab::BVHTree::get_bounding_box(), moab::Tree::get_bounding_box(), moab::AdaptiveKDTree::get_info(), moab::AdaptiveKDTree::get_last_iterator(), moab::ScdInterface::get_shared_vertices(), moab::AdaptiveKDTree::get_tree_iterator(), moab::ParallelMergeMesh::GetGlobalBox(), moab::Coupler::initialize_tree(), moab::Element::Map::inside_box(), LeafHexer::leaf(), TriStats::leaf(), moab::BVHTree::local_build_tree(), moab::Coupler::locate_points(), main(), moab::operator<<(), moab::common_tree::operator<<(), moab::BoundBox::operator==(), moab::AdaptiveKDTree::point_search(), moab::BVHTree::point_search(), moab::AdaptiveKDTree::print(), moab::TreeNodePrinter::print_geometry(), moab::AdaptiveKDTree::ray_intersect_triangles(), moab::ScdInterface::remove_box(), scaled_corner(), scaled_face(), moab::BVHTree::set_interval(), moab::Bvh_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::set_interval(), moab::Skinner::skin_box(), moab::ScdInterface::tag_shared_vertices(), test_bound_box(), test_build_from_pts(), test_build_from_tri(), test_leaf_intersects_ray_common(), test_leaf_volume(), moab::Coupler::test_local_box(), test_locator(), test_save(), TriStats::TriStats(), moab::BoundBox::update(), TreeValidator::visit(), CubitWriter::visit(), and TriCounter::visit().

◆ build_tree()

static EntityHandle build_tree ( const double  points[],
int  num_points,
BSPTree tool 
)
static

Definition at line 1683 of file bsp_tree_test.cpp.

1684 {
1685  // create points
1686  ErrorCode rval;
1687  std::vector< EntityHandle > pts( num_points );
1688  for( int i = 0; i < num_points; ++i )
1689  {
1690  rval = tool.moab()->create_vertex( points + 3 * i, pts[i] );CHECK_ERR( rval );
1691  }
1692 
1693  // calculate bounding box of tree
1694  double minpt[3], maxpt[3];
1695  box( points, num_points, minpt, maxpt );
1696 
1697  // create initial (1-node) tree
1698  EntityHandle root;
1699  rval = tool.create_tree( minpt, maxpt, root );CHECK_ERR( rval );
1700 
1701  BSPTreeIter iter;
1702  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1703 
1704  rval = tool.moab()->add_entities( root, &pts[0], pts.size() );CHECK_ERR( rval );
1705 
1706  // build tree
1707  std::vector< EntityHandle > left_pts, right_pts;
1708  std::vector< CartVect > coords( num_points ), tmp_coords;
1709  for( ; MB_SUCCESS == rval; rval = iter.step() )
1710  {
1711  pts.clear();
1712  rval = tool.moab()->get_entities_by_handle( iter.handle(), pts );CHECK_ERR( rval );
1713  while( pts.size() > 1 )
1714  {
1715 
1716  coords.resize( pts.size() );
1717  rval = tool.moab()->get_coords( &pts[0], pts.size(), coords[0].array() );CHECK_ERR( rval );
1718 
1719  // find two points far apart apart
1720  std::vector< CartVect >* ptr;
1721  if( coords.size() < 10 )
1722  ptr = &coords;
1723  else
1724  {
1725  tmp_coords.resize( 16 );
1726  CartVect pn, px;
1727  box( coords[0].array(), coords.size(), pn.array(), px.array() );
1728  tmp_coords[8] = pn;
1729  tmp_coords[9] = CartVect( px[0], pn[1], pn[2] );
1730  tmp_coords[10] = CartVect( px[0], px[1], pn[2] );
1731  tmp_coords[11] = CartVect( pn[0], px[1], pn[2] );
1732  tmp_coords[12] = CartVect( pn[0], pn[1], px[2] );
1733  tmp_coords[13] = CartVect( px[0], pn[1], px[2] );
1734  tmp_coords[14] = px;
1735  tmp_coords[15] = CartVect( pn[0], px[1], px[2] );
1736  for( int i = 0; i < 8; ++i )
1737  {
1738  tmp_coords[i] = coords[0];
1739  for( size_t j = 1; j < coords.size(); ++j )
1740  if( ( coords[j] - tmp_coords[i + 8] ).length_squared() <
1741  ( tmp_coords[i] - tmp_coords[i + 8] ).length_squared() )
1742  tmp_coords[i] = coords[j];
1743  }
1744  tmp_coords.resize( 8 );
1745  ptr = &tmp_coords;
1746  }
1747 
1748  size_t pt1 = 0, pt2 = 0;
1749  double lsqr = -1;
1750  for( size_t i = 0; i < ptr->size(); ++i )
1751  {
1752  for( size_t j = 0; j < ptr->size(); ++j )
1753  {
1754  double ls = ( ( *ptr )[i] - ( *ptr )[j] ).length_squared();
1755  if( ls > lsqr )
1756  {
1757  lsqr = ls;
1758  pt1 = i;
1759  pt2 = j;
1760  }
1761  }
1762  }
1763 
1764  // if all points are coincident
1765  if( lsqr <= 1e-12 ) break;
1766 
1767  // define normal orthogonal to line through two points
1768  CartVect norm = ( *ptr )[pt1] - ( *ptr )[pt2];
1769  norm.normalize();
1770 
1771  // find mean position for plane
1772  double coeff = 0.0;
1773  for( size_t i = 0; i < coords.size(); ++i )
1774  coeff -= norm % coords[i];
1775  coeff /= coords.size();
1776 
1777  // left/right sort points
1778  left_pts.clear();
1779  right_pts.clear();
1780  for( size_t i = 0; i < coords.size(); ++i )
1781  {
1782  double d = -( norm % coords[i] );
1783  if( d >= coeff )
1784  left_pts.push_back( pts[i] );
1785  else
1786  right_pts.push_back( pts[i] );
1787  }
1788 
1789  rval = tool.split_leaf( iter, BSPTree::Plane( norm.array(), coeff ), left_pts, right_pts );CHECK_ERR( rval );
1790  CHECK( !left_pts.empty() && !right_pts.empty() );
1791  pts.swap( left_pts );
1792  }
1793 
1794  // printf("Leaf %d contains %d vertices: ", (int)ID_FROM_HANDLE(iter.handle()),
1795  // (int)(pts.size()) );
1796  // for (size_t i = 0; i < pts.size(); ++i)
1797  // printf( "%d, ", (int)ID_FROM_HANDLE(pts[i]));
1798  // printf("\n");
1799  }
1800 
1801  CHECK( rval == MB_ENTITY_NOT_FOUND );
1802 
1803  // verify that tree is constructed correctly
1804  for( int i = 0; i < num_points; ++i )
1805  {
1806  CartVect pt( points + 3 * i );
1808  rval = tool.leaf_containing_point( root, pt.array(), leaf );CHECK_ERR( rval );
1809  Range ents;
1810  rval = tool.moab()->get_entities_by_handle( leaf, ents );CHECK_ERR( rval );
1811  bool found = false;
1812  for( Range::iterator j = ents.begin(); j != ents.end(); ++j )
1813  {
1814  CartVect ent_coords;
1815  rval = tool.moab()->get_coords( &*j, 1, ent_coords.array() );CHECK_ERR( rval );
1816  if( ( pt - ent_coords ).length_squared() < 1e-6 ) found = true;
1817  }
1818  CHECK( found );
1819  }
1820 
1821  return root;
1822 }

References moab::Interface::add_entities(), moab::CartVect::array(), moab::Range::begin(), box(), CHECK, CHECK_ERR, moab::BSPTree::create_tree(), moab::Interface::create_vertex(), moab::Range::end(), ErrorCode, moab::Interface::get_coords(), moab::Interface::get_entities_by_handle(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), leaf, moab::BSPTree::leaf_containing_point(), length_squared(), MB_ENTITY_NOT_FOUND, MB_SUCCESS, moab::BSPTree::moab(), moab::CartVect::normalize(), moab::BSPTree::split_leaf(), and moab::BSPTreeIter::step().

Referenced by test_leaf_polyhedron().

◆ check_equal()

void check_equal ( const BSPTree::Plane p1,
const BSPTree::Plane p2,
const char *  exp1,
const char *  exp2,
int  line,
const char *  file 
)

Definition at line 67 of file bsp_tree_test.cpp.

73 {
74  if( fabs( p1.norm[0] - p2.norm[0] ) > 1e-6 || fabs( p1.norm[1] - p2.norm[1] ) > 1e-6 ||
75  fabs( p1.norm[2] - p2.norm[2] ) > 1e-6 || fabs( p1.coeff - p2.coeff ) > 1e-6 )
76  {
77  printf( "Equality Test Failed: %s == %s\n", exp1, exp2 );
78  printf( " at line %d of '%s'\n", line, file );
79  printf( " Expected: %f x + %f y + %f z + %f = 0\n", p1.norm[0], p1.norm[1], p1.norm[2], p1.coeff );
80  printf( " Actual : %f x + %f y + %f z + %f = 0\n", p2.norm[0], p2.norm[1], p2.norm[2], p2.coeff );
81  printf( "\n" );
82  FLAG_ERROR;
83  }
84 }

References moab::BSPTree::Plane::coeff, FLAG_ERROR, and moab::BSPTree::Plane::norm.

Referenced by check_equal_eigvect().

◆ compare_hexes()

bool compare_hexes ( const double  expected[8][3],
const double  actual[8][3],
double  epsilon 
)

Definition at line 181 of file bsp_tree_test.cpp.

182 {
183  // for each of three possible rotations
184  const int rotation_maps[3][8] = {
185  { 0, 1, 2, 3, 4, 5, 6, 7 }, { 3, 2, 6, 7, 0, 1, 5, 4 }, { 7, 3, 2, 6, 4, 0, 1, 5 } };
186  for( int i = 0; i < 3; ++i )
187  {
188  // compare for rotationts about axis from face 4 to 5
189  for( int j = 0; j < 4; ++j )
190  {
191  bool match = true;
192  // for each face vertex
193  for( int k = 0; k < 4 && match; ++k )
194  {
195  // for each coordinate
196  for( int d = 0; d < 3; ++d )
197  {
198  if( fabs( expected[( j + k ) % 4][d] - actual[rotation_maps[i][k]][d] ) > epsilon ||
199  fabs( expected[( j + k ) % 4 + 4][d] - actual[rotation_maps[i][k + 4]][d] ) > epsilon )
200  {
201  match = false;
202  break;
203  }
204  }
205  }
206 
207  if( match ) return true;
208  }
209  }
210 
211  printf( "Hex vertex copmarison failed.\n" );
212  printf( " Exected Actual\n" );
213  for( int v = 0; v < 8; ++v )
214  {
215  printf( "% 9f % 9f % 9f % 9f % 9f % 9f\n", expected[v][0], expected[v][1], expected[v][2], actual[v][0],
216  actual[v][1], actual[v][2] );
217  }
218 
219  return false;
220 }

Referenced by test_box_iterator(), test_box_tree_create(), test_leaf_containing_point_bounded_tree(), and test_merge_leaf().

◆ main()

◆ neighbors()

static std::vector< int > neighbors ( const BSPTreeBoxIter iter,
const EntityHandle  leaves[8],
BSPTreeBoxIter::SideBits  side,
double  epsilon 
)
static

Definition at line 972 of file bsp_tree_test.cpp.

976 {
977  std::vector< BSPTreeBoxIter > list;
978  ErrorCode rval = iter.get_neighbors( side, list, epsilon );CHECK_ERR( rval );
979 
980  std::vector< int > results;
981  for( size_t i = 0; i < list.size(); ++i )
982  results.push_back( std::find( leaves, leaves + 8, list[i].handle() ) - leaves );
983  std::sort( results.begin(), results.end() );
984  return results;
985 }

References CHECK_ERR, ErrorCode, and moab::BSPTreeBoxIter::get_neighbors().

Referenced by MetisPartitioner::assemble_graph(), ZoltanPartitioner::assemble_graph(), MetisPartitioner::assemble_taggedsets_graph(), moab::Intx2Mesh::DetermineOrderedNeighbors(), get_part_boundary_verts(), get_part_neighbors(), iMeshP_getNumPartNborsArr(), moab::Intx2Mesh::intersect_meshes(), ZoltanPartitioner::partition_owned_cells(), test_box_iter_neighbors(), test_entity_copy_parts(), and test_get_neighbors().

◆ test_box_iter_neighbors()

void test_box_iter_neighbors ( )

Definition at line 987 of file bsp_tree_test.cpp.

988 {
989  Core moab;
990  BSPTree tool( &moab );
991  ErrorCode rval;
992  EntityHandle root;
993  BSPTreeBoxIter iter;
994  BSPTree::Plane p;
995 
996  /* Build Tree */
997 
998  const double corners[8][3] = { { 0, 0, 0 }, { 8, 0, 0 }, { 8, 2, 0 }, { 0, 2, 0 },
999  { 0, 0, 1 }, { 8, 0, 1 }, { 8, 2, 1 }, { 0, 2, 1 } };
1000  rval = tool.create_tree( corners, root );CHECK_ERR( rval );
1001  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1002  EntityHandle leaves[8];
1003 
1004  /* +----------------------------------------+
1005  | |
1006  | 0* |
1007  | |
1008  +----------------------------------------+ */
1009 
1010  p = BSPTree::Plane( 1, 0, 0, -4 );
1011  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1012 
1013  /* +-------------------+--------------------+
1014  | | |
1015  | 0* | 1 |
1016  | | |
1017  +----------------------------------------+ */
1018 
1019  p = BSPTree::Plane( -1, 0, 0, 2 );
1020  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1021 
1022  /* +---------+---------+--------------------+
1023  | | | |
1024  | 1 | 0* | 2 |
1025  | | | |
1026  +----------------------------------------+ */
1027 
1028  p = BSPTree::Plane( 0, 1, 0, -1 );
1029  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1030 
1031  /* +---------+---------+--------------------+
1032  | | 1 | |
1033  | 2 +---------+ 3 |
1034  | | 0* | |
1035  +----------------------------------------+ */
1036 
1037  leaves[0] = iter.handle();
1038  rval = iter.step();CHECK_ERR( rval );
1039  leaves[1] = iter.handle();
1040  rval = iter.step();CHECK_ERR( rval );
1041 
1042  /* +---------+---------+--------------------+
1043  | | 1 | |
1044  | 2* +---------+ 3 |
1045  | | 0 | |
1046  +----------------------------------------+ */
1047 
1048  p = BSPTree::Plane( 0, -1, 0, 1 );
1049  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1050 
1051  /* +---------+---------+--------------------+
1052  | 2* | 1 | |
1053  +---------+---------+ 4 |
1054  | 3 | 0 | |
1055  +----------------------------------------+ */
1056 
1057  leaves[2] = iter.handle();
1058  rval = iter.step();CHECK_ERR( rval );
1059  leaves[3] = iter.handle();
1060  rval = iter.step();CHECK_ERR( rval );
1061 
1062  /* +---------+---------+--------------------+
1063  | 2 | 1 | |
1064  +---------+---------+ 4* |
1065  | 3 | 0 | |
1066  +----------------------------------------+ */
1067 
1068  p = BSPTree::Plane( 0, 1, 0, -1 );
1069  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1070 
1071  /* +---------+---------+--------------------+
1072  | 2 | 1 | 5 |
1073  +---------+---------+--------------------+
1074  | 3 | 0 | 4* |
1075  +----------------------------------------+ */
1076 
1077  p = BSPTree::Plane( 1, 0, 0, -6 );
1078  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1079 
1080  /* +---------+---------+--------------------+
1081  | 2 | 1 | 6 |
1082  +---------+---------+----------+---------+
1083  | 3 | 0 | 4* | 5 |
1084  +------------------------------+---------+ */
1085 
1086  leaves[4] = iter.handle();
1087  rval = iter.step();CHECK_ERR( rval );
1088  leaves[5] = iter.handle();
1089  rval = iter.step();CHECK_ERR( rval );
1090 
1091  /* +---------+---------+--------------------+
1092  | 2 | 1 | 6* |
1093  +---------+---------+----------+---------+
1094  | 3 | 0 | 4 | 5 |
1095  +------------------------------+---------+ */
1096 
1097  p = BSPTree::Plane( -1, 0, 0, 6 );
1098  rval = tool.split_leaf( iter, p );CHECK_ERR( rval );
1099 
1100  /* +---------+---------+--------------------+
1101  | 2 | 1 | 7 | 6 |
1102  +---------+---------+----------+---------+
1103  | 3 | 0 | 4 | 5 |
1104  +------------------------------+---------+ */
1105 
1106  leaves[6] = iter.handle();
1107  rval = iter.step();CHECK_ERR( rval );
1108  leaves[7] = iter.handle();
1109 
1110  /* check all neighbors of each leaf */
1111 
1112  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1113 
1114  // NOTE: Several values in the expected result list are
1115  // commented out in the tests below. When the tolerance
1116  // is greater than zero, the search algorithm may or may
1117  // not return leaves that are not face-adjacent (e.g. adjacent
1118  // only along edges or at corners.) The determining factor
1119  // for whether or not such a neighbor is returned is which
1120  // sub-tree of the split that defined the source leaf side
1121  // the neighbor is on. The algorithm will not search the subtree
1122  // of the split that created the side and that contains the
1123  // source leaf.
1124 
1125  // check neighbors of leaf 0
1126  std::vector< int > expected;
1127  CHECK_EQUAL( leaves[0], iter.handle() );
1128  expected.clear();
1129  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1130  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1131  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1132  expected.push_back( 3 );
1133  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
1134  expected.insert( expected.begin(), 2 );
1135  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1136  expected.clear();
1137  expected.push_back( 1 );
1138  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
1139  // See NOTE // expected.push_back( 2 ); expected.push_back( 7 );
1140  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1141  expected.clear();
1142  expected.push_back( 4 );
1143  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
1144  expected.push_back( 7 );
1145  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1146 
1147  // check neighbors of leaf 1
1148  CHECK_ERR( iter.step() );
1149  CHECK_EQUAL( leaves[1], iter.handle() );
1150  expected.clear();
1151  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1152  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1153  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1154  expected.push_back( 2 );
1155  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
1156  expected.push_back( 3 );
1157  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1158  expected.clear();
1159  expected.push_back( 0 );
1160  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
1161  // See NOTE // expected.push_back( 3 ); expected.push_back( 4 );
1162  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1163  expected.clear();
1164  expected.push_back( 7 );
1165  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
1166  expected.insert( expected.begin(), 4 );
1167  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1168 
1169  /* +---------+---------+--------------------+
1170  | 2 | 1 | 7 | 6 |
1171  +---------+---------+----------+---------+
1172  | 3 | 0 | 4 | 5 |
1173  +------------------------------+---------+ */
1174 
1175  // check neighbors of leaf 2
1176  CHECK_ERR( iter.step() );
1177  CHECK_EQUAL( leaves[2], iter.handle() );
1178  expected.clear();
1179  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1180  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1181  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1182  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1183  expected.push_back( 3 );
1184  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
1185  // See NOTE // expected.insert( expected.begin(), 0 );
1186  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1187  expected.clear();
1188  expected.push_back( 1 );
1189  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
1190  expected.insert( expected.begin(), 0 );
1191  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1192 
1193  // check neighbors of leaf 3
1194  CHECK_ERR( iter.step() );
1195  CHECK_EQUAL( leaves[3], iter.handle() );
1196  expected.clear();
1197  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1198  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1199  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1200  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1201  expected.push_back( 2 );
1202  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
1203  // See NOTE // expected.insert( expected.begin(), 1 );
1204  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1205  expected.clear();
1206  expected.push_back( 0 );
1207  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
1208  expected.push_back( 1 );
1209  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1210 
1211  /* +---------+---------+--------------------+
1212  | 2 | 1 | 7 | 6 |
1213  +---------+---------+----------+---------+
1214  | 3 | 0 | 4 | 5 |
1215  +------------------------------+---------+ */
1216 
1217  // check neighbors of leaf 4
1218  CHECK_ERR( iter.step() );
1219  CHECK_EQUAL( leaves[4], iter.handle() );
1220  expected.clear();
1221  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1222  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1223  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1224  expected.push_back( 0 );
1225  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
1226  expected.push_back( 1 );
1227  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1228  expected.clear();
1229  expected.push_back( 7 );
1230  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
1231  expected.insert( expected.begin(), 6 );
1232  // See NOTE // expected.insert( expected.begin(), 1 );
1233  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1234  expected.clear();
1235  expected.push_back( 5 );
1236  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
1237  // See NOTE // expected.push_back( 6 );
1238  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1239 
1240  // check neighbors of leaf 5
1241  CHECK_ERR( iter.step() );
1242  CHECK_EQUAL( leaves[5], iter.handle() );
1243  expected.clear();
1244  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1245  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1246  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1247  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1248  expected.push_back( 4 );
1249  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
1250  // See NOTE // expected.push_back( 7 );
1251  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1252  expected.clear();
1253  expected.push_back( 6 );
1254  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
1255  expected.push_back( 7 );
1256  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1257 
1258  /* +---------+---------+--------------------+
1259  | 2 | 1 | 7 | 6 |
1260  +---------+---------+----------+---------+
1261  | 3 | 0 | 4 | 5 |
1262  +------------------------------+---------+ */
1263 
1264  // check neighbors of leaf 6
1265  CHECK_ERR( iter.step() );
1266  CHECK_EQUAL( leaves[6], iter.handle() );
1267  expected.clear();
1268  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1269  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1270  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1271  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1272  expected.push_back( 7 );
1273  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
1274  // See NOTE // expected.insert( expected.begin(), 4 );
1275  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1276  expected.clear();
1277  expected.push_back( 5 );
1278  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
1279  expected.insert( expected.begin(), 4 );
1280  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1281 
1282  // check neighbors of leaf 7
1283  CHECK_ERR( iter.step() );
1284  CHECK_EQUAL( leaves[7], iter.handle() );
1285  expected.clear();
1286  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
1287  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
1288  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
1289  expected.push_back( 1 );
1290  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
1291  expected.insert( expected.begin(), 0 );
1292  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
1293  expected.clear();
1294  expected.push_back( 4 );
1295  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
1296  // See NOTE // expected.insert( expected.begin(), 0 );
1297  expected.push_back( 5 );
1298  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
1299  expected.clear();
1300  expected.push_back( 6 );
1301  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
1302  // See NOTE // expected.insert( expected.begin(), 5 );
1303  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
1304 }

References moab::BSPTreeBoxIter::B0154, moab::BSPTreeBoxIter::B1265, moab::BSPTreeBoxIter::B2376, moab::BSPTreeBoxIter::B3047, moab::BSPTreeBoxIter::B3210, moab::BSPTreeBoxIter::B4567, CHECK_EQUAL, CHECK_ERR, moab::BSPTree::create_tree(), ErrorCode, moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), neighbors(), moab::BSPTree::split_leaf(), and moab::BSPTreeBoxIter::step().

Referenced by main().

◆ test_box_iterator()

void test_box_iterator ( )

Definition at line 243 of file bsp_tree_test.cpp.

244 {
245  Core moab;
246  BSPTree tool( &moab );
247  ErrorCode rval;
248  EntityHandle root;
249  BSPTreeBoxIter iter;
250  const double min[3] = { -1, -2, -3 };
251  const double max[3] = { 3, 2, 1 };
252 
253  // create a depth-1 tree
254  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
255  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
256 
257  // check initial state of iterator
258  CHECK_EQUAL( &tool, iter.tool() );
259  CHECK_EQUAL( root, iter.handle() );
260  CHECK_EQUAL( 1u, iter.depth() );
261 
262  // check initial corner values
263  double corners[8][3], expt[8][3];
264  aabox_corners( min, max, expt );
265  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
266  CHECK( compare_hexes( expt, corners, 1e-6 ) );
267 
268  // should fail if at root
269  BSPTree::Plane p;
270  rval = iter.get_parent_split_plane( p );
272 
273  // check that step past end returns correct value
274  rval = iter.step();
276 
277  // reset iterator
278  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
279 
280  // check that step past start returns correct value
281  rval = iter.back();
283 
284  // reset iterator
285  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
286 
287  // insert a single split plane
288  rval = tool.split_leaf( iter, BSPTree::Plane( 2, 0, 0, 0 ) );CHECK_ERR( rval );
289 
290  // check initial location
291  CHECK_EQUAL( 2u, iter.depth() );
292  CHECK( iter.handle() != root );
293 
294  // create new iterators at left and right ends
295  BSPTreeIter left, right;
296  rval = tool.get_tree_iterator( root, left );CHECK_ERR( rval );
297  rval = tool.get_tree_end_iterator( root, right );CHECK_ERR( rval );
298 
299  // compare post-split iterator to left
300  CHECK_EQUAL( left.depth(), iter.depth() );
301  CHECK_EQUAL( left.handle(), iter.handle() );
302 
303  // check box
304  aabox_corners( min, max, expt );
305  for( int i = 0; i < 8; ++i )
306  if( expt[i][0] > 0 ) expt[i][0] = 0;
307  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
308  CHECK( compare_hexes( expt, corners, 1e-6 ) );
309 
310  // step to other leaf
311  rval = iter.step();CHECK_ERR( rval );
312 
313  // check location
314  CHECK_EQUAL( 2u, iter.depth() );
315  CHECK( iter.handle() != root );
316 
317  // compare stepped iterator to right
318  CHECK_EQUAL( right.depth(), iter.depth() );
319  CHECK_EQUAL( right.handle(), iter.handle() );
320 
321  // check box
322  aabox_corners( min, max, expt );
323  for( int i = 0; i < 8; ++i )
324  if( expt[i][0] < 0 ) expt[i][0] = 0;
325  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
326  CHECK( compare_hexes( expt, corners, 1e-6 ) );
327 
328  // step to back to first leaf
329  rval = iter.back();CHECK_ERR( rval );
330 
331  // compare to left
332  CHECK_EQUAL( left.depth(), iter.depth() );
333  CHECK_EQUAL( left.handle(), iter.handle() );
334 
335  // check box
336  aabox_corners( min, max, expt );
337  for( int i = 0; i < 8; ++i )
338  if( expt[i][0] > 0 ) expt[i][0] = 0;
339  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
340  CHECK( compare_hexes( expt, corners, 1e-6 ) );
341 
342  // check plane
343  // should have unit normal
344  left.get_parent_split_plane( p );
345  CHECK_EQUAL( BSPTree::Plane( 1, 0, 0, 0 ), p );
346  p.norm[0] = 11;
347  right.get_parent_split_plane( p );
348  CHECK_EQUAL( BSPTree::Plane( 1, 0, 0, 0 ), p );
349 
350  // check step past ends
351  rval = left.back();
353  rval = right.step();
355 }

References aabox_corners(), moab::BSPTreeIter::back(), moab::BSPTreeBoxIter::back(), CHECK, CHECK_EQUAL, CHECK_ERR, compare_hexes(), moab::BSPTree::create_tree(), moab::BSPTreeIter::depth(), ErrorCode, moab::BSPTreeBoxIter::get_box_corners(), moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_end_iterator(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), MB_ENTITY_NOT_FOUND, moab::BSPTree::Plane::norm, moab::BSPTree::split_leaf(), moab::BSPTreeIter::step(), moab::BSPTreeBoxIter::step(), and moab::BSPTreeIter::tool().

Referenced by main().

◆ test_box_leaf_intersects_ray()

void test_box_leaf_intersects_ray ( )

Definition at line 32 of file bsp_tree_test.cpp.

33 {
35 }

References test_leaf_intersects_ray_common().

Referenced by main().

◆ test_box_tree_create()

void test_box_tree_create ( )

Definition at line 435 of file bsp_tree_test.cpp.

436 {
437  Core moab;
438  BSPTree tool( &moab );
439  ErrorCode rval;
440  EntityHandle root;
441  BSPTreeBoxIter iter;
442  BSPTree::Plane p;
443  const double min[3] = { -2, -2, -2 };
444  const double max[3] = { 2, 2, 2 };
445 
446  // create a depth-1 tree
447  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
448  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
449 
450  // check initial state of iterator
451  CHECK_EQUAL( &tool, iter.tool() );
452  CHECK_EQUAL( root, iter.handle() );
453  CHECK_EQUAL( 1u, iter.depth() );
454 
455  // check initial corner values
456  double corners[8][3], expt[8][3];
457  aabox_corners( min, max, expt );
458  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
459  CHECK( compare_hexes( expt, corners, 1e-6 ) );
460 
461  // Try splits that should fail because they
462  // do not intersect the leaf at all
463  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 0, 1, 4 ) );
464  CHECK_EQUAL( MB_FAILURE, rval );
465  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 0, 1, -4 ) );
466  CHECK_EQUAL( MB_FAILURE, rval );
467  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1, 0, 4 ) );
468  CHECK_EQUAL( MB_FAILURE, rval );
469  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1, 0, -4 ) );
470  CHECK_EQUAL( MB_FAILURE, rval );
471  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 0, 0, 4 ) );
472  CHECK_EQUAL( MB_FAILURE, rval );
473  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 0, 0, -4 ) );
474  CHECK_EQUAL( MB_FAILURE, rval );
475  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, -1, 7 ) );
476  CHECK_EQUAL( MB_FAILURE, rval );
477  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, -1, -7 ) );
478  CHECK_EQUAL( MB_FAILURE, rval );
479  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, -1, 7 ) );
480  CHECK_EQUAL( MB_FAILURE, rval );
481  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, -1, -7 ) );
482  CHECK_EQUAL( MB_FAILURE, rval );
483  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, -1, 7 ) );
484  CHECK_EQUAL( MB_FAILURE, rval );
485  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, -1, -7 ) );
486  CHECK_EQUAL( MB_FAILURE, rval );
487  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, -1, 7 ) );
488  CHECK_EQUAL( MB_FAILURE, rval );
489  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, -1, -7 ) );
490  CHECK_EQUAL( MB_FAILURE, rval );
491 
492  // Try a split that should fail because the
493  // resulting leaf would not be a hexahedron.
494  // Clip each corner twice using planes with opposing normals
495  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, -1, -4 ) );
496  CHECK_EQUAL( MB_FAILURE, rval );
497  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 1, 4 ) );
498  CHECK_EQUAL( MB_FAILURE, rval );
499  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, -1, -4 ) );
500  CHECK_EQUAL( MB_FAILURE, rval );
501  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, 1, 4 ) );
502  CHECK_EQUAL( MB_FAILURE, rval );
503  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, -1, -4 ) );
504  CHECK_EQUAL( MB_FAILURE, rval );
505  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, 1, 4 ) );
506  CHECK_EQUAL( MB_FAILURE, rval );
507  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, -1, -4 ) );
508  CHECK_EQUAL( MB_FAILURE, rval );
509  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, 1, 4 ) );
510  CHECK_EQUAL( MB_FAILURE, rval );
511  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, 1, -4 ) );
512  CHECK_EQUAL( MB_FAILURE, rval );
513  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, -1, 4 ) );
514  CHECK_EQUAL( MB_FAILURE, rval );
515  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, 1, -4 ) );
516  CHECK_EQUAL( MB_FAILURE, rval );
517  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, -1, 4 ) );
518  CHECK_EQUAL( MB_FAILURE, rval );
519  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 1, -4 ) );
520  CHECK_EQUAL( MB_FAILURE, rval );
521  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, -1, 4 ) );
522  CHECK_EQUAL( MB_FAILURE, rval );
523  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, 1, -4 ) );
524  CHECK_EQUAL( MB_FAILURE, rval );
525  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, -1, 4 ) );
526  CHECK_EQUAL( MB_FAILURE, rval );
527  // Clip each edge
528  rval = tool.split_leaf( iter, BSPTree::Plane( -1, -1, 0, -2 ) );
529  CHECK_EQUAL( MB_FAILURE, rval );
530  rval = tool.split_leaf( iter, BSPTree::Plane( 1, -1, 0, -2 ) );
531  CHECK_EQUAL( MB_FAILURE, rval );
532  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 0, -2 ) );
533  CHECK_EQUAL( MB_FAILURE, rval );
534  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, 0, -2 ) );
535  CHECK_EQUAL( MB_FAILURE, rval );
536  rval = tool.split_leaf( iter, BSPTree::Plane( 0, -1, -1, -2 ) );
537  CHECK_EQUAL( MB_FAILURE, rval );
538  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1, -1, -2 ) );
539  CHECK_EQUAL( MB_FAILURE, rval );
540  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1, 1, -2 ) );
541  CHECK_EQUAL( MB_FAILURE, rval );
542  rval = tool.split_leaf( iter, BSPTree::Plane( 0, -1, 1, -2 ) );
543  CHECK_EQUAL( MB_FAILURE, rval );
544  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 0, -1, -2 ) );
545  CHECK_EQUAL( MB_FAILURE, rval );
546  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 0, -1, -2 ) );
547  CHECK_EQUAL( MB_FAILURE, rval );
548  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 0, 1, -2 ) );
549  CHECK_EQUAL( MB_FAILURE, rval );
550  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 0, 1, -2 ) );
551  CHECK_EQUAL( MB_FAILURE, rval );
552 
553  // verify that iterator is still valid after many failed splits
554  CHECK_EQUAL( &tool, iter.tool() );
555  CHECK_EQUAL( root, iter.handle() );
556  CHECK_EQUAL( 1u, iter.depth() );
557  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
558  CHECK( compare_hexes( expt, corners, 1e-6 ) );
559 
560  // split with z=0
561  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 0, 0.5, 0 ) );CHECK_ERR( rval );
562  CHECK_EQUAL( 2u, iter.depth() );
563 
564  // check that parent split plane is correct
565  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
566  CHECK_EQUAL( BSPTree::Plane( 0, 0, 1, 0 ), p );
567 
568  // check that box corners are correct
569  aabox_corners( min, max, expt );
570  for( unsigned i = 0; i < 8; ++i )
571  if( expt[i][2] > 0.0 ) expt[i][2] = 0.0;
572  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
573  CHECK( compare_hexes( expt, corners, 1e-6 ) );
574 
575  // split with z=-1 and normal in opposite direction
576  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 0, -2, -2 ) );CHECK_ERR( rval );
577  CHECK_EQUAL( 3u, iter.depth() );
578  for( unsigned i = 0; i < 8; ++i )
579  if( expt[i][2] < -1.0 ) expt[i][2] = -1.0;
580  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
581  CHECK( compare_hexes( expt, corners, 1e-6 ) );
582 
583  // step to next leaf (z < -1)
584  rval = iter.step();CHECK_ERR( rval );
585  CHECK_EQUAL( 3u, iter.depth() );
586  aabox_corners( min, max, expt );
587  for( unsigned i = 0; i < 8; ++i )
588  if( expt[i][2] > -1.0 ) expt[i][2] = -1.0;
589  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
590  CHECK( compare_hexes( expt, corners, 1e-6 ) );
591 
592  // split at x = -1
593  rval = tool.split_leaf( iter, BSPTree::Plane( -0.1, 0, 0, -0.1 ) );CHECK_ERR( rval );
594  CHECK_EQUAL( 4u, iter.depth() );
595 
596  // check that parent split plane is correct
597  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
598  CHECK_EQUAL( BSPTree::Plane( -1, 0, 0, -1 ), p );
599 
600  // check that leaf box is correct
601  aabox_corners( -1, -2, -2, 2, 2, -1, expt );
602  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
603  CHECK( compare_hexes( expt, corners, 1e-6 ) );
604 
605  // split at x = 1
606  rval = tool.split_leaf( iter, BSPTree::Plane( 5, 0, 0, -5 ) );CHECK_ERR( rval );
607  CHECK_EQUAL( 5u, iter.depth() );
608 
609  // check that parent split plane is correct
610  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
611  CHECK_EQUAL( BSPTree::Plane( 1, 0, 0, -1 ), p );
612 
613  // check that leaf box is correct
614  aabox_corners( -1, -2, -2, 1, 2, -1, expt );
615  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
616  CHECK( compare_hexes( expt, corners, 1e-6 ) );
617 
618  // split at y = -1
619  rval = tool.split_leaf( iter, BSPTree::Plane( 0, -1, 0, -1 ) );CHECK_ERR( rval );
620  CHECK_EQUAL( 6u, iter.depth() );
621 
622  // check that parent split plane is correct
623  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
624  CHECK_EQUAL( BSPTree::Plane( 0, -1, 0, -1 ), p );
625 
626  // check that leaf box is correct
627  aabox_corners( -1, -1, -2, 1, 2, -1, expt );
628  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
629  CHECK( compare_hexes( expt, corners, 1e-6 ) );
630 
631  // split at y = 1
632  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1, 0, -1 ) );CHECK_ERR( rval );
633  CHECK_EQUAL( 7u, iter.depth() );
634 
635  // check that parent split plane is correct
636  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
637  CHECK_EQUAL( BSPTree::Plane( 0, 1, 0, -1 ), p );
638 
639  // check that leaf box is correct
640  aabox_corners( -1, -1, -2, 1, 1, -1, expt );
641  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
642  CHECK( compare_hexes( expt, corners, 1e-6 ) );
643 
644  // iterate over tree, verifying
645  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
646  CHECK_EQUAL( 3u, iter.depth() );
647  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
648  CHECK_EQUAL( BSPTree::Plane( 0, 0, -1, -1 ), p );
649  aabox_corners( -2, -2, -1, 2, 2, 0, expt );
650  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
651  CHECK( compare_hexes( expt, corners, 1e-6 ) );
652 
653  rval = iter.step();CHECK_ERR( rval );
654  CHECK_EQUAL( 7u, iter.depth() );
655  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
656  CHECK_EQUAL( BSPTree::Plane( 0, 1, 0, -1 ), p );
657  aabox_corners( -1, -1, -2, 1, 1, -1, expt );
658  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
659  CHECK( compare_hexes( expt, corners, 1e-6 ) );
660 
661  rval = iter.step();CHECK_ERR( rval );
662  CHECK_EQUAL( 7u, iter.depth() );
663  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
664  CHECK_EQUAL( BSPTree::Plane( 0, 1, 0, -1 ), p );
665  aabox_corners( -1, 1, -2, 1, 2, -1, expt );
666  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
667  CHECK( compare_hexes( expt, corners, 1e-6 ) );
668 
669  rval = iter.step();CHECK_ERR( rval );
670  CHECK_EQUAL( 6u, iter.depth() );
671  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
672  CHECK_EQUAL( BSPTree::Plane( 0, -1, 0, -1 ), p );
673  aabox_corners( -1, -2, -2, 1, -1, -1, expt );
674  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
675  CHECK( compare_hexes( expt, corners, 1e-6 ) );
676 
677  rval = iter.step();CHECK_ERR( rval );
678  CHECK_EQUAL( 5u, iter.depth() );
679  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
680  CHECK_EQUAL( BSPTree::Plane( 1, 0, 0, -1 ), p );
681  aabox_corners( 1, -2, -2, 2, 2, -1, expt );
682  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
683  CHECK( compare_hexes( expt, corners, 1e-6 ) );
684 
685  rval = iter.step();CHECK_ERR( rval );
686  CHECK_EQUAL( 4u, iter.depth() );
687  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
688  CHECK_EQUAL( BSPTree::Plane( -1, 0, 0, -1 ), p );
689  aabox_corners( -2, -2, -2, -1, 2, -1, expt );
690  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
691  CHECK( compare_hexes( expt, corners, 1e-6 ) );
692 
693  rval = iter.step();CHECK_ERR( rval );
694  CHECK_EQUAL( 2u, iter.depth() );
695  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
696  CHECK_EQUAL( BSPTree::Plane( 0, 0, 1, 0 ), p );
697  aabox_corners( -2, -2, 0, 2, 2, 2, expt );
698  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
699  CHECK( compare_hexes( expt, corners, 1e-6 ) );
700 
701  // no more leaves
702  rval = iter.step();
704 }

References aabox_corners(), CHECK, CHECK_EQUAL, CHECK_ERR, compare_hexes(), moab::BSPTree::create_tree(), moab::BSPTreeIter::depth(), ErrorCode, moab::BSPTreeBoxIter::get_box_corners(), moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), MB_ENTITY_NOT_FOUND, moab::BSPTree::split_leaf(), moab::BSPTreeBoxIter::step(), and moab::BSPTreeIter::tool().

Referenced by main().

◆ test_gen_leaf_intersects_ray()

void test_gen_leaf_intersects_ray ( )

Definition at line 36 of file bsp_tree_test.cpp.

37 {
39 }

References test_leaf_intersects_ray_common().

Referenced by main().

◆ test_iterator()

void test_iterator ( )

Definition at line 96 of file bsp_tree_test.cpp.

97 {
98  Core moab;
99  BSPTree tool( &moab );
100  ErrorCode rval;
101  EntityHandle root;
102  BSPTreeIter iter;
103 
104  // create a depth-1 tree
105  rval = tool.create_tree( root );CHECK_ERR( rval );
106  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
107 
108  // check initial state of iterator
109  CHECK_EQUAL( &tool, iter.tool() );
110  CHECK_EQUAL( root, iter.handle() );
111  CHECK_EQUAL( 1u, iter.depth() );
112 
113  // should fail if at root
114  BSPTree::Plane p;
115  rval = iter.get_parent_split_plane( p );
117 
118  // check that step past end returns correct value
119  rval = iter.step();
121 
122  // reset iterator
123  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
124 
125  // check that step past start returns correct value
126  rval = iter.back();
128 
129  // reset iterator
130  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
131 
132  // insert a single split plane
133  rval = tool.split_leaf( iter, BSPTree::Plane( 2, 0, 0, 0 ) );CHECK_ERR( rval );
134 
135  // check initial location
136  CHECK_EQUAL( 2u, iter.depth() );
137  CHECK( iter.handle() != root );
138 
139  // create new iterators at left and right ends
140  BSPTreeIter left, right;
141  rval = tool.get_tree_iterator( root, left );CHECK_ERR( rval );
142  rval = tool.get_tree_end_iterator( root, right );CHECK_ERR( rval );
143 
144  // compare post-split iterator to left
145  CHECK_EQUAL( left.depth(), iter.depth() );
146  CHECK_EQUAL( left.handle(), iter.handle() );
147 
148  // step to other leaf
149  rval = iter.step();CHECK_ERR( rval );
150 
151  // check location
152  CHECK_EQUAL( 2u, iter.depth() );
153  CHECK( iter.handle() != root );
154 
155  // compare stepped iterator to right
156  CHECK_EQUAL( right.depth(), iter.depth() );
157  CHECK_EQUAL( right.handle(), iter.handle() );
158 
159  // step to back to first leaf
160  rval = iter.back();CHECK_ERR( rval );
161 
162  // compare to left
163  CHECK_EQUAL( left.depth(), iter.depth() );
164  CHECK_EQUAL( left.handle(), iter.handle() );
165 
166  // check plane
167  // should have unit normal
168  left.get_parent_split_plane( p );
169  CHECK_EQUAL( BSPTree::Plane( 1, 0, 0, 0 ), p );
170  p.norm[0] = 11;
171  right.get_parent_split_plane( p );
172  CHECK_EQUAL( BSPTree::Plane( 1, 0, 0, 0 ), p );
173 
174  // check step past ends
175  rval = left.back();
177  rval = right.step();
179 }

References moab::BSPTreeIter::back(), CHECK, CHECK_EQUAL, CHECK_ERR, moab::BSPTree::create_tree(), moab::BSPTreeIter::depth(), ErrorCode, moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_end_iterator(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), MB_ENTITY_NOT_FOUND, moab::BSPTree::Plane::norm, moab::BSPTree::split_leaf(), moab::BSPTreeIter::step(), and moab::BSPTreeIter::tool().

Referenced by main().

◆ test_leaf_containing_point_bounded_tree()

void test_leaf_containing_point_bounded_tree ( )

Definition at line 706 of file bsp_tree_test.cpp.

707 {
708  Core moab;
709  BSPTree tool( &moab );
710  ErrorCode rval;
711  EntityHandle root;
712  BSPTreeIter iter;
713  BSPTreeBoxIter b_iter;
714  BSPTree::Plane p;
715  EntityHandle h;
716  double expected[8][3], corners[8][3];
717 
718  /* Build Tree
719 
720  1.0 +---------+--------------+
721  | A | |
722  | | |
723  0.7 +---------+ C |
724  | | |
725  | | |
726  | B | |
727  | +--------------+ 0.3
728  | | D |
729  | | |
730  0.0 +---------+--------------+
731  0.0 0.4 1.0 */
732 
733  const BSPTree::Plane X_split( 1.0, 0.0, 0.0, -0.4 );
734  const BSPTree::Plane AB_split( 0.0, -1.0, 0.0, 0.7 );
735  const BSPTree::Plane CD_split( 0.0, -1.0, 0.0, 0.3 );
736 
737  const double min[3] = { 0, 0, 0 };
738  const double max[3] = { 1, 1, 1 };
739  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
740  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
741 
742  rval = tool.split_leaf( iter, X_split );CHECK_ERR( rval );
743 
744  rval = tool.split_leaf( iter, AB_split );CHECK_ERR( rval );
745  const EntityHandle A = iter.handle();
746 
747  rval = iter.step();CHECK_ERR( rval );
748  const EntityHandle B = iter.handle();
749 
750  rval = iter.step();CHECK_ERR( rval );
751  rval = tool.split_leaf( iter, CD_split );CHECK_ERR( rval );
752  const EntityHandle C = iter.handle();
753 
754  rval = iter.step();CHECK_ERR( rval );
755  const EntityHandle D = iter.handle();
756 
757  // Test queries inside tree
758 
759  const double A_point[] = { 0.1, 0.8, 0.5 };
760  rval = tool.leaf_containing_point( root, A_point, h );CHECK_ERR( rval );
761  CHECK_EQUAL( A, h );
762  rval = tool.leaf_containing_point( root, A_point, iter );CHECK_ERR( rval );
763  CHECK_EQUAL( A, iter.handle() );
764  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
765  CHECK_EQUAL( AB_split, p );
766  rval = tool.leaf_containing_point( root, A_point, b_iter );CHECK_ERR( rval );
767  CHECK_EQUAL( A, b_iter.handle() );
768  aabox_corners( 0.0, 0.7, 0.0, 0.4, 1.0, 1.0, expected );
769  rval = b_iter.get_box_corners( corners );CHECK_ERR( rval );
770  CHECK( compare_hexes( expected, corners, 1e-6 ) );
771 
772  const double B_point[] = { 0.3, 0.1, 0.6 };
773  rval = tool.leaf_containing_point( root, B_point, h );CHECK_ERR( rval );
774  CHECK_EQUAL( B, h );
775  rval = tool.leaf_containing_point( root, B_point, iter );CHECK_ERR( rval );
776  CHECK_EQUAL( B, iter.handle() );
777  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
778  CHECK_EQUAL( AB_split, p );
779  rval = tool.leaf_containing_point( root, B_point, b_iter );CHECK_ERR( rval );
780  CHECK_EQUAL( B, b_iter.handle() );
781  aabox_corners( 0.0, 0.0, 0.0, 0.4, 0.7, 1.0, expected );
782  rval = b_iter.get_box_corners( corners );CHECK_ERR( rval );
783  CHECK( compare_hexes( expected, corners, 1e-6 ) );
784 
785  const double C_point[] = { 0.9, 0.9, 0.1 };
786  rval = tool.leaf_containing_point( root, C_point, h );CHECK_ERR( rval );
787  CHECK_EQUAL( C, h );
788  rval = tool.leaf_containing_point( root, C_point, iter );CHECK_ERR( rval );
789  CHECK_EQUAL( C, iter.handle() );
790  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
791  CHECK_EQUAL( CD_split, p );
792  rval = tool.leaf_containing_point( root, C_point, b_iter );CHECK_ERR( rval );
793  CHECK_EQUAL( C, b_iter.handle() );
794  aabox_corners( 0.4, 0.3, 0.0, 1.0, 1.0, 1.0, expected );
795  rval = b_iter.get_box_corners( corners );CHECK_ERR( rval );
796  CHECK( compare_hexes( expected, corners, 1e-6 ) );
797 
798  const double D_point[] = { 0.5, 0.2, 0.9 };
799  rval = tool.leaf_containing_point( root, D_point, h );CHECK_ERR( rval );
800  CHECK_EQUAL( D, h );
801  rval = tool.leaf_containing_point( root, D_point, iter );CHECK_ERR( rval );
802  CHECK_EQUAL( D, iter.handle() );
803  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
804  CHECK_EQUAL( CD_split, p );
805  rval = tool.leaf_containing_point( root, D_point, b_iter );CHECK_ERR( rval );
806  CHECK_EQUAL( D, b_iter.handle() );
807  aabox_corners( 0.4, 0.0, 0.0, 1.0, 0.3, 1.0, expected );
808  rval = b_iter.get_box_corners( corners );CHECK_ERR( rval );
809  CHECK( compare_hexes( expected, corners, 1e-6 ) );
810 
811  // Try a couple points outside of the tree
812 
813  const double above_pt[] = { 0.5, 0.5, 2.0 };
814  rval = tool.leaf_containing_point( root, above_pt, b_iter );
816 
817  const double left_pt[] = { -1.0, 0.5, 0.5 };
818  rval = tool.leaf_containing_point( root, left_pt, b_iter );
820 }

References aabox_corners(), CHECK, CHECK_EQUAL, CHECK_ERR, compare_hexes(), moab::BSPTree::create_tree(), ErrorCode, moab::BSPTreeBoxIter::get_box_corners(), moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), moab::BSPTree::leaf_containing_point(), MB_ENTITY_NOT_FOUND, moab::BSPTree::split_leaf(), and moab::BSPTreeIter::step().

Referenced by main().

◆ test_leaf_containing_point_unbounded_tree()

void test_leaf_containing_point_unbounded_tree ( )

Definition at line 822 of file bsp_tree_test.cpp.

823 {
824  Core moab;
825  BSPTree tool( &moab );
826  ErrorCode rval;
827  EntityHandle root;
828  BSPTreeIter iter;
829  BSPTree::Plane p;
830  EntityHandle h;
831 
832  /* Build Tree
833 
834  \ |
835  \ C o (0,4,0)
836  \ |
837  \ |
838  \ |
839  B \ | D
840  \|
841  ________o (0,0,0)
842  \
843  \
844  A \
845  o (1,-2,0)
846  \
847  */
848  const BSPTree::Plane X_split( 2.0, 1.0, 0.0, 0.0 );
849  const BSPTree::Plane AB_split( 0.0, 1.0, 0.0, 0.0 );
850  const BSPTree::Plane CD_split( 1.0, 0.0, 0.0, 0.0 );
851 
852  rval = tool.create_tree( root );CHECK_ERR( rval );
853  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
854 
855  rval = tool.split_leaf( iter, X_split );CHECK_ERR( rval );
856 
857  rval = tool.split_leaf( iter, AB_split );CHECK_ERR( rval );
858  const EntityHandle A = iter.handle();
859 
860  rval = iter.step();CHECK_ERR( rval );
861  const EntityHandle B = iter.handle();
862 
863  rval = iter.step();CHECK_ERR( rval );
864  rval = tool.split_leaf( iter, CD_split );CHECK_ERR( rval );
865  const EntityHandle C = iter.handle();
866 
867  rval = iter.step();CHECK_ERR( rval );
868  const EntityHandle D = iter.handle();
869 
870  // Test queries inside tree
871 
872  const double A_point[] = { -1000, -1000, -1000 };
873  rval = tool.leaf_containing_point( root, A_point, h );CHECK_ERR( rval );
874  CHECK_EQUAL( A, h );
875  rval = tool.leaf_containing_point( root, A_point, iter );CHECK_ERR( rval );
876  CHECK_EQUAL( A, iter.handle() );
877  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
878  CHECK_EQUAL( AB_split, p );
879 
880  const double B_point[] = { -3, 1, 100 };
881  rval = tool.leaf_containing_point( root, B_point, h );CHECK_ERR( rval );
882  CHECK_EQUAL( B, h );
883  rval = tool.leaf_containing_point( root, B_point, iter );CHECK_ERR( rval );
884  CHECK_EQUAL( B, iter.handle() );
885  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
886  CHECK_EQUAL( AB_split, p );
887 
888  const double C_point[] = { -10, 500, 0 };
889  rval = tool.leaf_containing_point( root, C_point, h );CHECK_ERR( rval );
890  CHECK_EQUAL( C, h );
891  rval = tool.leaf_containing_point( root, C_point, iter );CHECK_ERR( rval );
892  CHECK_EQUAL( C, iter.handle() );
893  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
894  CHECK_EQUAL( CD_split, p );
895 
896  const double D_point[] = { 10, 500, 0 };
897  rval = tool.leaf_containing_point( root, D_point, h );CHECK_ERR( rval );
898  CHECK_EQUAL( D, h );
899  rval = tool.leaf_containing_point( root, D_point, iter );CHECK_ERR( rval );
900  CHECK_EQUAL( D, iter.handle() );
901  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
902  CHECK_EQUAL( CD_split, p );
903 }

References CHECK_EQUAL, CHECK_ERR, moab::BSPTree::create_tree(), ErrorCode, moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), moab::BSPTree::leaf_containing_point(), moab::BSPTree::split_leaf(), and moab::BSPTreeIter::step().

Referenced by main().

◆ test_leaf_intersects_ray_common()

void test_leaf_intersects_ray_common ( bool  box)

Start with only root box for initial testing

Now split twice and test the bottom right corne

Definition at line 1523 of file bsp_tree_test.cpp.

1524 {
1525  ErrorCode rval;
1526  Core moab;
1527  BSPTree tool( &moab );
1528  double t_in, t_out;
1529 
1530  /** Start with only root box for initial testing **/
1531 
1532  /* (1,5,-3) (2,5,-3)
1533  o----o
1534  /: / \
1535  / : / \
1536  (1,5,-1)o----o \
1537  | : \ \
1538  | : Y \ \
1539  | : ^ \ \
1540  | : | \ \
1541  | : +-->X \ \ (6,1,-3)
1542  | o./..........\.......o
1543  | . L \ /
1544  |. Z \ /
1545  o--------------------o
1546  (1,1,-1) (6,1,-1)
1547  */
1548  EntityHandle root;
1549  const double corners[][3] = { { 1, 1, -3 }, { 6, 1, -3 }, { 2, 5, -3 }, { 1, 5, -3 },
1550  { 1, 1, -1 }, { 6, 1, -1 }, { 2, 5, -1 }, { 1, 5, -1 } };
1551  rval = tool.create_tree( corners, root );CHECK_ERR( rval );
1552 
1553  BSPTreeIter gen_iter;
1554  BSPTreeBoxIter box_iter;
1555  BSPTreeIter& iter = box ? static_cast< BSPTreeIter& >( box_iter ) : gen_iter;
1556  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1557 
1558  // start with point inside box
1559  const double pt1[] = { 3.5, 3, -2 };
1560  const double dir1[] = { 0.1, 0.1, 0.1 };
1561  CHECK_RAY_XSECTS( pt1, dir1, 0, 2.5 );
1562  const double dir2[] = { 5, 5, 5 };
1563  CHECK_RAY_XSECTS( pt1, dir2, 0, 0.05 );
1564  const double pxdir[] = { 1, 0, 0 };
1565  CHECK_RAY_XSECTS( pt1, pxdir, 0, 0.5 );
1566  const double nxdir[] = { -1, 0, 0 };
1567  CHECK_RAY_XSECTS( pt1, nxdir, 0, 2.5 );
1568  const double pydir[] = { 0, 1, 0 };
1569  CHECK_RAY_XSECTS( pt1, pydir, 0, 0.5 );
1570  const double nydir[] = { 0, -1, 0 };
1571  CHECK_RAY_XSECTS( pt1, nydir, 0, 2 );
1572  const double pzdir[] = { 0, 0, 1 };
1573  CHECK_RAY_XSECTS( pt1, pzdir, 0, 1 );
1574  const double nzdir[] = { 0, 0, -1 };
1575  CHECK_RAY_XSECTS( pt1, nzdir, 0, 1 );
1576 
1577  // point below box
1578  const double pt2[] = { 3.5, 3, -4 };
1579  CHECK( !iter.intersect_ray( pt2, dir1, t_in, t_out ) );
1580  CHECK( !iter.intersect_ray( pt2, dir2, t_in, t_out ) );
1581  CHECK( !iter.intersect_ray( pt2, pxdir, t_in, t_out ) );
1582  CHECK( !iter.intersect_ray( pt2, nxdir, t_in, t_out ) );
1583  CHECK( !iter.intersect_ray( pt2, pydir, t_in, t_out ) );
1584  CHECK( !iter.intersect_ray( pt2, nydir, t_in, t_out ) );
1585  CHECK_RAY_XSECTS( pt2, pzdir, 1, 3 );
1586  CHECK( !iter.intersect_ray( pt2, nzdir, t_in, t_out ) );
1587 
1588  // point right of box
1589  const double pt3[] = { 7, 3, -2 };
1590  CHECK( !iter.intersect_ray( pt3, dir1, t_in, t_out ) );
1591  CHECK( !iter.intersect_ray( pt3, dir2, t_in, t_out ) );
1592  CHECK( !iter.intersect_ray( pt3, pxdir, t_in, t_out ) );
1593  CHECK_RAY_XSECTS( pt3, nxdir, 3, 6 );
1594  CHECK( !iter.intersect_ray( pt3, pydir, t_in, t_out ) );
1595  CHECK( !iter.intersect_ray( pt3, nydir, t_in, t_out ) );
1596  CHECK( !iter.intersect_ray( pt3, pzdir, t_in, t_out ) );
1597  CHECK( !iter.intersect_ray( pt3, nzdir, t_in, t_out ) );
1598 
1599  // a few more complex test cases
1600  const double dira[] = { -2, -2, 0 };
1601  CHECK_RAY_XSECTS( pt3, dira, 0.75, 1.0 );
1602  const double dirb[] = { -1, -2.1, 0 };
1603  CHECK( !iter.intersect_ray( pt3, dirb, t_in, t_out ) );
1604 
1605  /** Now split twice and test the bottom right corne **/
1606 
1607  BSPTree::Plane Y3( BSPTree::Y, 3.0 );
1608  rval = tool.split_leaf( iter, Y3 );CHECK_ERR( rval );
1609  BSPTree::Plane X2( BSPTree::X, 2.0 );
1610  rval = tool.split_leaf( iter, X2 );CHECK_ERR( rval );
1611  rval = iter.step();CHECK_ERR( rval );
1612 
1613  /*
1614  (2,3,-3)
1615  o--------o (4,3,-3)
1616  /: / \
1617  / : / \
1618  (2,3,-1)o--------o(4,3,-1)\ (6,1,-3)
1619  | o.......\.......o
1620  | . \ /
1621  |. \ /
1622  o---------------o
1623  (2,1,-1) (6,1,-1)
1624  */
1625 
1626  // start with point inside box
1627  const double pt4[] = { 4, 2, -2 };
1628  CHECK_RAY_XSECTS( pt4, dir1, 0, 5 );
1629  CHECK_RAY_XSECTS( pt4, dir2, 0, 0.1 );
1630  CHECK_RAY_XSECTS( pt4, pxdir, 0, 1 );
1631  CHECK_RAY_XSECTS( pt4, nxdir, 0, 2 );
1632  CHECK_RAY_XSECTS( pt4, pydir, 0, 1 );
1633  CHECK_RAY_XSECTS( pt4, nydir, 0, 1 );
1634  CHECK_RAY_XSECTS( pt4, pzdir, 0, 1 );
1635  CHECK_RAY_XSECTS( pt4, nzdir, 0, 1 );
1636 
1637  // point below box
1638  const double pt5[] = { 4, 2, -4 };
1639  CHECK( !iter.intersect_ray( pt5, dir1, t_in, t_out ) );
1640  CHECK( !iter.intersect_ray( pt5, dir2, t_in, t_out ) );
1641  CHECK( !iter.intersect_ray( pt5, pxdir, t_in, t_out ) );
1642  CHECK( !iter.intersect_ray( pt5, nxdir, t_in, t_out ) );
1643  CHECK( !iter.intersect_ray( pt5, pydir, t_in, t_out ) );
1644  CHECK( !iter.intersect_ray( pt5, nydir, t_in, t_out ) );
1645  CHECK_RAY_XSECTS( pt5, pzdir, 1, 3 );
1646  CHECK( !iter.intersect_ray( pt5, nzdir, t_in, t_out ) );
1647 
1648  // point right of box
1649  const double pt6[] = { 7, 2, -2 };
1650  CHECK( !iter.intersect_ray( pt6, dir1, t_in, t_out ) );
1651  CHECK( !iter.intersect_ray( pt6, dir2, t_in, t_out ) );
1652  CHECK( !iter.intersect_ray( pt6, pxdir, t_in, t_out ) );
1653  CHECK_RAY_XSECTS( pt6, nxdir, 2, 5 );
1654  CHECK( !iter.intersect_ray( pt6, pydir, t_in, t_out ) );
1655  CHECK( !iter.intersect_ray( pt6, nydir, t_in, t_out ) );
1656  CHECK( !iter.intersect_ray( pt6, pzdir, t_in, t_out ) );
1657  CHECK( !iter.intersect_ray( pt6, nzdir, t_in, t_out ) );
1658 
1659  // a few more complex test cases
1660  const double dird[] = { -2, -2, 0 };
1661  CHECK_RAY_XSECTS( pt6, dird, 0.5, 0.5 );
1662  const double dire[] = { -3, -2, 0 };
1663  CHECK_RAY_XSECTS( pt6, dire, 0.4, 0.5 );
1664  const double dirf[] = { -2, -2.1, 0 };
1665  CHECK( !iter.intersect_ray( pt6, dirf, t_in, t_out ) );
1666 }

References box(), CHECK, CHECK_ERR, CHECK_RAY_XSECTS, moab::BSPTree::create_tree(), ErrorCode, moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::intersect_ray(), moab::BSPTree::split_leaf(), moab::BSPTreeIter::step(), moab::BSPTree::X, and moab::BSPTree::Y.

Referenced by test_box_leaf_intersects_ray(), and test_gen_leaf_intersects_ray().

◆ test_leaf_polyhedron()

void test_leaf_polyhedron ( )

Definition at line 1824 of file bsp_tree_test.cpp.

1825 {
1826  // array of 20 points used to construct tree
1827  static const double points[] = { 7, 6, 3, 5, 3, 5, 9, 2, 6, 7, 2, 1, 3, 9, 0, 6, 0, 6, 1, 6,
1828  2, 9, 7, 8, 2, 0, 2, 5, 7, 3, 2, 2, 9, 7, 9, 8, 1, 6, 3, 3,
1829  9, 2, 4, 9, 1, 4, 8, 7, 3, 0, 5, 0, 1, 6, 2, 3, 6, 1, 6, 0 };
1830  const int num_pts = sizeof( points ) / ( 3 * sizeof( double ) );
1831 
1832  ErrorCode rval;
1833  Core moab;
1834  BSPTree tool( &moab );
1835  EntityHandle root = build_tree( points, num_pts, tool );
1836 
1837  BSPTreeIter iter;
1838  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1839 
1840  std::vector< EntityHandle > pts;
1841  std::vector< CartVect > coords;
1842 
1843  for( ; rval == MB_SUCCESS; rval = iter.step() )
1844  {
1845  BSPTreePoly poly;
1846  rval = iter.calculate_polyhedron( poly );CHECK_ERR( rval );
1847 
1848  CHECK( poly.is_valid() );
1849  CHECK( poly.volume() > 0.0 );
1850 
1851  pts.clear();
1852  rval = tool.moab()->get_entities_by_handle( iter.handle(), pts );CHECK_ERR( rval );
1853  CHECK( !pts.empty() );
1854  coords.resize( pts.size() );
1855  rval = tool.moab()->get_coords( &pts[0], pts.size(), coords[0].array() );CHECK_ERR( rval );
1856 
1857  for( size_t i = 0; i < pts.size(); ++i )
1858  CHECK( poly.is_point_contained( coords[i] ) );
1859  }
1860 }

References build_tree(), moab::BSPTreeIter::calculate_polyhedron(), CHECK, CHECK_ERR, ErrorCode, moab::Interface::get_coords(), moab::Interface::get_entities_by_handle(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), moab::BSPTreePoly::is_point_contained(), moab::BSPTreePoly::is_valid(), MB_SUCCESS, moab::BSPTree::moab(), moab::BSPTreeIter::step(), and moab::BSPTreePoly::volume().

Referenced by main().

◆ test_leaf_sibling()

void test_leaf_sibling ( )

Definition at line 1306 of file bsp_tree_test.cpp.

1307 {
1308  Core moab;
1309  BSPTree tool( &moab );
1310  ErrorCode rval;
1311  EntityHandle root;
1312  BSPTreeIter iter;
1313 
1314  /* Build Tree
1315 
1316  1.0 +---------+--------------+
1317  | A | |
1318  | | |
1319  0.7 +---------+ C |
1320  | | |
1321  | | |
1322  | B | |
1323  | +--------------+ 0.3
1324  | | D |
1325  | | |
1326  0.0 +---------+--------------+
1327  0.0 0.4 1.0 */
1328 
1329  const BSPTree::Plane X_split( 1.0, 0.0, 0.0, -0.4 );
1330  const BSPTree::Plane AB_split( 0.0, -1.0, 0.0, 0.7 );
1331  const BSPTree::Plane CD_split( 0.0, -1.0, 0.0, 0.3 );
1332 
1333  const double min[3] = { 0, 0, 0 };
1334  const double max[3] = { 1, 1, 1 };
1335  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
1336  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1337  rval = tool.split_leaf( iter, X_split );CHECK_ERR( rval );
1338  rval = tool.split_leaf( iter, AB_split );CHECK_ERR( rval );
1339  rval = iter.step();CHECK_ERR( rval );
1340  rval = iter.step();CHECK_ERR( rval );
1341  rval = tool.split_leaf( iter, CD_split );CHECK_ERR( rval );
1342 
1343  // create two iterators for testing
1344  BSPTreeIter iter1, iter2;
1345  rval = tool.get_tree_iterator( root, iter1 );CHECK_ERR( rval );
1346  rval = tool.get_tree_iterator( root, iter2 );CHECK_ERR( rval );
1347 
1348  // iter1 == A, iter2 == A
1349  CHECK( !iter1.is_sibling( iter1 ) );
1350  CHECK( !iter1.is_sibling( iter1.handle() ) );
1351  CHECK( !iter1.is_sibling( iter2 ) );
1352  CHECK( iter1.sibling_is_forward() );
1353 
1354  // iter1 == A, iter2 == B
1355  rval = iter2.step();CHECK_ERR( rval );
1356  CHECK( iter1.is_sibling( iter2 ) );
1357  CHECK( iter1.is_sibling( iter2.handle() ) );
1358  CHECK( iter2.is_sibling( iter1 ) );
1359  CHECK( iter2.is_sibling( iter1.handle() ) );
1360  CHECK( !iter2.sibling_is_forward() );
1361 
1362  // iter1 == A, iter2 == C
1363  rval = iter2.step();CHECK_ERR( rval );
1364  CHECK( !iter1.is_sibling( iter2 ) );
1365  CHECK( !iter1.is_sibling( iter2.handle() ) );
1366  CHECK( !iter2.is_sibling( iter1 ) );
1367  CHECK( !iter2.is_sibling( iter1.handle() ) );
1368  CHECK( iter2.sibling_is_forward() );
1369 
1370  // iter1 == B, iter2 == C
1371  rval = iter1.step();CHECK_ERR( rval );
1372  CHECK( !iter1.is_sibling( iter2 ) );
1373  CHECK( !iter1.is_sibling( iter2.handle() ) );
1374  CHECK( !iter2.is_sibling( iter1 ) );
1375  CHECK( !iter2.is_sibling( iter1.handle() ) );
1376  CHECK( !iter1.sibling_is_forward() );
1377 
1378  // iter1 == D, iter2 == C
1379  rval = iter1.step();CHECK_ERR( rval );
1380  CHECK_EQUAL( iter1.handle(), iter2.handle() );
1381  rval = iter1.step();CHECK_ERR( rval );
1382  CHECK( iter1.is_sibling( iter2 ) );
1383  CHECK( iter1.is_sibling( iter2.handle() ) );
1384  CHECK( iter2.is_sibling( iter1 ) );
1385  CHECK( iter2.is_sibling( iter1.handle() ) );
1386  CHECK( !iter1.sibling_is_forward() );
1387 }

References CHECK, CHECK_EQUAL, CHECK_ERR, moab::BSPTree::create_tree(), ErrorCode, moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), moab::BSPTreeIter::is_sibling(), moab::BSPTreeIter::sibling_is_forward(), moab::BSPTree::split_leaf(), and moab::BSPTreeIter::step().

Referenced by main().

◆ test_leaf_splits_intersects()

void test_leaf_splits_intersects ( )

Definition at line 1441 of file bsp_tree_test.cpp.

1442 {
1443  Core moab;
1444  BSPTree tool( &moab );
1445  ErrorCode rval;
1446  EntityHandle root;
1447  BSPTreeBoxIter iter;
1448  BSPTree::Plane p;
1449 
1450  const double min[3] = { 0, 0, 0 };
1451  const double max[3] = { 1, 2, 3 };
1452  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
1453  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1454 
1455  p.set( 1, 0, 0, 1 ); // x == -1
1456  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
1457  CHECK( !iter.intersects( p ) );
1458  p.flip();
1459  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
1460  CHECK( !iter.intersects( p ) );
1461 
1462  p.set( 1, 0, 0, 0 ); // x == 0
1463  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1464  p.flip();
1465  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1466 
1467  p.set( 1, 0, 0, -0.5 ); // x == 0.5
1468  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
1469  CHECK( iter.intersects( p ) );
1470  p.flip();
1471  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
1472  CHECK( iter.intersects( p ) );
1473 
1474  p.set( 1, 0, 0, -1 ); // x == 1
1475  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1476  p.flip();
1477  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1478 
1479  p.set( 1, 0, 0, -2 ); // x == 2
1480  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
1481  CHECK( !iter.intersects( p ) );
1482  p.flip();
1483  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
1484  CHECK( !iter.intersects( p ) );
1485 
1486  double pt1[3] = { 0, 0, 1.5 };
1487  double pt2[3] = { 1, 0, 1.5 };
1488  double pt3[3] = { 0, 1, 3.0 };
1489  p.set( pt1, pt2, pt3 );
1490  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1491  CHECK( iter.intersects( p ) );
1492  p.flip();
1493  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1494  CHECK( iter.intersects( p ) );
1495 
1496  double pt4[3] = { 0, 2, 2.8 };
1497  p.set( pt1, pt2, pt4 );
1498  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
1499  CHECK( iter.intersects( p ) );
1500  p.flip();
1501  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
1502  CHECK( iter.intersects( p ) );
1503 
1504  double pta[3] = { 0.8, 0, 0 };
1505  double ptb[3] = { 0, 0.2, 3 };
1506  double ptc[3] = { 0.8, 2, 3 };
1507  p.set( pta, ptb, ptc );
1508  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1509  CHECK( iter.intersects( p ) );
1510  p.flip();
1511  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
1512  CHECK( iter.intersects( p ) );
1513 }

References CHECK, CHECK_EQUAL, CHECK_ERR, moab::BSPTree::create_tree(), ErrorCode, moab::BSPTree::Plane::flip(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeBoxIter::intersects(), moab::BSPTreeBoxIter::MISS, moab::BSPTreeBoxIter::NONHEX, moab::BSPTree::Plane::set(), moab::BSPTreeBoxIter::SPLIT, and moab::BSPTreeBoxIter::splits().

Referenced by main().

◆ test_leaf_volume()

void test_leaf_volume ( bool  box)

Definition at line 1389 of file bsp_tree_test.cpp.

1390 {
1391  Core moab;
1392  BSPTree tool( &moab );
1393  ErrorCode rval;
1394  EntityHandle root;
1395  BSPTreeBoxIter b_iter;
1396  BSPTreeIter g_iter;
1397  BSPTreeIter& iter = box ? b_iter : g_iter;
1398 
1399  /* Build Tree
1400 
1401  1.0 +---------+--------------+
1402  | A | |
1403  | | |
1404  0.7 +---------+ C |
1405  | | |
1406  | | |
1407  | B | |
1408  | +--------------+ 0.3
1409  | | D |
1410  | | |
1411  0.0 +---------+--------------+
1412  0.0 0.4 1.0 */
1413 
1414  const BSPTree::Plane X_split( 1.0, 0.0, 0.0, -0.4 );
1415  const BSPTree::Plane AB_split( 0.0, -1.0, 0.0, 0.7 );
1416  const BSPTree::Plane CD_split( 0.0, -1.0, 0.0, 0.3 );
1417 
1418  const double min[3] = { 0, 0, 0 };
1419  const double max[3] = { 1, 1, 1 };
1420  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
1421  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1422  rval = tool.split_leaf( iter, X_split );CHECK_ERR( rval );
1423  rval = tool.split_leaf( iter, AB_split );CHECK_ERR( rval );
1424  rval = iter.step();CHECK_ERR( rval );
1425  rval = iter.step();CHECK_ERR( rval );
1426  rval = tool.split_leaf( iter, CD_split );CHECK_ERR( rval );
1427 
1428  // reset iterator
1429  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
1430 
1431  // check leaf volumes
1432  CHECK_REAL_EQUAL( 0.12, iter.volume(), 1e-12 ); // A
1433  CHECK_ERR( iter.step() );
1434  CHECK_REAL_EQUAL( 0.28, iter.volume(), 1e-12 ); // B
1435  CHECK_ERR( iter.step() );
1436  CHECK_REAL_EQUAL( 0.42, iter.volume(), 1e-12 ); // C
1437  CHECK_ERR( iter.step() );
1438  CHECK_REAL_EQUAL( 0.18, iter.volume(), 1e-12 ); // D
1439 }

References box(), CHECK_ERR, CHECK_REAL_EQUAL, moab::BSPTree::create_tree(), ErrorCode, moab::BSPTree::get_tree_iterator(), moab::BSPTree::split_leaf(), moab::BSPTreeIter::step(), and moab::BSPTreeIter::volume().

Referenced by test_leaf_volume_box(), and test_leaf_volume_gen().

◆ test_leaf_volume_box()

void test_leaf_volume_box ( )

Definition at line 22 of file bsp_tree_test.cpp.

23 {
24  test_leaf_volume( true );
25 }

References test_leaf_volume().

Referenced by main().

◆ test_leaf_volume_gen()

void test_leaf_volume_gen ( )

Definition at line 26 of file bsp_tree_test.cpp.

27 {
28  test_leaf_volume( false );
29 }

References test_leaf_volume().

Referenced by main().

◆ test_merge_leaf()

void test_merge_leaf ( )

Definition at line 905 of file bsp_tree_test.cpp.

906 {
907  Core moab;
908  BSPTree tool( &moab );
909  ErrorCode rval;
910  EntityHandle root;
911  BSPTreeBoxIter iter;
912  BSPTree::Plane p;
913  double expected[8][3], corners[8][3];
914 
915  /* Build Tree
916 
917  1.0 +---------+--------------+
918  | A | |
919  | | |
920  0.7 +---------+ C |
921  | | |
922  | | |
923  | B | |
924  | +--------------+ 0.3
925  | | D |
926  | | |
927  0.0 +---------+--------------+
928  0.0 0.4 1.0 */
929 
930  const BSPTree::Plane X_split( 1.0, 0.0, 0.0, -0.4 );
931  const BSPTree::Plane AB_split( 0.0, -1.0, 0.0, 0.7 );
932  const BSPTree::Plane CD_split( 0.0, -1.0, 0.0, 0.3 );
933 
934  const double min[3] = { 0, 0, 0 };
935  const double max[3] = { 1, 1, 1 };
936  rval = tool.create_tree( min, max, root );CHECK_ERR( rval );
937  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
938  rval = tool.split_leaf( iter, X_split );CHECK_ERR( rval );
939  const EntityHandle AB = iter.handle();
940  rval = tool.split_leaf( iter, AB_split );CHECK_ERR( rval );
941  rval = iter.step();CHECK_ERR( rval );
942  rval = iter.step();CHECK_ERR( rval );
943  const EntityHandle CD = iter.handle();
944  rval = tool.split_leaf( iter, CD_split );CHECK_ERR( rval );
945  rval = iter.step();CHECK_ERR( rval );
946 
947  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
948  rval = tool.merge_leaf( iter );CHECK_ERR( rval );
949  CHECK_EQUAL( AB, iter.handle() );
950  CHECK_EQUAL( 2u, iter.depth() );
951  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
952  CHECK_EQUAL( X_split, p );
953  aabox_corners( 0.0, 0.0, 0.0, 0.4, 1.0, 1.0, expected );
954  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
955  CHECK( compare_hexes( expected, corners, 1e-6 ) );
956 
957  rval = iter.step();CHECK_ERR( rval );
958  rval = iter.step();CHECK_ERR( rval );
959  rval = tool.merge_leaf( iter );CHECK_ERR( rval );
960  CHECK_EQUAL( CD, iter.handle() );
961  CHECK_EQUAL( 2u, iter.depth() );
962  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
963  CHECK_EQUAL( X_split, p );
964  aabox_corners( 0.4, 0.0, 0.0, 1.0, 1.0, 1.0, expected );
965  rval = iter.get_box_corners( corners );CHECK_ERR( rval );
966  CHECK( compare_hexes( expected, corners, 1e-6 ) );
967 
968  rval = iter.step();
970 }

References aabox_corners(), CHECK, CHECK_EQUAL, CHECK_ERR, compare_hexes(), moab::BSPTree::create_tree(), moab::BSPTreeIter::depth(), ErrorCode, moab::BSPTreeBoxIter::get_box_corners(), moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), MB_ENTITY_NOT_FOUND, moab::BSPTree::merge_leaf(), moab::BSPTree::split_leaf(), and moab::BSPTreeBoxIter::step().

Referenced by main().

◆ test_set_plane()

void test_set_plane ( )

Definition at line 86 of file bsp_tree_test.cpp.

87 {
89  const double points[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
90  p.set( points[0], points[1], points[2] );
91  CHECK_REAL_EQUAL( 0.0, p.distance( points[0] ), 1e-10 );
92  CHECK_REAL_EQUAL( 0.0, p.distance( points[1] ), 1e-10 );
93  CHECK_REAL_EQUAL( 0.0, p.distance( points[2] ), 1e-10 );
94 }

References CHECK_REAL_EQUAL, moab::BSPTree::Plane::distance(), and moab::BSPTree::Plane::set().

Referenced by main().

◆ test_tree_create()

void test_tree_create ( )

Definition at line 357 of file bsp_tree_test.cpp.

358 {
359  Core moab;
360  BSPTree tool( &moab );
361  ErrorCode rval;
362  EntityHandle root;
363  BSPTreeIter iter;
364  BSPTree::Plane p;
365 
366  // create a depth-1 tree
367  rval = tool.create_tree( root );CHECK_ERR( rval );
368  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
369 
370  // check initial state of iterator
371  CHECK_EQUAL( &tool, iter.tool() );
372  CHECK_EQUAL( root, iter.handle() );
373  CHECK_EQUAL( 1u, iter.depth() );
374 
375  // split with z=0
376  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 0, 0.5, 0 ) );CHECK_ERR( rval );
377  CHECK_EQUAL( 2u, iter.depth() );
378 
379  // check that parent split plane is correct
380  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
381  CHECK_EQUAL( BSPTree::Plane( 0, 0, 1, 0 ), p );
382 
383  // split lower leaf with diagonal plane
384  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 0, 0 ) );CHECK_ERR( rval );
385  CHECK_EQUAL( 3u, iter.depth() );
386 
387  const double r = 0.5 * sqrt( 2.0 );
388 
389  // check that parent split plane is correct
390  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
391  CHECK_EQUAL( BSPTree::Plane( r, r, 0, 0 ), p );
392 
393  // step to upper leaf
394  rval = iter.step();CHECK_ERR( rval );
395 
396  // split upper leaf with diagonal plane
397  rval = tool.split_leaf( iter, BSPTree::Plane( -1, 1, 0, 0 ) );CHECK_ERR( rval );
398  CHECK_EQUAL( 4u, iter.depth() );
399 
400  // check that parent split plane is correct
401  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
402  CHECK_EQUAL( BSPTree::Plane( -r, r, 0, 0 ), p );
403 
404  // iterate over four leaves
405 
406  // first leaf
407  rval = tool.get_tree_iterator( root, iter );CHECK_ERR( rval );
408  CHECK_EQUAL( 3u, iter.depth() );
409  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
410  CHECK_EQUAL( BSPTree::Plane( r, r, 0, 0 ), p );
411 
412  // second leaf
413  rval = iter.step();CHECK_ERR( rval );
414  CHECK_EQUAL( 4u, iter.depth() );
415  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
416  CHECK_EQUAL( BSPTree::Plane( -r, r, 0, 0 ), p );
417 
418  // third leaf
419  rval = iter.step();CHECK_ERR( rval );
420  CHECK_EQUAL( 4u, iter.depth() );
421  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
422  CHECK_EQUAL( BSPTree::Plane( -r, r, 0, 0 ), p );
423 
424  // fourth leaf
425  rval = iter.step();CHECK_ERR( rval );
426  CHECK_EQUAL( 2u, iter.depth() );
427  rval = iter.get_parent_split_plane( p );CHECK_ERR( rval );
428  CHECK_EQUAL( BSPTree::Plane( 0, 0, 1, 0 ), p );
429 
430  // no more leaves
431  rval = iter.step();
433 }

References CHECK_EQUAL, CHECK_ERR, moab::BSPTree::create_tree(), moab::BSPTreeIter::depth(), ErrorCode, moab::BSPTreeIter::get_parent_split_plane(), moab::BSPTree::get_tree_iterator(), moab::BSPTreeIter::handle(), MB_ENTITY_NOT_FOUND, moab::BSPTree::split_leaf(), moab::BSPTreeIter::step(), and moab::BSPTreeIter::tool().

Referenced by main().