ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
27namespace itk
28{
47template <typename TElementIdentifier, typename TElement>
48class ITK_TEMPLATE_EXPORT ValarrayImageContainer
49 : public Object
50 , private std::valarray<TElement>
51{
52public:
58
60 using ElementIdentifier = TElementIdentifier;
61 using Element = TElement;
62
63private:
65 using ValarrayType = std::valarray<Element>;
66
67protected:
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 {}
84
85
86public:
88 itkNewMacro(Self);
89
91 itkOverrideGetNameOfClassMacro(ValarrayImageContainer);
92
94 TElement &
96 {
97 return this->ValarrayType::operator[](id);
98 }
99
101 const TElement &
103 {
104 return this->ValarrayType::operator[](id);
105 }
106
109 TElement *
111 {
112 if (this->Size() > 0)
113 {
114 return &(this->ValarrayType::operator[](0));
115 }
116
117 return nullptr;
118 }
119
121 unsigned long
122 Size() const
123 {
124 return static_cast<unsigned long>(this->ValarrayType::size());
125 }
126
131 void
133 {
134 this->ValarrayType::resize(num);
135 }
136
140 void
142 {
143 this->ValarrayType::resize(this->ValarrayType::size());
144 }
145
147 void
149 {
150 this->ValarrayType::resize(0);
151 }
152
154 void
155 Fill(const TElement & value)
156 {
157 this->ValarrayType::operator=(value);
158 }
159
160public:
164 void
165 PrintSelf(std::ostream & os, Indent indent) const override
166 {
167 Object::PrintSelf(os, indent);
168 // Print out the pointer to bulk data memory. We use const_cast<> to
169 // cast away the constness so we can call GetBufferPointer()
170 os << indent << "Pointer: " << const_cast<ValarrayImageContainer *>(this)->GetBufferPointer() << std::endl;
172
173 os << indent << "Size: " << this->Size() << std::endl;
174 }
175};
176} // end namespace itk
177
178#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
void PrintSelf(std::ostream &os, Indent indent) const override
Implements transparent reference counting.
TElement & operator[](const ElementIdentifier id)
void Fill(const TElement &value)
std::valarray< Element > ValarrayType
SmartPointer< const Self > ConstPointer
ValarrayImageContainer(unsigned long n, const Element &x)
void Reserve(ElementIdentifier num)
const TElement & operator[](const ElementIdentifier id) const
void PrintSelf(std::ostream &os, Indent indent) const override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....