ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkNeighborhoodAllocator.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 itkNeighborhoodAllocator_h
19#define itkNeighborhoodAllocator_h
21#include <algorithm>
22#include <iostream>
23#include <memory>
24#include "itkMacro.h"
25
26namespace itk
27{
43template <typename TPixel>
45{
46public:
49
54 using iterator = TPixel *;
55 using const_iterator = const TPixel *;
56
59
62
64 void
65 Allocate(unsigned int n)
66 {
69 }
70
72 void
74 {
75 m_Data.reset();
77 }
78
83 {
84 std::copy_n(other.m_Data.get(), m_ElementCount, m_Data.get());
85 }
86
87
89 NeighborhoodAllocator(Self && other) noexcept
90 : m_ElementCount{ other.m_ElementCount }
91 , m_Data{ std::move(other.m_Data) }
92 {
93 other.m_ElementCount = 0;
94 }
95
97 Self &
98 operator=(const Self & other)
99 {
100 if (this != &other)
101 {
102 this->set_size(other.m_ElementCount);
103 std::copy_n(other.m_Data.get(), m_ElementCount, m_Data.get());
104 }
105 return *this;
106 }
107
109 Self &
110 operator=(Self && other) noexcept
111 {
112 if (this != &other)
113 {
114 m_ElementCount = other.m_ElementCount;
115 m_Data = std::move(other.m_Data);
116 other.m_ElementCount = 0;
117 }
118 return *this;
119 }
120
125 {
126 return m_Data.get();
127 }
129 begin() const
130 {
131 return m_Data.get();
132 }
135 {
136 return (m_Data.get() + m_ElementCount);
137 }
139 end() const
140 {
141 return (m_Data.get() + m_ElementCount);
142 }
143 unsigned int
144 size() const
145 {
146 return m_ElementCount;
147 }
148
149
152 const TPixel &
153 operator[](unsigned int i) const
154 {
155 return m_Data[i];
156 }
157 TPixel &
158 operator[](unsigned int i)
159 {
160 return m_Data[i];
161 }
162
163
165 void
166 set_size(unsigned int n)
167 {
168 if (n != m_ElementCount)
169 {
170 *this = NeighborhoodAllocator();
172 m_ElementCount = n;
173 }
174 }
175
176 TPixel *
177 data() noexcept
178 {
179 return m_Data.get();
180 }
181
182 const TPixel *
183 data() const noexcept
184 {
185 return m_Data.get();
186 }
187
188private:
189 unsigned int m_ElementCount{ 0 };
190 std::unique_ptr<TPixel[]> m_Data;
191};
192
193template <typename TPixel>
194inline std::ostream &
195operator<<(std::ostream & o, const NeighborhoodAllocator<TPixel> & a)
196{
197 o << "NeighborhoodAllocator { this = " << &a << ", begin = " << static_cast<const void *>(a.begin())
198 << ", size=" << a.size() << " }";
199 return o;
200}
201
202
203// Equality operator.
204template <typename TPixel>
205inline bool
207{
208 const unsigned int size = lhs.size();
209 return (size == rhs.size()) && ((size == 0) || std::equal(lhs.begin(), lhs.end(), rhs.begin()));
210}
211
212// Inequality operator.
213template <typename TPixel>
214inline bool
216{
217 return !(lhs == rhs);
218}
219} // end namespace itk
220#endif
A memory allocator for use as the default allocator type in Neighborhood.
const TPixel * data() const noexcept
Self & operator=(const Self &other)
NeighborhoodAllocator(Self &&other) noexcept
TPixel & operator[](unsigned int i)
const TPixel & operator[](unsigned int i) const
std::unique_ptr< TPixel[]> m_Data
Self & operator=(Self &&other) noexcept
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition itkIndex.h:545
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition itkIndex.h:552
auto make_unique_for_overwrite(const vcl_size_t numberOfElements)