Field3D
DenseField< Data_T > Class Template Reference

This subclass of Field stores data in a contiguous std::vector. More...

#include <DenseField.h>

Inheritance diagram for DenseField< Data_T >:
ResizableField< Data_T > WritableField< Data_T > Field< Data_T > FieldRes FieldBase RefBase

List of all members.

Classes

class  const_iterator
class  iterator

Public Types

typedef ResizableField< Data_T > base
 Convenience typedef for referring to base class.
typedef DenseField< Data_T > class_type
typedef
CubicGenericFieldInterp
< DenseField< Data_T > > 
CubicInterp
typedef
LinearGenericFieldInterp
< DenseField< Data_T > > 
LinearInterp
typedef boost::intrusive_ptr
< DenseField
Ptr
typedef std::vector< PtrVec
 This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInputFile::readVectorLayers() will return its data in.

Public Member Functions

virtual void clear (const Data_T &value)
 Clears all the voxels in the storage.
Data_T & fastLValue (int i, int j, int k)
 Write access to voxel. Notice that this is non-virtual.
const Data_T & fastValue (int i, int j, int k) const
 Read access to voxel. Notice that this is non-virtual.
const FIELD3D_VEC3_T< size_t > & internalMemSize () const
 Returns the internal memory size in each dimension. This is used for example in LinearInterpolator, where it optimizes random access to voxels.
Constructors & destructor
 DenseField ()
 Constructs an empty buffer.
From Field
virtual Data_T value (int i, int j, int k) const
 Read access to a voxel. The coordinates are in integer voxel space .
virtual long long int memSize () const
 Returns the memory usage (in bytes)
From WritableField
virtual Data_T & lvalue (int i, int j, int k)
 Write access to a voxel. The coordinates are global coordinates.
Iterators
const_iterator cbegin () const
 Const iterator to first element. "cbegin" matches the tr1 c++ standard.
const_iterator cbegin (const Box3i &subset) const
 Const iterator to first element of specific subset.
const_iterator cend () const
 Const iterator pointing one element past the last valid one.
const_iterator cend (const Box3i &subset) const
 Const iterator pointing one element past the last valid one (for a subset)
iterator begin ()
 Iterator to first element.
iterator begin (const Box3i &subset)
 Iterator to first element of specific subset.
iterator end ()
 Iterator pointing one element past the last valid one.
iterator end (const Box3i &subset)
 Iterator pointing one element past the last valid one (for a subset)
From FieldBase
virtual std::string className () const
 Returns the class name of the object. Used by the class pool and when writing the data to disk.
virtual FieldBase::Ptr clone () const
 Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement it.

Static Public Member Functions

static const char * classType ()
static
DEFINE_FIELD_RTTI_CONCRETE_CLASS
const char * 
staticClassName ()

Protected Member Functions

virtual void sizeChanged ()
 Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.

Protected Attributes

std::vector< Data_T > m_data
 Field storage.
FIELD3D_VEC3_T< size_t > m_memSize
 Memory allocation size in each dimension.
size_t m_memSizeXY
 X scanline * Y scanline size.

Private Member Functions

Data_T * ptr (int i, int j, int k)
 Returns a pointer to a given element. Used by the iterators mainly.
const Data_T * ptr (int i, int j, int k) const
 Returns a pointer to a given element. Used by the iterators mainly.

Static Private Attributes

static TemplatedFieldType
< DenseField< Data_T > > 
ms_classType

Detailed Description

template<class Data_T>
class DenseField< Data_T >

This subclass of Field stores data in a contiguous std::vector.

Refer to using_fields for examples of how to use this in your code.

Definition at line 82 of file DenseField.h.


Member Typedef Documentation

template<class Data_T>
typedef boost::intrusive_ptr<DenseField> DenseField< Data_T >::Ptr

Reimplemented from ResizableField< Data_T >.

Definition at line 89 of file DenseField.h.

template<class Data_T>
typedef std::vector<Ptr> DenseField< Data_T >::Vec

This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInputFile::readVectorLayers() will return its data in.

Reimplemented from Field< Data_T >.

Definition at line 90 of file DenseField.h.

template<class Data_T>
typedef LinearGenericFieldInterp<DenseField<Data_T> > DenseField< Data_T >::LinearInterp

Definition at line 92 of file DenseField.h.

