13 #ifndef ML_STD_TYPE_INFOS_H
14 #define ML_STD_TYPE_INFOS_H
38 template <
typename VTYP>
47 static inline const char *
typeName(
MLuint8 *) {
static const char name[]=
"unsigned int8";
return name; }
99 static const char *v[] =
113 static const char *v[] =
130 static const char *v[] =
143 static const char *v[] =
158 static const char *v[] =
170 static const char *v[] =
183 static const char *v[] =
199 static const char *v[] =
210 static const char *v[] =
233 if (_numInstances > 0)
247 MLuint numLocalGoodCastTos=0;
248 const char **goodLocalCastTos=
nullptr;
249 _getGoodCastTos(
static_cast<VTYP
>(0), numLocalGoodCastTos, goodLocalCastTos);
315 typeName(
static_cast<VTYP*
>(
nullptr)),
318 reinterpret_cast<const MLTypeData*
>(&_typeMin),
319 reinterpret_cast<const MLTypeData*
>(&_typeMax),
320 reinterpret_cast<const MLTypeData*
>(&_typeDefault),
324 _rangeAndPrecisionEquiv(
static_cast<VTYP
>(0)),
367 for (
size_t i=0;i<size;i++)
369 value_cast(dest) = value_cast(
source);
370 source +=
sizeof(VTYP)*sourceStride;
371 dest +=
sizeof(VTYP)*destStride;
378 const VTYP value = value_cast(fillValue);
379 VTYP* arrayPtr = &value_cast(dest);
384 memset(arrayPtr, value, n*
sizeof(VTYP) );
387 for (
size_t i = 0; i < n; i++) {
425 const VTYP* srcPtr = &value_cast(
source);
426 VTYP* destPtr = &value_cast(dest);
427 const VTYP offsetValue = value_cast(offset);
428 for (
size_t i = 0; i<size; i++) {
429 *destPtr++ = castToType((*srcPtr++) * factor + offsetValue);
437 const VTYP constValue = value_cast(value);
438 const VTYP* arrayPtr = &value_cast(buffer);
439 for (
size_t i=0; i<size; i++) {
440 if (*arrayPtr++ != constValue) {
return false; }
450 const auto *begin =
reinterpret_cast<const VTYP *
>(p);
451 auto min_max = std::minmax_element(begin, begin + s);
452 min =
static_cast<double>(*min_max.first);
453 max =
static_cast<double>(*min_max.second);
461 value_cast(t) = castToType(value_cast(p) * (1.0-r) + value_cast(q) * r);
Template class to register the standard integer classes as voxel types in the ML.
static void MLTYPE_multWithOtherType(const MLTypeInfos *otherInfos, const MLTypeData *otherData, const MLTypeData *myData, MLTypeData *r)
Implements multiplication with another type. Result is written into parameter three.
static void MLTYPE_castToOtherType(const MLTypeData *myData, const MLTypeInfos *otherInfos, MLTypeData *otherData)
Returns the parameter cast to double. Usually implemented by default with function casting component-...
MLDataType _rangeAndPrecisionEquiv(MLuint32)
static VTYP castToType(MLdouble v)
Implements a method that rounds a double value when casting to an integer but does not round when cas...
static void MLTYPE_arrayGetMinMax(const MLTypeData *p, size_t s, MLdouble &min, MLdouble &max)
Gets the mininum and maximum component values from the array in the first argument,...
static bool MLTYPE_arrayEqualsValue(const MLTypeData *value, const MLTypeData *buffer, size_t size)
Checks that the first argument equals all the values given with the second argument (and the size in ...
MLDataType _rangeAndPrecisionEquiv(MLuint64)
void _getGoodCastTos(MLfloat, MLuint &num, const char **&typeNames)
void _getGoodCastTos(MLuint32, MLuint &num, const char **&typeNames)
void _getGoodCastTos(MLuint64, MLuint &num, const char **&typeNames)
static void MLTYPE_plusInt(const MLTypeData *p, MLint q, MLTypeData *r)
Implements integer addition to parameter one. Result is written into parameter three.
MLDataType _rangeAndPrecisionEquiv(MLdouble)
MLDataType _rangeAndPrecisionEquiv(MLuint16)
static void MLTYPE_multWithInt(const MLTypeData *p, MLint q, MLTypeData *r)
Implements multiplication with integer. Result is written into parameter three.
MLDataType _rangeAndPrecisionEquiv(MLint32)
static const char * typeName(MLfloat *)
static bool MLTYPE_isEqualToType(const MLTypeData *p, const MLTypeData *q)
Returns true if both parameters are equal; otherwise, it returns false.
static void MLTYPE_multWithType(const MLTypeData *p, const MLTypeData *q, MLTypeData *r)
Implements multiplication with its own type. Result is written into parameter three.
static void MLTYPE_multWithDouble(const MLTypeData *p, MLdouble q, MLTypeData *r)
Implements multiplication with double. Result is written into parameter three.
static void MLTYPE_setToMinimum(MLTypeData *p)
Sets value to minimum value. Must be implemented.
static const char * typeName(MLdouble *)
static void MLTYPE_copy(const MLTypeData *source, MLTypeData *dest)
Copies first parameter to second one.
static const char * typeName(MLuint8 *)
static void MLTYPE_setComponent(MLTypeData *p, size_t, MLdouble v)
Sets n-th component from double value. Must be implemented.
static const char * typeName(MLint8 *)
static const char * typeName(MLint32 *)
void _getGoodCastTos(MLint32, MLuint &num, const char **&typeNames)
static const VTYP _typeMax
Permanent instance of the maximum value.
static const char * typeName(MLuint32 *)
static bool MLTYPE_isEqualToTypeWithEpsilon(const MLTypeData *p, const MLTypeData *q, MLdouble eps)
Returns true if both parameters are equal within a static epsilon; otherwise, it returns false.
static MLTypeInfos * _myInfos
Permanent instance of a pointer to the typeInfos used by this class.
void _getGoodCastTos(MLuint8, MLuint &num, const char **&typeNames)
static void MLTYPE_arrayRescale(const MLTypeData *source, MLdouble factor, const MLTypeData *offset, MLTypeData *dest, size_t size)
Scales the values from the first parameter with the second parameter and offsets it with the value fr...
static const VTYP _typeMin
Permanent instance of the minimum value.
static void MLTYPE_setStringValue(const char *s, MLTypeData *r)
Converts the string s to a value and writes result into r. Use MLTypeComponentsFromString() if possib...
MLDataType _rangeAndPrecisionEquiv(MLfloat)
static VTYP & value_cast(MLTypeData *v)
Avoid using reinterpret_casts.
MLDataType _rangeAndPrecisionEquiv(MLuint8)
static MLdouble MLTYPE_getComponent(const MLTypeData *p, size_t)
Returns n-th component as double value. Must be implemented.
void _getGoodCastTos(MLdouble, MLuint &num, const char **&typeNames)
static bool MLTYPE_castToBool(const MLTypeData *p)
Returns the parameter cast to bool. Typically, it returns false if it is identically to the default e...
static void MLTYPE_setToDefault(MLTypeData *p)
Sets value to default value. Must be implemented.
static void MLTYPE_interpolate(const MLTypeData *p, const MLTypeData *q, MLdouble r, MLTypeData *t)
Interpolates linearly between the first and the second parameter, at the position given by the third ...
static char * MLTYPE_getStringValue(const MLTypeData *p)
Returns the value as string to be freed by MLFree(). Use MLTypeComponentsToString() if possible.
static void MLTYPE_castFromOtherType(const MLTypeInfos *otherInfos, const MLTypeData *otherData, MLTypeData *myData)
Casts the first parameters to data type and writes it into the second parameter.
static MLint32 _numInstances
The number of instances of this class.
static const VTYP & value_cast(const MLTypeData *v)
static void MLTYPE_negate(const MLTypeData *p, MLTypeData *q)
Negates the value. See also the specialized negations for unsigned types that leave the value unchang...
void _getGoodCastTos(MLint64, MLuint &num, const char **&typeNames)
static MLint MLTYPE_castToInt(const MLTypeData *p)
Returns the parameter cast to integer. Often the integer cast of the first component.
static void MLTYPE_castFromDouble(MLdouble p, MLTypeData *q)
Casts the first parameters to data type and writes it into the second parameter.
static const char * typeName(MLuint16 *)
static void MLTYPE_plusType(const MLTypeData *p, const MLTypeData *q, MLTypeData *r)
Implements parameter two addition to parameter one. Result is written into parameter three.
void _getGoodCastTos(MLuint16, MLuint &num, const char **&typeNames)
static void MLTYPE_arrayCopy(const MLTypeData *source, MLTypeData *dest, size_t size)
Copies s elements from the first parameter to the second one.
static void MLTYPE_castFromInt(MLint p, MLTypeData *q)
Casts the first parameters to data type and writes it into the second parameter.
static const VTYP _typeDefault
Permanent instance of the default value.
static void MLTYPE_plusDouble(const MLTypeData *p, MLdouble q, MLTypeData *r)
Implements double addition to parameter one. Result is written into parameter three.
static const char * typeName(MLuint64 *)
static void MLTYPE_arrayFill(const MLTypeData *fillValue, MLTypeData *dest, size_t n)
Copies the first parameter to the second one as often as given in the third parameter.
MLTStdTypeInfos()
Constructor.
MLDataType _rangeAndPrecisionEquiv(MLint64)
void _getGoodCastTos(MLint16, MLuint &num, const char **&typeNames)
static void MLTYPE_normalize(const MLTypeData *, MLTypeData *q)
Normalizes the type.
static void MLTYPE_setToMaximum(MLTypeData *p)
Sets value to minimum value. Must be implemented.
static const char * typeName(MLint64 *)
static void MLTYPE_arrayCopyWithStrides(const MLTypeData *source, MLssize_t sourceStride, MLTypeData *dest, MLssize_t destStride, size_t size)
Same as MLTYPE_arrayCopy, but allows to specify stride values for source and destination.
void _getGoodCastTos(MLint8, MLuint &num, const char **&typeNames)
static MLdouble MLTYPE_castToDouble(const MLTypeData *p)
Returns the parameter cast to double. Often the integer cast of the first component.
MLDataType _rangeAndPrecisionEquiv(MLint8)
static const char * typeName(MLint16 *)
MLDataType _rangeAndPrecisionEquiv(MLint16)
MLint32 MLDataType
MLDataType.
DT MLAbs(const DT val)
Defines a templated MLAbs version to circumvent fabs ambiguities on different platforms.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ; otherwise, it returns false.
bool MLValuesAreEqualWOM(MLint8 a, MLint8 b)
Returns true if values a and b are equal; otherwise, it returns false.
@ MLuint8Type
Enumerator for the unsigned 8-bit ML integer type.
@ MLuint32Type
Enumerator for the unsigned 32-bit ML integer type.
@ MLfloatType
Enumerator for the signed 32-bit ML floating point type.
@ MLuint16Type
Enumerator for the unsigned 16-bit ML integer type.
@ MLint64Type
Enumerator for the signed 64-bit ML integer type.
@ MLint16Type
Enumerator for the signed 16-bit ML integer type.
@ MLint32Type
Enumerator for the signed 32-bit ML integer type.
@ MLdoubleType
Enumerator for the signed 64-bit ML floating point type.
@ MLint8Type
Enumerator for the signed 8-bit ML integer type.
@ MLuint64Type
Enumerator for the unsigned 64-bit ML integer type.
#define ML_PROGRAMMING_ERROR
A case occurred that should not appear and there are a variety of reasons, typically it is a programm...
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_FATAL_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be du...
MLEXPORT MLint32 MLTypeComponentsFromString(const MLTypeInfos *infos, const char *stringData, const MLTypeData *defaultValue, MLTypeData *data)
Converts a string of a data type instance to instance data, i.e., similar to sscanf.
MLEXPORT void MLTypeMultWithOtherType(const MLTypeInfos *myInfos, const MLTypeData *myData, const MLTypeInfos *otherInfos, const MLTypeData *otherData, MLTypeData *targetData)
Casts another data element otherData with attributes given by otherInfos to a local buffer of a type ...
MLEXPORT void MLTypeCastToOtherType(const MLTypeInfos *otherInfos, const MLTypeData *otherData, const MLTypeInfos *myInfos, MLTypeData *myData)
Converts a data instance referenced by otherData of a type specified by otherInfos to another data in...
MLEXPORT char * MLTypeComponentsToString(const MLTypeInfos *infos, const MLTypeData *data)
Converts a data type instance to a string.
MLEXPORT MLint32 MLTypeInfosInit(MLTypeInfos *infos, size_t typeSize, const char *name, MLdouble dblMin, MLdouble dblMax, const MLTypeData *typeMinPtr, const MLTypeData *typeMaxPtr, const MLTypeData *typeDefaultPtr, const char *typeStructInfo, MLint32 isScalarType, MLTypeGroup typeGroup, MLDataType rangeAndPrecisionEquiv, void **componentAddresses, size_t numGoodCastTos, const char **goodCastTos)
Initialization of the main properties of MLTypeInfos.
#define ML_HARAKIRI
This logs the fatal error with file and line number.
#define MLEXPORT
To export symbols from a DLL/shared object, we need to mark them with the MLEXPORT symbol.
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
#define ML_TYPE_ASSIGN_FUNCTION_POINTERS()
MLuint64 MLuint
An unsigned ML integer type with at least 64 bits used for index calculations on very large images ev...
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
boost::graph_traits< ml_graph_ptr >::vertex_descriptor source(graph_traits< ml_graph_ptr >::edge_descriptor e, const ml_graph_ptr)
Returns the vertex descriptor for u of the edge (u,v) represented by e.
void ML_UTILS_EXPORT logTypeComponentsFromStringError(const char *function)
const MLint _ML_STD_SLEN
Length of strings for component descriptions and class names.
Structure containing all data type features and pointers to all functions needed to implement operati...
const char * name
Pointer to the data type name.
TypeTraits for scalar ML datatypes.