Isis 3 Programmer Reference
RawCubeChunk.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "IsisDebug.h"
8 #include "RawCubeChunk.h"
9 
10 #include <cmath>
11 #include <iostream>
12 
13 #include <QByteArray>
14 
15 #include "Area3D.h"
16 #include "Displacement.h"
17 #include "Distance.h"
18 #include "IException.h"
19 #include "IString.h"
20 
21 namespace Isis {
29  RawCubeChunk::RawCubeChunk(const Area3D &placement, int numBytes) {
30  m_dirty = false;
31 
32  m_rawBuffer = new QByteArray(numBytes, '\0');
34 
35  m_sampleCount = (int)round(placement.getWidth().pixels()) + 1;
36  m_lineCount = (int)round(placement.getHeight().pixels()) + 1;
37  m_bandCount = (int)round(placement.getDepth().pixels()) + 1;
38 
39  m_startSample = (int)round(placement.getStartX().pixels());
40  m_startLine = (int)round(placement.getStartY().pixels());
41  m_startBand = (int)round(placement.getStartZ().pixels());
42  }
43 
57  RawCubeChunk::RawCubeChunk(int startSample, int startLine, int startBand,
58  int endSample, int endLine, int endBand,
59  int numBytes) {
60  m_dirty = false;
61 
62  m_rawBuffer = new QByteArray(numBytes, '\0');
64 
65  m_sampleCount = endSample - startSample + 1;
66  m_lineCount = endLine - startLine + 1;
67  m_bandCount = endBand - startBand + 1;
68 
69  m_startSample = startSample;
70  m_startLine = startLine;
71  m_startBand = startBand;
72  }
73 
74 
79  if(m_rawBuffer) {
80  delete m_rawBuffer;
81  m_rawBuffer = NULL;
83  }
84  }
85 
86 
90  bool RawCubeChunk::isDirty() const {
91  return m_dirty;
92  }
93 
94 
101  void RawCubeChunk::setRawData(QByteArray rawData) {
102  if(rawData.size() != m_rawBuffer->size()) {
103  IString msg = "Cannot set raw data on a RawCubeChunk with a differently "
104  "sized data array";
105  throw IException(IException::Programmer, msg, _FILEINFO_);
106  }
107 
108  m_dirty = true;
109  *m_rawBuffer = rawData;
111  }
112 
113 
121  unsigned char RawCubeChunk::getChar(int offset) const {
122  return ((unsigned char *)m_rawBuffer->data())[offset];
123  }
124 
133  short RawCubeChunk::getShort(int offset) const {
134  return ((short *)m_rawBuffer->data())[offset];
135  }
136 
145  float RawCubeChunk::getFloat(int offset) const {
146  return ((float *)m_rawBuffer->data())[offset];
147  }
148 
149 
155  if(m_rawBuffer)
156  return m_rawBuffer->size();
157  else
158  return -1;
159  }
160 
161 
169  void RawCubeChunk::setData(unsigned char value, int offset) {
170  ASSERT(offset < getByteCount());
171 
172  m_dirty = true;
173  m_rawBufferInternalPtr[offset] = value;
174  }
175 
176 
184  void RawCubeChunk::setData(short value, int offset) {
185  ASSERT((int)(offset * sizeof(short)) < getByteCount());
186 
187  m_dirty = true;
188  ((short *)m_rawBufferInternalPtr)[offset] = value;
189  }
190 
191 
199  void RawCubeChunk::setData(const float &value, const int &offset) {
200  ASSERT((int)(offset * sizeof(float)) < getByteCount());
201 
202  m_dirty = true;
203  ((float *)m_rawBufferInternalPtr)[offset] = value;
204  }
205 
206 
213  void RawCubeChunk::setDirty(bool dirty) {
214  m_dirty = dirty;
215  }
216 }
217 
Isis::RawCubeChunk::setDirty
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...
Definition: RawCubeChunk.cpp:213
Isis::RawCubeChunk::m_dirty
bool m_dirty
True if the data does not match what is on disk.
Definition: RawCubeChunk.h:117
Isis::RawCubeChunk::m_rawBufferInternalPtr
char * m_rawBufferInternalPtr
This is the internal pointer to the raw buffer for performance.
Definition: RawCubeChunk.h:122
Isis::RawCubeChunk::getFloat
float getFloat(int offset) const
Definition: RawCubeChunk.cpp:145
Isis::RawCubeChunk::m_startBand
int m_startBand
The one-based (inclusive) start band of the cube chunk.
Definition: RawCubeChunk.h:136
Isis::RawCubeChunk::isDirty
bool isDirty() const
Definition: RawCubeChunk.cpp:90
Isis::RawCubeChunk::m_bandCount
int m_bandCount
The number of bands in the cube chunk.
Definition: RawCubeChunk.h:129
Isis::RawCubeChunk::RawCubeChunk
RawCubeChunk(const Area3D &placement, int numBytes)
This constructor creates a new cube chunk based on the provided placement and data size.
Definition: RawCubeChunk.cpp:29
Isis::Area3D::getDepth
Distance getDepth() const
Returns the depth (in the Z dimension) of the 3D area.
Definition: Area3D.cpp:184
Isis::RawCubeChunk::m_startLine
int m_startLine
The one-based (inclusive) start line of the cube chunk.
Definition: RawCubeChunk.h:134
Isis::RawCubeChunk::m_startSample
int m_startSample
The one-based (inclusive) start sample of the cube chunk.
Definition: RawCubeChunk.h:132
Isis::RawCubeChunk::m_sampleCount
int m_sampleCount
The number of samples in the cube chunk.
Definition: RawCubeChunk.h:125
Isis::RawCubeChunk::getShort
short getShort(int offset) const
Definition: RawCubeChunk.cpp:133
Isis::Area3D::getStartX
Displacement getStartX() const
Returns the leftmost X position of the 3D area.
Definition: Area3D.cpp:115
Isis::RawCubeChunk::m_rawBuffer
QByteArray * m_rawBuffer
This is the raw data to be put on disk.
Definition: RawCubeChunk.h:120
Isis::RawCubeChunk::getByteCount
int getByteCount() const
Definition: RawCubeChunk.cpp:154
Isis::RawCubeChunk::m_lineCount
int m_lineCount
The number of lines in the cube chunk.
Definition: RawCubeChunk.h:127
Isis::RawCubeChunk::~RawCubeChunk
virtual ~RawCubeChunk()
The destructor.
Definition: RawCubeChunk.cpp:78
Isis::Area3D::getStartZ
Displacement getStartZ() const
Returns the frontmost Z position of the 3D area.
Definition: Area3D.cpp:145
Isis::Area3D::getWidth
Distance getWidth() const
Returns the width (in the X dimension) of the 3D area.
Definition: Area3D.cpp:160
Isis::RawCubeChunk::setData
void setData(unsigned char value, int offset)
Sets the char at the given offset in the raw data buffer of this chunk.
Definition: RawCubeChunk.cpp:169
Isis::Displacement::pixels
double pixels(double pixelsPerMeter=1.0) const
Get the displacement in pixels using the given conversion ratio.
Definition: Displacement.cpp:117
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::RawCubeChunk::setRawData
void setRawData(QByteArray rawData)
Sets the chunk's raw data.
Definition: RawCubeChunk.cpp:101
Isis::Area3D::getHeight
Distance getHeight() const
Returns the height (in the Y dimension) of the 3D area.
Definition: Area3D.cpp:172
Isis::RawCubeChunk::getChar
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 ...
Definition: RawCubeChunk.cpp:121
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::Area3D
Represents a 3D area (a 3D "cube")
Definition: Area3D.h:29
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::Distance::pixels
double pixels(double pixelsPerMeter=1.0) const
Get the distance in pixels using the given conversion ratio.
Definition: Distance.cpp:131
Isis::Area3D::getStartY
Displacement getStartY() const
Returns the topmost Y position of the 3D area.
Definition: Area3D.cpp:130
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16