MeshKit  1.0
make_watertight.cpp
Go to the documentation of this file.
00001 // ********************************************************************
00002 // Brandon Smith
00003 // August, 2009
00004 
00005 /* _curve_to_be_tested_for_watertightness_
00006       vert1 X X vert1
00007             | |
00008       vert2 X |
00009   surf1     | |    surf2
00010             | |
00011       vert3 X X vert2
00012             | |
00013       vert4 X X vert3                   */
00014 
00015 // input:  h5m filename, tolerance
00016 // output: watertight h5m
00017 
00018 // make CXXFLAGS=-g for debug
00019 // make CXXFLAGS=-pg for profiling
00020 
00021 // modified by Andrew Davis 2012
00022 // Updated deprecated MOAB calls
00023 
00024 #include <iostream>
00025 #include <sstream>
00026 #include <iomanip> // for setprecision
00027 #include <limits> // for min/max values
00028 #include <assert.h>
00029 #include <math.h>
00030 #include <time.h>
00031 #include <vector>
00032 
00033 #include "moab/Core.hpp"
00034 #include "MBTagConventions.hpp"
00035 #include "moab/Range.hpp"
00036 #include "moab/Skinner.hpp"
00037 #include "moab/GeomTopoTool.hpp"
00038 
00039 #include "meshkit/mw_func.hpp"
00040 #include "meshkit/gen.hpp"
00041 #include "meshkit/arc.hpp"
00042 #include "meshkit/zip.hpp"
00043 #include "meshkit/cleanup.hpp"
00044 
00045 
00046 using namespace moab;
00047 
00048 ErrorCode write_sealed_file( std::string root_filename, double facet_tol, bool is_acis);
00049 
00050 
00051 
00052 int main(int argc, char **argv) 
00053   {
00054 
00055 // ******************************************************************
00056 // Load the h5m file 
00057 // ******************************************************************
00058 
00059     clock_t start_time = clock();
00060 
00061 
00062     // check input args
00063     if( 2 > argc || 3 < argc ) 
00064       {
00065         std::cout << "To zip a faceted h5m file:" << std::endl;
00066         std::cout << "$ ./make_watertight <input_file.h5m>" << std::endl;
00067         std::cout << "To facet and zip an ACIS file using the default facet tolerance:" << std::endl;
00068         std::cout << "$ ./make_watertight <input_file.sat>" << std::endl;
00069         std::cout << "To facet and zip an ACIS file using a specified facet tolerance:" << std::endl;
00070         std::cout << "$ ./make_watertight <input_file.sat> <facet_tolerance>" << std::endl;
00071         return MB_FAILURE;
00072       }
00073 
00074     // The root name does not have an extension
00075     std::string input_name = argv[1];
00076     std::string root_name = argv[1];
00077     int len = root_name.length();
00078     root_name.erase(len - 4);
00079     bool is_acis;
00080 
00081     // load the input file
00082     ErrorCode result, rval;
00083     EntityHandle input_set;
00084 
00085     rval = MBI()->create_meshset( MESHSET_SET, input_set );
00086 
00087     if(gen::error(MB_SUCCESS!=rval,"failed to create_meshset"))
00088       {
00089         return rval;
00090       }
00091 
00092     std::cout << "Loading input file..." << std::endl;
00093 
00094     // If reading an h5m file, the facet tolerance has already been determined.
00095     // Read the facet_tol from the file_set. There should only be one input
00096     // argument.
00097 
00098     if(std::string::npos!=input_name.find("h5m") && (2==argc)) 
00099       {
00100         rval = MBI()->load_file( input_name.c_str(), &input_set );
00101         if(gen::error(MB_SUCCESS!=rval,"failed to load_file 0"))
00102           {
00103             return rval;      
00104           }
00105         
00106         is_acis = false;
00107 
00108        }
00109     //loading completed at this point
00110     clock_t load_time = clock();  
00111     //seal the input mesh set
00112     double facet_tol;
00113     result= mw_func::make_mesh_watertight(input_set, facet_tol);
00114     if(gen::error(MB_SUCCESS!=result, "could not make model watertight")) return result;
00115 
00116   
00117     //write file
00118     clock_t zip_time = clock();  
00119     std::cout << "Writing zipped file..." << std::endl;
00120     write_sealed_file( root_name, facet_tol, is_acis);
00121     if(gen::error(MB_SUCCESS!=result, "could not write the sealed mesh to a new file"))
00122     return result; 
00123 
00124     clock_t write_time = clock();
00125     std::cout << "Timing(seconds): loading=" 
00126               << (double) (load_time -start_time)/CLOCKS_PER_SEC << ", sealing=" 
00127               << (double) (zip_time  -load_time )/CLOCKS_PER_SEC << ", writing=" 
00128               << (double) (write_time-zip_time  )/CLOCKS_PER_SEC << std::endl;
00129 
00130   return 0;  
00131   }
00132 
00133 
00134 ErrorCode write_sealed_file( std::string root_filename, double facet_tol, bool is_acis){
00135 
00136     ErrorCode result;
00137     std::string output_filename;
00138     if(is_acis) {  
00139       std::stringstream facet_tol_ss;
00140       facet_tol_ss << facet_tol; 
00141       output_filename = root_filename + "_" + facet_tol_ss.str() + "_zip.h5m";
00142     } else {
00143       output_filename = root_filename + "_zip.h5m";
00144     }
00145     // PROBLEM: If I write the input meshset the writer returns MB_FAILURE.
00146     // This happens only if I delete vertices when merging.
00147     // result = MBI()->write_mesh( filename_new.c_str(), &input_meshset, 1);
00148     result = MBI()->write_mesh( output_filename.c_str() );
00149     if (MB_SUCCESS != result) std::cout << "result= " << result << std::endl;
00150     assert(MB_SUCCESS == result);
00151 
00152   return result; 
00153 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines