MACField.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_MACField_H_
#define _INCLUDED_Field3D_MACField_H_
#include <vector>
#include <boost/lexical_cast.hpp>
#include "Field.h"
//----------------------------------------------------------------------------//
#include "ns.h"
FIELD3D_NAMESPACE_OPEN
//----------------------------------------------------------------------------//
// Forward declarations
//----------------------------------------------------------------------------//
template <class T>
class LinearMACFieldInterp;
template <class T>
class CubicMACFieldInterp;
//----------------------------------------------------------------------------//
// Enumerators
//----------------------------------------------------------------------------//
enum MACComponent {
MACCompU = 0,
MACCompV,
MACCompW
};
//----------------------------------------------------------------------------//
// MACField
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
template <class Data_T>
class MACField : public ResizableField<Data_T>
{
public:
// Typedefs ------------------------------------------------------------------
typedef boost::intrusive_ptr<MACField> Ptr;
typedef std::vector<Ptr> Vec;
typedef typename Data_T::BaseType real_t;
typedef LinearMACFieldInterp<Data_T> LinearInterp;
typedef CubicMACFieldInterp<Data_T> CubicInterp;
// RTTI replacement ----------------------------------------------------------
typedef MACField<Data_T> class_type;
DEFINE_FIELD_RTTI_CONCRETE_CLASS;
static const char *staticClassName()
{
return "MACField";
}
static const char* staticClassType()
{
return MACField<Data_T>::ms_classType.name();
}
// Constructors --------------------------------------------------------------
MACField();
// \}
// Main methods --------------------------------------------------------------
virtual void clear(const Data_T &value);
// From Field base class -----------------------------------------------------
virtual Data_T value(int i, int j, int k) const;
virtual long long int memSize() const;
// From WritableField base class ---------------------------------------------
virtual Data_T& lvalue(int i, int j, int k);
// Concrete component access -------------------------------------------------
const real_t& u(int i, int j, int k) const;
real_t& u(int i, int j, int k);
const real_t& v(int i, int j, int k) const;
real_t& v(int i, int j, int k);
const real_t& w(int i, int j, int k) const;
real_t& w(int i, int j, int k);
// Iterators -----------------------------------------------------------------
class const_mac_comp_iterator;
class mac_comp_iterator;
const_mac_comp_iterator cbegin_comp(MACComponent comp) const;
const_mac_comp_iterator cbegin_comp(MACComponent comp,
const Box3i &subset) const;
const_mac_comp_iterator cend_comp(MACComponent comp) const;
const_mac_comp_iterator cend_comp(MACComponent comp,
const Box3i &subset) const;
mac_comp_iterator begin_comp(MACComponent comp);
mac_comp_iterator begin_comp(MACComponent comp,
const Box3i &subset);
mac_comp_iterator end_comp(MACComponent comp);
mac_comp_iterator end_comp(MACComponent comp,
const Box3i &subset);
// Utility methods -----------------------------------------------------------
real_t uCenter(int i, int j, int k) const
{
return (u(i, j, k) + u(i + 1, j, k)) * 0.5;
}
real_t vCenter(int i, int j, int k) const
{
return (v(i, j, k) + v(i, j + 1, k)) * 0.5;
}
real_t wCenter(int i, int j, int k) const
{
return (w(i, j, k) + w(i, j, k + 1)) * 0.5;
}
void copyMAC(typename MACField::Ptr other)
{
matchDefinition(other);
std::copy(other->m_u.begin(), other->m_u.end(), m_u.begin());
std::copy(other->m_v.begin(), other->m_v.end(), m_v.begin());
std::copy(other->m_w.begin(), other->m_w.end(), m_w.begin());
}
// Utility methods -----------------------------------------------------------
V3i getComponentSize() const
{ return V3i((int)m_u.size(), (int)m_v.size(), (int)m_w.size()); }
// From FieldBase ------------------------------------------------------------
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION;
virtual FieldBase::Ptr clone() const
{ return Ptr(new MACField(*this)); }
protected:
// From ResizableField class ---------------------------------------------
virtual void sizeChanged();
// Concrete component access -------------------------------------------------
const real_t* uPtr(int i, int j, int k) const;
real_t* uPtr(int i, int j, int k);
const real_t* vPtr(int i, int j, int k) const;
real_t* vPtr(int i, int j, int k);
const real_t* wPtr(int i, int j, int k) const;
real_t* wPtr(int i, int j, int k);
// Data members --------------------------------------------------------------
std::vector<real_t> m_u;
std::vector<real_t> m_v;
std::vector<real_t> m_w;
V3i m_uSize;
int m_uSizeXY;
V3i m_vSize;
int m_vSizeXY;
V3i m_wSize;
int m_wSizeXY;
mutable Data_T m_dummy;
private:
// Static data members -------------------------------------------------------
static TemplatedFieldType<MACField<Data_T> > ms_classType;
// Typedefs ------------------------------------------------------------------
typedef ResizableField<Data_T> base;
};
//----------------------------------------------------------------------------//
// Static member instantiation
//----------------------------------------------------------------------------//
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(MACField);
//----------------------------------------------------------------------------//
// Typedefs
//----------------------------------------------------------------------------//
typedef MACField<V3h> MACField3h;
typedef MACField<V3f> MACField3f;
typedef MACField<V3d> MACField3d;
//----------------------------------------------------------------------------//
// MACField::const_mac_comp_iterator
//----------------------------------------------------------------------------//
template <class Data_T>
class MACField<Data_T>::const_mac_comp_iterator
{
public:
// Typedefs ------------------------------------------------------------------
typedef MACField<Data_T> class_type;
typedef typename MACField<Data_T>::real_t real_t;
// Constructors --------------------------------------------------------------
const_mac_comp_iterator(MACComponent comp,
const class_type &field,
const Box3i &window,
const V3i &currentPos)
: x(currentPos.x), y(currentPos.y), z(currentPos.z),
m_p(NULL), m_window(window), m_comp(comp),
m_field(field)
{
if (window.intersects(currentPos))
updatePointer();
}
// Operators -----------------------------------------------------------------
const const_mac_comp_iterator& operator ++ ()
{
if (x == m_window.max.x) {
if (y == m_window.max.y) {
if (z == m_window.max.z) {
m_p = 0;
return *this;
} else {
x = m_window.min.x;
y = m_window.min.y;
++z;
}
} else {
x = m_window.min.x;
++y;
}
updatePointer();
} else {
++x;
++m_p;
}
return *this;
}
template <class Iter_T>
inline bool operator == (const Iter_T &rhs) const
{
return m_p == &(*rhs);
}
template <class Iter_T>
inline bool operator != (const Iter_T &rhs) const
{
return m_p != &(*rhs);
}
inline const real_t& operator * () const
{
return *m_p;
}
inline const real_t* operator -> () const
{
return m_p;
}
// Public data members -------------------------------------------------------
int x, y, z;
private:
// Convenience methods -------------------------------------------------------
void updatePointer()
{
switch (m_comp) {
case MACCompU:
m_p = m_field.uPtr(x, y, z);
break;
case MACCompV:
m_p = m_field.vPtr(x, y, z);
break;
case MACCompW:
m_p = m_field.wPtr(x, y, z);
break;
default:
assert(false && "Illegal MACComponent in const_mac_comp_iterator");
}
}
// Private data members ------------------------------------------------------
const real_t *m_p;
Box3i m_window;
MACComponent m_comp;
const class_type &m_field;
};
//----------------------------------------------------------------------------//
template <class Data_T>
class MACField<Data_T>::mac_comp_iterator
{
public:
// Typedefs ------------------------------------------------------------------
typedef MACField<Data_T> class_type;
typedef typename MACField<Data_T>::real_t real_t;
// Constructors --------------------------------------------------------------
mac_comp_iterator(MACComponent comp, class_type &field,
const Box3i &window, const V3i &currentPos)
: x(currentPos.x), y(currentPos.y), z(currentPos.z),
m_p(NULL), m_window(window), m_comp(comp),
m_field(field)
{
if (window.intersects(currentPos))
updatePointer();
}
// Operators -----------------------------------------------------------------
mac_comp_iterator& operator ++ ()
{
if (x == m_window.max.x) {
if (y == m_window.max.y) {
if (z == m_window.max.z) {
m_p = 0;
return *this;
} else {
x = m_window.min.x;
y = m_window.min.y;
++z;
}
} else {
x = m_window.min.x;
++y;
}
updatePointer();
} else {
++x;
++m_p;
}
return *this;
}
template <class Iter_T>
inline bool operator == (const Iter_T &rhs) const
{
return m_p == &(*rhs);
}
template <class Iter_T>
inline bool operator != (const Iter_T &rhs) const
{
return m_p != &(*rhs);
}
inline real_t& operator * () const
{
return *m_p;
}
inline real_t* operator -> () const
{
return m_p;
}
// Public data members -------------------------------------------------------
int x, y, z;
private:
// Convenience methods -------------------------------------------------------
void updatePointer()
{
switch (m_comp) {
case MACCompU:
m_p = m_field.uPtr(x, y, z);
break;
case MACCompV:
m_p = m_field.vPtr(x, y, z);
break;
case MACCompW:
m_p = m_field.wPtr(x, y, z);
break;
default:
assert(false && "Illegal MACComponent in const_mac_comp_iterator");
}
}
// Private data members ------------------------------------------------------
real_t *m_p;
Box3i m_window;
MACComponent m_comp;
class_type &m_field;
};
//----------------------------------------------------------------------------//
// Implementation specific helpers
//----------------------------------------------------------------------------//
namespace MACFieldUtil {
inline Box3i makeDataWindowForComponent(Box3i dataWindow, MACComponent comp)
{
switch (comp) {
case MACCompU:
dataWindow.max += V3i(1, 0, 0);
break;
case MACCompV:
dataWindow.max += V3i(0, 1, 0);
break;
case MACCompW:
dataWindow.max += V3i(0, 0, 1);
break;
default:
assert(false && "Illegal MACComponent in makeDataWindowForComponent");
}
return dataWindow;
}
}
//----------------------------------------------------------------------------//
// MACField implementations
//----------------------------------------------------------------------------//
template <class Data_T>
MACField<Data_T>::MACField()
: base()
{
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline void MACField<Data_T>::clear(const Data_T &value)
{
std::fill(m_u.begin(), m_u.end(), value.x);
std::fill(m_v.begin(), m_v.end(), value.y);
std::fill(m_w.begin(), m_w.end(), value.z);
}
//----------------------------------------------------------------------------//
template <class Data_T>
Data_T MACField<Data_T>::value(int i, int j, int k) const
{
return Data_T(uCenter(i, j, k), vCenter(i, j, k), wCenter(i, j, k));
}
//----------------------------------------------------------------------------//
template <class Data_T>
long long int MACField<Data_T>::memSize() const
{
long long int superClassMemSize = base::memSize();
long long int vectorMemSize =
(m_u.capacity() + m_v.capacity() + m_w.capacity()) * sizeof(real_t);
return sizeof(*this) + vectorMemSize + superClassMemSize;
}
//----------------------------------------------------------------------------//
template <class Data_T>
Data_T& MACField<Data_T>::lvalue(int i, int j, int k)
{
m_dummy = value(i, j, k);
return m_dummy;
}
//----------------------------------------------------------------------------//
template <class Data_T>
void MACField<Data_T>::sizeChanged()
{
// Call base class
base::sizeChanged();
V3i baseSize =
base::m_dataWindow.max - base::m_dataWindow.min + V3i(1);
if (std::min(std::min(baseSize.x, baseSize.y), baseSize.z) < 0)
throw Exc::ResizeException("Attempt to resize ResizableField object "
"using negative size. Data window was: " +
boost::lexical_cast<std::string>(baseSize));
// Calculate the size for each component of the MAC field
m_uSize = baseSize + V3i(1, 0, 0);
m_vSize = baseSize + V3i(0, 1, 0);
m_wSize = baseSize + V3i(0, 0, 1);
// Calculate the size of each z slice
m_uSizeXY = m_uSize.x * m_uSize.y;
m_vSizeXY = m_vSize.x * m_vSize.y;
m_wSizeXY = m_wSize.x * m_wSize.y;
// Allocate memory
try {
m_u.resize(m_uSize.x * m_uSize.y * m_uSize.z);
m_v.resize(m_vSize.x * m_vSize.y * m_vSize.z);
m_w.resize(m_wSize.x * m_wSize.y * m_wSize.z);
}
catch (std::bad_alloc &) {
throw Exc::MemoryException("Couldn't allocate MACField of size " +
boost::lexical_cast<std::string>(baseSize));
}
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline const typename MACField<Data_T>::real_t&
MACField<Data_T>::u(int i, int j, int k) const
{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x + 1);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z);
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return m_u[i + j * m_uSize.x + k * m_uSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename MACField<Data_T>::real_t&
MACField<Data_T>::u(int i, int j, int k)
{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x + 1);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z);
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return m_u[i + j * m_uSize.x + k * m_uSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline const typename MACField<Data_T>::real_t&
MACField<Data_T>::v(int i, int j, int k) const
{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y + 1);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z);
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return m_v[i + j * m_vSize.x + k * m_vSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename MACField<Data_T>::real_t&
MACField<Data_T>::v(int i, int j, int k)
{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y + 1);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z);
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return m_v[i + j * m_vSize.x + k * m_vSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline const typename MACField<Data_T>::real_t&
MACField<Data_T>::w(int i, int j, int k) const
{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z + 1);
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return m_w[i + j * m_wSize.x + k * m_wSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename MACField<Data_T>::real_t&
MACField<Data_T>::w(int i, int j, int k)
{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z + 1);
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return m_w[i + j * m_wSize.x + k * m_wSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::const_mac_comp_iterator
MACField<Data_T>::cbegin_comp(MACComponent comp) const
{
using namespace MACFieldUtil;
if (FieldRes::dataResolution() == V3i(0))
return cend_comp(comp);
Box3i dataWindow =
makeDataWindowForComponent(base::m_dataWindow, comp);
return const_mac_comp_iterator(comp, *this, dataWindow, dataWindow.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::const_mac_comp_iterator
MACField<Data_T>::cbegin_comp(MACComponent comp, const Box3i &subset) const
{
using namespace MACFieldUtil;
if (subset.isEmpty())
return cend_comp(comp, subset);
Box3i dataWindow = makeDataWindowForComponent(subset, comp);
return const_mac_comp_iterator(comp, *this, dataWindow, subset.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::const_mac_comp_iterator
MACField<Data_T>::cend_comp(MACComponent comp) const
{
using namespace MACFieldUtil;
Box3i dataWindow =
makeDataWindowForComponent(base::m_dataWindow, comp);
return const_mac_comp_iterator(comp, *this, dataWindow,
V3i(dataWindow.min.x,
dataWindow.min.y,
dataWindow.max.z + 1));
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::const_mac_comp_iterator
MACField<Data_T>::cend_comp(MACComponent comp, const Box3i &subset) const
{
using namespace MACFieldUtil;
Box3i dataWindow = makeDataWindowForComponent(subset, comp);
return const_mac_comp_iterator(comp, *this, dataWindow,
V3i(dataWindow.min.x,
dataWindow.min.y,
dataWindow.max.z + 1));
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::mac_comp_iterator
MACField<Data_T>::begin_comp(MACComponent comp)
{
using namespace MACFieldUtil;
if (FieldRes::dataResolution() == V3i(0))
return end_comp(comp);
Box3i dataWindow = makeDataWindowForComponent(base::m_dataWindow, comp);
return mac_comp_iterator(comp, *this, dataWindow, dataWindow.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::mac_comp_iterator
MACField<Data_T>::begin_comp(MACComponent comp, const Box3i &subset)
{
using namespace MACFieldUtil;
if (subset.isEmpty())
return end_comp(comp, subset);
Box3i dataWindow = makeDataWindowForComponent(subset, comp);
return mac_comp_iterator(comp, *this, dataWindow, subset.min);
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::mac_comp_iterator
MACField<Data_T>::end_comp(MACComponent comp)
{
using namespace MACFieldUtil;
Box3i dataWindow = makeDataWindowForComponent(base::m_dataWindow, comp);
return mac_comp_iterator(comp, *this, dataWindow, V3i(dataWindow.min.x,
dataWindow.min.y,
dataWindow.max.z + 1));
}
//----------------------------------------------------------------------------//
template <class Data_T>
typename MACField<Data_T>::mac_comp_iterator
MACField<Data_T>::end_comp(MACComponent comp, const Box3i &subset)
{
using namespace MACFieldUtil;
Box3i dataWindow = makeDataWindowForComponent(subset, comp);
return mac_comp_iterator(comp, *this, dataWindow, V3i(dataWindow.min.x,
dataWindow.min.y,
dataWindow.max.z + 1));
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline const typename MACField<Data_T>::real_t*
MACField<Data_T>::uPtr(int i, int j, int k) const
{
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return &m_u[i + j * m_uSize.x + k * m_uSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename MACField<Data_T>::real_t*
MACField<Data_T>::uPtr(int i, int j, int k)
{
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return &m_u[i + j * m_uSize.x + k * m_uSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline const typename MACField<Data_T>::real_t*
MACField<Data_T>::vPtr(int i, int j, int k) const
{
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return &m_v[i + j * m_vSize.x + k * m_vSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename MACField<Data_T>::real_t*
MACField<Data_T>::vPtr(int i, int j, int k)
{
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return &m_v[i + j * m_vSize.x + k * m_vSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline const typename MACField<Data_T>::real_t*
MACField<Data_T>::wPtr(int i, int j, int k) const
{
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return &m_w[i + j * m_wSize.x + k * m_wSizeXY];
}
//----------------------------------------------------------------------------//
template <class Data_T>
inline typename MACField<Data_T>::real_t*
MACField<Data_T>::wPtr(int i, int j, int k)
{
// Add crop window offset
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
return &m_w[i + j * m_wSize.x + k * m_wSizeXY];
}
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_HEADER_CLOSE
//----------------------------------------------------------------------------//
#endif // Include guard
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
Field.h
Contains Field, WritableField and ResizableField classes.
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION
#define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field)
Definition Field.h:479
MACField3d
MACField< V3d > MACField3d
Definition MACField.h:352
MACField3f
MACField< V3f > MACField3f
Definition MACField.h:351
MACComponent
MACComponent
Definition MACField.h:71
MACCompV
@ MACCompV
Definition MACField.h:73
MACCompU
@ MACCompU
Definition MACField.h:72
MACCompW
@ MACCompW
Definition MACField.h:74
MACField3h
MACField< V3h > MACField3h
Definition MACField.h:350
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
Box3i
Imath::Box3i Box3i
Definition SpiMathLib.h:77
CubicMACFieldInterp
Definition FieldInterp.h:435
FieldBase::Ptr
boost::intrusive_ptr< FieldBase > Ptr
Definition Field.h:97
FieldRes::dataResolution
V3i const dataResolution() const
Definition Field.h:256
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::memSize
virtual long long int memSize() const
Returns the memory usage (in bytes).
Definition Field.h:279
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
LinearMACFieldInterp
Definition FieldInterp.h:313
MACField::const_mac_comp_iterator
Definition MACField.h:360
MACField::const_mac_comp_iterator::m_comp
MACComponent m_comp
Component to look up.
Definition MACField.h:463
MACField::const_mac_comp_iterator::updatePointer
void updatePointer()
Definition MACField.h:439
MACField::const_mac_comp_iterator::class_type
MACField< Data_T > class_type
Definition MACField.h:365
MACField::const_mac_comp_iterator::m_p
const real_t * m_p
Pointer to current element.
Definition MACField.h:459
MACField::const_mac_comp_iterator::m_window
Box3i m_window
Window to traverse.
Definition MACField.h:461
MACField::const_mac_comp_iterator::x
int x
Current position.
Definition MACField.h:433
MACField::const_mac_comp_iterator::const_mac_comp_iterator
const_mac_comp_iterator(MACComponent comp, const class_type &field, const Box3i &window, const V3i &currentPos)
Definition MACField.h:370
MACField::const_mac_comp_iterator::real_t
MACField< Data_T >::real_t real_t
Definition MACField.h:366
MACField::const_mac_comp_iterator::z
int z
Definition MACField.h:433
MACField::const_mac_comp_iterator::m_field
const class_type & m_field
Reference to field being iterated over.
Definition MACField.h:465
MACField::const_mac_comp_iterator::y
int y
Definition MACField.h:433
MACField::mac_comp_iterator
Definition MACField.h:473
MACField::mac_comp_iterator::m_p
real_t * m_p
Pointer to current element.
Definition MACField.h:570
MACField::mac_comp_iterator::z
int z
Definition MACField.h:544
MACField::mac_comp_iterator::m_field
class_type & m_field
Reference to field being iterated over.
Definition MACField.h:576
MACField::mac_comp_iterator::m_comp
MACComponent m_comp
Component to look up.
Definition MACField.h:574
MACField::mac_comp_iterator::updatePointer
void updatePointer()
Definition MACField.h:550
MACField::mac_comp_iterator::mac_comp_iterator
mac_comp_iterator(MACComponent comp, class_type &field, const Box3i &window, const V3i &currentPos)
Definition MACField.h:483
MACField::mac_comp_iterator::y
int y
Definition MACField.h:544
MACField::mac_comp_iterator::x
int x
Current position.
Definition MACField.h:544
MACField::mac_comp_iterator::class_type
MACField< Data_T > class_type
Definition MACField.h:478
MACField::mac_comp_iterator::m_window
Box3i m_window
Window to traverse.
Definition MACField.h:572
MACField::mac_comp_iterator::real_t
MACField< Data_T >::real_t real_t
Definition MACField.h:479
MACField
This subclass of Field implements a standard MAC field. Refer to your favorite fluid simulations book...
Definition MACField.h:96
MACField::class_type
MACField< Data_T > class_type
Definition MACField.h:112
MACField::vCenter
real_t vCenter(int i, int j, int k) const
Returns the v-component interpolated to the cell center.
Definition MACField.h:238
MACField< V3h >::m_u
std::vector< real_t > m_u
Definition MACField.h:306
MACField::w
const real_t & w(int i, int j, int k) const
Read access to value on w-facing wall.
Definition MACField.h:774
MACField::ms_classType
static TemplatedFieldType< MACField< Data_T > > ms_classType
Definition MACField.h:332
MACField::base
ResizableField< Data_T > base
Definition MACField.h:336
MACField::real_t
Data_T::BaseType real_t
This typedef is used to refer to the scalar component type of the vectors.
Definition MACField.h:105
MACField::Vec
std::vector< Ptr > Vec
Definition MACField.h:102
MACField::MACField
MACField()
Constructs an empty buffer.
Definition MACField.h:611
MACField< V3h >::m_wSizeXY
int m_wSizeXY
Definition MACField.h:323
MACField::uPtr
const real_t * uPtr(int i, int j, int k) const
Direct access to value on u-facing wall.
Definition MACField.h:920
MACField::cbegin_comp
const_mac_comp_iterator cbegin_comp(MACComponent comp, const Box3i &subset) const
Const iterator to first element of specific subset.
Definition MACField.h:826
MACField::begin_comp
mac_comp_iterator begin_comp(MACComponent comp, const Box3i &subset)
Iterator to first element of specific subset.
Definition MACField.h:881
MACField< V3h >::m_uSizeXY
int m_uSizeXY
Definition MACField.h:315
MACField< V3h >::m_wSize
V3i m_wSize
Definition MACField.h:321
MACField< V3h >::DEFINE_FIELD_RTTI_CONCRETE_CLASS
DEFINE_FIELD_RTTI_CONCRETE_CLASS
Definition MACField.h:113
MACField::vPtr
const real_t * vPtr(int i, int j, int k) const
Direct access to value on v-facing wall.
Definition MACField.h:946
MACField::sizeChanged
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc....
Definition MACField.h:658
MACField::u
const real_t & u(int i, int j, int k) const
Read access to value on u-facing wall.
Definition MACField.h:698
MACField< V3h >::m_uSize
V3i m_uSize
Definition MACField.h:313
MACField::LinearInterp
LinearMACFieldInterp< Data_T > LinearInterp
Definition MACField.h:107
MACField::staticClassType
static const char * staticClassType()
Definition MACField.h:120
MACField::Ptr
boost::intrusive_ptr< MACField > Ptr
Definition MACField.h:101
MACField< V3h >::m_vSize
V3i m_vSize
Definition MACField.h:317
MACField< V3h >::m_vSizeXY
int m_vSizeXY
Definition MACField.h:319
MACField< V3h >::value
virtual V3h value(int i, int j, int k) const
MACField::end_comp
mac_comp_iterator end_comp(MACComponent comp)
Iterator to first element.
Definition MACField.h:894
MACField< V3h >::m_dummy
V3h m_dummy
Definition MACField.h:326
MACField::clone
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
Definition MACField.h:271
MACField::wPtr
const real_t * wPtr(int i, int j, int k) const
Direct access to value on w-facing wall.
Definition MACField.h:972
MACField::w
real_t & w(int i, int j, int k)
Write access to value on w-facing wall.
Definition MACField.h:793
MACField::end_comp
mac_comp_iterator end_comp(MACComponent comp, const Box3i &subset)
Iterator to first element of specific subset.
Definition MACField.h:907
MACField::CubicInterp
CubicMACFieldInterp< Data_T > CubicInterp
Definition MACField.h:108
MACField::uCenter
real_t uCenter(int i, int j, int k) const
Returns the u-component interpolated to the cell center.
Definition MACField.h:233
MACField< V3h >::FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
Definition MACField.h:269
MACField< V3h >::m_v
std::vector< real_t > m_v
Definition MACField.h:308
MACField::v
const real_t & v(int i, int j, int k) const
Read access to value on v-facing wall.
Definition MACField.h:736
MACField::cend_comp
const_mac_comp_iterator cend_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
Definition MACField.h:839
MACField::clear
virtual void clear(const Data_T &value)
Clears all the voxels in the storage.
Definition MACField.h:620
MACField::lvalue
virtual Data_T & lvalue(int i, int j, int k)
This will return the appropriate interpolated value but setting that to something else does not chang...
Definition MACField.h:649
MACField::cbegin_comp
const_mac_comp_iterator cbegin_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
Definition MACField.h:812
MACField< V3h >::m_w
std::vector< real_t > m_w
Definition MACField.h:310
MACField::vPtr
real_t * vPtr(int i, int j, int k)
Direct access to value on v-facing wall.
Definition MACField.h:959
MACField::uPtr
real_t * uPtr(int i, int j, int k)
Direct access to value on u-facing wall.
Definition MACField.h:933
MACField::cend_comp
const_mac_comp_iterator cend_comp(MACComponent comp, const Box3i &subset) const
Const iterator to first element of specific subset.
Definition MACField.h:854
MACField::getComponentSize
V3i getComponentSize() const
Returns the size of U,V,W components.
Definition MACField.h:261
MACField::u
real_t & u(int i, int j, int k)
Write access to value on u-facing wall.
Definition MACField.h:717
MACField::copyMAC
void copyMAC(typename MACField::Ptr other)
TEMP: Copies the MAC field data from another MAC field. This should be re-implemented using proper it...
Definition MACField.h:250
MACField::v
real_t & v(int i, int j, int k)
Write access to value on v-facing wall.
Definition MACField.h:755
MACField::wPtr
real_t * wPtr(int i, int j, int k)
Direct access to value on w-facing wall.
Definition MACField.h:985
MACField::memSize
virtual long long int memSize() const
Returns the memory usage (in bytes).
Definition MACField.h:638
MACField::staticClassName
static const char * staticClassName()
Definition MACField.h:115
MACField::wCenter
real_t wCenter(int i, int j, int k) const
Returns the w-component interpolated to the cell center.
Definition MACField.h:243
MACField::begin_comp
mac_comp_iterator begin_comp(MACComponent comp)
Iterator to first element.
Definition MACField.h:868
ResizableField
Definition Field.h:835
ResizableField::matchDefinition
void matchDefinition(FieldRes::Ptr fieldToMatch)
Sets up this field so that resolution and mapping matches the other.
Definition Field.h:1003
ResizableField::sizeChanged
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc....
Definition Field.h:901
FIELD3D_NAMESPACE_OPEN
Definition FieldMapping.cpp:74
MACFieldUtil
Definition MACField.h:584
MACFieldUtil::makeDataWindowForComponent
Box3i makeDataWindowForComponent(Box3i dataWindow, MACComponent comp)
Definition MACField.h:586
ns.h
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
TemplatedFieldType
Used to return a string for the name of a templated field.
Definition Traits.h:283