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

Go to the source code of this file.

Functions

void test_read_ascii ()
 
void test_write_ascii ()
 
void test_type_option ()
 
void test_detect_type ()
 
void test_endian_option ()
 
void test_big_endian ()
 
void test_little_endian ()
 
void test_detect_byte_order ()
 
void read_file (Interface &moab, const char *input_file, const char *options="")
 
void convert_file (const char *source_file, const char *dest_file, const char *options="")
 
void check_mesh_is_tet (Interface &moab)
 
int main ()
 
ErrorCode read_file_ (Interface &moab, const char *input_file, const char *options="")
 

Variables

static const char sample [] = "sample.stl"
 
static const char * tmp_file = "test.stl"
 

Function Documentation

◆ check_mesh_is_tet()

void check_mesh_is_tet ( Interface moab)

Definition at line 166 of file stl_test.cpp.

167 {
168  ErrorCode rval;
169  Range verts, tris, other;
170  rval = moab.get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval );
171  rval = moab.get_entities_by_type( 0, MBTRI, tris );CHECK_ERR( rval );
172  rval = moab.get_entities_by_handle( 0, other );CHECK_ERR( rval );
173 
174  CHECK_EQUAL( 4, (int)verts.size() );
175  CHECK_EQUAL( 4, (int)tris.size() );
176  other = subtract( other, verts );
177  other = subtract( other, tris );
178  CHECK( other.all_of_type( MBENTITYSET ) );
179 
180  const double expt_coords[4][3] = { { 0, 0, 0 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
181  EntityHandle vert_handles[4] = { 0, 0, 0, 0 };
182  for( Range::iterator i = verts.begin(); i != verts.end(); ++i )
183  {
184  double coords[3];
185  rval = moab.get_coords( &*i, 1, coords );CHECK_ERR( rval );
186 
187  bool found = false;
188  for( int j = 0; j < 4; ++j )
189  {
190  double ds = 0;
191  for( int d = 0; d < 3; ++d )
192  {
193  double dl = expt_coords[j][d] - coords[d];
194  ds += dl * dl;
195  }
196 
197  if( ds < 1e-6 )
198  {
199  CHECK_EQUAL( (EntityHandle)0, vert_handles[j] );
200  vert_handles[j] = *i;
201  found = true;
202  break;
203  }
204  }
205  CHECK( found );
206  }
207 
208  const int expt_conn[4][3] = { { 0, 1, 3 }, { 0, 2, 1 }, { 0, 3, 2 }, { 1, 2, 3 } };
209  EntityHandle tri_handles[4] = { 0, 0, 0, 0 };
210  for( Range::iterator i = tris.begin(); i != tris.end(); ++i )
211  {
212  const EntityHandle* conn = 0;
213  int len = 0;
214  rval = moab.get_connectivity( *i, conn, len );CHECK_ERR( rval );
215  CHECK_EQUAL( 3, len );
216 
217  int conn_idx[3] = { static_cast< int >( std::find( vert_handles, vert_handles + 4, conn[0] ) - vert_handles ),
218  static_cast< int >( std::find( vert_handles, vert_handles + 4, conn[1] ) - vert_handles ),
219  static_cast< int >( std::find( vert_handles, vert_handles + 4, conn[2] ) - vert_handles ) };
220  CHECK( conn_idx[0] != 4 );
221  CHECK( conn_idx[1] != 4 );
222  CHECK( conn_idx[2] != 4 );
223 
224  bool found = false;
225  for( int j = 0; j < 4; ++j )
226  {
227  int k = std::find( expt_conn[j], expt_conn[j] + 3, conn_idx[0] ) - expt_conn[j];
228  if( k == 3 ) continue;
229 
230  if( expt_conn[j][( k + 1 ) % 3] == conn_idx[1] && expt_conn[j][( k + 2 ) % 3] == conn_idx[2] )
231  {
232  CHECK_EQUAL( (EntityHandle)0, tri_handles[j] );
233  tri_handles[j] = *i;
234  found = true;
235  break;
236  }
237  }
238  CHECK( found );
239  }
240 }

References moab::Range::all_of_type(), moab::Range::begin(), CHECK, CHECK_EQUAL, CHECK_ERR, moab::Range::end(), ErrorCode, MBENTITYSET, MBTRI, MBVERTEX, moab::Range::size(), and moab::subtract().

Referenced by test_big_endian(), test_little_endian(), test_read_ascii(), and test_write_ascii().

◆ convert_file()

void convert_file ( const char *  source_file,
const char *  dest_file,
const char *  options = "" 
)

Definition at line 66 of file stl_test.cpp.

67 {
68  ErrorCode rval;
69  Core moab;
70 
71  rval = moab.load_file( input_file );CHECK_ERR( rval );
72 
73  rval = moab.write_file( output_file, "STL", options );CHECK_ERR( rval );
74 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by test_big_endian(), test_detect_byte_order(), test_detect_type(), test_endian_option(), test_little_endian(), test_type_option(), and test_write_ascii().

◆ main()

int main ( )

Definition at line 38 of file stl_test.cpp.

39 {
40  int result = 0;
41 
42  result += RUN_TEST( test_read_ascii );
43  result += RUN_TEST( test_write_ascii );
44  result += RUN_TEST( test_type_option );
45  result += RUN_TEST( test_detect_type );
46  result += RUN_TEST( test_endian_option );
47  result += RUN_TEST( test_big_endian );
48  result += RUN_TEST( test_little_endian );
49  result += RUN_TEST( test_detect_byte_order );
50 
51  remove( tmp_file );
52  return result;
53 }

References RUN_TEST, test_big_endian(), test_detect_byte_order(), test_detect_type(), test_endian_option(), test_little_endian(), test_read_ascii(), test_type_option(), test_write_ascii(), and tmp_file.

◆ read_file()

void read_file ( Interface moab,
const char *  input_file,
const char *  options = "" 
)

◆ read_file_()

ErrorCode read_file_ ( Interface moab,
const char *  input_file,
const char *  options = "" 
)

Definition at line 55 of file stl_test.cpp.

56 {
57  ErrorCode rval = moab.load_file( input_file, 0, options );
58  return rval;
59 }

References ErrorCode, and input_file.

Referenced by read_file(), test_detect_type(), test_endian_option(), and test_type_option().

◆ test_big_endian()

void test_big_endian ( )

Definition at line 135 of file stl_test.cpp.

136 {
137  Core moab;
138  convert_file( sample, tmp_file, "BINARY;BIG_ENDIAN" );
139  read_file( moab, tmp_file, "BINARY;BIG_ENDIAN" );
141  remove( tmp_file );
142 }

References check_mesh_is_tet(), convert_file(), read_file(), sample, and tmp_file.

Referenced by main().

◆ test_detect_byte_order()

void test_detect_byte_order ( )

Definition at line 153 of file stl_test.cpp.

154 {
155  Core moab;
156 
157  convert_file( sample, tmp_file, "BINARY;LITTLE_ENDIAN" );
158  read_file( moab, tmp_file, "BINARY" );
159 
160  convert_file( sample, tmp_file, "BINARY;BIG_ENDIAN" );
161  read_file( moab, tmp_file, "BINARY" );
162 
163  remove( tmp_file );
164 }

References convert_file(), read_file(), sample, and tmp_file.

Referenced by main().

◆ test_detect_type()

void test_detect_type ( )

Definition at line 107 of file stl_test.cpp.

108 {
109  Core moab;
110 
111  read_file( moab, sample );
112 
113  convert_file( sample, tmp_file, "BINARY" );
115 
116  remove( tmp_file );
117 }

References convert_file(), read_file(), read_file_(), sample, and tmp_file.

Referenced by main().

◆ test_endian_option()

void test_endian_option ( )

Definition at line 119 of file stl_test.cpp.

120 {
121  ErrorCode rval;
122  Core moab;
123 
124  convert_file( sample, tmp_file, "BINARY;BIG_ENDIAN" );
125  rval = read_file_( moab, tmp_file, "BINARY;LITTLE_ENDIAN" );
126  CHECK( MB_SUCCESS != rval );
127 
128  convert_file( sample, tmp_file, "BINARY;LITTLE_ENDIAN" );
129  rval = read_file_( moab, tmp_file, "BINARY;BIG_ENDIAN" );
130  CHECK( MB_SUCCESS != rval );
131 
132  remove( tmp_file );
133 }

References CHECK, convert_file(), ErrorCode, MB_SUCCESS, read_file_(), sample, and tmp_file.

Referenced by main().

◆ test_little_endian()

void test_little_endian ( )

Definition at line 144 of file stl_test.cpp.

145 {
146  Core moab;
147  convert_file( sample, tmp_file, "BINARY;LITTLE_ENDIAN" );
148  read_file( moab, tmp_file, "BINARY;LITTLE_ENDIAN" );
150  remove( tmp_file );
151 }

References check_mesh_is_tet(), convert_file(), read_file(), sample, and tmp_file.

Referenced by main().

◆ test_read_ascii()

void test_read_ascii ( )

Definition at line 76 of file stl_test.cpp.

77 {
78  Core moab;
79  read_file( moab, sample, "ASCII" );
81 }

References check_mesh_is_tet(), read_file(), and sample.

Referenced by main().

◆ test_type_option()

void test_type_option ( )

Definition at line 92 of file stl_test.cpp.

93 {
94  ErrorCode rval;
95  Core moab;
96 
97  rval = read_file_( moab, sample, "BINARY" );
98  CHECK( MB_SUCCESS != rval );
99 
100  convert_file( sample, tmp_file, "BINARY" );
101  rval = read_file_( moab, tmp_file, "ASCII" );
102  CHECK( MB_SUCCESS != rval );
103 
104  remove( tmp_file );
105 }

References CHECK, convert_file(), ErrorCode, MB_SUCCESS, read_file_(), sample, and tmp_file.

Referenced by main().

◆ test_write_ascii()

void test_write_ascii ( )

Definition at line 83 of file stl_test.cpp.

84 {
85  convert_file( sample, tmp_file, "ASCII" );
86  Core moab;
87  read_file( moab, tmp_file, "ASCII" );
88  remove( tmp_file );
90 }

References check_mesh_is_tet(), convert_file(), read_file(), sample, and tmp_file.

Referenced by main().

Variable Documentation

◆ sample

◆ tmp_file