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