Isis 3 Programmer Reference
Isis::Buffer Class Reference

Buffer for reading and writing cube data. More...

#include <Buffer.h>

Inheritance diagram for Isis::Buffer:
Inheritance graph
Collaboration diagram for Isis::Buffer:
Collaboration graph

Public Member Functions

 Buffer ()
 Default constructor for proper initialization purposes.
 
 Buffer (const int nsamps, const int nlines, const int nbands, const Isis::PixelType type)
 Creates a Buffer object.
 
 ~Buffer ()
 Destroys the Buffer object and frees shape buffer.
 
 Buffer (const Buffer &)
 The copy constructor.
 
Bufferoperator= (const double &d)
 Assign the entire buffer to a constant double value.
 
int SampleDimension () const
 Returns the number of samples in the shape buffer.
 
int LineDimension () const
 Returns the number of lines in the shape buffer.
 
int BandDimension () const
 Returns the number of bands in the shape buffer.
 
int size () const
 Returns the total number of pixels in the shape buffer.
 
int Sample (const int index=0) const
 Returns the sample position associated with a shape buffer index.
 
int Line (const int index=0) const
 Returns the line position associated with a shape buffer index.
 
int Band (const int index=0) const
 Returns the band position associated with a shape buffer index.
 
void Position (const int index, int &i_samp, int &i_line, int &i_band) const
 Returns the sample, line, and band position associated with a shape buffer index.
 
int Index (const int i_samp, const int i_line, const int i_band) const
 Given a sample, line, and band position, this returns the appropriate index in the shape buffer.
 
double at (const int index) const
 Returns the value in the shape buffer at the given index.
 
double & operator[] (const int index)
 Returns the value in the shape buffer at given index.
 
const double & operator[] (const int index) const
 Returns the value in the shape buffer at given index.
 
double * DoubleBuffer () const
 Returns the value of the shape buffer.
 
void Copy (const Buffer &in, bool includeRawBuf=true)
 Allows copying of the buffer contents to another Buffer.
 
bool CopyOverlapFrom (const Buffer &in)
 Allows copying of the buffer contents of a larger buffer to another same size or smaller Buffer, using their base positions to relate data.
 
void * RawBuffer () const
 Returns a void pointer to the raw buffer.
 
Isis::PixelType PixelType () const
 Returns the raw buffer pixel type.
 

Protected Member Functions

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.
 
void SetBaseSample (const int start_samp)
 This method is used to set the base sample position of the shape buffer.
 
void SetBaseLine (const int start_line)
 This method is used to set the base line position of the shape buffer.
 
void SetBaseBand (const int start_band)
 This method is used to set the base band position of the shape buffer.
 
void Allocate ()
 Size or resize the memory buffer.
 
Bufferoperator= (const Buffer &rvalue)
 Copy operator.
 

Protected Attributes

int p_sample
 Starting sample to read/write.
 
int p_nsamps
 Number of samples to read/write.
 
int p_line
 Starting line to read/write.
 
int p_nlines
 Number of lines to read/write.
 
int p_band
 Starting band to read/write.
 
int p_nbands
 Number of bands to read/write.
 
int p_npixels
 Number of pixels (nsamps * nlines * nbands)
 
double * p_buf
 Shape buffer allocated to the size of npixels for handling reads/writes.
 
const Isis::PixelType p_pixelType
 The pixel type of the raw buffer.
 
void * p_rawbuf
 The raw dm read from the disk.
 

Detailed Description

Buffer for reading and writing cube data.

This is the base class for I/O on buffers of data from cubes. The programmer can define an arbitrary shape using this object and then read or write that shape from a cube. Some example shapes are lines, tiles, columns, cublets, and spectral pencils. Data which is read or written to a cube will always be contained within an internal buffer of type double. There are methods for querying the sample/line/band position based upon the buffer index. Note that this class does not read/write data but is used in conjunction with the class to read/write data. Even more powerful are the BufferManager classes which inherit this object and can step through cubes by line, tile, boxcar, column, etc.

If you would like to see Buffer being used in implementation, see circle.cpp

Author
2002-04-09 Kris Becker & Jeff Anderson
History

