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< Field_T::value_type > 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_typeclass_type
 
typedef boost::intrusive_ptr< MIPBasePtr
 
- Public Types inherited from Field< Field_T::value_type >
typedef Field< Field_T::value_typeclass_type
 
typedef boost::intrusive_ptr< FieldPtr
 
typedef Field_T::value_type value_type
 Allows us to reference the template class. More...
 
typedef std::vector< PtrVec
 This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInputFile::readVectorLayers() will return its data in. More...
 
- 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. More...
 
Field_T::Ptr concreteMipLevel (const size_t level) const
 Returns a concretely typed pointer to a MIP level. More...
 
Data_T fastMipValue (size_t level, int i, int j, int k) const
 Read access to voxel at a given MIP level. More...
 
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. More...
 
virtual bool levelLoaded (const size_t level) const
 Whether a given MIP level is loaded. More...
 
virtual Field< Data_T >::Ptr mipLevel (const size_t level) const
 Returns a MIP level field. More...
 
virtual V3i mipResolution (size_t level) const
 Returns the resolution of a given MIP level. More...
 
virtual Data_T mipValue (size_t level, int i, int j, int k) const
 Read access to a voxel in a given MIP level. More...
 
const Field_T * rawMipLevel (const size_t level) const
 Returns a raw pointer to a MIP level. More...
 
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. More...
 
void setupLazyLoad (const ProxyVec &proxies, const typename LazyLoadAction< Field_T >::Vec &actions)
 Sets up the MIP field in lazy-load mode. More...
 
Constructors & destructor
 MIPField ()
 Constructs an empty MIP field. More...
 
 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. More...
 
const MIPFieldoperator= (const MIPField &rhs)
 Assignment operator. More...
 
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) More...
 
virtual void mappingChanged ()
 We need to know if the mapping changed so that we may update the MIP levels' mappings. More...
 
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 . More...
 
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. More...
 
- Public Member Functions inherited from MIPBase< Field_T::value_type >
size_t lowestLevel () const
 Lowest MIP level to use. More...
 
 MIPBase ()
 
const V3imipOffset () const
 Returns the base MIP offset. More...
 
size_t numLevels () const
 Number of MIP levels. More...
 
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. More...
 
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. More...
 
- 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. More...
 
const_iterator cbegin (const Box3i &subset) const
 Const iterator to first element of specific subset. More...
 
const_iterator cend () const
 Const iterator pointing one element past the last valid one. More...
 
const_iterator cend (const Box3i &subset) const
 Const iterator pointing one element past the last valid one (for a subset) More...
 
virtual std::string dataTypeString () const
 
virtual ~Field ()
 Dtor. More...
 
- Public Member Functions inherited from FieldRes
V3i const dataResolution () const
 
virtual std::string dataTypeString () const
 
const Box3idataWindow () const
 Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field subclass. More...
 
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. More...
 
 FieldRes ()
 This constructor ensures that we have a valid mapping at all times. More...
 
 FieldRes (const FieldRes &src)
 Base class copy constructor. More...
 
bool isInBounds (int i, int j, int k) const
 Returns true is the indicies are in bounds of the data window. More...
 
FieldMapping::Ptr mapping ()
 Returns a pointer to the mapping. More...
 
const FieldMapping::Ptr mapping () const
 Returns a pointer to the mapping. More...
 
void setMapping (FieldMapping::Ptr mapping)
 Sets the field's mapping. More...
 
- Public Member Functions inherited from FieldBase
 FieldBase ()
 Constructor. More...
 
 FieldBase (const FieldBase &)
 Copy Constructor. More...
 
virtual ~FieldBase ()
 Destructor. More...
 
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. More...
 
virtual std::string classType () const =0
 Returns the full class type string. More...
 
FieldMetadatametadata ()
 accessor to the m_metadata class More...
 
const FieldMetadatametadata () const
 Read only access to the m_metadata class. More...
 
void copyMetadata (const FieldBase &field)
 Copies the metadata from a second field. More...
 
- Public Member Functions inherited from RefBase
void ref () const
 Used by boost::intrusive_pointer. More...
 
size_t refcnt ()
 Used by boost::intrusive_pointer. More...
 
void unref () const
 Used by boost::intrusive_pointer. More...
 
WeakPtr weakPtr () const
 
 RefBase ()
 
 RefBase (const RefBase &)
 Copy constructor. More...
 
RefBaseoperator= (const RefBase &)
 Assignment operator. More...
 
