MeshKit  1.0
example_mbvolop.cpp
Go to the documentation of this file.
00001 
00009 /*
00010  *  test for volume creation operation
00011  *  volumes are created with 2 initial surfaces, top and bottom, one cropping line, and
00012  *  several splitting lines; also, a main direction for all operations, including weaving
00013  *  top and bottom are first cropped, then split several times (in this example, 2 times)
00014  */
00015 #include <iostream>
00016 #include <fstream>
00017 
00018 #include <time.h>
00019 #include <stdlib.h>
00020 #include <cstring>
00021 
00022 #include "meshkit/MKCore.hpp"
00023 #include "meshkit/MeshOp.hpp"
00024 #include "meshkit/ModelEnt.hpp"
00025 #include "meshkit/MBVolOp.hpp"
00026 #include "meshkit/MBSplitOp.hpp"
00027 
00028 
00029 using namespace MeshKit;
00030 
00031 
00032 #include "meshkit/ReadPolyLine.hpp"
00033 
00034 MKCore *mk;
00035 
00036 std::string usage_string =
00037 " <input file bottom> <input file top>    input files.\n"
00038 "< direction > 3 doubles for sweeping direction\n"
00039 " <output file >   output moab database \n";
00040 
00041 std::string filename_top;
00042 std::string filename_bot;
00043 double direction[3]={0., 0., 1.};
00044 std::string output_file_name;
00045 
00046 
00047 int main(int argc, char* argv[])
00048 {
00049   // check command line arg
00050 
00051   filename_bot = (std::string) MESH_DIR + "/BedCropL3.h5m";
00052   filename_top = (std::string) MESH_DIR + "/SurfCropL3.h5m";//"/polyPB.txt";
00053 
00054   output_file_name = "volumesIce.h5m"; // output
00055 
00056   //number_tests_successful = 0;
00057 
00058   if (argc<=1)
00059   {
00060     std::cout<<usage_string;
00061     std::cout << "\n\n";
00062     std::cout<< "default arguments:" << filename_bot << " "<<filename_top << " "
00063         << " "<<direction[0] << " " << direction[1] << " "<< direction[2]<<" " << output_file_name <<"\n";
00064   }
00065   else if (argc==7)
00066   {
00067     filename_bot = argv[1];
00068     filename_top = argv[2];
00069     direction[0] = atof(argv[3]);
00070     direction[1] = atof(argv[4]);
00071     direction[2] = atof(argv[5]);
00072     output_file_name= argv[6];
00073   }
00074   else
00075   {
00076     std::cout << usage_string << " abort.\n";
00077     return 1;
00078   }
00079   // initialize everything
00080 
00081   mk = new MKCore();
00082   mk->load_mesh(filename_bot.c_str());
00083   MEntVector  botFaces;
00084   // we should have 2 faces only, for top and bottom
00085   mk->get_entities_by_dimension(2, botFaces);
00086   // load a second one
00087   mk->load_mesh(filename_top.c_str());
00088   MEntVector  allFaces;
00089   mk->get_entities_by_dimension(2, allFaces);
00090 
00091   MBVolOp *eVolOp = (MBVolOp*) mk->construct_meshop("MBVolOp", allFaces);
00092 
00093   //selection.push_back(*dum.rbegin());// push just the last one retrieved from core
00094   eVolOp->set_direction(direction[0], direction[1], direction[2]);
00095 
00096   std::cout<<"Total number of faces: " << allFaces.size() << "\n";
00097   mk->setup_and_execute();
00098 
00099   if(output_file_name.length()>0)
00100   {
00101     std::cout << "writing output to " << output_file_name << std::endl;
00102     // output only the root set with the volume
00103     //
00104     MEntSelection & mentset = eVolOp->me_selection();
00105     moab::Range rangeResult = (*(mentset.begin()) ).second;
00106     moab::EntityHandle resultSet = rangeResult[0]; // the first set
00107     mk->moab_instance()->write_mesh(output_file_name.c_str(), &resultSet, 1);// write the result set only
00108   }
00109 
00110   return 0;
00111 }
00112 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines