#include <iostream>
#include <cstdlib>
#include <cstdio>
#include "moab/Core.hpp"
#include "moab/Interface.hpp"
#include "moab/Range.hpp"
#include "moab/ProgOptions.hpp"
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 23 of file FixPolys.cpp.
24 {
25 ProgOptions opts;
26
27 string inputFile = test_file_name;
28 opts.addOpt< string >( "inFile,i", "Specify the input file name string ", &inputFile );
29
30 string outFile = "out.h5m";
31 opts.addOpt< string >( "outFile,o", "Specify the output file name string ", &outFile );
32
33 opts.parseCommandLine( argc, argv );
34
35 // Instantiate
36 Core mb;
37
38 ErrorCode rval = mb.load_file( inputFile.c_str() );MB_CHK_SET_ERR( rval, "Error loading file" );
39
40 cout << " reading file " << inputFile << "\n";
41
42 // Get all 2d elements in the file set
43 Range elems;
44 rval = mb.get_entities_by_dimension( 0, 2, elems );MB_CHK_SET_ERR( rval, "Error getting 2d elements" );
45
46 cout << "number of cells: " << elems.size() << "\n";
47
48 Tag gidTag = mb.globalId_tag();
49 Range OldCells;
50 for( Range::iterator it = elems.begin(); it != elems.end(); ++it )
51 {
52 EntityHandle cell = *it;
53 const EntityHandle* conn;
54 int number_nodes;
55 rval = mb.get_connectivity( cell, conn, number_nodes );MB_CHK_SET_ERR( rval, "Error getting connectivity" );
56 // now check if we have consecutive duplicated vertices, and if so, create a new cell
57 std::vector< EntityHandle > new_verts;
58 // push to it, if we do not have duplicates
59
60 EntityHandle current = conn[0];
61 // new_verts.push_back(current);
62 for( int i = 1; i <= number_nodes; i++ )
63 {
64 EntityHandle nextV;
65 if( i < number_nodes )
66 nextV = conn[i];
67 else
68 nextV = conn[0]; // first vertex
69 if( current != nextV )
70 {
71 new_verts.push_back( current );
72 current = nextV;
73 }
74 }
75 if( number_nodes > (int)new_verts.size() )
76 {
77 // create a new poly, and put this in a list to be removed
78 int gid;
79 rval = mb.tag_get_data( gidTag, &cell, 1, &gid );MB_CHK_SET_ERR( rval, "Error getting global id tag" );
80 EntityHandle newCell;
81 rval = mb.create_element( MBPOLYGON, &new_verts[0], (int)new_verts.size(), newCell );MB_CHK_SET_ERR( rval, "Error creating new polygon " );
82 rval = mb.tag_set_data( gidTag, &newCell, 1, &gid );MB_CHK_SET_ERR( rval, "Error setting global id tag" );
83 cout << "delete old cell " << cell << " with num_nodes vertices: " << number_nodes
84 << " and with global id: " << gid << "\n";
85 for( int i = 0; i < number_nodes; i++ )
86 {
87 cout << " " << conn[i];
88 }
89 cout << "\n";
90 OldCells.insert( cell );
91 }
92 mb.delete_entities( OldCells );
93 }
94 rval = mb.write_file( outFile.c_str() );MB_CHK_SET_ERR( rval, "Error writing file" );
95
96 return 0;
97 }
References ProgOptions::addOpt(), moab::Range::begin(), moab::Core::create_element(), moab::Core::delete_entities(), moab::Range::end(), ErrorCode, moab::Core::get_connectivity(), moab::Core::get_entities_by_dimension(), moab::Core::globalId_tag(), moab::Range::insert(), moab::Core::load_file(), mb, MB_CHK_SET_ERR, MBPOLYGON, ProgOptions::parseCommandLine(), moab::Range::size(), moab::Core::tag_get_data(), moab::Core::tag_set_data(), test_file_name, and moab::Core::write_file().