MeshKit  1.0
test_setpnt2quad.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 #include <cstring>
00014 
00015 #include "meshkit/MKCore.hpp"
00016 #include "meshkit/MeshOp.hpp"
00017 #include "meshkit/ModelEnt.hpp"
00018 #include "meshkit/TriangleMesher.hpp"
00019 
00020 #include "meshkit/QslimMesher.hpp"
00021 #include "meshkit/QslimOptions.hpp"
00022 
00023 #include "meshkit/MBGeomOp.hpp"
00024 #include "meshkit/MBSplitOp.hpp"
00025 
00026 #include "meshkit/CAMALPaver.hpp"
00027 #include "meshkit/SizingFunction.hpp"
00028 
00029 
00030 using namespace MeshKit;
00031 
00032 #include "TestUtil.hpp"
00033 #include "meshkit/ReadPolyLine.hpp"
00034 
00035 MKCore *mk;
00036 
00037 
00038 int main(int argc, char* argv[])
00039 {
00040   // check command line arg
00041   const char *filename = 0;
00042   //const char *outfile = 0;
00043 
00044   std::string fstr=TestDir+"/pts.h5m";
00045   filename = fstr.c_str();
00046   std::string polyFile = TestDir +"/polyPB.txt";
00047   const char * file_poly = polyFile.c_str();
00048 
00049   char * opts  = (char *)("pc");
00050   int direction = 3; // default
00051   double fretting = 1.e+38;// huge, do not eliminate anything in general
00052 
00053   mk = new MKCore();
00054   mk->load_mesh(filename);
00055   MEntVector selection, dum;
00056   mk->get_entities_by_dimension(2, dum);
00057   selection.push_back(*dum.rbegin());// push just the last one retrieved from core
00058 
00059   TriangleMesher *tm = (TriangleMesher*) mk->construct_meshop("TriangleMesher", selection);
00060 
00061   tm->set_options(opts, direction, fretting);
00062 
00063   // done with triangulation, now qslim it:
00064   QslimOptions options;
00065   options.face_target = 4500;
00066   options.will_constrain_boundaries = true;
00067   options.boundary_constraint_weight = 100;
00068   options.height_fields = 1;
00069   options.create_range = 1;
00070 
00071   // use the same model ents as from triangle
00072   QslimMesher *qm = (QslimMesher*) mk->construct_meshop("QslimMesher", selection);
00073 
00074   qm->set_options(options);
00075 
00076   // mk.add_arc(tm, qm )
00077   //mk->get_graph().addArc(tm->get_node(), qm->get_node());
00078   // insert_node(GraphNode *inserted, GraphNode *before, GraphNode *after= NULL);
00079   mk->insert_node( qm, mk->leaf_node(), tm);
00080 
00081   // selection.clear();
00082   MBGeomOp * geo = (MBGeomOp *) mk->construct_meshop("MBGeomOp", selection);
00083 
00084   // maybe we should look at the moab set from the previous node in the
00085   // graph, to decide what set to geometrize
00086   // mk->get_graph().addArc(qm->get_node(), geo->get_node());
00087   // insert_node(GraphNode *inserted, GraphNode *before, GraphNode *after= NULL);
00088   mk->insert_node(geo, mk->leaf_node(), qm);
00089 
00090   // now add a split operation
00091   // we should add it to the graph
00092   MEntVector noEntsYet;
00093   MBSplitOp * splitOp = (MBSplitOp*) mk->construct_meshop("MBSplitOp", noEntsYet);
00094 
00095   // make sure that we split the face we want...
00096   //mk->get_graph().addArc(geo->get_node(), splitOp->get_node());
00097   //insert_node(GraphNode *inserted, GraphNode *before, GraphNode *after= NULL);
00098   mk->insert_node(splitOp, mk->leaf_node(), geo);
00099   // how???
00100 
00101   std::vector<double> xyz;
00102   double dirSplit[3];
00103 
00104   int rc = ReadPolyLineFromFile(file_poly, dirSplit, xyz);
00105   if (rc !=0)
00106   {
00107     std::cout<<" can't read from polyline file\n";
00108     return rc;
00109   }
00110   int sizePolygon = (int)xyz.size()/3;
00111   if (sizePolygon < 3) {
00112     std::cerr << " Not enough points in the polygon" << std::endl;
00113     return 1;
00114   }
00115 
00116   // we know we will split a face with id 1; there should be only one so far
00117   //  !!!
00118   splitOp->set_options( /* int globalId*/ 1, dirSplit[0], dirSplit[1],
00119       dirSplit[2], /* int closed*/ 1, /*min_dot*/ 0.8);
00120 
00121   for (int k=0 ; k<sizePolygon; k++)
00122       splitOp->add_points(xyz[3*k], xyz[3*k+1], xyz[3*k+2]);
00123 
00124   // add an operation for CAMAL Paver mesher...
00125   MEntVector surfs;// empty so far
00126   CAMALPaver * camalPaver = (CAMALPaver*) mk->construct_meshop("CAMALPaver", surfs);
00127   // this will make sure that camal will be executed after split
00128   // if the model ents sel is empty, trigger a special case...
00129   // size the mesh
00130   double mesh_size = 50;
00131   /*SizingFunction *sf =*/ new SizingFunction(mk, -1, mesh_size);
00132   // convention: will add the latest SizingFunction available to the model ents
00133   // before the "setup" in execute
00134   /*{
00135     for (unsigned int i = 0; i < surfs.size(); i++)
00136       surfs[i]->sizing_function_index(sf->core_index());
00137   }*/
00138 
00139   //mk->get_graph().addArc(splitOp->get_node(), camalPaver->get_node());
00140   // insert_node(GraphNode *inserted, GraphNode *before, GraphNode *after= NULL);
00141   mk->insert_node(camalPaver, mk->leaf_node(), splitOp);
00142 
00143   mk->setup_and_execute();
00144 
00145   MEntSelection & mentSel = camalPaver->me_selection();
00146   MEntVector ments;
00147   for (MEntSelection::iterator sit = mentSel.begin(); sit != mentSel.end(); sit++) {
00148         // make a me, for convenience
00149       ModelEnt *me = (*sit).first;
00150       ments.push_back(me);
00151   }
00152 
00153   mk->save_mesh_from_model_ents("test.h5m", ments);
00154 
00155   return 0;
00156 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines