Isis 3 Programmer Reference
BufferManager.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "BufferManager.h"
8
9#include <iostream>
10#include <string>
11
12#include "IException.h"
13
14using namespace std;
15
16namespace Isis {
17 BufferManager::BufferManager() {
18 }
19
20
44 BufferManager::BufferManager(int maxsamps, int maxlines,
45 int maxbands, int bufsamps,
46 int buflines, int bufbands,
47 Isis::PixelType type, bool reverse) :
48 Isis::Buffer(bufsamps, buflines, bufbands, type),
49 p_maxSamps(maxsamps), p_maxLines(maxlines),
50 p_maxBands(maxbands) {
51 SetIncrements(bufsamps, buflines, bufbands);
52 p_reverse = reverse;
53 }
54
55
62 BufferManager::BufferManager(const BufferManager &other) :
63 Buffer(other),
64 p_maxSamps(other.p_maxSamps), p_maxLines(other.p_maxLines),
65 p_maxBands(other.p_maxBands), p_sinc(other.p_sinc), p_linc(other.p_linc),
66 p_binc(other.p_binc), p_soff(other.p_soff), p_loff(other.p_loff),
67 p_boff(other.p_boff), p_currentSample(other.p_currentSample),
68 p_currentLine(other.p_currentLine), p_currentBand(other.p_currentBand),
69 p_nmaps(other.p_nmaps), p_currentMap(other.p_currentMap),
70 p_reverse(other.p_reverse) {
71 }
72
73
81 std::swap(p_maxSamps, other.p_maxSamps);
82 std::swap(p_maxLines, other.p_maxLines);
83 std::swap(p_maxBands, other.p_maxBands);
84 std::swap(p_sinc, other.p_sinc);
85 std::swap(p_linc, other.p_linc);
86 std::swap(p_binc, other.p_binc);
87 std::swap(p_soff, other.p_soff);
88 std::swap(p_loff, other.p_loff);
89 std::swap(p_boff, other.p_boff);
90 std::swap(p_currentSample, other.p_currentSample);
91 std::swap(p_currentLine, other.p_currentLine);
92 std::swap(p_currentBand, other.p_currentBand);
93 std::swap(p_nmaps, other.p_nmaps);
94 std::swap(p_currentMap, other.p_currentMap);
95 std::swap(p_reverse, other.p_reverse);
96 }
97
98
107 BufferManager copy(rhs);
108 swap(copy);
109 return *this;
110 }
111
112
139 void BufferManager::SetIncrements(const int sinc, const int linc,
140 const int binc) {
141 p_sinc = sinc;
142 p_linc = linc;
143 p_binc = binc;
144
145 p_soff = 0;
146 p_loff = 0;
147 p_boff = 0;
148
150 p_currentMap = 0;
151
152 p_nmaps = ((BigInt)((p_maxSamps - 1) / p_sinc + 1) *
153 (BigInt)((p_maxLines - 1) / p_linc + 1) *
154 (BigInt)((p_maxBands - 1) / p_binc + 1));
155 }
156
157
178 void BufferManager::SetOffsets(const int soff, const int loff,
179 const int boff) {
180 p_soff = soff;
181 p_loff = loff;
182 p_boff = boff;
183 }
184
185
219 if(map >= 0) {
220 p_currentMap = map;
221
222 if(!p_reverse) {
223 int sampDimension = (p_maxSamps / p_sinc);
224 if (p_maxSamps % p_sinc)
225 sampDimension++;
226
227 p_currentSample = (map % sampDimension) * p_sinc + 1;
228 map /= sampDimension;
229
230 int lineDimension = (p_maxLines / p_linc);
231 if (p_maxLines % p_linc)
232 lineDimension++;
233
234 p_currentLine = (map % lineDimension) * p_linc + 1;
235 map /= lineDimension;
236
237 p_currentBand = map * p_binc + 1;
238 }
239 else {
240 int bandDimension = (p_maxBands / p_binc);
241 if (p_maxBands % p_binc)
242 bandDimension++;
243
244 p_currentBand = (map % bandDimension) * p_binc + 1;
245 map /= bandDimension;
246
247 int lineDimension = (p_maxLines / p_linc);
248 if (p_maxLines % p_linc)
249 lineDimension++;
250
251 p_currentLine = (map % lineDimension) * p_linc + 1;
252 map /= lineDimension;
253
254 p_currentSample = map * p_sinc + 1;
255 }
256
260 }
261 else {
262 string message = "Invalid value for argument [map]";
263 throw IException(IException::Programmer, message, _FILEINFO_);
264 }
265
266 return !end();
267 }
268} // end namespace isis
Buffer for reading and writing cube data.
Definition Buffer.h:53
void SetBasePosition(const int start_sample, const int start_line, const int start_band)
This method is used to set the base position of the shape buffer.
Definition Buffer.cpp:106
Manages a Buffer over a cube.
BufferManager & operator=(const BufferManager &rhs)
Creates a new BufferManager with the same values as another.
int p_currentSample
Current sample.
void swap(BufferManager &other)
Swaps the values of this BufferManager with that of another.
int p_currentBand
Current band.
int p_linc
Line increment.
int p_maxBands
Maximum bands to map.
int p_currentLine
Current line.
void SetOffsets(const int soff, const int loff, const int boff)
Sets the offset of the buffer.
int p_maxSamps
Maximum samples to map.
int p_boff
Band offset.
bool p_reverse
If true the axies are processed in Band, Line, Sample order (e.g., BIL).
int p_sinc
Sample increment.
int p_soff
Sample offset.
bool setpos(BigInt map)
Sets the position of the shape in the cube.
int p_loff
Line offset.
bool end() const
Returns true if the shape buffer has accessed the end of the cube.
BigInt p_currentMap
Current buffer map position.
void SetIncrements(const int sinc, const int linc, const int binc)
Sets how the shape is incremented through the cube.
int p_maxLines
Maximum lines to map.
BigInt p_nmaps
Total number of objects to map.
int p_binc
Band increment.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
long long int BigInt
Big int.
Definition Constants.h:49
PixelType
Enumerations for Isis Pixel Types.
Definition PixelType.h:27
Namespace for the standard library.