44 #ifndef _INCLUDED_MIPField_H_ 45 #define _INCLUDED_MIPField_H_ 49 #include <boost/lexical_cast.hpp> 50 #include <boost/thread/mutex.hpp> 108 template <
class Field_T>
115 typedef typename Field_T::value_type
Data_T;
118 typedef boost::intrusive_ptr<MIPField>
Ptr;
119 typedef std::vector<Ptr>
Vec;
156 virtual long long int memSize()
const;
159 virtual void mappingChanged();
167 virtual Data_T value(
int i,
int j,
int k)
const;
168 virtual size_t voxelCount()
const;
188 virtual Data_T mipValue(
size_t level,
int i,
int j,
int k)
const;
190 virtual bool levelLoaded(
const size_t level)
const;
191 virtual void getVsMIPCoord(
const V3f &vsP,
const size_t level,
198 Data_T fastMipValue(
size_t level,
int i,
int j,
int k)
const;
223 void setup(
const FieldVec &fields);
226 void setupLazyLoad(
const ProxyVec &proxies,
230 FieldPtr mipLevel(
const size_t level)
const;
233 const Field_T* rawMipLevel(
const size_t level)
const;
236 typename Field_T::Ptr concreteMipLevel(
const size_t level)
const;
282 void updateAuxMembers()
const;
284 void loadLevelFromDisk(
size_t level)
const;
286 template <
typename T>
287 void sanityChecks(
const T &fields);
295 template <
typename Data_T>
303 template <
typename Data_T>
313 template <
class Field_T>
316 m_ioMutex(new
boost::mutex)
323 template <
class Field_T>
332 template <
class Field_T>
342 template <
class Field_T>
356 for (
size_t i = 0, end =
m_fields.size(); i < end; ++i) {
364 std::cerr <<
"MIPField::op=(): Failed to clone." << std::endl;
378 template <
class Field_T>
389 template <
class Field_T>
406 for (
size_t i = 0; i < fields.size(); i++) {
416 template <
class Field_T>
426 if (proxies.size() != actions.size()) {
427 throw MIPFieldException(
"Incorrect number of lazy load actions");
442 for (
size_t i = 0; i < proxies.size(); i++) {
444 m_mipRes[i] = proxies[i]->extents().size() +
V3i(1);
454 template <
class Field_T>
469 template <
class Field_T>
483 template <
class Field_T>
484 typename Field_T::Ptr
497 template <
class Field_T>
506 template <
class Field_T>
511 for (
size_t i = 0; i <
m_fields.size(); i++) {
521 template <
class Field_T>
524 long long int mem = 0;
525 for (
size_t i = 0; i <
m_fields.size(); i++) {
530 return mem +
sizeof(*this);
535 template <
class Field_T>
542 for (
size_t i = 1; i <
m_fields.size(); i++) {
554 template <
class Field_T>
563 template <
class Field_T>
572 template <
class Field_T>
581 template <
typename Field_T>
590 template <
typename Field_T>
604 template <
class Field_T>
619 template <
class Field_T>
623 for (
size_t i = 0; i <
m_fields.size(); i++) {
630 template <
class Field_T>
640 template <
class Field_T>
645 boost::mutex::scoped_lock lock(*
m_ioMutex);
658 m_fields[level]->setMapping(mapping);
665 template <
class Field_T>
670 using boost::lexical_cast;
672 using Exc::MIPFieldException;
675 if (fields.size() == 0) {
676 throw MIPFieldException(
"Zero fields in input");
679 for (
size_t i = 0; i < fields.size(); i++) {
681 throw MIPFieldException(
"Found null pointer in input");
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" 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 " 713 template <
typename Field_T>
723 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
const Field_T * rawMipLevel(const size_t level) const
Returns a raw pointer to a MIP level.
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...
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...
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
virtual Data_T mipValue(size_t level, int i, int j, int k) const
Read access to a voxel in a given MIP level.
static NestedFieldType< MIPField< Field_T > > ms_classType
Contains the DenseField class.
Namespace for Exception objects.
EmptyField< Data_T > ProxyField
virtual void mappingChanged()
We need to know if the mapping changed so that we may update the MIP levels' mappings.
RefBase & operator=(const RefBase &)
Assignment operator.
boost::intrusive_ptr< FieldBase > Ptr
virtual size_t voxelCount() const
Counts the number of voxels. For most fields, this is just the volume of the data window...
LazyLoadAction< Field_T >::Vec m_loadActions
Lazy load actions. Only used if setupLazyLoad() has been called.
void setupLazyLoad(const ProxyVec &proxies, const typename LazyLoadAction< Field_T >::Vec &actions)
Sets up the MIP field in lazy-load mode.
Contains the EmptyField class.
FIELD3D_API FieldMapping::Ptr adjustedMIPFieldMapping(const FieldMapping::Ptr baseMapping, const V3i &baseRes, const Box3i &extents, const size_t level)
boost::intrusive_ptr< FieldRes > Ptr
CubicMIPFieldInterp< Data_T > CubicInterp
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...
This subclass stores a MIP representation of a Field_T field.
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
boost::intrusive_ptr< MIPField > Ptr
std::vector< Field_T * > m_rawFields
Raw pointers to MIP levels.
void clear()
Clears all the levels of the MIP field.
const MIPField & operator=(const MIPField &rhs)
Assignment operator.
Contains MIPInterp class.
MIPField()
Constructs an empty MIP field.
Field_T::value_type Data_T
boost::intrusive_ptr< FieldMapping > Ptr
static DEFINE_FIELD_RTTI_CONCRETE_CLASS const char * staticClassName()
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
This subclass of Field does not store any data.
size_t m_lowestLevel
The lowest MIP level to use. Defaults to 0, but can be set higher to prevent high resolution levels f...
void updateAuxMembers() const
Updates the dependent data members based on m_field.
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
virtual Data_T value(int i, int j, int k) const
Read access to a voxel. The coordinates are in integer voxel space .
std::vector< V3i > m_mipRes
Resolution of each MIP level.
boost::intrusive_ptr< EmptyField > Ptr
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
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...
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
Box3i m_extents
Defines the extents of the the storage. This may be larger or smaller than the data window...
void updateMapping(FieldRes::Ptr field)
Updates the mapping, extents and data window to match the given field. Used so that the MIPField will...
size_t m_numLevels
Number of MIP levels. The default is 1.
#define DECLARE_FIELD3D_GENERIC_EXCEPTION(name, base_class)
Used to declare a generic but named exception.
static const char * staticClassType()
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
std::vector< FieldPtr > FieldVec
virtual V3i mipResolution(size_t level) const
Returns the resolution of a given MIP level.
Contains MIP-related utility functions.
virtual long long int memSize() const
Returns the memory usage (in bytes)
FIELD3D_API V3i mipResolution(const V3i &baseRes, const size_t level)
Contains the SparseField class.
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 ...
#define DEFINE_FIELD_RTTI_CONCRETE_CLASS
Data_T fastMipValue(size_t level, int i, int j, int k) const
Read access to voxel at a given MIP level.
MIPField< Field_T > class_type
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
Used to return a string for the name of a nested templated field.
Field_T::Ptr concreteMipLevel(const size_t level) const
Returns a concretely typed pointer to a MIP level.
virtual Field< Data_T >::Ptr mipLevel(const size_t level) const
Returns a MIP level field.
std::vector< ProxyPtr > ProxyVec
MIPLinearInterp< MIPField< Field_T > > LinearInterp
boost::intrusive_ptr< Field > Ptr
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
virtual bool levelLoaded(const size_t level) const
Whether a given MIP level is loaded.
std::string name
Optional name of the field.
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...