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

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 ()
 
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...
 
- 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
 
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...
 
FieldMetadata< FieldBase > & metadata ()
 accessor to the m_metadata class More...
 
const FieldMetadata< FieldBase > & metadata () const
 Read only access to the m_metadata class. More...
 
virtual void metadataHasChanged (const std::string &)
 This function should implemented by concrete classes to get the callback when metadata changes. 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...
 

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

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

Definition at line 115 of file MIPField.h.

template<class Field_T>
typedef Field_T MIPField< Field_T >::NestedType

Definition at line 116 of file MIPField.h.

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

Definition at line 118 of file MIPField.h.

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

Definition at line 119 of file MIPField.h.

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

Definition at line 121 of file MIPField.h.

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

Definition at line 122 of file MIPField.h.

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

Definition at line 124 of file MIPField.h.

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

Definition at line 126 of file MIPField.h.

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

Definition at line 127 of file MIPField.h.

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

Definition at line 128 of file MIPField.h.

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

Definition at line 130 of file MIPField.h.

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

Definition at line 131 of file MIPField.h.

template<class Field_T>
typedef MIPField<Field_T> MIPField< Field_T >::class_type

Definition at line 173 of file MIPField.h.

template<class Field_T>
typedef MIPBase<Data_T> MIPField< Field_T >::base
protected

Definition at line 242 of file MIPField.h.

Constructor & Destructor Documentation

template<class Field_T >
MIPField< Field_T >::MIPField ( )

Constructs an empty MIP field.

Definition at line 314 of file MIPField.h.

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

315  : base(),
316  m_ioMutex(new boost::mutex)
317 {
318  m_fields.resize(base::m_numLevels);
319 }
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
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
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
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 324 of file MIPField.h.

References MIPField< Field_T >::init().

325  : base(other)
326 {
327  init(other);
328 }
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
Definition: MIPField.h:344
MIPBase< Data_T > base
Definition: MIPField.h:242

Member Function Documentation

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

Assignment operator.

Definition at line 334 of file MIPField.h.

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

335 {
336  base::operator=(rhs);
337  return init(rhs);
338 }
RefBase & operator=(const RefBase &)
Assignment operator.
Definition: RefCount.h:134
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
Definition: MIPField.h:344
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 522 of file MIPField.h.

References MIPField< Field_T >::m_fields.

523 {
524  long long int mem = 0;
525  for (size_t i = 0; i < m_fields.size(); i++) {
526  if (m_fields[i]) {
527  mem += m_fields[i]->memSize();
528  }
529  }
530  return mem + sizeof(*this);
531 }
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
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 536 of file MIPField.h.

References detail::adjustedMIPFieldMapping(), FieldRes::dataWindow(), FieldRes::extents(), MIPField< Field_T >::m_fields, and FieldRes::mapping().

537 {
538  V3i baseRes = base::dataWindow().size() + V3i(1);
539  if (m_fields[0]) {
540  m_fields[0]->setMapping(base::mapping());
541  }
542  for (size_t i = 1; i < m_fields.size(); i++) {
543  if (m_fields[i]) {
546  m_fields[i]->extents(), i);
547  m_fields[i]->setMapping(mapping);
548  }
549  }
550 }
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
Definition: Field.h:254
FIELD3D_API FieldMapping::Ptr adjustedMIPFieldMapping(const FieldMapping::Ptr baseMapping, const V3i &baseRes, const Box3i &extents, const size_t level)
Definition: MIPUtil.cpp:77
Imath::V3i V3i
Definition: SpiMathLib.h:71
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
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
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:258
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:268
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 499 of file MIPField.h.

References MIPField< Field_T >::fastMipValue().

500 {
501  return fastMipValue(0, i, j, k);
502 }
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:606
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 508 of file MIPField.h.

References MIPField< Field_T >::m_fields.

509 {
510  size_t count = 0;
511  for (size_t i = 0; i < m_fields.size(); i++) {
512  if (m_fields[i]) {
513  count += m_fields[i]->voxelCount();
514  }
515  }
516  return count;
517 }
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
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  }
template<class Field_T>
static const char* MIPField< Field_T >::staticClassType ( )
inlinestatic

Definition at line 181 of file MIPField.h.

