MeshKit  1.0
example_mbsplitop.cpp
Go to the documentation of this file.
00001 
00012 #include <iostream>
00013 #include <fstream>
00014 
00015 #include <time.h>
00016 #include <stdlib.h>
00017 #include <cstring>
00018 
00019 #include "meshkit/MKCore.hpp"
00020 #include "meshkit/MeshOp.hpp"
00021 #include "meshkit/ModelEnt.hpp"
00022 #include "meshkit/MBSplitOp.hpp"
00023 
00024 #include "meshkit/ReadPolyLine.hpp"
00025 
00026 using namespace MeshKit;
00027 
00028 
00029 
00030 MKCore *mk;
00031 
00032 std::string usage_string =
00033 " <input file>      input file.\n"
00034 " <polyline file> file with the direction and polyline for cropping\n"
00035 " <closed loop>   1 or 0 for closed or not \n"
00036 " <surface_id>    global id of the surface to split \n"
00037 " <min_dot>       min dot for max angle allowed betwen consecutive edges"
00038 " <output file >   output moab database \n";
00039 
00040 std::string filenameS;
00041 std::string filename_out;
00042 std::string polygon_file_name;
00043 int closed = 0;
00044 int surfId = 1;// surface id to split
00045 double min_dot = 0.8;
00046 
00047 int main(int argc, char* argv[])
00048 {
00049   // check command line arg
00050   const char *filename = 0;
00051   const char *file_poly = 0;
00052   const char *outfile = 0;
00053   closed = 1;// to split or not
00054   surfId = 1;
00055   min_dot = 0;
00056 
00057 
00058   filenameS = (std::string) MESH_DIR +  "/PB.h5m";
00059   polygon_file_name = (std::string) MESH_DIR +  "/polyPB.txt";
00060   filename_out = "PB_new.h5m";
00061 
00062   if (argc<=1)
00063   {
00064     std::cout<<usage_string;
00065     std::cout << "\n\n";
00066     std::cout<< "default arguments: ../../data/PB.h5m ../../data/polyPB.txt 1 1 0.8 PB_new.h5m \n";
00067     filename = filenameS.c_str();
00068     file_poly = polygon_file_name.c_str();
00069     outfile = 0; // do not output if default, do not save the db
00070   }
00071   else if (argc==7)
00072   {
00073     filename = argv[1];
00074     file_poly = argv[2];
00075     closed = atoi(argv[3]);
00076     surfId = atoi(argv[4]);
00077     min_dot = atof(argv[5]);
00078     outfile = argv[6];
00079   }
00080   else
00081   {
00082     std::cout << usage_string << " abort.\n";
00083     return 1;
00084   }
00085   // initialize everything
00086 
00087   mk = new MKCore();
00088   mk->load_mesh(filename);
00089 
00090   MEntVector  selection;
00091   mk->get_entities_by_dimension(2, selection);
00092   //selection.push_back(*dum.rbegin());// push just the last one retrieved from core
00093 
00094   MBSplitOp *splitOp = (MBSplitOp*) mk->construct_meshop("MBSplitOp", selection);
00095 
00096   std::vector<double> xyz;
00097   double direction[3];
00098 
00099   int rc = ReadPolyLineFromFile(file_poly, direction, xyz);
00100   if (rc !=0)
00101   {
00102     std::cout<<" can't read from polyline file\n";
00103     return rc;
00104 
00105   }
00106   int sizePolygon = (int)xyz.size()/3;
00107   if ((closed && sizePolygon < 3 ) || (!closed&& sizePolygon<2)) {
00108     std::cerr << " Not enough points in the polygon" << std::endl;
00109     return 1;
00110   }
00111 
00112   splitOp->set_options( /* int globalId*/ surfId, direction[0], direction[1],
00113       direction[2], /* int closed*/ closed, /*min_dot*/ min_dot);
00114 
00115   for (int k=0 ; k<sizePolygon; k++)
00116     splitOp->add_points(xyz[3*k], xyz[3*k+1], xyz[3*k+2]);
00117 
00118   mk->setup_and_execute();
00119 
00120   if(outfile)
00121   {
00122     std::cout << "writing output to " << outfile << std::endl;
00123     mk->moab_instance()->write_mesh(outfile);// write everything left
00124   }
00125 
00126   return 0;
00127 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines