ITK  5.4.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 {
42 {
43 public:
51 
57 
58  using MeasurementVectorLength = size_t;
59 
60  template <typename TVectorType>
61  static bool
62  IsResizable(const TVectorType &)
63  {
64  // Test whether the vector type is resizable or not
65  //
66  // If the default constructor creates a vector of
67  // length zero, we assume that it is resizable,
68  // otherwise that is a pretty useless measurement vector.
70 
71  return (len == 0);
72  }
73 
74  template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
78  const char * errMsg = "Length Mismatch")
79  {
80  if (VLength != VLength2)
81  {
82  itkGenericExceptionMacro(<< errMsg);
83  }
84  return 0;
85  }
86 
87  template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
91  const char * errMsg = "Length Mismatch")
92  {
93  if (VLength != VLength2)
94  {
95  itkGenericExceptionMacro(<< errMsg);
96  }
97  return 0;
98  }
99 
100  template <typename TValue1, typename TValue2>
102  Assert(const Array<TValue1> & a, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
103  {
104  if (b.Size() != a.Size())
105  {
106  itkGenericExceptionMacro(<< errMsg);
107  }
108  return 0;
109  }
110 
111  template <typename TValue1, typename TValue2>
113  Assert(const Array<TValue1> * a, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
114  {
115  if (b->Size() != a->Size())
116  {
117  itkGenericExceptionMacro(<< errMsg);
118  }
119  return 0;
120  }
121 
122  template <typename TValue1, typename TValue2>
126  const char * errMsg = "Length Mismatch")
127  {
128  if (b.Size() != a.Size())
129  {
130  itkGenericExceptionMacro(<< errMsg);
131  }
132  return 0;
133  }
134 
135  template <typename TValue1, typename TValue2>
139  const char * errMsg = "Length Mismatch")
140  {
141  if (b->Size() != a->Size())
142  {
143  itkGenericExceptionMacro(<< errMsg);
144  }
145  return 0;
146  }
147 
148  template <typename TValue1, typename TValue2>
150  Assert(const std::vector<TValue1> & a, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
151  {
152  if (b.size() != a.size())
153  {
154  itkGenericExceptionMacro(<< errMsg);
155  }
156  return 0;
157  }
158 
159  template <typename TValue1, typename TValue2>
161  Assert(const std::vector<TValue1> * a, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
162  {
163  if (b->size() != a->size())
164  {
165  itkGenericExceptionMacro(<< errMsg);
166  }
167  return 0;
168  }
169 
170  template <typename TValue1, unsigned int VLength, typename TValue2>
172  Assert(const FixedArray<TValue1, VLength> &, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
173  {
174  if (b.Size() == 0)
175  {
176  return VLength;
177  }
178  if (b.Size() != 0)
179  {
180  if (b.Size() != VLength)
181  {
182  itkGenericExceptionMacro(<< errMsg);
183  }
184  }
185  return 0;
186  }
187 
188  template <typename TValue1, unsigned int VLength, typename TValue2>
190  Assert(const FixedArray<TValue1, VLength> *, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
191  {
192  if (b->Size() == 0)
193  {
194  return VLength;
195  }
196  else if (b->Size() != VLength)
197  {
198  itkGenericExceptionMacro(<< errMsg);
199  }
200  return 0;
201  }
202 
203  template <typename TValue1, unsigned int VLength, typename TValue2>
207  const char * errMsg = "Length Mismatch")
208  {
209  if (b.Size() == 0)
210  {
211  return VLength;
212  }
213  if (b.Size() != 0)
214  {
215  if (b.Size() != VLength)
216  {
217  itkGenericExceptionMacro(<< errMsg);
218  }
219  }
220  return 0;
221  }
222 
223  template <typename TValue1, unsigned int VLength, typename TValue2>
227  const char * errMsg = "Length Mismatch")
228  {
229  if (b->Size() == 0)
230  {
231  return VLength;
232  }
233  else if (b->Size() != VLength)
234  {
235  itkGenericExceptionMacro(<< errMsg);
236  }
237  return 0;
238  }
239 
240  template <typename TValue1, unsigned int VLength, typename TValue2>
242  Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
243  {
244  if (b.empty())
245  {
246  return VLength;
247  }
248  if (!b.empty())
249  {
250  if (b.size() != VLength)
251  {
252  itkGenericExceptionMacro(<< errMsg);
253  }
254  }
255  return 0;
256  }
257 
258  template <typename TValue1, unsigned int VLength, typename TValue2>
260  Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
261  {
262  if (b->size() == 0)
263  {
264  return VLength;
265  }
266  else if (b->size() != VLength)
267  {
268  itkGenericExceptionMacro(<< errMsg);
269  }
270  return 0;
271  }
272 
273  template <typename TValue1, unsigned int VLength>
275  Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
276  {
277  if (l == 0)
278  {
279  return VLength;
280  }
281  else if (l != VLength)
282  {
283  itkGenericExceptionMacro(<< errMsg);
284  }
285  return 0;
286  }
287 
288  template <typename TValue1, unsigned int VLength>
290  Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
291  {
292  if (l == 0)
293  {
294  return VLength;
295  }
296  else if (l != VLength)
297  {
298  itkGenericExceptionMacro(<< errMsg);
299  }
300  return 0;
301  }
302 
303  template <typename TValue>
305  Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
306  {
307  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
308  {
309  itkGenericExceptionMacro(<< errMsg);
310  }
311  else if (l == 0)
312  {
313  return a.Size();
314  }
315  return 0;
316  }
317 
318  template <typename TValue>
320  Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
321  {
322  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
323  {
324  itkGenericExceptionMacro(<< errMsg);
325  }
326  else if (l == 0)
327  {
328  return a->Size();
329  }
330  return 0;
331  }
332 
333  template <typename TValue>
336  const MeasurementVectorLength l,
337  const char * errMsg = "Length Mismatch")
338  {
339  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
340  {
341  itkGenericExceptionMacro(<< errMsg);
342  }
343  else if (l == 0)
344  {
345  return a.Size();
346  }
347  return 0;
348  }
349 
350  template <typename TValue>
353  const MeasurementVectorLength l,
354  const char * errMsg = "Length Mismatch")
355  {
356  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
357  {
358  itkGenericExceptionMacro(<< errMsg);
359  }
360  else if (l == 0)
361  {
362  return a->Size();
363  }
364  return 0;
365  }
366 
367  template <typename TValue>
369  Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
370  {
371  if (((l != 0) && (a.size() != l)) || (a.empty()))
372  {
373  itkGenericExceptionMacro(<< errMsg);
374  }
375  else if (l == 0)
376  {
377  return static_cast<MeasurementVectorLength>(a.size());
378  }
379  return 0;
380  }
381 
382  template <typename TValue>
384  Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
385  {
386  if (((l != 0) && (a->size() != l)) || (a->size() == 0))
387  {
388  itkGenericExceptionMacro(<< errMsg);
389  }
390  else if (l == 0)
391  {
392  return a->size();
393  }
394  return 0;
395  }
396 
397  template <typename TArrayType>
398  static void
399  Assign(TArrayType & m, const TArrayType & v)
400  {
401  m = v;
402  }
403 
404  template <typename TValue, unsigned int VLength>
405  static void
406  Assign(FixedArray<TValue, VLength> & m, const TValue & v)
407  {
408  m[0] = v;
409  }
410 };
411 
418 template <typename TMeasurementVector>
420 {
421 public:
422  using ValueType = typename TMeasurementVector::ValueType;
423 };
424 
425 template <typename T>
426 class MeasurementVectorTraitsTypes<std::vector<T>>
427 {
428 public:
429  using ValueType = T;
430 };
431 
435 template <typename TPixelType>
437 {
438 public:
439  /* type of the vector that matches this pixel type */
440  using MeasurementVectorType = TPixelType;
441 };
442 
444 
448 template <>
450 {
451 public:
453 };
454 
455 template <>
456 class MeasurementVectorPixelTraits<unsigned char>
457 {
458 public:
460 };
461 
462 template <>
463 class MeasurementVectorPixelTraits<signed char>
464 {
465 public:
466  using MeasurementVectorType = FixedArray<signed char, 1>;
467 };
468 
469 template <>
470 class MeasurementVectorPixelTraits<unsigned short>
471 {
472 public:
473  using MeasurementVectorType = FixedArray<unsigned short, 1>;
474 };
475 
476 template <>
477 class MeasurementVectorPixelTraits<short>
478 {
479 public:
480  using MeasurementVectorType = FixedArray<short, 1>;
481 };
482 
483 template <>
484 class MeasurementVectorPixelTraits<unsigned int>
485 {
486 public:
487  using MeasurementVectorType = FixedArray<unsigned int, 1>;
488 };
489 
490 template <>
491 class MeasurementVectorPixelTraits<int>
492 {
493 public:
494  using MeasurementVectorType = FixedArray<int, 1>;
495 };
496 
497 template <>
498 class MeasurementVectorPixelTraits<unsigned long>
499 {
500 public:
501  using MeasurementVectorType = FixedArray<unsigned long, 1>;
502 };
503 
504 template <>
505 class MeasurementVectorPixelTraits<long>
506 {
507 public:
508  using MeasurementVectorType = FixedArray<long, 1>;
509 };
510 
511 template <>
512 class MeasurementVectorPixelTraits<unsigned long long>
513 {
514 public:
515  using MeasurementVectorType = FixedArray<unsigned long long, 1>;
516 };
517 
518 template <>
519 class MeasurementVectorPixelTraits<long long>
520 {
521 public:
522  using MeasurementVectorType = FixedArray<long long, 1>;
523 };
524 
525 template <>
526 class MeasurementVectorPixelTraits<float>
527 {
528 public:
529  using MeasurementVectorType = FixedArray<float, 1>;
530 };
531 
532 template <>
533 class MeasurementVectorPixelTraits<double>
534 {
535 public:
536  using MeasurementVectorType = FixedArray<double, 1>;
537 };
538 
540 
541 } // namespace Statistics
542 } // namespace itk
543 
544 #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:172
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:225
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:275
itk::Statistics::MeasurementVectorTraits::InstanceIdentifier
IdentifierType InstanceIdentifier
Definition: itkMeasurementVectorTraits.h:50
itk::Statistics::MeasurementVectorTraits::TotalRelativeFrequencyType
NumericTraits< RelativeFrequencyType >::AccumulateType TotalRelativeFrequencyType
Definition: itkMeasurementVectorTraits.h:56
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const FixedArray< TValue2, VLength2 > &, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:76
itkRGBPixel.h
itkVariableSizeMatrix.h
itkMatrix.h
itk::Statistics::MeasurementVectorTraitsTypes
Definition: itkMeasurementVectorTraits.h:419
itk::Statistics::MeasurementVectorTraits::MeasurementVectorLength
vcl_size_t MeasurementVectorLength
Definition: itkMeasurementVectorTraits.h:58
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:190
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:369
itkVariableLengthVector.h
itk::Statistics::MeasurementVectorTraitsTypes< std::vector< T > >::ValueType
T ValueType
Definition: itkMeasurementVectorTraits.h:429
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue1 > *a, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:113
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:75
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:150
itk::Statistics::MeasurementVectorTraits::Assign
static void Assign(TArrayType &m, const TArrayType &v)
Definition: itkMeasurementVectorTraits.h:399
itk::Statistics::MeasurementVectorPixelTraits::MeasurementVectorType
TPixelType MeasurementVectorType
Definition: itkMeasurementVectorTraits.h:440
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:260
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:205
itk::Statistics::MeasurementVectorTraits::AbsoluteFrequencyType
InstanceIdentifier AbsoluteFrequencyType
Definition: itkMeasurementVectorTraits.h:53
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const FixedArray< TValue2, VLength2 > *, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:89
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:335
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:242
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:590
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > *a, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:137
itk::Statistics::MeasurementVectorTraits::Assign
static void Assign(FixedArray< TValue, VLength > &m, const TValue &v)
Definition: itkMeasurementVectorTraits.h:406
itk::Statistics::MeasurementVectorTraits
Definition: itkMeasurementVectorTraits.h:41
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:320
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:290
itk::Statistics::MeasurementVectorTraits::RelativeFrequencyType
NumericTraits< AbsoluteFrequencyType >::RealType RelativeFrequencyType
Definition: itkMeasurementVectorTraits.h:54
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > &a, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:124
itk::Statistics::MeasurementVectorTraits::IsResizable
static bool IsResizable(const TVectorType &)
Definition: itkMeasurementVectorTraits.h:62
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:161
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:209
itk::Statistics::MeasurementVectorTraits::TotalAbsoluteFrequencyType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkMeasurementVectorTraits.h:55
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:384
itk::Statistics::MeasurementVectorPixelTraits
Definition: itkMeasurementVectorTraits.h:436
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:422
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:102
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:128
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:85
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:352
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:305
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itkSize.h