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