MOAB: Mesh Oriented datABase  (version 5.4.1)
intx_in_plane_test.cpp
Go to the documentation of this file.
00001 /*
00002  * intx_in_plane_test.cpp
00003  *
00004  *  Created on: Oct 4, 2012
00005  */
00006 #include <iostream>
00007 #include <sstream>
00008 #include <ctime>
00009 #include <cstdlib>
00010 #include <cstdio>
00011 #include <cstring>
00012 #include "moab/Core.hpp"
00013 #include "moab/Interface.hpp"
00014 #include "moab/IntxMesh/Intx2MeshInPlane.hpp"
00015 #include "moab/IntxMesh/IntxUtils.hpp"
00016 #include "TestUtil.hpp"
00017 #include <cmath>
00018 
00019 using namespace moab;
00020 
00021 int main( int argc, char* argv[] )
00022 {
00023     // check command line arg
00024     const char* filename_mesh1 = STRINGIFY( MESHDIR ) "/mbcslam/m1.vtk";
00025     const char* filename_mesh2 = STRINGIFY( MESHDIR ) "/mbcslam/m2.vtk";
00026     const char* newFile        = "intx1.vtk";
00027     const char* edgesFile      = "polyWithEdges.vtk";
00028     if( argc == 4 )
00029     {
00030         filename_mesh1 = argv[1];
00031         filename_mesh2 = argv[2];
00032         newFile        = argv[3];
00033     }
00034     else
00035     {
00036         printf( "Usage: %s <mesh_filename1> <mesh_filename2>  <newFile>\n", argv[0] );
00037         if( argc != 1 ) return 1;
00038         printf( "No files specified.  Defaulting to: %s  %s  %s\n", filename_mesh1, filename_mesh2, newFile );
00039     }
00040 
00041     // read meshes in 2 file sets
00042     Core moab;
00043     Interface* mb = &moab;  // global
00044     EntityHandle sf1, sf2;
00045     ErrorCode rval = mb->create_meshset( MESHSET_SET, sf1 );
00046     if( MB_SUCCESS != rval ) return 1;
00047     rval = mb->create_meshset( MESHSET_SET, sf2 );
00048     if( MB_SUCCESS != rval ) return 1;
00049     rval = mb->load_file( filename_mesh1, &sf1 );
00050     if( MB_SUCCESS != rval ) return 1;
00051     rval = mb->load_file( filename_mesh2, &sf2 );
00052     if( MB_SUCCESS != rval ) return 1;
00053 
00054     EntityHandle outputSet;
00055     rval = mb->create_meshset( MESHSET_SET, outputSet );
00056     if( MB_SUCCESS != rval ) return 1;
00057 
00058     Intx2MeshInPlane worker( mb );
00059     IntxAreaUtils areaAdaptor;
00060     rval = areaAdaptor.positive_orientation( mb, sf1, -1 );MB_CHK_ERR( rval );
00061     rval = areaAdaptor.positive_orientation( mb, sf2, -1 );MB_CHK_ERR( rval );
00062 
00063     worker.set_error_tolerance( 1.e-5 );
00064     rval = worker.FindMaxEdges( sf1, sf2 );MB_CHK_ERR( rval );
00065     // worker.enable_debug();
00066     rval = worker.intersect_meshes( sf1, sf2, outputSet );
00067     if( MB_SUCCESS != rval ) return 1;
00068     rval = mb->write_mesh( newFile, &outputSet, 1 );
00069     if( MB_SUCCESS != rval ) return 1;
00070 
00071     // retrieve polygons and get adjacent edges
00072     Range polygons;
00073     rval = mb->get_entities_by_type( outputSet, MBPOLYGON, polygons );
00074     if( MB_SUCCESS != rval ) return 1;
00075 
00076     Range edges;
00077     rval = mb->get_adjacencies( polygons, 1, true, edges, Interface::UNION );
00078     if( MB_SUCCESS != rval ) return 1;
00079 
00080     std::cout << "number of edges:" << edges.size() << "\n";
00081     // add edges to the output set
00082     rval = mb->add_entities( outputSet, edges );
00083     if( MB_SUCCESS != rval ) return 1;
00084     rval = mb->write_mesh( edgesFile, &outputSet, 1 );
00085     if( MB_SUCCESS != rval ) return 1;
00086     return 0;
00087 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines