ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMeasurementVectorTraits.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 itkMeasurementVectorTraits_h
19#define itkMeasurementVectorTraits_h
20
22#include "vnl/vnl_vector_fixed.h"
23#include "itkRGBPixel.h"
24#include "itkMatrix.h"
26#include "itkNumericTraits.h"
28#include "itkSize.h"
29#include <vector>
30
31namespace itk::Statistics
32{
36
38{
39public:
47
53
55
56 template <typename TVectorType>
57 static bool
58 IsResizable(const TVectorType &)
59 {
60 // Test whether the vector type is resizable or not
61 //
62 // If the default constructor creates a vector of
63 // length zero, we assume that it is resizable,
64 // otherwise that is a pretty useless measurement vector.
66
67 return len == 0;
68 }
69
70 template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
74 const char * errMsg = "Length Mismatch")
75 {
76 if (VLength != VLength2)
77 {
78 itkGenericExceptionMacro(<< errMsg);
79 }
80 return 0;
81 }
82
83 template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
87 const char * errMsg = "Length Mismatch")
88 {
89 if (VLength != VLength2)
90 {
91 itkGenericExceptionMacro(<< errMsg);
92 }
93 return 0;
94 }
95
96 template <typename TValue1, typename TValue2>
98 Assert(const Array<TValue1> & a, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
99 {
100 if (b.Size() != a.Size())
101 {
102 itkGenericExceptionMacro(<< errMsg);
103 }
104 return 0;
105 }
106
107 template <typename TValue1, typename TValue2>
109 Assert(const Array<TValue1> * a, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
110 {
111 if (b->Size() != a->Size())
112 {
113 itkGenericExceptionMacro(<< errMsg);
114 }
115 return 0;
116 }
117
118 template <typename TValue1, typename TValue2>
122 const char * errMsg = "Length Mismatch")
123 {
124 if (b.Size() != a.Size())
125 {
126 itkGenericExceptionMacro(<< errMsg);
127 }
128 return 0;
129 }
130
131 template <typename TValue1, typename TValue2>
135 const char * errMsg = "Length Mismatch")
136 {
137 if (b->Size() != a->Size())
138 {
139 itkGenericExceptionMacro(<< errMsg);
140 }
141 return 0;
142 }
143
144 template <typename TValue1, typename TValue2>
146 Assert(const std::vector<TValue1> & a, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
147 {
148 if (b.size() != a.size())
149 {
150 itkGenericExceptionMacro(<< errMsg);
151 }
152 return 0;
153 }
154
155 template <typename TValue1, typename TValue2>
157 Assert(const std::vector<TValue1> * a, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
158 {
159 if (b->size() != a->size())
160 {
161 itkGenericExceptionMacro(<< errMsg);
162 }
163 return 0;
164 }
165
166 template <typename TValue1, unsigned int VLength, typename TValue2>
168 Assert(const FixedArray<TValue1, VLength> &, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
169 {
170 if (b.Size() == 0)
171 {
172 return VLength;
173 }
174 if (b.Size() != 0)
175 {
176 if (b.Size() != VLength)
177 {
178 itkGenericExceptionMacro(<< errMsg);
179 }
180 }
181 return 0;
182 }
183
184 template <typename TValue1, unsigned int VLength, typename TValue2>
186 Assert(const FixedArray<TValue1, VLength> *, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
187 {
188 if (b->Size() == 0)
189 {
190 return VLength;
191 }
192 if (b->Size() != VLength)
193 {
194 itkGenericExceptionMacro(<< errMsg);
195 }
196 return 0;
197 }
198
199 template <typename TValue1, unsigned int VLength, typename TValue2>
203 const char * errMsg = "Length Mismatch")
204 {
205 if (b.Size() == 0)
206 {
207 return VLength;
208 }
209 if (b.Size() != VLength)
210 {
211 itkGenericExceptionMacro(<< errMsg);
212 }
213 return 0;
214 }
215
216 template <typename TValue1, unsigned int VLength, typename TValue2>
220 const char * errMsg = "Length Mismatch")
221 {
222 if (b->Size() == 0)
223 {
224 return VLength;
225 }
226 if (b->Size() != VLength)
227 {
228 itkGenericExceptionMacro(<< errMsg);
229 }
230 return 0;
231 }
232
233 template <typename TValue1, unsigned int VLength, typename TValue2>
235 Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
236 {
237 if (b.empty())
238 {
239 return VLength;
240 }
241 if (b.size() != VLength)
242 {
243 itkGenericExceptionMacro(<< errMsg);
244 }
245 return 0;
246 }
247
248 template <typename TValue1, unsigned int VLength, typename TValue2>
250 Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
251 {
252 if (b->size() == 0)
253 {
254 return VLength;
255 }
256 if (b->size() != VLength)
257 {
258 itkGenericExceptionMacro(<< errMsg);
259 }
260 return 0;
261 }
262
263 template <typename TValue1, unsigned int VLength>
265 Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
266 {
267 if (l == 0)
268 {
269 return VLength;
270 }
271 if (l != VLength)
272 {
273 itkGenericExceptionMacro(<< errMsg);
274 }
275 return 0;
276 }
277
278 template <typename TValue1, unsigned int VLength>
280 Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
281 {
282 if (l == 0)
283 {
284 return VLength;
285 }
286 if (l != VLength)
287 {
288 itkGenericExceptionMacro(<< errMsg);
289 }
290 return 0;
291 }
292
293 template <typename TValue>
295 Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
296 {
297 if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
298 {
299 itkGenericExceptionMacro(<< errMsg);
300 }
301 else if (l == 0)
302 {
303 return a.Size();
304 }
305 return 0;
306 }
307
308 template <typename TValue>
310 Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
311 {
312 if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
313 {
314 itkGenericExceptionMacro(<< errMsg);
315 }
316 else if (l == 0)
317 {
318 return a->Size();
319 }
320 return 0;
321 }
322
323 template <typename TValue>
327 const char * errMsg = "Length Mismatch")
328 {
329 if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
330 {
331 itkGenericExceptionMacro(<< errMsg);
332 }
333 else if (l == 0)
334 {
335 return a.Size();
336 }
337 return 0;
338 }
339
340 template <typename TValue>
344 const char * errMsg = "Length Mismatch")
345 {
346 if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
347 {
348 itkGenericExceptionMacro(<< errMsg);
349 }
350 else if (l == 0)
351 {
352 return a->Size();
353 }
354 return 0;
355 }
356
357 template <typename TValue>
359 Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
360 {
361 if (((l != 0) && (a.size() != l)) || (a.empty()))
362 {
363 itkGenericExceptionMacro(<< errMsg);
364 }
365 else if (l == 0)
366 {
367 return static_cast<MeasurementVectorLength>(a.size());
368 }
369 return 0;
370 }
371
372 template <typename TValue>
374 Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
375 {
376 if (((l != 0) && (a->size() != l)) || (a->size() == 0))
377 {
378 itkGenericExceptionMacro(<< errMsg);
379 }
380 else if (l == 0)
381 {
382 return a->size();
383 }
384 return 0;
385 }
386
387 template <typename TArrayType>
388 static void
389 Assign(TArrayType & m, const TArrayType & v)
390 {
391 m = v;
392 }
393
394 template <typename TValue, unsigned int VLength>
395 static void
396 Assign(FixedArray<TValue, VLength> & m, const TValue & v)
397 {
398 m[0] = v;
399 }
400};
401
405
406template <typename TMeasurementVector>
408{
409public:
410 using ValueType = typename TMeasurementVector::ValueType;
411};
412
413template <typename T>
415{
416public:
417 using ValueType = T;
418};
419
422
423template <typename TPixelType>
425{
426public:
427 /* type of the vector that matches this pixel type */
428 using MeasurementVectorType = TPixelType;
429};
430
432
436template <>
438{
439public:
441};
442
443template <>
444class MeasurementVectorPixelTraits<unsigned char>
445{
446public:
448};
449
450template <>
451class MeasurementVectorPixelTraits<signed char>
452{
453public:
454 using MeasurementVectorType = FixedArray<signed char, 1>;
455};
456
457template <>
458class MeasurementVectorPixelTraits<unsigned short>
459{
460public:
461 using MeasurementVectorType = FixedArray<unsigned short, 1>;
462};
463
464template <>
466{
467public:
468 using MeasurementVectorType = FixedArray<short, 1>;
469};
470
471template <>
472class MeasurementVectorPixelTraits<unsigned int>
473{
474public:
475 using MeasurementVectorType = FixedArray<unsigned int, 1>;
476};
477
478template <>
480{
481public:
482 using MeasurementVectorType = FixedArray<int, 1>;
483};
484
485template <>
486class MeasurementVectorPixelTraits<unsigned long>
487{
488public:
489 using MeasurementVectorType = FixedArray<unsigned long, 1>;
490};
491
492template <>
494{
495public:
496 using MeasurementVectorType = FixedArray<long, 1>;
497};
498
499template <>
500class MeasurementVectorPixelTraits<unsigned long long>
501{
502public:
503 using MeasurementVectorType = FixedArray<unsigned long long, 1>;
504};
505
506template <>
507class MeasurementVectorPixelTraits<long long>
508{
509public:
510 using MeasurementVectorType = FixedArray<long long, 1>;
511};
512
513template <>
515{
516public:
517 using MeasurementVectorType = FixedArray<float, 1>;
518};
519
520template <>
522{
523public:
524 using MeasurementVectorType = FixedArray<double, 1>;
525};
526
528
529} // namespace itk::Statistics
530
531
532#endif // itkMeasurementVectorTraits_h
Array class with size defined at construction time.
Definition itkArray.h:48
SizeValueType Size() const
Definition itkArray.h:130
Simulate a standard C array with copy semantics.
static constexpr unsigned int GetLength()
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const Array< TValue2 > &b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const Array< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const Array< TValue1 > *a, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > &a, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
NumericTraits< RelativeFrequencyType >::AccumulateType TotalRelativeFrequencyType
static MeasurementVectorLength Assert(const std::vector< TValue1 > &a, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const FixedArray< TValue2, VLength2 > *, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const Array< TValue1 > &a, const Array< TValue2 > &b, const char *errMsg="Length Mismatch")
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
static MeasurementVectorLength Assert(const std::vector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > *a, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const std::vector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const FixedArray< TValue2, VLength2 > &, const char *errMsg="Length Mismatch")
static void Assign(FixedArray< TValue, VLength > &m, const TValue &v)
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
static void Assign(TArrayType &m, const TArrayType &v)
static MeasurementVectorLength Assert(const std::vector< TValue1 > *a, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
NumericTraits< AbsoluteFrequencyType >::RealType RelativeFrequencyType
static MeasurementVectorLength Assert(const Array< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
SizeValueType IdentifierType
Definition itkIntTypes.h:90
STL namespace.