Field.h
Go to the documentation of this file.
//----------------------------------------------------------------------------//
/*
* Copyright (c) 2009 Sony Pictures Imageworks Inc
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution. Neither the name of Sony Pictures Imageworks nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifndef _INCLUDED_Field3D_Field_H_
#define _INCLUDED_Field3D_Field_H_
#include <cmath>
#include <vector>
#include <map>
#include <boost/intrusive_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include "Traits.h"
#include "Exception.h"
#include "FieldMapping.h"
#include "FieldMetadata.h"
#include "Log.h"
#include "RefCount.h"
#include "Types.h"
//----------------------------------------------------------------------------//
#include "ns.h"
FIELD3D_NAMESPACE_OPEN
//----------------------------------------------------------------------------//
// Exceptions
//----------------------------------------------------------------------------//
namespace Exc {
DECLARE_FIELD3D_GENERIC_EXCEPTION(MemoryException, Exception)
DECLARE_FIELD3D_GENERIC_EXCEPTION(ResizeException, Exception)
} // namespace Exc
//----------------------------------------------------------------------------//
// FieldBase
//----------------------------------------------------------------------------//
class FIELD3D_API FieldBase : public RefBase, public MetadataCallback
{
public:
// Typedefs ------------------------------------------------------------------
typedef boost::intrusive_ptr<FieldBase> Ptr;
typedef FieldBase class_type;
// Constructors --------------------------------------------------------------
FieldBase();
FieldBase(const FieldBase &);
virtual ~FieldBase();
// RTTI replacement ----------------------------------------------------------
static const char *staticClassName()
{
return "FieldBase";
}
static const char* staticClassType()
{
return staticClassName();
}
// To be implemented by subclasses -------------------------------------------
virtual std::string className() const = 0;
virtual std::string classType() const = 0;
virtual Ptr clone() const = 0;
// Access to metadata --------------------------------------------------------
FieldMetadata& metadata()
{ return m_metadata; }
const FieldMetadata& metadata() const
{ return m_metadata; }
void copyMetadata(const FieldBase &field)
{ m_metadata = field.metadata(); }
// Public data members -------------------------------------------------------
std::string name;
std::string attribute;
private:
// Private data members ------------------------------------------------------
FieldMetadata m_metadata;
};
//----------------------------------------------------------------------------//
// FieldRes
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
class FieldRes : public FieldBase
{
public:
// Typedefs ------------------------------------------------------------------
typedef boost::intrusive_ptr<FieldRes> Ptr;
typedef std::vector<Ptr> Vec;
// RTTI replacement ----------------------------------------------------------
typedef FieldRes class_type;
DEFINE_FIELD_RTTI_ABSTRACT_CLASS;
virtual std::string dataTypeString() const
{ return std::string("FieldRes"); }
static const char *staticClassName()
{
return "FieldRes";
}
static const char *staticClassType()
{
return staticClassName();
}
// Ctor, dtor ----------------------------------------------------------------
FieldRes();
FieldRes(const FieldRes &src);
// Main methods --------------------------------------------------------------
inline const Box3i& extents() const
{ return m_extents; }
inline const Box3i& dataWindow() const
{ return m_dataWindow; }
inline V3i const dataResolution() const
{ return m_dataWindow.max - m_dataWindow.min + V3i(1); }
void setMapping(FieldMapping::Ptr mapping);
FieldMapping::Ptr mapping()
{ return m_mapping; }
const FieldMapping::Ptr mapping() const
{ return m_mapping; }
bool isInBounds(int i, int j, int k) const;
// To be implemented by subclasses -------------------------------------------
virtual long long int memSize() const
{ return sizeof(*this); }
virtual void mappingChanged()
{ /* Empty */ }
virtual size_t voxelCount() const
{
V3i res = m_dataWindow.size() + V3i(1);
return res.x * res.y * res.z;
}
protected:
// Typedefs ------------------------------------------------------------------
typedef MatrixFieldMapping default_mapping;
// Data members --------------------------------------------------------------
Box3i m_extents;
Box3i m_dataWindow;
FieldMapping::Ptr m_mapping;
private:
// Typedefs ------------------------------------------------------------------
typedef FieldBase base;
};
//----------------------------------------------------------------------------//
inline FieldRes::FieldRes()
: m_mapping(new default_mapping)
{
m_extents = Box3i(V3i(0), V3i(-1));
m_dataWindow = m_extents;
m_mapping->setExtents(m_extents);
}
//----------------------------------------------------------------------------//
inline FieldRes::FieldRes(const FieldRes &src)
: FieldBase(src)
{
// Call base class first
// FieldBase(src);
// Copy self
*this = src;
m_mapping = src.mapping()->clone();
}
//----------------------------------------------------------------------------//
inline void FieldRes::setMapping(FieldMapping::Ptr mapping)
{
if (mapping) {
m_mapping = mapping->clone();
m_mapping->setExtents(m_extents);
} else {
Msg::print(Msg::SevWarning,
"Tried to call FieldRes::setMapping with null pointer");
}
// Tell subclasses about the mapping change
mappingChanged();
}
//----------------------------------------------------------------------------//
inline bool FieldRes::isInBounds(int i, int j, int k) const
{
// Check bounds
if (i < m_dataWindow.min.x || i > m_dataWindow.max.x ||
j < m_dataWindow.min.y || j > m_dataWindow.max.y ||
k < m_dataWindow.min.z || k > m_dataWindow.max.z) {
return false;
}
return true;
}
//----------------------------------------------------------------------------//
// Field
//----------------------------------------------------------------------------//
template <class Data_T>
class Field : public FieldRes
{
public:
// Typedefs ------------------------------------------------------------------
typedef boost::intrusive_ptr<Field> Ptr;
typedef Data_T value_type;
typedef std::vector<Ptr> Vec;
// RTTI replacement ----------------------------------------------------------
typedef Field<Data_T> class_type;
DEFINE_FIELD_RTTI_ABSTRACT_CLASS;
static const char *staticClassName()
{
return "Field";
}
static const char* staticClassType()
{
return Field<Data_T>::ms_classType.name();
}
// Constructors --------------------------------------------------------------
virtual ~Field()
{ /* Empty */ }
// Iterators -----------------------------------------------------------------
class const_iterator;
const_iterator cbegin() const;
const_iterator cbegin(const Box3i &subset) const;
const_iterator cend() const;
const_iterator cend(const Box3i &subset) const;
// To be implemented by subclasses -------------------------------------------
virtual Data_T value(int i, int j, int k) const = 0;
// Other member functions ----------------------------------------------------
virtual std::string dataTypeString() const
{ return DataTypeTraits<Data_T>::name(); }
private:
// Static data members -------------------------------------------------------
static TemplatedFieldType<Field<Data_T> > ms_classType;
// Typedefs ------------------------------------------------------------------
typedef FieldRes base;
};
//----------------------------------------------------------------------------//
#define FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION \
virtual std::string className() const \
{ return staticClassName(); } \
virtual std::string classType() const \
{ return staticClassType(); } \
#define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field) \
template <typename Data_T> \
TemplatedFieldType<field<Data_T> > field<Data_T>::ms_classType = \
TemplatedFieldType<field<Data_T> >(); \
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(Field);
//----------------------------------------------------------------------------//
// Field::const_iterator
//----------------------------------------------------------------------------//
template <class Data_T>
class Field<Data_T>::const_iterator
{
public:
#if defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
typedef std::forward_iterator_tag iterator_category;
typedef Data_T value_type;
typedef ptrdiff_t difference_type;
typedef ptrdiff_t distance_type;
typedef Data_T *pointer;
typedef Data_T& reference;
#endif
// Constructors --------------------------------------------------------------
const_iterator(const const_iterator &i)
: x(i.x), y(i.y), z(i.z),
m_window(i.m_window), m_field(i.m_field)
{ }
const_iterator(const Field<Data_T> &field, const Box3i &window,
const V3i &currentPos)
: x(currentPos.x), y(currentPos.y), z(currentPos.z),
m_window(window), m_field(field)
{ }
// Operators -----------------------------------------------------------------
inline const const_iterator& operator ++ ()
{
if (x == m_window.max.x) {
if (y == m_window.max.y) {
x = m_window.min.x;
y = m_window.min.y;
++z;
} else {
x = m_window.min.x;
++y;
}
} else {
++x;
}
return *this;
}
template <class Iter_T>
bool operator == (const Iter_T &rhs) const
{
return x == rhs.x && y == rhs.y && z == rhs.z;
}
template <class Iter_T>
bool operator != (const Iter_T &rhs) const
{
return x != rhs.x || y != rhs.y || z != rhs.z;
}
inline Data_T operator * () const
{
return m_field.value(x, y, z);
}
// Public data members -------------------------------------------------------
int x, y, z;
private:
// Private data members ------------------------------------------------------
Box3i m_window;
const Field<Data_T> &m_field;
};
//----------------------------------------------------------------------------//
template <class Data_T>
typename Field<Data_T>::const_iterator
Field<Data_T>::cbegin() const
{
if (FieldRes::dataResolution() == V3i(0))
return cend();
return const_iterator(*this, m_dataWindow, m_dataWindow.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename Field<Data_T>::const_iterator
Field<Data_T>::cbegin(const Box3i &subset) const
{
if (subset.isEmpty())
return cend(subset);
return const_iterator(*this, subset, subset.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename Field<Data_T>::const_iterator
Field<Data_T>::cend() const
{
return const_iterator(*this, m_dataWindow,
V3i(m_dataWindow.min.x,
m_dataWindow.min.y,
m_dataWindow.max.z + 1));
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename Field<Data_T>::const_iterator
Field<Data_T>::cend(const Box3i &subset) const
{
return const_iterator(*this, subset, V3i(subset.min.x,
subset.min.y,
subset.max.z + 1));
}
//----------------------------------------------------------------------------//
// WritableField
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
template <class Data_T>
class WritableField
: public Field<Data_T>
{
public:
// Typedefs ------------------------------------------------------------------
typedef boost::intrusive_ptr<WritableField> Ptr;
// RTTI replacement ----------------------------------------------------------
typedef WritableField<Data_T> class_type;
DEFINE_FIELD_RTTI_ABSTRACT_CLASS;
static const char *staticClassName()
{
return "WritableField";
}
static const char* staticClassType()
{
return WritableField<Data_T>::ms_classType.name();
}
// Iterators -----------------------------------------------------------------
class iterator;
inline iterator begin();
inline iterator begin(const Box3i &subset);
inline iterator end();
inline iterator end(const Box3i &subset);
// To be implemented by subclasses -------------------------------------------
virtual Data_T& lvalue(int i, int j, int k) = 0;
// Main methods --------------------------------------------------------------
virtual void clear(const Data_T &value)
{ std::fill(begin(), end(), value); }
private:
// Static data members -------------------------------------------------------
static TemplatedFieldType<WritableField<Data_T> > ms_classType;
// Typedefs ------------------------------------------------------------------
typedef Field<Data_T> base;
};
//----------------------------------------------------------------------------//
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(WritableField);
//----------------------------------------------------------------------------//
// WritableField::iterator
//----------------------------------------------------------------------------//
template <class Data_T>
class WritableField<Data_T>::iterator
{
public:
#if defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
typedef std::forward_iterator_tag iterator_category;
typedef Data_T value_type;
typedef ptrdiff_t difference_type;
typedef ptrdiff_t distance_type;
typedef Data_T *pointer;
typedef Data_T& reference;
#endif
// Constructors --------------------------------------------------------------
iterator(WritableField<Data_T> &field, const Box3i &window,
const V3i &currentPos)
: x(currentPos.x), y(currentPos.y), z(currentPos.z),
m_window(window), m_field(field)
{ }
// Operators -----------------------------------------------------------------
inline const iterator& operator ++ ()
{
if (x == m_window.max.x) {
if (y == m_window.max.y) {
x = m_window.min.x;
y = m_window.min.y;
++z;
} else {
x = m_window.min.x;
++y;
}
} else {
++x;
}
return *this;
}
template <class Iter_T>
bool operator == (const Iter_T &rhs) const
{
return x == rhs.x && y == rhs.y && z == rhs.z;
}
template <class Iter_T>
bool operator != (const Iter_T &rhs) const
{
return x != rhs.x || y != rhs.y || z != rhs.z;
}
inline Data_T& operator * () const
{
return m_field.lvalue(x, y, z);
}
// Public data members -------------------------------------------------------
int x, y, z;
private:
// Private data members ------------------------------------------------------
Box3i m_window;
WritableField<Data_T> &m_field;
};
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename WritableField<Data_T>::iterator
WritableField<Data_T>::begin()
{
if (FieldRes::dataResolution() == V3i(0))
return end();
return iterator(*this, Field<Data_T>::m_dataWindow,
Field<Data_T>::m_dataWindow.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename WritableField<Data_T>::iterator
WritableField<Data_T>::begin(const Box3i &subset)
{
if (subset.isEmpty())
return end(subset);
return iterator(*this, subset, subset.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename WritableField<Data_T>::iterator
WritableField<Data_T>::end()
{ return iterator(*this, Field<Data_T>::m_dataWindow,
V3i(Field<Data_T>::m_dataWindow.min.x,
Field<Data_T>::m_dataWindow.min.y,
Field<Data_T>::m_dataWindow.max.z + 1));
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename WritableField<Data_T>::iterator
WritableField<Data_T>::end(const Box3i &subset)
{ return iterator(*this, subset,
V3i(subset.min.x, subset.min.y, subset.max.z + 1));
}
//----------------------------------------------------------------------------//
// ResizableField
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
template <class Data_T>
class ResizableField
: public WritableField<Data_T>
{
public:
// Typedefs ------------------------------------------------------------------
typedef boost::intrusive_ptr<ResizableField> Ptr;
// RTTI replacement ----------------------------------------------------------
typedef ResizableField<Data_T> class_type;
DEFINE_FIELD_RTTI_ABSTRACT_CLASS;
static const char *staticClassName()
{
return "ResizableField";
}
static const char* staticClassType()
{
return ResizableField<Data_T>::ms_classType.name();
}
// Main methods --------------------------------------------------------------
void setSize(const V3i &size);
void setSize(const Box3i &extents);
void setSize(const Box3i &extents, const Box3i &dataWindow);
void setSize(const V3i &size, int padding);
void copyFrom(typename Field<Data_T>::Ptr other);
template <class Data_T2>
void copyFrom(typename Field<Data_T2>::Ptr other);
void matchDefinition(FieldRes::Ptr fieldToMatch);
protected:
// Static data members -------------------------------------------------------
static TemplatedFieldType<ResizableField<Data_T> > ms_classType;
// Typedefs ------------------------------------------------------------------
typedef WritableField<Data_T> base;
// To be implemented by subclasses -------------------------------------------
virtual void sizeChanged()
{ base::m_mapping->setExtents(base::m_extents); }
};
//----------------------------------------------------------------------------//
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(ResizableField);
//----------------------------------------------------------------------------//
template <class Data_T>
void ResizableField<Data_T>::setSize(const V3i &size)
{
assert(size.x >= 0);
assert(size.y >= 0);
assert(size.z >= 0);
Field<Data_T>::m_extents.min = V3i(0);
Field<Data_T>::m_extents.max = size - V3i(1);
Field<Data_T>::m_dataWindow = Field<Data_T>::m_extents;
// Tell subclasses that the size changed so they can update themselves.
sizeChanged();
}
//----------------------------------------------------------------------------//
template <class Data_T>
void ResizableField<Data_T>::setSize(const Box3i &extents)
{
Field<Data_T>::m_extents = extents;
Field<Data_T>::m_dataWindow = extents;
// Tell subclasses that the size changed so they can update themselves.
sizeChanged();
}
//----------------------------------------------------------------------------//
template <class Data_T>
void ResizableField<Data_T>::setSize(const Box3i &extents,
const Box3i &dataWindow)
{
Field<Data_T>::m_extents = extents;
Field<Data_T>::m_dataWindow = dataWindow;
// Tell subclasses that the size changed so they can update themselves.
sizeChanged();
}
//----------------------------------------------------------------------------//
template <class Data_T>
void ResizableField<Data_T>::setSize(const V3i &size, int padding)
{
assert(size.x >= 0);
assert(size.y >= 0);
assert(size.z >= 0);
assert(padding >= 0);
setSize(Box3i(V3i(0), size - V3i(1)),
Box3i(V3i(-padding), size + V3i(padding - 1)));
}
//----------------------------------------------------------------------------//
template <class Data_T>
void ResizableField<Data_T>::copyFrom(typename Field<Data_T>::Ptr other)
{
// Set mapping
FieldRes::setMapping(other->mapping());
// Set size to match
setSize(other->extents(), other->dataWindow());
// Copy over the data
typename base::iterator i = base::begin();
typename base::iterator end = base::end();
typename Field<Data_T>::const_iterator c = other->cbegin();
for (; i != end; ++i, ++c)
*i = *c;
}
//----------------------------------------------------------------------------//
template <class Data_T>
template <class Data_T2>
void ResizableField<Data_T>::copyFrom(typename Field<Data_T2>::Ptr other)
{
// Set mapping
FieldRes::setMapping(other->mapping());
// Set size to match
setSize(other->extents(), other->dataWindow());
// Copy over the data
typename base::iterator i = base::begin();
typename base::iterator end = base::end();
typename Field<Data_T2>::const_iterator c = other->cbegin();
for (; i != end; ++i, ++c)
*i = *c;
}
//----------------------------------------------------------------------------//
template <class Data_T>
void ResizableField<Data_T>::matchDefinition(FieldRes::Ptr fieldToMatch)
{
setSize(fieldToMatch->extents(), fieldToMatch->dataWindow());
FieldRes::setMapping(fieldToMatch->mapping());
}
//----------------------------------------------------------------------------//
// Field-related utility functions
//----------------------------------------------------------------------------//
template <class Data_T, class Data_T2>
bool sameDefinition(typename Field<Data_T>::Ptr a,
typename Field<Data_T2>::Ptr b,
double tolerance = 0.0)
{
if (a->extents() != b->extents()) {
return false;
}
if (a->dataWindow() != b->dataWindow()) {
return false;
}
if (!a->mapping()->isIdentical(b->mapping(), tolerance)) {
return false;
}
return true;
}
//----------------------------------------------------------------------------//
template <class Data_T>
bool isIdentical(typename Field<Data_T>::Ptr a, typename Field<Data_T>::Ptr b)
{
if (!sameDefinition<Data_T, Data_T>(a, b)) {
return false;
}
// If data window is the same, we can safely assume that the range of
// both fields' iterators are the same.
typename Field<Data_T>::const_iterator is1 = a->cbegin();
typename Field<Data_T>::const_iterator is2 = b->cbegin();
typename Field<Data_T>::const_iterator ie1 = a->cend();
bool same = true;
for (; is1 != ie1; ++is1, ++is2) {
if (*is1 != *is2) {
same = false;
break;
}
}
return same;
}
//----------------------------------------------------------------------------//
inline int contToDisc(double contCoord)
{
return static_cast<int>(std::floor(contCoord));
}
//----------------------------------------------------------------------------//
inline double discToCont(int discCoord)
{
return static_cast<double>(discCoord) + 0.5;
}
//----------------------------------------------------------------------------//
inline V2i contToDisc(const V2d &contCoord)
{
return V2i(contToDisc(contCoord.x), contToDisc(contCoord.y));
}
//----------------------------------------------------------------------------//
inline V2d discToCont(const V2i &discCoord)
{
return V2d(discToCont(discCoord.x), discToCont(discCoord.y));
}
//----------------------------------------------------------------------------//
inline V3i contToDisc(const V3d &contCoord)
{
return V3i(contToDisc(contCoord.x), contToDisc(contCoord.y),
contToDisc(contCoord.z));
}
//----------------------------------------------------------------------------//
inline V3d discToCont(const V3i &discCoord)
{
return V3d(discToCont(discCoord.x), discToCont(discCoord.y),
discToCont(discCoord.z));
}
//----------------------------------------------------------------------------//
inline Box3d continuousBounds(const Box3i &bbox)
{
Box3d result;
result.min.x = static_cast<float>(bbox.min.x);
result.min.y = static_cast<float>(bbox.min.y);
result.min.z = static_cast<float>(bbox.min.z);
result.max.x = static_cast<float>(bbox.max.x + 1);
result.max.y = static_cast<float>(bbox.max.y + 1);
result.max.z = static_cast<float>(bbox.max.z + 1);
return result;
}
//----------------------------------------------------------------------------//
inline Box3i discreteBounds(const Box3d &bbox)
{
using std::floor;
using std::ceil;
Box3i result;
result.min.x = static_cast<int>(floor(clampForType<double, int>(bbox.min.x)));
result.min.y = static_cast<int>(floor(clampForType<double, int>(bbox.min.y)));
result.min.z = static_cast<int>(floor(clampForType<double, int>(bbox.min.z)));
result.max.x = static_cast<int>(ceil(clampForType<double, int>(bbox.max.x)));
result.max.y = static_cast<int>(ceil(clampForType<double, int>(bbox.max.y)));
result.max.z = static_cast<int>(ceil(clampForType<double, int>(bbox.max.z)));
return result;
}
//----------------------------------------------------------------------------//
inline Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
{
Box3i result;
result.min.x = std::max(bbox.min.x, bounds.min.x);
result.min.y = std::max(bbox.min.y, bounds.min.y);
result.min.z = std::max(bbox.min.z, bounds.min.z);
result.max.x = std::min(bbox.max.x, bounds.max.x);
result.max.y = std::min(bbox.max.y, bounds.max.y);
result.max.z = std::min(bbox.max.z, bounds.max.z);
return result;
}
//----------------------------------------------------------------------------//
template <class Iter_T>
void advance(Iter_T &iter, int num)
{
if (num <= 0) {
return;
}
for (int i=0; i<num; ++i, ++iter) {
// Empty
}
}
//----------------------------------------------------------------------------//
template <class Iter_T>
void advance(Iter_T &iter, int num, const Iter_T &end)
{
if (num <= 0) {
return;
}
for (int i=0; i<num && iter != end; ++i, ++iter) {
// Empty
}
}
//----------------------------------------------------------------------------//
inline V3i indexToCoord(const size_t idx, const V3i &res)
{
const int i = idx % res.x;
const int j = (idx / res.x) % res.y;
const int k = idx / (res.x * res.y);
return V3i(i, j, k);
}
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_HEADER_CLOSE
//----------------------------------------------------------------------------//
#endif // Include guard
Exception.h
Contains Exception base class.
DECLARE_FIELD3D_GENERIC_EXCEPTION
#define DECLARE_FIELD3D_GENERIC_EXCEPTION(name, base_class)
Used to declare a generic but named exception.
Definition Exception.h:107
operator*
FIELD3D_VEC3_T< T > operator*(S s, const FIELD3D_VEC3_T< T > vec)
Scalar times Vec3 multiplication. Makes the interpolation calls cleaner.
Definition FieldInterp.h:1558
FieldMapping.h
Contains the FieldMapping base class and the NullFieldMapping and MatrixFieldMapping subclasses.
FieldMetadata.h
Basic container for metedata.
continuousBounds
Box3d continuousBounds(const Box3i &bbox)
Definition Field.h:1111
contToDisc
int contToDisc(double contCoord)
Goes from continuous coordinates to discrete coordinates See Graphics Gems - What is a pixel.
Definition Field.h:1061
discreteBounds
Box3i discreteBounds(const Box3d &bbox)
Converts a floating point bounding box to an integer bounding box.
Definition Field.h:1128
clipBounds
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Definition Field.h:1145
sameDefinition
bool sameDefinition(typename Field< Data_T >::Ptr a, typename Field< Data_T2 >::Ptr b, double tolerance=0.0)
Checks whether the mapping and resolution in two different fields are identical.
Definition Field.h:1016
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION
#define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field)
Definition Field.h:479
discToCont
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel.
Definition Field.h:1070
isIdentical
bool isIdentical(typename Field< Data_T >::Ptr a, typename Field< Data_T >::Ptr b)
Checks whether the span and data in two different fields are identical.
Definition Field.h:1037
indexToCoord
V3i indexToCoord(const size_t idx, const V3i &res)
Definition Field.h:1187
Log.h
Contains the Log class which can be used to redirect output to an arbitrary destination.
RefCount.h
Contains base class for reference counting with Mutex.
V2i
Imath::V2i V2i
Definition SpiMathLib.h:65
V2d
Imath::V2d V2d
Definition SpiMathLib.h:67
Box3d
Imath::Box3d Box3d
Definition SpiMathLib.h:79
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
V3d
Imath::V3d V3d
Definition SpiMathLib.h:74
Box3i
Imath::Box3i Box3i
Definition SpiMathLib.h:77
Traits.h
Types.h
Contains typedefs for the commonly used types in Field3D.
clampForType
To_T clampForType(const From_T v)
Definition Types.h:94
Exc::Exception
Definition Exception.h:74
FieldBase::clone
virtual Ptr clone() const =0
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
FieldBase::class_type
FieldBase class_type
Definition Field.h:98
FieldBase::Ptr
boost::intrusive_ptr< FieldBase > Ptr
Definition Field.h:97
FieldBase::className
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.
FieldBase::FieldBase
FieldBase()
Constructor.
Definition Field.cpp:54
FieldBase::metadata
const FieldMetadata & metadata() const
Read only access to the m_metadata class.
Definition Field.h:159
FieldBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field.h:155
FieldBase::staticClassName
static const char * staticClassName()
Definition Field.h:118
FieldBase::staticClassType
static const char * staticClassType()
Definition Field.h:123
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition Field.h:173
FieldBase::copyMetadata
void copyMetadata(const FieldBase &field)
Copies the metadata from a second field.
Definition Field.h:163
FieldBase::classType
virtual std::string classType() const =0
Returns the full class type string.
FieldBase::m_metadata
FieldMetadata m_metadata
metadata
Definition Field.h:180
FieldBase::name
std::string name
Optional name of the field.
Definition Field.h:171
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92
FieldMetadata
Definition FieldMetadata.h:85
FieldRes
Definition Field.h:208
FieldRes::class_type
FieldRes class_type
Definition Field.h:218
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::staticClassType
static const char * staticClassType()
Definition Field.h:229
FieldRes::dataResolution
V3i const dataResolution() const
Definition Field.h:256
FieldRes::dataTypeString
virtual std::string dataTypeString() const
Definition Field.h:221
FieldRes::setMapping
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition Field.h:347
FieldRes::base
FieldBase base
Convenience typedef for referring to base class.
Definition Field.h:319
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition Field.h:213
FieldRes::voxelCount
virtual size_t voxelCount() const
Counts the number of voxels. For most fields, this is just the volume of the data window,...
Definition Field.h:289
FieldRes::mapping
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition Field.h:263
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
FieldRes::default_mapping
MatrixFieldMapping default_mapping
Definition Field.h:299
FieldRes::DEFINE_FIELD_RTTI_ABSTRACT_CLASS
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition Field.h:219
FieldRes::memSize
virtual long long int memSize() const
Returns the memory usage (in bytes).
Definition Field.h:279
FieldRes::mapping
const FieldMapping::Ptr mapping() const
Returns a pointer to the mapping.
Definition Field.h:267
FieldRes::m_mapping
FieldMapping::Ptr m_mapping
Pointer to the field's mapping.
Definition Field.h:312
FieldRes::FieldRes
FieldRes()
This constructor ensures that we have a valid mapping at all times.
Definition Field.h:325
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
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
FieldRes::isInBounds
bool isInBounds(int i, int j, int k) const
Returns true is the indicies are in bounds of the data window.
Definition Field.h:362
FieldRes::Vec
std::vector< Ptr > Vec
Definition Field.h:214
FieldRes::mappingChanged
virtual void mappingChanged()
Tells the subclass that the mapping changed.
Definition Field.h:283
FieldRes::staticClassName
static const char * staticClassName()
Definition Field.h:224
Field::const_iterator
Definition Field.h:492
Field::const_iterator::y
int y
Definition Field.h:552
Field::const_iterator::x
int x
Current position.
Definition Field.h:552
Field::const_iterator::m_field
const Field< Data_T > & m_field
Reference to field being iterated over.
Definition Field.h:561
Field::const_iterator::m_window
Box3i m_window
Window to traverse.
Definition Field.h:559
Field::const_iterator::z
int z
Definition Field.h:552
Field::const_iterator::const_iterator
const_iterator(const const_iterator &i)
Definition Field.h:506
Field::const_iterator::const_iterator
const_iterator(const Field< Data_T > &field, const Box3i &window, const V3i &currentPos)
Definition Field.h:511
Field
Definition Field.h:390
Field::ms_classType
static TemplatedFieldType< Field< Data_T > > ms_classType
Definition Field.h:462
Field::DEFINE_FIELD_RTTI_ABSTRACT_CLASS
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition Field.h:408
Field::Vec
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition Field.h:403
Field::dataTypeString
virtual std::string dataTypeString() const
Definition Field.h:454
Field::staticClassType
static const char * staticClassType()
Definition Field.h:415
Field::Ptr
boost::intrusive_ptr< Field > Ptr
Definition Field.h:395
Field::value
virtual Data_T value(int i, int j, int k) const =0
Read access to a voxel. The coordinates are in integer voxel space .
Field::base
FieldRes base
Convenience typedef for referring to base class.
Definition Field.h:467
Field::value_type
Data_T value_type
Allows us to reference the template class.
Definition Field.h:398
Field::~Field
virtual ~Field()
Dtor.
Definition Field.h:423
Field::class_type
Field< Data_T > class_type
Definition Field.h:407
Field::cend
const_iterator cend() const
Const iterator pointing one element past the last valid one.
Definition Field.h:591
Field::cbegin
const_iterator cbegin() const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
Definition Field.h:569
Field::staticClassName
static const char * staticClassName()
Definition Field.h:410
MatrixFieldMapping
Represents the mapping of a field by a matrix transform.
Definition FieldMapping.h:335
MetadataCallback
Definition FieldMetadata.h:71
RefBase::RefBase
RefBase()
Definition RefCount.h:120
ResizableField
Definition Field.h:835
ResizableField::setSize
void setSize(const V3i &size)
Resizes the object.
Definition Field.h:913
ResizableField::matchDefinition
void matchDefinition(FieldRes::Ptr fieldToMatch)
Sets up this field so that resolution and mapping matches the other.
Definition Field.h:1003
ResizableField::class_type
ResizableField< Data_T > class_type
Definition Field.h:844
ResizableField::DEFINE_FIELD_RTTI_ABSTRACT_CLASS
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition Field.h:845
ResizableField::ms_classType
static TemplatedFieldType< ResizableField< Data_T > > ms_classType
Definition Field.h:890
ResizableField::staticClassType
static const char * staticClassType()
Definition Field.h:852
ResizableField::sizeChanged
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc....
Definition Field.h:901
ResizableField::copyFrom
void copyFrom(typename Field< Data_T >::Ptr other)
Copies the data from another Field, also resizes.
Definition Field.h:967
ResizableField::staticClassName
static const char * staticClassName()
Definition Field.h:847
ResizableField::Ptr
boost::intrusive_ptr< ResizableField > Ptr
Definition Field.h:840
ResizableField::base
WritableField< Data_T > base
Definition Field.h:894
WritableField::iterator
Definition Field.h:704
WritableField::iterator::y
int y
Definition Field.h:762
WritableField::iterator::m_window
Box3i m_window
Window to traverse.
Definition Field.h:769
WritableField::iterator::z
int z
Definition Field.h:762
WritableField::iterator::iterator
iterator(WritableField< Data_T > &field, const Box3i &window, const V3i &currentPos)
Definition Field.h:717
WritableField::iterator::x
int x
Current position.
Definition Field.h:762
WritableField::iterator::m_field
WritableField< Data_T > & m_field
Reference to field being iterated over.
Definition Field.h:771
WritableField
Definition Field.h:625
WritableField::base
Field< Data_T > base
Definition Field.h:690
WritableField::staticClassType
static const char * staticClassType()
Definition Field.h:642
WritableField::end
iterator end()
Iterator pointing one element past the last valid one.
Definition Field.h:802
WritableField::class_type
WritableField< Data_T > class_type
Definition Field.h:634
WritableField::lvalue
virtual Data_T & lvalue(int i, int j, int k)=0
Write access to a voxel. The coordinates are global coordinates.
WritableField::DEFINE_FIELD_RTTI_ABSTRACT_CLASS
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition Field.h:635
WritableField::ms_classType
static TemplatedFieldType< WritableField< Data_T > > ms_classType
Definition Field.h:686
WritableField::Ptr
boost::intrusive_ptr< WritableField > Ptr
Definition Field.h:630
WritableField::staticClassName
static const char * staticClassName()
Definition Field.h:637
WritableField::clear
virtual void clear(const Data_T &value)
Clears all the voxels in the storage. Should be re-implemented by subclasses that can provide a more ...
Definition Field.h:679
WritableField::begin
iterator begin()
Iterator to first element.
Definition Field.h:779
advance
void advance(Iter_T &iter, int num)
Definition Field.h:1161
Exc
Namespace for Exception objects.
Definition Exception.h:57
FIELD3D_NAMESPACE_OPEN
Definition FieldMapping.cpp:74
Msg::SevWarning
@ SevWarning
Definition Log.h:68
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70
ns.h
FIELD3D_API
#define FIELD3D_API
Definition ns.h:77
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
DataTypeTraits::name
static std::string name()
Definition Traits.h:267
TemplatedFieldType
Used to return a string for the name of a templated field.
Definition Traits.h:283