00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkValarrayImageContainer_h
00018 #define __itkValarrayImageContainer_h
00019
00020 #include "itkObject.h"
00021 #include "itkObjectFactory.h"
00022
00023 #include <utility>
00024 #include <valarray>
00025
00026 namespace itk
00027 {
00028
00046 template <
00047 typename TElementIdentifier,
00048 typename TElement
00049 >
00050 class ValarrayImageContainer:
00051 public Object,
00052 private std::valarray<TElement>
00053 {
00054 public:
00056 typedef ValarrayImageContainer Self;
00057 typedef Object Superclass;
00058 typedef SmartPointer<Self> Pointer;
00059 typedef SmartPointer<const Self> ConstPointer;
00060
00062 typedef TElementIdentifier ElementIdentifier;
00063 typedef TElement Element;
00064
00065 private:
00067 typedef std::valarray<Element> ValarrayType;
00068
00069 protected:
00074 ValarrayImageContainer():
00075 ValarrayType() {}
00076 ValarrayImageContainer(unsigned long n):
00077 ValarrayType(n) {}
00078 ValarrayImageContainer(unsigned long n, const Element& x):
00079 ValarrayType(n, x) {}
00080 ValarrayImageContainer(const Self& r):
00081 ValarrayType(r) {}
00082
00083 public:
00085 itkNewMacro(Self);
00086
00088 itkTypeMacro(ValarrayImageContainer, Object);
00089
00091 TElement & operator[](const ElementIdentifier id)
00092 { return this->ValarrayType::operator[](id); };
00093
00095 const TElement & operator[](const ElementIdentifier id) const
00096 { return this->ValarrayType::operator[](id); };
00097
00100 TElement *GetBufferPointer()
00101 { return &(this->ValarrayType::operator[](0)); };
00102
00104 unsigned long Size(void) const
00105 { return static_cast<unsigned long>(this->ValarrayType::size()); };
00106
00111 void Reserve(ElementIdentifier num)
00112 { this->ValarrayType::resize(num); };
00113
00117 void Squeeze(void)
00118 { this->ValarrayType::resize( this->ValarrayType::size() ); };
00119
00121 void Initialize(void)
00122 { this->ValarrayType::resize( 0 ); };
00123
00125 void Fill(const TElement & value)
00126 { this->ValarrayType::operator=( value ); };
00127
00128 public:
00132 virtual void PrintSelf(std::ostream& os, Indent indent) const
00133 {
00134 Object::PrintSelf(os, indent);
00135
00136
00137 os << indent << "Pointer: "
00138 << const_cast<ValarrayImageContainer*>(this)->GetBufferPointer()
00139 << std::endl;
00140
00141 os << indent << "Size: " << this->Size() << std::endl;
00142 };
00143
00144 };
00145
00146 }
00147
00148 #endif