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();
138 virtual std::string className()
const = 0;
141 virtual std::string classType()
const = 0;
145 virtual Ptr clone()
const = 0;
156 {
return m_metadata; }
160 {
return m_metadata; }
218 typedef boost::intrusive_ptr<FieldRes>
Ptr;
219 typedef std::vector<Ptr>
Vec;
227 {
return std::string(
"FieldRes"); }
236 return staticClassName();
255 {
return m_extents; }
259 {
return m_dataWindow; }
262 {
return m_dataWindow.max - m_dataWindow.min +
V3i(1); }
269 {
return m_mapping; }
273 {
return m_mapping; }
276 bool isInBounds(
int i,
int j,
int k)
const;
285 {
return sizeof(*this); }
296 V3i res = m_dataWindow.size() +
V3i(1);
297 return res.x * res.y * res.z;
359 "Tried to call FieldRes::setMapping with null pointer");
393 template <
class Data_T>
400 typedef boost::intrusive_ptr<Field>
Ptr;
408 typedef std::vector<Ptr>
Vec;
435 class const_iterator;
438 const_iterator cbegin()
const;
440 const_iterator cbegin(
const Box3i &subset)
const;
442 const_iterator cend()
const;
445 const_iterator cend(
const Box3i &subset)
const;
455 virtual Data_T value(
int i,
int j,
int k)
const = 0;
478 #define FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION \ 479 virtual std::string className() const \ 480 { return staticClassName(); } \ 481 virtual std::string classType() const \ 482 { return staticClassType(); } \ 484 #define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field) \ 485 template <typename Data_T> \ 486 TemplatedFieldType<field<Data_T> > field<Data_T>::ms_classType = \ 487 TemplatedFieldType<field<Data_T> >(); \ 495 template <
class Data_T>
500 #if defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 501 typedef std::forward_iterator_tag iterator_category;
503 typedef ptrdiff_t difference_type;
504 typedef ptrdiff_t distance_type;
505 typedef Data_T *pointer;
506 typedef Data_T& reference;
512 : x(i.x), y(i.y), z(i.z),
513 m_window(i.m_window), m_field(i.m_field)
517 const V3i ¤tPos)
518 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
519 m_window(window), m_field(field)
526 if (x == m_window.max.x) {
527 if (y == m_window.max.y) {
540 template <
class Iter_T>
541 bool operator == (
const Iter_T &rhs)
const 543 return x == rhs.x && y == rhs.y && z == rhs.z;
545 template <
class Iter_T>
546 bool operator != (
const Iter_T &rhs)
const 548 return x != rhs.x || y != rhs.y || z != rhs.z;
552 return m_field.value(x, y, z);
572 template <
class Data_T>
583 template <
class Data_T>
587 if (subset.isEmpty())
594 template <
class Data_T>
606 template <
class Data_T>
627 template <
class Data_T>
629 :
public Field<Data_T>
635 typedef boost::intrusive_ptr<WritableField>
Ptr;
644 return "WritableField";
678 virtual Data_T& lvalue(
int i,
int j,
int k) = 0;
684 virtual void clear(
const Data_T &value)
685 { std::fill(begin(), end(), value); }
707 template <
class Data_T>
711 #if defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 712 typedef std::forward_iterator_tag iterator_category;
714 typedef ptrdiff_t difference_type;
715 typedef ptrdiff_t distance_type;
716 typedef Data_T *pointer;
717 typedef Data_T& reference;
723 const V3i ¤tPos)
724 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
725 m_window(window), m_field(field)
732 if (x == m_window.max.x) {
733 if (y == m_window.max.y) {
747 template <
class Iter_T>
748 bool operator == (
const Iter_T &rhs)
const 750 return x == rhs.x && y == rhs.y && z == rhs.z;
753 template <
class Iter_T>
754 bool operator != (
const Iter_T &rhs)
const 756 return x != rhs.x || y != rhs.y || z != rhs.z;
761 return m_field.lvalue(x, y, z);
782 template <
class Data_T>
794 template <
class Data_T>
798 if (subset.isEmpty())
800 return iterator(*
this, subset, subset.min);
805 template <
class Data_T>
816 template <
class Data_T>
820 V3i(subset.min.x, subset.min.y, subset.max.z + 1));
837 template <
class Data_T>
845 typedef boost::intrusive_ptr<ResizableField>
Ptr;
854 return "ResizableField";
867 void setSize(
const V3i &size);
879 void setSize(
const V3i &size,
int padding);
885 template <
class Data_T2>
907 { base::m_mapping->setExtents(base::m_extents); }
917 template <
class Data_T>
934 template <
class Data_T>
945 template <
class Data_T>
957 template <
class Data_T>
963 assert(padding >= 0);
971 template <
class Data_T>
980 typename base::iterator i = base::begin();
981 typename base::iterator end = base::end();
983 for (; i != end; ++i, ++c)
989 template <
class Data_T>
990 template <
class Data_T2>
998 typename base::iterator i = base::begin();
999 typename base::iterator end = base::end();
1001 for (; i != end; ++i, ++c)
1007 template <
class Data_T>
1010 setSize(fieldToMatch->extents(), fieldToMatch->dataWindow());
1020 template <
class Data_T,
class Data_T2>
1023 double tolerance = 0.0)
1041 template <
class Data_T>
1044 if (!sameDefinition<Data_T, Data_T>(a, b)) {
1053 for (; is1 != ie1; ++is1, ++is2) {
1068 return static_cast<int>(
std::floor(contCoord));
1077 return static_cast<double>(discCoord) + 0.5;
1119 result.min.x =
static_cast<float>(bbox.min.x);
1120 result.min.y =
static_cast<float>(bbox.min.y);
1121 result.min.z =
static_cast<float>(bbox.min.z);
1122 result.max.x =
static_cast<float>(bbox.max.x + 1);
1123 result.max.y =
static_cast<float>(bbox.max.y + 1);
1124 result.max.z =
static_cast<float>(bbox.max.z + 1);
1133 result.min.x =
static_cast<int>(
std::floor(bbox.min.x));
1134 result.min.y =
static_cast<int>(
std::floor(bbox.min.y));
1135 result.min.z =
static_cast<int>(
std::floor(bbox.min.z));
1136 result.max.x =
static_cast<int>(
std::ceil(bbox.max.x));
1137 result.max.y =
static_cast<int>(
std::ceil(bbox.max.y));
1138 result.max.z =
static_cast<int>(
std::ceil(bbox.max.z));
1147 result.min.x = std::max(bbox.min.x, bounds.min.x);
1148 result.min.y = std::max(bbox.min.y, bounds.min.y);
1149 result.min.z = std::max(bbox.min.z, bounds.min.z);
1150 result.max.x = std::min(bbox.max.x, bounds.max.x);
1151 result.max.y = std::min(bbox.max.y, bounds.max.y);
1152 result.max.z = std::min(bbox.max.z, bounds.max.z);
1159 template <
class Iter_T>
1165 for (
int i=0; i<num; ++i, ++iter) {
1173 template <
class Iter_T>
1174 void advance(Iter_T &iter,
int num,
const Iter_T &end)
1179 for (
int i=0; i<num && iter != end; ++i, ++iter) {
1188 const int i = idx % res.x;
1189 const int j = (idx / res.x) % res.y;
1190 const int k = idx / (res.x * res.y);
1191 return V3i(i, j, k);
1200 #endif // Include guard #define FIELD3D_NAMESPACE_HEADER_CLOSE
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
FieldMapping::Ptr m_mapping
Pointer to the field's mapping.
Contains typedefs for the commonly used types in Field3D.
FieldMetadata< FieldBase > m_metadata
metadata
static const char * staticClassType()
FieldMetadata< FieldBase > & metadata()
accessor to the m_metadata class
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Namespace for Exception objects.
FieldRes()
This constructor ensures that we have a valid mapping at all times.
MatrixFieldMapping default_mapping
static const char * staticClassName()
void matchDefinition(FieldRes::Ptr fieldToMatch)
Sets up this field so that resolution and mapping matches the other.
static const char * staticClassName()
boost::intrusive_ptr< ResizableField > Ptr
Contains base class for reference counting with Mutex.
boost::intrusive_ptr< FieldBase > Ptr
WritableField< Data_T > class_type
static const char * staticClassType()
const_iterator cend() const
Const iterator pointing one element past the last valid one.
static std::string name()
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
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 size_t voxelCount() const
Counts the number of voxels. For most fields, this is just the volume of the data window...
Data_T value_type
Allows us to reference the template class.
boost::intrusive_ptr< FieldRes > Ptr
const FieldMapping::Ptr mapping() const
Returns a pointer to the mapping.
static const char * staticClassName()
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 ...
void copyFrom(typename Field< Data_T >::Ptr other)
Copies the data from another Field, also resizes.
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Contains the Log class which can be used to redirect output to an arbitrary destination.
ResizableField< Data_T > class_type
Box3i m_window
Window to traverse.
boost::intrusive_ptr< FieldMapping > Ptr
void setSize(const V3i &size)
Resizes the object.
const Field< Data_T > & m_field
Reference to field being iterated over.
static const char * staticClassType()
static const char * staticClassType()
bool isInBounds(int i, int j, int k) const
Returns true is the indicies are in bounds of the data window.
iterator begin()
Iterator to first element.
void advance(Iter_T &iter, int num)
iterator end()
Iterator pointing one element past the last valid one.
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
FIELD3D_VEC3_T< T > floor(const FIELD3D_VEC3_T< T > &v)
Floor function for Vec3.
Box3i discreteBounds(const Box3d &bbox)
virtual std::string dataTypeString() const
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
const_iterator(const Field< Data_T > &field, const Box3i &window, const V3i ¤tPos)
Contains the FieldMapping base class and the NullFieldMapping and MatrixFieldMapping subclasses...
virtual std::string dataTypeString() const
static TemplatedFieldType< ResizableField< Data_T > > ms_classType
static const char * staticClassName()
void copyMetadata(const FieldBase &field)
Copies the metadata from a second field.
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
static TemplatedFieldType< Field< Data_T > > ms_classType
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Box3i m_extents
Defines the extents of the the storage. This may be larger or smaller than the data window...
FieldBase base
Convenience typedef for referring to base class.
Used to return a string for the name of a templated field.
FieldRes base
Convenience typedef for referring to base class.
V3i const dataResolution() const
static TemplatedFieldType< WritableField< Data_T > > ms_classType
const_iterator cbegin() const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
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.
#define DECLARE_FIELD3D_GENERIC_EXCEPTION(name, base_class)
Used to declare a generic but named exception.
std::string attribute
Optional name of the attribute the field represents.
static const char * staticClassType()
virtual void mappingChanged()
Tells the subclass that the mapping changed.
int contToDisc(double contCoord)
Goes from continuous coordinates to discrete coordinates See Graphics Gems - What is a pixel...
WritableField< Data_T > & m_field
Reference to field being iterated over.
const_iterator(const const_iterator &i)
V3i indexToCoord(const size_t idx, const V3i &res)
boost::intrusive_ptr< WritableField > Ptr
virtual long long int memSize() const
Returns the memory usage (in bytes)
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.
FIELD3D_VEC3_T< T > ceil(const FIELD3D_VEC3_T< T > &v)
Ceil function for Vec3.
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_ABSTRACT_CLASS
virtual void metadataHasChanged(const std::string &)
This function should implemented by concrete classes to get the callback when metadata changes...
WritableField< Data_T > base
const FieldMetadata< FieldBase > & metadata() const
Read only access to the m_metadata class.
iterator(WritableField< Data_T > &field, const Box3i &window, const V3i ¤tPos)
Contains Exception base class.
Represents the mapping of a field by a matrix transform.
Box3i m_window
Window to traverse.
Box3d continuousBounds(const Box3i &bbox)
boost::intrusive_ptr< Field > Ptr
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
std::string name
Optional name of the field.
Field< Data_T > class_type
static const char * staticClassName()
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel...
#define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field)