MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /** \brief This test shows how to fix polygons that have duplicated vertices 00002 * 00003 * We sometimes use padded vertices option, to reduce the number of data sequences 00004 * We identify first the polygons that have padded vertices 00005 * then we set the new ones with reduced number of vertices, but with the same global id tag 00006 */ 00007 00008 #include <iostream> 00009 #include <cstdlib> 00010 #include <cstdio> 00011 00012 #include "moab/Core.hpp" 00013 #include "moab/Interface.hpp" 00014 #include "moab/Range.hpp" 00015 #include "moab/ProgOptions.hpp" 00016 00017 00018 using namespace moab; 00019 using namespace std; 00020 00021 #ifdef MOAB_HAVE_HDF5 00022 string test_file_name = string( MESH_DIR ) + string( "/64bricks_512hex_256part.h5m" ); 00023 #endif 00024 int main( int argc, char** argv ) 00025 { 00026 ProgOptions opts; 00027 00028 string inputFile = test_file_name; 00029 opts.addOpt< string >( "inFile,i", "Specify the input file name string ", &inputFile ); 00030 00031 string outFile = "out.h5m"; 00032 opts.addOpt< string >( "outFile,o", "Specify the output file name string ", &outFile ); 00033 00034 opts.parseCommandLine( argc, argv ); 00035 00036 00037 // Instantiate 00038 Core mb; 00039 00040 ErrorCode rval = mb.load_file( inputFile.c_str());MB_CHK_SET_ERR( rval, "Error loading file" ); 00041 00042 00043 cout << " reading file " << inputFile << "\n"; 00044 00045 // Get all 2d elements in the file set 00046 Range elems; 00047 rval = mb.get_entities_by_dimension( 0, 2, elems );MB_CHK_SET_ERR( rval, "Error getting 2d elements" ); 00048 00049 cout << "number of cells: " << elems.size() << "\n"; 00050 00051 Tag gidTag = mb.globalId_tag(); 00052 Range OldCells; 00053 for( Range::iterator it = elems.begin(); it != elems.end(); ++it ) 00054 { 00055 EntityHandle cell = *it; 00056 const EntityHandle* conn; 00057 int number_nodes; 00058 rval = mb.get_connectivity( cell, conn, number_nodes); MB_CHK_SET_ERR( rval, "Error getting connectivity" ); 00059 // now check if we have consecutive duplicated vertices, and if so, create a new cell 00060 std::vector<EntityHandle> new_verts; 00061 // push to it, if we do not have duplicates 00062 00063 EntityHandle current=conn[0]; 00064 //new_verts.push_back(current); 00065 for (int i=1; i<=number_nodes; i++) 00066 { 00067 EntityHandle nextV; 00068 if (i<number_nodes) 00069 nextV = conn[i]; 00070 else 00071 nextV=conn[0];// first vertex 00072 if (current!=nextV) 00073 { 00074 new_verts.push_back(current); 00075 current=nextV; 00076 } 00077 } 00078 if (number_nodes > (int)new_verts.size()) 00079 { 00080 // create a new poly, and put this in a list to be removed 00081 int gid; 00082 rval = mb.tag_get_data(gidTag, &cell, 1, &gid); MB_CHK_SET_ERR( rval, "Error getting global id tag" ); 00083 EntityHandle newCell; 00084 rval = mb.create_element(MBPOLYGON, &new_verts[0], (int)new_verts.size(), 00085 newCell); MB_CHK_SET_ERR( rval, "Error creating new polygon "); 00086 rval = mb.tag_set_data(gidTag, &newCell, 1, &gid); MB_CHK_SET_ERR( rval, "Error setting global id tag" ); 00087 cout << "delete old cell " << cell << " with num_nodes vertices: " << number_nodes << " and with global id: "<< gid << "\n"; 00088 for (int i=0; i<number_nodes; i++) 00089 { 00090 cout << " " << conn[i]; 00091 } 00092 cout << "\n"; 00093 OldCells.insert(cell); 00094 } 00095 mb.delete_entities(OldCells); 00096 00097 } 00098 rval = mb.write_file( outFile.c_str());MB_CHK_SET_ERR( rval, "Error writing file" ); 00099 00100 return 0; 00101 }