2003-05-16 Stuart Sides - modified schema from astrogeology...isis.astrogeology

2005-01-16 Jeff Anderson - moved some private methods/variables into protected space

2007-09-05 Kris Becker - Added default constructor for added protection; Added assignment operator for a single value for convenience.

2008-06-25 Noah Hilt - Added some safety measures to the allocate and deconstructor methods to prevent accessing buffers that have not been initialized. Added memory checking to make sure to release any memory if initialized.

2010-06-22 Steven Lambright - "Copy" now ensures pixel types are the same to prevent going out of memory bounds

2012-07-02 Steven Lambright and Stuart Sides - Added "includeRawBuf" to Copy(). We did this to simplify implementation in Cube::copy()... this ought to be usable in many other areas also. References #961.

2012-11-19 Steven Lambright - Added CopyOverlapFrom() for use as a quicker IO than going back to Cube. References #1232.

2017-08-30 Summer Stapleton - Updated documentation. References #4807.

Definition at line 53 of file Buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

Isis::Buffer::Buffer ( )

Default constructor for proper initialization purposes.

This constructor is mostly useless but is needed so that it protects against improper usage.

Definition at line 25 of file Buffer.cpp.

◆ Buffer() [2/3]

Isis::Buffer::Buffer ( const int nsamps,
const int nlines,
const int nbands,
const Isis::PixelType type )

Creates a Buffer object.

Note that the number of pixels in the buffer can not exceed 2GB.

Parameters
nsampsNumber of samples in shape.
nlinesNumber of lines in shape.
nbandsNumber of bands in shape.
typeRaw buffer pixel type
Exceptions
Isis::iException::Programmer- Invalid value for a dimension

Definition at line 41 of file Buffer.cpp.

References Allocate(), p_band, p_line, p_nbands, p_nlines, p_npixels, p_nsamps, p_sample, and Isis::IException::Programmer.

◆ ~Buffer()

Isis::Buffer::~Buffer ( )

Destroys the Buffer object and frees shape buffer.

Definition at line 68 of file Buffer.cpp.

References p_buf, and p_rawbuf.

◆ Buffer() [3/3]

Isis::Buffer::Buffer ( const Buffer & rhs)

The copy constructor.

Allows a new Buffer object to be created using an existing Buffer object.

Parameters
rhsThe Buffer to be used to create the new buffer

Definition at line 320 of file Buffer.cpp.

References Allocate(), Copy(), p_band, p_line, p_npixels, and p_sample.

Member Function Documentation

◆ Allocate()

void Isis::Buffer::Allocate ( )
protected

Size or resize the memory buffer.

Exceptions
Isis::iException::System- Memory allocation failed

Definition at line 340 of file Buffer.cpp.

References Isis::Message::MemoryAllocationFailed(), p_buf, p_npixels, p_pixelType, p_rawbuf, Isis::SizeOf(), and Isis::IException::Unknown.

Referenced by Buffer(), Buffer(), and Isis::Brick::Resize().

◆ at()

double Isis::Buffer::at ( const int index) const

Returns the value in the shape buffer at the given index.

Parameters
indexIndex position in buffer. Out of bounds index is trapped.
Returns
double Buffer value at index
Exceptions
Isis::iException::Programmer- Array Subscript not in range

Definition at line 231 of file Buffer.cpp.

References Isis::Message::ArraySubscriptNotInRange(), p_buf, p_npixels, and Isis::IException::Programmer.

Referenced by Isis::CubeDataThreadTester::BrickChanged(), Isis::ViewportBuffer::fillBuffer(), Isis::CubeDataThreadTester::ReadBrick(), and Isis::CubeDataThreadTester::ReadWriteBrick().

◆ Band()

int Isis::Buffer::Band ( const int index = 0) const

Returns the band position associated with a shape buffer index.

The shape buffer is one dimensional. Let us assume a nsamps=2, nlines=3, and nbands=2. Therefore the total size of the shape buffer is 12 and valid index values are 0-11. Indexes 0-5 will return band 1 and 6-11 will return band 2.

