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