MeshKit
1.0
|
00001 00009 #include <iostream> 00010 00011 #include <time.h> 00012 #include <stdlib.h> 00013 #include <cstring> 00014 00015 #include "meshkit/MKCore.hpp" 00016 #include "meshkit/MeshOp.hpp" 00017 #include "meshkit/ModelEnt.hpp" 00018 #include "meshkit/QslimMesher.hpp" 00019 #include "meshkit/QslimOptions.hpp" 00020 00021 using namespace MeshKit; 00022 00023 00024 00025 MKCore *mk; 00026 00027 std::string usage_string = 00028 "-o <file> Output final model to given file.\n" 00029 "-s <count> Set the target number of faces.\n" 00030 "-i <timings> Intervals for timing reports.\n" 00031 "-e <thresh> Set the maximum error tolerance.\n" 00032 "-t <t> Set pair selection tolerance.\n" 00033 "-Q[pv] Select what constraint quadrics to use [default=p].\n" 00034 "-On Optimal placement policy.\n" 00035 " 0=endpoints, 1=endormid, 2=line, 3=optimal [default]\n" 00036 "-B <weight> Use boundary preservation planes with given weight.\n" 00037 "-b preserve boundary (do not use with -B option) \n" 00038 "-m Preserve mesh quality.\n" 00039 "-a Enable area weighting.\n" 00040 "-p Height fields positivity. Used for height fields, assume \n" 00041 " triangles are originally positively oriented. \n" 00042 "-d do not use delayed deletion \n" 00043 "-c keep costs in a (sparse!!!!) tag \n" 00044 "-r create the range with resulting triangles, and delete the original elements" 00045 "-k keep the topology unchanged, like holes, tunnels." 00046 "\n"; 00047 00048 std::string logging_usage_string = 00049 "-l <file> Log all simplification operations to given file.\n" 00050 "-L[xqcvfdA] Set information to be output.\n" 00051 " x=contractions, q=quadrics, c=cost\n" 00052 " v=vert. notes, f=face notes\n" 00053 " d=model defn, A=All.\n"; 00054 00055 int main(int argc, char* argv[]) 00056 { 00057 // check command line arg 00058 const char *filename = 0; 00059 const char *outfile = 0; 00060 00061 //process options 00062 QslimOptions options; 00063 // process all options, as given with regular qslimmesher 00064 // the last argument must be the input file 00065 // one argument must be -o <the output file>, otherwise it is the standard output 00066 // in the process, a mesh file is read (instanced) and the 00067 // set of triangles is passed 00068 // it could be the root set for the mesh 00069 std::string fstr; 00070 if (argc<=1) 00071 { 00072 std::cout<<usage_string; 00073 std::cout << "\n\n"; 00074 fstr=(std::string) MESH_DIR + "/partBed.smf"; 00075 std::cout<< "default arguments: -s 4500 -B 1000 -p -o out.smf " << fstr <<" \n"; 00076 options.face_target = 4500; 00077 options.will_constrain_boundaries = true; 00078 options.boundary_constraint_weight = 1000; 00079 options.height_fields = 1; 00080 00081 filename = fstr.c_str(); 00082 // ostr = "out.smf"; 00083 // outfile = ostr.c_str(); 00084 } 00085 else 00086 { 00087 // the file should be the last argument; if not, we have a problem, we will not be able to read it 00088 filename = argv[argc-1]; 00089 int i=1;// will loop through arguments, and process them 00090 for (i=1; i<argc-1 ; i++) 00091 { 00092 if (argv[i][0]=='-') 00093 { 00094 switch (argv[i][1]) 00095 { 00096 case 'l': 00097 { 00098 // open a log file 00099 options.logfile = new std::ofstream(argv[i+1]); 00100 if (!options.logfile) 00101 { 00102 // cannot open log file, exit 00103 std::cout << "can't open log file\n"; 00104 return 1; 00105 } 00106 i++; 00107 break; 00108 } 00109 case 'L': 00110 // parse the logging options 00111 { 00112 char *c; 00113 int errflg = 0; 00114 c = argv[i]+2;// skip -L 00115 while( *c ) 00116 { 00117 if( *c=='x' ) 00118 options.selected_output |= OUTPUT_CONTRACTIONS; 00119 else if( *c=='q' ) 00120 options.selected_output |= OUTPUT_QUADRICS; 00121 else if( *c=='c' ) 00122 options.selected_output |= OUTPUT_COST; 00123 else if( *c=='v' ) 00124 options.selected_output |= OUTPUT_VERT_NOTES; 00125 else if( *c=='f' ) 00126 options.selected_output |= OUTPUT_FACE_NOTES; 00127 else if( *c=='d' ) 00128 options.selected_output |= OUTPUT_MODEL_DEFN; 00129 else if( *c=='A' ) 00130 options.selected_output |= OUTPUT_ALL; 00131 else 00132 errflg++; 00133 c++; 00134 } 00135 if (errflg>0) 00136 { 00137 std::cout<<logging_usage_string; 00138 std::cout<< "!! Ignore the error it\n"; 00139 00140 } 00141 break; 00142 } 00143 case 'a': 00144 { 00145 options.will_weight_by_area = 1; 00146 break; 00147 } 00148 case 'B': 00149 { 00150 options.boundary_constraint_weight = atof(argv[i+1]); 00151 options.will_constrain_boundaries = 1; 00152 i++; 00153 break; 00154 } 00155 case 's': 00156 { 00157 options.face_target = atoi(argv[i+1]); 00158 i++; 00159 break; 00160 } 00161 case 't': 00162 { 00163 options.pair_selection_tolerance = atof(argv[i+1]); 00164 i++; 00165 break; 00166 } 00167 case 'o': 00168 { 00169 outfile = argv[i+1]; 00170 i++; 00171 break; 00172 } 00173 00174 case 'O': 00175 { 00176 char * c ; 00177 c = argv[i]+2; 00178 int ival = atoi(c); 00179 if( ival < 0 || ival > PLACE_OPTIMAL ) 00180 ival=PLACE_OPTIMAL; 00181 options.placement_policy = ival; 00182 break; 00183 } 00184 00185 case 'Q': 00186 { 00187 options.will_use_plane_constraint = false; 00188 options.will_use_vertex_constraint = false; 00189 options.will_use_plane_constraint = false; 00190 00191 char * c ; 00192 c = argv[i]+2; 00193 while( *c ) 00194 { 00195 if( *c=='p' ) 00196 options.will_use_plane_constraint = true; 00197 else if( *c=='v' ) 00198 options.will_use_vertex_constraint = true; 00199 else 00200 { 00201 std::cout<< "wrong input " << argv[i] << std::endl; 00202 } 00203 c++; 00204 } 00205 break; 00206 } 00207 00208 case 'e': 00209 { 00210 options.error_tolerance = atof(argv[i+1]); 00211 i++; 00212 break; 00213 } 00214 00215 case 'b': 00216 { 00217 options.will_preserve_boundaries = true; 00218 break; 00219 } 00220 00221 case 'm': 00222 { 00223 options.will_preserve_mesh_quality = true; 00224 break; 00225 } 00226 00227 case 'p': 00228 { 00229 options.height_fields = true; 00230 break; 00231 } 00232 case 'i': 00233 { 00234 options.timingIntervals=atof(argv[i+1]); 00235 i++; 00236 break; 00237 } 00238 case 'd': 00239 { 00240 options.useDelayedDeletion = false; 00241 break; 00242 } 00243 case 'c': 00244 { 00245 options.plotCost = 1; 00246 break; 00247 } 00248 case 'r': 00249 { 00250 options.create_range = true; 00251 break; 00252 } 00253 case 'k': 00254 { 00255 options.topology = 1; 00256 break; 00257 } 00258 default : 00259 { 00260 std::cout << "unsupported wrong input argument " << argv[i] <<std::endl; 00261 return 0; 00262 } 00263 } 00264 } 00265 } 00266 } 00267 // initialize everything 00268 00269 mk = new MKCore(); 00270 mk->load_mesh(filename); 00271 MEntVector selection, dum; 00272 mk->get_entities_by_dimension(2, dum); 00273 selection.push_back(*dum.rbegin());// push just the last one retrieved from core 00274 00275 QslimMesher *qm = (QslimMesher*) mk->construct_meshop("QslimMesher", selection); 00276 00277 qm->set_options(options); 00278 00279 mk->setup_and_execute(); 00280 00281 if(outfile) 00282 { 00283 std::cout << "writing output to " << outfile << std::endl; 00284 mk->moab_instance()->write_mesh(outfile);// write everything left 00285 } 00286 00287 return 0; 00288 }