Parameters
indexShape buffer index to map to a band position. Defaults to 0.
Returns
int The absolute band number based on the buffer index.

Definition at line 162 of file Buffer.cpp.

References p_band, p_nlines, and p_nsamps.

Referenced by CopyOverlapFrom(), Position(), and Isis::CubeIoHandler::writeIntoRaw().

◆ BandDimension()

int Isis::Buffer::BandDimension ( ) const
inline

Returns the number of bands in the shape buffer.

Returns
int

Definition at line 88 of file Buffer.h.

References p_nbands.

Referenced by Isis::CubeIoHandler::writeIntoRaw().

◆ Copy()

void Isis::Buffer::Copy ( const Buffer & in,
bool includeRawBuf = true )

Allows copying of the buffer contents to another Buffer.

Parameters
inThe Buffer to be copied.
includeRawBufWhether to include raw dm read from disk
Exceptions
Isis::iException::Programmer- Input and Output buffers are not the same size
Isis::iException::Programmer- Input and Output buffers do not use the same pixel type

Definition at line 255 of file Buffer.cpp.

References p_buf, p_npixels, p_pixelType, p_rawbuf, Isis::IException::Programmer, and Isis::SizeOf().

Referenced by Buffer().

◆ CopyOverlapFrom()

bool Isis::Buffer::CopyOverlapFrom ( const Buffer & in)

Allows copying of the buffer contents of a larger buffer to another same size or smaller Buffer, using their base positions to relate data.

This does not copy the raw buffer.

Parameters
inThe Buffer to be copied.
Returns
The operation was successful (the buffers overlapped)

Definition at line 285 of file Buffer.cpp.

References Band(), Line(), p_band, p_line, p_nbands, p_nlines, p_npixels, p_nsamps, p_sample, Sample(), and size().

◆ DoubleBuffer()

double * Isis::Buffer::DoubleBuffer ( ) const
inline

Returns the value of the shape buffer.

Returns
double* The shape buffer

Definition at line 138 of file Buffer.h.

References p_buf.

Referenced by Isis::AutoReg::ApplyGradientFilter(), Isis::Process::CalculateStatistics(), Isis::Cube::histogram(), Isis::DemShape::localRadius(), Isis::Cube::statistics(), and Isis::CubeIoHandler::writeIntoRaw().

◆ Index()

int Isis::Buffer::Index ( const int i_samp,
const int i_line,
const int i_band ) const

Given a sample, line, and band position, this returns the appropriate index in the shape buffer.

Parameters
i_sampSample position.
i_lineLine position.
i_bandBand position.
Returns
int Index at the specified sample, line and band.
Exceptions
Isis::iException::Programmer- Array Subscript not in range

Definition at line 197 of file Buffer.cpp.

References Isis::Message::ArraySubscriptNotInRange(), p_band, p_line, p_nbands, p_nlines, p_nsamps, p_sample, and Isis::IException::Programmer.

Referenced by Isis::ViewportBuffer::fillBuffer(), and Isis::CubeIoHandler::writeIntoRaw().

◆ Line()

int Isis::Buffer::Line ( const int index = 0) const

Returns the line position associated with a shape buffer index.

The shape buffer is one dimensional. Let us assume a nsamps=2, nlines=3, and nbands=2. Therefore the total size of the shape buffer is 12 and valid index values are 0-11. Line(0), Line(1), Line(6) and Line(7), will return a 1, Line(2), Line(3), Line(8) and Line(9) will return a 2, and Line(4), Line(5), Line(10), and Line(11) will return a 3.

Parameters
indexShape buffer index to map to a line position. Defaults to 0
Returns
int The absolute line number based on the buffer index

Definition at line 145 of file Buffer.cpp.

References p_line, p_nlines, and p_nsamps.

Referenced by CopyOverlapFrom(), Isis::CubeViewport::cubeDataChanged(), Isis::ViewportBuffer::fillBuffer(), Position(), Isis::QtExporter::writeGrayscale(), and Isis::StreamExporter::writeGrayscale().

◆ LineDimension()

int Isis::Buffer::LineDimension ( ) const
inline

Returns the number of lines in the shape buffer.