182  {
184  }
This subclass stores a MIP representation of a Field_T field.
Definition: MIPField.h:109
std::string name
Optional name of the field.
Definition: Field.h:176
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 556 of file MIPField.h.

References MIPField< Field_T >::fastMipValue().

557 {
558  return fastMipValue(level, i, j, k);
559 }
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:606
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 564 of file MIPField.h.

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

565 {
566  assert(level < base::m_numLevels);
567  return m_mipRes[level];
568 }
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition: MIPField.h:264
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
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 573 of file MIPField.h.

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

574 {
575  assert(level < base::m_numLevels);
576  return m_rawFields[level] != NULL;
577 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
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 582 of file MIPField.h.

References MIPField< Field_T >::m_relativeResolution.

584 {
585  outVsP = vsP * m_relativeResolution[level];
586 }
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Definition: MIPField.h:267
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 592 of file MIPField.h.

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

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

593 {
594  assert(level < base::m_numLevels);
595  // Ensure level is loaded.
596  if (!m_rawFields[level]) {
597  loadLevelFromDisk(level);
598  }
599  return m_fields[level];
600 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition: MIPField.h:641
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
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 606 of file MIPField.h.

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

Referenced by MIPField< Field_T >::mipValue(), and MIPField< Field_T >::value().

607 {
608  assert(level < base::m_numLevels);
609  // Ensure level is loaded.
610  if (!m_rawFields[level]) {
611  loadLevelFromDisk(level);
612  }
613  // Read from given level
614  return m_rawFields[level]->fastValue(i, j, k);
615 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition: MIPField.h:641
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.

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

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:314
template<class Field_T >
void MIPField< Field_T >::clear ( )

Clears all the levels of the MIP field.

Definition at line 379 of file MIPField.h.

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

Referenced by MIPField< Field_T >::setup(), and MIPField< Field_T >::setupLazyLoad().

380 {
381  m_fields.clear();
382  m_rawFields.clear();
383  base::m_numLevels = 0;
385 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
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:192
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
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
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 390 of file MIPField.h.

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

391 {
392  // Clear existing data
393  clear();
394  // Run sanity checks. This will throw an exception if the fields are invalid.
395  sanityChecks(fields);
396  // Update state of object
397  m_fields = fields;
398  base::m_numLevels = fields.size();
400  updateMapping(fields[0]);
402  // Resize vectors
403  m_mipRes.resize(base::m_numLevels);
405  // For each MIP level
406  for (size_t i = 0; i < fields.size(); i++) {
407  // Update MIP res from real fields
408  m_mipRes[i] = m_fields[i]->extents().size() + V3i(1);
409  // Update relative resolutions
411  }
412 }
void clear()
Clears all the levels of the MIP field.
Definition: MIPField.h:379
Imath::V3i V3i
Definition: SpiMathLib.h:71
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:192
void updateAuxMembers() const
Updates the dependent data members based on m_field.
Definition: MIPField.h:620
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition: MIPField.h:264
Imath::V3f V3f
Definition: SpiMathLib.h:73
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
Definition: MIPField.h:668
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:631
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Definition: MIPField.h:267
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
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 418 of file MIPField.h.

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

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

420 {
421  using namespace Exc;
422 
423  // Clear existing data
424  clear();
425  // Check same number of proxies and actions
426  if (proxies.size() != actions.size()) {
427  throw MIPFieldException("Incorrect number of lazy load actions");
428  }
429  // Run sanity checks. This will throw an exception if the fields are invalid.
430  sanityChecks(proxies);
431  // Store the lazy load actions
432  m_loadActions = actions;
433  // Update state of object
434  base::m_numLevels = proxies.size();
436  m_fields.resize(base::m_numLevels);
437  updateMapping(proxies[0]);
439  // Resize vectors
440  m_mipRes.resize(base::m_numLevels);
442  for (size_t i = 0; i < proxies.size(); i++) {
443  // Update mip res from proxy fields
444  m_mipRes[i] = proxies[i]->extents().size() + V3i(1);
445  // Update relative resolutions
447  }
448 }
Namespace for Exception objects.
Definition: Exception.h:57
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
Definition: MIPField.h:258
void clear()
Clears all the levels of the MIP field.
Definition: MIPField.h:379
Imath::V3i V3i
Definition: SpiMathLib.h:71
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:192
void updateAuxMembers() const
Updates the dependent data members based on m_field.
Definition: MIPField.h:620
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition: MIPField.h:264
Imath::V3f V3f
Definition: SpiMathLib.h:73
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
Definition: MIPField.h:668
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:631
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Definition: MIPField.h:267
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
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 471 of file MIPField.h.

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

472 {
473  assert(level < base::m_numLevels);
474  // Ensure level is loaded.
475  if (!m_rawFields[level]) {
476  loadLevelFromDisk(level);
477  }
478  return m_rawFields[level];
479 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition: MIPField.h:641
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 485 of file MIPField.h.

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

486 {
487  assert(level < base::m_numLevels);
488  // Ensure level is loaded.
489  if (!m_rawFields[level]) {
490  loadLevelFromDisk(level);
491  }
492  return m_fields[level];
493 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
Definition: MIPField.h:641
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
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 344 of file MIPField.h.

References MIPField< Field_T >::clone(), field_dynamic_cast(), MIPField< Field_T >::m_fields, MIPField< Field_T >::m_ioMutex, 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(), and MIPField< Field_T >::operator=().

345 {
346  // If any of the fields aren't yet loaded, we can rely on the same load
347  // actions as the other one
349  // Copy all the regular data members
350  m_mipRes = rhs.m_mipRes;
352  // The contained fields must be individually cloned if they have already
353  // been loaded
354  m_fields.resize(rhs.m_fields.size());
355  m_rawFields.resize(rhs.m_rawFields.size());
356  for (size_t i = 0, end = m_fields.size(); i < end; ++i) {
357  // Update the field pointer
358  if (rhs.m_fields[i]) {
359  FieldBase::Ptr baseClone = rhs.m_fields[i]->clone();
360  FieldPtr clone = field_dynamic_cast<Field_T>(baseClone);
361  if (clone) {
362  m_fields[i] = clone;
363  } else {
364  std::cerr << "MIPField::op=(): Failed to clone." << std::endl;
365  }
366  }
367  // Update the raw pointer
368  m_rawFields[i] = m_fields[i].get();
369  }
370  // New mutex
371  m_ioMutex.reset(new boost::mutex);
372  // Done
373  return *this;
374 }
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
boost::intrusive_ptr< FieldBase > Ptr
Definition: Field.h:97
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
Definition: MIPField.h:258
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
Field_T::Ptr FieldPtr
Definition: MIPField.h:130
std::vector< V3i > m_mipRes
Resolution of each MIP level.
Definition: MIPField.h:264
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
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
Definition: MIPField.h:267
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
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
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 631 of file MIPField.h.

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

Referenced by MIPField< Field_T >::setup(), and MIPField< Field_T >::setupLazyLoad().

632 {
633  base::m_extents = field->extents();
634  base::m_dataWindow = field->dataWindow();
635  base::setMapping(field->mapping());
636 }
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:315
void setMapping(FieldMapping::Ptr mapping)
Sets the field&#39;s mapping.
Definition: Field.h:352
Box3i m_extents
Defines the extents of the the storage. This may be larger or smaller than the data window...
Definition: Field.h:312
template<class Field_T >
void MIPField< Field_T >::updateAuxMembers ( ) const
protected

Updates the dependent data members based on m_field.

Definition at line 620 of file MIPField.h.

References MIPField< Field_T >::m_fields, and MIPField< Field_T >::m_rawFields.

Referenced by MIPField< Field_T >::loadLevelFromDisk(), MIPField< Field_T >::setup(), and MIPField< Field_T >::setupLazyLoad().

621 {
622  m_rawFields.resize(m_fields.size());
623  for (size_t i = 0; i < m_fields.size(); i++) {
624  m_rawFields[i] = m_fields[i].get();
625  }
626 }
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
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
template<class Field_T >
void MIPField< Field_T >::loadLevelFromDisk ( size_t  level) const
protected

Loads the given level from disk.

Definition at line 641 of file MIPField.h.

References detail::adjustedMIPFieldMapping(), FieldRes::dataWindow(), FieldRes::extents(), MIPField< Field_T >::m_fields, MIPField< Field_T >::m_ioMutex, MIPField< Field_T >::m_loadActions, MIPField< Field_T >::m_rawFields, FieldRes::mapping(), and MIPField< Field_T >::updateAuxMembers().

Referenced by MIPField< Field_T >::concreteMipLevel(), MIPField< Field_T >::fastMipValue(), MIPField< Field_T >::mipLevel(), MIPField< Field_T >::rawMipLevel(), and MIPField< Field_T >::setupLazyLoad().

642 {
643  // Double-check locking
644  if (!m_rawFields[level]) {
645  boost::mutex::scoped_lock lock(*m_ioMutex);
646  if (!m_rawFields[level]) {
647  // Execute the lazy load action
648  m_fields[level] = m_loadActions[level]->load();
649  // Remove lazy load action
650  m_loadActions[level].reset();
651  // Update aux data
653  // Update the mapping of the loaded field
654  V3i baseRes = base::dataWindow().size() + V3i(1);
657  m_fields[level]->extents(), level);
658  m_fields[level]->setMapping(mapping);
659  }
660  }
661 }
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
Definition: Field.h:254
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
Definition: MIPField.h:258
FIELD3D_API FieldMapping::Ptr adjustedMIPFieldMapping(const FieldMapping::Ptr baseMapping, const V3i &baseRes, const Box3i &extents, const size_t level)
Definition: MIPUtil.cpp:77
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
Definition: MIPField.h:262
Imath::V3i V3i
Definition: SpiMathLib.h:71
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
void updateAuxMembers() const
Updates the dependent data members based on m_field.
Definition: MIPField.h:620
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
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
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:258
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:268
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 668 of file MIPField.h.

References FIELD3D_NAMESPACE_HEADER_CLOSE.

Referenced by MIPField< Field_T >::setup(), and MIPField< Field_T >::setupLazyLoad().

669 {
670  using boost::lexical_cast;
671  using std::string;
672  using Exc::MIPFieldException;
673 
674  // Check zero length
675  if (fields.size() == 0) {
676  throw MIPFieldException("Zero fields in input");
677  }
678  // Check all non-null
679  for (size_t i = 0; i < fields.size(); i++) {
680  if (!fields[i]) {
681  throw MIPFieldException("Found null pointer in input");
682  }
683  }
684  // Check decreasing resolution at higher levels
685  V3i prevSize = fields[0]->extents().size();
686  for (size_t i = 1; i < fields.size(); i++) {
687  V3i size = fields[i]->extents().size();
688  if (size.x > prevSize.x ||
689  size.y > prevSize.y ||
690  size.z > prevSize.z) {
691  throw MIPFieldException("Field " +
692  lexical_cast<string>(i) +
693  " had greater resolution than previous"
694  " level");
695  }
696  if (size.x >= prevSize.x &&
697  size.y >= prevSize.y &&
698  size.z >= prevSize.z) {
699  throw MIPFieldException("Field " +
700  lexical_cast<string>(i) +
701  " did not decrease in resolution from "
702  " previous level");
703  }
704  prevSize = size;
705  }
706  // All good.
707 }
Imath::V3i V3i
Definition: SpiMathLib.h:71

Member Data Documentation

template<class Field_T>
MIPField< Field_T >::FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION

Definition at line 205 of file MIPField.h.

template<class Field_T>
NestedFieldType< MIPField< Field_T > > MIPField< Field_T >::ms_classType
staticprotected
Initial value:

Definition at line 246 of file MIPField.h.

template<class Field_T>
std::vector<FieldPtr> MIPField< Field_T >::m_fields
mutableprotected
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(), MIPField< Field_T >::loadLevelFromDisk(), and MIPField< Field_T >::setupLazyLoad().

template<class Field_T>
std::vector<Field_T*> MIPField< Field_T >::m_rawFields
mutableprotected
template<class Field_T>
std::vector<V3i> MIPField< Field_T >::m_mipRes
mutableprotected
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 >::getVsMIPCoord(), MIPField< Field_T >::init(), MIPField< Field_T >::setup(), and MIPField< Field_T >::setupLazyLoad().

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


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