template<class Data_T>
typedef CubicGenericFieldInterp<DenseField<Data_T> > DenseField< Data_T >::CubicInterp

Definition at line 93 of file DenseField.h.

template<class Data_T>
typedef ResizableField<Data_T> DenseField< Data_T >::base

Convenience typedef for referring to base class.

Reimplemented from ResizableField< Data_T >.

Definition at line 95 of file DenseField.h.

template<class Data_T>
typedef DenseField<Data_T> DenseField< Data_T >::class_type

Reimplemented from ResizableField< Data_T >.

Definition at line 122 of file DenseField.h.


Constructor & Destructor Documentation

template<class Data_T >
DenseField< Data_T >::DenseField ( )

Constructs an empty buffer.

Definition at line 403 of file DenseField.h.

Referenced by DenseField< Data_T >::clone().

  : base(),
    m_memSize(0), m_memSizeXY(0)
{
  // Empty
}

Member Function Documentation

template<class Data_T >
void DenseField< Data_T >::clear ( const Data_T &  value) [virtual]

Clears all the voxels in the storage.

Reimplemented from WritableField< Data_T >.

Definition at line 413 of file DenseField.h.

{
  std::fill(m_data.begin(), m_data.end(), value);
}
template<class Data_T >
Data_T DenseField< Data_T >::value ( int  i,
int  j,
int  k 
) const [virtual]

Read access to a voxel. The coordinates are in integer voxel space .

Note:
Before the internal storage is accessed, the subclass must compute the data window coordinates by looking at Field::m_dataWindow.
Virtual functions are known not to play nice with threading. Therefor, concrete classes can implement (by convention) fastValue() as a non-virtual function.

Implements Field< Data_T >.

Definition at line 421 of file DenseField.h.

{
  return fastValue(i, j, k);
}
template<class Data_T >
long long int DenseField< Data_T >::memSize ( ) const [virtual]

Returns the memory usage (in bytes)

Note:
This needs to be re-implemented for any subclass that adds data members. Those classes should also call their superclass and add the combined memory use.

Reimplemented from FieldRes.

Definition at line 429 of file DenseField.h.

{ 
  long long int superClassMemSize = base::memSize();
  long long int vectorMemSize = m_data.capacity() * sizeof(Data_T);
  return sizeof(*this) + vectorMemSize + superClassMemSize; 
}
template<class Data_T>
static DEFINE_FIELD_RTTI_CONCRETE_CLASS const char* DenseField< Data_T >::staticClassName ( ) [inline, static]

Reimplemented from ResizableField< Data_T >.

Definition at line 125 of file DenseField.h.

Referenced by DenseField< Data_T >::className().

  {
    return "DenseField";
  }
template<class Data_T>
static const char* DenseField< Data_T >::classType ( ) [inline, static]

Reimplemented from ResizableField< Data_T >.

Definition at line 130 of file DenseField.h.

References FieldBase::name.

template<class Data_T >
Data_T & DenseField< Data_T >::lvalue ( int  i,
int  j,
int  k 
) [virtual]

Write access to a voxel. The coordinates are global coordinates.

Note:
Before the internal storage is accessed, the subclass must compute the crop window coordinates by looking at Field::m_dataWindow.
This is named differently from the const value so that non-const objects still have a clear way of accessing data in a const way.
Virtual functions are known not to play nice with threading. Therefor, concrete classes can implement (by convention) fastLValue() as a non-virtual function.

Implements WritableField< Data_T >.

Definition at line 439 of file DenseField.h.

{
  return fastLValue(i, j, k);
}
template<class Data_T >
const Data_T & DenseField< Data_T >::fastValue ( int  i,
int  j,
int  k 
) const

Read access to voxel. Notice that this is non-virtual.

Definition at line 447 of file DenseField.h.

{
  assert (i >= base::m_dataWindow.min.x);
  assert (i <= base::m_dataWindow.max.x);
  assert (j >= base::m_dataWindow.min.y);
  assert (j <= base::m_dataWindow.max.y);
  assert (k >= base::m_dataWindow.min.z);
  assert (k <= base::m_dataWindow.max.z);
  // Add crop window offset
  i -= base::m_dataWindow.min.x;
  j -= base::m_dataWindow.min.y;
  k -= base::m_dataWindow.min.z;
  // Access data
  return m_data[i + j * m_memSize.x + k * m_memSizeXY];
}
template<class Data_T >
Data_T & DenseField< Data_T >::fastLValue ( int  i,
int  j,
int  k 
)

