MIPField< Field_T > Class Template Reference
Fields

This subclass stores a MIP representation of a Field_T field. More...

`#include <MIPField.h>`

Inheritance diagram for MIPField< Field_T >:

## Public Types

typedef MIPField< Field_T > | class_type
typedef CubicMIPFieldInterp< Data_T > | CubicInterp
typedef Field_T::value_type | Data_T
typedef Field_T::Ptr | FieldPtr
typedef std::vector< FieldPtr > | FieldVec
typedef MIPLinearInterp< MIPField< Field_T > > | LinearInterp
typedef Field_T | NestedType
typedef EmptyField< Data_T > | ProxyField
typedef ProxyField::Ptr | ProxyPtr
typedef std::vector< ProxyPtr > | ProxyVec
typedef boost::intrusive_ptr< MIPField > | Ptr
typedef Data_T | value_type
typedef std::vector< Ptr > | Vec
Public Types inherited from MIPBase< Field_T::value_type >
typedef MIPBase< Field_T::value_type > | class_type
typedef boost::intrusive_ptr< MIPBase > | Ptr
Public Types inherited from Field< Field_T::value_type >
typedef Field< Field_T::value_type > | class_type
typedef boost::intrusive_ptr< Field > | Ptr
typedef Field_T::value_type | value_type
| Allows us to reference the template class.
typedef std::vector< Ptr > | Vec
| This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInputFile::readVectorLayers() will return its data in.
Public Types inherited from FieldRes
typedef FieldRes | class_type
typedef boost::intrusive_ptr< FieldRes > | Ptr
typedef std::vector< Ptr > | Vec
Public Types inherited from FieldBase
typedef FieldBase | class_type
typedef boost::intrusive_ptr< FieldBase > | Ptr
Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBase > | Ptr
typedef boost::weak_ptr< RefBase > | WeakPtr

## Public Member Functions

void | clear ()
| Clears all the levels of the MIP field.
Field_T::Ptr | concreteMipLevel (const size_t level) const
| Returns a concretely typed pointer to a MIP level.
Data_T | fastMipValue (size_t level, int i, int j, int k) const
| Read access to voxel at a given MIP level.
virtual void | getVsMIPCoord (const V3f &vsP, const size_t level, V3f &outVsP) const
| Given a voxel space coordinate in the 0-level field, computes the coordinate in another level.
virtual bool | levelLoaded (const size_t level) const
| Whether a given MIP level is loaded.
virtual Field< Data_T >::Ptr | mipLevel (const size_t level) const
| Returns a MIP level field.
virtual V3i | mipResolution (size_t level) const
| Returns the resolution of a given MIP level.
virtual Data_T | mipValue (size_t level, int i, int j, int k) const
| Read access to a voxel in a given MIP level.
const Field_T * | rawMipLevel (const size_t level) const
| Returns a raw pointer to a MIP level.
void | setup (const FieldVec &fields)
| Sets up the MIP field given a set of non-MIP fields This call performs sanity checking to ensure that MIP properties are satisfied for each level. In this case, all MIP levels are available in memory.
void | setupLazyLoad (const ProxyVec &proxies, const typename LazyLoadAction< Field_T >::Vec &actions)
| Sets up the MIP field in lazy-load mode.
Constructors & destructor
| MIPField ()
| Constructs an empty MIP field.
| MIPField (const MIPField &other)
| Copy constructor. We need this because a) we own a mutex and b) we own shared pointers and shallow copies are not good enough.
const MIPField & | operator= (const MIPField &rhs)
| Assignment operator.
From FieldRes
Returns -current- memory use, rather than the amount used if all levels were loaded.
virtual long long int | memSize () const
| Returns the memory usage (in bytes).
virtual void | mappingChanged ()
| We need to know if the mapping changed so that we may update the MIP levels' mappings.
From Field
For a MIP field, the common value() call accesses data at level 0 only.
virtual Data_T | value (int i, int j, int k) const
| Read access to a voxel. The coordinates are in integer voxel space .
virtual size_t | voxelCount () const
| Counts the number of voxels. For most fields, this is just the volume of the data window, but sparse data structures can override this to return a better value.
Public Member Functions inherited from MIPBase< Field_T::value_type >
size_t | lowestLevel () const
| Lowest MIP level to use.
| MIPBase ()
const V3i & | mipOffset () const
| Returns the base MIP offset.
size_t | numLevels () const
| Number of MIP levels.
void | setLowestLevel (size_t level)
| Sets the lowest MIP level to use. Defaults to zero, but can be set higher to prevent high resolution levels from being accessed.
void | setMIPOffset (const V3i &offset)
| Sets the base MIP offset. This is used to indicate where voxel space coordinate (0, 0, 0) really maps to.
Public Member Functions inherited from Field< Field_T::value_type >
const_iterator | cbegin () const
| Const iterator to first element. "cbegin" matches the tr1 c++ standard.
const_iterator | cend () const
| Const iterator pointing one element past the last valid one.
virtual std::string | dataTypeString () const
virtual | ~Field ()
| Dtor.
Public Member Functions inherited from FieldRes
V3i const | dataResolution () const
const Box3i & | dataWindow () const
| Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field subclass.
const Box3i & | extents () const
| Returns the extents of the data. This signifies the relevant area that the data exists over. However, the data window (below) may be smaller than the extents, in which case it is only safe to call value() for those coordinate inside the data window.
| FieldRes ()
| This constructor ensures that we have a valid mapping at all times.
| FieldRes (const FieldRes &src)
| Base class copy constructor.
bool | isInBounds (int i, int j, int k) const
| Returns true is the indicies are in bounds of the data window.
FieldMapping::Ptr | mapping ()
| Returns a pointer to the mapping.
const FieldMapping::Ptr | mapping () const
| Returns a pointer to the mapping.
void | setMapping (FieldMapping::Ptr mapping)
| Sets the field's mapping.
Public Member Functions inherited from FieldBase
| FieldBase ()
| Constructor.
| FieldBase (const FieldBase &)
| Copy Constructor.
virtual | ~FieldBase ()
| Destructor.
virtual std::string | className () const =0
| Returns the class name of the object. Used by the class pool and when writing the data to disk.
virtual std::string | classType () const =0
| Returns the full class type string.
FieldMetadata & | metadata ()
| accessor to the m_metadata class
const FieldMetadata & | metadata () const
| Read only access to the m_metadata class.
void | copyMetadata (const FieldBase &field)
| Copies the metadata from a second field.
Public Member Functions inherited from RefBase
void | ref () const
| Used by boost::intrusive_pointer.
size_t | refcnt ()
| Used by boost::intrusive_pointer.
void | unref () const
| Used by boost::intrusive_pointer.
WeakPtr | weakPtr () const
| RefBase ()
| RefBase (const RefBase &)
| Copy constructor.
RefBase & | operator= (const RefBase &)
| Assignment operator.
virtual | ~RefBase ()
| Destructor.
virtual bool | checkRTTI (const char *typenameStr)=0
| This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();.
bool | matchRTTI (const char *typenameStr)
| Performs a check to see if the given typename string matches this class' This needs to be implemented in -all- subclasses, even abstract ones.
Public Member Functions inherited from MetadataCallback
virtual void | metadataHasChanged (const std::string &)
| Alerts the callback holder that the metadata has changed.

