Go to the documentation of this file.
45 #ifndef _INCLUDED_Field3D_Field_H_
46 #define _INCLUDED_Field3D_Field_H_
52 #include <boost/intrusive_ptr.hpp>
53 #include <boost/thread/mutex.hpp>
97 typedef boost::intrusive_ptr<FieldBase>
Ptr;
125 return staticClassName();
156 {
return m_metadata; }
160 {
return m_metadata; }
213 typedef boost::intrusive_ptr<FieldRes>
Ptr;
214 typedef std::vector<Ptr>
Vec;
222 {
return std::string(
"FieldRes"); }
280 {
return sizeof(*this); }
292 return res.x * res.y * res.z;
354 "Tried to call FieldRes::setMapping with null pointer");
388 template <
class Data_T>
395 typedef boost::intrusive_ptr<Field>
Ptr;
403 typedef std::vector<Ptr>
Vec;
430 class const_iterator;
450 virtual Data_T
value(
int i,
int j,
int k)
const = 0;
473 #define FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION \
474 virtual std::string className() const \
475 { return staticClassName(); } \
476 virtual std::string classType() const \
477 { return staticClassType(); } \
479 #define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field) \
480 template <typename Data_T> \
481 TemplatedFieldType<field<Data_T> > field<Data_T>::ms_classType = \
482 TemplatedFieldType<field<Data_T> >(); \
490 template <
class Data_T>
495 #if defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
496 typedef std::forward_iterator_tag iterator_category;
498 typedef ptrdiff_t difference_type;
499 typedef ptrdiff_t distance_type;
500 typedef Data_T *pointer;
501 typedef Data_T& reference;
507 : x(i.x), y(i.y), z(i.z),
508 m_window(i.m_window), m_field(i.m_field)
512 const V3i ¤tPos)
513 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
514 m_window(window), m_field(field)
521 if (x == m_window.max.x) {
522 if (y == m_window.max.y) {
535 template <
class Iter_T>
536 bool operator == (
const Iter_T &rhs)
const
538 return x == rhs.x && y == rhs.y && z == rhs.z;
540 template <
class Iter_T>
541 bool operator != (
const Iter_T &rhs)
const
543 return x != rhs.x || y != rhs.y || z != rhs.z;
547 return m_field.value(x, y, z);
567 template <
class Data_T>
578 template <
class Data_T>
582 if (subset.isEmpty())
589 template <
class Data_T>
594 V3i(m_dataWindow.min.x,
596 m_dataWindow.max.z + 1));
601 template <
class Data_T>
622 template <
class Data_T>
624 :
public Field<Data_T>
630 typedef boost::intrusive_ptr<WritableField>
Ptr;
639 return "WritableField";
654 inline iterator
begin();
658 inline iterator
end();
661 inline iterator
end(
const Box3i &subset);
673 virtual Data_T&
lvalue(
int i,
int j,
int k) = 0;
702 template <
class Data_T>
706 #if defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
707 typedef std::forward_iterator_tag iterator_category;
709 typedef ptrdiff_t difference_type;
710 typedef ptrdiff_t distance_type;
711 typedef Data_T *pointer;
712 typedef Data_T& reference;
718 const V3i ¤tPos)
719 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
720 m_window(window), m_field(field)
727 if (x == m_window.max.x) {
728 if (y == m_window.max.y) {
742 template <
class Iter_T>
743 bool operator == (
const Iter_T &rhs)
const
745 return x == rhs.x && y == rhs.y && z == rhs.z;
748 template <
class Iter_T>
749 bool operator != (
const Iter_T &rhs)
const
751 return x != rhs.x || y != rhs.y || z != rhs.z;
756 return m_field.lvalue(x, y, z);
777 template <
class Data_T>
789 template <
class Data_T>
793 if (subset.isEmpty())
795 return iterator(*
this, subset, subset.min);
800 template <
class Data_T>
811 template <
class Data_T>
815 V3i(subset.min.x, subset.min.y, subset.max.z + 1));
832 template <
class Data_T>
840 typedef boost::intrusive_ptr<ResizableField>
Ptr;
849 return "ResizableField";
880 template <
class Data_T2>
912 template <
class Data_T>
929 template <
class Data_T>
940 template <
class Data_T>
942 const Box3i &dataWindow)
952 template <
class Data_T>
958 assert(padding >= 0);
966 template <
class Data_T>
975 typename base::iterator i = base::begin();
976 typename base::iterator end = base::end();
978 for (; i != end; ++i, ++c)
984 template <
class Data_T>
985 template <
class Data_T2>
993 typename base::iterator i = base::begin();
994 typename base::iterator end = base::end();
996 for (; i != end; ++i, ++c)
1002 template <
class Data_T>
1005 setSize(fieldToMatch->extents(), fieldToMatch->dataWindow());
1015 template <
class Data_T,
class Data_T2>
1018 double tolerance = 0.0)
1036 template <
class Data_T>
1039 if (!sameDefinition<Data_T, Data_T>(a, b)) {
1048 for (; is1 != ie1; ++is1, ++is2) {
1063 return static_cast<int>(
std::floor(contCoord));
1072 return static_cast<double>(discCoord) + 0.5;
1114 result.min.x =
static_cast<float>(bbox.min.x);
1115 result.min.y =
static_cast<float>(bbox.min.y);
1116 result.min.z =
static_cast<float>(bbox.min.z);
1117 result.max.x =
static_cast<float>(bbox.max.x + 1);
1118 result.max.y =
static_cast<float>(bbox.max.y + 1);
1119 result.max.z =
static_cast<float>(bbox.max.z + 1);
1134 result.min.x =
static_cast<int>(
floor(clampForType<double, int>(bbox.min.x)));
1135 result.min.y =
static_cast<int>(
floor(clampForType<double, int>(bbox.min.y)));
1136 result.min.z =
static_cast<int>(
floor(clampForType<double, int>(bbox.min.z)));
1137 result.max.x =
static_cast<int>(
ceil(clampForType<double, int>(bbox.max.x)));
1138 result.max.y =
static_cast<int>(
ceil(clampForType<double, int>(bbox.max.y)));
1139 result.max.z =
static_cast<int>(
ceil(clampForType<double, int>(bbox.max.z)));
1148 result.min.x =
std::max(bbox.min.x, bounds.min.x);
1149 result.min.y =
std::max(bbox.min.y, bounds.min.y);
1150 result.min.z =
std::max(bbox.min.z, bounds.min.z);
1151 result.max.x =
std::min(bbox.max.x, bounds.max.x);
1152 result.max.y =
std::min(bbox.max.y, bounds.max.y);
1153 result.max.z =
std::min(bbox.max.z, bounds.max.z);
1160 template <
class Iter_T>
1166 for (
int i=0; i<num; ++i, ++iter) {
1174 template <
class Iter_T>
1175 void advance(Iter_T &iter,
int num,
const Iter_T &end)
1180 for (
int i=0; i<num && iter != end; ++i, ++iter) {
1189 const int i = idx % res.x;
1190 const int j = (idx / res.x) % res.y;
1191 const int k = idx / (res.x * res.y);
1192 return V3i(i, j, k);
1201 #endif // Include guard
Box3i m_extents
Defines the extents of the the storage. This may be larger or smaller than the data window,...
void setSize(const V3i &size)
Resizes the object.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
bool isIdentical(typename Field< Data_T >::Ptr a, typename Field< Data_T >::Ptr b)
Checks whether the span and data in two different fields are identical.
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
virtual std::string classType() const =0
Returns the full class type string.
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
virtual Data_T & lvalue(int i, int j, int k)=0
Write access to a voxel. The coordinates are global coordinates.
static const char * staticClassType()
virtual size_t voxelCount() const
Counts the number of voxels. For most fields, this is just the volume of the data window,...
virtual std::string dataTypeString() const
int contToDisc(double contCoord)
Goes from continuous coordinates to discrete coordinates See Graphics Gems - What is a pixel.
FIELD3D_VEC3_T< T > operator*(S s, const FIELD3D_VEC3_T< T > vec)
Scalar times Vec3 multiplication. Makes the interpolation calls cleaner.
virtual void mappingChanged()
Tells the subclass that the mapping changed.
Contains typedefs for the commonly used types in Field3D.
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel.
FieldMetadata & metadata()
accessor to the m_metadata class
boost::intrusive_ptr< Field > Ptr
const FieldMapping::Ptr mapping() const
Returns a pointer to the mapping.
#define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field)
iterator end()
Iterator pointing one element past the last valid one.
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e....
virtual std::string className() const =0
Returns the class name of the object. Used by the class pool and when writing the data to disk.
static const char * staticClassType()
const FieldMetadata & metadata() const
Read only access to the m_metadata class.
static TemplatedFieldType< WritableField< Data_T > > ms_classType
Data_T value_type
Allows us to reference the template class.
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
virtual Ptr clone() const =0
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
WritableField< Data_T > base
boost::intrusive_ptr< FieldMapping > Ptr
std::string name
Optional name of the field.
Contains the FieldMapping base class and the NullFieldMapping and MatrixFieldMapping subclasses.
Contains base class for reference counting with Mutex.
V3i indexToCoord(const size_t idx, const V3i &res)
const_iterator cbegin() const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
boost::intrusive_ptr< FieldBase > Ptr
void copyMetadata(const FieldBase &field)
Copies the metadata from a second field.
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
const_iterator cend(const Box3i &subset) const
Const iterator pointing one element past the last valid one (for a subset)
Box3i m_window
Window to traverse.
V3i const dataResolution() const
bool sameDefinition(typename Field< Data_T >::Ptr a, typename Field< Data_T2 >::Ptr b, double tolerance=0.0)
Checks whether the mapping and resolution in two different fields are identical.
FieldRes()
This constructor ensures that we have a valid mapping at all times.
WritableField< Data_T > class_type
FIELD3D_VEC3_T< T > floor(const FIELD3D_VEC3_T< T > &v)
Floor function for Vec3.
static const char * staticClassType()
Contains the Log class which can be used to redirect output to an arbitrary destination.
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Box3i discreteBounds(const Box3d &bbox)
Converts a floating point bounding box to an integer bounding box.
Contains Exception base class.
Box3d continuousBounds(const Box3i &bbox)
boost::intrusive_ptr< FieldRes > Ptr
bool isInBounds(int i, int j, int k) const
Returns true is the indicies are in bounds of the data window.
MatrixFieldMapping default_mapping
static const char * staticClassType()
std::string attribute
Optional name of the attribute the field represents.
T max(const T a, const T2 b)
Max operation on mixed types.
iterator begin()
Iterator to first element.
static TemplatedFieldType< Field< Data_T > > ms_classType
FieldMapping::Ptr m_mapping
Pointer to the field's mapping.
void advance(Iter_T &iter, int num)
static TemplatedFieldType< ResizableField< Data_T > > ms_classType
boost::intrusive_ptr< WritableField > Ptr
const_iterator cend() const
Const iterator pointing one element past the last valid one.
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
virtual long long int memSize() const
Returns the memory usage (in bytes)
static const char * staticClassName()
void matchDefinition(FieldRes::Ptr fieldToMatch)
Sets up this field so that resolution and mapping matches the other.
const Field< Data_T > & m_field
Reference to field being iterated over.
static const char * staticClassName()
boost::intrusive_ptr< ResizableField > Ptr
static const char * staticClassName()
FIELD3D_VEC3_T< T > ceil(const FIELD3D_VEC3_T< T > &v)
Ceil function for Vec3.
Represents the mapping of a field by a matrix transform.
static const char * staticClassName()
Namespace for Exception objects.
const_iterator(const const_iterator &i)
WritableField< Data_T > & m_field
Reference to field being iterated over.
Box3i m_window
Window to traverse.
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over....
const_iterator(const Field< Data_T > &field, const Box3i &window, const V3i ¤tPos)
FieldRes base
Convenience typedef for referring to base class.
FieldMetadata m_metadata
metadata
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc....
FieldBase base
Convenience typedef for referring to base class.
const_iterator cbegin(const Box3i &subset) const
Const iterator to first element of specific subset.
virtual std::string dataTypeString() const
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
ResizableField< Data_T > class_type
Used to return a string for the name of a templated field.
static std::string name()
T min(const T a, const T2 b)
Min operation on mixed types.
static const char * staticClassType()
static const char * staticClassName()
Field< Data_T > class_type
void copyFrom(typename Field< Data_T >::Ptr other)
Copies the data from another Field, also resizes.
virtual Data_T value(int i, int j, int k) const =0
Read access to a voxel. The coordinates are in integer voxel space .
#define DECLARE_FIELD3D_GENERIC_EXCEPTION(name, base_class)
Used to declare a generic but named exception.
iterator(WritableField< Data_T > &field, const Box3i &window, const V3i ¤tPos)
virtual void clear(const Data_T &value)
Clears all the voxels in the storage. Should be re-implemented by subclasses that can provide a more ...
DEFINE_FIELD_RTTI_ABSTRACT_CLASS