Write access to voxel. Notice that this is non-virtual.

Definition at line 466 of file DenseField.h.

{
  assert (i >= base::m_dataWindow.min.x);
  assert (i <= base::m_dataWindow.max.x);
  assert (j >= base::m_dataWindow.min.y);
  assert (j <= base::m_dataWindow.max.y);
  assert (k >= base::m_dataWindow.min.z);
  assert (k <= base::m_dataWindow.max.z);
  // Add crop window offset
  i -= base::m_dataWindow.min.x;
  j -= base::m_dataWindow.min.y;
  k -= base::m_dataWindow.min.z;
  // Access data
  return m_data[i + j * m_memSize.x + k * m_memSizeXY];
}
template<class Data_T >
DenseField< Data_T >::const_iterator DenseField< Data_T >::cbegin ( ) const

Const iterator to first element. "cbegin" matches the tr1 c++ standard.

Reimplemented from Field< Data_T >.

Definition at line 486 of file DenseField.h.

References FieldRes::dataResolution().

{ 
  if (FieldRes::dataResolution() == V3i(0))
    return cend();
  return const_iterator(*this, base::m_dataWindow, base::m_dataWindow.min); 
}
template<class Data_T >
DenseField< Data_T >::const_iterator DenseField< Data_T >::cbegin ( const Box3i subset) const

Const iterator to first element of specific subset.

Reimplemented from Field< Data_T >.

Definition at line 497 of file DenseField.h.

{ 
  if (subset.isEmpty())
    return cend(subset);
  return const_iterator(*this, subset, subset.min); 
}
template<class Data_T >
DenseField< Data_T >::const_iterator DenseField< Data_T >::cend ( ) const

Const iterator pointing one element past the last valid one.

Reimplemented from Field< Data_T >.

Definition at line 508 of file DenseField.h.

{ 
  return const_iterator(*this, base::m_dataWindow, 
                        V3i(base::m_dataWindow.min.x, 
                            base::m_dataWindow.min.y,
                            base::m_dataWindow.max.z + 1));
}
template<class Data_T >
DenseField< Data_T >::const_iterator DenseField< Data_T >::cend ( const Box3i subset) const

Const iterator pointing one element past the last valid one (for a subset)

Reimplemented from Field< Data_T >.

Definition at line 520 of file DenseField.h.

{ 
  return const_iterator(*this, subset, 
                        V3i(subset.min.x, subset.min.y, subset.max.z + 1));
}
template<class Data_T >
DenseField< Data_T >::iterator DenseField< Data_T >::begin ( )

Iterator to first element.

Reimplemented from WritableField< Data_T >.

Definition at line 530 of file DenseField.h.

References FieldRes::dataResolution().

Referenced by DenseFieldIO::readData(), and DenseFieldIO::writeData().

{ 
  if (FieldRes::dataResolution() == V3i(0))
    return end();
  return iterator(*this, base::m_dataWindow, base::m_dataWindow.min); }
template<class Data_T >
DenseField< Data_T >::iterator DenseField< Data_T >::begin ( const Box3i subset)

Iterator to first element of specific subset.

Reimplemented from WritableField< Data_T >.

Definition at line 540 of file DenseField.h.

{ 
  if (subset.isEmpty())
    return end(subset);
  return iterator(*this, subset, subset.min); 
}
template<class Data_T >
DenseField< Data_T >::iterator DenseField< Data_T >::end ( )

Iterator pointing one element past the last valid one.

Reimplemented from WritableField< Data_T >.

Definition at line 551 of file DenseField.h.

{ 
  return iterator(*this, base::m_dataWindow, 
                  V3i(base::m_dataWindow.min.x, 
                      base::m_dataWindow.min.y,
                      base::m_dataWindow.max.z + 1));
}
template<class Data_T >
DenseField< Data_T >::iterator DenseField< Data_T >::end ( const Box3i subset)

Iterator pointing one element past the last valid one (for a subset)

Reimplemented from WritableField< Data_T >.

Definition at line 563 of file DenseField.h.

{ 
  return iterator(*this, subset, 
                  V3i(subset.min.x, subset.min.y, subset.max.z + 1));
}
template<class Data_T>
const FIELD3D_VEC3_T<size_t>& DenseField< Data_T >::internalMemSize ( ) const [inline]