virtual ~RefBase ()
 Destructor. More...
 
virtual bool checkRTTI (const char *typenameStr)=0
 This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();. More...
 
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. More...
 
- Public Member Functions inherited from MetadataCallback
virtual void metadataHasChanged (const std::string &)
 Alerts the callback holder that the metadata has changed. More...
 

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 Public Member Functions inherited from RefBase
static const char * staticClassType ()
 

Protected Types

typedef MIPBase< Data_Tbase
 
- Protected Types inherited from MIPBase< Field_T::value_type >
typedef Field< Field_T::value_typebase
 
- Protected Types inherited from FieldRes
typedef MatrixFieldMapping default_mapping
 

Protected Member Functions

const MIPFieldinit (const MIPField &rhs)
 Copies from a second MIPField. More...
 
void loadLevelFromDisk (size_t level) const
 Loads the given level from disk. More...
 
template<typename T >
void sanityChecks (const T &fields)
 Sanity checks to ensure that the provided Fields are a MIP representation. More...
 
void syncLevelInfo (const size_t level) const
 Updates the name, attribute and metadata for a given level. More...
 
void updateAuxMembers () const
 Updates the dependent data members based on m_field. More...
 
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. More...
 

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. More...
 
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. More...
 
LazyLoadAction< Field_T >::Vec m_loadActions
 Lazy load actions. Only used if setupLazyLoad() has been called. More...
 
std::vector< V3im_mipRes
 Resolution of each MIP level. More...
 
std::vector< Field_T * > m_rawFields
 Raw pointers to MIP levels. More...
 
std::vector< V3fm_relativeResolution
 Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions. More...
 
- 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. More...
 
V3i m_mipOffset
 Base coordinate offset. This is used to indicate where voxel space coordinate (0, 0, 0) really maps to. More...
 
size_t m_numLevels
 Number of MIP levels. The default is 1. More...
 
- 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. More...
 
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. More...
 
FieldMapping::Ptr m_mapping
 Pointer to the field's mapping. More...
 

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

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. More...
 
std::string name
 Optional name of the field. More...
 

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 {
328  m_fields.resize(base::m_numLevels);
329 }

References MIPField< Field_T >::m_fields, and MIPBase< Data_T >::m_numLevels.

Referenced by MIPField< DenseField< Data_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 }

References 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 {
346  base::operator=(rhs);
347  return init(rhs);
348 }

◆ memSize()

template<class Field_T >
long long int MIPField< Field_T >::memSize
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 }

◆ 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 =
553  base::setMIPOffset(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]) {
562  detail::adjustedMIPFieldMapping(this, baseRes,
563  m_fields[i]->extents(), i);
564  m_fields[i]->setMapping(mapping);
565  }
566  }
567 }

References detail::adjustedMIPFieldMapping(), 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< Field_T::value_type >.

Definition at line 511 of file MIPField.h.

512 {
513  return fastMipValue(0, i, j, k);
514 }

◆ voxelCount()

template<class Field_T >
size_t MIPField< Field_T >::voxelCount
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 }

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

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

◆ 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 {
583  assert(level < base::m_numLevels);
584  return m_mipRes[level];
585 }

◆ 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 {
592  assert(level < base::m_numLevels);
593  return m_rawFields[level] != NULL;
594 }

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

◆ mipLevel()

template<typename Field_T >
Field< typename MIPField< 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 {
623  assert(level < base::m_numLevels);
624  // Ensure level is loaded.
625  if (!m_rawFields[level]) {
626  loadLevelFromDisk(level);
627  }
628  // Return
629  return m_fields[level];
630 }

◆ 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 {
638  assert(level < base::m_numLevels);
639  // Ensure level is loaded.
640  if (!m_rawFields[level]) {
641  loadLevelFromDisk(level);
642  }
643  // Read from given level
644  return m_rawFields[level]->fastValue(i, j, k);
645 }

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

Definition at line 207 of file MIPField.h.

208  {
209  return Ptr(new MIPField(*this));
210  }

◆ 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();
393  base::m_numLevels = 0;
395 }

◆ 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
413  m_mipRes.resize(base::m_numLevels);
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 }

◆ 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.
440  sanityChecks(proxies);
441  // Store the lazy load actions
442  m_loadActions = actions;
443  // Update state of object
444  base::m_numLevels = proxies.size();
446  m_fields.resize(base::m_numLevels);
447  updateMapping(proxies[0]);
449  // Resize vectors
450  m_mipRes.resize(base::m_numLevels);
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 }

