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