KWStyle - itkValarrayImageContainer.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkValarrayImageContainer.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkValarrayImageContainer_h
18 #define __itkValarrayImageContainer_h
19
20 #include "itkObject.h"
21 #include "itkObjectFactory.h"
22
23 #include <utility>
24 #include <valarray>
25
26 namespace itk
27 {
28
29 /** \class ValarrayImageContainer
30  * Defines a front-end to the STL "valarray" container that conforms to the
31  * ImageContainerInterface.  This is a full-fleged Object, so
32  * there is modification time, debug, and reference count information.
33  *
34  * Template parameters for ValarrayImageContainer:
35  *
36  * TElementIdentifier =
37  *    An INTEGRAL type for use in indexing the valarray.
38  *    It must have a < operator defined for ordering.
39  *
40  * TElement =
41  *    The element type stored in the container.
42  *
43  * \ingroup ImageObjects
44  * \ingroup DataRepresentation
45  */
46 template <
47   typename TElementIdentifier,
48   typename TElement
49 IND **>
50 class ValarrayImageContainer: 
51 IND **public Object,
52 IND **private std::valarray<TElement>
53 {
54 public:
55   /** Standard class typedefs. */
56   typedef ValarrayImageContainer     Self;
57 TDA   typedef Object  Superclass;
58 TDA   typedef SmartPointer<Self>  Pointer;
59 TDA   typedef SmartPointer<const Self>  ConstPointer;
60     
61   /** Save the template parameters. */
62   typedef TElementIdentifier  ElementIdentifier;
63   typedef TElement            Element;
64   
65 private:
66   /** Quick access to the STL valarray type that was inherited. */
67   typedef std::valarray<Element>  ValarrayType;
68   
69 protected:
70   /** Provide pass-through constructors corresponding to all the STL
71    * valarray constructors.  These are for internal use only since
72    * this is also an Object which must be constructed through the
73    * "New()" routine. */
74   ValarrayImageContainer():
75 IND ****ValarrayType() {}
76   ValarrayImageContainer(unsigned long n):
77 IND ****ValarrayType(n) {}
78   ValarrayImageContainer(unsigned long n, const Element& x):
79 IND ****ValarrayType(n, x) {}
80   ValarrayImageContainer(const Self& r):
81 IND ****ValarrayType(r) {}
82   
83 public:
84   /** Method for creation through the object factory. */
85   itkNewMacro(Self);
86   
87   /** Standard part of every itk Object. */
88   itkTypeMacro(ValarrayImageContainer, Object);
89
90   /** Index operator. This version can be an lvalue. */
91   TElement & operator[](const ElementIdentifier id)
92     { return this->ValarrayType::operator[](id); };
93
94   /** Index operator. This version can only be an rvalue */
95   const TElement & operator[](const ElementIdentifier id) const
96     { return this->ValarrayType::operator[](id); };
97
98   /** Return a pointer to the beginning of the buffer.  This is used by
99    * the image iterator class. */
100   TElement *GetBufferPointer()
101     { return &(this->ValarrayType::operator[](0)); };
102   
103   /** Get the number of elements currently stored in the container. */
104   unsigned long Size(void) const
105     { return static_cast<unsigned long>(this->ValarrayType::size()); };
106
107   /** Tell the container to allocate enough memory to allow at least
108    * as many elements as the size given to be stored.  This is NOT
109    * guaranteed to actually allocate any memory, but is useful if the
110    * implementation of the container allocates contiguous storage. */
111   void Reserve(ElementIdentifier num)
112     { this->ValarrayType::resize(num); };
113   
114   /** Tell the container to try to minimize its memory usage for storage of
115    * the current number of elements.  This is NOT guaranteed to decrease
116    * memory usage. */
117   void Squeeze(void)
118     { this->ValarrayType::resize( this->ValarrayType::size() ); };
119
120   /** Tell the container to release any of its allocated memory. */
121   void Initialize(void)
122     { this->ValarrayType::resize( 0 ); };
123
124 IND ***/** Tell the container to release any of its allocated memory. */
125   void Fill(const TElement & value)
126     { this->ValarrayType::operator=( value ); };
127   
128 public:
129   /** PrintSelf routine. Normally this is a protected internal method. It is
130    * made public here so that Image can call this method.  Users should not
131    * call this method but should call Print() instead.  */
132   virtual void PrintSelf(std::ostream& os, Indent indent) const
133 IND **{
134     Object::PrintSelf(os, indent);
135     // Print out the pointer to bulk data memory. We use const_cast<> to
136     // cast away the constness so we can call GetBufferPointer()
137     os << indent << "Pointer: "
138        << const_cast<ValarrayImageContainer*>(this)->GetBufferPointer()
139 IND *******<< std::endl;
140     
141     os << indent << "Size: " << this->Size() << std::endl;
142 IND **};
143   
144 };
145
146 // end namespace itk
147   
148 #endif
149

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:51PM
© Kitware Inc.