Field3D
MIPField< Field_T > Class Template Reference

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

#include <MIPField.h>

Inheritance diagram for MIPField< Field_T >:
MIPBase< Field_T::value_type > Field< Data_T > FieldRes FieldBase RefBase MetadataCallback

Public Types

typedef MIPField< Field_T > class_type
 
typedef CubicMIPFieldInterp< Data_TCubicInterp
 
typedef Field_T::value_type Data_T
 
typedef Field_T::Ptr FieldPtr
 
typedef std::vector< FieldPtrFieldVec
 
typedef MIPLinearInterp< MIPField< Field_T > > LinearInterp
 
typedef Field_T NestedType
 
typedef EmptyField< Data_TProxyField
 
typedef ProxyField::Ptr ProxyPtr
 
typedef std::vector< ProxyPtrProxyVec
 
typedef boost::intrusive_ptr< MIPFieldPtr
 
typedef Data_T value_type
 
typedef std::vector< PtrVec
 
- Public Types inherited from MIPBase< Field_T::value_type >
typedef MIPBase< Field_T::value_type > class_type
 
typedef boost::intrusive_ptr< MIPBasePtr
 
- Public Types inherited from Field< Data_T >
typedef Field< Data_T > class_type
 
typedef boost::intrusive_ptr< FieldPtr
 
typedef Data_T value_type
 Allows us to reference the template class.
 
typedef std::vector< PtrVec
 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< FieldResPtr
 
typedef std::vector< PtrVec
 
- Public Types inherited from FieldBase
typedef FieldBase class_type
 
typedef boost::intrusive_ptr< FieldBasePtr
 
- Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBasePtr
 
typedef boost::weak_ptr< RefBaseWeakPtr
 

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 MIPFieldoperator= (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 V3imipOffset () 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< Data_T >
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)
 
virtual std::string dataTypeString () const
 
virtual ~Field ()
 Dtor.
 
- Public Member Functions inherited from FieldRes
V3i const dataResolution () const
 
const Box3idataWindow () const
 Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field subclass.
 
const Box3iextents () 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.
 
FieldMetadatametadata ()
 accessor to the m_metadata class
 
const FieldMetadatametadata () 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.
 