◆ 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 {
483  assert(level < base::m_numLevels);
484  // Ensure level is loaded.
485  if (!m_rawFields[level]) {
486  loadLevelFromDisk(level);
487  }
488  // Return
489  return m_rawFields[level];
490 }

◆ 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 {
498  assert(level < base::m_numLevels);
499  // Ensure level is loaded.
500  if (!m_rawFields[level]) {
501  loadLevelFromDisk(level);
502  }
503  // Return
504  return m_fields[level];
505 }

◆ 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
359  // Copy all the regular data members
360  m_mipRes = rhs.m_mipRes;
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();
370  FieldPtr clone = field_dynamic_cast<Field_T>(baseClone);
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 }

References MIPField< Field_T >::m_fields, MIPField< Field_T >::m_loadActions, MIPField< Field_T >::m_mipRes, MIPField< Field_T >::m_rawFields, and MIPField< Field_T >::m_relativeResolution.

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 }

◆ updateAuxMembers()

template<class Field_T >
void MIPField< Field_T >::updateAuxMembers
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 }

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

◆ 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
703  syncLevelInfo(level);
704  // Update the mapping of the loaded field
705  V3i baseRes = base::dataWindow().size() + V3i(1);
707  detail::adjustedMIPFieldMapping(this, baseRes,
708  m_fields[level]->extents(), level);
709  m_fields[level]->setMapping(mapping);
710  }
711  }
712 }

References detail::adjustedMIPFieldMapping().

◆ 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) + " > " +
753  lexical_cast<string>(prevSize));
754  }
755  prevSize = size;
756  }
757  // All good.
758 }

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:

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 >::init(), and 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.

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

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

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

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

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

◆ 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:
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::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
V3i
Imath::V3i V3i
Definition: SpiMathLib.h:71
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
MIPField::Ptr
boost::intrusive_ptr< MIPField > Ptr
Definition: MIPField.h:118
FieldBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field.h:155
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
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
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
MIPField::m_loadActions
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
Definition: MIPField.h:258
MIPField::m_rawFields
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
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
V3f
Imath::V3f V3f
Definition: SpiMathLib.h:73
FieldBase::name
std::string name
Optional name of the field.
Definition: Field.h:171
MIPField::clear
void clear()
Clears all the levels of the MIP field.
Definition: MIPField.h:389
FieldBase::Ptr
boost::intrusive_ptr< FieldBase > Ptr
Definition: Field.h:97
FieldRes::setMapping
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition: Field.h:347
FieldRes::mapping
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:263
RefBase::operator=
RefBase & operator=(const RefBase &)
Assignment operator.
Definition: RefCount.h:134
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::MIPField
MIPField()
Constructs an empty MIP field.
Definition: MIPField.h:324
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition: Field.h:173
MIPBase::mipOffset
const V3i & mipOffset() const
Returns the base MIP offset.
Definition: MIPBase.h:180
detail::k_mipOffsetStr
const std::string k_mipOffsetStr
Definition: MIPUtil.cpp:66
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::FieldPtr
Field_T::Ptr FieldPtr
Definition: MIPField.h:130
MIPField::m_mipRes
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition: MIPField.h:264
MIPField::init
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
Definition: MIPField.h:354
MIPBase::m_numLevels
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:196
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::sanityChecks
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
Definition: MIPField.h:719
Exc
Namespace for Exception objects.
Definition: Exception.h:57
MIPField::updateAuxMembers
void updateAuxMembers() const
Updates the dependent data members based on m_field.
Definition: MIPField.h:650
MIPField::loadLevelFromDisk
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition: MIPField.h:685
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
MIPField::base
MIPBase< Data_T > base
Definition: MIPField.h:242
MIPField
This subclass stores a MIP representation of a Field_T field.
Definition: MIPField.h:110
NestedFieldType
Used to return a string for the name of a nested templated field.
Definition: Traits.h:307
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
detail::adjustedMIPFieldMapping
FIELD3D_API FieldMapping::Ptr adjustedMIPFieldMapping(const FieldRes *base, const V3i &baseRes, const Box3i &extents, const size_t level)
Definition: MIPUtil.cpp:82
MIPField::syncLevelInfo
void syncLevelInfo(const size_t level) const
Updates the name, attribute and metadata for a given level.
Definition: MIPField.h:661
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