## Static Public Member Functions

static DEFINE_FIELD_RTTI_CONCRETE_CLASS const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from MIPBase< Field_T::value_type >
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from Field< Field_T::value_type >
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from FieldRes
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from FieldBase
static const char * | staticClassName ()
static const char * | staticClassType ()
static const char * | staticClassType ()

## Protected Types

typedef MIPBase< Data_T > | base
Protected Types inherited from MIPBase< Field_T::value_type >
typedef Field< Field_T::value_type > | base
Protected Types inherited from FieldRes
typedef MatrixFieldMapping | default_mapping

## Protected Member Functions

const MIPField & | init (const MIPField &rhs)
| Copies from a second MIPField.
void | loadLevelFromDisk (size_t level) const
| Loads the given level from disk.
template<typename T>
void | sanityChecks (const T &fields)
| Sanity checks to ensure that the provided Fields are a MIP representation.
void | syncLevelInfo (const size_t level) const
| Updates the name, attribute and metadata for a given level.
void | updateAuxMembers () const
| Updates the dependent data members based on m_field.
void | updateMapping (FieldRes::Ptr field)
| Updates the mapping, extents and data window to match the given field. Used so that the MIPField will appear to have the same mapping in space as the level-0 field.

## Protected Attributes

std::vector< FieldPtr > | m_fields
| Storage of all MIP levels. Some or all of the pointers may be NULL. This is mutable because it needs updating during lazy loading of data.
boost::shared_ptr< boost::mutex > | m_ioMutex
| Mutex lock around IO. Used to make sure only one thread reads MIP level data at a time. When a field is cloned, the two new fields will share the mutex, since they point to the same file.
LazyLoadAction< Field_T >::Vec | m_loadActions
| Lazy load actions. Only used if setupLazyLoad() has been called.
std::vector< V3i > | m_mipRes
| Resolution of each MIP level.
std::vector< Field_T * > | m_rawFields
| Raw pointers to MIP levels.
std::vector< V3f > | m_relativeResolution
| Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Protected Attributes inherited from MIPBase< Field_T::value_type >
size_t | m_lowestLevel
| The lowest MIP level to use. Defaults to 0, but can be set higher to prevent high resolution levels from being accessed.
V3i | m_mipOffset
| Base coordinate offset. This is used to indicate where voxel space coordinate (0, 0, 0) really maps to.
size_t | m_numLevels
| Number of MIP levels. The default is 1.
Protected Attributes inherited from FieldRes
Box3i | m_dataWindow
| Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Box3i | m_extents
| Defines the extents of the the storage. This may be larger or smaller than the data window, and in the case where it is larger, care must be taken not to access voxels outside the data window. This should be treated as a closed (i.e. inclusive) interval.
FieldMapping::Ptr | m_mapping
| Pointer to the field's mapping.

