00001 #ifndef IMGALGOS_WINDOW_H
00002 #define IMGALGOS_WINDOW_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdint.h>
00016 #include <cstring>
00017 #include <sstream>
00018 #include <algorithm>
00019 #include <iostream>
00020 #include <iomanip>
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "MsgLogger/MsgLogger.h"
00030
00031 namespace ImgAlgos {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 using namespace std;
00049
00050
00051
00052 class Window {
00053
00054 public:
00055
00056
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
00070 Window(const shape_t* shape=0)
00071 {
00072 set(shape);
00073 }
00074
00075
00076
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
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
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
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
00127 const shape_t* shape() { return m_shape; }
00128
00129
00130
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
00142
00143 MsgLog(_name(), info, ss.str());
00144 }
00145
00146
00147
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
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
00180 return *this;
00181 }
00182
00183
00184
00185 private:
00186
00187 const shape_t* m_shape;
00188
00189
00190 inline const char* _name() {return "ImgAlgos::Window";}
00191 };
00192
00193
00194
00195
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 }
00211
00212 #endif // IMGALGOS_WINDOW_H