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:
51 using ValueType = TValue;
52 using Self = Array;
53 using VnlVectorType = vnl_vector<TValue>;
54 using SizeValueType = typename vnl_vector<TValue>::size_type;
55
56public:
59 Array() = default;
60
63 Array(const Array &);
64
66 explicit Array(const VnlVectorType &);
67
71 explicit Array(SizeValueType dimension);
72
74 explicit Array(SizeValueType dimension, const ValueType & value);
75
83 Array(TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
84
85#if defined(ITK_LEGACY_REMOVE)
91 Array(const TValue * datain, SizeValueType sz);
92
93#else // defined ( ITK_LEGACY_REMOVE )
99 Array(const TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
100#endif
101
103 template <typename TArrayValue>
105 {
106 this->SetSize(r.GetSize());
107 for (SizeValueType i = 0; i < r.GetSize(); ++i)
108 {
109 this->operator[](i) = static_cast<TValue>(r[i]);
110 }
111 }
112
114 void
115 Fill(const TValue & v)
116 {
117 this->fill(v);
118 }
119
121 Self &
122 operator=(const Self & rhs);
123
124 Self &
126
130 Size() const
131 {
132 return static_cast<SizeValueType>(this->size());
133 }
134 unsigned int
136 {
137 return static_cast<SizeValueType>(this->size());
138 }
139
141 const TValue &
143 {
144 return this->operator[](i);
145 }
146
148 void
149 SetElement(SizeValueType i, const TValue & value)
150 {
151 this->operator[](i) = value;
152 }
153
155 void
157
159 GetSize() const
160 {
161 return static_cast<SizeValueType>(this->size());
162 }
163
172 void
173 SetDataSameSize(TValue * datain, bool LetArrayManageMemory = false);
174
184 void
185 SetData(TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
186
187#ifdef __INTEL_COMPILER
188# pragma warning disable 444 // destructor for base class "itk::Array<>" is not virtual
189#endif
192 ~Array() override;
193
194#if !defined(ITK_LEGACY_REMOVE)
195 void
196 swap(Array & other)
197 {
198 this->Swap(other);
199 }
200#endif
201
202 void
203 Swap(Array & other) noexcept
204 {
205 using std::swap;
206 this->VnlVectorType::swap(other);
207 swap(this->m_LetArrayManageMemory, other.m_LetArrayManageMemory);
208 }
209
210private:
213};
214
215// Deduction guide to avoid compiler warnings (-wctad-maybe-unsupported) when using class template argument deduction.
216template <typename TValue>
217Array(TValue *, typename vnl_vector<TValue>::size_type, bool) -> Array<TValue>;
218
219template <typename TValue>
220std::ostream &
221operator<<(std::ostream & os, const Array<TValue> & arr)
222{
223 os << '[';
224 const unsigned int length = arr.size();
225 if (length >= 1)
226 {
227 const unsigned int last = length - 1;
228 for (unsigned int i = 0; i < last; ++i)
229 {
230 os << arr[i] << ", ";
231 }
232 os << arr[last];
233 }
234 os << ']';
235 return os;
236}
237
238// declaration of specialization
239template <>
240ITKCommon_EXPORT std::ostream & operator<< <double>(std::ostream & os, const Array<double> & arr);
241template <>
242ITKCommon_EXPORT std::ostream & operator<< <float>(std::ostream & os, const Array<float> & arr);
243
244
245template <typename T>
246inline void
247swap(Array<T> & a, Array<T> & b) noexcept
248{
249 a.Swap(b);
250}
251
252} // namespace itk
253
254#ifndef ITK_MANUAL_INSTANTIATION
255# include "itkArray.hxx"
256#endif
257
258#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:130
void SetElement(SizeValueType i, const TValue &value)
Definition itkArray.h:149
SizeValueType GetSize() const
Definition itkArray.h:159
Array(const TValue *datain, SizeValueType sz)
Array(const Array< TArrayValue > &r)
Definition itkArray.h:104
vnl_vector< TValue > VnlVectorType
Definition itkArray.h:53
void Swap(Array &other) noexcept
Definition itkArray.h:203
unsigned int GetNumberOfElements() const
Definition itkArray.h:135
Self & operator=(const VnlVectorType &rhs)
~Array() override
Array(TValue *datain, SizeValueType sz, bool LetArrayManageMemory=false)
Array(SizeValueType dimension)
Array Self
Definition itkArray.h:52
const TValue & GetElement(SizeValueType i) const
Definition itkArray.h:142
TValue ValueType
Definition itkArray.h:51
Array(const Array &)
Array(SizeValueType dimension, const ValueType &value)
void Fill(const TValue &v)
Definition itkArray.h:115
void SetSize(SizeValueType sz)
typename vnl_vector< TValue >::size_type SizeValueType
Definition itkArray.h:54
Self & operator=(const Self &rhs)
Array(const VnlVectorType &)
void SetDataSameSize(TValue *datain, bool LetArrayManageMemory=false)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition itkArray.h:247
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 >