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;
142 virtual Ptr clone()
const = 0;
153 {
return m_metadata; }
157 {
return m_metadata; }
215 typedef boost::intrusive_ptr<FieldRes>
Ptr;
216 typedef std::vector<Ptr>
Vec;
224 {
return std::string(
"FieldRes"); }
233 return staticClassName();
252 {
return m_extents; }
256 {
return m_dataWindow; }
259 {
return m_dataWindow.max - m_dataWindow.min +
V3i(1); }
266 {
return m_mapping; }
270 {
return m_mapping; }
273 bool isInBounds(
int i,
int j,
int k)
const;
282 {
return sizeof(*this); }
343 "Tried to call FieldRes::setMapping with null pointer");
375 template <
class Data_T>
382 typedef boost::intrusive_ptr<Field>
Ptr;
390 typedef std::vector<Ptr>
Vec;
417 class const_iterator;
420 const_iterator
cbegin()
const;
424 const_iterator
cend()
const;
427 const_iterator
cend(
const Box3i &subset)
const;
437 virtual Data_T
value(
int i,
int j,
int k)
const = 0;
460 #define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field) \
461 template <typename Data_T> \
462 TemplatedFieldType<field<Data_T> > field<Data_T>::ms_classType = \
463 TemplatedFieldType<field<Data_T> >(); \
469 template <
class Data_T>
480 template <
class Data_T>
484 if (subset.isEmpty())
491 template <
class Data_T>
496 V3i(m_dataWindow.min.x,
498 m_dataWindow.max.z + 1));
503 template <
class Data_T>
516 template <
class Data_T>
525 : x(i.x), y(i.y), z(i.z),
526 m_window(i.m_window), m_field(i.m_field)
530 const V3i ¤tPos)
531 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
532 m_window(window), m_field(field)
539 if (x == m_window.max.x) {
540 if (y == m_window.max.y) {
553 template <
class Iter_T>
554 bool operator == (
const Iter_T &rhs)
const
556 return x == rhs.x && y == rhs.y && z == rhs.z;
558 template <
class Iter_T>
559 bool operator != (
const Iter_T &rhs)
const
561 return x != rhs.x || y != rhs.y || z != rhs.z;
565 return m_field.value(x, y, z);
595 template <
class Data_T>
597 :
public Field<Data_T>
603 typedef boost::intrusive_ptr<WritableField>
Ptr;
612 return "WritableField";
627 inline iterator
begin();
631 inline iterator
end();
634 inline iterator
end(
const Box3i &subset);
646 virtual Data_T&
lvalue(
int i,
int j,
int k) = 0;
653 { std::fill(
begin(),
end(), value); }
673 template <
class Data_T>
685 template <
class Data_T>
689 if (subset.isEmpty())
691 return iterator(*
this, subset, subset.min);
696 template <
class Data_T>
707 template <
class Data_T>
711 V3i(subset.min.x, subset.min.y, subset.max.z + 1));
718 template <
class Data_T>
726 const V3i ¤tPos)
727 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
728 m_window(window), m_field(field)
735 if (x == m_window.max.x) {
736 if (y == m_window.max.y) {
750 template <
class Iter_T>
751 bool operator == (
const Iter_T &rhs)
const
753 return x == rhs.x && y == rhs.y && z == rhs.z;
756 template <
class Iter_T>
757 bool operator != (
const Iter_T &rhs)
const
759 return x != rhs.x || y != rhs.y || z != rhs.z;
764 return m_field.lvalue(x, y, z);
797 template <
class Data_T>
805 typedef boost::intrusive_ptr<ResizableField>
Ptr;
814 return "ResizableField";
845 template <
class Data_T2>
877 template <
class Data_T>
890 template <
class Data_T>
901 template <
class Data_T>
903 const Box3i &dataWindow)
914 template <
class Data_T>
919 size +
V3i(padding - 1)));
924 template <
class Data_T>
933 typename base::iterator i = base::begin();
934 typename base::iterator end = base::end();
936 for (; i != end; ++i, ++c)
942 template <
class Data_T>
943 template <
class Data_T2>
951 typename base::iterator i = base::begin();
952 typename base::iterator end = base::end();
954 for (; i != end; ++i, ++c)
960 template <
class Data_T>
963 setSize(fieldToMatch->extents(), fieldToMatch->dataWindow());
973 template <
class Data_T,
class Data_T2>
993 template <
class Data_T>
996 if (!sameDefinition<Data_T, Data_T>(a, b)) {
1005 for (; is1 != ie1; ++is1, ++is2) {
1020 return static_cast<int>(std::floor(contCoord));
1029 return static_cast<double>(discCoord) + 0.5;
1069 template <
class Iter_T>
1072 if (num <= 0)
return;
1073 for (
int i=0; i<num; ++i, ++iter);
1079 template <
class Iter_T>
1080 void advance(Iter_T &iter,
int num,
const Iter_T &end)
1084 for (
int i=0; i<num && iter != end; ++i, ++iter);
1093 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
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
FieldMetadata< FieldBase > & metadata()
accessor to the m_metadata class
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
static const char * classType()
Namespace for Exception objects.
FieldRes()
This constructor ensures that we have a valid mapping at all times.
MatrixFieldMapping default_mapping
static const char * staticClassName()
static const char * classType()
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
const_iterator cend() const
Const iterator pointing one element past the last valid one.
static std::string name()
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.
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.
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.
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
static const char * classType()
Box3i m_extents
Defines the extents of the the storage. This may be larger or smaller than the data window...
static const char * classType()
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.
virtual Data_T & lvalue(int i, int j, int k)=0
Write access to a voxel. The coordinates are global coordinates.
bool sameDefinition(typename Field< Data_T >::Ptr a, typename Field< Data_T2 >::Ptr b)
Checks whether the mapping and resolution in two different fields are identical.
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.
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)
boost::intrusive_ptr< WritableField > Ptr
virtual long long int memSize() const
Returns the memory usage (in bytes)
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
static const char * classType()
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.
virtual Data_T value(int i, int j, int k) const =0
Read access to a voxel. The coordinates are in integer voxel space .
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.
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)