## Static Protected Attributes

static NestedFieldType< MIPField< Field_T > > | ms_classType
Static Protected Attributes inherited from MIPBase< Field_T::value_type >
static TemplatedFieldType< MIPBase< Field_T::value_type > > | ms_classType

## From FieldBase

| FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
virtual FieldBase::Ptr | clone () const
| Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement it.

## Additional Inherited Members

Public Attributes inherited from MIPBase< Field_T::value_type >
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from Field< Field_T::value_type >
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from FieldRes
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from FieldBase
std::string | attribute
| Optional name of the attribute the field represents.
std::string | name
| Optional name of the field.

## Detailed Description

template<class Field_T>
class MIPField< Field_T >

This subclass stores a MIP representation of a Field_T field.

Each level in the MIPField is stored as a SparseField, and each level shares the same FieldMapping definition, even though their resolution is different.

The class is lazy loading, such that no MIP levels are read from disk until they are needed. On top of this, standard SparseField caching (memory limiting) is available, and operates the same as normal SparseFields.

The class is thread safe, and ensures that data is read from disk from in one single thread, using the double-checked locking mechanism.

Interpolation into a MIP field may be done either directly to a single level, or by blending between two MIP levels. When blending, each field is assumed to match the other levels only in local-space.

Definition at line 109 of file MIPField.h.

## Member Typedef Documentation

## Data_T

template<class Field_T>

typedef Field_T::value_type MIPField< Field_T >::Data_T

Definition at line 115 of file MIPField.h.

## NestedType

template<class Field_T>

typedef Field_T MIPField< Field_T >::NestedType

Definition at line 116 of file MIPField.h.

## Ptr

template<class Field_T>

typedef boost::intrusive_ptr<MIPField> MIPField< Field_T >::Ptr

Definition at line 118 of file MIPField.h.

## Vec

template<class Field_T>

typedef std::vector<Ptr> MIPField< Field_T >::Vec

Definition at line 119 of file MIPField.h.

## LinearInterp

template<class Field_T>

typedef MIPLinearInterp<MIPField<Field_T> > MIPField< Field_T >::LinearInterp

Definition at line 121 of file MIPField.h.

## CubicInterp

template<class Field_T>

typedef CubicMIPFieldInterp<Data_T> MIPField< Field_T >::CubicInterp

Definition at line 122 of file MIPField.h.

## value_type

template<class Field_T>

typedef Data_T MIPField< Field_T >::value_type

Definition at line 124 of file MIPField.h.

## ProxyField

template<class Field_T>

typedef EmptyField<Data_T> MIPField< Field_T >::ProxyField

Definition at line 126 of file MIPField.h.

## ProxyPtr

template<class Field_T>

typedef ProxyField::Ptr MIPField< Field_T >::ProxyPtr

Definition at line 127 of file MIPField.h.

## ProxyVec

template<class Field_T>

typedef std::vector<ProxyPtr> MIPField< Field_T >::ProxyVec

Definition at line 128 of file MIPField.h.

## FieldPtr

template<class Field_T>

typedef Field_T::Ptr MIPField< Field_T >::FieldPtr

Definition at line 130 of file MIPField.h.

## FieldVec

template<class Field_T>

typedef std::vector<FieldPtr> MIPField< Field_T >::FieldVec

Definition at line 131 of file MIPField.h.

## class_type

template<class Field_T>

typedef MIPField<Field_T> MIPField< Field_T >::class_type

Definition at line 173 of file MIPField.h.

## base

template<class Field_T>

typedef MIPBase<Data_T> MIPField< Field_T >::base

protected

Definition at line 242 of file MIPField.h.

## Constructor & Destructor Documentation

## MIPField() [1/2]

template<class Field_T>

MIPField< Field_T >::MIPField | ( |  | ) |

Constructs an empty MIP field.

Definition at line 324 of file MIPField.h.

: base(),
m_ioMutex(new boost::mutex)
{
m_fields.resize(base::m_numLevels);
}
MIPBase::m_numLevels
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition MIPBase.h:196
MIPField
This subclass stores a MIP representation of a Field_T field.
Definition MIPField.h:110
MIPField::m_ioMutex
boost::shared_ptr< boost::mutex > m_ioMutex
Mutex lock around IO. Used to make sure only one thread reads MIP level data at a time....
Definition MIPField.h:271
MIPField::base
MIPBase< Data_T > base
Definition MIPField.h:242
MIPField::m_fields
std::vector< FieldPtr > m_fields
Storage of all MIP levels. Some or all of the pointers may be NULL. This is mutable because it needs ...
Definition MIPField.h:256

