Isis 3 Programmer Reference
RawCubeChunk.cpp
1 #include "IsisDebug.h"
2 #include "RawCubeChunk.h"
3 
4 #include <cmath>
5 #include <iostream>
6 
7 #include <QByteArray>
8 
9 #include "Area3D.h"
10 #include "Displacement.h"
11 #include "Distance.h"
12 #include "IException.h"
13 #include "IString.h"
14 
15 namespace Isis {
23  RawCubeChunk::RawCubeChunk(const Area3D &placement, int numBytes) {
24  m_dirty = false;
25 
26  m_rawBuffer = new QByteArray(numBytes, '\0');
28 
29  m_sampleCount = (int)round(placement.getWidth().pixels()) + 1;
30  m_lineCount = (int)round(placement.getHeight().pixels()) + 1;
31  m_bandCount = (int)round(placement.getDepth().pixels()) + 1;
32 
33  m_startSample = (int)round(placement.getStartX().pixels());
34  m_startLine = (int)round(placement.getStartY().pixels());
35  m_startBand = (int)round(placement.getStartZ().pixels());
36  }
37 
51  RawCubeChunk::RawCubeChunk(int startSample, int startLine, int startBand,
52  int endSample, int endLine, int endBand,
53  int numBytes) {
54  m_dirty = false;
55 
56  m_rawBuffer = new QByteArray(numBytes, '\0');
58 
59  m_sampleCount = endSample - startSample + 1;
60  m_lineCount = endLine - startLine + 1;
61  m_bandCount = endBand - startBand + 1;
62 
63  m_startSample = startSample;
64  m_startLine = startLine;
65  m_startBand = startBand;
66  }
67 
68 
73  if(m_rawBuffer) {
74  delete m_rawBuffer;
75  m_rawBuffer = NULL;
77  }
78  }
79 
80 
84  bool RawCubeChunk::isDirty() const {
85  return m_dirty;
86  }
87 
88 
95  void RawCubeChunk::setRawData(QByteArray rawData) {
96  if(rawData.size() != m_rawBuffer->size()) {
97  IString msg = "Cannot set raw data on a RawCubeChunk with a differently "
98  "sized data array";
100  }
101 
102  m_dirty = true;
103  *m_rawBuffer = rawData;
105  }
106 
107 
115  unsigned char RawCubeChunk::getChar(int offset) const {
116  return ((unsigned char *)m_rawBuffer->data())[offset];
117  }
118 
127  short RawCubeChunk::getShort(int offset) const {
128  return ((short *)m_rawBuffer->data())[offset];
129  }
130 
139  float RawCubeChunk::getFloat(int offset) const {
140  return ((float *)m_rawBuffer->data())[offset];
141  }
142 
143 
149  if(m_rawBuffer)
150  return m_rawBuffer->size();
151  else
152  return -1;
153  }
154 
155 
163  void RawCubeChunk::setData(unsigned char value, int offset) {
164  ASSERT(offset < getByteCount());
165 
166  m_dirty = true;
167  m_rawBufferInternalPtr[offset] = value;
168  }
169 
170 
178  void RawCubeChunk::setData(short value, int offset) {
179  ASSERT((int)(offset * sizeof(short)) < getByteCount());
180 
181  m_dirty = true;
182  ((short *)m_rawBufferInternalPtr)[offset] = value;
183  }
184 
185 
193  void RawCubeChunk::setData(const float &value, const int &offset) {
194  ASSERT((int)(offset * sizeof(float)) < getByteCount());
195 
196  m_dirty = true;
197  ((float *)m_rawBufferInternalPtr)[offset] = value;
198  }
199 
200 
207  void RawCubeChunk::setDirty(bool dirty) {
208  m_dirty = dirty;
209  }
210 }
211 
void setRawData(QByteArray rawData)
Sets the chunk&#39;s raw data.
float getFloat(int offset) const
char * m_rawBufferInternalPtr
This is the internal pointer to the raw buffer for performance.
Definition: RawCubeChunk.h:137
Represents a 3D area (a 3D "cube")
Definition: Area3D.h:41
int m_bandCount
The number of bands in the cube chunk.
Definition: RawCubeChunk.h:144
QByteArray * m_rawBuffer
This is the raw data to be put on disk.
Definition: RawCubeChunk.h:135
int m_sampleCount
The number of samples in the cube chunk.
Definition: RawCubeChunk.h:140
RawCubeChunk(const Area3D &placement, int numBytes)
This constructor creates a new cube chunk based on the provided placement and data size...
double pixels(double pixelsPerMeter=1.0) const
Get the distance in pixels using the given conversion ratio.
Definition: Distance.cpp:143
Distance getDepth() const
Returns the depth (in the Z dimension) of the 3D area.
Definition: Area3D.cpp:200
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
void setDirty(bool dirty)
Sets the chunk&#39;s dirty flag, indicating whether or not the chunk&#39;s data matches the data that is on d...
void setData(unsigned char value, int offset)
Sets the char at the given offset in the raw data buffer of this chunk.
Displacement getStartX() const
Returns the leftmost X position of the 3D area.
Definition: Area3D.cpp:131
virtual ~RawCubeChunk()
The destructor.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
int m_lineCount
The number of lines in the cube chunk.
Definition: RawCubeChunk.h:142
Distance getWidth() const
Returns the width (in the X dimension) of the 3D area.
Definition: Area3D.cpp:176
Displacement getStartZ() const
Returns the frontmost Z position of the 3D area.
Definition: Area3D.cpp:161
int m_startSample
The one-based (inclusive) start sample of the cube chunk.
Definition: RawCubeChunk.h:147
Distance getHeight() const
Returns the height (in the Y dimension) of the 3D area.
Definition: Area3D.cpp:188
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 ...
double pixels(double pixelsPerMeter=1.0) const
Get the displacement in pixels using the given conversion ratio.
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
bool isDirty() const
int getByteCount() const
int m_startBand
The one-based (inclusive) start band of the cube chunk.
Definition: RawCubeChunk.h:151
short getShort(int offset) const
int m_startLine
The one-based (inclusive) start line of the cube chunk.
Definition: RawCubeChunk.h:149
bool m_dirty
True if the data does not match what is on disk.
Definition: RawCubeChunk.h:132
Displacement getStartY() const
Returns the topmost Y position of the 3D area.
Definition: Area3D.cpp:146