00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkValarrayImageContainer.h,v $ 00005 Language: C++ 00006 Date: $Date: 2002/12/05 15:00:19 $ 00007 Version: $Revision: 1.11 $ 00008 00009 Copyright (c) 2002 Insight Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 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 00124 public: 00128 virtual void PrintSelf(std::ostream& os, Indent indent) const 00129 { 00130 Object::PrintSelf(os, indent); 00131 // Print out the pointer to bulk data memory. We use const_cast<> to 00132 // cast away the constness so we can call GetBufferPointer() 00133 os << indent << "Pointer: " 00134 << const_cast<ValarrayImageContainer*>(this)->GetBufferPointer() 00135 << std::endl; 00136 00137 os << indent << "Size: " << this->Size() << std::endl; 00138 }; 00139 00140 }; 00141 00142 } // end namespace itk 00143 00144 #endif