References m_fields, m_ioMutex, and MIPBase< Data_T >::m_numLevels.

Referenced by clone(), init(), MIPField(), and operator=().

## MIPField() [2/2]

template<class Field_T>

MIPField< Field_T >::MIPField | ( | const MIPField< Field_T > & | other | ) |

Copy constructor. We need this because a) we own a mutex and b) we own shared pointers and shallow copies are not good enough.

Definition at line 334 of file MIPField.h.

: base(other)
{
init(other);
}
MIPField::init
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
Definition MIPField.h:354

References init(), and MIPField().

## Member Function Documentation

## operator=()

template<class Field_T>

const MIPField< Field_T > & MIPField< Field_T >::operator= | ( | const MIPField< Field_T > & | rhs | ) |

Assignment operator.

Definition at line 344 of file MIPField.h.

{
base::operator=(rhs);
return init(rhs);
}
RefBase::operator=
RefBase & operator=(const RefBase &)
Assignment operator.
Definition RefCount.h:134

References init(), MIPField(), and RefBase::operator=().

## memSize()

template<class Field_T>

long long int MIPField< Field_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 534 of file MIPField.h.

{
long long int mem = 0;
for (size_t i = 0; i < m_fields.size(); i++) {
if (m_fields[i]) {
mem += m_fields[i]->memSize();
}
}
return mem + sizeof(*this);
}

References m_fields.

## mappingChanged()

template<class Field_T>

void MIPField< Field_T >::mappingChanged | ( |  | ) |

virtual

We need to know if the mapping changed so that we may update the MIP levels' mappings.

Reimplemented from FieldRes.

Definition at line 548 of file MIPField.h.

