ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkValarrayImageContainer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkValarrayImageContainer_h
19 #define __itkValarrayImageContainer_h
20 
21 #include "itkObject.h"
22 #include "itkObjectFactory.h"
23 
24 #include <utility>
25 #include <valarray>
26 
27 namespace itk
28 {
47 template<
48  typename TElementIdentifier,
49  typename TElement
50  >
52  public Object,
53  private std::valarray< TElement >
54 {
55 public:
58  typedef Object Superclass;
61 
63  typedef TElementIdentifier ElementIdentifier;
64  typedef TElement Element;
65 
66 private:
68  typedef std::valarray< Element > ValarrayType;
69 
70 protected:
76  ValarrayType() {}
77  ValarrayImageContainer(unsigned long n):
78  ValarrayType(n) {}
79  ValarrayImageContainer(unsigned long n, const Element & x):
80  ValarrayType(n, x) {}
82  ValarrayType(r) {}
84 
85 public:
87  itkNewMacro(Self);
88 
90  itkTypeMacro(ValarrayImageContainer, Object);
91 
93  TElement & operator[](const ElementIdentifier id)
94  { return this->ValarrayType::operator[](id); }
95 
97  const TElement & operator[](const ElementIdentifier id) const
98  { return this->ValarrayType::operator[](id); }
99 
102  TElement * GetBufferPointer()
103  {
104  if ( this->Size() > 0 )
105  {
106  return & ( this->ValarrayType::operator[](0) );
107  }
108  else
109  {
110  return NULL;
111  }
112  }
114 
116  unsigned long Size(void) const
117  { return static_cast< unsigned long >( this->ValarrayType::size() ); }
118 
124  { this->ValarrayType::resize(num); }
125 
129  void Squeeze(void)
130  { this->ValarrayType::resize( this->ValarrayType::size() ); }
131 
133  void Initialize(void)
134  { this->ValarrayType::resize(0); }
135 
137  void Fill(const TElement & value)
138  { this->ValarrayType::operator=(value); }
139 
140 public:
144  virtual void PrintSelf(std::ostream & os, Indent indent) const
145  {
146  Object::PrintSelf(os, indent);
147  // Print out the pointer to bulk data memory. We use const_cast<> to
148  // cast away the constness so we can call GetBufferPointer()
149  os << indent << "Pointer: "
150  << const_cast< ValarrayImageContainer * >( this )->GetBufferPointer()
151  << std::endl;
153 
154  os << indent << "Size: " << this->Size() << std::endl;
155  }
156 };
157 } // end namespace itk
158 
159 #endif
160