ITK  6.0.0
Insight Toolkit
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
83 Array(ValueType * datain, SizeValueType sz, bool LetArrayManageMemory = false);
84
85#if defined(ITK_LEGACY_REMOVE)
90 Array(const ValueType * datain, SizeValueType sz);
91
92#else // defined ( ITK_LEGACY_REMOVE )
97 Array(const ValueType * datain, SizeValueType sz, bool LetArrayManageMemory = false);
98#endif
99
101 template <typename TArrayValue>
103 {
104 this->SetSize(r.GetSize());
105 for (SizeValueType i = 0; i < r.GetSize(); ++i)
106 {
107 this->operator[](i) = static_cast<TValue>(r[i]);
108 }
109 }
113 void
114 Fill(TValue const & v)
115 {
116 this->fill(v);
117 }
118
120 Self &
121 operator=(const Self & rhs);
122
123 Self &
125
128 Size() const
129 {
130 return static_cast<SizeValueType>(this->size());
131 }
132 unsigned int
134 {
135 return static_cast<SizeValueType>(this->size());
136 }
140 const TValue &
142 {
143 return this->operator[](i);
144 }
145
147 void
148 SetElement(SizeValueType i, const TValue & value)
149 {
150 this->operator[](i) = value;
151 }
152
154 void
156
158 GetSize() const
159 {
160 return static_cast<SizeValueType>(this->size());
161 }
162
171 void
172 SetDataSameSize(TValue * datain, bool LetArrayManageMemory = false);
173
183 void
184 SetData(TValue * datain, SizeValueType sz, bool LetArrayManageMemory = false);
185
186#ifdef __INTEL_COMPILER
187# pragma warning disable 444 // destructor for base class "itk::Array<>" is not virtual
188#endif
191 ~Array() override;
192
193#if !defined(ITK_LEGACY_REMOVE)
194 void
195 swap(Array & other)
196 {
197 this->Swap(other);
198 }
199#endif
200
201 void
202 Swap(Array & other) noexcept
203 {
204 using std::swap;
205 this->VnlVectorType::swap(other);
206 swap(this->m_LetArrayManageMemory, other.m_LetArrayManageMemory);
207 }
208
209private:
211 bool m_LetArrayManageMemory{ true };
212};
213
214template <typename TValue>
215std::ostream &
216operator<<(std::ostream & os, const Array<TValue> & arr)
217{
218 os << '[';
219 const unsigned int length = arr.size();
220 if (length >= 1)
221 {
222 const unsigned int last = length - 1;
223 for (unsigned int i = 0; i < last; ++i)
224 {
225 os << arr[i] << ", ";
226 }
227 os << arr[last];
228 }
229 os << ']';
230 return os;
231}
232
233// declaration of specialization
234template <>
235ITKCommon_EXPORT std::ostream & operator<<<double>(std::ostream & os, const Array<double> & arr);
236template <>
237ITKCommon_EXPORT std::ostream & operator<<<float>(std::ostream & os, const Array<float> & arr);
238
239
240template <typename T>
241inline void
242swap(Array<T> & a, Array<T> & b) noexcept
243{
244 a.Swap(b);
245}
246
247} // namespace itk
248
249#ifndef ITK_MANUAL_INSTANTIATION
250# include "itkArray.hxx"
251#endif
252
253#endif
Pixel-wise addition of two images.
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:128
void SetElement(SizeValueType i, const TValue &value)
Definition: itkArray.h:148
SizeValueType GetSize() const
Definition: itkArray.h:158
Array(const Array< TArrayValue > &r)
Definition: itkArray.h:102
vnl_vector< TValue > VnlVectorType
Definition: itkArray.h:54
void Swap(Array &other) noexcept
Definition: itkArray.h:202
unsigned int GetNumberOfElements() const
Definition: itkArray.h:133
Self & operator=(const VnlVectorType &rhs)
~Array() override
Array(SizeValueType dimension)
const TValue & GetElement(SizeValueType i) const
Definition: itkArray.h:141
void Fill(TValue const &v)
Definition: itkArray.h:114
TValue ValueType
Definition: itkArray.h:52
Array(const ValueType *datain, SizeValueType sz)
Array(const Array &)
Array(SizeValueType dimension, const ValueType &value)
void SetSize(SizeValueType sz)
typename vnl_vector< TValue >::size_type SizeValueType
Definition: itkArray.h:55
Self & operator=(const Self &rhs)
Array(const VnlVectorType &)
Array(ValueType *datain, SizeValueType sz, bool LetArrayManageMemory=false)
void SetDataSameSize(TValue *datain, bool LetArrayManageMemory=false)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<<double >(std::ostream &os, const Array< double > &arr)
void swap(Array< T > &a, Array< T > &b) noexcept
Definition: itkArray.h:242
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)