ITK  5.2.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  * http://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 = std::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.
69  TVectorType m;
71 
72  return (len == 0);
73  }
74 
75  template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
79  const char * errMsg = "Length Mismatch")
80  {
81  if (VLength != VLength2)
82  {
83  itkGenericExceptionMacro(<< errMsg);
84  }
85  return 0;
86  }
87 
88  template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
92  const char * errMsg = "Length Mismatch")
93  {
94  if (VLength != VLength2)
95  {
96  itkGenericExceptionMacro(<< errMsg);
97  }
98  return 0;
99  }
100 
101  template <typename TValue1, typename TValue2>
103  Assert(const Array<TValue1> & a, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
104  {
105  if (b.Size() != a.Size())
106  {
107  itkGenericExceptionMacro(<< errMsg);
108  }
109  return 0;
110  }
111 
112  template <typename TValue1, typename TValue2>
114  Assert(const Array<TValue1> * a, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
115  {
116  if (b->Size() != a->Size())
117  {
118  itkGenericExceptionMacro(<< errMsg);
119  }
120  return 0;
121  }
122 
123  template <typename TValue1, typename TValue2>
127  const char * errMsg = "Length Mismatch")
128  {
129  if (b.Size() != a.Size())
130  {
131  itkGenericExceptionMacro(<< errMsg);
132  }
133  return 0;
134  }
135 
136  template <typename TValue1, typename TValue2>
140  const char * errMsg = "Length Mismatch")
141  {
142  if (b->Size() != a->Size())
143  {
144  itkGenericExceptionMacro(<< errMsg);
145  }
146  return 0;
147  }
148 
149  template <typename TValue1, typename TValue2>
151  Assert(const std::vector<TValue1> & a, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
152  {
153  if (b.size() != a.size())
154  {
155  itkGenericExceptionMacro(<< errMsg);
156  }
157  return 0;
158  }
159 
160  template <typename TValue1, typename TValue2>
162  Assert(const std::vector<TValue1> * a, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
163  {
164  if (b->size() != a->size())
165  {
166  itkGenericExceptionMacro(<< errMsg);
167  }
168  return 0;
169  }
170 
171  template <typename TValue1, unsigned int VLength, typename TValue2>
173  Assert(const FixedArray<TValue1, VLength> &, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
174  {
175  if (b.Size() == 0)
176  {
177  return VLength;
178  }
179  if (b.Size() != 0)
180  {
181  if (b.Size() != VLength)
182  {
183  itkGenericExceptionMacro(<< errMsg);
184  }
185  }
186  return 0;
187  }
188 
189  template <typename TValue1, unsigned int VLength, typename TValue2>
191  Assert(const FixedArray<TValue1, VLength> *, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
192  {
193  if (b->Size() == 0)
194  {
195  return VLength;
196  }
197  else if (b->Size() != VLength)
198  {
199  itkGenericExceptionMacro(<< errMsg);
200  }
201  return 0;
202  }
203 
204  template <typename TValue1, unsigned int VLength, typename TValue2>
208  const char * errMsg = "Length Mismatch")
209  {
210  if (b.Size() == 0)
211  {
212  return VLength;
213  }
214  if (b.Size() != 0)
215  {
216  if (b.Size() != VLength)
217  {
218  itkGenericExceptionMacro(<< errMsg);
219  }
220  }
221  return 0;
222  }
223 
224  template <typename TValue1, unsigned int VLength, typename TValue2>
228  const char * errMsg = "Length Mismatch")
229  {
230  if (b->Size() == 0)
231  {
232  return VLength;
233  }
234  else if (b->Size() != VLength)
235  {
236  itkGenericExceptionMacro(<< errMsg);
237  }
238  return 0;
239  }
240 
241  template <typename TValue1, unsigned int VLength, typename TValue2>
243  Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
244  {
245  if (b.empty())
246  {
247  return VLength;
248  }
249  if (!b.empty())
250  {
251  if (b.size() != VLength)
252  {
253  itkGenericExceptionMacro(<< errMsg);
254  }
255  }
256  return 0;
257  }
258 
259  template <typename TValue1, unsigned int VLength, typename TValue2>
261  Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
262  {
263  if (b->size() == 0)
264  {
265  return VLength;
266  }
267  else if (b->size() != VLength)
268  {
269  itkGenericExceptionMacro(<< errMsg);
270  }
271  return 0;
272  }
273 
274  template <typename TValue1, unsigned int VLength>
276  Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
277  {
278  if (l == 0)
279  {
280  return VLength;
281  }
282  else if (l != VLength)
283  {
284  itkGenericExceptionMacro(<< errMsg);
285  }
286  return 0;
287  }
288 
289  template <typename TValue1, unsigned int VLength>
291  Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
292  {
293  if (l == 0)
294  {
295  return VLength;
296  }
297  else if (l != VLength)
298  {
299  itkGenericExceptionMacro(<< errMsg);
300  }
301  return 0;
302  }
303 
304  template <typename TValue>
306  Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
307  {
308  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
309  {
310  itkGenericExceptionMacro(<< errMsg);
311  }
312  else if (l == 0)
313  {
314  return a.Size();
315  }
316  return 0;
317  }
318 
319  template <typename TValue>
321  Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
322  {
323  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
324  {
325  itkGenericExceptionMacro(<< errMsg);
326  }
327  else if (l == 0)
328  {
329  return a->Size();
330  }
331  return 0;
332  }
333 
334  template <typename TValue>
337  const MeasurementVectorLength l,
338  const char * errMsg = "Length Mismatch")
339  {
340  if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
341  {
342  itkGenericExceptionMacro(<< errMsg);
343  }
344  else if (l == 0)
345  {
346  return a.Size();
347  }
348  return 0;
349  }
350 
351  template <typename TValue>
354  const MeasurementVectorLength l,
355  const char * errMsg = "Length Mismatch")
356  {
357  if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
358  {
359  itkGenericExceptionMacro(<< errMsg);
360  }
361  else if (l == 0)
362  {
363  return a->Size();
364  }
365  return 0;
366  }
367 
368  template <typename TValue>
370  Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
371  {
372  if (((l != 0) && (a.size() != l)) || (a.empty()))
373  {
374  itkGenericExceptionMacro(<< errMsg);
375  }
376  else if (l == 0)
377  {
378  return static_cast<MeasurementVectorLength>(a.size());
379  }
380  return 0;
381  }
382 
383  template <typename TValue>
385  Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
386  {
387  if (((l != 0) && (a->size() != l)) || (a->size() == 0))
388  {
389  itkGenericExceptionMacro(<< errMsg);
390  }
391  else if (l == 0)
392  {
393  return a->size();
394  }
395  return 0;
396  }
397 
398  template <typename TArrayType>
399  static void
400  Assign(TArrayType & m, const TArrayType & v)
401  {
402  m = v;
403  }
404 
405  template <typename TValue, unsigned int VLength>
406  static void
407  Assign(FixedArray<TValue, VLength> & m, const TValue & v)
408  {
409  m[0] = v;
410  }
411 };
412 
419 template <typename TMeasurementVector>
421 {
422 public:
423  using ValueType = typename TMeasurementVector::ValueType;
424 };
425 
426 template <typename T>
427 class MeasurementVectorTraitsTypes<std::vector<T>>
428 {
429 public:
430  using ValueType = T;
431 };
432 
436 template <typename TPixelType>
438 {
439 public:
440  /* type of the vector that matches this pixel type */
441  using MeasurementVectorType = TPixelType;
442 };
443 
445 
449 template <>
451 {
452 public:
454 };
455 
456 template <>
457 class MeasurementVectorPixelTraits<unsigned char>
458 {
459 public:
461 };
462 
463 template <>
464 class MeasurementVectorPixelTraits<signed char>
465 {
466 public:
467  using MeasurementVectorType = FixedArray<signed char, 1>;
468 };
469 
470 template <>
471 class MeasurementVectorPixelTraits<unsigned short>
472 {
473 public:
474  using MeasurementVectorType = FixedArray<unsigned short, 1>;
475 };
476 
477 template <>
478 class MeasurementVectorPixelTraits<signed short>
479 {
480 public:
481  using MeasurementVectorType = FixedArray<signed short, 1>;
482 };
483 
484 template <>
485 class MeasurementVectorPixelTraits<unsigned int>
486 {
487 public:
488  using MeasurementVectorType = FixedArray<unsigned int, 1>;
489 };
490 
491 template <>
492 class MeasurementVectorPixelTraits<signed int>
493 {
494 public:
495  using MeasurementVectorType = FixedArray<signed int, 1>;
496 };
497 
498 template <>
499 class MeasurementVectorPixelTraits<unsigned long>
500 {
501 public:
502  using MeasurementVectorType = FixedArray<unsigned long, 1>;
503 };
504 
505 template <>
506 class MeasurementVectorPixelTraits<signed long>
507 {
508 public:
509  using MeasurementVectorType = FixedArray<signed long, 1>;
510 };
511 
512 template <>
513 class MeasurementVectorPixelTraits<unsigned long long>
514 {
515 public:
516  using MeasurementVectorType = FixedArray<unsigned long long, 1>;
517 };
518 
519 template <>
520 class MeasurementVectorPixelTraits<signed long long>
521 {
522 public:
523  using MeasurementVectorType = FixedArray<signed long long, 1>;
524 };
525 
526 template <>
527 class MeasurementVectorPixelTraits<float>
528 {
529 public:
530  using MeasurementVectorType = FixedArray<float, 1>;
531 };
532 
533 template <>
534 class MeasurementVectorPixelTraits<double>
535 {
536 public:
537  using MeasurementVectorType = FixedArray<double, 1>;
538 };
539 
541 
542 } // namespace Statistics
543 } // namespace itk
544 
545 #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:173
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:226
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:276
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:77
itkRGBPixel.h
itkVariableSizeMatrix.h
itkMatrix.h
itk::Statistics::MeasurementVectorTraitsTypes
Definition: itkMeasurementVectorTraits.h:420
itk::Statistics::MeasurementVectorTraits::MeasurementVectorLength
std::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:191
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const std::vector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:370
itkVariableLengthVector.h
itk::Statistics::MeasurementVectorTraitsTypes< std::vector< T > >::ValueType
T ValueType
Definition: itkMeasurementVectorTraits.h:430
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue1 > *a, const Array< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:114
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:74
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:151
itk::Statistics::MeasurementVectorTraits::Assign
static void Assign(TArrayType &m, const TArrayType &v)
Definition: itkMeasurementVectorTraits.h:400
itk::Statistics::MeasurementVectorPixelTraits::MeasurementVectorType
TPixelType MeasurementVectorType
Definition: itkMeasurementVectorTraits.h:441
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const std::vector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:261
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const VariableLengthVector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:206
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:90
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:336
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > &, const std::vector< TValue2 > &b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:243
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:592
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue1 > *a, const VariableLengthVector< TValue2 > *b, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:138
itk::Statistics::MeasurementVectorTraits::Assign
static void Assign(FixedArray< TValue, VLength > &m, const TValue &v)
Definition: itkMeasurementVectorTraits.h:407
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:52
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:321
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const FixedArray< TValue1, VLength > *, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:291
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:125
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:162
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:208
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:385
itk::Statistics::MeasurementVectorPixelTraits
Definition: itkMeasurementVectorTraits.h:437
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:423
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:103
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:131
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const VariableLengthVector< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:353
itk::Statistics::MeasurementVectorTraits::Assert
static MeasurementVectorLength Assert(const Array< TValue > &a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
Definition: itkMeasurementVectorTraits.h:306
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itkSize.h