ITK  4.2.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 private:
66 
68  typedef std::valarray< Element > ValarrayType;
69 protected:
70 
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) {}
83 public:
84 
86  itkNewMacro(Self);
87 
89  itkTypeMacro(ValarrayImageContainer, Object);
90 
92  TElement & operator[](const ElementIdentifier id)
93  { return this->ValarrayType::operator[](id); }
94 
96  const TElement & operator[](const ElementIdentifier id) const
97  { return this->ValarrayType::operator[](id); }
98 
101  TElement * GetBufferPointer()
102  {
103  if ( this->Size() > 0 )
104  {
105  return & ( this->ValarrayType::operator[](0) );
106  }
107  else
108  {
109  return NULL;
110  }
111  }
113 
115  unsigned long Size(void) const
116  { return static_cast< unsigned long >( this->ValarrayType::size() ); }
117 
123  { this->ValarrayType::resize(num); }
124 
128  void Squeeze(void)
129  { this->ValarrayType::resize( this->ValarrayType::size() ); }
130 
132  void Initialize(void)
133  { this->ValarrayType::resize(0); }
134 
136  void Fill(const TElement & value)
137  { this->ValarrayType::operator=(value); }
138 public:
139 
143  virtual void PrintSelf(std::ostream & os, Indent indent) const
144  {
145  Object::PrintSelf(os, indent);
146  // Print out the pointer to bulk data memory. We use const_cast<> to
147  // cast away the constness so we can call GetBufferPointer()
148  os << indent << "Pointer: "
149  << const_cast< ValarrayImageContainer * >( this )->GetBufferPointer()
150  << std::endl;
152 
153  os << indent << "Size: " << this->Size() << std::endl;
154  }
155 };
156 } // end namespace itk
157 
158 #endif
159