Field3D
|
This subclass of Field implements a standard MAC field. Refer to your favorite fluid simulations book for an explanation. More...
#include <MACField.h>
Classes | |
class | const_mac_comp_iterator |
class | mac_comp_iterator |
Public Types | |
typedef MACField< Data_T > | class_type |
typedef CubicMACFieldInterp < Data_T > | CubicInterp |
typedef LinearMACFieldInterp < Data_T > | LinearInterp |
typedef boost::intrusive_ptr < MACField > | Ptr |
typedef Data_T::BaseType | real_t |
This typedef is used to refer to the scalar component type of the vectors. | |
typedef std::vector< Ptr > | Vec |
Public Member Functions | |
virtual void | clear (const Data_T &value) |
Clears all the voxels in the storage. | |
void | copyMAC (MACField::Ptr other) |
TEMP: Copies the MAC field data from another MAC field. This should be re-implemented using proper iterators over the field. | |
V3i | getComponentSize () const |
Returns the size of U,V,W components. | |
real_t | uCenter (int i, int j, int k) const |
Returns the u-component interpolated to the cell center. | |
real_t | vCenter (int i, int j, int k) const |
Returns the v-component interpolated to the cell center. | |
real_t | wCenter (int i, int j, int k) const |
Returns the w-component interpolated to the cell center. | |
Constructors & destructor | |
MACField () | |
Constructs an empty buffer. | |
From Field | |
virtual Data_T | value (int i, int j, int k) const |
virtual long long int | memSize () const |
From WritableField | |
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 change the MAC field. | |
MAC-component access | |
const real_t & | u (int i, int j, int k) const |
Read access to value on u-facing wall. | |
real_t & | u (int i, int j, int k) |
Write access to value on u-facing wall. | |
const real_t & | v (int i, int j, int k) const |
Read access to value on v-facing wall. | |
real_t & | v (int i, int j, int k) |
Write access to value on v-facing wall. | |
const real_t & | w (int i, int j, int k) const |
Read access to value on w-facing wall. | |
real_t & | w (int i, int j, int k) |
Write access to value on w-facing wall. | |
MAC-component iterators | |
A note about MAC iterators The subset that we choose to iterate over is defined by voxels, not MAC face coordinates. Thus, iterator from (0, 0, 0) to (0, 0, 0) will actually visit (0, 0, 0) and (1, 0, 0) for the u component, and (0, 0, 0) to (0, 1, 0) for the v component... | |
const_mac_comp_iterator | cbegin_comp (MACComponent comp) const |
Const iterator to first element. "cbegin" matches the tr1 c++ standard. | |
const_mac_comp_iterator | cbegin_comp (MACComponent comp, const Box3i &subset) const |
Const iterator to first element of specific subset. | |
const_mac_comp_iterator | cend_comp (MACComponent comp) const |
Const iterator to first element. "cbegin" matches the tr1 c++ standard. | |
const_mac_comp_iterator | cend_comp (MACComponent comp, const Box3i &subset) const |
Const iterator to first element of specific subset. | |
mac_comp_iterator | begin_comp (MACComponent comp) |
Iterator to first element. | |
mac_comp_iterator | begin_comp (MACComponent comp, const Box3i &subset) |
Iterator to first element of specific subset. | |
mac_comp_iterator | end_comp (MACComponent comp) |
Iterator to first element. | |
mac_comp_iterator | end_comp (MACComponent comp, const Box3i &subset) |
Iterator to first element of specific subset. | |
From FieldBase | |
virtual std::string | className () const |
virtual FieldBase::Ptr | clone () const |
Static Public Member Functions | |
static const char * | classType () |
static const char * | staticClassName () |
Public Attributes | |
DEFINE_FIELD_RTTI_CONCRETE_CLASS | |
Protected Member Functions | |
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 real_t * | uPtr (int i, int j, int k) const |
Direct access to value on u-facing wall. | |
real_t * | uPtr (int i, int j, int k) |
Direct access to value on u-facing wall. | |
const real_t * | vPtr (int i, int j, int k) const |
Direct access to value on v-facing wall. | |
real_t * | vPtr (int i, int j, int k) |
Direct access to value on v-facing wall. | |
const real_t * | wPtr (int i, int j, int k) const |
Direct access to value on w-facing wall. | |
real_t * | wPtr (int i, int j, int k) |
Direct access to value on w-facing wall. | |
Protected Attributes | |
Data_T | m_dummy |
Dummy storage of a temp value that lvalue() can write to. | |
std::vector< real_t > | m_u |
U component storage. | |
V3i | m_uSize |
Size of U grid along each axis. | |
int | m_uSizeXY |
Size of xy slice for u component. | |
std::vector< real_t > | m_v |
V component storage. | |
V3i | m_vSize |
Size of V grid along each axis. | |
int | m_vSizeXY |
Size of xy slice for v component. | |
std::vector< real_t > | m_w |
W component storage. | |
V3i | m_wSize |
Size of W grid along each axis. | |
int | m_wSizeXY |
Size of xy slice for w component. | |
Private Types | |
typedef ResizableField< Data_T > | base |
Static Private Attributes | |
static TemplatedFieldType < MACField< Data_T > > | ms_classType |
This subclass of Field implements a standard MAC field. Refer to your favorite fluid simulations book for an explanation.
The definition for u,v,w indexing used can be found on page 25 in Bridson - Fluid Simulation for Computer Graphics
typedef boost::intrusive_ptr<MACField> MACField::Ptr |
Reimplemented from ResizableField< Data_T >.
Definition at line 101 of file MACField.h.
typedef std::vector<Ptr> MACField::Vec |
Definition at line 102 of file MACField.h.
typedef Data_T::BaseType MACField::real_t |
This typedef is used to refer to the scalar component type of the vectors.
Definition at line 105 of file MACField.h.
typedef LinearMACFieldInterp<Data_T> MACField::LinearInterp |
Definition at line 107 of file MACField.h.
typedef CubicMACFieldInterp<Data_T> MACField::CubicInterp |
Definition at line 108 of file MACField.h.
typedef MACField<Data_T> MACField::class_type |
Reimplemented from ResizableField< Data_T >.
Definition at line 112 of file MACField.h.
typedef ResizableField<Data_T> MACField::base [private] |
Reimplemented from ResizableField< Data_T >.
Definition at line 337 of file MACField.h.
MACField::MACField | ( | ) |
Constructs an empty buffer.
Definition at line 600 of file MACField.h.
Referenced by clone().
: base() { }
static const char* MACField::staticClassName | ( | ) | [inline, static] |
Reimplemented from ResizableField< Data_T >.
Definition at line 115 of file MACField.h.
Referenced by className().
{ return "MACField"; }
static const char* MACField::classType | ( | ) | [inline, static] |
Reimplemented from ResizableField< Data_T >.
Definition at line 120 of file MACField.h.
{ return MACField<Data_T>::ms_classType.name(); }
void MACField::clear | ( | const Data_T & | value | ) | [inline, virtual] |
Data_T MACField::value | ( | int | i, |
int | j, | ||
int | k | ||
) | const [virtual] |
Definition at line 619 of file MACField.h.
Referenced by convertMACToCellCentered().
long long int MACField::memSize | ( | ) | const [virtual] |
Definition at line 627 of file MACField.h.
{ 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; }
Data_T & MACField::lvalue | ( | int | i, |
int | j, | ||
int | k | ||
) | [virtual] |
This will return the appropriate interpolated value but setting that to something else does not change the MAC field.
Definition at line 638 of file MACField.h.
Read access to value on u-facing wall.
Definition at line 687 of file MACField.h.
Referenced by LinearMACFieldInterp::sample(), CubicMACFieldInterp::sample(), uCenter(), and convertCellCenteredToMAC().
{ 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]; }
Write access to value on u-facing wall.
Definition at line 706 of file MACField.h.
{ 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]; }
Read access to value on v-facing wall.
Definition at line 725 of file MACField.h.
Referenced by LinearMACFieldInterp::sample(), CubicMACFieldInterp::sample(), vCenter(), and convertCellCenteredToMAC().
{ 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]; }
Write access to value on v-facing wall.
Definition at line 744 of file MACField.h.
{ 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]; }
Read access to value on w-facing wall.
Definition at line 763 of file MACField.h.
Referenced by LinearMACFieldInterp::sample(), CubicMACFieldInterp::sample(), wCenter(), and convertCellCenteredToMAC().
{ 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]; }
Write access to value on w-facing wall.
Definition at line 782 of file MACField.h.
{ 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]; }
MACField< Data_T >::const_mac_comp_iterator MACField::cbegin_comp | ( | MACComponent | comp | ) | const |
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
Definition at line 801 of file MACField.h.
References FieldRes::dataResolution(), and MACFieldUtil::makeDataWindowForComponent().
Referenced by MACFieldIO::writeData().
{ 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); }
MACField< Data_T >::const_mac_comp_iterator MACField::cbegin_comp | ( | MACComponent | comp, |
const Box3i & | subset | ||
) | const |
Const iterator to first element of specific subset.
Definition at line 815 of file MACField.h.
References MACFieldUtil::makeDataWindowForComponent().
{ 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); }
MACField< Data_T >::const_mac_comp_iterator MACField::cend_comp | ( | MACComponent | comp | ) | const |
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
Definition at line 828 of file MACField.h.
References MACFieldUtil::makeDataWindowForComponent().
{ 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)); }
MACField< Data_T >::const_mac_comp_iterator MACField::cend_comp | ( | MACComponent | comp, |
const Box3i & | subset | ||
) | const |
Const iterator to first element of specific subset.
Definition at line 843 of file MACField.h.
References MACFieldUtil::makeDataWindowForComponent().
{ 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)); }
MACField< Data_T >::mac_comp_iterator MACField::begin_comp | ( | MACComponent | comp | ) |
Iterator to first element.
Definition at line 857 of file MACField.h.
References FieldRes::dataResolution(), and MACFieldUtil::makeDataWindowForComponent().
Referenced by MACFieldIO::readData().
{ 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); }
MACField< Data_T >::mac_comp_iterator MACField::begin_comp | ( | MACComponent | comp, |
const Box3i & | subset | ||
) |
Iterator to first element of specific subset.
Definition at line 870 of file MACField.h.
References MACFieldUtil::makeDataWindowForComponent().
{ 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); }
MACField< Data_T >::mac_comp_iterator MACField::end_comp | ( | MACComponent | comp | ) |
Iterator to first element.
Definition at line 883 of file MACField.h.
References MACFieldUtil::makeDataWindowForComponent().
{ 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)); }
MACField< Data_T >::mac_comp_iterator MACField::end_comp | ( | MACComponent | comp, |
const Box3i & | subset | ||
) |
Iterator to first element of specific subset.
Definition at line 896 of file MACField.h.
References MACFieldUtil::makeDataWindowForComponent().
{ 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)); }
real_t MACField::uCenter | ( | int | i, |
int | j, | ||
int | k | ||
) | const [inline] |
Returns the u-component interpolated to the cell center.
Definition at line 233 of file MACField.h.
References u().
real_t MACField::vCenter | ( | int | i, |
int | j, | ||
int | k | ||
) | const [inline] |
Returns the v-component interpolated to the cell center.
Definition at line 238 of file MACField.h.
References v().
real_t MACField::wCenter | ( | int | i, |
int | j, | ||
int | k | ||
) | const [inline] |
Returns the w-component interpolated to the cell center.
Definition at line 243 of file MACField.h.
References w().
void MACField::copyMAC | ( | MACField::Ptr | other | ) | [inline] |
TEMP: Copies the MAC field data from another MAC field. This should be re-implemented using proper iterators over the field.
Definition at line 250 of file MACField.h.
References ResizableField< Data_T >::matchDefinition(), m_u, m_v, and m_w.
{ 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()); }
V3i MACField::getComponentSize | ( | ) | const [inline] |
Returns the size of U,V,W components.
Definition at line 261 of file MACField.h.
Referenced by MACFieldIO::writeInternal(), and MACFieldIO::writeData().
virtual std::string MACField::className | ( | ) | const [inline, virtual] |
Definition at line 269 of file MACField.h.
References staticClassName().
{ return staticClassName(); }
virtual FieldBase::Ptr MACField::clone | ( | ) | const [inline, virtual] |
Definition at line 272 of file MACField.h.
References MACField().
void MACField::sizeChanged | ( | ) | [protected, virtual] |
Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.
Reimplemented from ResizableField< Data_T >.
Definition at line 647 of file MACField.h.
{ // 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 &e) { throw Exc::MemoryException("Couldn't allocate MACField of size " + boost::lexical_cast<std::string>(baseSize)); } }
Definition at line 113 of file MACField.h.
std::vector<real_t> MACField::m_u [protected] |
U component storage.
Definition at line 307 of file MACField.h.
Referenced by copyMAC(), and getComponentSize().
std::vector<real_t> MACField::m_v [protected] |
V component storage.
Definition at line 309 of file MACField.h.
Referenced by copyMAC(), and getComponentSize().
std::vector<real_t> MACField::m_w [protected] |
W component storage.
Definition at line 311 of file MACField.h.
Referenced by copyMAC(), and getComponentSize().
V3i MACField::m_uSize [protected] |
Size of U grid along each axis.
Definition at line 314 of file MACField.h.
int MACField::m_uSizeXY [protected] |
Size of xy slice for u component.
Definition at line 316 of file MACField.h.
V3i MACField::m_vSize [protected] |
Size of V grid along each axis.
Definition at line 318 of file MACField.h.
int MACField::m_vSizeXY [protected] |
Size of xy slice for v component.
Definition at line 320 of file MACField.h.
V3i MACField::m_wSize [protected] |
Size of W grid along each axis.
Definition at line 322 of file MACField.h.
int MACField::m_wSizeXY [protected] |
Size of xy slice for w component.
Definition at line 324 of file MACField.h.
Data_T MACField::m_dummy [mutable, protected] |
Dummy storage of a temp value that lvalue() can write to.
Definition at line 327 of file MACField.h.
TemplatedFieldType<MACField<Data_T> > MACField::ms_classType [static, private] |
Reimplemented from ResizableField< Data_T >.
Definition at line 333 of file MACField.h.