MOAB: Mesh Oriented datABase  (version 5.5.0)
intx_in_plane_test.cpp
Go to the documentation of this file.
1 /*
2  * intx_in_plane_test.cpp
3  *
4  * Created on: Oct 4, 2012
5  */
6 #include <iostream>
7 #include <sstream>
8 #include <ctime>
9 #include <cstdlib>
10 #include <cstdio>
11 #include <cstring>
12 #include "moab/Core.hpp"
13 #include "moab/Interface.hpp"
16 #include "TestUtil.hpp"
17 #include <cmath>
18 
19 using namespace moab;
20 
21 int main( int argc, char* argv[] )
22 {
23  // check command line arg
24  const char* filename_mesh1 = STRINGIFY( MESHDIR ) "/mbcslam/m1.vtk";
25  const char* filename_mesh2 = STRINGIFY( MESHDIR ) "/mbcslam/m2.vtk";
26  const char* newFile = "intx1.vtk";
27  const char* edgesFile = "polyWithEdges.vtk";
28  if( argc == 4 )
29  {
30  filename_mesh1 = argv[1];
31  filename_mesh2 = argv[2];
32  newFile = argv[3];
33  }
34  else
35  {
36  printf( "Usage: %s <mesh_filename1> <mesh_filename2> <newFile>\n", argv[0] );
37  if( argc != 1 ) return 1;
38  printf( "No files specified. Defaulting to: %s %s %s\n", filename_mesh1, filename_mesh2, newFile );
39  }
40 
41  // read meshes in 2 file sets
42  Core moab;
43  Interface* mb = &moab; // global
44  EntityHandle sf1, sf2;
45  ErrorCode rval = mb->create_meshset( MESHSET_SET, sf1 );
46  if( MB_SUCCESS != rval ) return 1;
47  rval = mb->create_meshset( MESHSET_SET, sf2 );
48  if( MB_SUCCESS != rval ) return 1;
49  rval = mb->load_file( filename_mesh1, &sf1 );
50  if( MB_SUCCESS != rval ) return 1;
51  rval = mb->load_file( filename_mesh2, &sf2 );
52  if( MB_SUCCESS != rval ) return 1;
53 
54  EntityHandle outputSet;
55  rval = mb->create_meshset( MESHSET_SET, outputSet );
56  if( MB_SUCCESS != rval ) return 1;
57 
58  Intx2MeshInPlane worker( mb );
59  IntxAreaUtils areaAdaptor;
60  rval = areaAdaptor.positive_orientation( mb, sf1, -1 );MB_CHK_ERR( rval );
61  rval = areaAdaptor.positive_orientation( mb, sf2, -1 );MB_CHK_ERR( rval );
62 
63  worker.set_error_tolerance( 1.e-5 );
64  rval = worker.FindMaxEdges( sf1, sf2 );MB_CHK_ERR( rval );
65  // worker.enable_debug();
66  rval = worker.intersect_meshes( sf1, sf2, outputSet );
67  if( MB_SUCCESS != rval ) return 1;
68  rval = mb->write_mesh( newFile, &outputSet, 1 );
69  if( MB_SUCCESS != rval ) return 1;
70 
71  // retrieve polygons and get adjacent edges
72  Range polygons;
73  rval = mb->get_entities_by_type( outputSet, MBPOLYGON, polygons );
74  if( MB_SUCCESS != rval ) return 1;
75 
76  Range edges;
77  rval = mb->get_adjacencies( polygons, 1, true, edges, Interface::UNION );
78  if( MB_SUCCESS != rval ) return 1;
79 
80  std::cout << "number of edges:" << edges.size() << "\n";
81  // add edges to the output set
82  rval = mb->add_entities( outputSet, edges );
83  if( MB_SUCCESS != rval ) return 1;
84  rval = mb->write_mesh( edgesFile, &outputSet, 1 );
85  if( MB_SUCCESS != rval ) return 1;
86  return 0;
87 }