Isis 3 Programmer Reference
RawCubeChunk.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "RawCubeChunk.h"
8
9#include <cmath>
10#include <iostream>
11
12#include <QByteArray>
13
14#include "Area3D.h"
15#include "Displacement.h"
16#include "Distance.h"
17#include "IException.h"
18#include "IString.h"
19
20namespace Isis {
28 RawCubeChunk::RawCubeChunk(const Area3D &placement, int numBytes) {
29 m_dirty = false;
30
31 m_rawBuffer = new QByteArray(numBytes, '\0');
33
34 m_sampleCount = (int)round(placement.getWidth().pixels()) + 1;
35 m_lineCount = (int)round(placement.getHeight().pixels()) + 1;
36 m_bandCount = (int)round(placement.getDepth().pixels()) + 1;
37
38 m_startSample = (int)round(placement.getStartX().pixels());
39 m_startLine = (int)round(placement.getStartY().pixels());
40 m_startBand = (int)round(placement.getStartZ().pixels());
41 }
42
56 RawCubeChunk::RawCubeChunk(int startSample, int startLine, int startBand,
57 int endSample, int endLine, int endBand,
58 int numBytes) {
59 m_dirty = false;
60
61 m_rawBuffer = new QByteArray(numBytes, '\0');
63
64 m_sampleCount = endSample - startSample + 1;
65 m_lineCount = endLine - startLine + 1;
66 m_bandCount = endBand - startBand + 1;
67
68 m_startSample = startSample;
69 m_startLine = startLine;
70 m_startBand = startBand;
71 }
72
73
78 if(m_rawBuffer) {
79 delete m_rawBuffer;
80 m_rawBuffer = NULL;
82 }
83 }
84
85
89 bool RawCubeChunk::isDirty() const {
90 return m_dirty;
91 }
92
93
100 void RawCubeChunk::setRawData(QByteArray rawData) {
101 if(rawData.size() != m_rawBuffer->size()) {
102 IString msg = "Cannot set raw data on a RawCubeChunk with a differently "
103 "sized data array";
104 throw IException(IException::Programmer, msg, _FILEINFO_);
105 }
106
107 m_dirty = true;
108 *m_rawBuffer = rawData;
110 }
111
112
120 unsigned char RawCubeChunk::getChar(int offset) const {
121 return ((unsigned char *)m_rawBuffer->data())[offset];
122 }
123
132 short RawCubeChunk::getShort(int offset) const {
133 return ((short *)m_rawBuffer->data())[offset];
134 }
135
144 float RawCubeChunk::getFloat(int offset) const {
145 return ((float *)m_rawBuffer->data())[offset];
146 }
147
148
154 if(m_rawBuffer)
155 return m_rawBuffer->size();
156 else
157 return -1;
158 }
159
160
168 void RawCubeChunk::setData(unsigned char value, int offset) {
169
170 m_dirty = true;
171 m_rawBufferInternalPtr[offset] = value;
172 }
173
174
182 void RawCubeChunk::setData(short value, int offset) {
183
184 m_dirty = true;
185 ((short *)m_rawBufferInternalPtr)[offset] = value;
186 }
187
188
196 void RawCubeChunk::setData(const float &value, const int &offset) {
197
198 m_dirty = true;
199 ((float *)m_rawBufferInternalPtr)[offset] = value;
200 }
201
202
209 void RawCubeChunk::setDirty(bool dirty) {
210 m_dirty = dirty;
211 }
212}
213
Represents a 3D area (a 3D "cube")
Definition Area3D.h:29
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
Adds specific functionality to C++ strings.
Definition IString.h:165
int m_lineCount
The number of lines in the cube chunk.
short getShort(int offset) const
int getByteCount() const
QByteArray * m_rawBuffer
This is the raw data to be put on disk.
int m_startBand
The one-based (inclusive) start band of the cube chunk.
bool m_dirty
True if the data does not match what is on disk.
void setData(unsigned char value, int offset)
Sets the char at the given offset in the raw data buffer of this chunk.
void setDirty(bool dirty)
Sets the chunk's dirty flag, indicating whether or not the chunk's data matches the data that is on d...
int m_startLine
The one-based (inclusive) start line of the cube chunk.
char * m_rawBufferInternalPtr
This is the internal pointer to the raw buffer for performance.
int m_bandCount
The number of bands in the cube chunk.
void setRawData(QByteArray rawData)
Sets the chunk's raw data.
RawCubeChunk(const Area3D &placement, int numBytes)
This constructor creates a new cube chunk based on the provided placement and data size.
int m_startSample
The one-based (inclusive) start sample of the cube chunk.
int m_sampleCount
The number of samples in the cube chunk.
float getFloat(int offset) const
bool isDirty() const
unsigned char getChar(int offset) const
This method is currently not in use due to a faster way of getting data from the buffer (through the ...
virtual ~RawCubeChunk()
The destructor.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16