MeshKit
1.0
|
00001 #include "meshkit/Mesh.hpp" 00002 #include "meshkit/MeshRefine2D.hpp" 00003 #include "meshkit/QuadCleanUp.hpp" 00004 00005 #include "meshkit/DijkstraShortestPath.hpp" 00006 #include "meshkit/ObjectPool.hpp" 00007 00008 extern int QuadPatches(Jaal::Mesh *mesh); 00009 00010 using namespace Jaal; 00011 00012 void usage() 00013 { 00014 cout << "Usage: Executable -i in_meshfile -o out_meshfile -c cleanOp " << endl; 00015 00016 cout << " *****************************************************************" << endl; 00017 cout << " Option : Mesh Cleanup Operation " << endl; 00018 cout << " *****************************************************************" << endl; 00019 cout << " 0 : Report Mesh Quality " << endl; 00020 cout << " 1 : Remove interior doublets " << endl; 00021 cout << " 2 : Remove boundary singlets " << endl; 00022 cout << " 3 : Remove diamonds " << endl; 00023 cout << " 4 : Vertex Degree Reduction " << endl; 00024 cout << " 5 : Laplace Smoothing (No Weight) " << endl; 00025 cout << " 6 : Laplace Smoothing (Area Weight) " << endl; 00026 cout << " 7 : Laplace Smoothing (Edge Length Weight) " << endl; 00027 cout << " 8 : Advancing front Edge Swapping " << endl; 00028 cout << " 9 : Shape Optimization " << endl; 00029 cout << " 10 : Reverse Elements Connectivity " << endl; 00030 cout << " 11 : Refine QuadMesh ( Scheme 14 ) " << endl; 00031 cout << " 12 : Refine QuadMesh ( Scheme 15 ) " << endl; 00032 cout << " 13 : Swap Concave Faces " << endl; 00033 cout << " 14 : Refine Degree 3 Faces " << endl; 00034 cout << " 15 : Search Structured Submesh " << endl; 00035 cout << " 16 : Regularization with remeshing " << endl; 00036 cout << " 17 : Generate Quad-Irregular(Motorcycle) Graph " << endl; 00037 cout << " 18 : Generate Quad-to-Tri4 " << endl; 00038 cout << " 19 : Generate Quad-to-Tri2 " << endl; 00039 cout << " 20 : Shift irregular nodes inside domain " << endl; 00040 cout << " 21 : Everything automatic " << endl; 00041 } 00042 00044 00045 int main(int argc, char **argv) 00046 { 00047 Jaal::Mesh *mesh = new Jaal::Mesh; 00048 Jaal::MeshOptimization mopt; 00049 00050 /* 00051 double origin[] = { 0.0, 0.0, 0.0}; 00052 double length[] = { 1.0, 1.0, 1.0}; 00053 int gridim[] = { 6, 7, 2}; 00054 mesh = Jaal::create_structured_mesh(origin, length, gridim, 2 ); 00055 cout << mesh->getSize(1) << endl; 00056 Face *f = mesh->getFaceAt(0); 00057 mesh->remove(f); 00058 00059 f = mesh->getFaceAt(1); 00060 mesh->remove(f); 00061 00062 cout << mesh->getSize(1) << endl; 00063 mesh->saveAs( "tmp.off"); 00064 exit(0); 00065 */ 00066 00067 string infilename, outfilename; 00068 00069 int iopt, numiters = 100, topo_improve = 1; 00070 int cleanup_op = 0; 00071 00072 while( (iopt = getopt( argc, argv, "hgtc:i:o:") ) != -1) { 00073 switch(iopt) { 00074 case 'c': 00075 cleanup_op = atoi( optarg ); 00076 break; 00077 case 'h': 00078 usage(); 00079 break; 00080 case 'i': 00081 infilename = optarg; // Input QuadMesh File 00082 break; 00083 case 'o': 00084 outfilename = optarg; // Output QuadMesh File 00085 break; 00086 case 'l': 00087 numiters = atoi( optarg ); // Number of iterations for Laplacian Smoothing. 00088 break; 00089 case 't': 00090 topo_improve = atoi( optarg ); // Should we do topological Improvement: Default( Yes ); 00091 break; 00092 default: 00093 cout << "Usage: Executable t [0 1] -l #num -i in_meshfile -o out_meshfile -c cleanOp " << endl; 00094 break; 00095 } 00096 } 00097 00098 if( infilename.empty() ) { 00099 cout <<"Warning: No input file specified " << endl; 00100 usage(); 00101 return 1 ; 00102 } 00103 00104 if( outfilename.empty() ) { 00105 cout <<"Warning: No output file specified " << endl; 00106 usage(); 00107 return 2; 00108 } 00109 00110 mesh->readFromFile( infilename ); 00111 00112 size_t ninvert = mesh->count_inverted_faces(); 00113 size_t numfaces = mesh->getSize(2); 00114 size_t numBound = mesh->getBoundarySize(0); 00115 size_t nireg0 = mesh->count_irregular_nodes(4); 00116 00117 cout << "# of irregular nodes before cleanup : " << nireg0 << endl; 00118 00119 if( ninvert > 0.5*numfaces ) 00120 mesh->reverse(); 00121 00122 LaplaceSmoothing lapsmooth(mesh); 00123 LaplaceWeight *lapweight = NULL; 00124 00125 QuadCleanUp qClean(mesh); 00126 00127 vector<QTrack> qpath; 00128 vector<Vertex*> steiner; 00129 Mesh *q2t; 00130 int algo, numiter; 00131 00132 StopWatch swatch; 00133 swatch.start(); 00134 00135 switch( cleanup_op) { 00136 case 0: 00137 qClean.report(); 00138 exit(0); 00139 break; 00140 case 1: 00141 qClean.remove_interior_doublets(); 00142 break; 00143 case 2: 00144 qClean.remove_boundary_singlets(); 00145 break; 00146 case 3: 00147 qClean.remove_diamonds(); 00148 break; 00149 case 4: 00150 qClean.vertex_degree_reduction(); 00151 break; 00152 case 5: 00153 lapsmooth.setMethod(0); 00154 lapweight = new LaplaceNoWeight(); 00155 lapsmooth.setWeight(lapweight); 00156 lapsmooth.setNumIterations(100); 00157 lapsmooth.execute(); 00158 break; 00159 case 6: 00160 lapsmooth.setMethod(0); 00161 lapweight = new LaplaceAreaWeight(); 00162 lapsmooth.setWeight(lapweight); 00163 lapsmooth.setNumIterations(100); 00164 lapsmooth.execute(); 00165 break; 00166 case 7: 00167 lapsmooth.setMethod(0); 00168 lapweight = new LaplaceLengthWeight(); 00169 lapsmooth.setWeight(lapweight); 00170 lapsmooth.setNumIterations(100); 00171 lapsmooth.execute(); 00172 break; 00173 case 8: 00174 // qClean.advancing_front_edges_swap(); 00175 break; 00176 case 9: 00177 /* 00178 cout << "Choose algorithm : " << endl; 00179 cout << " Steepest Descent : 0 " << endl; 00180 cout << " Quasi Newton(default) : 1 " << endl; 00181 cout << " Trust Region : 2 " << endl; 00182 cout << " Feasible Newton : 3 " << endl; 00183 cout << " Laplacian : 4 " << endl; 00184 cin >> algo; 00185 cout << "Give number of iterations " << endl; 00186 cin >> numiter; 00187 mopt.shape_optimize( mesh, algo, numiter ); 00188 */ 00189 mopt.shape_optimize( mesh ); 00190 break; 00191 case 10: 00192 mesh->reverse(); 00193 break; 00194 case 11: 00195 mesh->refine_quads14(); 00196 break; 00197 case 12: 00198 mesh->refine_quads15(); 00199 break; 00200 case 13: 00201 qClean.swap_concave_faces(); 00202 break; 00203 case 14: 00204 qClean.refine_degree3_faces(); 00205 break; 00206 case 15: 00207 mesh->search_quad_patches(); 00208 break; 00209 case 16: 00210 qClean.remesh_defective_patches(); 00211 break; 00212 case 17: 00213 qpath = Jaal::generate_quad_partitioning(mesh); 00214 // Jaal::set_irregular_path_tag(mesh, qpath); 00215 break; 00216 case 18: 00217 q2t = Jaal::quad_to_tri4( mesh, steiner); 00218 q2t->saveAs("tmesh.off"); 00219 break; 00220 case 19: 00221 q2t = Jaal::quad_to_tri2( mesh ); 00222 mopt.shape_optimize( q2t ); 00223 q2t->saveAs("tmesh.off"); 00224 break; 00225 case 20: 00226 qClean.shift_irregular_nodes(); 00227 break; 00228 case 21: 00229 qClean.automatic(); 00230 break; 00231 } 00232 swatch.stop(); 00233 cout << "CleanUp time : " << swatch.getSeconds() << endl; 00234 00235 if( cleanup_op ) { 00236 00237 cout << "# Nodes : " << mesh->getSize(0) << endl; 00238 cout << "# Faces : " << mesh->getSize(2) << endl; 00239 cout << "# Inverted Faces : " << mesh->count_inverted_faces() << endl; 00240 cout << "# Concave Faces : " << mesh->count_concave_faces() << endl; 00241 cout << "# Irregular nodes : " << mesh->count_irregular_nodes(4) << endl; 00242 // cout << "Mesh Consistency : " << mesh->is_consistently_oriented() << endl; 00243 00244 // Jaal::set_large_area_tag(mesh); 00245 // Jaal::set_boundary_tag(mesh); 00246 // Jaal::set_tiny_area_tag(mesh); 00247 00248 // Jaal::set_layer_tag(mesh); 00249 // Jaal::set_constrained_tag(mesh); 00250 // Jaal::set_doublet_tag(mesh); 00251 // Jaal::set_bridge_tag(mesh); 00252 // Jaal::set_singlet_tag(mesh); 00253 // Jaal::set_regular_node_tag(mesh); 00254 } 00255 00256 mesh->collect_garbage(); 00257 // Jaal::set_diamond_tag(mesh); 00258 00259 cout << " Saving Mesh " << outfilename << endl; 00260 mesh->saveAs( outfilename); 00261 00262 mesh->get_topological_statistics(); 00263 plot_all_quad_quality_measures( mesh ); 00264 00265 assert( numBound == mesh->getBoundarySize(0) ); 00266 00267 if( lapweight ) delete lapweight; 00268 00269 if( mesh ) mesh->deleteAll(); 00270 00271 delete mesh; 00272 00273 return 0; 00274 } 00275