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  else 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() != 0)
213  {
214  if (b.Size() != VLength)
215  {
216  itkGenericExceptionMacro(<< errMsg);
217  }
218  }
219  return 0;
220  }
221 
222  template <typename TValue1, unsigned int VLength, typename TValue2>
226  const char * errMsg = "Length Mismatch")
227  {
228  if (b->Size() == 0)
229  {
230  return VLength;
231  }
232  else if (b->Size() != VLength)
233  {
234  itkGenericExceptionMacro(<< errMsg);
235  }
236  return 0;
237  }
238 
239  template <typename TValue1, unsigned int VLength, typename TValue2>
241  Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
242  {
243  if (b.empty())
244  {
245  return VLength;
246  }
247  if (!b.empty())
248  {
249  if (b.size() != VLength)
250  {
251  itkGenericExceptionMacro(<< errMsg);
252  }
253  }
254  return 0;
255  }
256 
257  template <typename TValue1, unsigned int VLength, typename TValue2>
259  Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
260  {
261  if (b->size() == 0)
262  {
263  return VLength;
264  }
265  else if (b->size() != VLength)
266  {
267  itkGenericExceptionMacro(<< errMsg);
268  }
269  return 0;
270  }
271 
272  template <typename TValue1, unsigned int VLength>
274  Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
275  {
276  if (l == 0)
277  {
278  return VLength;
279  }
280  else if (l != VLength)
281  {
282  itkGenericExceptionMacro(<< errMsg);
283  }
284  return 0;
285  }
286 
287  template <typename TValue1, unsigned int VLength>
289  Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
290  {
291  if (l == 0)
292  {
293  return VLength;
294  }
295  else if (l != VLength)
296  {
297  itkGenericExceptionMacro(<< errMsg);
298  }
299  return 0;
300  }
301 
302  template <typename TValue>
304  Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
305  {
306  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
307  {
308  itkGenericExceptionMacro(<< errMsg);
309  }
310  else if (l == 0)
311  {
312  return a.Size();
313  }
314  return 0;
315  }
316 
317  template <typename TValue>
319  Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
320  {
321  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
322  {
323  itkGenericExceptionMacro(<< errMsg);
324  }
325  else if (l == 0)
326  {
327  return a->Size();
328  }
329  return 0;
330  }
331 
332  template <typename TValue>
335  const MeasurementVectorLength l,
336  const char * errMsg = "Length Mismatch")
337  {
338  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
339  {
340  itkGenericExceptionMacro(<< errMsg);
341  }
342  else if (l == 0)
343  {
344  return a.Size();
345  }
346  return 0;
347  }
348 
349  template <typename TValue>
352  const MeasurementVectorLength l,
353  const char * errMsg = "Length Mismatch")
354  {
355  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
356  {
357  itkGenericExceptionMacro(<< errMsg);
358  }
359  else if (l == 0)
360  {
361  return a->Size();
362  }
363  return 0;
364  }
365 
366  template <typename TValue>
368  Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
369  {
370  if (((l != 0) && (a.size() != l)) || (a.empty()))
371  {
372  itkGenericExceptionMacro(<< errMsg);
373  }
374  else if (l == 0)
375  {
376  return static_cast<MeasurementVectorLength>(a.size());
377  }
378  return 0;
379  }
380 
381  template <typename TValue>
383  Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
384  {
385  if (((l != 0) && (a->size() != l)) || (a->size() == 0))
386  {
387  itkGenericExceptionMacro(<< errMsg);
388  }
389  else if (l == 0)
390  {
391  return a->size();
392  }
393  return 0;
394  }
395 
396  template <typename TArrayType>
397  static void
398  Assign(TArrayType & m, const TArrayType & v)
399  {
400  m = v;
401  }
402 
403  template <typename TValue, unsigned int VLength>
404  static void
405  Assign(FixedArray<TValue, VLength> & m, const TValue & v)
406  {
407  m[0] = v;
408  }
409 };
410 
416 template <typename TMeasurementVector>
418 {
419 public:
420  using ValueType = typename TMeasurementVector::ValueType;
421 };
422 
423 template <typename T>
424 class MeasurementVectorTraitsTypes<std::vector<T>>
425 {
426 public:
427  using ValueType = T;
428 };
429 
433 template <typename TPixelType>
435 {
436 public:
437  /* type of the vector that matches this pixel type */
438  using MeasurementVectorType = TPixelType;
439 };
440 
442 
446 template <>
448 {
449 public:
451 };
452 
453 template <>
454 class MeasurementVectorPixelTraits<unsigned char>
455 {
456 public:
458 };
459 
460 template <>
461 class MeasurementVectorPixelTraits<signed char>
462 {
463 public:
464  using MeasurementVectorType = FixedArray<signed char, 1>;
465 };
466 
467 template <>
468 class MeasurementVectorPixelTraits<unsigned short>
469 {
470 public:
471  using MeasurementVectorType = FixedArray<unsigned short, 1>;
472 };
473 
474 template <>
475 class MeasurementVectorPixelTraits<short>
476 {
477 public:
478  using MeasurementVectorType = FixedArray<short, 1>;
479 };
480 
481 template <>
482 class MeasurementVectorPixelTraits<unsigned int>
483 {
484 public:
485  using MeasurementVectorType = FixedArray<unsigned int, 1>;
486 };
487 
488 template <>
489 class MeasurementVectorPixelTraits<int>
490 {
491 public:
492  using MeasurementVectorType = FixedArray<int, 1>;
493 };
494 
495 template <>
496 class MeasurementVectorPixelTraits<unsigned long>
497 {
498 public:
499  using MeasurementVectorType = FixedArray<unsigned long, 1>;
500 };
501 
502 template <>
503 class MeasurementVectorPixelTraits<long>
504 {
505 public:
506  using MeasurementVectorType = FixedArray<long, 1>;
507 };
508 
509 template <>
510 class MeasurementVectorPixelTraits<unsigned long long>
511 {
512 public:
513  using MeasurementVectorType = FixedArray<unsigned long long, 1>;
514 };
515 
516 template <>
517 class MeasurementVectorPixelTraits<long long>
518 {
519 public:
520  using MeasurementVectorType = FixedArray<long long, 1>;
521 };
522 
523 template <>
524 class MeasurementVectorPixelTraits<float>
525 {
526 public:
527  using MeasurementVectorType = FixedArray<float, 1>;
528 };
529 
530 template <>
531 class MeasurementVectorPixelTraits<double>
532 {
533 public:
534  using MeasurementVectorType = FixedArray<double, 1>;
535 };
536 
538 
539 } // namespace Statistics
540 } // namespace itk
541 
542 #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:224
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:274
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:417
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:368
itkVariableLengthVector.h
itk::Statistics::MeasurementVectorTraitsTypes< std::vector< T > >::ValueType
T ValueType
Definition: itkMeasurementVectorTraits.h:427
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:398
itk::Statistics::MeasurementVectorPixelTraits::MeasurementVectorType
TPixelType MeasurementVectorType
Definition: itkMeasurementVectorTraits.h:438
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:259
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:334
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:241
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:405
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:319
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:289
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:383
itk::Statistics::MeasurementVectorPixelTraits
Definition: itkMeasurementVectorTraits.h:434
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:420
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:351
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:304
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itkSize.h