Returns the internal memory size in each dimension. This is used for example in LinearInterpolator, where it optimizes random access to voxels.

Definition at line 186 of file DenseField.h.

References DenseField< Data_T >::m_memSize.

Referenced by DenseFieldIO::writeInternal().

  { return m_memSize; }
template<class Data_T>
virtual std::string DenseField< Data_T >::className ( ) const [inline, virtual]

Returns the class name of the object. Used by the class pool and when writing the data to disk.

Note:
This is different from classType for any templated class, as classType() will include the template parameter(s) but className remains just the name of the template itself.

Implements FieldBase.

Definition at line 194 of file DenseField.h.

References DenseField< Data_T >::staticClassName().

  { return staticClassName(); }
template<class Data_T>
virtual FieldBase::Ptr DenseField< Data_T >::clone ( ) const [inline, virtual]

Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement it.

Implements FieldBase.

Definition at line 197 of file DenseField.h.

References DenseField< Data_T >::DenseField().

  { return Ptr(new DenseField(*this)); }
template<class Data_T >
void DenseField< Data_T >::sizeChanged ( ) [protected, virtual]

Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.

Note:
Make sure to call the base class version in subclasses!

Reimplemented from ResizableField< Data_T >.

Definition at line 572 of file DenseField.h.

{
  // Call base class
  base::sizeChanged();

  // Calculate offsets
  m_memSize = base::m_dataWindow.max - base::m_dataWindow.min + V3i(1);
  m_memSizeXY = m_memSize.x * m_memSize.y;

  // Check that mem size is >= 0 in all dimensions
  if (base::m_dataWindow.max.x < base::m_dataWindow.min.x ||
      base::m_dataWindow.max.y < base::m_dataWindow.min.y ||
      base::m_dataWindow.max.z < base::m_dataWindow.min.z)
    throw Exc::ResizeException("Attempt to resize ResizableField object "
                               "using negative size. Data window was: " +
                               boost::lexical_cast<std::string>(
                                 base::m_dataWindow.min) + " - " +
                               boost::lexical_cast<std::string>(
                                 base::m_dataWindow.max));

  // Allocate memory
  try {
    std::vector<Data_T>().swap(m_data);
    m_data.resize(m_memSize.x * m_memSize.y * m_memSize.z);
  }
  catch (std::bad_alloc &e) {
    throw Exc::MemoryException("Couldn't allocate DenseField of size " + 
                               boost::lexical_cast<std::string>(m_memSize));
  }
}
template<class Data_T >
Data_T * DenseField< Data_T >::ptr ( int  i,
int  j,
int  k 
) [inline, private]

Returns a pointer to a given element. Used by the iterators mainly.

Definition at line 606 of file DenseField.h.

{
  // Add crop window offset
  i -= base::m_dataWindow.min.x;
  j -= base::m_dataWindow.min.y;
  k -= base::m_dataWindow.min.z;
  // Access data
  return &m_data[i + j * m_memSize.x + k * m_memSizeXY];      
}
template<class Data_T >
const Data_T * DenseField< Data_T >::ptr ( int  i,
int  j,
int  k 
) const [inline, private]

Returns a pointer to a given element. Used by the iterators mainly.

Definition at line 619 of file DenseField.h.

{
  // Add crop window offset
  i -= base::m_dataWindow.min.x;
  j -= base::m_dataWindow.min.y;
  k -= base::m_dataWindow.min.z;
  // Access data
  return &m_data[i + j * m_memSize.x + k * m_memSizeXY];
}

Member Data Documentation

template<class Data_T>
FIELD3D_VEC3_T<size_t> DenseField< Data_T >::m_memSize [protected]

Memory allocation size in each dimension.

Definition at line 211 of file DenseField.h.

Referenced by DenseField< Data_T >::internalMemSize().

template<class Data_T>
size_t DenseField< Data_T >::m_memSizeXY [protected]

X scanline * Y scanline size.

Definition at line 213 of file DenseField.h.

template<class Data_T>
std::vector<Data_T> DenseField< Data_T >::m_data [protected]

Field storage.

Definition at line 215 of file DenseField.h.

template<class Data_T>
TemplatedFieldType<DenseField<Data_T> > DenseField< Data_T >::ms_classType [static, private]

Reimplemented from ResizableField< Data_T >.

Definition at line 221 of file DenseField.h.


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