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
32{
33namespace Statistics
34{
39
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 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() != VLength)
213 {
214 itkGenericExceptionMacro(<< errMsg);
215 }
216 return 0;
217 }
218
219 template <typename TValue1, unsigned int VLength, typename TValue2>
223 const char * errMsg = "Length Mismatch")
224 {
225 if (b->Size() == 0)
226 {
227 return VLength;
228 }
229 if (b->Size() != VLength)
230 {
231 itkGenericExceptionMacro(<< errMsg);
232 }
233 return 0;
234 }
235
236 template <typename TValue1, unsigned int VLength, typename TValue2>
238 Assert(const FixedArray<TValue1, VLength> &, const std::vector<TValue2> & b, const char * errMsg = "Length Mismatch")
239 {
240 if (b.empty())
241 {
242 return VLength;
243 }
244 if (b.size() != VLength)
245 {
246 itkGenericExceptionMacro(<< errMsg);
247 }
248 return 0;
249 }
250
251 template <typename TValue1, unsigned int VLength, typename TValue2>
253 Assert(const FixedArray<TValue1, VLength> *, const std::vector<TValue2> * b, const char * errMsg = "Length Mismatch")
254 {
255 if (b->size() == 0)
256 {
257 return VLength;
258 }
259 if (b->size() != VLength)
260 {
261 itkGenericExceptionMacro(<< errMsg);
262 }
263 return 0;
264 }
265
266 template <typename TValue1, unsigned int VLength>
268 Assert(const FixedArray<TValue1, VLength> &, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
269 {
270 if (l == 0)
271 {
272 return VLength;
273 }
274 if (l != VLength)
275 {
276 itkGenericExceptionMacro(<< errMsg);
277 }
278 return 0;
279 }
280
281 template <typename TValue1, unsigned int VLength>
283 Assert(const FixedArray<TValue1, VLength> *, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
284 {
285 if (l == 0)
286 {
287 return VLength;
288 }
289 if (l != VLength)
290 {
291 itkGenericExceptionMacro(<< errMsg);
292 }
293 return 0;
294 }
295
296 template <typename TValue>
298 Assert(const Array<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
299 {
300 if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
301 {
302 itkGenericExceptionMacro(<< errMsg);
303 }
304 else if (l == 0)
305 {
306 return a.Size();
307 }
308 return 0;
309 }
310
311 template <typename TValue>
313 Assert(const Array<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
314 {
315 if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
316 {
317 itkGenericExceptionMacro(<< errMsg);
318 }
319 else if (l == 0)
320 {
321 return a->Size();
322 }
323 return 0;
324 }
325
326 template <typename TValue>
330 const char * errMsg = "Length Mismatch")
331 {
332 if (((l != 0) && (a.Size() != l)) || (a.Size() == 0))
333 {
334 itkGenericExceptionMacro(<< errMsg);
335 }
336 else if (l == 0)
337 {
338 return a.Size();
339 }
340 return 0;
341 }
342
343 template <typename TValue>
347 const char * errMsg = "Length Mismatch")
348 {
349 if (((l != 0) && (a->Size() != l)) || (a->Size() == 0))
350 {
351 itkGenericExceptionMacro(<< errMsg);
352 }
353 else if (l == 0)
354 {
355 return a->Size();
356 }
357 return 0;
358 }
359
360 template <typename TValue>
362 Assert(const std::vector<TValue> & a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
363 {
364 if (((l != 0) && (a.size() != l)) || (a.empty()))
365 {
366 itkGenericExceptionMacro(<< errMsg);
367 }
368 else if (l == 0)
369 {
370 return static_cast<MeasurementVectorLength>(a.size());
371 }
372 return 0;
373 }
374
375 template <typename TValue>
377 Assert(const std::vector<TValue> * a, const MeasurementVectorLength l, const char * errMsg = "Length Mismatch")
378 {
379 if (((l != 0) && (a->size() != l)) || (a->size() == 0))
380 {
381 itkGenericExceptionMacro(<< errMsg);
382 }
383 else if (l == 0)
384 {
385 return a->size();
386 }
387 return 0;
388 }
389
390 template <typename TArrayType>
391 static void
392 Assign(TArrayType & m, const TArrayType & v)
393 {
394 m = v;
395 }
396
397 template <typename TValue, unsigned int VLength>
398 static void
399 Assign(FixedArray<TValue, VLength> & m, const TValue & v)
400 {
401 m[0] = v;
402 }
403};
404
409
410template <typename TMeasurementVector>
412{
413public:
414 using ValueType = typename TMeasurementVector::ValueType;
415};
416
417template <typename T>
419{
420public:
421 using ValueType = T;
422};
423
426
427template <typename TPixelType>
429{
430public:
431 /* type of the vector that matches this pixel type */
432 using MeasurementVectorType = TPixelType;
433};
434
436
440template <>
442{
443public:
445};
446
447template <>
448class MeasurementVectorPixelTraits<unsigned char>
449{
450public:
452};
453
454template <>
455class MeasurementVectorPixelTraits<signed char>
456{
457public:
458 using MeasurementVectorType = FixedArray<signed char, 1>;
459};
460
461template <>
462class MeasurementVectorPixelTraits<unsigned short>
463{
464public:
465 using MeasurementVectorType = FixedArray<unsigned short, 1>;
466};
467
468template <>
470{
471public:
472 using MeasurementVectorType = FixedArray<short, 1>;
473};
474
475template <>
476class MeasurementVectorPixelTraits<unsigned int>
477{
478public:
479 using MeasurementVectorType = FixedArray<unsigned int, 1>;
480};
481
482template <>
484{
485public:
486 using MeasurementVectorType = FixedArray<int, 1>;
487};
488
489template <>
490class MeasurementVectorPixelTraits<unsigned long>
491{
492public:
493 using MeasurementVectorType = FixedArray<unsigned long, 1>;
494};
495
496template <>
498{
499public:
500 using MeasurementVectorType = FixedArray<long, 1>;
501};
502
503template <>
504class MeasurementVectorPixelTraits<unsigned long long>
505{
506public:
507 using MeasurementVectorType = FixedArray<unsigned long long, 1>;
508};
509
510template <>
511class MeasurementVectorPixelTraits<long long>
512{
513public:
514 using MeasurementVectorType = FixedArray<long long, 1>;
515};
516
517template <>
519{
520public:
521 using MeasurementVectorType = FixedArray<float, 1>;
522};
523
524template <>
526{
527public:
528 using MeasurementVectorType = FixedArray<double, 1>;
529};
530
532
533} // namespace Statistics
534} // namespace itk
535
536#endif // itkMeasurementVectorTraits_h
Array class with size defined at construction time.
Definition itkArray.h:48
SizeValueType Size() const
Definition itkArray.h:131
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")
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType IdentifierType
Definition itkIntTypes.h:90
STL namespace.