cleaner.C

Go to the documentation of this file.
00001 
00007 #ifdef HAVE_CONFIG_H
00008 #include <tumble-conf.h>
00009 #endif /* HAVE_CONFIG_H */
00010 
00011 #include "cleaner.h"
00012 #include "timehelp.h"
00013 #include "simulation.h"
00014 
00015 using namespace std;
00016 
00017 Cleaner::Cleaner(BezierMesh *_bezier_mesh, BoundaryMesh *_bdry_mesh, char *filename)
00018 {
00019     bezier_mesh = _bezier_mesh;
00020     bdry_mesh   = _bdry_mesh;
00021 
00022     /* Initialize statistics */
00023     gettimeofday(&start_time,NULL);
00024     num_flips = 0;
00025     num_smoothed = 0;
00026     num_refines_size = 0;
00027     num_refines_angle = 0;
00028     num_coarsens = 0;
00029     num_refines_boundaries = 0;
00030 
00031     read_cfg_file(filename);
00032 }
00033 
00034 Cleaner::Cleaner(BezierMesh *_bezier_mesh, BoundaryMesh *_bdry_mesh,
00035                  double _jacobian_bound, double _lipschitz_const,
00036                  double _nn_const, double _dp_epsilon,
00037                  double _kr_frac, double _size_const)
00038 {
00039     bezier_mesh = _bezier_mesh;
00040     bdry_mesh   = _bdry_mesh;
00041     config_filename=NULL;
00042 
00043     /* Initialize statistics */
00044     gettimeofday(&start_time,NULL);
00045     num_flips = 0;
00046     num_smoothed = 0;
00047     num_refines_size = 0;
00048     num_refines_angle = 0;
00049     num_coarsens = 0;
00050     num_refines_boundaries = 0;
00051 
00052     jacobian_bound = _jacobian_bound;
00053     lipschitz_const = _lipschitz_const;
00054     nearest_neighbor_const = _nn_const;
00055     dp_epsilon = _dp_epsilon;
00056     keep_radius_frac = _kr_frac;
00057     size_const = _size_const;
00058 }
00059 
00060 
00061 void Cleaner::read_cfg_file(char *filename){
00062     config_filename=filename;
00063     FILE* f = fopen( filename, "r" );
00064     float temp=0.0;
00065 
00066     if( !f ) FATAL_ERROR("Cleaner::read_cfg_file --- could not read cfg file "
00067             << filename);
00068 
00069     fscanf(f, "jacobian_bound = %f\n", &temp );
00070     jacobian_bound = temp;
00071 
00072     fscanf(f, "lipschitz_const = %f\n", &temp);
00073     lipschitz_const = temp;
00074 
00075     fscanf(f, "nearest_neighbor_const = %f\n", &temp);
00076     nearest_neighbor_const = temp;
00077 
00078     fscanf(f, "dp_epsilon = %f\n", &temp);
00079     dp_epsilon = temp;
00080 
00081     fscanf(f, "keep_radius_frac = %f\n", &temp);
00082     keep_radius_frac=temp;
00083 
00084     fscanf(f, "size_const = %f\n", &temp);
00085     size_const = temp;
00086 
00087     fclose(f);
00088 }
00089 
00090 
00091 void Cleaner::clean(){
00092     /* flip all edges to be delaunay */
00093     num_flips = bezier_mesh->make_delaunay();
00094 
00095     /* Coarsen mesh using sizing constant */
00096     num_coarsens = bezier_mesh->coarsen_const_size(size_const, lipschitz_const, nearest_neighbor_const, dp_epsilon);
00097 
00098     /* Refine mesh, by splitig bdry edges that are encroaced,
00099      * and killing skinny and poor sized triangles
00100      */
00101     num_refines_boundaries = bezier_mesh->protect_boundarys();
00102     num_refines_size = bezier_mesh->remove_large_triangles(size_const);
00103     num_refines_angle = bezier_mesh->remove_small_angles();
00104 
00105     /* Smooth all edges in mesh (take 2 passes)*/
00106     num_smoothed = bezier_mesh->smooth_mesh(jacobian_bound, 3);
00107 
00108 #ifdef DEBUG
00109     print_summary();
00110 #endif
00111 }
00112 
00113 void Cleaner::print_summary(){
00114     if(config_filename) cout<<"Cleaning finished: Configfile: \""<<config_filename<<"\" ";
00115     cout<<"Elapsed Time: "<<elapsed_time_ms(start_time)<<"ms   Mesh size: "<<bezier_mesh->num_faces<<endl
00116         <<"EdgeFlips="<<num_flips<<" EdgeSmooths="<<num_smoothed<<" Coarsens="<<num_coarsens<<" RefinedSize="<<num_refines_size
00117         <<" RefinedAngle="<<num_refines_angle<<" RefinedBoundary="<<num_refines_boundaries<<endl<<endl;
00118 }
00119 
00120 

Generated on Mon May 24 09:53:30 2010 for TUMBLE by  doxygen 1.5.2