Returns
int

Definition at line 79 of file Buffer.h.

References p_nlines.

Referenced by Isis::CubeViewport::cubeDataChanged(), and Isis::ViewportBuffer::fillBuffer().

◆ operator=() [1/2]

Buffer & Isis::Buffer::operator= ( const Buffer & rvalue)
inlineprotected

Copy operator.

We will make it private since copies of these buffers do not need to occur.

Parameters
rvalueRight hand side
Returns
Buffer&

Definition at line 224 of file Buffer.h.

◆ operator=() [2/2]

Buffer & Isis::Buffer::operator= ( const double & d)

Assign the entire buffer to a constant double value.

Parameters
dValue to assign to the buffer
Returns
the current Buffer

Definition at line 89 of file Buffer.cpp.

References p_buf, and p_npixels.

◆ operator[]() [1/2]

double & Isis::Buffer::operator[] ( const int index)
inline

Returns the value in the shape buffer at given index.

Parameters
indexIndex position in buffer. No out of bounds index is checked
Returns
double&

Definition at line 118 of file Buffer.h.

References p_buf.

◆ operator[]() [2/2]

const double & Isis::Buffer::operator[] ( const int index) const
inline

Returns the value in the shape buffer at given index.

Parameters
indexIndex position in buffer. No out of bounds index is checked
Returns
double

Definition at line 129 of file Buffer.h.

References p_buf.

◆ PixelType()

Isis::PixelType Isis::Buffer::PixelType ( ) const
inline

Returns the raw buffer pixel type.

Returns
Isis::PixelType

Definition at line 160 of file Buffer.h.

References p_pixelType.

◆ Position()

void Isis::Buffer::Position ( const int index,
int & i_samp,
int & i_line,
int & i_band ) const

Returns the sample, line, and band position associated with a shape buffer index.

Performs the same function as the Sample, Line, and Band methods.

Parameters
indexShape buffer index to map to a band position.
i_sampSample position in shape buffer at index.
i_lineLine position in shape buffer at index
i_bandBand position in shape buffer at index.

Definition at line 177 of file Buffer.cpp.

References Band(), Line(), and Sample().

◆ RawBuffer()

void * Isis::Buffer::RawBuffer ( ) const
inline

Returns a void pointer to the raw buffer.

Cast this void pointer using information from the PixelType() method

Returns
void* Pointer to the raw buffer

Definition at line 151 of file Buffer.h.

References p_rawbuf.

◆ Sample()

int Isis::Buffer::Sample ( const int index = 0) const

Returns the sample position associated with a shape buffer index.

The shape buffer is one dimensional. Let us assume a nsamps=2, nlines=3, and nbands=2. Therefore the total size of the shape buffer is 12 and valid index values are 0-11. Sample(0), Sample(2), Sample(4), etc will return a 1 while Sample(1), Sample(3), Sample(5), etc will return a 2.

Parameters
indexShape buffer index to map to a sample position. Defaults to 0.
Returns
int The absolute sample number based on the buffer index.

Definition at line 127 of file Buffer.cpp.

References p_nsamps, and p_sample.

Referenced by CopyOverlapFrom(), Isis::CubeViewport::cubeDataChanged(), Isis::ViewportBuffer::fillBuffer(), Isis::CubeDataThread::OverlapIndex(), and Position().

◆ SampleDimension()

int Isis::Buffer::SampleDimension ( ) const
inline

Returns the number of samples in the shape buffer.

Returns
int

Definition at line 70 of file Buffer.h.

References p_nsamps.

Referenced by Isis::CubeViewport::cubeDataChanged(), and Isis::ViewportBuffer::fillBuffer().

◆ SetBaseBand()

void Isis::Buffer::SetBaseBand ( const int start_band)
inlineprotected

This method is used to set the base band position of the shape buffer.

Parameters
start_bandStarting band to set

Definition at line 193 of file Buffer.h.

References p_band.

Referenced by Isis::Brick::SetBaseBand(), and SetBasePosition().

◆ SetBaseLine()

void Isis::Buffer::SetBaseLine ( const int start_line)
inlineprotected

