00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "ImgAlgos/AlgSmearing.h"
00017
00018
00019
00020
00021 #include <math.h>
00022 #include <iomanip>
00023 #include <sstream>
00024
00025
00026
00027
00028 #include "MsgLogger/MsgLogger.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace ImgAlgos {
00039
00040
00041
00042
00043
00044
00045
00046 AlgSmearing::AlgSmearing( const double& sigma
00047 , const int& nsm
00048 , const double& thr_low
00049 , const unsigned& opt
00050 , const unsigned& pbits
00051 , const size_t& seg
00052 , const size_t& rowmin
00053 , const size_t& rowmax
00054 , const size_t& colmin
00055 , const size_t& colmax
00056 , const double& value
00057 )
00058 : m_sigma(sigma)
00059 , m_nsm(nsm)
00060 , m_nsm1(nsm+1)
00061 , m_thr_low(thr_low)
00062 , m_opt(opt)
00063 , m_pbits(pbits)
00064 , m_seg(seg)
00065 , m_rowmin(rowmin)
00066 , m_rowmax(rowmax)
00067 , m_colmin(colmin)
00068 , m_colmax(colmax)
00069 , m_value(value)
00070 {
00071 if(m_pbits & 1) printInputPars();
00072 evaluateWeights();
00073 if(m_pbits & 2) printWeights();
00074 }
00075
00076
00077
00078 void
00079 AlgSmearing::evaluateWeights()
00080 {
00081 m_weights = make_ndarray<double>(m_nsm1, m_nsm1);
00082
00083
00084
00085 if ( m_sigma == 0 ) {
00086 if(m_pbits) MsgLog(_name(), info, "Smearing is turned OFF by sigma = " << m_sigma);
00087 std::fill_n(m_weights.data(), int(m_weights.size()*sizeof(double)), double(0));
00088 m_weights[0][0] = 1;
00089 return;
00090 }
00091
00092 double norm = -0.5/(m_sigma*m_sigma);
00093 for (int r = 0; r < m_nsm1; r++) {
00094 for (int c = 0; c < m_nsm1; c++) {
00095 m_weights[r][c] = exp( norm * (r*r+c*c) );
00096 }
00097 }
00098 }
00099
00100
00101
00102 void
00103 AlgSmearing::printWeights()
00104 {
00105
00106
00107 std::stringstream ss; ss << "printWeights() - Weights for smearing";
00108 ss << "\n cols : ";
00109 for (int c = 0; c < m_nsm1; c++) ss << std::left << std::setw(10) << c;
00110 for (int r = 0; r < m_nsm1; r++) {
00111 ss << "\n row=" << r << ": " << fixed;
00112 for (int c = 0; c < m_nsm1; c++) {
00113 ss << " " << std::left << std::setw(8) << m_weights[r][c];
00114 }
00115 }
00116 MsgLog(_name(), info, ss.str());
00117 }
00118
00119
00120
00121 void
00122 AlgSmearing::printInputPars()
00123 {
00124 std::stringstream ss;
00125 ss << "\nsigma : " << m_sigma
00126 << "\nnsm : " << m_nsm
00127 << "\nnsm1 : " << m_nsm1
00128 << "\nthr_low : " << m_thr_low
00129 << "\nopt : " << m_opt
00130 << "\nseg : " << m_seg
00131 << "\nrowmin : " << m_rowmin
00132 << "\nrowmax : " << m_rowmax
00133 << "\ncolmin : " << m_colmin
00134 << "\ncolmax : " << m_colmax
00135 << "\nvalue : " << m_value
00136 << '\n';
00137 MsgLog(_name(), info, ss.str());
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 }