LevelSpec.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Image/LevelSpec.H"
00039
00040 #include "Util/Assert.H"
00041 #include "Util/StringConversions.H"
00042 #include "Util/log.H"
00043
00044 #include <sstream>
00045 #include <stdio.h>
00046
00047
00048
00049
00050
00051
00052
00053
00054 LevelSpec::LevelSpec() :
00055 itsLevMin(0), itsLevMax(0), itsDelMin(0), itsDelMax(0), itsMapLevel(0),
00056 itsMaxIndex(0), itsMaxDepth(0)
00057 { }
00058
00059
00060 LevelSpec::LevelSpec(const uint levmin, const uint levmax,
00061 const uint deltmin, const uint deltmax,
00062 const uint maplevel) :
00063 itsLevMin(levmin),
00064 itsLevMax(levmax),
00065 itsDelMin(deltmin),
00066 itsDelMax(deltmax),
00067 itsMapLevel(maplevel),
00068 itsMaxIndex( (deltmax-deltmin+1) * (levmax-levmin+1) ),
00069 itsMaxDepth( levmax + deltmax + 1 )
00070 {
00071 ASSERT(levmax >= levmin); ASSERT(deltmax >= deltmin);
00072 }
00073
00074
00075 void LevelSpec::init(const uint levmin, const uint levmax,
00076 const uint deltmin, const uint deltmax,
00077 const uint maplevel)
00078 {
00079 ASSERT(levmax >= levmin); ASSERT(deltmax >= deltmin);
00080
00081 itsLevMin = levmin; itsLevMax = levmax; itsDelMin = deltmin;
00082 itsDelMax = deltmax; itsMapLevel = maplevel;
00083 itsMaxIndex = (deltmax-deltmin+1) * (levmax-levmin+1);
00084 itsMaxDepth = levmax + deltmax + 1;
00085 }
00086
00087
00088 uint LevelSpec::levMin() const
00089 { return itsLevMin; }
00090
00091
00092 uint LevelSpec::levMax() const
00093 { return itsLevMax; }
00094
00095
00096 uint LevelSpec::delMin() const
00097 { return itsDelMin; }
00098
00099
00100 uint LevelSpec::delMax() const
00101 { return itsDelMax; }
00102
00103
00104 uint LevelSpec::mapLevel() const
00105 { return itsMapLevel; }
00106
00107
00108 uint LevelSpec::maxIndex() const
00109 { return itsMaxIndex; }
00110
00111
00112 uint LevelSpec::maxDepth() const
00113 { return itsMaxDepth; }
00114
00115
00116 bool LevelSpec::indexOK(uint index) const
00117 { return (index < itsMaxIndex); }
00118
00119
00120 bool LevelSpec::clevOK(uint centerlev) const
00121 { return (centerlev >= itsLevMin && centerlev <= itsLevMax); }
00122
00123
00124 bool LevelSpec::slevOK(uint surrlev) const
00125 {
00126 return (surrlev >= (itsLevMin + itsDelMin) &&
00127 surrlev <= (itsLevMax + itsDelMax));
00128 }
00129
00130
00131 bool LevelSpec::delOK(uint delta) const
00132 { return (delta >= itsDelMin && delta <= itsDelMax); }
00133
00134
00135 bool LevelSpec::csOK(uint centerlev, uint surroundlev) const
00136 {
00137
00138
00139
00140
00141
00142
00143 return clevOK(centerlev) && slevOK(surroundlev)
00144 && delOK(surroundlev - centerlev);
00145 }
00146
00147
00148 uint LevelSpec::csToIndex(uint centerlev, uint surroundlev) const
00149 {
00150 ASSERT( csOK(centerlev, surroundlev) );
00151
00152 const uint delta = surroundlev - centerlev;
00153
00154 return centerlev - itsLevMin +
00155 (delta - itsDelMin) * (itsLevMax - itsLevMin + 1);
00156 }
00157
00158
00159 void LevelSpec::indexToCS(uint index, uint& centerlev, uint& surroundlev) const
00160 {
00161 ASSERT( indexOK(index) );
00162
00163 centerlev = index % (itsLevMax - itsLevMin + 1) + itsLevMin;
00164 uint delta = index / (itsLevMax - itsLevMin + 1) + itsDelMin;
00165
00166 surroundlev = centerlev + delta;
00167
00168 ASSERT( csOK(centerlev, surroundlev) );
00169 }
00170
00171
00172 bool LevelSpec::operator==(const LevelSpec& that) const
00173 {
00174 return (this->itsLevMin == that.itsLevMin
00175 && this->itsLevMax == that.itsLevMax
00176 && this->itsDelMin == that.itsDelMax
00177 && this->itsDelMax == that.itsDelMax
00178 && this->itsMapLevel == that.itsMapLevel
00179 && this->itsMaxIndex == that.itsMaxIndex
00180 && this->itsMaxDepth == that.itsMaxDepth);
00181 }
00182
00183
00184
00185
00186
00187
00188 std::string convertToString(const LevelSpec& val)
00189 {
00190 std::stringstream s;
00191 s<<val.levMin()<<'-'<<val.levMax()<<','<<val.delMin()<<'-'<<
00192 val.delMax()<<','<<val.mapLevel();
00193 return s.str();
00194 }
00195
00196 void convertFromString(const std::string& str, LevelSpec& val)
00197 {
00198 std::stringstream s; int lmi = -2, lma = -2, dmi = -2, dma = -2, ml = -2;
00199 char c; s<<str; s>>lmi>>c>>lma>>c>>dmi>>c>>dma>>c>>ml;
00200 if (lmi == -2 || lma == -2 || dmi == -2 || dma == -2 || ml == -2)
00201 conversion_error::raise<LevelSpec>(str);
00202
00203 val.init(lmi, lma, dmi, dma, ml);
00204 }
00205
00206
00207
00208
00209
00210
00211
00212