ITK  5.4.0
Insight Toolkit
itkValarrayImageContainer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 <typename TElementIdentifier, typename TElement>
48 class ITK_TEMPLATE_EXPORT ValarrayImageContainer
49  : public Object
50  , private std::valarray<TElement>
51 {
52 public:
55  using Superclass = Object;
58 
60  using ElementIdentifier = TElementIdentifier;
61  using Element = TElement;
62 
63 private:
65  using ValarrayType = std::valarray<Element>;
66 
67 protected:
73  : ValarrayType()
74  {}
75  ValarrayImageContainer(unsigned long n)
76  : ValarrayType(n)
77  {}
78  ValarrayImageContainer(unsigned long n, const Element & x)
79  : ValarrayType(n, x)
80  {}
82  : ValarrayType(r)
83  {}
86 public:
88  itkNewMacro(Self);
89 
91  itkOverrideGetNameOfClassMacro(ValarrayImageContainer);
92 
94  TElement & operator[](const ElementIdentifier id) { return this->ValarrayType::operator[](id); }
95 
97  const TElement & operator[](const ElementIdentifier id) const { return this->ValarrayType::operator[](id); }
98 
101  TElement *
103  {
104  if (this->Size() > 0)
105  {
106  return &(this->ValarrayType::operator[](0));
107  }
108  else
109  {
110  return nullptr;
111  }
112  }
116  unsigned long
117  Size() const
118  {
119  return static_cast<unsigned long>(this->ValarrayType::size());
120  }
121 
126  void
128  {
129  this->ValarrayType::resize(num);
130  }
131 
135  void
137  {
138  this->ValarrayType::resize(this->ValarrayType::size());
139  }
140 
142  void
144  {
145  this->ValarrayType::resize(0);
146  }
147 
149  void
150  Fill(const TElement & value)
151  {
152  this->ValarrayType::operator=(value);
153  }
154 
155 public:
159  void
160  PrintSelf(std::ostream & os, Indent indent) const override
161  {
162  Object::PrintSelf(os, indent);
163  // Print out the pointer to bulk data memory. We use const_cast<> to
164  // cast away the constness so we can call GetBufferPointer()
165  os << indent << "Pointer: " << const_cast<ValarrayImageContainer *>(this)->GetBufferPointer() << std::endl;
168  os << indent << "Size: " << this->Size() << std::endl;
169  }
170 };
171 } // end namespace itk
172 
173 #endif
itk::ValarrayImageContainer::ValarrayImageContainer
ValarrayImageContainer()
Definition: itkValarrayImageContainer.h:72
itkObjectFactory.h
itk::ValarrayImageContainer::GetBufferPointer
TElement * GetBufferPointer()
Definition: itkValarrayImageContainer.h:102
itk::ValarrayImageContainer::ValarrayImageContainer
ValarrayImageContainer(unsigned long n, const Element &x)
Definition: itkValarrayImageContainer.h:78
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
itk::ValarrayImageContainer::ValarrayImageContainer
ValarrayImageContainer(unsigned long n)
Definition: itkValarrayImageContainer.h:75
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ValarrayImageContainer
Defines a front-end to the std\::<valarray> container that conforms to the ImageContainerInterface.
Definition: itkValarrayImageContainer.h:48
itk::ValarrayImageContainer::Squeeze
void Squeeze()
Definition: itkValarrayImageContainer.h:136
itk::ValarrayImageContainer::operator[]
TElement & operator[](const ElementIdentifier id)
Definition: itkValarrayImageContainer.h:94
itk::ValarrayImageContainer::Reserve
void Reserve(ElementIdentifier num)
Definition: itkValarrayImageContainer.h:127
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::ValarrayImageContainer::ValarrayImageContainer
ValarrayImageContainer(const Self &r)
Definition: itkValarrayImageContainer.h:81
itk::ValarrayImageContainer::Element
TElement Element
Definition: itkValarrayImageContainer.h:61
itk::ValarrayImageContainer::ElementIdentifier
TElementIdentifier ElementIdentifier
Definition: itkValarrayImageContainer.h:60
itk::ValarrayImageContainer::Size
unsigned long Size() const
Definition: itkValarrayImageContainer.h:117
itk::ValarrayImageContainer::operator[]
const TElement & operator[](const ElementIdentifier id) const
Definition: itkValarrayImageContainer.h:97
itk::ValarrayImageContainer::Fill
void Fill(const TElement &value)
Definition: itkValarrayImageContainer.h:150
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ValarrayImageContainer::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkValarrayImageContainer.h:160
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::ValarrayImageContainer::Initialize
void Initialize()
Definition: itkValarrayImageContainer.h:143
itk::Object::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::ValarrayImageContainer::ValarrayType
std::valarray< Element > ValarrayType
Definition: itkValarrayImageContainer.h:65