44 #ifndef _INCLUDED_Field3D_MACField_H_ 45 #define _INCLUDED_Field3D_MACField_H_ 48 #include <boost/lexical_cast.hpp> 94 template <
class Data_T>
101 typedef boost::intrusive_ptr<MACField>
Ptr;
102 typedef std::vector<Ptr>
Vec;
105 typedef typename Data_T::BaseType
real_t;
146 virtual Data_T
value(
int i,
int j,
int k)
const;
147 virtual long long int memSize()
const;
159 virtual Data_T&
lvalue(
int i,
int j,
int k);
170 const real_t&
u(
int i,
int j,
int k)
const;
173 real_t&
u(
int i,
int j,
int k);
176 const real_t&
v(
int i,
int j,
int k)
const;
179 real_t&
v(
int i,
int j,
int k);
182 const real_t&
w(
int i,
int j,
int k)
const;
185 real_t&
w(
int i,
int j,
int k);
210 const Box3i &subset)
const;
215 const Box3i &subset)
const;
221 const Box3i &subset);
226 const Box3i &subset);
235 return (
u(i, j, k) +
u(i + 1, j, k)) * 0.5;
240 return (
v(i, j, k) +
v(i, j + 1, k)) * 0.5;
245 return (
w(i, j, k) +
w(i, j, k + 1)) * 0.5;
253 std::copy(other->m_u.begin(), other->m_u.end(),
m_u.begin());
254 std::copy(other->m_v.begin(), other->m_v.end(),
m_v.begin());
255 std::copy(other->m_w.begin(), other->m_w.end(),
m_w.begin());
287 const real_t*
uPtr(
int i,
int j,
int k)
const;
290 real_t*
uPtr(
int i,
int j,
int k);
293 const real_t*
vPtr(
int i,
int j,
int k)
const;
296 real_t*
vPtr(
int i,
int j,
int k);
299 const real_t*
wPtr(
int i,
int j,
int k)
const;
302 real_t*
wPtr(
int i,
int j,
int k);
359 template <
class Data_T>
372 const class_type &field,
374 const V3i ¤tPos)
375 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
376 m_p(NULL), m_window(window), m_comp(comp),
386 if (x == m_window.max.x) {
387 if (y == m_window.max.y) {
403 template <
class Iter_T>
404 inline bool operator == (
const Iter_T &rhs)
const 406 return m_p == &(*rhs);
409 template <
class Iter_T>
410 inline bool operator != (
const Iter_T &rhs)
const 412 return m_p != &(*rhs);
420 inline const real_t* operator -> ()
const 438 m_p = m_field.uPtr(x, y, z);
441 m_p = m_field.vPtr(x, y, z);
444 m_p = m_field.wPtr(x, y, z);
447 assert(
false &&
"Illegal MACComponent in const_mac_comp_iterator");
466 template <
class Data_T>
479 const Box3i &window,
const V3i ¤tPos)
480 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
481 m_p(NULL), m_window(window), m_comp(comp),
491 if (x == m_window.max.x) {
492 if (y == m_window.max.y) {
508 template <
class Iter_T>
509 inline bool operator == (
const Iter_T &rhs)
const 511 return m_p == &(*rhs);
514 template <
class Iter_T>
515 inline bool operator != (
const Iter_T &rhs)
const 517 return m_p != &(*rhs);
525 inline real_t* operator -> ()
const 543 m_p = m_field.uPtr(x, y, z);
546 m_p = m_field.vPtr(x, y, z);
549 m_p = m_field.wPtr(x, y, z);
552 assert(
false &&
"Illegal MACComponent in const_mac_comp_iterator");
579 dataWindow.max +=
V3i(1, 0, 0);
582 dataWindow.max +=
V3i(0, 1, 0);
585 dataWindow.max +=
V3i(0, 0, 1);
588 assert(
false &&
"Illegal MACComponent in makeDataWindowForComponent");
599 template <
class Data_T>
608 template <
class Data_T>
611 std::fill(
m_u.begin(),
m_u.end(), value.x);
612 std::fill(
m_v.begin(),
m_v.end(), value.y);
613 std::fill(
m_w.begin(),
m_w.end(), value.z);
618 template <
class Data_T>
626 template <
class Data_T>
630 long long int vectorMemSize =
632 return sizeof(*this) + vectorMemSize + superClassMemSize;
637 template <
class Data_T>
646 template <
class Data_T>
655 if (std::min(std::min(baseSize.x, baseSize.y), baseSize.z) < 0)
656 throw Exc::ResizeException(
"Attempt to resize ResizableField object " 657 "using negative size. Data window was: " +
658 boost::lexical_cast<std::string>(baseSize));
676 catch (std::bad_alloc &e) {
677 throw Exc::MemoryException(
"Couldn't allocate MACField of size " +
678 boost::lexical_cast<std::string>(baseSize));
685 template <
class Data_T>
704 template <
class Data_T>
723 template <
class Data_T>
742 template <
class Data_T>
761 template <
class Data_T>
780 template <
class Data_T>
799 template <
class Data_T>
813 template <
class Data_T>
818 if (subset.isEmpty())
826 template <
class Data_T>
834 V3i(dataWindow.min.x,
836 dataWindow.max.z + 1));
841 template <
class Data_T>
848 V3i(dataWindow.min.x,
850 dataWindow.max.z + 1));
855 template <
class Data_T>
868 template <
class Data_T>
873 if (subset.isEmpty())
881 template <
class Data_T>
889 dataWindow.max.z + 1));
894 template <
class Data_T>
902 dataWindow.max.z + 1));
907 template <
class Data_T>
920 template <
class Data_T>
933 template <
class Data_T>
946 template <
class Data_T>
959 template <
class Data_T>
972 template <
class Data_T>
989 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
const_mac_comp_iterator cbegin_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
MACField< Data_T >::real_t real_t
const real_t * m_p
Pointer to current element.
const class_type & m_field
Reference to field being iterated over.
mac_comp_iterator(MACComponent comp, class_type &field, const Box3i &window, const V3i ¤tPos)
const real_t * uPtr(int i, int j, int k) const
Direct access to value on u-facing wall.
std::vector< real_t > m_v
V component storage.
mac_comp_iterator begin_comp(MACComponent comp)
Iterator to first element.
MACComponent m_comp
Component to look up.
virtual std::string className() const
Returns the class name of the object. Used by the class pool and when writing the data to disk...
This subclass of Field implements a standard MAC field. Refer to your favorite fluid simulations book...
Box3i makeDataWindowForComponent(Box3i dataWindow, MACComponent comp)
ResizableField< Data_T > base
void matchDefinition(FieldRes::Ptr fieldToMatch)
Sets up this field so that resolution and mapping matches the other.
std::vector< real_t > m_w
W component storage.
CubicMACFieldInterp< Data_T > CubicInterp
boost::intrusive_ptr< FieldBase > Ptr
real_t wCenter(int i, int j, int k) const
Returns the w-component interpolated to the cell center.
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.
FIELD3D_VEC3_T< T > operator*(S s, const FIELD3D_VEC3_T< T > vec)
Scalar times Vec3 multiplication. Makes the interpolation calls cleaner.
MACField< Data_T > class_type
const_mac_comp_iterator cend_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
real_t * m_p
Pointer to current element.
virtual long long int memSize() const
Returns the memory usage (in bytes)
virtual Data_T value(int i, int j, int k) const
const real_t & u(int i, int j, int k) const
Read access to value on u-facing wall.
class_type & m_field
Reference to field being iterated over.
const real_t & v(int i, int j, int k) const
Read access to value on v-facing wall.
MACField< V3d > MACField3d
int m_wSizeXY
Size of xy slice for w component.
V3i getComponentSize() const
Returns the size of U,V,W components.
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
DEFINE_FIELD_RTTI_CONCRETE_CLASS
boost::intrusive_ptr< MACField > Ptr
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(MACField)
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...
static TemplatedFieldType< MACField< Data_T > > ms_classType
MACComponent m_comp
Component to look up.
virtual long long int memSize() const
Returns the memory usage (in bytes)
int m_vSizeXY
Size of xy slice for v component.
MACField< V3h > MACField3h
mac_comp_iterator end_comp(MACComponent comp)
Iterator to first element.
V3i m_uSize
Size of U grid along each axis.
const_mac_comp_iterator(MACComponent comp, const class_type &field, const Box3i &window, const V3i ¤tPos)
static const char * classType()
real_t vCenter(int i, int j, int k) const
Returns the v-component interpolated to the cell center.
const real_t & w(int i, int j, int k) const
Read access to value on w-facing wall.
Used to return a string for the name of a templated field.
Data_T m_dummy
Dummy storage of a temp value that lvalue() can write to.
Data_T::BaseType real_t
This typedef is used to refer to the scalar component type of the vectors.
Contains Field, WritableField and ResizableField classes.
int m_uSizeXY
Size of xy slice for u component.
virtual void clear(const Data_T &value)
Clears all the voxels in the storage.
const real_t * wPtr(int i, int j, int k) const
Direct access to value on w-facing wall.
V3i m_vSize
Size of V grid along each axis.
Box3i m_window
Window to traverse.
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.
V3i const dataResolution() const
MACField< Data_T >::real_t real_t
MACField()
Constructs an empty buffer.
Box3i m_window
Window to traverse.
MACField< Data_T > class_type
LinearMACFieldInterp< Data_T > LinearInterp
MACField< Data_T > class_type
static const char * staticClassName()
const real_t * vPtr(int i, int j, int k) const
Direct access to value on v-facing wall.
real_t uCenter(int i, int j, int k) const
Returns the u-component interpolated to the cell center.
void copyMAC(MACField::Ptr other)
TEMP: Copies the MAC field data from another MAC field. This should be re-implemented using proper it...
V3i m_wSize
Size of W grid along each axis.
MACField< V3f > MACField3f
std::vector< real_t > m_u
U component storage.
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
std::string name
Optional name of the field.