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"
26#include "itkNumericTraits.h"
28#include "itkSize.h"
29#include <vector>
30
31namespace itk
32{
33namespace Statistics
34{
41{
42public:
50
56
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>
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>
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
416template <typename TMeasurementVector>
418{
419public:
420 using ValueType = typename TMeasurementVector::ValueType;
421};
422
423template <typename T>
425{
426public:
427 using ValueType = T;
428};
429
433template <typename TPixelType>
435{
436public:
437 /* type of the vector that matches this pixel type */
438 using MeasurementVectorType = TPixelType;
439};
440
442
446template <>
448{
449public:
451};
452
453template <>
454class MeasurementVectorPixelTraits<unsigned char>
455{
456public:
458};
459
460template <>
461class MeasurementVectorPixelTraits<signed char>
462{
463public:
464 using MeasurementVectorType = FixedArray<signed char, 1>;
465};
466
467template <>
468class MeasurementVectorPixelTraits<unsigned short>
469{
470public:
471 using MeasurementVectorType = FixedArray<unsigned short, 1>;
472};
473
474template <>
475class MeasurementVectorPixelTraits<short>
476{
477public:
478 using MeasurementVectorType = FixedArray<short, 1>;
479};
480
481template <>
482class MeasurementVectorPixelTraits<unsigned int>
483{
484public:
485 using MeasurementVectorType = FixedArray<unsigned int, 1>;
486};
487
488template <>
489class MeasurementVectorPixelTraits<int>
490{
491public:
492 using MeasurementVectorType = FixedArray<int, 1>;
493};
494
495template <>
496class MeasurementVectorPixelTraits<unsigned long>
497{
498public:
499 using MeasurementVectorType = FixedArray<unsigned long, 1>;
500};
501
502template <>
503class MeasurementVectorPixelTraits<long>
504{
505public:
506 using MeasurementVectorType = FixedArray<long, 1>;
507};
508
509template <>
510class MeasurementVectorPixelTraits<unsigned long long>
511{
512public:
513 using MeasurementVectorType = FixedArray<unsigned long long, 1>;
514};
515
516template <>
517class MeasurementVectorPixelTraits<long long>
518{
519public:
520 using MeasurementVectorType = FixedArray<long long, 1>;
521};
522
523template <>
524class MeasurementVectorPixelTraits<float>
525{
526public:
527 using MeasurementVectorType = FixedArray<float, 1>;
528};
529
530template <>
531class MeasurementVectorPixelTraits<double>
532{
533public:
534 using MeasurementVectorType = FixedArray<double, 1>;
535};
536
538
539} // namespace Statistics
540} // namespace itk
541
542#endif // itkMeasurementVectorTraits_h
Array class with size defined at construction time.
Definition: itkArray.h:48
SizeValueType Size() const
Definition: itkArray.h:128
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
static unsigned int GetLength()
typename TMeasurementVector::ValueType ValueType
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")
static bool IsResizable(const TVectorType &)
NumericTraits< AbsoluteFrequencyType >::RealType RelativeFrequencyType
static MeasurementVectorLength Assert(const Array< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
STL namespace.