1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include "meshkit/Mesh.hpp"
#include "meshkit/MeshRefine2D.hpp"
#include "meshkit/QuadCleanUp.hpp"

#include "meshkit/DijkstraShortestPath.hpp"
#include "meshkit/ObjectPool.hpp"

extern int QuadPatches(Jaal::Mesh *mesh);

using namespace Jaal;

void usage()
{
     cout << "Usage: Executable -i in_meshfile -o out_meshfile -c cleanOp " << endl;

     cout << " *****************************************************************" << endl;
     cout << " Option :   Mesh Cleanup Operation " << endl;
     cout << " *****************************************************************" << endl;
     cout << " 0      :   Report Mesh Quality " << endl;
     cout << " 1      :   Remove interior doublets  " << endl;
     cout << " 2      :   Remove boundary singlets  " << endl;
     cout << " 3      :   Remove diamonds " << endl;
     cout << " 4      :   Vertex Degree Reduction " << endl;
     cout << " 5      :   Laplace Smoothing (No Weight)    " << endl;
     cout << " 6      :   Laplace Smoothing (Area Weight)  " << endl;
     cout << " 7      :   Laplace Smoothing (Edge Length Weight)  " << endl;
     cout << " 8      :   Advancing front Edge Swapping " << endl;
     cout << " 9      :   Shape Optimization  " << endl;
     cout << " 10     :   Reverse Elements Connectivity  " << endl;
     cout << " 11     :   Refine QuadMesh ( Scheme 14 )  " << endl;
     cout << " 12     :   Refine QuadMesh ( Scheme 15 )  " << endl;
     cout << " 13     :   Swap Concave Faces  " << endl;
     cout << " 14     :   Refine Degree 3 Faces  " << endl;
     cout << " 15     :   Search Structured Submesh " << endl;
     cout << " 16     :   Regularization with remeshing " << endl;
     cout << " 17     :   Generate Quad-Irregular(Motorcycle) Graph " << endl;
     cout << " 18     :   Generate Quad-to-Tri4 " << endl;
     cout << " 19     :   Generate Quad-to-Tri2 " << endl;
     cout << " 20     :   Shift irregular nodes inside domain " << endl;
     cout << " 21     :   Everything automatic " << endl;
}

////////////////////////////////////////////////////////////////////////////////

