MeVisLab Toolbox Reference
mlParameterInfoUtils.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3//------------------------------------------------------------------------------
4
5#pragma once
6
9#include <mlRangeCasts.h>
10#include <FMEThirdPartyWarningsDisable.h>
11#include <QVariant>
12#include <FMEThirdPartyWarningsRestore.h>
13
14
15ML_START_NAMESPACE
16
17namespace parameter_info_utils {
18
19 template < class ValueType >
20 QVariantList ToQVariantList( const TImageVector< ValueType >& vec )
21 {
22 QVariantList result;
23 for (size_t i = 0; i < TImageVector< ValueType >::NumberOfDimensions; ++i )
24 {
25 result << vec[ i ];
26 }
27 return result;
28 }
29
30 template < class ValueType, size_t N, class DC >
32 {
33 QVariantList result;
34 for (size_t i = 0; i < N; ++i )
35 {
36 result << vec[ i ];
37 }
38 return result;
39 }
40
41 /*
42 * Note that QVariant::fromValue() does not work for all types, so need some specializations.
43 * Just using result << v results in other problems, e.g. there not being an non-ambiguous
44 * auto-conversion to QVariant for int64_t on gcc.
45 */
46 template <class ValueType >
47 void AppendToQVariantList( QVariantList& result, const ValueType& v )
48 {
49 QVariant qvar = QVariant::fromValue( v );
50 result << qvar;
51 }
52
53 inline void AppendToQVariantList( QVariantList& result, const char* v )
54 {
55 QString qstr = QString::fromUtf8( v );
56 result << qstr;
57 }
58
59 inline void AppendToQVariantList( QVariantList& result, const std::string& v )
60 {
61 QString qstr = QString::fromStdString( v );
62 result << qstr;
63 }
64
65 template < class Iterable >
66 QVariantList IterableToQVariantList( const Iterable& iterable )
67 {
68 QVariantList result;
69 for ( const auto& v: iterable )
70 {
71 AppendToQVariantList( result, v );
72 }
73 return result;
74 }
75
76 inline QVariantList ToQVariantList( const SubImageBox& box )
77 {
78 QVariantList result;
79 result.insert( 0, ToQVariantList( box.v1) );
80 result.insert( 1, ToQVariantList( box.v2) );
81 return result;
82 }
83
84//--------------------------------------------------------------------------
85 inline QVariantList ToQVariant( const ImageVector& vec )
86 {
87 return ToQVariantList( vec );
88 }
89
90 template < class ValueType, size_t N >
92 {
93 return FloatVectorToQVariantList( vec );
94 }
95
96 template < class ValueType >
97 QVariantList ToQVariant( const std::vector< ValueType >& vec )
98 {
99 return IterableToQVariantList( vec );
100 }
101
102 inline QVariantList ToQVariant( const SubImageBox& box )
103 {
104 return ToQVariantList( box );
105 }
106
107 inline QVariant ToQVariant( const std::string& x ) { return { QString::fromStdString( x ) }; }
108 inline QVariant ToQVariant( const char* x ) { return { x }; }
109
110 inline QVariant ToQVariant( bool x ) { return { x }; }
111 inline QVariant ToQVariant( MLuint8 x ) { return { x }; }
112 inline QVariant ToQVariant( MLint8 x ) { return { x }; }
113 inline QVariant ToQVariant( MLuint16 x ) { return { x }; }
114 inline QVariant ToQVariant( MLint16 x ) { return { x }; }
115 inline QVariant ToQVariant( MLuint32 x ) { return { x }; }
116 inline QVariant ToQVariant( MLint32 x ) { return { x }; }
117 inline QVariant ToQVariant( MLuint64 x ) { return { x }; }
118 inline QVariant ToQVariant( MLint64 x ) { return { x }; }
119 inline QVariant ToQVariant( MLfloat x ) { return { x }; }
120 inline QVariant ToQVariant( MLdouble x ) { return { x }; }
121
122}
123
124ML_END_NAMESPACE
@ N
Template class for vector arithmetic with floating point datatypes.
ImageVector is the 6D TVector specialization used by the ML for all image indexing.
VectorType v1
Corner v1 of the subimage region (included in region).
VectorType v2
Corner v2 of the subimage region (also included in region!).
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition mlTypeDefs.h:424
unsigned int MLuint32
Definition mlTypeDefs.h:184
unsigned char MLuint8
Definition mlTypeDefs.h:108
double MLdouble
Definition mlTypeDefs.h:216
unsigned short MLuint16
Definition mlTypeDefs.h:141
signed short MLint16
Definition mlTypeDefs.h:124
char MLint8
Definition mlTypeDefs.h:96
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
Definition mlTypeDefs.h:411
signed int MLint32
Definition mlTypeDefs.h:160
float MLfloat
Definition mlTypeDefs.h:200
QVariantList ToQVariantList(const TImageVector< ValueType > &vec)
QVariantList FloatVectorToQVariantList(const FloatingPointVector< ValueType, N, DC > &vec)
QVariantList IterableToQVariantList(const Iterable &iterable)
void AppendToQVariantList(QVariantList &result, const ValueType &v)
QVariantList ToQVariant(const ImageVector &vec)