ImgAlgos/include/Window.h

Go to the documentation of this file.
00001 #ifndef IMGALGOS_WINDOW_H
00002 #define IMGALGOS_WINDOW_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: Window.h 10528 2015-07-30 00:47:04Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class Window.
00010 //------------------------------------------------------------------------
00011 
00012 //-----------------
00013 // C/C++ Headers --
00014 //-----------------
00015 #include <stdint.h>    // uint8_t, uint32_t, etc.
00016 #include <cstring>     // size_t
00017 #include <sstream>     // for stringstream
00018 #include <algorithm>   // std::max
00019 #include <iostream>    // std::ostream
00020 #include <iomanip>     // for setw, setfill
00021 
00022 //#include <string>
00023 //#include <fstream>   // ofstream
00024 //#include <sstream>   // for stringstream
00025 //#include <iostream>
00026 //#include <math.h>
00027 //#include <stdio.h>
00028 
00029 #include "MsgLogger/MsgLogger.h"
00030 
00031 namespace ImgAlgos {
00032 
00033 /// @addtogroup ImgAlgos
00034 
00035 /**
00036  *  @ingroup ImgAlgos
00037  *
00038  *  @brief Holds 2-d window limits and pointer to the window shape.
00039  *
00040  *  This software was developed for the LCLS project.  If you use all or 
00041  *  part of it, please give an appropriate acknowledgment.
00042  *
00043  *  @version $Id: Window.h 10528 2015-07-30 00:47:04Z dubrovin@SLAC.STANFORD.EDU $
00044  *
00045  *  @author Mikhail S. Dubrovin
00046  */
00047 
00048 using namespace std;
00049 
00050 //--------------------
00051 
00052 class Window {
00053 
00054  public: 
00055 
00056   // Size limits [MIN_SIZE_LIMIT, MAX_SIZE_LIMIT) 
00057   static const size_t MIN_SIZE_LIMIT = 0;  
00058   static const size_t MAX_SIZE_LIMIT = 100000;  
00059 
00060   typedef unsigned shape_t;
00061 
00062   size_t segind;
00063   size_t rowmin;
00064   size_t rowmax;
00065   size_t colmin;
00066   size_t colmax;
00067 
00068 //--------------------
00069   /// Constructor (including default) sets window parameters from shape or from default limits
00070   Window(const shape_t* shape=0) 
00071   { 
00072     set(shape);
00073   }
00074 
00075 //--------------------
00076   /// Constructor sets specified window parameters and checks their validity if shape is is already available
00077   Window( const size_t& segi
00078         , const size_t& rmin
00079         , const size_t& rmax
00080         , const size_t& cmin
00081         , const size_t& cmax )
00082   : m_shape(0)
00083   {
00084     set(segi, rmin, rmax, cmin, cmax);
00085   }
00086 
00087 //--------------------
00088   /// Set window parameters
00089   void set( const size_t& segi
00090           , const size_t& rmin
00091           , const size_t& rmax
00092           , const size_t& cmin
00093           , const size_t& cmax )
00094   {
00095     segind = segi;
00096     rowmin = rmin;
00097     rowmax = rmax;
00098     colmin = cmin;
00099     colmax = cmax;
00100     if(m_shape) validate(m_shape);
00101   }
00102 
00103 //--------------------
00104   /// Set window parameters from shape
00105   void set(const shape_t* shape=0)
00106   {
00107     m_shape = shape; 
00108     rowmin = MIN_SIZE_LIMIT;
00109     rowmax = (shape) ? m_shape[0] : MAX_SIZE_LIMIT;
00110     colmin = MIN_SIZE_LIMIT;
00111     colmax = (shape) ? m_shape[1] : MAX_SIZE_LIMIT;
00112   }
00113 
00114 //--------------------
00115   /// Validate window parameters
00116   void validate(const shape_t* shape) 
00117   {
00118     m_shape = shape;
00119     rowmin = std::max((int)MIN_SIZE_LIMIT, int(rowmin));
00120     rowmax = std::min((size_t) m_shape[0], rowmax);
00121     colmin = std::max((int)MIN_SIZE_LIMIT, int(colmin));
00122     colmax = std::min((size_t) m_shape[1], colmax);
00123   }
00124 
00125 //--------------------
00126   /// Returns pointer to the shape
00127   const shape_t* shape() { return m_shape; }
00128 
00129 //--------------------
00130   /// Prints memeber data
00131   void print()
00132   {
00133     std::stringstream ss; 
00134     ss << "seg:"   << segind
00135        << " rmin:" << rowmin
00136        << " rmax:" << rowmax
00137        << " cmin:" << colmin
00138        << " cmax:" << colmax;  
00139     if(m_shape) ss << " shape=(" << m_shape[0]
00140                    << "," << m_shape[1]<< ")";
00141     //ss << '\n';
00142 
00143     MsgLog(_name(), info, ss.str()); 
00144   }
00145 
00146 //--------------------
00147   /// Make window with specified parameters
00148   Window& make( const size_t& segi
00149               , const size_t& rmin
00150               , const size_t& rmax
00151               , const size_t& cmin
00152               , const size_t& cmax )
00153   {
00154     set(segi, rmin, rmax, cmin, cmax);
00155     m_shape = 0;
00156     return *this;
00157   }
00158 
00159 
00160 //--------------------
00161   Window(const Window& rhs)
00162   {
00163     segind = rhs.segind;
00164     rowmin = rhs.rowmin;
00165     rowmax = rhs.rowmax;
00166     colmin = rhs.colmin;
00167     colmax = rhs.colmax;
00168   }
00169 
00170 //--------------------
00171   /// copy object operator
00172   Window& operator=(const Window& rhs)
00173   {
00174     segind = rhs.segind;
00175     rowmin = rhs.rowmin;
00176     rowmax = rhs.rowmax;
00177     colmin = rhs.colmin;
00178     colmax = rhs.colmax;
00179     //m_shape= rhs.shape(); 
00180     return *this;
00181   }
00182 
00183 //--------------------
00184 
00185  private:
00186 
00187   const shape_t* m_shape;  
00188 
00189   /// Returns string name of the class for messanger
00190   inline const char* _name() {return "ImgAlgos::Window";}
00191 };
00192 
00193 //--------------------
00194 
00195   /// operator <<
00196   inline std::ostream& operator<<(std::ostream& out, const Window& w) {
00197     return out << "  segind:" << std::setw(2) << w.segind 
00198                << "  rowmin:" << std::setw(4) << w.rowmin 
00199                << "  rowmax:" << std::setw(4) << w.rowmax                       
00200                << "  colmin:" << std::setw(4) << w.colmin 
00201                << "  colmax:" << std::setw(4) << w.colmax;
00202   }
00203 
00204 //--------------------
00205 //--------------------
00206 //--------------------
00207 //--------------------
00208 //--------------------
00209 
00210 } // namespace ImgAlgos
00211 
00212 #endif // IMGALGOS_WINDOW_H

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7