00001 #ifndef STDDOMAINS_HEADER_
00002 #define STDDOMAINS_HEADER_
00003
00004 #include "../headers.h"
00005
00007
00012 class MStdDomains: public ISquareDomains {
00013 DECLARE_debugModule;
00014
00015 DECLARE_TypeInfo( MStdDomains, "Standard domains generator"
00016 , "Creates domain blocks of many types (standard, horizontal, vertical, diamond)"
00017 , {
00018 label: "Per-level max-domain-count divisor",
00019 desc: "How many times will the maximum domain count\n"
00020 "decrease with every level\n"
00021 "(dimensions are equal to 2^level)",
00022 type: settingInt(0,0,4,IntLog2)
00023 }, {
00024 label: "More-downscaled domain count",
00025 desc: "The development of count of domains\n"
00026 "made from more downscaled images",
00027 type: settingCombo("none\nno decrease\nhalf per scale",0)
00028 }, {
00029 label: "Standard domains portion",
00030 desc: "How big portion from all domains\n"
00031 "will be of standard type",
00032 type: settingInt(0,1,8)
00033 }, {
00034 label: "Diamond domains portion",
00035 desc: "How big portion from all domains\n"
00036 "will be of diamond type",
00037 type: settingInt(0,0,8)
00038 }, {
00039 label: "Horizontal domains portion",
00040 desc: "How big portion from all domains\n"
00041 "will be of horizontal type",
00042 type: settingInt(0,0,8)
00043 }, {
00044 label: "Vertical domains portion",
00045 desc: "How big portion from all domains\n"
00046 "will be of vertical type",
00047 type: settingInt(0,0,8)
00048 } )
00049
00050 protected:
00052 enum Settings { MaxDomCountLevelDivisor, MultiDownScaling
00053 , DomPortion_Standard, DomPortion_Diamond, DomPortion_Horiz, DomPortion_Vert };
00054
00055
00057 PoolList pools;
00058 int width
00059 , height
00060 , zoom;
00061
00062
00063 #ifndef NDEBUG
00064 MStdDomains(): width(-1), height(-1), zoom(-1) {}
00065 #endif
00066
00067 ~MStdDomains() {
00068 for (PoolList::iterator it=pools.begin(); it!=pools.end(); ++it)
00069 it->free();
00070 }
00071
00072 public:
00075 void initPools(const PlaneBlock &planeBlock);
00076 void fillPixelsInPools(PlaneBlock &planeBlock);
00077
00078 const PoolList& getPools() const
00079 { return pools; }
00080 std::vector<short> getLevelDensities(int level,int stdDomCountLog2);
00081
00082 void writeSettings(std::ostream &file);
00083 void readSettings(std::istream &file);
00084
00085 void writeData(std::ostream &) {}
00086 void readData(std::istream &) {}
00088 };
00089
00090
00091
00092 namespace MatrixWalkers {
00094 struct ReverseAssigner: public OperatorBase {
00095 template<class R1,class R2> void operator()(R1 &dest,R2 src) const { dest= src; }
00096 };
00098 template<class T,class I=PtrInt>
00099 struct HalfShrinker: public Rotation_0<T,I> { ROTBASE_INHERIT
00100 typedef Rotation_0<T,I> Base;
00101
00102 HalfShrinker( TMatrix matrix, I x0=0, I y0=0 )
00103 : Base(matrix,x0,y0) {}
00104
00105 T get() {
00106 TMatrix &c= current;
00107 T *cs= c.start;
00108 return ldexp( cs[0] + cs[1] + cs[c.colSkip] + cs[c.colSkip+1], -2 );
00109 }
00110 void outerStep() { Base::outerStep(); Base::outerStep(); }
00111 void innerStep() { Base::innerStep(); Base::innerStep(); }
00112 };
00114 template<class T,class I=PtrInt>
00115 struct HorizShrinker: public Rotation_0<T,I> { ROTBASE_INHERIT
00116 typedef Rotation_0<T,I> Base;
00117
00118 bool addHalf;
00119
00120 HorizShrinker(TMatrix matrix)
00121 : Base(matrix), addHalf(false) {}
00122
00123 T get() {
00124 Real groups[2];
00125 T *cs= current.start;
00126 groups[addHalf]= cs[0] + cs[current.colSkip] + cs[current.colSkip*2];
00127 ++cs;
00128 groups[!addHalf]= cs[0] + cs[current.colSkip] + cs[current.colSkip*2];
00129 return (ldexp(groups[0],1)+groups[1]) * Real(1.0/9.0);
00130 }
00131 void innerStep() {
00132
00133 Base::innerStep();
00134 if (addHalf)
00135 Base::innerStep();
00136 addHalf= !addHalf;
00137 }
00138 void outerStep() {
00139 for (int i=0; i<3; ++i)
00140 Base::outerStep();
00141 }
00142 };
00144 template<class T,class I=PtrInt>
00145 struct VertShrinker: public Rotation_0<T,I> { ROTBASE_INHERIT
00146 typedef Rotation_0<T,I> Base;
00147
00148 bool addHalf;
00149
00150 VertShrinker(TMatrix matrix)
00151 : Base(matrix), addHalf(false) {}
00152
00153 T get() {
00154 Real groups[2];
00155 T *cs= current.start;
00156 groups[addHalf]= cs[0] + cs[1] + cs[2];
00157 cs+= current.colSkip;
00158 groups[!addHalf]= cs[0] + cs[1] + cs[2];
00159 return (ldexp(groups[0],1)+groups[1]) * Real(1.0/9.0);
00160 }
00161 void innerStep() {
00162 for (int i=0; i<3; ++i)
00163 Base::innerStep();
00164 }
00165 void outerStep() {
00166
00167 Base::outerStep();
00168 if (addHalf)
00169 Base::outerStep();
00170 addHalf= !addHalf;
00171 }
00172 };
00175 template<class T,class I=PtrInt>
00176 struct DiamShrinker: public Rotation_0<T,I> { ROTBASE_INHERIT
00177 typedef Rotation_0<T,I> Base;
00178
00179 DiamShrinker(TMatrix matrix,I side)
00180 : Base( matrix, side-1, 0 ) {}
00181
00182 T get() {
00183 TMatrix &c= current;
00184 T *cs= c.start;
00185 return ldexp( cs[0] + cs[1] + cs[c.colSkip] + cs[c.colSkip+1], -2 );
00186 }
00187 void outerStep() { lastStart+= current.colSkip+1; }
00188 void innerStep() { current.start+= 1-current.colSkip; }
00189 };
00190 }
00191
00192
00193 #endif // STDDOMAINS_HEADER_