int main(int argc, char **argv)
{
     Jaal::Mesh *mesh = new Jaal::Mesh;
     Jaal::MeshOptimization mopt;

     /*
          double origin[]   = { 0.0, 0.0, 0.0};
          double length[]   = { 1.0, 1.0, 1.0};
          int    gridim[]   = { 6, 7, 2};
          mesh = Jaal::create_structured_mesh(origin, length, gridim, 2 );
          cout << mesh->getSize(1) << endl;
          Face *f = mesh->getFaceAt(0);
          mesh->remove(f);

          f = mesh->getFaceAt(1);
          mesh->remove(f);

          cout << mesh->getSize(1) << endl;
          mesh->saveAs( "tmp.off");
          exit(0);
     */

     string infilename, outfilename;

     int iopt, numiters = 100, topo_improve = 1;<--- The scope of the variable 'numiters' can be reduced.<--- The scope of the variable 'topo_improve' can be reduced.
     int cleanup_op = 0;

     while( (iopt = getopt( argc, argv, "hgtc:i:o:") ) != -1) {
          switch(iopt) {
          case 'c':
               cleanup_op = atoi( optarg );
               break;
          case 'h':
               usage();
               break;
          case 'i':
               infilename = optarg;   // Input QuadMesh File
               break;
          case 'o':
               outfilename = optarg; // Output QuadMesh File
               break;
          case 'l':
               numiters  = atoi( optarg ); // Number of iterations for Laplacian Smoothing.<--- Variable 'numiters' is assigned a value that is never used.
               break;
          case 't':
               topo_improve  = atoi( optarg ); // Should we do topological Improvement: Default( Yes );<--- Variable 'topo_improve' is assigned a value that is never used.
               break;
          default:
               cout << "Usage: Executable t [0 1]  -l #num  -i in_meshfile -o out_meshfile -c cleanOp " << endl;
               break;
          }
     }

     if( infilename.empty() ) {
          cout <<"Warning: No input file specified " << endl;
          usage();
          return 1 ;
     }

     if( outfilename.empty() ) {
          cout <<"Warning: No output file specified " << endl;
          usage();
          return 2;
     }

     mesh->readFromFile( infilename );

     size_t ninvert  =  mesh->count_inverted_faces();
     size_t numfaces =  mesh->getSize(2);
     size_t numBound =  mesh->getBoundarySize(0);
     size_t nireg0   =  mesh->count_irregular_nodes(4);

     cout << "# of irregular nodes before cleanup : " << nireg0 << endl;

     if( ninvert > 0.5*numfaces )
          mesh->reverse();

     LaplaceSmoothing lapsmooth(mesh);
     LaplaceWeight *lapweight = NULL;

     QuadCleanUp qClean(mesh);

     vector<QTrack>  qpath;
     vector<Vertex*> steiner;
     Mesh *q2t;
     int  algo, numiter;<--- Unused variable: algo<--- Unused variable: numiter

     StopWatch swatch;
     swatch.start();

     switch( cleanup_op) {
     case 0:
          qClean.report();
          exit(0);
          break;
     case 1:
          qClean.remove_interior_doublets();
          break;
     case 2:
          qClean.remove_boundary_singlets();
          break;
     case 3:
          qClean.remove_diamonds();
          break;
     case 4:
          qClean.vertex_degree_reduction();
          break;
     case 5:
          lapsmooth.setMethod(0);
          lapweight = new LaplaceNoWeight();
          lapsmooth.setWeight(lapweight);
          lapsmooth.setNumIterations(100);
          lapsmooth.execute();
          break;
     case 6:
          lapsmooth.setMethod(0);
          lapweight = new LaplaceAreaWeight();
          lapsmooth.setWeight(lapweight);
          lapsmooth.setNumIterations(100);
          lapsmooth.execute();
          break;
     case 7:
          lapsmooth.setMethod(0);
          lapweight = new LaplaceLengthWeight();
          lapsmooth.setWeight(lapweight);
          lapsmooth.setNumIterations(100);
          lapsmooth.execute();
          break;
     case 8:
//         qClean.advancing_front_edges_swap();
          break;
     case 9:
          /*
                    cout << "Choose algorithm : " << endl;
                    cout << "    Steepest Descent       : 0 " << endl;
                    cout << "    Quasi Newton(default)  : 1  " << endl;
                    cout << "    Trust Region           : 2 " << endl;
                    cout << "    Feasible Newton        : 3 " << endl;
                    cout << "    Laplacian              : 4 " << endl;
                    cin  >> algo;
                    cout << "Give number of iterations " << endl;
                    cin  >> numiter;
                    mopt.shape_optimize( mesh, algo, numiter );
          */
          mopt.shape_optimize( mesh );
          break;
     case 10:
          mesh->reverse();
          break;
     case 11:
          mesh->refine_quads14();
          break;
     case 12:
          mesh->refine_quads15();
          break;
     case 13:
          qClean.swap_concave_faces();
          break;
     case 14:
          qClean.refine_degree3_faces();
          break;
     case 15:
          mesh->search_quad_patches();
          break;
     case 16:
          qClean.remesh_defective_patches();
          break;
     case 17:
          qpath = Jaal::generate_quad_partitioning(mesh);<--- Variable 'qpath' is assigned a value that is never used.
//      Jaal::set_irregular_path_tag(mesh, qpath);
          break;
     case 18:
          q2t = Jaal::quad_to_tri4( mesh, steiner);
          q2t->saveAs("tmesh.off");
          break;
     case 19:
          q2t = Jaal::quad_to_tri2( mesh );
          mopt.shape_optimize( q2t );
          q2t->saveAs("tmesh.off");
          break;
     case 20:
          qClean.shift_irregular_nodes();
          break;
     case 21:
          qClean.automatic();
          break;
     }
     swatch.stop();
     cout << "CleanUp time : " << swatch.getSeconds() << endl;

     if( cleanup_op ) {

          cout << "# Nodes           : " << mesh->getSize(0) << endl;
          cout << "# Faces           : " << mesh->getSize(2) << endl;
          cout << "# Inverted Faces  : " << mesh->count_inverted_faces() << endl;
          cout << "# Concave Faces   : " << mesh->count_concave_faces() << endl;
          cout << "# Irregular nodes : " << mesh->count_irregular_nodes(4) << endl;
//        cout << "Mesh Consistency  : " << mesh->is_consistently_oriented() << endl;

          // Jaal::set_large_area_tag(mesh);
          // Jaal::set_boundary_tag(mesh);
          // Jaal::set_tiny_area_tag(mesh);

          // Jaal::set_layer_tag(mesh);
          // Jaal::set_constrained_tag(mesh);
          // Jaal::set_doublet_tag(mesh);
          // Jaal::set_bridge_tag(mesh);
          // Jaal::set_singlet_tag(mesh);
          // Jaal::set_regular_node_tag(mesh);
     }

     mesh->collect_garbage();
//   Jaal::set_diamond_tag(mesh);

     cout << " Saving Mesh " << outfilename << endl;
     mesh->saveAs( outfilename);

     mesh->get_topological_statistics();
     plot_all_quad_quality_measures( mesh );

     assert( numBound == mesh->getBoundarySize(0) );<--- Assert statement calls a function which may have desired side effects: 'getBoundarySize'.

     if( lapweight ) delete lapweight;

     if( mesh ) mesh->deleteAll();

     delete mesh;

     return 0;
}