ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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::Statistics
32{
37
39{
40public:
48
54
56
57 template <typename TVectorType>
58 static bool
59 IsResizable(const TVectorType &)
60 {
61 // Test whether the vector type is resizable or not
62 //
63 // If the default constructor creates a vector of
64 // length zero, we assume that it is resizable,
65 // otherwise that is a pretty useless measurement vector.
67
68 return (len == 0);
69 }
70
71 template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
75 const char * errMsg = "Length Mismatch")
76 {
77 if (VLength != VLength2)
78 {
79 itkGenericExceptionMacro(<< errMsg);
80 }
81 return 0;
82 }
83
84 template <typename TValue1, unsigned int VLength, typename TValue2, unsigned int VLength2>
88 const char * errMsg = "Length Mismatch")
89 {
90 if (VLength != VLength2)
91 {
92 itkGenericExceptionMacro(<< errMsg);
93 }
94 return 0;
95 }
96
97 template <typename TValue1, typename TValue2>
99 Assert(const Array<TValue1> & a, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
100 {
101 if (b.Size() != a.Size())
102 {
103 itkGenericExceptionMacro(<< errMsg);
104 }
105 return 0;
106 }
107
108 template <typename TValue1, typename TValue2>
110 Assert(const Array<TValue1> * a, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
111 {
112 if (b->Size() != a->Size())
113 {
114 itkGenericExceptionMacro(<< errMsg);
115 }
116 return 0;
117 }
118
119 template <typename TValue1, typename TValue2>
123 const char * errMsg = "Length Mismatch")
124 {
125 if (b.Size() != a.Size())
126 {
127 itkGenericExceptionMacro(<< errMsg);
128 }
129 return 0;
130 }
131
132 template <typename TValue1, typename TValue2>
136 const char * errMsg = "Length Mismatch")
137 {
138 if (b->Size() != a->Size())
139 {
140 itkGenericExceptionMacro(<< errMsg);
141 }
142 return 0;
143 }
144
145 template <typename TValue1, typename TValue2>
147 Assert(const std::vector<TValue1> & a, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
148 {
149 if (b.size() != a.size())
150 {
151 itkGenericExceptionMacro(<< errMsg);
152 }
153 return 0;
154 }
155
156 template <typename TValue1, typename TValue2>
158 Assert(const std::vector<TValue1> * a, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
159 {
160 if (b->size() != a->size())
161 {
162 itkGenericExceptionMacro(<< errMsg);
163 }
164 return 0;
165 }
166
167 template <typename TValue1, unsigned int VLength, typename TValue2>
169 Assert(const FixedArray<TValue1, VLength> &, const Array<TValue2> & b, const char * errMsg = "Length Mismatch")
170 {
171 if (b.Size() == 0)
172 {
173 return VLength;
174 }
175 if (b.Size() != 0)
176 {
177 if (b.Size() != VLength)
178 {
179 itkGenericExceptionMacro(<< errMsg);
180 }
181 }
182 return 0;
183 }
184
185 template <typename TValue1, unsigned int VLength, typename TValue2>
187 Assert(const FixedArray<TValue1, VLength> *, const Array<TValue2> * b, const char * errMsg = "Length Mismatch")
188 {
189 if (b->Size() == 0)
190 {
191 return VLength;
192 }
193 if (b->Size() != VLength)
194 {
195 itkGenericExceptionMacro(<< errMsg);
196 }
197 return 0;
198 }
199
200 template <typename TValue1, unsigned int VLength, typename TValue2>
204 const char * errMsg = "Length Mismatch")
205 {
206 if (b.Size() == 0)
207 {
208 return VLength;
209 }
210 if (b.Size() != VLength)
211 {
212 itkGenericExceptionMacro(<< errMsg);
213 }
214 return 0;
215 }
216
217 template <typename TValue1, unsigned int VLength, typename TValue2>
221 const char * errMsg = "Length Mismatch")
222 {
223 if (b->Size() == 0)
224 {
225 return VLength;
226 }
227 if (b->Size() != VLength)
228 {
229 itkGenericExceptionMacro(<< errMsg);
230 }
231 return 0;
232 }
233
234 template <typename TValue1, unsigned int VLength, typename TValue2>
236 Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
237 {
238 if (b.empty())
239 {
240 return VLength;
241 }
242 if (b.size() != VLength)
243 {
244 itkGenericExceptionMacro(<< errMsg);
245 }
246 return 0;
247 }
248
249 template <typename TValue1, unsigned int VLength, typename TValue2>
251 Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
252 {
253 if (b->size() == 0)
254 {
255 return VLength;
256 }
257 if (b->size() != VLength)
258 {
259 itkGenericExceptionMacro(<< errMsg);
260 }
261 return 0;
262 }
263
264 template <typename TValue1, unsigned int VLength>
266 Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
267 {
268 if (l == 0)
269 {
270 return VLength;
271 }
272 if (l != VLength)
273 {
274 itkGenericExceptionMacro(<< errMsg);
275 }
276 return 0;
277 }
278
279 template <typename TValue1, unsigned int VLength>
281 Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
282 {
283 if (l == 0)
284 {
285 return VLength;
286 }
287 if (l != VLength)
288 {
289 itkGenericExceptionMacro(<< errMsg);
290 }
291 return 0;
292 }
293
294 template <typename TValue>
296 Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
297 {
298 if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
299 {
300 itkGenericExceptionMacro(<< errMsg);
301 }
302 else if (l == 0)
303 {
304 return a.Size();
305 }
306 return 0;
307 }
308
309 template <typename TValue>
311 Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
312 {
313 if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
314 {
315 itkGenericExceptionMacro(<< errMsg);
316 }
317 else if (l == 0)
318 {
319 return a->Size();
320 }
321 return 0;
322 }
323
324 template <typename TValue>
328 const char * errMsg = "Length Mismatch")
329 {
330 if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
331 {
332 itkGenericExceptionMacro(<< errMsg);
333 }
334 else if (l == 0)
335 {
336 return a.Size();
337 }
338 return 0;
339 }
340
341 template <typename TValue>
345 const char * errMsg = "Length Mismatch")
346 {
347 if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
348 {
349 itkGenericExceptionMacro(<< errMsg);
350 }
351 else if (l == 0)
352 {
353 return a->Size();
354 }
355 return 0;
356 }
357
358 template <typename TValue>
360 Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
361 {
362 if (((l != 0) && (a.size() != l)) || (a.empty()))
363 {
364 itkGenericExceptionMacro(<< errMsg);
365 }
366 else if (l == 0)
367 {
368 return static_cast<MeasurementVectorLength>(a.size());
369 }
370 return 0;
371 }
372
373 template <typename TValue>
375 Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
376 {
377 if (((l != 0) && (a->size() != l)) || (a->size() == 0))
378 {
379 itkGenericExceptionMacro(<< errMsg);
380 }
381 else if (l == 0)
382 {
383 return a->size();
384 }
385 return 0;
386 }
387
388 template <typename TArrayType>
389 static void
390 Assign(TArrayType & m, const TArrayType & v)
391 {
392 m = v;
393 }
394
395 template <typename TValue, unsigned int VLength>
396 static void
397 Assign(FixedArray<TValue, VLength> & m, const TValue & v)
398 {
399 m[0] = v;
400 }
401};
402
407
408template <typename TMeasurementVector>
410{
411public:
412 using ValueType = typename TMeasurementVector::ValueType;
413};
414
415template <typename T>
417{
418public:
419 using ValueType = T;
420};
421
424
425template <typename TPixelType>
427{
428public:
429 /* type of the vector that matches this pixel type */
430 using MeasurementVectorType = TPixelType;
431};
432
434
438template <>
440{
441public:
443};
444
445template <>
446class MeasurementVectorPixelTraits<unsigned char>
447{
448public:
450};
451
452template <>
453class MeasurementVectorPixelTraits<signed char>
454{
455public:
456 using MeasurementVectorType = FixedArray<signed char, 1>;
457};
458
459template <>
460class MeasurementVectorPixelTraits<unsigned short>
461{
462public:
463 using MeasurementVectorType = FixedArray<unsigned short, 1>;
464};
465
466template <>
468{
469public:
470 using MeasurementVectorType = FixedArray<short, 1>;
471};
472
473template <>
474class MeasurementVectorPixelTraits<unsigned int>
475{
476public:
477 using MeasurementVectorType = FixedArray<unsigned int, 1>;
478};
479
480template <>
482{
483public:
484 using MeasurementVectorType = FixedArray<int, 1>;
485};
486
487template <>
488class MeasurementVectorPixelTraits<unsigned long>
489{
490public:
491 using MeasurementVectorType = FixedArray<unsigned long, 1>;
492};
493
494template <>
496{
497public:
498 using MeasurementVectorType = FixedArray<long, 1>;
499};
500
501template <>
502class MeasurementVectorPixelTraits<unsigned long long>
503{
504public:
505 using MeasurementVectorType = FixedArray<unsigned long long, 1>;
506};
507
508template <>
509class MeasurementVectorPixelTraits<long long>
510{
511public:
512 using MeasurementVectorType = FixedArray<long long, 1>;
513};
514
515template <>
517{
518public:
519 using MeasurementVectorType = FixedArray<float, 1>;
520};
521
522template <>
524{
525public:
526 using MeasurementVectorType = FixedArray<double, 1>;
527};
528
530
531} // namespace itk::Statistics
532
533
534#endif // itkMeasurementVectorTraits_h
Array class with size defined at construction time.
Definition itkArray.h:48
SizeValueType Size() const
Definition itkArray.h:130
Simulate a standard C array with copy semantics.
static unsigned int GetLength()
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")
NumericTraits< AbsoluteFrequencyType >::RealType RelativeFrequencyType
static MeasurementVectorLength Assert(const Array< TValue > *a, const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
SizeValueType IdentifierType
Definition itkIntTypes.h:90
STL namespace.