00001
00002
00003
00004 #ifndef LOG_H
00005 #define LOG_H 1
00006
00007 #include <fstream>
00008
00009 #include <cstdlib>
00010 #include <cstdarg>
00011 #include <cstdio>
00012 #include "meshmorph.h"
00013
00014 #include "state.h"
00015
00016 typedef std::map<std::string,double,lts> map_s_d;
00017 typedef std::map<std::string,double,lts>::iterator sd_it;
00018
00019 class Log
00020 {
00021 private:
00022 Log (void);
00023 Log (Log const &);
00024 Log& operator = (Log const &);
00025 ~Log (void);
00026 static Log * only_one;
00027 std::ofstream Cfile;
00028 std::ofstream Mfile;
00029
00030 int num_verts;
00031 double leaves_mean;
00032 int leaves_min;
00033 int leaves_max;
00034 double face_mean;
00035 int face_min;
00036 int face_max;
00037 double f_check_mean;
00038 int f_check_min;
00039 int f_check_max;
00040
00041 int num_sets;
00042 double vps_mean;
00043 int vps_min;
00044 int vps_max;
00045
00046 double moved_mean;
00047 int moved_min;
00048 int moved_max;
00049
00050 int N;
00051 double d_min;
00052 double d_max;
00053 vec_d md;
00054 double fs_mean;
00055 int fs_min;
00056 int fs_max;
00057 double ps_mean;
00058 double ps_min;
00059 double ps_max;
00060
00061 double fs_face_change_mean;
00062 double fs_face_change_min;
00063 double fs_face_change_max;
00064 double ps_face_change_mean;
00065 double ps_face_change_min;
00066 double ps_face_change_max;
00067
00068
00069
00070
00071
00072
00073 vec_d topN_val;
00074
00075
00076
00077
00078 vec_d vd_val;
00079
00080
00081
00082
00083 vec_d sepdis;
00084
00085 vector3 p_orig;
00086 vector3 const * p_new;
00087 vector3 cp_orig;
00088 vector3 cp_new;
00089 vec_i trouble;
00090
00091 int num_faces;
00092 double bpf_mean;
00093 int bpf_min;
00094 int bpf_max;
00095 int num_boxes;
00096 int num_empty_boxes;
00097 double fpb_mean;
00098 int fpb_min;
00099 int fpb_max;
00100
00101 double t1;
00102 timeval tim;
00103 time_t currtime;
00104 public:
00105 static Log & instance (void);
00106
00107 int getN (void)
00108 {
00109 return N;
00110 }
00111
00112 void groupInit (void);
00113 void writeVertMoveDistribution (int const &);
00114 void writeFiles (int const & group);
00115 void writeSepDistances (int const &);
00116 void updateHauss_1 (std::string const &,double const &,map_s_d &);
00117 void updateHauss_2 (std::string const &,o_it const &,double const &,map_s_d &);
00118 void updateHauss_1_noself (std::string const &,double const &,map_s_d &);
00119 void updateHauss_2_noself (std::string const &,o_it const &,double const &,map_s_d &);
00120 void writeCommandSettings (void);
00121 void closeFiles (void);
00122 void updateFile (int const &,bool,double const &);
00123 void statusFileInit (void);
00124 void writeObjectList (void);
00125 void writeObjectData (void);
00126
00127 void updateVertDisplStats (Vertex * const,vector3 const &);
00128 void clearVals (void);
00129 void writeMoveSummary (int const &,int const &);
00130 void writeRefracted (int const &);
00131 void writeRefractedNow (int const & group,int code);
00132 void writeIntersected (int const &);
00133 void writeNonnice (int const &);
00134 void writeVD (int const &);
00135 void writeAD (int const & group);
00136 void printNumNonnice (std::ostream &) const;
00137 void printNumInt (std::ostream &) const;
00138 void setTime (time_t);
00139 void openMainFile (void);
00140 void recordTime (std::string const &);
00141 void updateBoxesPerFaceStats (int const &);
00142 void calculateFacesPerBoxStats (void);
00143 void printPartitioningStats (std::ostream &) const;
00144 void updateClosestPtStats (int const &,int const &,int const &);
00145 void printClosestPtStats (std::ostream &) const;
00146 void updateVertexSchedulingStats (int const &);
00147 void updateMovedVertsFromSet (void);
00148 void printVertexSchedulingStats (std::ostream &) const;
00149 void updateClosestPtSearchStats (int const &,int const &,Search_Stats const &);
00150 void printClosestPtSearchStats (std::ostream &) const;
00151 void openOrDie (std::ofstream * const handle,std::string str,const int & group);
00152
00153 bool isGood (Vertex const * const) const;
00154 void writeDetailedMoveInfo (void);
00155 void printBad (Vertex const * const) const;
00156 void setDetailedInfoPreMove (Vertex * const);
00157 void setDetailedInfoPostMove (Vertex *);
00158
00159 std::string formatv(char const *fmt, va_list args)
00160 {
00161 char buffer[512];
00162 uint needLen;
00163 va_list argsCopy;
00164 va_copy(argsCopy, args);
00165
00166 needLen = vsnprintf(buffer, sizeof(buffer), fmt, args);
00167 if (needLen <= sizeof(buffer))
00168 {
00169 va_end(argsCopy);
00170 return std::string(buffer);
00171 }
00172 else
00173 {
00174 char *big_buffer = new char[needLen + 1];
00175 vsnprintf(big_buffer, needLen + 1, fmt, argsCopy);
00176 std::string ret(big_buffer);
00177 delete[] big_buffer;
00178 va_end(argsCopy);
00179 return ret;
00180 }
00181 };
00182
00183 std::string format(char const *fmt, ...)
00184 {
00185 va_list args;
00186 va_start(args, fmt);
00187 std::string ret(formatv(fmt, args));
00188 va_end(args);
00189 return ret;
00190 };
00191
00192 };
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 #endif