ITK  5.0.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  >
51 class ITK_TEMPLATE_EXPORT ValarrayImageContainer:
52  public Object,
53  private std::valarray< TElement >
54 {
55 public:
58  using Superclass = Object;
61 
63  using ElementIdentifier = TElementIdentifier;
64  using Element = TElement;
65 
66 private:
68  using ValarrayType = std::valarray< Element >;
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 nullptr;
111  }
112  }
114 
116  unsigned long Size() const
117  { return static_cast< unsigned long >( this->ValarrayType::size() ); }
118 
124  { this->ValarrayType::resize(num); }
125 
129  void Squeeze()
130  { this->ValarrayType::resize( this->ValarrayType::size() ); }
131 
133  void Initialize()
134  { this->ValarrayType::resize(0); }
135 
137  void Fill(const TElement & value)
138  { this->ValarrayType::operator=(value); }
139 
140 public:
144  void PrintSelf(std::ostream & os, Indent indent) const override
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
Light weight base class for most itk classes.
TElement & operator[](const ElementIdentifier id)
void Reserve(ElementIdentifier num)
void PrintSelf(std::ostream &os, Indent indent) const override
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
Defines a front-end to the std\::&lt;valarray&gt; container that conforms to the ImageContainerInterface.
void Fill(const TElement &value)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void PrintSelf(std::ostream &os, Indent indent) const override
std::valarray< Element > ValarrayType
ValarrayImageContainer(unsigned long n, const Element &x)
Base class for most ITK classes.
Definition: itkObject.h:60
const TElement & operator[](const ElementIdentifier id) const