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 syncLevelInfo(
const size_t level)
const;
286 void loadLevelFromDisk(
size_t level)
const;
288 template <
typename T>
289 void sanityChecks(
const T &fields);
297 template <
typename Data_T>
309 template <
typename Data_T>
323 template <
class Field_T>
326 m_ioMutex(new
boost::mutex)
333 template <
class Field_T>
342 template <
class Field_T>
352 template <
class Field_T>
366 for (
size_t i = 0, end =
m_fields.size(); i < end; ++i) {
374 std::cerr <<
"MIPField::op=(): Failed to clone." << std::endl;
388 template <
class Field_T>
399 template <
class Field_T>
416 for (
size_t i = 0; i < fields.size(); i++) {
426 template <
class Field_T>
436 if (proxies.size() != actions.size()) {
437 throw MIPFieldException(
"Incorrect number of lazy load actions");
452 for (
size_t i = 0; i < proxies.size(); i++) {
454 m_mipRes[i] = proxies[i]->extents().size() +
V3i(1);
464 template <
class Field_T>
479 template <
class Field_T>
494 template <
class Field_T>
495 typename Field_T::Ptr
509 template <
class Field_T>
518 template <
class Field_T>
523 for (
size_t i = 0; i <
m_fields.size(); i++) {
533 template <
class Field_T>
536 long long int mem = 0;
537 for (
size_t i = 0; i <
m_fields.size(); i++) {
542 return mem +
sizeof(*this);
547 template <
class Field_T>
559 for (
size_t i = 1; i <
m_fields.size(); i++) {
571 template <
class Field_T>
580 template <
class Field_T>
589 template <
class Field_T>
598 template <
typename Field_T>
605 const V3i offset((mipOff.x >> level) << level,
606 (mipOff.y >> level) << level,
607 (mipOff.z >> level) << level);
611 const V3f diff = offset - mipOff;
614 outVsP = (vsP - diff) * pow(2.0, -static_cast<float>(level));
619 template <
typename Field_T>
634 template <
class Field_T>
649 template <
class Field_T>
653 for (
size_t i = 0; i <
m_fields.size(); i++) {
660 template <
class Field_T>
669 m_fields[level]->copyMetadata(*
this);
674 template <
class Field_T>
684 template <
class Field_T>
689 boost::mutex::scoped_lock lock(*
m_ioMutex);
695 throw Exc::MIPFieldException(
"Couldn't load MIP level: " +
696 boost::lexical_cast<std::string>(level));
709 m_fields[level]->setMapping(mapping);
716 template <
class Field_T>
721 using boost::lexical_cast;
723 using Exc::MIPFieldException;
726 if (fields.size() == 0) {
727 throw MIPFieldException(
"Zero fields in input");
730 for (
size_t i = 0; i < fields.size(); i++) {
732 throw MIPFieldException(
"Found null pointer in input");
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" 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));
764 template <
typename Field_T>
774 #endif // Include guard virtual V3i mipResolution(size_t level) const
Returns the resolution of a given MIP level.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
FIELD3D_API V3i mipResolution(const V3i &baseRes, const size_t level, const V3i &add)
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...
static NestedFieldType< MIPField< Field_T > > ms_classType
Contains the DenseField class.
Namespace for Exception objects.
EmptyField< Data_T > ProxyField
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
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.
Data_T fastMipValue(size_t level, int i, int j, int k) const
Read access to voxel at a given MIP level.
boost::intrusive_ptr< FieldBase > Ptr
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.
virtual Data_T mipValue(size_t level, int i, int j, int k) const
Read access to a voxel in a given MIP level.
Contains the EmptyField class.
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
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
static DEFINE_FIELD_RTTI_CONCRETE_CLASS const char * staticClassName()
virtual size_t voxelCount() const
Counts the number of voxels. For most fields, this is just the volume of the data window...
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
virtual Data_T value(int i, int j, int k) const
Read access to a voxel. The coordinates are in integer voxel space .
FIELD3D_API FieldMapping::Ptr adjustedMIPFieldMapping(const FieldRes *base, const V3i &baseRes, const Box3i &extents, const size_t level)
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
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...
const Field_T * rawMipLevel(const size_t level) const
Returns a raw pointer to a MIP level.
void updateAuxMembers() const
Updates the dependent data members based on m_field.
const MIPField & init(const MIPField &rhs)
Copies from a second MIPField.
const V3i & mipOffset() const
Returns the base MIP offset.
std::vector< V3i > m_mipRes
Resolution of each MIP level.
void loadLevelFromDisk(size_t level) const
Loads the given level from disk.
boost::intrusive_ptr< EmptyField > Ptr
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
virtual Field< Data_T >::Ptr mipLevel(const size_t level) const
Returns a MIP level field.
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...
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...
void sanityChecks(const T &fields)
Sanity checks to ensure that the provided Fields are a MIP representation.
virtual long long int memSize() const
Returns the memory usage (in bytes)
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...
FieldMetadata & metadata()
accessor to the m_metadata class
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()
void syncLevelInfo(const size_t level) const
Updates the name, attribute and metadata for a given level.
std::vector< V3f > m_relativeResolution
Relative resolution of each MIP level. Pre-computed to avoid int-to-float conversions.
std::string attribute
Optional name of the attribute the field represents.
Field_T::Ptr concreteMipLevel(const size_t level) const
Returns a concretely typed pointer to a MIP level.
std::vector< FieldPtr > FieldVec
Contains MIP-related utility functions.
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
Contains the SparseField class.
virtual bool levelLoaded(const size_t level) const
Whether a given MIP level is loaded.
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
const std::string k_mipOffsetStr
MIPField< Field_T > class_type
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.
Used to return a string for the name of a nested templated field.
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
std::vector< ProxyPtr > ProxyVec
MIPLinearInterp< MIPField< Field_T > > LinearInterp
boost::intrusive_ptr< Field > Ptr
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
std::string name
Optional name of the field.