RefBaseoperator= (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 charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from MIPBase< Field_T::value_type >
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from Field< Data_T >
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from FieldRes
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from FieldBase
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from RefBase
static const charstaticClassType ()
 

Protected Types

typedef MIPBase< Data_Tbase
 
- 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 MIPFieldinit (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< FieldPtrm_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< V3im_mipRes
 Resolution of each MIP level.
 
std::vector< Field_T * > m_rawFields
 Raw pointers to MIP levels.
 
std::vector< V3fm_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< Data_T >
 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.

325 : base(),
326 m_ioMutex(new boost::mutex)
327{
329}
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition MIPBase.h:196
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
MIPBase< Data_T > base
Definition MIPField.h:242
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 MIPField< Field_T >::m_fields, and MIPBase< Data_T >::m_numLevels.

Referenced by MIPField< Field_T >::clone().

◆ 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.

335 : base(other)
336{
337 init(other);
338}
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
Definition MIPField.h:354

References FIELD3D_MTX_T, and MIPField< Field_T >::init().

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.

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

References FIELD3D_MTX_T.

◆ 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.

535{
536 long long int mem = 0;
537 for (size_t i = 0; i < m_fields.size(); i++) {
538 if (m_fields[i]) {
539 mem += m_fields[i]->memSize();
540 }
541 }
542 return mem + sizeof(*this);
543}

References FIELD3D_MTX_T.

◆ 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.

549{
550 // Update MIP offset
551 const V3i offset =
554
555 V3i baseRes = base::dataWindow().size() + V3i(1);
556 if (m_fields[0]) {
557 m_fields[0]->setMapping(base::mapping());
558 }
559 for (size_t i = 1; i < m_fields.size(); i++) {
560 if (m_fields[i]) {
563 m_fields[i]->extents(), i);
564 m_fields[i]->setMapping(mapping);
565 }
566 }
567}
Imath::V3i V3i
Definition SpiMathLib.h:71
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field.h:155
boost::intrusive_ptr< FieldMapping > Ptr
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.
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition Field.h:263
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over....
Definition Field.h:249
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
void setMIPOffset(const V3i &offset)
Sets the base MIP offset. This is used to indicate where voxel space coordinate (0,...
Definition MIPBase.h:230
const std::string k_mipOffsetStr
Definition MIPUtil.cpp:66
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(), FIELD3D_MTX_T, and detail::k_mipOffsetStr.

◆ 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< Data_T >.

Definition at line 511 of file MIPField.h.

512{
513 return fastMipValue(0, i, j, k);
514}
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 FIELD3D_MTX_T.

◆ 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.

521{
522 size_t count = 0;
523 for (size_t i = 0; i < m_fields.size(); i++) {
524 if (m_fields[i]) {
525 count += m_fields[i]->voxelCount();
526 }
527 }
528 return count;
529}

References FIELD3D_MTX_T.

◆ staticClassName()

template<class Field_T >
static DEFINE_FIELD_RTTI_CONCRETE_CLASS const char * MIPField< Field_T >::staticClassName ( )
inlinestatic

Definition at line 176 of file MIPField.h.

177 {
178 return "MIPField";
179 }

◆ staticClassType()

template<class Field_T >
static const char * MIPField< Field_T >::staticClassType ( )
inlinestatic

Definition at line 181 of file MIPField.h.

182 {
184 }
std::string name
Optional name of the field.
Definition Field.h:171
This subclass stores a MIP representation of a Field_T field.
Definition MIPField.h:110

References FieldBase::name.

◆ 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
levelThe MIP level to read from

Implements MIPBase< Field_T::value_type >.

Definition at line 573 of file MIPField.h.

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

References FIELD3D_MTX_T.

◆ 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.

582{
584 return m_mipRes[level];
585}
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition MIPField.h:264

References FIELD3D_MTX_T.

◆ 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.

591{
593 return m_rawFields[level] != NULL;
594}
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition MIPField.h:262

References FIELD3D_MTX_T.

◆ 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.

601{
602 const V3i &mipOff = base::mipOffset();
603
604 // Compute offset of current level
605 const V3i offset((mipOff.x >> level) << level,
606 (mipOff.y >> level) << level,
607 (mipOff.z >> level) << level);
608
609 // Difference between current offset and base offset is num voxels
610 // to offset current level by
611 const V3f diff = offset - mipOff;
612
613 // Incorporate shift due to mip offset
614 outVsP = (vsP - diff) * pow(2.0, -static_cast<float>(level));
615}
Imath::V3f V3f
Definition SpiMathLib.h:73
const V3i & mipOffset() const
Returns the base MIP offset.
Definition MIPBase.h:180

References FIELD3D_MTX_T.

◆ 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.

622{
624 // Ensure level is loaded.
625 if (!m_rawFields[level]) {
627 }
628 // Return
629 return m_fields[level];
630}
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition MIPField.h:685

References FIELD3D_MTX_T.

◆ 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.

637{
639 // Ensure level is loaded.
640 if (!m_rawFields[level]) {
642 }
643 // Read from given level
644 return m_rawFields[level]->fastValue(i, j, k);
645}

References FIELD3D_MTX_T.

◆ clone()

template<class Field_T >
virtual FieldBase::Ptr MIPField< Field_T >::clone ( ) const
inlinevirtual

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

Implements FieldBase.

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

Definition at line 207 of file MIPField.h.

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

References MIPField< Field_T >::MIPField().

◆ 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.

390{
391 m_fields.clear();
392 m_rawFields.clear();
395}
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

◆ 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.

401{
402 // Clear existing data
403 clear();
404 // Run sanity checks. This will throw an exception if the fields are invalid.
405 sanityChecks(fields);
406 // Update state of object
407 m_fields = fields;
408 base::m_numLevels = fields.size();
410 updateMapping(fields[0]);
412 // Resize vectors
415 // For each MIP level
416 for (size_t i = 0; i < fields.size(); i++) {
417 // Update MIP res from real fields
418 m_mipRes[i] = m_fields[i]->extents().size() + V3i(1);
419 // Update relative resolutions
421 }
422}
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
void clear()
Clears all the levels of the MIP field.
Definition MIPField.h:389
void updateAuxMembers() const
Updates the dependent data members based on m_field.
Definition MIPField.h:650
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
Definition MIPField.h:719
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Definition MIPField.h:267

References FIELD3D_MTX_T.

◆ 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
mipGroupPathPath in F3D file to read data from.

Definition at line 427 of file MIPField.h.

430{
431 using namespace Exc;
432
433 // Clear existing data
434 clear();
435 // Check same number of proxies and actions
436 if (proxies.size() != actions.size()) {
437 throw MIPFieldException("Incorrect number of lazy load actions");
438 }
439 // Run sanity checks. This will throw an exception if the fields are invalid.
441 // Store the lazy load actions
443 // Update state of object
444 base::m_numLevels = proxies.size();
449 // Resize vectors
452 for (size_t i = 0; i < proxies.size(); i++) {
453 // Update mip res from proxy fields
454 m_mipRes[i] = proxies[i]->extents().size() + V3i(1);
455 // Update relative resolutions
457 }
458}
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
Definition MIPField.h:258
Namespace for Exception objects.
Definition Exception.h:57

References FIELD3D_MTX_T.

◆ 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.

482{
484 // Ensure level is loaded.
485 if (!m_rawFields[level]) {
487 }
488 // Return
489 return m_rawFields[level];
490}

References FIELD3D_MTX_T.

◆ 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.

497{
499 // Ensure level is loaded.
500 if (!m_rawFields[level]) {
502 }
503 // Return
504 return m_fields[level];
505}

References FIELD3D_MTX_T.

◆ 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.

355{
356 // If any of the fields aren't yet loaded, we can rely on the same load
357 // actions as the other one
358 m_loadActions = rhs.m_loadActions;
359 // Copy all the regular data members
360 m_mipRes = rhs.m_mipRes;
361 m_relativeResolution = rhs.m_relativeResolution;
362 // The contained fields must be individually cloned if they have already
363 // been loaded
364 m_fields.resize(rhs.m_fields.size());
365 m_rawFields.resize(rhs.m_rawFields.size());
366 for (size_t i = 0, end = m_fields.size(); i < end; ++i) {
367 // Update the field pointer
368 if (rhs.m_fields[i]) {
369 FieldBase::Ptr baseClone = rhs.m_fields[i]->clone();
371 if (clone) {
372 m_fields[i] = clone;
373 } else {
374 std::cerr << "MIPField::op=(): Failed to clone." << std::endl;
375 }
376 }
377 // Update the raw pointer
378 m_rawFields[i] = m_fields[i].get();
379 }
380 // New mutex
381 m_ioMutex.reset(new boost::mutex);
382 // Done
383 return *this;
384}
boost::intrusive_ptr< FieldBase > Ptr
Definition Field.h:97
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
Field_T::Ptr FieldPtr
Definition MIPField.h:130

References FIELD3D_MTX_T, and MIPField< Field_T >::m_loadActions.

Referenced by MIPField< Field_T >::MIPField().

◆ 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.

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

◆ 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.

651{
652 m_rawFields.resize(m_fields.size());
653 for (size_t i = 0; i < m_fields.size(); i++) {
654 m_rawFields[i] = m_fields[i].get();
655 }
656}

References FIELD3D_MTX_T.

◆ 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.

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

References FIELD3D_MTX_T.

◆ 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.

686{
687 // Double-check locking
688 if (!m_rawFields[level]) {
689 boost::mutex::scoped_lock lock(*m_ioMutex);
690 if (!m_rawFields[level]) {
691 // Execute the lazy load action
692 m_fields[level] = m_loadActions[level]->load();
693 // Check that field was loaded
694 if (!m_fields[level]) {
695 throw Exc::MIPFieldException("Couldn't load MIP level: " +
696 boost::lexical_cast<std::string>(level));
697 }
698 // Remove lazy load action
699 m_loadActions[level].reset();
700 // Update aux data
702 // Ensure metadata is up to date
704 // Update the mapping of the loaded field
705 V3i baseRes = base::dataWindow().size() + V3i(1);
709 m_fields[level]->setMapping(mapping);
710 }
711 }
712}
void syncLevelInfo(const size_t level) const
Updates the name, attribute and metadata for a given level.
Definition MIPField.h:661

References detail::adjustedMIPFieldMapping(), and FIELD3D_MTX_T.

◆ 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.

720{
721 using boost::lexical_cast;
722 using std::string;
723 using Exc::MIPFieldException;
724
725 // Check zero length
726 if (fields.size() == 0) {
727 throw MIPFieldException("Zero fields in input");
728 }
729 // Check all non-null
730 for (size_t i = 0; i < fields.size(); i++) {
731 if (!fields[i]) {
732 throw MIPFieldException("Found null pointer in input");
733 }
734 }
735 // Check decreasing resolution at higher levels
736 V3i prevSize = fields[0]->extents().size();
737 for (size_t i = 1; i < fields.size(); i++) {
738 V3i size = fields[i]->extents().size();
739 if (size.x > prevSize.x ||
740 size.y > prevSize.y ||
741 size.z > prevSize.z) {
742 throw MIPFieldException("Field " + lexical_cast<string>(i) +
743 " had greater resolution than previous"
744 " level");
745 }
746 if (size.x >= prevSize.x &&
747 size.y >= prevSize.y &&
748 size.z >= prevSize.z) {
749 throw MIPFieldException("Field " + lexical_cast<string>(i) +
750 " did not decrease in resolution from "
751 " previous level: " +
752 lexical_cast<string>(size) + " > " +
754 }
755 prevSize = size;
756 }
757 // All good.
758}

References FIELD3D_MTX_T.

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<typename Field_T >
NestedFieldType< MIPField< Field_T > > MIPField< Field_T >::ms_classType
staticprotected
Initial value:
=
Used to return a string for the name of a nested templated field.
Definition Traits.h:307

Definition at line 246 of file MIPField.h.

◆ m_fields

template<class Field_T >
std::vector<FieldPtr> MIPField< Field_T >::m_fields
mutableprotected

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 MIPField< Field_T >::MIPField().

◆ m_loadActions

template<class Field_T >
LazyLoadAction<Field_T>::Vec MIPField< Field_T >::m_loadActions
mutableprotected

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

Definition at line 258 of file MIPField.h.

Referenced by MIPField< Field_T >::init().

◆ m_rawFields

template<class Field_T >
std::vector<Field_T*> MIPField< Field_T >::m_rawFields
mutableprotected

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.

◆ m_mipRes

template<class Field_T >
std::vector<V3i> MIPField< Field_T >::m_mipRes
mutableprotected

Resolution of each MIP level.

Definition at line 264 of file MIPField.h.

◆ m_relativeResolution

template<class Field_T >
std::vector<V3f> MIPField< Field_T >::m_relativeResolution
mutableprotected

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

Definition at line 267 of file MIPField.h.

◆ 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.


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