Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkValarrayImageContainer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkValarrayImageContainer.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-03-03 15:11:20 $
00007   Version:   $Revision: 1.15 $
00008 
00009   Copyright (c) Insight Software 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) {}
00083 
00084 public:
00086   itkNewMacro(Self);
00087 
00089   itkTypeMacro(ValarrayImageContainer, Object);
00090 
00092   TElement & operator[](const ElementIdentifier id)
00093     { return this->ValarrayType::operator[](id); };
00094 
00096   const TElement & operator[](const ElementIdentifier id) const
00097     { return this->ValarrayType::operator[](id); };
00098 
00101   TElement *GetBufferPointer() 
00102     {
00103     if (this->Size() > 0)
00104       {
00105       return &(this->ValarrayType::operator[](0));
00106       }
00107     else
00108       {
00109       return NULL;
00110       }
00111     };
00113 
00115   unsigned long Size(void) const
00116     { return static_cast<unsigned long>(this->ValarrayType::size()); }
00117 
00122   void Reserve(ElementIdentifier num)
00123     { this->ValarrayType::resize(num); }
00124 
00128   void Squeeze(void)
00129     { this->ValarrayType::resize( this->ValarrayType::size() ); }
00130 
00132   void Initialize(void)
00133     { this->ValarrayType::resize( 0 ); }
00134 
00136   void Fill(const TElement & value)
00137     { this->ValarrayType::operator=( value ); }
00138 
00139 public:
00143   virtual void PrintSelf(std::ostream& os, Indent indent) const
00144     {
00145     Object::PrintSelf(os, indent);
00146     // Print out the pointer to bulk data memory. We use const_cast<> to
00147     // cast away the constness so we can call GetBufferPointer()
00148     os << indent << "Pointer: "
00149        << const_cast<ValarrayImageContainer*>(this)->GetBufferPointer()
00150        << std::endl;
00152 
00153     os << indent << "Size: " << this->Size() << std::endl;
00154     }
00155   
00156 };
00157 
00158 } // end namespace itk
00159   
00160 #endif
00161 

Generated at Mon Jul 12 2010 20:05:55 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000