MOAB: Mesh Oriented datABase  (version 5.2.1)
test_boundbox.cpp
Go to the documentation of this file.
00001 #include "TestUtil.hpp"
00002 #include "moab/Core.hpp"
00003 #include "moab/BoundBox.hpp"
00004 #include "moab/ScdInterface.hpp"
00005 
00006 using namespace moab;
00007 
00008 #include <iostream>
00009 
00010 //! test add_entities, get_entities, num_entities
00011 void test_bound_box();
00012 
00013 int main()
00014 {
00015     int err = 0;
00016 
00017     err += RUN_TEST( test_bound_box );
00018 
00019     if( !err )
00020         printf( "ALL TESTS PASSED\n" );
00021     else
00022         printf( "%d TESTS FAILED\n", err );
00023 
00024     return err;
00025 }
00026 
00027 void test_bound_box()
00028 {
00029     BoundBox box;
00030     CartVect vec( 0.0 );
00031     double tol = 0.0;
00032     std::vector< double > vals( 6, 0.0 );
00033     BoundBox other_box( &vals[0] );
00034 
00035     // test for contains point failure
00036     bool result = box.contains_point( vec.array(), tol );
00037     CHECK( !result );
00038     result = box.intersects_box( other_box, tol );
00039     CHECK( !result );
00040 
00041     box = other_box;
00042     tol = 1.0e-10;
00043 
00044     // test for success
00045     result = box.contains_point( &vals[0], tol );
00046     CHECK( result );
00047     result = box.intersects_box( other_box, tol );
00048     CHECK( result );
00049 
00050     // check update functions
00051     CartVect three( 3.0 );
00052     box.update_max( three.array() );
00053     result = box.contains_point( three.array(), tol );
00054     CHECK( result );
00055     result = box.contains_point( ( three * 1.1 ).array(), tol );
00056     CHECK( !result );
00057     result = box.intersects_box( BoundBox( three, three ), tol );
00058     CHECK( result );
00059     result = box.intersects_box( BoundBox( 1.1 * three, 3.0 * three ), tol );
00060     CHECK( !result );
00061 
00062     CartVect negthree( -3.0 );
00063     box.update_min( negthree.array() );
00064     result = box.contains_point( negthree.array(), tol );
00065     CHECK( result );
00066     result = box.contains_point( ( negthree * 1.1 ).array(), tol );
00067     CHECK( !result );
00068     result = box.intersects_box( BoundBox( negthree, negthree ), tol );
00069     CHECK( result );
00070     result = box.intersects_box( BoundBox( 3.0 * negthree, 1.1 * negthree ), tol );
00071     CHECK( !result );
00072 
00073     for( int i = 0; i < 3; i++ )
00074     {
00075         vals[i]     = -4.0;
00076         vals[3 + i] = 4.0;
00077     }
00078     box.update( &vals[0] );
00079     result = box.contains_point( &vals[0], tol );
00080     CHECK( result );
00081     result = box.contains_point( ( CartVect( &vals[0] ) * 1.1 ).array(), tol );
00082     CHECK( !result );
00083     result = box.intersects_box( BoundBox( &vals[0] ), tol );
00084     CHECK( result );
00085     result = box.intersects_box( BoundBox( 1.2 * CartVect( &vals[0] ), 1.1 * CartVect( &vals[0] ) ), tol );
00086     CHECK( !result );
00087 
00088     // check length functions
00089     tol = 1.0e-6;
00090 
00091     // box should be 8 on a side, or 3*(2^3)^2 or 192 for diag length squared
00092     double diagsq = box.diagonal_squared();
00093     CHECK_REAL_EQUAL( diagsq, 192.0, tol );
00094     double diag = box.diagonal_length();
00095     CHECK_REAL_EQUAL( diag, sqrt( 3.0 ) * 8.0, tol );
00096 
00097     // check distance function
00098 
00099     // face-centered
00100     vals[0] = vals[1] = 0.0;
00101     vals[2]           = 6.0;
00102     double dist       = box.distance_squared( CartVect( &vals[0] ).array() );
00103     CHECK_REAL_EQUAL( dist, 4.0, tol );
00104     dist = box.distance( CartVect( &vals[0] ).array() );
00105     CHECK_REAL_EQUAL( dist, 2.0, tol );
00106 
00107     // edge-centered
00108     vals[0] = 0.0;
00109     vals[1] = vals[2] = 6.0;
00110     dist              = box.distance_squared( CartVect( &vals[0] ).array() );
00111     CHECK_REAL_EQUAL( dist, 8.0, tol );
00112     dist = box.distance( CartVect( &vals[0] ).array() );
00113     CHECK_REAL_EQUAL( dist, sqrt( 8.0 ), tol );
00114 
00115     // vertex-centered
00116     vals[0] = vals[1] = vals[2] = 6.0;
00117     dist                        = box.distance_squared( CartVect( &vals[0] ).array() );
00118     CHECK_REAL_EQUAL( dist, 12.0, tol );
00119     dist = box.distance( CartVect( &vals[0] ).array() );
00120     CHECK_REAL_EQUAL( dist, sqrt( 12.0 ), tol );
00121 
00122     // check entity-based functions
00123     Core mb;
00124     ScdInterface* scdi;
00125     ErrorCode rval = mb.query_interface( scdi );CHECK_ERR( rval );
00126     ScdBox* scd_box;
00127     // create a 10x10x10 box
00128     rval = scdi->construct_box( HomCoord( 0, 0, 0 ), HomCoord( 10, 10, 10 ), NULL, 0, scd_box );CHECK_ERR( rval );
00129 
00130     EntityHandle vert = scd_box->start_vertex(), elem = scd_box->start_element();
00131     rval = box.update( mb, vert );CHECK_ERR( rval );
00132     rval = mb.get_coords( &vert, 1, &vals[0] );CHECK_ERR( rval );
00133     tol    = 1.0e-10;
00134     result = box.contains_point( &vals[0], tol );
00135     CHECK( result );
00136     rval = box.update( mb, elem );CHECK_ERR( rval );
00137     rval = mb.get_coords( &elem, 1, &vals[0] );CHECK_ERR( rval );
00138     result = box.contains_point( &vals[0], tol );
00139     CHECK( result );
00140 
00141     Range all_elems( elem, elem + scd_box->num_elements() - 1 );
00142     rval = box.update( mb, all_elems );CHECK_ERR( rval );
00143     CartVect center;
00144     box.compute_center( center );
00145     tol = 1.0e-6;
00146     CHECK_REAL_EQUAL( ( center - CartVect( 5.0, 5.0, 5.0 ) ).length(), 0.0, tol );
00147 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines