ImgAlgos/src/AlgArrProc.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: AlgArrProc.cpp 12801 2016-10-29 00:20:40Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class AlgArrProc
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "ImgAlgos/AlgArrProc.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <sstream>   // for stringstream
00022 #include <cstring>  // for memcpy
00023 
00024 namespace ImgAlgos {
00025 
00026   typedef AlgArrProc::wind_t wind_t;
00027   typedef AlgImgProc::pixel_status_t pixel_status_t;
00028   typedef AlgImgProc::conmap_t conmap_t;
00029   typedef AlgImgProc::pixel_minimums_t pixel_minimums_t;
00030   typedef AlgImgProc::pixel_maximums_t pixel_maximums_t;
00031   //typedef AlgImgProc::nphoton_t nphoton_t;
00032 
00033 //--------------------
00034 // Constructors --
00035 //--------------------
00036 
00037 AlgArrProc::AlgArrProc(const unsigned& pbits)
00038   : m_pbits(pbits)
00039   , m_is_inited(false)
00040   , m_mask_def(0)
00041   , m_mask(0)
00042 {
00043   if(m_pbits & 256) MsgLog(_name(), info, "in c-tor:1 AlgArrProc(.)");
00044 
00045   // default init
00046   v_winds.clear();
00047   setSoNPars();
00048   setPeakSelectionPars();
00049 }
00050 
00051 //--------------------
00052 
00053 AlgArrProc::AlgArrProc(ndarray<const wind_t,2> nda_winds, const unsigned& pbits)
00054   : m_pbits(pbits)
00055   , m_is_inited(false)
00056   , m_mask_def(0)
00057   , m_mask(0)
00058 {
00059   if(m_pbits & 256) MsgLog(_name(), info, "in c-tor:2 AlgArrProc(..)");
00060 
00061   setWindows(nda_winds);
00062   // default init
00063   setSoNPars();
00064   setPeakSelectionPars();
00065 
00066   if(m_pbits & 2) printInputPars();
00067 }
00068 
00069 //--------------------
00070 
00071 AlgArrProc::~AlgArrProc () 
00072 { 
00073     if(m_pbits & 256) MsgLog(_name(), info, "in d-tor ~AlgArrProc");
00074     //for(std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) delete *it;
00075     if(m_mask_def) delete m_mask_def; 
00076 }
00077 
00078 //--------------------
00079 
00080 void
00081 AlgArrProc::setWindows(ndarray<const wind_t,2> nda_winds)
00082 {
00083   if(m_pbits & 256) MsgLog(_name(), info, "in setWindows");
00084 
00085   v_winds.reserve(nda_winds.shape()[0]);
00086   v_winds.clear();
00087 
00088   for( unsigned i=0; i < nda_winds.shape()[0]; ++i) {
00089     const wind_t* p = &nda_winds[i][0];
00090     Window win((size_t)p[0], (size_t)p[1], (size_t)p[2], (size_t)p[3], (size_t)p[4]);
00091     v_winds.push_back(win);
00092   }
00093 }
00094 
00095 //--------------------
00096 
00097 void
00098 AlgArrProc::setPeakSelectionPars(const float& npix_min, 
00099                                  const float& npix_max, 
00100                                  const float& amax_thr, 
00101                                  const float& atot_thr,
00102                                  const float& son_min)
00103 {
00104   if(m_pbits & 256) MsgLog(_name(), info, "in setPeakSelectionPars");
00105 
00106   m_peak_npix_min = npix_min;
00107   m_peak_npix_max = npix_max;
00108   m_peak_amax_thr = amax_thr;
00109   m_peak_atot_thr = atot_thr;
00110   m_peak_son_min  = son_min;
00111 }
00112 
00113 //--------------------
00114 
00115 void 
00116 AlgArrProc::setSoNPars(const float& r0, const float& dr)
00117 { 
00118   if(m_pbits & 256) MsgLog(_name(), info, "in setSoNPars, r0=" << r0 << " dr=" << dr);
00119 
00120   m_r0=r0; 
00121   m_dr=dr; 
00122 }
00123 
00124 //--------------------
00125 
00126 void 
00127 AlgArrProc::printInputPars()
00128 {
00129   std::stringstream ss; 
00130   ss << "printInputPars():"
00131      << "\n  pbits: " << m_pbits;
00132 
00133   if(v_winds.empty()) { 
00134     ss << "\n  vector of windows is empty - entire ndarray will be processed.\n";
00135   } else {
00136     ss << "\n  Number of windows = " << v_winds.size();
00137     for(std::vector<Window>::iterator it = v_winds.begin(); it != v_winds.end(); ++ it) ss << '\n' << *it;
00138   }
00139   ss << "\n  S/N evaluation parameters:"
00140      << "\n    r0: " << m_r0
00141      << "\n    dr: " << m_dr;
00142 
00143   ss << "\n  Peak selection parameters:"
00144      << "\n    npix_min: " << m_peak_npix_min
00145      << "\n    npix_max: " << m_peak_npix_max
00146      << "\n    amax_thr: " << m_peak_amax_thr
00147      << "\n    atot_thr: " << m_peak_atot_thr
00148      << "\n    son_min : " << m_peak_son_min;
00149 
00150   MsgLog(_name(), info, ss.str()); 
00151 
00152   if(v_algip.size()>0) {
00153     for(std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) (*it) -> printInputPars();
00154   }
00155   else MsgLog(_name(), info, "v_algip is empty...");
00156 }
00157 
00158 //--------------------
00159 
00160 const ndarray<const float, 2>
00161 AlgArrProc::_ndarrayOfPeakPars(const unsigned& npeaks)
00162 {
00163     if(m_pbits & 256) MsgLog(_name(), info, "in _ndarrayOfPeakPars, npeaks = " << npeaks);
00164 
00165     //unsigned sizepk = sizeof(Peak) / sizeof(float);
00166     unsigned sizepk = 17;
00167     if(m_pbits & 1) MsgLog(_name(), info, "List of found peaks, npeaks = " << npeaks << " peak size = " << sizepk); 
00168 
00169     ndarray<float, 2> nda = make_ndarray<float>(npeaks,sizepk);
00170 
00171     unsigned pkcounter = 0;
00172     for (std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) {
00173       //std::vector<Peak>& peaks = (*it) -> getVectorOfPeaks();
00174       std::vector<Peak>& peaks = (*it) -> getVectorOfSelectedPeaks();
00175 
00176       for (std::vector<Peak>::iterator ip = peaks.begin(); ip != peaks.end(); ++ip) {
00177         const Peak& peak = (*ip);
00178         float* p_nda = &nda[pkcounter++][0];
00179         p_nda[ 0] = peak.seg;
00180         p_nda[ 1] = peak.row;
00181         p_nda[ 2] = peak.col;
00182         p_nda[ 3] = peak.npix;       
00183         p_nda[ 4] = peak.amp_max;    
00184         p_nda[ 5] = peak.amp_tot;    
00185         p_nda[ 6] = peak.row_cgrav;   
00186         p_nda[ 7] = peak.col_cgrav;   
00187         p_nda[ 8] = peak.row_sigma;  
00188         p_nda[ 9] = peak.col_sigma;  
00189         p_nda[10] = peak.row_min;    
00190         p_nda[11] = peak.row_max;    
00191         p_nda[12] = peak.col_min;    
00192         p_nda[13] = peak.col_max;    
00193         p_nda[14] = peak.bkgd;       
00194         p_nda[15] = peak.noise;      
00195         p_nda[16] = peak.son; 
00196 
00197         if(m_pbits & 1) cout << peak << '\n';
00198       }
00199     }
00200     return nda;
00201 }
00202 
00203 //--------------------
00204 
00205 ndarray<const pixel_status_t, 3>
00206 AlgArrProc::mapsOfPixelStatus()
00207 {
00208   if(m_pbits & 256) MsgLog(_name(), info, "in mapsOfPixelStatus");
00209 
00210   unsigned shape[3] = {m_nsegs, m_nrows, m_ncols};
00211   ndarray<pixel_status_t, 3> maps(shape);
00212 
00213   for(std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) {
00214 
00215     ndarray<pixel_status_t, 2>& map = (*it) -> mapOfPixelStatus();
00216     const Window& win = (*it) -> window();
00217 
00218     for(unsigned r = win.rowmin; r<win.rowmax; r++) 
00219       for(unsigned c = win.colmin; c<win.colmax; c++)
00220         maps[win.segind][r][c] = map[r][c];
00221   }
00222   return maps;
00223 }
00224 
00225 //--------------------
00226 
00227 ndarray<const conmap_t, 3>
00228 AlgArrProc::mapsOfConnectedPixels()
00229 {
00230   if(m_pbits & 256) MsgLog(_name(), info, "in mapsOfConnectedPixels");
00231 
00232   unsigned shape[3] = {m_nsegs, m_nrows, m_ncols};
00233   ndarray<conmap_t, 3> maps(shape);
00234 
00235   for(std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) {
00236 
00237     ndarray<conmap_t, 2>& conmap = (*it) -> mapOfConnectedPixels();
00238     const Window& win = (*it) -> window();
00239 
00240     for(unsigned r = win.rowmin; r<win.rowmax; r++) 
00241       for(unsigned c = win.colmin; c<win.colmax; c++)
00242         maps[win.segind][r][c] = conmap[r][c];
00243   }
00244   return maps;
00245 }
00246 
00247 //--------------------
00248 
00249 ndarray<const pixel_minimums_t, 3>
00250 AlgArrProc::mapsOfLocalMinimums()
00251 {
00252   if(m_pbits & 256) MsgLog(_name(), info, "in mapsOfLocalMinimums");
00253 
00254   unsigned shape[3] = {m_nsegs, m_nrows, m_ncols};
00255   ndarray<pixel_minimums_t, 3> maps(shape);
00256 
00257   for(std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) {
00258 
00259     ndarray<pixel_minimums_t, 2>& locminmap = (*it) -> mapOfLocalMinimums();
00260     const Window& win = (*it) -> window();
00261 
00262     for(unsigned r = win.rowmin; r<win.rowmax; r++) 
00263       for(unsigned c = win.colmin; c<win.colmax; c++)
00264         maps[win.segind][r][c] = locminmap[r][c];
00265   }
00266   return maps;
00267 }
00268 
00269 //--------------------
00270 
00271 ndarray<const pixel_maximums_t, 3>
00272 AlgArrProc::mapsOfLocalMaximums()
00273 {
00274   if(m_pbits & 256) MsgLog(_name(), info, "in mapsOfLocalMaximums");
00275 
00276   unsigned shape[3] = {m_nsegs, m_nrows, m_ncols};
00277   ndarray<pixel_maximums_t, 3> maps(shape);
00278 
00279   for(std::vector<AlgImgProc*>::iterator it = v_algip.begin(); it != v_algip.end(); ++it) {
00280 
00281     ndarray<pixel_maximums_t, 2>& locmaxmap = (*it) -> mapOfLocalMaximums();
00282     const Window& win = (*it) -> window();
00283 
00284     for(unsigned r = win.rowmin; r<win.rowmax; r++) 
00285       for(unsigned c = win.colmin; c<win.colmax; c++)
00286         maps[win.segind][r][c] = locmaxmap[r][c];
00287   }
00288   return maps;
00289 }
00290 
00291 //--------------------
00292 
00293 //--------------------
00294 } // namespace ImgAlgos
00295 //--------------------
00296 

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7