This method is used to set the base line position of the shape buffer.

Parameters
start_lineStarting line to set

Definition at line 183 of file Buffer.h.

References p_line.

Referenced by Isis::Brick::SetBaseLine(), and SetBasePosition().

◆ SetBasePosition()

void Isis::Buffer::SetBasePosition ( const int start_sample,
const int start_line,
const int start_band )
protected

This method is used to set the base position of the shape buffer.

In general it is used by BufferManager objects to progress sequentially through a cube by line, tile, boxcar, etc.

Parameters
start_sampleStarting sample to set.
start_lineStarting line to set.
start_bandStarting band to set.

Definition at line 106 of file Buffer.cpp.

References SetBaseBand(), SetBaseLine(), and SetBaseSample().

Referenced by Isis::Brick::SetBasePosition(), Isis::BufferManager::setpos(), and Isis::Portal::SetPosition().

◆ SetBaseSample()

void Isis::Buffer::SetBaseSample ( const int start_samp)
inlineprotected

This method is used to set the base sample position of the shape buffer.

Parameters
start_sampStarting sample to set

Definition at line 173 of file Buffer.h.

References p_sample.

Referenced by SetBasePosition(), and Isis::Brick::SetBaseSample().

◆ size()

Member Data Documentation

◆ p_band

int Isis::Buffer::p_band
protected

Starting band to read/write.

Definition at line 204 of file Buffer.h.

Referenced by Band(), Buffer(), Buffer(), CopyOverlapFrom(), Index(), and SetBaseBand().

◆ p_buf

double* Isis::Buffer::p_buf
protected

Shape buffer allocated to the size of npixels for handling reads/writes.

Definition at line 208 of file Buffer.h.

Referenced by Allocate(), at(), Copy(), DoubleBuffer(), operator=(), operator[](), operator[](), Isis::Brick::Resize(), and ~Buffer().

◆ p_line

int Isis::Buffer::p_line
protected

Starting line to read/write.

Definition at line 201 of file Buffer.h.

Referenced by Buffer(), Buffer(), CopyOverlapFrom(), Index(), Line(), and SetBaseLine().

◆ p_nbands

int Isis::Buffer::p_nbands
protected

Number of bands to read/write.

Definition at line 205 of file Buffer.h.

Referenced by BandDimension(), Buffer(), CopyOverlapFrom(), Index(), and Isis::Brick::Resize().

◆ p_nlines

int Isis::Buffer::p_nlines
protected

Number of lines to read/write.

Definition at line 202 of file Buffer.h.

Referenced by Band(), Buffer(), CopyOverlapFrom(), Index(), Line(), LineDimension(), and Isis::Brick::Resize().

◆ p_npixels

int Isis::Buffer::p_npixels
protected

Number of pixels (nsamps * nlines * nbands)

Definition at line 207 of file Buffer.h.

Referenced by Allocate(), at(), Buffer(), Buffer(), Copy(), CopyOverlapFrom(), operator=(), Isis::Brick::Resize(), and size().

◆ p_nsamps

int Isis::Buffer::p_nsamps
protected

Number of samples to read/write.

Definition at line 199 of file Buffer.h.

Referenced by Band(), Buffer(), CopyOverlapFrom(), Index(), Line(), Isis::Brick::Resize(), Sample(), and SampleDimension().

◆ p_pixelType

const Isis::PixelType Isis::Buffer::p_pixelType
protected

The pixel type of the raw buffer.

Definition at line 211 of file Buffer.h.

Referenced by Allocate(), Copy(), and PixelType().

◆ p_rawbuf

void* Isis::Buffer::p_rawbuf
protected

The raw dm read from the disk.

Definition at line 212 of file Buffer.h.

Referenced by Allocate(), Copy(), RawBuffer(), Isis::Brick::Resize(), and ~Buffer().

◆ p_sample

int Isis::Buffer::p_sample
protected

Starting sample to read/write.

Definition at line 198 of file Buffer.h.

Referenced by Buffer(), Buffer(), CopyOverlapFrom(), Index(), Sample(), and SetBaseSample().


The documentation for this class was generated from the following files: