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());
262 {
return V3i((
int)
m_u.size(), (int)
m_v.size(), (int)
m_w.size()); }
286 const real_t*
uPtr(
int i,
int j,
int k)
const;
289 real_t*
uPtr(
int i,
int j,
int k);
292 const real_t*
vPtr(
int i,
int j,
int k)
const;
295 real_t*
vPtr(
int i,
int j,
int k);
298 const real_t*
wPtr(
int i,
int j,
int k)
const;
301 real_t*
wPtr(
int i,
int j,
int k);
358 template <
class Data_T>
371 const class_type &field,
373 const V3i ¤tPos)
374 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
375 m_p(NULL), m_window(window), m_comp(comp),
378 if (window.intersects(currentPos))
386 if (x == m_window.max.x) {
387 if (y == m_window.max.y) {
388 if (z == m_window.max.z) {
408 template <
class Iter_T>
409 inline bool operator == (
const Iter_T &rhs)
const 411 return m_p == &(*rhs);
414 template <
class Iter_T>
415 inline bool operator != (
const Iter_T &rhs)
const 417 return m_p != &(*rhs);
425 inline const real_t* operator -> ()
const 443 m_p = m_field.uPtr(x, y, z);
446 m_p = m_field.vPtr(x, y, z);
449 m_p = m_field.wPtr(x, y, z);
452 assert(
false &&
"Illegal MACComponent in const_mac_comp_iterator");
471 template <
class Data_T>
484 const Box3i &window,
const V3i ¤tPos)
485 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
486 m_p(NULL), m_window(window), m_comp(comp),
489 if (window.intersects(currentPos))
497 if (x == m_window.max.x) {
498 if (y == m_window.max.y) {
499 if (z == m_window.max.z) {
519 template <
class Iter_T>
520 inline bool operator == (
const Iter_T &rhs)
const 522 return m_p == &(*rhs);
525 template <
class Iter_T>
526 inline bool operator != (
const Iter_T &rhs)
const 528 return m_p != &(*rhs);
536 inline real_t* operator -> ()
const 554 m_p = m_field.uPtr(x, y, z);
557 m_p = m_field.vPtr(x, y, z);
560 m_p = m_field.wPtr(x, y, z);
563 assert(
false &&
"Illegal MACComponent in const_mac_comp_iterator");
590 dataWindow.max +=
V3i(1, 0, 0);
593 dataWindow.max +=
V3i(0, 1, 0);
596 dataWindow.max +=
V3i(0, 0, 1);
599 assert(
false &&
"Illegal MACComponent in makeDataWindowForComponent");
610 template <
class Data_T>
619 template <
class Data_T>
622 std::fill(
m_u.begin(),
m_u.end(), value.x);
623 std::fill(
m_v.begin(),
m_v.end(), value.y);
624 std::fill(
m_w.begin(),
m_w.end(), value.z);
629 template <
class Data_T>
637 template <
class Data_T>
641 long long int vectorMemSize =
643 return sizeof(*this) + vectorMemSize + superClassMemSize;
648 template <
class Data_T>
657 template <
class Data_T>
666 if (std::min(std::min(baseSize.x, baseSize.y), baseSize.z) < 0)
667 throw Exc::ResizeException(
"Attempt to resize ResizableField object " 668 "using negative size. Data window was: " +
669 boost::lexical_cast<std::string>(baseSize));
687 catch (std::bad_alloc &) {
688 throw Exc::MemoryException(
"Couldn't allocate MACField of size " +
689 boost::lexical_cast<std::string>(baseSize));
696 template <
class Data_T>
715 template <
class Data_T>
734 template <
class Data_T>
753 template <
class Data_T>
772 template <
class Data_T>
791 template <
class Data_T>
810 template <
class Data_T>
824 template <
class Data_T>
829 if (subset.isEmpty())
837 template <
class Data_T>
845 V3i(dataWindow.min.x,
847 dataWindow.max.z + 1));
852 template <
class Data_T>
859 V3i(dataWindow.min.x,
861 dataWindow.max.z + 1));
866 template <
class Data_T>
879 template <
class Data_T>
884 if (subset.isEmpty())
892 template <
class Data_T>
900 dataWindow.max.z + 1));
905 template <
class Data_T>
913 dataWindow.max.z + 1));
918 template <
class Data_T>
931 template <
class Data_T>
944 template <
class Data_T>
957 template <
class Data_T>
970 template <
class Data_T>
983 template <
class Data_T>
1000 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
real_t wCenter(int i, int j, int k) const
Returns the w-component interpolated to the cell center.
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)
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.
V3i getComponentSize() const
Returns the size of U,V,W components.
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.
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
const real_t & v(int i, int j, int k) const
Read access to value on v-facing wall.
std::vector< real_t > m_w
W component storage.
CubicMACFieldInterp< Data_T > CubicInterp
const real_t & u(int i, int j, int k) const
Read access to value on u-facing wall.
boost::intrusive_ptr< FieldBase > Ptr
real_t uCenter(int i, int j, int k) const
Returns the u-component interpolated to the cell center.
static const char * staticClassType()
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
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)
const real_t * wPtr(int i, int j, int k) const
Direct access to value on w-facing wall.
class_type & m_field
Reference to field being iterated over.
virtual Data_T value(int i, int j, int k) const
MACField< V3d > MACField3d
int m_wSizeXY
Size of xy slice for w component.
const real_t & w(int i, int j, int k) const
Read access to value on w-facing wall.
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...
void copyMAC(typename MACField::Ptr other)
TEMP: Copies the MAC field data from another MAC field. This should be re-implemented using proper it...
static TemplatedFieldType< MACField< Data_T > > ms_classType
MACComponent m_comp
Component to look up.
int m_vSizeXY
Size of xy slice for v component.
const real_t * uPtr(int i, int j, int k) const
Direct access to value on u-facing wall.
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)
real_t vCenter(int i, int j, int k) const
Returns the v-component interpolated to the cell center.
Used to return a string for the name of a templated field.
V3i const dataResolution() const
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_mac_comp_iterator cend_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
const real_t * vPtr(int i, int j, int k) const
Direct access to value on v-facing wall.
V3i m_vSize
Size of V grid along each axis.
Box3i m_window
Window to traverse.
virtual long long int memSize() const
Returns the memory usage (in bytes)
const_mac_comp_iterator cbegin_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
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()
V3i m_wSize
Size of W grid along each axis.
MACField< V3f > MACField3f
std::vector< real_t > m_u
U component storage.
std::string name
Optional name of the field.