44 #ifndef _INCLUDED_Field3D_DenseField_H_ 45 #define _INCLUDED_Field3D_DenseField_H_ 49 #include <boost/lexical_cast.hpp> 63 template <
class Field_T>
65 template <
class Field_T>
81 template <
class Data_T>
89 typedef boost::intrusive_ptr<DenseField>
Ptr;
90 typedef std::vector<Ptr>
Vec;
116 virtual Data_T
value(
int i,
int j,
int k)
const;
117 virtual long long int memSize()
const;
139 virtual Data_T&
lvalue(
int i,
int j,
int k);
145 const Data_T&
fastValue(
int i,
int j,
int k)
const;
226 inline Data_T*
ptr(
int i,
int j,
int k);
228 inline const Data_T*
ptr(
int i,
int j,
int k)
const;
247 template <
class Data_T>
259 const V3i ¤tPos)
260 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
261 m_window(window), m_field(field)
262 { m_p = m_field.ptr(x, y, z); }
268 if (x == m_window.max.x) {
269 if (y == m_window.max.y) {
270 m_p = m_field.ptr(x = m_window.min.x, y = m_window.min.y, ++z);
272 m_p = m_field.ptr(x = m_window.min.x, ++y, z);
281 template <
class Iter_T>
282 inline bool operator == (
const Iter_T &rhs)
const 284 return m_p == &(*rhs);
287 template <
class Iter_T>
288 inline bool operator != (
const Iter_T &rhs)
const 290 return m_p != &(*rhs);
298 inline const Data_T* operator -> ()
const 325 template <
class Data_T>
337 const V3i ¤tPos)
338 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
339 m_window(window), m_field(field)
340 { m_p = m_field.ptr(x, y, z); }
346 if (x == m_window.max.x) {
347 if (y == m_window.max.y) {
348 m_p = m_field.ptr(x = m_window.min.x, y = m_window.min.y, ++z);
350 m_p = m_field.ptr(x = m_window.min.x, ++y, z);
359 template <
class Iter_T>
360 inline bool operator == (
const Iter_T &rhs)
const 362 return m_p == &(*rhs);
365 template <
class Iter_T>
366 inline bool operator != (
const Iter_T &rhs)
const 368 return m_p != &(*rhs);
376 inline Data_T* operator -> ()
const 402 template <
class Data_T>
412 template <
class Data_T>
420 template <
class Data_T>
428 template <
class Data_T>
432 long long int vectorMemSize =
m_data.capacity() *
sizeof(Data_T);
433 return sizeof(*this) + vectorMemSize + superClassMemSize;
438 template <
class Data_T>
446 template <
class Data_T>
465 template <
class Data_T>
484 template <
class Data_T>
495 template <
class Data_T>
499 if (subset.isEmpty())
506 template <
class Data_T>
518 template <
class Data_T>
523 V3i(subset.min.x, subset.min.y, subset.max.z + 1));
528 template <
class Data_T>
538 template <
class Data_T>
542 if (subset.isEmpty())
544 return iterator(*
this, subset, subset.min);
549 template <
class Data_T>
561 template <
class Data_T>
566 V3i(subset.min.x, subset.min.y, subset.max.z + 1));
571 template <
class Data_T>
585 throw Exc::ResizeException(
"Attempt to resize ResizableField object " 586 "using negative size. Data window was: " +
587 boost::lexical_cast<std::string>(
589 boost::lexical_cast<std::string>(
594 std::vector<Data_T>().swap(
m_data);
597 catch (std::bad_alloc &e) {
598 throw Exc::MemoryException(
"Couldn't allocate DenseField of size " +
599 boost::lexical_cast<std::string>(
m_memSize));
605 template <
class Data_T>
618 template <
class Data_T>
641 #endif // Include guard This subclass of Field stores data in a contiguous std::vector.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
static DEFINE_FIELD_RTTI_CONCRETE_CLASS const char * staticClassName()
const FIELD3D_VEC3_T< size_t > & internalMemSize() const
Returns the internal memory size in each dimension. This is used for example in LinearInterpolator, where it optimizes random access to voxels.
FIELD3D_VEC3_T< size_t > m_memSize
Memory allocation size in each dimension.
const_iterator cend() const
Const iterator pointing one element past the last valid one.
std::vector< Data_T > m_data
Field storage.
DenseField< double > DenseFieldd
iterator begin()
Iterator to first element.
class_type & m_field
Reference to field being iterated over.
DenseField< V3d > DenseField3d
LinearGenericFieldInterp< DenseField< Data_T > > LinearInterp
boost::intrusive_ptr< FieldBase > Ptr
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.
virtual std::string className() const
Returns the class name of the object. Used by the class pool and when writing the data to disk...
iterator end()
Iterator pointing one element past the last valid one.
virtual long long int memSize() const
Returns the memory usage (in bytes)
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
DenseField< Data_T > class_type
const_iterator(const class_type &field, const Box3i &window, const V3i ¤tPos)
virtual FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
size_t m_memSizeXY
X scanline * Y scanline size.
DenseField< Data_T > class_type
DenseField()
Constructs an empty buffer.
Data_T * ptr(int i, int j, int k)
Returns a pointer to a given element. Used by the iterators mainly.
static const char * classType()
Data_T * m_p
Pointer to current element.
virtual Data_T value(int i, int j, int k) const
Read access to a voxel. The coordinates are in integer voxel space .
const Data_T * m_p
Pointer to current element.
ResizableField< Data_T > base
DenseField< half > DenseFieldh
virtual long long int memSize() const
Returns the memory usage (in bytes)
static TemplatedFieldType< DenseField< Data_T > > ms_classType
const Data_T & fastValue(int i, int j, int k) const
Read access to voxel. Notice that this is non-virtual.
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(DenseField)
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
DenseField< Data_T > class_type
Used to return a string for the name of a templated field.
iterator(class_type &field, const Box3i &window, const V3i ¤tPos)
virtual void clear(const Data_T &value)
Clears all the voxels in the storage.
Box3i m_window
Window to traverse.
Contains Field, WritableField and ResizableField classes.
const_iterator cbegin() const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
boost::intrusive_ptr< DenseField > Ptr
DenseField< float > DenseFieldf
DenseField< V3h > DenseField3h
Box3i m_window
Window to traverse.
DenseField< V3f > DenseField3f
#define DEFINE_FIELD_RTTI_CONCRETE_CLASS
V3i const dataResolution() const
Data_T & fastLValue(int i, int j, int k)
Write access to voxel. Notice that this is non-virtual.
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 class_type & m_field
Reference to field being iterated over.
CubicGenericFieldInterp< DenseField< Data_T > > CubicInterp
std::string name
Optional name of the field.