{
// Update MIP offset
const V3i offset =
base::metadata().vecIntMetadata(detail::k_mipOffsetStr, V3i(0));
base::setMIPOffset(offset);
V3i baseRes = base::dataWindow().size() + V3i(1);
if (m_fields[0]) {
m_fields[0]->setMapping(base::mapping());
}
for (size_t i = 1; i < m_fields.size(); i++) {
if (m_fields[i]) {
FieldMapping::Ptr mapping =
detail::adjustedMIPFieldMapping(this, baseRes,
m_fields[i]->extents(), i);
m_fields[i]->setMapping(mapping);
}
}
}
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
FieldBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field.h:155
FieldMetadata::vecIntMetadata
V3i vecIntMetadata(const std::string &name, const V3i &defaultVal) const
Tries to retrieve a V3i metadata value. Returns the specified default value if no metadata was found.
Definition FieldMetadata.cpp:143
FieldRes::mapping
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition Field.h:263
FieldRes::extents
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over....
Definition Field.h:249
FieldRes::dataWindow
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
Definition Field.h:253
MIPBase::setMIPOffset
void setMIPOffset(const V3i &offset)
Sets the base MIP offset. This is used to indicate where voxel space coordinate (0,...
Definition MIPBase.h:230
detail::adjustedMIPFieldMapping
FIELD3D_API FieldMapping::Ptr adjustedMIPFieldMapping(const FieldRes *base, const V3i &baseRes, const Box3i &extents, const size_t level)
Definition MIPUtil.cpp:82

References detail::adjustedMIPFieldMapping(), FieldRes::dataWindow(), FieldRes::extents(), detail::k_mipOffsetStr, m_fields, FieldRes::mapping(), FieldBase::metadata(), and MIPBase< Data_T >::setMIPOffset().

## value()

template<class Field_T>

MIPField< Field_T >::Data_T MIPField< Field_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< Field_T::value_type >.

Definition at line 511 of file MIPField.h.

{
return fastMipValue(0, i, j, k);
}
MIPField::fastMipValue
Data_T fastMipValue(size_t level, int i, int j, int k) const
Read access to voxel at a given MIP level.
Definition MIPField.h:636

References fastMipValue().

## voxelCount()

template<class Field_T>

size_t MIPField< Field_T >::voxelCount | ( |  | ) | const

virtual

Counts the number of voxels. For most fields, this is just the volume of the data window, but sparse data structures can override this to return a better value.

Reimplemented from FieldRes.

Definition at line 520 of file MIPField.h.

{
size_t count = 0;
for (size_t i = 0; i < m_fields.size(); i++) {
if (m_fields[i]) {
count += m_fields[i]->voxelCount();
}
}
return count;
}

References m_fields.

## staticClassName()

template<class Field_T>

DEFINE_FIELD_RTTI_CONCRETE_CLASS const char * MIPField< Field_T >::staticClassName | ( |  | ) |

inline static

Definition at line 176 of file MIPField.h.

{
return "MIPField";
}

## staticClassType()

template<class Field_T>

const char * MIPField< Field_T >::staticClassType | ( |  | ) |

inline static

Definition at line 181 of file MIPField.h.

{
return MIPField<Field_T>::ms_classType.name();
}
FieldBase::name
std::string name
Optional name of the field.
Definition Field.h:171

References ms_classType.

## mipValue()

template<class Field_T>

MIPField< Field_T >::Data_T MIPField< Field_T >::mipValue | ( | size_t | level,
|  | int | i,
|  | int | j,
|  | int | k ) const

virtual

Read access to a voxel in a given MIP level.

Parameters

  level | The MIP level to read from

Implements MIPBase< Field_T::value_type >.

Definition at line 573 of file MIPField.h.

{
return fastMipValue(level, i, j, k);
}

References fastMipValue().

## mipResolution()

template<class Field_T>

V3i MIPField< Field_T >::mipResolution | ( | size_t | level | ) | const

virtual

Returns the resolution of a given MIP level.

Implements MIPBase< Field_T::value_type >.

Definition at line 581 of file MIPField.h.

{
assert(level < base::m_numLevels);
return m_mipRes[level];
}
MIPField::m_mipRes
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition MIPField.h:264

References m_mipRes, and MIPBase< Data_T >::m_numLevels.

## levelLoaded()

template<class Field_T>

bool MIPField< Field_T >::levelLoaded | ( | const size_t | level | ) | const

virtual

Whether a given MIP level is loaded.

Implements MIPBase< Field_T::value_type >.

Definition at line 590 of file MIPField.h.

{
assert(level < base::m_numLevels);
return m_rawFields[level] != NULL;
}
MIPField::m_rawFields
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition MIPField.h:262

References MIPBase< Data_T >::m_numLevels, and m_rawFields.

## getVsMIPCoord()

template<typename Field_T>

void MIPField< Field_T >::getVsMIPCoord | ( | const V3f & | vsP,
|  | const size_t | level,
|  | V3f & | outVsP ) const

virtual

Given a voxel space coordinate in the 0-level field, computes the coordinate in another level.

Implements MIPBase< Field_T::value_type >.

Definition at line 599 of file MIPField.h.

{
const V3i &mipOff = base::mipOffset();
// Compute offset of current level
const V3i offset((mipOff.x >> level) << level,
(mipOff.y >> level) << level,
(mipOff.z >> level) << level);
// Difference between current offset and base offset is num voxels
// to offset current level by
const V3f diff = offset - mipOff;
// Incorporate shift due to mip offset
outVsP = (vsP - diff) * pow(2.0, -static_cast<float>(level));
}
MIPBase::mipOffset
const V3i & mipOffset() const
Returns the base MIP offset.
Definition MIPBase.h:180

References MIPBase< Data_T >::mipOffset().

## mipLevel()

template<typename Field_T>

Field< typenameMIPField< Field_T >::Data_T >::Ptr MIPField< Field_T >::mipLevel | ( | const size_t | level | ) | const

virtual

Returns a MIP level field.

Implements MIPBase< Field_T::value_type >.

Definition at line 621 of file MIPField.h.

{
assert(level < base::m_numLevels);
// Ensure level is loaded.
if (!m_rawFields[level]) {
loadLevelFromDisk(level);
}
// Return
return m_fields[level];
}
MIPField::loadLevelFromDisk
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition MIPField.h:685

References loadLevelFromDisk(), m_fields, MIPBase< Data_T >::m_numLevels, and m_rawFields.

## fastMipValue()

template<class Field_T>

MIPField< Field_T >::Data_T MIPField< Field_T >::fastMipValue | ( | size_t | level,
|  | int | i,
|  | int | j,
|  | int | k ) const

Read access to voxel at a given MIP level.

Definition at line 636 of file MIPField.h.

{
assert(level < base::m_numLevels);
// Ensure level is loaded.
if (!m_rawFields[level]) {
loadLevelFromDisk(level);
}
// Read from given level
return m_rawFields[level]->fastValue(i, j, k);
}

References loadLevelFromDisk(), MIPBase< Data_T >::m_numLevels, and m_rawFields.

Referenced by mipValue(), and value().

## clone()

template<class Field_T>

virtual FieldBase::Ptr MIPField< Field_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.

Reimplemented in MIPDenseField< Data_T >, and MIPSparseField< Data_T >.

Definition at line 207 of file MIPField.h.

{
return Ptr(new MIPField(*this));
}
MIPField::Ptr
boost::intrusive_ptr< MIPField > Ptr
Definition MIPField.h:118
MIPField::MIPField
MIPField()
Constructs an empty MIP field.
Definition MIPField.h:324

References MIPField().

Referenced by init().

## clear()

template<class Field_T>

void MIPField< Field_T >::clear | ( |  | ) |

Clears all the levels of the MIP field.

Definition at line 389 of file MIPField.h.

{
m_fields.clear();
m_rawFields.clear();
base::m_numLevels = 0;
base::m_lowestLevel = 0;
}
MIPBase::m_lowestLevel
size_t m_lowestLevel
The lowest MIP level to use. Defaults to 0, but can be set higher to prevent high resolution levels f...
Definition MIPBase.h:199

References m_fields, MIPBase< Data_T >::m_lowestLevel, MIPBase< Data_T >::m_numLevels, and m_rawFields.

Referenced by setup(), and setupLazyLoad().

## setup()

template<class Field_T>

void MIPField< Field_T >::setup | ( | const FieldVec & | fields | ) |

Sets up the MIP field given a set of non-MIP fields This call performs sanity checking to ensure that MIP properties are satisfied for each level. In this case, all MIP levels are available in memory.

Note
  The MIP level order is implied to be zero-first.

Definition at line 400 of file MIPField.h.

{
// Clear existing data
clear();
// Run sanity checks. This will throw an exception if the fields are invalid.
sanityChecks(fields);
// Update state of object
m_fields = fields;
base::m_numLevels = fields.size();
base::m_lowestLevel = 0;
updateMapping(fields[0]);
updateAuxMembers();
// Resize vectors
m_mipRes.resize(base::m_numLevels);
m_relativeResolution.resize(base::m_numLevels);
// For each MIP level
for (size_t i = 0; i < fields.size(); i++) {
// Update MIP res from real fields
m_mipRes[i] = m_fields[i]->extents().size() + V3i(1);
// Update relative resolutions
m_relativeResolution[i] = V3f(m_mipRes[i]) / m_mipRes[0];
}
}
V3f
Imath::V3f V3f
Definition SpiMathLib.h:73
MIPField::updateMapping
void updateMapping(FieldRes::Ptr field)
Updates the mapping, extents and data window to match the given field. Used so that the MIPField will...
Definition MIPField.h:675
MIPField::clear
void clear()
Clears all the levels of the MIP field.
Definition MIPField.h:389
MIPField::updateAuxMembers
void updateAuxMembers() const
Updates the dependent data members based on m_field.
Definition MIPField.h:650
MIPField::sanityChecks
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
Definition MIPField.h:719
MIPField::m_relativeResolution
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Definition MIPField.h:267

References clear(), m_fields, MIPBase< Data_T >::m_lowestLevel, m_mipRes, MIPBase< Data_T >::m_numLevels, m_relativeResolution, sanityChecks(), updateAuxMembers(), and updateMapping().

## setupLazyLoad()

template<class Field_T>

void MIPField< Field_T >::setupLazyLoad | ( | const ProxyVec & | proxies,
|  | const typename LazyLoadAction< Field_T >::Vec & | actions )

Sets up the MIP field in lazy-load mode.

Parameters

  mipGroupPath | Path in F3D file to read data from.

Definition at line 427 of file MIPField.h.

{
using namespace Exc;
// Clear existing data
clear();
// Check same number of proxies and actions
if (proxies.size() != actions.size()) {
throw MIPFieldException("Incorrect number of lazy load actions");
}
// Run sanity checks. This will throw an exception if the fields are invalid.
sanityChecks(proxies);
// Store the lazy load actions
m_loadActions = actions;
// Update state of object
base::m_numLevels = proxies.size();
base::m_lowestLevel = 0;
m_fields.resize(base::m_numLevels);
updateMapping(proxies[0]);
updateAuxMembers();
// Resize vectors
m_mipRes.resize(base::m_numLevels);
m_relativeResolution.resize(base::m_numLevels);
for (size_t i = 0; i < proxies.size(); i++) {
// Update mip res from proxy fields
m_mipRes[i] = proxies[i]->extents().size() + V3i(1);
// Update relative resolutions
m_relativeResolution[i] = V3f(m_mipRes[i]) / m_mipRes[0];
}
}
MIPField::m_loadActions
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
Definition MIPField.h:258

References clear(), m_fields, m_loadActions, MIPBase< Data_T >::m_lowestLevel, m_mipRes, MIPBase< Data_T >::m_numLevels, m_relativeResolution, sanityChecks(), updateAuxMembers(), and updateMapping().

## rawMipLevel()

template<class Field_T>

const Field_T * MIPField< Field_T >::rawMipLevel | ( | const size_t | level | ) | const

Returns a raw pointer to a MIP level.

Definition at line 481 of file MIPField.h.

{
assert(level < base::m_numLevels);
// Ensure level is loaded.
if (!m_rawFields[level]) {
loadLevelFromDisk(level);
}
// Return
return m_rawFields[level];
}

References loadLevelFromDisk(), MIPBase< Data_T >::m_numLevels, and m_rawFields.

## concreteMipLevel()

template<class Field_T>

Field_T::Ptr MIPField< Field_T >::concreteMipLevel | ( | const size_t | level | ) | const

Returns a concretely typed pointer to a MIP level.

Definition at line 496 of file MIPField.h.

{
assert(level < base::m_numLevels);
// Ensure level is loaded.
if (!m_rawFields[level]) {
loadLevelFromDisk(level);
}
// Return
return m_fields[level];
}

References loadLevelFromDisk(), m_fields, MIPBase< Data_T >::m_numLevels, and m_rawFields.

## init()

template<class Field_T>

const MIPField< Field_T > & MIPField< Field_T >::init | ( | const MIPField< Field_T > & | rhs | ) |

protected

Copies from a second MIPField.

Definition at line 354 of file MIPField.h.

{
// If any of the fields aren't yet loaded, we can rely on the same load
// actions as the other one
m_loadActions = rhs.m_loadActions;
// Copy all the regular data members
m_mipRes = rhs.m_mipRes;
m_relativeResolution = rhs.m_relativeResolution;
// The contained fields must be individually cloned if they have already
// been loaded
m_fields.resize(rhs.m_fields.size());
m_rawFields.resize(rhs.m_rawFields.size());
for (size_t i = 0, end = m_fields.size(); i < end; ++i) {
// Update the field pointer
if (rhs.m_fields[i]) {
FieldBase::Ptr baseClone = rhs.m_fields[i]->clone();
FieldPtr clone = field_dynamic_cast<Field_T>(baseClone);
if (clone) {
m_fields[i] = clone;
} else {
std::cerr << "MIPField::op=(): Failed to clone." << std::endl;
}
}
// Update the raw pointer
m_rawFields[i] = m_fields[i].get();
}
// New mutex
m_ioMutex.reset(new boost::mutex);
// Done
return *this;
}
MIPField::clone
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
Definition MIPField.h:207
MIPField::FieldPtr
Field_T::Ptr FieldPtr
Definition MIPField.h:130
field_dynamic_cast
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition RefCount.h:256

References clone(), field_dynamic_cast(), m_fields, m_ioMutex, m_loadActions, m_mipRes, m_rawFields, m_relativeResolution, and MIPField().

Referenced by MIPField(), and operator=().

## updateMapping()

template<class Field_T>

void MIPField< Field_T >::updateMapping | ( | FieldRes::Ptr | field | ) |

protected

Updates the mapping, extents and data window to match the given field. Used so that the MIPField will appear to have the same mapping in space as the level-0 field.

Definition at line 675 of file MIPField.h.

{
base::m_extents = field->extents();
base::m_dataWindow = field->dataWindow();
base::setMapping(field->mapping());
}
FieldRes::m_extents
Box3i m_extents
Defines the extents of the the storage. This may be larger or smaller than the data window,...
Definition Field.h:307
FieldRes::setMapping
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition Field.h:347
FieldRes::m_dataWindow
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e....
Definition Field.h:310

References FieldRes::m_dataWindow, FieldRes::m_extents, and FieldRes::setMapping().

Referenced by setup(), and setupLazyLoad().

## updateAuxMembers()

template<class Field_T>

void MIPField< Field_T >::updateAuxMembers | ( |  | ) | const

protected

Updates the dependent data members based on m_field.

Definition at line 650 of file MIPField.h.

{
m_rawFields.resize(m_fields.size());
for (size_t i = 0; i < m_fields.size(); i++) {
m_rawFields[i] = m_fields[i].get();
}
}

References m_fields, and m_rawFields.

Referenced by loadLevelFromDisk(), setup(), and setupLazyLoad().

## syncLevelInfo()

template<class Field_T>

void MIPField< Field_T >::syncLevelInfo | ( | const size_t | level | ) | const

protected

Updates the name, attribute and metadata for a given level.

Definition at line 661 of file MIPField.h.

{
// At this point, m_fields[level] is guaranteed in memory
// First sync name, attribute
m_fields[level]->name = base::name;
m_fields[level]->attribute = base::attribute;
// Copy metadata
m_fields[level]->copyMetadata(*this);
}
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition Field.h:173

References FieldBase::attribute, m_fields, and FieldBase::name.

Referenced by loadLevelFromDisk().

## loadLevelFromDisk()

template<class Field_T>

void MIPField< Field_T >::loadLevelFromDisk | ( | size_t | level | ) | const

protected

Loads the given level from disk.

Definition at line 685 of file MIPField.h.

{
// Double-check locking
if (!m_rawFields[level]) {
boost::mutex::scoped_lock lock(*m_ioMutex);
if (!m_rawFields[level]) {
// Execute the lazy load action
m_fields[level] = m_loadActions[level]->load();
// Check that field was loaded
if (!m_fields[level]) {
throw Exc::MIPFieldException("Couldn't load MIP level: " +
boost::lexical_cast<std::string>(level));
}
// Remove lazy load action
m_loadActions[level].reset();
// Update aux data
updateAuxMembers();
// Ensure metadata is up to date
syncLevelInfo(level);
// Update the mapping of the loaded field
V3i baseRes = base::dataWindow().size() + V3i(1);
FieldMapping::Ptr mapping =
detail::adjustedMIPFieldMapping(this, baseRes,
m_fields[level]->extents(), level);
m_fields[level]->setMapping(mapping);
}
}
}
MIPField::syncLevelInfo
void syncLevelInfo(const size_t level) const
Updates the name, attribute and metadata for a given level.
Definition MIPField.h:661

References detail::adjustedMIPFieldMapping(), FieldRes::dataWindow(), FieldRes::extents(), m_fields, m_ioMutex, m_loadActions, m_rawFields, FieldRes::mapping(), syncLevelInfo(), and updateAuxMembers().

Referenced by concreteMipLevel(), fastMipValue(), mipLevel(), and rawMipLevel().

## sanityChecks()

template<class Field_T>
template<class T>

void MIPField< Field_T >::sanityChecks | ( | const T & | fields | ) |

protected

Sanity checks to ensure that the provided Fields are a MIP representation.

Definition at line 719 of file MIPField.h.

{
using boost::lexical_cast;
using std::string;
using Exc::MIPFieldException;
// Check zero length
if (fields.size() == 0) {
throw MIPFieldException("Zero fields in input");
}
// Check all non-null
for (size_t i = 0; i < fields.size(); i++) {
if (!fields[i]) {
throw MIPFieldException("Found null pointer in input");
}
}
// Check decreasing resolution at higher levels
V3i prevSize = fields[0]->extents().size();
for (size_t i = 1; i < fields.size(); i++) {
V3i size = fields[i]->extents().size();
if (size.x > prevSize.x ||
size.y > prevSize.y ||
size.z > prevSize.z) {
throw MIPFieldException("Field " + lexical_cast<string>(i) +
" had greater resolution than previous"
" level");
}
if (size.x >= prevSize.x &&
size.y >= prevSize.y &&
size.z >= prevSize.z) {
throw MIPFieldException("Field " + lexical_cast<string>(i) +
" did not decrease in resolution from "
" previous level: " +
lexical_cast<string>(size) + " > " +
lexical_cast<string>(prevSize));
}
prevSize = size;
}
// All good.
}

Referenced by setup(), and setupLazyLoad().

## Member Data Documentation

## FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION

template<class Field_T>

MIPField< Field_T >::FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION

Definition at line 205 of file MIPField.h.

## ms_classType

template<class Field_T>

NestedFieldType<MIPField<Field_T> > MIPField< Field_T >::ms_classType

static protected

Definition at line 246 of file MIPField.h.

Referenced by staticClassType().

## m_fields

template<class Field_T>

std::vector<FieldPtr> MIPField< Field_T >::m_fields

mutable protected

Storage of all MIP levels. Some or all of the pointers may be NULL. This is mutable because it needs updating during lazy loading of data.

Definition at line 256 of file MIPField.h.

Referenced by clear(), concreteMipLevel(), init(), loadLevelFromDisk(), mappingChanged(), memSize(), MIPField(), mipLevel(), setup(), setupLazyLoad(), syncLevelInfo(), updateAuxMembers(), and voxelCount().

## m_loadActions

template<class Field_T>

LazyLoadAction<Field_T>::Vec MIPField< Field_T >::m_loadActions

mutable protected

Lazy load actions. Only used if setupLazyLoad() has been called.

Definition at line 258 of file MIPField.h.

Referenced by init(), loadLevelFromDisk(), and setupLazyLoad().

## m_rawFields

template<class Field_T>

std::vector<Field_T*> MIPField< Field_T >::m_rawFields

mutable protected

Raw pointers to MIP levels.

Note
  Important note: This is also used as the double-checked locking indicator.

Definition at line 262 of file MIPField.h.

Referenced by clear(), concreteMipLevel(), fastMipValue(), init(), levelLoaded(), loadLevelFromDisk(), mipLevel(), rawMipLevel(), and updateAuxMembers().

## m_mipRes

template<class Field_T>

std::vector<V3i> MIPField< Field_T >::m_mipRes

mutable protected

Resolution of each MIP level.

Definition at line 264 of file MIPField.h.

Referenced by init(), mipResolution(), setup(), and setupLazyLoad().

## m_relativeResolution

template<class Field_T>

std::vector<V3f> MIPField< Field_T >::m_relativeResolution

mutable protected

Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.

Definition at line 267 of file MIPField.h.

Referenced by init(), setup(), and setupLazyLoad().

## m_ioMutex

template<class Field_T>

boost::shared_ptr<boost::mutex> MIPField< Field_T >::m_ioMutex

protected

Mutex lock around IO. Used to make sure only one thread reads MIP level data at a time. When a field is cloned, the two new fields will share the mutex, since they point to the same file.

Definition at line 271 of file MIPField.h.

Referenced by init(), loadLevelFromDisk(), and MIPField().

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

- export/MIPField.h