|
Isis 3.0 Object Programmers' Reference |
Home |
00001 00023 #include <string> 00024 #include "BufferManager.h" 00025 00026 using namespace std; 00027 namespace Isis { 00051 BufferManager::BufferManager(const int maxsamps,const int maxlines, 00052 const int maxbands,const int bufsamps, 00053 const int buflines, const int bufbands, 00054 const Isis::PixelType type, const bool reverse) : 00055 Isis::Buffer(bufsamps,buflines,bufbands,type), 00056 p_maxSamps(maxsamps),p_maxLines(maxlines), 00057 p_maxBands(maxbands) { 00058 SetIncrements (bufsamps,buflines,bufbands); 00059 p_reverse = reverse; 00060 } 00061 00088 void BufferManager::SetIncrements(const int sinc, const int linc, 00089 const int binc) { 00090 p_sinc = sinc; 00091 p_linc = linc; 00092 p_binc = binc; 00093 00094 p_soff = 0; 00095 p_loff = 0; 00096 p_boff = 0; 00097 00098 p_currentSample = p_currentLine = p_currentBand = 1; 00099 p_currentMap = 0; 00100 00101 p_nmaps = ( (BigInt) ((p_maxSamps - 1) / p_sinc + 1) * 00102 (BigInt) ((p_maxLines - 1) / p_linc + 1) * 00103 (BigInt) ((p_maxBands - 1) / p_binc + 1) ); 00104 } 00105 00126 void BufferManager::SetOffsets (const int soff, const int loff, 00127 const int boff) { 00128 p_soff = soff; 00129 p_loff = loff; 00130 p_boff = boff; 00131 } 00132 00165 bool BufferManager::setpos(const BigInt map) { 00166 if (map < 0) { 00167 string message = "Invalid value for argument [map]"; 00168 throw Isis::iException::Message(Isis::iException::Programmer,message,_FILEINFO_); 00169 } 00170 if ( p_reverse ) { 00171 if (p_currentMap+1 == map) { 00172 p_currentBand += p_binc; 00173 if (p_currentBand > p_maxBands) { 00174 p_currentBand = 1; 00175 p_currentLine += p_linc; 00176 if (p_currentLine > p_maxLines) { 00177 p_currentLine = 1; 00178 p_currentSample += p_sinc; 00179 } 00180 } 00181 } else if (p_currentMap-1 == map) { 00182 p_currentBand -= p_binc; 00183 if (p_currentBand < 1) { 00184 p_currentBand = ((p_maxBands - 1) / p_binc) * p_binc + 1; 00185 p_currentBand -= p_binc; 00186 if (p_currentLine < 1) { 00187 p_currentLine = ((p_maxLines - 1) / p_linc) * p_linc + 1; 00188 p_currentSample -= p_sinc; 00189 } 00190 } 00191 } else { 00192 p_currentSample = p_currentLine = p_currentBand = 1; 00193 if (map < p_nmaps) { 00194 for (int i=0; i<map; i++) { 00195 p_currentBand += p_binc; 00196 if (p_currentBand > p_maxBands) { 00197 p_currentBand = 1; 00198 p_currentLine += p_linc; 00199 if (p_currentLine > p_maxLines) { 00200 p_currentLine = 1; 00201 p_currentSample += p_sinc; 00202 } 00203 } 00204 } 00205 } 00206 } 00207 } else { //p_reverse is false 00208 if (p_currentMap+1 == map) { 00209 p_currentSample += p_sinc; 00210 if (p_currentSample > p_maxSamps) { 00211 p_currentSample = 1; 00212 p_currentLine += p_linc; 00213 if (p_currentLine > p_maxLines) { 00214 p_currentLine = 1; 00215 p_currentBand += p_binc; 00216 } 00217 } 00218 } else if (p_currentMap-1 == map) { 00219 p_currentSample -= p_sinc; 00220 if (p_currentSample < 1) { 00221 p_currentSample = ((p_maxSamps - 1) / p_sinc) * p_sinc + 1; 00222 p_currentLine -= p_linc; 00223 if (p_currentLine < 1) { 00224 p_currentLine = ((p_maxLines - 1) / p_linc) * p_linc + 1; 00225 p_currentBand -= p_binc; 00226 } 00227 } 00228 } else { 00229 p_currentSample = p_currentLine = p_currentBand = 1; 00230 if (map < p_nmaps) { 00231 for (int i=0; i<map; i++) { 00232 p_currentSample += p_sinc; 00233 if (p_currentSample > p_maxSamps) { 00234 p_currentSample = 1; 00235 p_currentLine += p_linc; 00236 if (p_currentLine > p_maxLines) { 00237 p_currentLine = 1; 00238 p_currentBand += p_binc; 00239 } 00240 } 00241 } 00242 } 00243 } 00244 } 00245 00246 SetBasePosition (p_currentSample + p_soff, 00247 p_currentLine + p_loff, 00248 p_currentBand + p_boff); 00249 00250 p_currentMap = map; 00251 00252 return !end(); 00253 } 00254 } // end namespace isis