ITK  6.0.0
Insight Toolkit
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"
25 #include "itkVariableSizeMatrix.h"
26 #include "itkNumericTraits.h"
28 #include "itkSize.h"
29 #include <vector>
30 
31 namespace itk
32 {
33 namespace Statistics
34 {
41 {
42 public:
50 
56 
57  using MeasurementVectorLength = size_t;
58 
59  template <typename TVectorType>
60  static bool
61  IsResizable(const TVectorType &)
62  {
63  // Test whether the vector type is resizable or not
64  //
65  // If the default constructor creates a vector of
66  // length zero, we assume that it is resizable,
67  // otherwise that is a pretty useless measurement vector.
69 
70  return (len == 0);
71  }
72 
73  template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
77  const char * errMsg = "Length Mismatch")
78  {
79  if (VLength != VLength2)
80  {
81  itkGenericExceptionMacro(<< errMsg);
82  }
83  return 0;
84  }
85 
86  template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
90  const char * errMsg = "Length Mismatch")
91  {
92  if (VLength != VLength2)
93  {
94  itkGenericExceptionMacro(<< errMsg);
95  }
96  return 0;
97  }
98 
99  template <typename TValue1, typename TValue2>
101  Assert(const Array<TValue1> & a, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
102  {
103  if (b.Size() != a.Size())
104  {
105  itkGenericExceptionMacro(<< errMsg);
106  }
107  return 0;
108  }
109 
110  template <typename TValue1, typename TValue2>
112  Assert(const Array<TValue1> * a, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
113  {
114  if (b->Size() != a->Size())
115  {
116  itkGenericExceptionMacro(<< errMsg);
117  }
118  return 0;
119  }
120 
121  template <typename TValue1, typename TValue2>
125  const char * errMsg = "Length Mismatch")
126  {
127  if (b.Size() != a.Size())
128  {
129  itkGenericExceptionMacro(<< errMsg);
130  }
131  return 0;
132  }
133 
134  template <typename TValue1, typename TValue2>
138  const char * errMsg = "Length Mismatch")
139  {
140  if (b->Size() != a->Size())
141  {
142  itkGenericExceptionMacro(<< errMsg);
143  }
144  return 0;
145  }
146 
147  template <typename TValue1, typename TValue2>
149  Assert(const std::vector<TValue1> & a, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
150  {
151  if (b.size() != a.size())
152  {
153  itkGenericExceptionMacro(<< errMsg);
154  }
155  return 0;
156  }
157 
158  template <typename TValue1, typename TValue2>
160  Assert(const std::vector<TValue1> * a, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
161  {
162  if (b->size() != a->size())
163  {
164  itkGenericExceptionMacro(<< errMsg);
165  }
166  return 0;
167  }
168 
169  template <typename TValue1, unsigned int VLength, typename TValue2>
171  Assert(const FixedArray<TValue1, VLength> &, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
172  {
173  if (b.Size() == 0)
174  {
175  return VLength;
176  }
177  if (b.Size() != 0)
178  {
179  if (b.Size() != VLength)
180  {
181  itkGenericExceptionMacro(<< errMsg);
182  }
183  }
184  return 0;
185  }
186 
187  template <typename TValue1, unsigned int VLength, typename TValue2>
189  Assert(const FixedArray<TValue1, VLength> *, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
190  {
191  if (b->Size() == 0)
192  {
193  return VLength;
194  }
195  if (b->Size() != VLength)
196  {
197  itkGenericExceptionMacro(<< errMsg);
198  }
199  return 0;
200  }
201 
202  template <typename TValue1, unsigned int VLength, typename TValue2>
206  const char * errMsg = "Length Mismatch")
207  {
208  if (b.Size() == 0)
209  {
210  return VLength;
211  }
212  if (b.Size() != VLength)
213  {
214  itkGenericExceptionMacro(<< errMsg);
215  }
216  return 0;
217  }
218 
219  template <typename TValue1, unsigned int VLength, typename TValue2>
223  const char * errMsg = "Length Mismatch")
224  {
225  if (b->Size() == 0)
226  {
227  return VLength;
228  }
229  if (b->Size() != VLength)
230  {
231  itkGenericExceptionMacro(<< errMsg);
232  }
233  return 0;
234  }
235 
236  template <typename TValue1, unsigned int VLength, typename TValue2>
238  Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
239  {
240  if (b.empty())
241  {
242  return VLength;
243  }
244  if (b.size() != VLength)
245  {
246  itkGenericExceptionMacro(<< errMsg);
247  }
248  return 0;
249  }
250 
251  template <typename TValue1, unsigned int VLength, typename TValue2>
253  Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
254  {
255  if (b->size() == 0)
256  {
257  return VLength;
258  }
259  if (b->size() != VLength)
260  {
261  itkGenericExceptionMacro(<< errMsg);
262  }
263  return 0;
264  }
265 
266  template <typename TValue1, unsigned int VLength>
268  Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
269  {
270  if (l == 0)
271  {
272  return VLength;
273  }
274  if (l != VLength)
275  {
276  itkGenericExceptionMacro(<< errMsg);
277  }
278  return 0;
279  }
280 
281  template <typename TValue1, unsigned int VLength>
283  Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
284  {
285  if (l == 0)
286  {
287  return VLength;
288  }
289  if (l != VLength)
290  {
291  itkGenericExceptionMacro(<< errMsg);
292  }
293  return 0;
294  }
295 
296  template <typename TValue>
298  Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
299  {
300  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
301  {
302  itkGenericExceptionMacro(<< errMsg);
303  }
304  else if (l == 0)
305  {
306  return a.Size();
307  }
308  return 0;
309  }
310 
311  template <typename TValue>
313  Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
314  {
315  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
316  {
317  itkGenericExceptionMacro(<< errMsg);
318  }
319  else if (l == 0)
320  {
321  return a->Size();
322  }
323  return 0;
324  }
325 
326  template <typename TValue>
329  const MeasurementVectorLength l,
330  const char * errMsg = "Length Mismatch")
331  {
332  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
333  {
334  itkGenericExceptionMacro(<< errMsg);
335  }
336  else if (l == 0)
337  {
338  return a.Size();
339  }
340  return 0;
341  }
342 
343  template <typename TValue>
346  const MeasurementVectorLength l,
347  const char * errMsg = "Length Mismatch")
348  {
349  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
350  {
351  itkGenericExceptionMacro(<< errMsg);
352  }
353  else if (l == 0)
354  {
355  return a->Size();
356  }
357  return 0;
358  }
359 
360  template <typename TValue>
362  Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
363  {
364  if (((l != 0) && (a.size() != l)) || (a.empty()))
365  {
366  itkGenericExceptionMacro(<< errMsg);
367  }
368  else if (l == 0)
369  {
370  return static_cast<MeasurementVectorLength>(a.size());
371  }
372  return 0;
373  }
374 
375  template <typename TValue>
377  Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
378  {
379  if (((l != 0) && (a->size() != l)) || (a->size() == 0))
380  {
381  itkGenericExceptionMacro(<< errMsg);
382  }
383  else if (l == 0)
384  {
385  return a->size();
386  }
387  return 0;
388  }
389 
390  template <typename TArrayType>
391  static void
392  Assign(TArrayType & m, const TArrayType & v)
393  {
394  m = v;
395  }
396 
397  template <typename TValue, unsigned int VLength>
398  static void
399  Assign(FixedArray<TValue, VLength> & m, const TValue & v)
400  {
401  m[0] = v;
402  }
403 };
404 
410 template <typename TMeasurementVector>
412 {
413 public:
414  using ValueType = typename TMeasurementVector::ValueType;
415 };
416 
417 template <typename T>
418 class MeasurementVectorTraitsTypes<std::vector<T>>
419 {
420 public:
421  using ValueType = T;
422 };
423 
427 template <typename TPixelType>
429 {
430 public:
431  /* type of the vector that matches this pixel type */
432  using MeasurementVectorType = TPixelType;
433 };
434 
436 
440 template <>
442 {
443 public:
445 };
446 
447 template <>
448 class MeasurementVectorPixelTraits<unsigned char>
449 {
450 public:
452 };
453 
454 template <>
455 class MeasurementVectorPixelTraits<signed char>
456 {
457 public:
458  using MeasurementVectorType = FixedArray<signed char, 1>;
459 };
460 
461 template <>
462 class MeasurementVectorPixelTraits<unsigned short>
463 {
464 public:
465  using MeasurementVectorType = FixedArray<unsigned short, 1>;
466 };
467 
468 template <>
469 class MeasurementVectorPixelTraits<short>
470 {
471 public:
472  using MeasurementVectorType = FixedArray<short, 1>;
473 };
474 
475 template <>
476 class MeasurementVectorPixelTraits<unsigned int>
477 {
478 public:
479  using MeasurementVectorType = FixedArray<unsigned int, 1>;
480 };
481 
482 template <>
483 class MeasurementVectorPixelTraits<int>
484 {
485 public:
486  using MeasurementVectorType = FixedArray<int, 1>;
487 };
488 
489 template <>
490 class MeasurementVectorPixelTraits<unsigned long>
491 {
492 public:
493  using MeasurementVectorType = FixedArray<unsigned long, 1>;
494 };
495 
496 template <>
497 class MeasurementVectorPixelTraits<long>
498 {
499 public:
500  using MeasurementVectorType = FixedArray<long, 1>;
501 };
502 
503 template <>
504 class MeasurementVectorPixelTraits<unsigned long long>
505 {
506 public:
507  using MeasurementVectorType = FixedArray<unsigned long long, 1>;
508 };
509 
510 template <>
511 class MeasurementVectorPixelTraits<long long>
512 {
513 public:
514  using MeasurementVectorType = FixedArray<long long, 1>;
515 };
516 
517 template <>
518 class MeasurementVectorPixelTraits<float>
519 {
520 public:
521  using MeasurementVectorType = FixedArray<float, 1>;
522 };
523 
524 template <>
525 class MeasurementVectorPixelTraits<double>
526 {
527 public:
528  using MeasurementVectorType = FixedArray<double, 1>;
529 };
530 
532 
533 } // namespace Statistics
534 } // namespace itk
535 
536 #endif // itkMeasurementVectorTraits_h
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const Array< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:171
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:221
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:268
itk::Statistics::MeasurementVectorTraits::InstanceIdentifier
IdentifierType InstanceIdentifier
Definition: itkMeasurementVectorTraits.h:49
itk::Statistics::MeasurementVectorTraits::TotalRelativeFrequencyType
NumericTraits< RelativeFrequencyType >::AccumulateType TotalRelativeFrequencyType
Definition: itkMeasurementVectorTraits.h:55
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const FixedArray< TValue2, VLength2 > &, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:75
itkRGBPixel.h
itkVariableSizeMatrix.h
itkMatrix.h
itk::Statistics::MeasurementVectorTraitsTypes
Definition: itkMeasurementVectorTraits.h:411
itk::Statistics::MeasurementVectorTraits::MeasurementVectorLength
vcl_size_t MeasurementVectorLength
Definition: itkMeasurementVectorTraits.h:57
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:189
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:362
itkVariableLengthVector.h
itk::Statistics::MeasurementVectorTraitsTypes< std::vector< T > >::ValueType
T ValueType
Definition: itkMeasurementVectorTraits.h:421
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue1 > *a, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:112
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:76
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue1 > &a, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:149
itk::Statistics::MeasurementVectorTraits::Assign
static void Assign(TArrayType &m, const TArrayType &v)
Definition: itkMeasurementVectorTraits.h:392
itk::Statistics::MeasurementVectorPixelTraits::MeasurementVectorType
TPixelType MeasurementVectorType
Definition: itkMeasurementVectorTraits.h:432
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:253
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:204
itk::Statistics::MeasurementVectorTraits::AbsoluteFrequencyType
InstanceIdentifier AbsoluteFrequencyType
Definition: itkMeasurementVectorTraits.h:52
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const FixedArray< TValue2, VLength2 > *, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:88
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:328
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:238
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:587
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > *a, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:136
itk::Statistics::MeasurementVectorTraits::Assign
static void Assign(FixedArray< TValue, VLength > &m, const TValue &v)
Definition: itkMeasurementVectorTraits.h:399
itk::Statistics::MeasurementVectorTraits
Definition: itkMeasurementVectorTraits.h:40
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:313
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:283
itk::Statistics::MeasurementVectorTraits::RelativeFrequencyType
NumericTraits< AbsoluteFrequencyType >::RealType RelativeFrequencyType
Definition: itkMeasurementVectorTraits.h:53
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > &a, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:123
itk::Statistics::MeasurementVectorTraits::IsResizable
static bool IsResizable(const TVectorType &)
Definition: itkMeasurementVectorTraits.h:61
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue1 > *a, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:160
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:210
itk::Statistics::MeasurementVectorTraits::TotalAbsoluteFrequencyType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkMeasurementVectorTraits.h:54
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:377
itk::Statistics::MeasurementVectorPixelTraits
Definition: itkMeasurementVectorTraits.h:428
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::Statistics::MeasurementVectorTraitsTypes::ValueType
typename TMeasurementVector::ValueType ValueType
Definition: itkMeasurementVectorTraits.h:414
itkNumericTraitsStdVector.h
itkNumericTraits.h
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue1 > &a, const Array< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:101
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:128
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:86
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:345
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:298
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itkSize.h