ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkArray.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 itkArray_h
19#define itkArray_h
20
21#include "itkMacro.h"
22
23#include "vxl_version.h"
24#include "vnl/vnl_vector.h"
25
26namespace itk
27{
46template <typename TValue>
47class ITK_TEMPLATE_EXPORT Array : public vnl_vector<TValue>
48{
49public:
50
52 using ValueType = TValue;
53 using Self = Array;
54 using VnlVectorType = vnl_vector<TValue>;
55 using SizeValueType = typename vnl_vector<TValue>::size_type;
56
57public:
60 Array() = default;
61
64 Array(const Array &);
65
67 explicit Array(const VnlVectorType &);
68
72 explicit Array(SizeValueType dimension);
73
75 explicit Array(SizeValueType dimension, const ValueType & value);
76
84 Array(TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
85
86#if defined(ITK_LEGACY_REMOVE)
92 Array(const TValue * datain, SizeValueType sz);
93
94#else // defined ( ITK_LEGACY_REMOVE )
100 Array(const TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
101#endif
102
104 template <typename TArrayValue>
106 {
107 this->SetSize(r.GetSize());
108 for (SizeValueType i = 0; i < r.GetSize(); ++i)
109 {
110 this->operator[](i) = static_cast<TValue>(r[i]);
111 }
112 }
113
114
116 void
117 Fill(const TValue & v)
118 {
119 this->fill(v);
120 }
121
123 Self &
124 operator=(const Self & rhs);
125
126 Self &
128
131 Size() const
132 {
133 return static_cast<SizeValueType>(this->size());
134 }
135 unsigned int
137 {
138 return static_cast<SizeValueType>(this->size());
139 }
140
141
143 const TValue &
145 {
146 return this->operator[](i);
147 }
148
150 void
151 SetElement(SizeValueType i, const TValue & value)
152 {
153 this->operator[](i) = value;
154 }
155
157 void
159
161 GetSize() const
162 {
163 return static_cast<SizeValueType>(this->size());
164 }
165
174 void
175 SetDataSameSize(TValue * datain, bool LetArrayManageMemory = false);
176
186 void
187 SetData(TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
188
189#ifdef __INTEL_COMPILER
190# pragma warning disable 444 // destructor for base class "itk::Array<>" is not virtual
191#endif
194 ~Array() override;
195
196#if !defined(ITK_LEGACY_REMOVE)
197 void
198 swap(Array & other)
199 {
200 this->Swap(other);
201 }
202#endif
203
204 void
205 Swap(Array & other) noexcept
206 {
207 using std::swap;
208 this->VnlVectorType::swap(other);
209 swap(this->m_LetArrayManageMemory, other.m_LetArrayManageMemory);
210 }
211
212private:
215};
216
217// Deduction guide to avoid compiler warnings (-wctad-maybe-unsupported) when using class template argument deduction.
218template <typename TValue>
219Array(TValue *, typename vnl_vector<TValue>::size_type, bool) -> Array<TValue>;
220
221template <typename TValue>
222std::ostream &
223operator<<(std::ostream & os, const Array<TValue> & arr)
224{
225 os << '[';
226 const unsigned int length = arr.size();
227 if (length >= 1)
228 {
229 const unsigned int last = length - 1;
230 for (unsigned int i = 0; i < last; ++i)
231 {
232 os << arr[i] << ", ";
233 }
234 os << arr[last];
235 }
236 os << ']';
237 return os;
238}
239
240// declaration of specialization
241template <>
242ITKCommon_EXPORT std::ostream & operator<< <double>(std::ostream & os, const Array<double> & arr);
243template <>
244ITKCommon_EXPORT std::ostream & operator<< <float>(std::ostream & os, const Array<float> & arr);
245
246
247template <typename T>
248inline void
249swap(Array<T> & a, Array<T> & b) noexcept
250{
251 a.Swap(b);
252}
253
254} // namespace itk
255
256#ifndef ITK_MANUAL_INSTANTIATION
257# include "itkArray.hxx"
258#endif
259
260#endif
Array class with size defined at construction time.
Definition itkArray.h:48
Array()=default
void SetData(TValue *datain, SizeValueType sz, bool LetArrayManageMemory=false)
SizeValueType Size() const
Definition itkArray.h:131
void SetElement(SizeValueType i, const TValue &value)
Definition itkArray.h:151
SizeValueType GetSize() const
Definition itkArray.h:161
Array(const TValue *datain, SizeValueType sz)
Array(const Array< TArrayValue > &r)
Definition itkArray.h:105
vnl_vector< TValue > VnlVectorType
Definition itkArray.h:54
void Swap(Array &other) noexcept
Definition itkArray.h:205
unsigned int GetNumberOfElements() const
Definition itkArray.h:136
Self & operator=(const VnlVectorType &rhs)
~Array() override
Array(TValue *datain, SizeValueType sz, bool LetArrayManageMemory=false)
Array(SizeValueType dimension)
Array Self
Definition itkArray.h:53
const TValue & GetElement(SizeValueType i) const
Definition itkArray.h:144
TValue ValueType
Definition itkArray.h:52
Array(const Array &)
Array(SizeValueType dimension, const ValueType &value)
void Fill(const TValue &v)
Definition itkArray.h:117
void SetSize(SizeValueType sz)
typename vnl_vector< TValue >::size_type SizeValueType
Definition itkArray.h:55
Self & operator=(const Self &rhs)
Array(const VnlVectorType &)
void SetDataSameSize(TValue *datain, bool LetArrayManageMemory=false)
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition itkArray.h:249
ITKCommon_EXPORT std::ostream & operator<<< float >(std::ostream &os, const Array< float > &arr)
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
ITKCommon_EXPORT std::ostream & operator<<< double >(std::ostream &os, const Array< double > &arr)
Array(TValue *, typename vnl_vector< TValue >::size_type, bool) -> Array< TValue >