/***************************************************************************/
/*

    Filename:  MilReg.h
    Owner   :  Matrox Imaging
    Revision:  10.60.0776
    Content :  This file contains the defines and the prototypes for the
               MIL Registration module. (Mreg...).

    Copyright © Matrox Electronic Systems Ltd., 1992-2023.
    All Rights Reserved

*/
/***************************************************************************/

#ifndef __MILREG_H__
#define __MILREG_H__

#if (!M_MIL_LITE) // MIL FULL ONLY

/* C++ directive if needed */
#ifdef __cplusplus
extern "C"
{
#endif

/***************************************************************************/
/*                      MilReg CAPI defines                                */
/***************************************************************************/

/***************************************************************************/
/* Index values                                                            */
/***************************************************************************/
#define M_DEFAULT                               0x10000000L // Also defined in mil.h
#define M_CONTEXT                               0x08000000L
#define M_ALL                                   0x40000000L // Also defined in Milmod.h
#define M_GENERAL                               0x20000000L // Also defined in Milmod.h

/***************************************************************************/
/* MregAlloc()                                                             */
/***************************************************************************/

/* Registration types */
#define M_INVALID_REGISTRATION_TYPE                       0L
#define M_CORRELATION                                     1L
#define M_STITCHING                                       M_CORRELATION
#define M_EXTENDED_DEPTH_OF_FIELD                         2L
#define M_DEPTH_FROM_FOCUS                                3L
#define M_PHOTOMETRIC_STEREO                              4L
#define M_HIGH_DYNAMIC_RANGE                              5L

#define IS_REGISTRATION_TYPE(RegType) (   RegType == M_STITCHING || \
                                          RegType == M_EXTENDED_DEPTH_OF_FIELD || \
                                          RegType == M_DEPTH_FROM_FOCUS || \
                                          RegType == M_PHOTOMETRIC_STEREO || \
                                          RegType == M_HIGH_DYNAMIC_RANGE )

/***************************************************************************/
/* MregAllocResult()                                                       */
/***************************************************************************/

/* Registration result types */
#define M_STITCHING_RESULT                               1L
#define M_EXTENDED_DEPTH_OF_FIELD_RESULT                 2L
#define M_DEPTH_FROM_FOCUS_RESULT                        3L
#define M_PHOTOMETRIC_STEREO_RESULT                      4L
#define M_HIGH_DYNAMIC_RANGE_RESULT                      5L

#define IS_REGISTRATION_RESULT_TYPE(RegType) (  RegType == M_STITCHING_RESULT || \
                                                RegType == M_EXTENDED_DEPTH_OF_FIELD_RESULT || \
                                                RegType == M_DEPTH_FROM_FOCUS_RESULT || \
                                                RegType == M_PHOTOMETRIC_STEREO_RESULT || \
                                                RegType == M_HIGH_DYNAMIC_RANGE_RESULT )

#define M_HIGH_DYNAMIC_RANGE_WORKSPACE                   0x00000010L
#define M_PHOTOMETRIC_STEREO_CALIBRATED_WORKSPACE        0x00000021L
#define M_PHOTOMETRIC_STEREO_UNCALIBRATED_WORKSPACE      0x00000022L

/***************************************************************************/
/* MregControl() and MregInquire()                                         */
/***************************************************************************/

/* ControlType and InquireType for correlation context */
#define M_REGISTRATION_TYPE                 1L
#define M_OWNER_SYSTEM                      1101L      /* already defined in mil.h */

#define M_NUMBER_OF_REGISTRATION_ELEMENTS   2L
#if OldDefinesSupport
#define M_NUMBER_OF_ELEMENTS                2L
   MIL_DEPRECATED(M_NUMBER_OF_ELEMENTS, 1030)
#endif
#define M_TRANSFORMATION_TYPE               3L
#define M_MIN_OVERLAP                       4L
#define M_MOSAIC_STATIC_INDEX               5L
#define M_MOSAIC_OFFSET_X                   6L
#define M_MOSAIC_OFFSET_Y                   7L
#define M_MOSAIC_COMPOSITION                8L
#define M_SR_PSF_TYPE                      10L
#define M_SR_PSF_RADIUS                    11L
#define M_SR_CONDITIONING_TYPE             12L
#define M_SR_SMOOTHNESS                    13L
#define M_SR_FLOAT_MODE                    14L
#define M_SR_FIXED_POINT                   15L
#define M_DELETE_ELEMENT                   16L
#define M_PAIRING_MODE                     17L
#define M_MAX_INTERMEDIATES                18L
#define M_MOSAIC_SCALE                     19L
#define M_SR_MAX_ITER                      20L
#define M_STITCHING_LAST_LEVEL          10021L
// skip 21L, reserved for M_FAILURE_MESSAGE
#define M_SR_COMMUTE_BLUR_AND_WARP         22L
#define M_SCORE_TYPE                       37L  // already defined in milpat.h
/* ControlType and InquireType for fusion context */
#define M_CIRCLE_OF_CONFUSION_RADIUS_MAX 1906L
#define M_TRANSLATION_TOLERANCE          1907L
#define M_MODE                            103L // already defined in milim.h
/* ControlType and InquireType for depth from focus context */
#define M_REGULARIZATION_MODE            2020L
#define M_REGULARIZATION_SIZE            2021L 
#define M_ADAPTIVE_SMOOTHING             2022L 
#define M_ADAPTIVE_INTENSITY_DELTA       2023L 
#define M_INTENSITY_MAP                  2030L 
#define M_FOCUS_DEPTH_SIZE               2193L 
#define M_CONFIDENCE_MAP                 2195L 

/* ControlType and InquireType for photometric stereo context */
#define M_DRAW_WITH_NO_RESULT            2683L
#define M_GAUSSIAN_CURVATURE             2691L
#define M_MEAN_CURVATURE                 2692L
#define M_LIGHT_VECTOR_TYPE              2694L
#define M_LIGHT_VECTOR_COMPONENT_1       2695L
#define M_LIGHT_VECTOR_COMPONENT_2       2696L
#define M_LIGHT_VECTOR_COMPONENT_3       2697L
#define M_LOCAL_SHAPE                    2698L  // TBC!!!
#define M_LOCAL_CONTRAST                 2699L  // TBC!!!
#define M_TEXTURE_IMAGE                  2700L  // TBC!!!
#define M_MIN_IMAGE                      2701L  // TBC!!!
#define M_MAX_IMAGE                      2702L  // TBC!!!
#define M_SHAPE_NORMALIZATION            2703L  // TBC!!!
#define M_SHAPE_MASK                     2704L  // TBC!!!
#define M_SHAPE_SMOOTHNESS               2705L  // TBC!!!
#define M_NON_UNIFORMITY_CORRECTION      2706L  // TBC!!!
#define M_OBJECT_SIZE                    2707L  // TBC!!!

#define M_IMPROVED_LOCAL_SHAPE           5272L

#define M_TONE_MAPPING_MODE              2800L
#define M_TONE_MAPPING_COEFFICIENT       2801L
#define M_TONE_MAPPING_LOW_THRESHOLD     2802L
#define M_TONE_MAPPING_HIGH_THRESHOLD    2803L
#define M_FUSION_MODE                    2804L
#define M_FUSION_LOW_THRESHOLD           2805L
#define M_FUSION_HIGH_THRESHOLD          2806L
#define M_FUSION_COVERAGE                2807L
#define M_IMAGE_GAIN                     5260L
#define M_GAIN_MODE                      5261L

#define M_DRAW_REMAP_FACTOR_MODE         3353 
#define M_DRAW_REMAP_FACTOR_VALUE        3354 

#define M_RANGE_FACTOR_GAUSSIAN_CURVATURE    3362	
#define M_RANGE_FACTOR_MEAN_CURVATURE        3363	
#define M_RANGE_FACTOR_LOCAL_SHAPE           3364

#define M_STOP_CALCULATE                  116L // also in milblob.h

/* ControlValue for M_LIGHT_VECTOR_TYPE in photometric stereo context */
#define M_SPHERICAL                      2716L 
#define M_CARTESIAN                      2717L

/* ControlType and InquireType for context element */
#define M_OPTIMIZE_LOCATION              1002L
#define M_LOCATION_DELTA                 1003L
#define M_ACCURACY                        106L  // already defined in    milmod.h, miledge.h, milpat.h
#define M_REFERENCE_X                     100L  // already defined in    milmod.h, milpat.h
#define M_REFERENCE_Y                     101L  // already defined in    milmod.h, milpat.h
#define M_OPTICAL_CENTER_X               1007L
#define M_OPTICAL_CENTER_Y               1008L
#define M_FOCAL_LENGTH                   1009L
#define M_MASK_IMAGE                     1020L
#define M_EXTRACT_MODELS                 1021L
#define M_ACCEPTANCE_LEVEL               1022L

#define M_SET_LOCATION_TARGET            1010L
#define M_SET_LOCATION_PARAM_TYPE        1011L
#define M_SET_LOCATION_PARAM_1           1012L
#define M_SET_LOCATION_PARAM_2           1013L
#define M_SET_LOCATION_PARAM_3           1014L
#define M_SET_LOCATION_PARAM_4           1015L

#define M_SET_LOCATION_PARAM_DATA_1      1016L

/* ControlType and InquireType for result */
#define M_DRAW_CROSS_SIZE                              115L // also defined in miledge.h
#if OldDefinesSupport
   #define M_DRAW_RELATIVE_ORIGIN_X       319L // deprecated : Use MgraControl(... M_DRAW_OFFSET_X...)
   #define M_DRAW_RELATIVE_ORIGIN_Y       320L // deprecated : Use MgraControl(... M_DRAW_OFFSET_Y...)
   #define M_DRAW_SCALE_X                3203L // deprecated : Use MgraControl(... M_DRAW_ZOOM_X ...)
   #define M_DRAW_SCALE_Y                3204L // deprecated : Use MgraControl(... M_DRAW_ZOOM_Y ...)
//    MIL_DEPRECATED(M_DRAW_RELATIVE_ORIGIN_X, 1010)           Already defined in mil.h
//    MIL_DEPRECATED(M_DRAW_RELATIVE_ORIGIN_Y, 1010)           Already defined in mil.h
//    MIL_DEPRECATED(M_DRAW_SCALE_X, 1010)                     Already defined in mil.h
//    MIL_DEPRECATED(M_DRAW_SCALE_Y, 1010)                     Already defined in mil.h
#endif

/* InquireType modifiers */
#define M_DEFAULT                               0x10000000L // already defined in mil.h

/* Index */
#define M_ALL                                   0x40000000L // already defined in mil.h

/* Basic ControlValue  */
#define M_DEFAULT                               0x10000000L // already defined in mil.h
#define M_ENABLE                                     -9997L // already defined in mil.h
#define M_DISABLE                                    -9999L // already defined in mil.h
#define M_INFINITE                              -1L // Also defined in Mil.h

/* ControlValue for M_TRANSFORMATION_TYPE */
#define M_TRANSLATION                                    1L // also in milcal.h
#define M_TRANSLATION_ROTATION                           2L // also in milcal.h
#define M_TRANSLATION_ROTATION_SCALE                     3L // also in milcal.h
#define M_AZIM_ELEV_ROLL                                 4L
#define M_PERSPECTIVE                                    5L

/* ControlValue for M_ACCURACY */
#define M_LOW                                            1L          // Already defined in    miledge.h, milcode.h, milmod.h, milocr, milpat.h, mil.h
#define M_HIGH                                           3L          // Already defined in    miledge.h, milcode.h, milmod.h, milocr, milpat.h, mil.h
#define M_VERY_HIGH                                      4L          // Already defined in    miledge.h, milcode.h, milmod.h, milocr, milpat.h

/* ControlValue for M_REFERENCE_X, M_REFERENCE_Y, M_OPTICAL_CENTER_X, M_OPTICAL_CENTER_Y */
#define M_CENTER_ELEMENT                        0x40000000L

/* ControlValue for M_OPTICAL_CENTER_X, M_OPTICAL_CENTER_Y */
#define M_CENTER_OBJECT                         0x10000000L 

/* ControlValue for M_MOSAIC_STATIC_INDEX */
#define M_REGISTRATION_GLOBAL                   0x02000000L
#define M_ALL                                   0x40000000L // already defined in mil.h

/* ControlValue for M_MOSAIC_OFFSET_X */
#define M_ALIGN_LEFT                            0x40000010L

/* ControlValue for M_MOSAIC_OFFSET_Y */
#define M_ALIGN_TOP                             0x40000011L


/* ControlValue for M_MOSAIC_COMPOSITION */
#define M_SUPER_RESOLUTION                               1L
#define M_FIRST_IMAGE                                    2L
#define M_LAST_IMAGE                                     3L
#define M_AVERAGE_IMAGE                                  4L
#define M_FUSION_IMAGE                                   5L

/* ControlValue for M_SR_PSF_TYPE */
#define M_CIRCULAR                                       1L
#define M_GAUSSIAN                                   0x805L // also defined in miledge.h
/*#define M_SMOOTH */                                         // also defined in miledge.h

/* ControlValue for M_SR_CONDITIONING_TYPE */
/*#define M_SMOOTH */                                         // also defined in miledge.h

/* ControlValue for M_PAIRING_MODE */
#define M_USE_SET_LOCATION_TARGET                        1L
#define M_USE_MAX_INTERMEDIATES                          2L

/* ControlValue for M_MODE */
#define M_FAST                                  0x00002000L // already defined in milim.h
#define M_RECONSTRUCTION                              1908L

/* ControlValue for M_FOCUS_MEASURE */

/* ControlValue for M_REGULARIZATION_MODE */
#define M_DISABLE                                    -9999L // already defined in mil.h
#define M_AVERAGE                               0x00000020L // already defined in milim.h
#define M_ADAPTIVE                                    2048L // already defined in mil.h

/* ControlValue for M_INTENSITY_MAP */
#define M_ENABLE                                     -9997L // already defined in mil.h
#define M_DISABLE                                    -9999L // already defined in mil.h


/***************************************************************************/
/* MregSetLocation()                                                       */
/***************************************************************************/

/* Index */
#define M_ALL                                   0x40000000L // already defined in mil.h

/* Target */
#define M_REGISTRATION_GLOBAL                   0x02000000L
#define M_PREVIOUS                              0x40000003L
#define M_NEXT                                  0x40000004L
#define M_UNCHANGED                             0x40000005L
#define M_COPY                                  0x00020000L // already defined in mil.h

/* ParamType */
#define M_POSITION_XY                                    1L
#define M_POSITION_XY_ANGLE                              2L
#define M_POSITION_XY_ANGLE_SCALE                        3L
#define M_WARP_POLYNOMIAL                       0x00200000L // already defined in milim.h
#define M_WARP_4_CORNER                         0x00800000L // already defined in mil.h
#define M_WARP_4_CORNER_REVERSE                 0x01000000L // already defined in mil.h
#define M_TIE_POINT_LIST                                 4L
#define M_COPY_REG_CONTEXT                      0x40000001L
#define M_COPY_REG_RESULT                       0x40000002L



/***************************************************************************/
/* MregGetResult()                                                         */
/***************************************************************************/

/* ResultIndex */
#define M_ALL                                   0x40000000L // already defined in mil.h
#define M_GENERAL                               0x20000000L // also defined in milmod.h

/* ResultType */
#define M_RESULT                                0x00001000L // also used by milmeas.h and milmod.h
#define M_SCORE                                 0x00001400L // also defined in MilPat.h and milmod.h
#define M_FAILURE_CODE                                  20L
#define M_FAILURE_MESSAGE                               21L
#define M_FAILURE_MESSAGE_LENGTH                        22L
#define M_MOSAIC_SIZE_X                                  9L
#define M_MOSAIC_SIZE_Y                                 10L
#define M_MOSAIC_OFFSET_X                                6L // also a ControlType
#define M_MOSAIC_OFFSET_Y                                7L // also a ControlType
#define M_NUMBER_OF_IMAGES                            6003L // already defined in mil.h
#define M_IMAGE_SIZE_X                             M_SIZE_X // Already defined in milcode.h, mil.h   
#define M_IMAGE_SIZE_Y                             M_SIZE_Y // Already defined in milcode.h, mil.h
#define M_IMAGE_SIZE_BAND                             1911L
#define M_IMAGE_TYPE                                     1L // Already defined in milblob.h  
#define M_STATUS                                0x00008002L // Already defined in milcode.h
#define M_HDR_IMAGE_STATUS                            2000L
#define M_HDR_IMAGE_STATUS_SIZE                       2001L
#define M_HDR_STATUS                                  2002L
#define M_MAX_INDEX_VALUE                             2197L
#if OldDefinesSupport
#define M_EDOF_IMAGE_SIZE_X                           1909L
#define M_EDOF_IMAGE_SIZE_Y                           1910L
#define M_EDOF_IMAGE_SIZE_BAND                        1911L
#define M_EDOF_IMAGE_TYPE                             1912L
#define M_EDOF_STATUS                                 1914L
MIL_DEPRECATED(M_EDOF_IMAGE_SIZE_X   , 1020)
MIL_DEPRECATED(M_EDOF_IMAGE_SIZE_Y   , 1020)
MIL_DEPRECATED(M_EDOF_IMAGE_SIZE_BAND, 1020)
MIL_DEPRECATED(M_EDOF_IMAGE_TYPE     , 1020)
MIL_DEPRECATED(M_EDOF_STATUS         , 1020)
#endif
#define M_AVAILABLE             MAKE_INT64(0x0000400000000000) // Also defined in mil.h

                                                            // These results should not clash when added with M_GLOBAL
#define M_ANGLE                                 0x00000800L // already defined in mil.h
#define M_POSITION_X                            0x00003400L // also defined in milpat.h
#define M_POSITION_Y                            0x00004400L // also defined in milpat.h
#define M_SCALE                                 0x00008010L // also defined in milpat.h
#define M_TRANSFORMED_UL_X                              23L
#define M_TRANSFORMED_UL_Y                              24L
#define M_TRANSFORMED_UR_X                              25L
#define M_TRANSFORMED_UR_Y                              26L
#define M_TRANSFORMED_BL_X                              27L
#define M_TRANSFORMED_BL_Y                              28L
#define M_TRANSFORMED_BR_X                              29L
#define M_TRANSFORMED_BR_Y                              30L
#define M_ELEVATION                                     49L
#define M_AZIMUTH                                       50L
#define M_ROLL                                          51L
#define M_TRANSFORMATION_MATRIX_ID                      52L
#define M_REVERSE_TRANSFORMATION_MATRIX_ID              53L
#define M_EXPOSURE_GAIN                                 70L
#define M_EXPOSURE_OFFSET                               71L
#define M_TRANSFORMATION_MATRIX                         72L
#define M_REVERSE_TRANSFORMATION_MATRIX                 73L
#define M_PAIR_PARTNER_NUMBER                           74L
#define M_PAIR_PARTNER                                  75L

#define M_GLOBAL                                0x00000008L // already defined in mil.h, milmeas.h

/* ResultType modifiers */
#define M_DEFAULT                               0x10000000L // already defined in mil.h
#define M_REGISTRATION_GLOBAL                   0x02000000L
#define M_REFERENCE                             0x04000000L

#define M_REG_OBJECT                            (M_USER_ATTRIBUTE       | MAKE_INT64(0x0000000800000000))
#define M_REG_STITCHING_CONTEXT                 (M_REG_OBJECT           | 0x00000001L )
#define M_REG_EDOF_CONTEXT                      (M_REG_OBJECT           | 0x00000004L )
#define M_REG_STITCHING_RESULT                  (M_REG_OBJECT           | 0x00000002L )
#define M_REG_EDOF_RESULT                       (M_REG_OBJECT           | 0x00000008L )
#define M_REG_DFF_CONTEXT                       (M_REG_OBJECT           | 0x00000010L )
#define M_REG_DFF_RESULT                        (M_REG_OBJECT           | 0x00000020L )
#define M_REG_PHOTOMETRIC_STEREO_CONTEXT        (M_REG_OBJECT           | 0x00000040L )
#define M_REG_PHOTOMETRIC_STEREO_RESULT         (M_REG_OBJECT           | 0x00000080L )
#define M_REG_HDR_CONTEXT                       (M_REG_OBJECT           | 0x00000100L )
#define M_REG_HDR_RESULT                        (M_REG_OBJECT           | 0x00000200L )
#if OldDefinesSupport
   #define M_REG_CONTEXT                         M_REG_STITCHING_CONTEXT
   #define M_REG_RESULT                          M_REG_STITCHING_RESULT
   MIL_DEPRECATED(M_REG_CONTEXT, 1010)
   MIL_DEPRECATED(M_REG_RESULT , 1010)
#endif

#define M_REG_CONTEXT_MASK ( M_REG_STITCHING_CONTEXT | \
                           M_REG_EDOF_CONTEXT | \
                           M_REG_DFF_CONTEXT | \
                           M_REG_PHOTOMETRIC_STEREO_CONTEXT | \
                           M_REG_HDR_CONTEXT  )
#define M_REG_RESULT_MASK (  M_REG_STITCHING_RESULT | \
                           M_REG_EDOF_RESULT | \
                           M_REG_DFF_RESULT | \
                           M_REG_PHOTOMETRIC_STEREO_RESULT | \
                           M_REG_HDR_RESULT )
#define M_REG_OBJECT_MASK (  M_REG_CONTEXT_MASK | \
                             M_REG_RESULT_MASK )
#define IS_REG_CONTEXT(type) (   type == M_REG_STITCHING_CONTEXT || \
                                 type == M_REG_EDOF_CONTEXT || \
                                 type == M_REG_DFF_CONTEXT || \
                                 type == M_REG_PHOTOMETRIC_STEREO_CONTEXT || \
                                 type == M_REG_HDR_CONTEXT )
#define IS_REG_RESULT(type) (    type == M_REG_STITCHING_RESULT || \
                                 type == M_REG_EDOF_RESULT || \
                                 type == M_REG_DFF_RESULT || \
                                 type == M_REG_PHOTOMETRIC_STEREO_RESULT || \
                                 type == M_REG_HDR_RESULT )
#define IS_REG_OBJECT(type) (    IS_REG_CONTEXT(type) || \
                                 IS_REG_RESULT(type) )
/* Result values */
#define M_SUCCESS                               0x00000000L
#define M_FAILURE                               0x00000001L

#define M_FAILURE_BAD_TRANSFORM_PARAM           1L
#define M_FAILURE_TOO_MANY_ELEMENTS             2L
#define M_FAILURE_NOT_FOUND                     3L
#define M_FAILURE_HINT_MATH_EXCEPTION           4L
#define M_FAILURE_CALCULATE_MATH_EXCEPTION      5L
#define M_FAILURE_IMAGE_TOO_SMALL               6L
#define M_FAILURE_IMAGE_NO_INFO                 7L
#define M_FAILURE_NO_CONVERGENCE                8L

#define M_EMPTY                                236L // also in milmod.h, mildmr.h
#define M_CURRENTLY_CALCULATING               2718L 
#define M_TIMEOUT_REACHED                     2554L // also in milmod.h, mildmr.h
#define M_STOPPED_BY_REQUEST                  2555L // also in milmod.h, mildmr.h
#define M_NOT_ENOUGH_MEMORY                      4L // also in mil.h, mil3dmap.h, mildmr.h
#define M_COMPLETE                      0x00000000L // also in mil.h, milmod.h, mildmr.h
#define M_INTERNAL_ERROR                         5L // also in milcal.h, mildmr.h

//Status values for HDR processing
#define M_HDR_SUCCESSFUL                         0L
#define M_HDR_SUCCESSFULL                        M_HDR_SUCCESSFUL
#define M_HDR_INSUFFICIENT_CONTRAST              1L
#define M_HDR_INSUFFICIENT_CONTRIBUTION          3L
#define M_HDR_MERGE_AREA_SIZE_INSUFFICIENT       4L
#define M_HDR_MERGE_AREA_GAIN_INCORRECT          5L
#define M_HDR_IMAGE_LIMITED_TO_SINGLE_COLOR      6L

/***************************************************************************/
/* MregCalculate()                                                         */
/***************************************************************************/
/* Operation */
#define M_ACCUMULATE                                 0x200L // already defined in milcal.h
#define M_COMPUTE                                        1L
#define M_ACCUMULATE_AND_COMPUTE  (M_ACCUMULATE + M_COMPUTE)
#if OldDefinesSupport
   #define M_FUSION                               M_COMPUTE
   #define M_ACCUMULATE_AND_FUSION                M_ACCUMULATE_AND_COMPUTE
   #define M_HDR_INSUFFICIENT_COLOR_DEPTH         M_HDR_INSUFFICIENT_CONTRAST
   MIL_DEPRECATED(M_FUSION                      , 1020)
   MIL_DEPRECATED(M_ACCUMULATE_AND_FUSION       , 1020)
   MIL_DEPRECATED(M_HDR_INSUFFICIENT_COLOR_DEPTH, 1050)
#endif


/***************************************************************************/
/* MregDraw()                                                              */
/***************************************************************************/

/* Operation */
#define M_DRAW_POST_REGISTRATION_IMAGE                   1L
#define M_DRAW_BOX                              0x00000020L // already defined in milpat.h
#define M_DRAW_TIE_POINTS                               10L
#define M_DRAW_EDOF_IMAGE                                2L 
#define M_DRAW_DEPTH_INDEX_MAP                           3L
#define M_DRAW_DEPTH_CONFIDENCE_MAP                      4L
#define M_DRAW_DEPTH_INTENSITY_MAP                       5L
#define M_DRAW_ALBEDO_IMAGE                              6L
#define M_DRAW_GAUSSIAN_CURVATURE_IMAGE                  7L
#define M_DRAW_MEAN_CURVATURE_IMAGE                      8L
#define M_DRAW_LOCAL_SHAPE_IMAGE                         9L // TBC!!! 
#define M_DRAW_LOCAL_CONTRAST_IMAGE                     11L // TBC!!! 
#define M_DRAW_TEXTURE_IMAGE                            12L // TBC!!! 
#define M_DRAW_MIN_IMAGE                                13L // TBC!!! 
#define M_DRAW_MAX_IMAGE                                14L // TBC!!!
#define M_DRAW_HDR_IMAGE                                15L
#define M_DRAW_HDR_FULL_IMAGE                           16L

/***************************************************************************/
/* MregTransformCoordinate() and MregTransformCoordinateList()             */
/***************************************************************************/

/* Source and destination */
#define M_REGISTRATION_GLOBAL                   0x02000000L
#define M_MOSAIC                                0x40000002L

/***************************************************************************/
/*                 MilReg CAPI function prototypes                         */
/***************************************************************************/

MIL_ID MFTYPE MregAlloc(MIL_ID SystemId,
                        MIL_INT64  RegistrationType,
                        MIL_INT64  ControlFlag,
                        MIL_ID *ContextIdPtr);

MIL_ID MFTYPE MregAllocResult(MIL_ID SystemId,
                              MIL_INT64  ControlFlag,
                              MIL_ID *ResultIdPtr);

void MFTYPE MregCalculate(MIL_ID ContextId,
                          const MIL_ID *ImageOrContainerArrayPtr,
                          MIL_ID RegResultOrImageId,
                          MIL_INT NumImages,
                          MIL_INT64  ControlFlag);

#if M_MIL_USE_64BIT
// Prototypes for 64 bits OSs
void MFTYPE MregControlInt64 (MIL_ID ContextOrResultId,
                              MIL_INT Index,
                              MIL_INT64  ControlType,
                              MIL_INT64  ControlValue);

void MFTYPE MregControlDouble(MIL_ID     ContextOrResultId,
                              MIL_INT    Index,
                              MIL_INT64  ControlType,
                              MIL_DOUBLE ControlValue);

#else
// Prototypes for 32 bits OSs
#define MregControlInt64  MregControl
#define MregControlDouble MregControl
void MFTYPE MregControl      (MIL_ID     ContextOrResultId,
                              MIL_INT    Index,
                              MIL_INT64  ControlType,
                              MIL_DOUBLE ControlValue);
#endif

void MFTYPE MregDraw(MIL_ID ContextGraId,
                     MIL_ID ResultRegId,
                     MIL_ID DstImageBufOrListGraId,
                     MIL_INT64  Operation,
                     MIL_INT    Index,
                     MIL_INT64  ControlFlag);

void MFTYPE MregFree(MIL_ID ContextOrResultId);

void MFTYPE MregGetResult(MIL_ID RegResultId,
                          MIL_INT    ResultIndex,
                          MIL_INT64  ResultType,
                          void *ResultArrayPtr);

MIL_INT MFTYPE MregInquire(MIL_ID ContextOrResultId,
                           MIL_INT Index,
                           MIL_INT64  InquireType,
                           void *UserVarPtr);

#if M_MIL_USE_UNICODE

MIL_ID MFTYPE MregRestoreW(MIL_CONST_TEXTW_PTR FileName,
                           MIL_ID SystemId,
                           MIL_INT64  ControlFlag,
                           MIL_ID *ContextOrResultIdPtr);

void MFTYPE MregSaveW(MIL_CONST_TEXTW_PTR FileName,
                      MIL_ID ContextOrResultId,
                      MIL_INT64  ControlFlag);

void MFTYPE MregStreamW(MIL_TEXTW_PTR MemPtrOrFileName,
                        MIL_ID SysId,
                        MIL_INT64  Operation,
                        MIL_INT64  StreamType,
                        MIL_DOUBLE Version,
                        MIL_INT64  ControlFlag,
                        MIL_ID *ContextOrResultRegIdPtr,
                        MIL_INT *SizeByteVarPtr);

MIL_ID MFTYPE MregRestoreA(MIL_CONST_TEXTA_PTR FileName,
                           MIL_ID SystemId,
                           MIL_INT64  ControlFlag,
                           MIL_ID *ContextOrResultIdPtr);

void MFTYPE MregSaveA(MIL_CONST_TEXTA_PTR FileName,
                      MIL_ID ContextOrResultId,
                      MIL_INT64  ControlFlag);

void MFTYPE MregStreamA(MIL_TEXTA_PTR MemPtrOrFileName,
                        MIL_ID SysId,
                        MIL_INT64  Operation,
                        MIL_INT64  StreamType,
                        MIL_DOUBLE Version,
                        MIL_INT64  ControlFlag,
                        MIL_ID *ContextOrResultRegIdPtr,
                        MIL_INT *SizeByteVarPtr);

#if M_MIL_UNICODE_API
#define MregSave           MregSaveW
#define MregRestore        MregRestoreW
#define MregStream         MregStreamW
#else
#define MregSave           MregSaveA
#define MregRestore        MregRestoreA
#define MregStream         MregStreamA
#endif

#else

MIL_ID MFTYPE MregRestore(MIL_CONST_TEXT_PTR FileName,
                          MIL_ID SystemId,
                          MIL_INT64  ControlFlag,
                          MIL_ID *ContextOrResultIdPtr);

void MFTYPE MregSave(MIL_CONST_TEXT_PTR FileName,
                     MIL_ID ContextOrResultId,
                     MIL_INT64  ControlFlag);

void MFTYPE MregStream(MIL_TEXT_PTR MemPtrOrFileName,
                       MIL_ID SysId,
                       MIL_INT64  Operation,
                       MIL_INT64  StreamType,
                       MIL_DOUBLE Version,
                       MIL_INT64  ControlFlag,
                       MIL_ID *ContextOrResultRegIdPtr,
                       MIL_INT *SizeByteVarPtr);
#endif

#if M_MIL_USE_64BIT
// Prototypes for 64 bits OSs
void MFTYPE MregSetLocationInt64(MIL_ID     ContextId,
                                 MIL_INT    Index,
                                 MIL_INT    Target,
                                 MIL_INT64  ParamType,
                                 MIL_INT64  Param1,
                                 MIL_DOUBLE Param2,
                                 MIL_DOUBLE Param3,
                                 MIL_DOUBLE Param4,
                                 MIL_INT64  ControlFlag);

void MFTYPE MregSetLocationDouble(MIL_ID     ContextId,
                                  MIL_INT    Index,
                                  MIL_INT    Target,
                                  MIL_INT64  ParamType,
                                  MIL_DOUBLE Param1,
                                  MIL_DOUBLE Param2,
                                  MIL_DOUBLE Param3,
                                  MIL_DOUBLE Param4,
                                  MIL_INT64  ControlFlag);
#else
// Prototypes for 32 bits OSs
#define MregSetLocationInt64  MregSetLocation
#define MregSetLocationDouble MregSetLocation
void MFTYPE MregSetLocation(MIL_ID     ContextId,
                            MIL_INT    Index,
                            MIL_INT    Target,
                            MIL_INT64  ParamType,
                            MIL_DOUBLE Param1,
                            MIL_DOUBLE Param2,
                            MIL_DOUBLE Param3,
                            MIL_DOUBLE Param4,
                            MIL_INT64  ControlFlag);
#endif

void MFTYPE MregTransformImage(MIL_ID RegResultId,
                               const MIL_ID *ImageOrContainerArrayPtr,
                               MIL_ID DestImageBufId,
                               MIL_INT NumImages,
                               MIL_INT64  InterpolationMode,
                               MIL_INT64  ControlFlag);

void MFTYPE MregTransformCoordinate(MIL_ID     RegResultId,
                                    MIL_INT    Source,
                                    MIL_INT    Destination,
                                    MIL_DOUBLE X,
                                    MIL_DOUBLE Y,
                                    MIL_DOUBLE *ResXPtr,
                                    MIL_DOUBLE *ResYPtr,
                                    MIL_INT64  ControlFlag);

void MFTYPE MregTransformCoordinateList(MIL_ID            RegResultId,
                                        MIL_INT           Source,
                                        MIL_INT           Destination,
                                        MIL_INT           NumPoints,
                                        const MIL_DOUBLE* SrcCoordXArrayPtr,
                                        const MIL_DOUBLE* SrcCoordYArrayPtr,
                                        MIL_DOUBLE*       DstCoordXArrayPtr,
                                        MIL_DOUBLE*       DstCoordYArrayPtr,
                                        MIL_INT64         ControlFlag);

/* C++ directive if needed */
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus

inline void MFTYPE MregStreamCpp(MilStreamParam MemPtrOrFileName,
                                 MIL_ID         SysId,
                                 MIL_INT64      Operation,
                                 MIL_INT64      StreamType,
                                 MIL_DOUBLE     Version,
                                 MIL_INT64      ControlFlag,
                                 MIL_ID*        ContextOrResultRegIdPtr,
                                 MIL_INT*       SizeByteVarPtr)
   {
   MregStream(MemPtrOrFileName.m_Param, SysId, Operation, StreamType, Version, ControlFlag, ContextOrResultRegIdPtr, SizeByteVarPtr);
   }

#undef  MregStream
#define MregStream MregStreamCpp

#endif // __cplusplus

#if M_MIL_USE_64BIT
#ifdef __cplusplus
//////////////////////////////////////////////////////////////
// MregControl function definition when compiling c++ files
//////////////////////////////////////////////////////////////
#if !M_MIL_USE_LINUX
inline void MregControl      (MIL_ID ContextOrResultId, 
                              MIL_INT Index, 
                              MIL_INT64  ControlType, 
                              int ControlValue)
   {
   MregControlInt64(ContextOrResultId, Index, ControlType, ControlValue);
   };
#endif
inline void MregControl      (MIL_ID ContextOrResultId, 
                              MIL_INT Index, 
                              MIL_INT64  ControlType, 
                              MIL_INT32 ControlValue)
   {
   MregControlInt64(ContextOrResultId, Index, ControlType, ControlValue);
   }
inline void MregControl      (MIL_ID ContextOrResultId, 
                              MIL_INT Index, 
                              MIL_INT64  ControlType, 
                              MIL_INT64 ControlValue)
   {
   MregControlInt64(ContextOrResultId, Index, ControlType, ControlValue);
   }
inline void MregControl      (MIL_ID     ContextOrResultId, 
                              MIL_INT    Index, 
                              MIL_INT64  ControlType, 
                              MIL_DOUBLE ControlValue)
   {
   MregControlDouble(ContextOrResultId, Index, ControlType, ControlValue);
   }

//////////////////////////////////////////////////////////////
// MregSetLocation function definition when compiling c++ files
//////////////////////////////////////////////////////////////
#if !M_MIL_USE_LINUX
inline void MregSetLocation(MIL_ID     ContextId, 
                            MIL_INT    Index, 
                            MIL_INT    Target,
                            MIL_INT64  ParamType,
                            int        Param1,
                            MIL_DOUBLE Param2,
                            MIL_DOUBLE Param3,
                            MIL_DOUBLE Param4,
                            MIL_INT64  ControlFlag)
   {
   MregSetLocationInt64(ContextId, Index, Target, ParamType, Param1, Param2, Param3, Param4, ControlFlag);
   }
#endif
inline void MregSetLocation(MIL_ID     ContextId, 
                            MIL_INT    Index, 
                            MIL_INT    Target,
                            MIL_INT64  ParamType,
                            MIL_INT32  Param1,
                            MIL_DOUBLE Param2,
                            MIL_DOUBLE Param3,
                            MIL_DOUBLE Param4,
                            MIL_INT64  ControlFlag)
   {
   MregSetLocationInt64(ContextId, Index, Target, ParamType, Param1, Param2, Param3, Param4, ControlFlag);
   }
inline void MregSetLocation(MIL_ID     ContextId, 
                            MIL_INT    Index, 
                            MIL_INT    Target,
                            MIL_INT64  ParamType,
                            MIL_INT64  Param1,
                            MIL_DOUBLE Param2,
                            MIL_DOUBLE Param3,
                            MIL_DOUBLE Param4,
                            MIL_INT64  ControlFlag)
   {
   MregSetLocationInt64(ContextId, Index, Target, ParamType, Param1, Param2, Param3, Param4, ControlFlag);
   }
inline void MregSetLocation(MIL_ID     ContextId, 
                            MIL_INT    Index, 
                            MIL_INT    Target,
                            MIL_INT64  ParamType,
                            MIL_DOUBLE Param1,
                            MIL_DOUBLE Param2,
                            MIL_DOUBLE Param3,
                            MIL_DOUBLE Param4,
                            MIL_INT64  ControlFlag)
   {
   MregSetLocationDouble(ContextId, Index, Target, ParamType, Param1, Param2, Param3, Param4, ControlFlag);
   }
#else
//////////////////////////////////////////////////////////////
// For C file, call the default function, i.e. Int64 one
//////////////////////////////////////////////////////////////
#define MregControl     MregControlDouble
#define MregSetLocation MregSetLocationDouble

#endif // __cplusplus
#endif // M_MIL_USE_64BIT

#if M_MIL_USE_SAFE_TYPE

//////////////////////////////////////////////////////////////
// See milos.h for explanation about these functions.
//////////////////////////////////////////////////////////////

// ----------------------------------------------------------
// MregGetResult

inline void MFTYPE MregGetResultUnsafe  (MIL_ID RegResultId, MIL_INT ResultIndex, MIL_INT64  ResultType, void        *ResultArrayPtr);
inline void MFTYPE MregGetResultSafeType(MIL_ID RegResultId, MIL_INT ResultIndex, MIL_INT64  ResultType, MilVoidPtr   ResultArrayPtr);
// ----------------------------------------------------------
// MregInquire

inline MIL_INT MFTYPE MregInquireUnsafe  (MIL_ID ContextOrResultId, MIL_INT Index, MIL_INT64  InquireType, void        *UserVarPtr);

// ----------------------------------------------------------
// MregGetResult

inline void MFTYPE MregGetResultSafeType  (MIL_ID RegResultId, MIL_INT ResultIndex, MIL_INT64  ResultType, MilVoidPtr ResultArrayPtr)
   {
   MIL_INT64 RequiredParamType = M_PARAM_TYPE_MIL_INT64;
   if(!(M_DEFAULT_DATA_TYPE_BIT_SET(ResultType) || M_RECOMMENDED_DATA_TYPE_BIT_SET(ResultType)))
      {
      MregGetResult(RegResultId, ResultIndex, ResultType | M_DEFAULT_DATA_TYPE, &RequiredParamType);
      }
   if(!MfuncPointerIsCompatible(RequiredParamType, ResultArrayPtr.Type, ResultType))
      {
      SafeTypeError(MIL_TEXT("MregGetResult"));
      }
   MregGetResult(RegResultId, ResultIndex, ResultType, ResultArrayPtr.Ptr);
   }

inline void MFTYPE MregGetResultUnsafe(MIL_ID RegResultId, MIL_INT ResultIndex, MIL_INT64  ResultType, void *ResultArrayPtr)
   {
   MregGetResult (RegResultId, ResultIndex, ResultType, ResultArrayPtr );
   }

// ----------------------------------------------------------
// MregInquire

inline MIL_INT MFTYPE MregInquireSafeType(MIL_ID ContextOrResultId, MIL_INT Index, MIL_INT64  InquireType, MilVoidPtr UserVarPtr)
   {
   MIL_INT64 RequiredParamType = M_PARAM_TYPE_MIL_INT64;
   if(!(M_DEFAULT_DATA_TYPE_BIT_SET(InquireType) || M_RECOMMENDED_DATA_TYPE_BIT_SET(InquireType)))
      {
      MregInquire(ContextOrResultId, Index, InquireType | M_DEFAULT_DATA_TYPE, &RequiredParamType);
      }
   if(!MfuncPointerIsCompatible(RequiredParamType, UserVarPtr.Type, InquireType))
      {
      SafeTypeError(MIL_TEXT("MregInquire"));
      }
   return MregInquire(ContextOrResultId, Index, InquireType, UserVarPtr.Ptr);
   }

inline MIL_INT MFTYPE MregInquireUnsafe(MIL_ID ContextOrResultId, MIL_INT Index, MIL_INT64  InquireType, void *UserVarPtr)
   {
   return MregInquire (ContextOrResultId, Index, InquireType, UserVarPtr);
   }

#define MregGetResult        MregGetResultSafeType
#define MregInquire          MregInquireSafeType

#else // #if M_MIL_USE_SAFE_TYPE

#define MregGetResultUnsafe        MregGetResult
#define MregInquireUnsafe          MregInquire

#endif // #if M_MIL_USE_SAFE_TYPE

// ----------------------------------------------------------
// Overload for std::vector.
#if defined(M_MIL_USE_VECTOR) && M_MIL_USE_VECTOR
template <typename UserType>
inline void MFTYPE MregGetResult(MIL_ID ResultId, MIL_INT Index, MIL_INT64  ResultType, std::vector<UserType> &ValuePtr)
   {
   //! If the given MIL data type is not the same as the SrcType, change it to the correct one
   //! and give a warning.
   MIL_INT64 InternalTrueDataTypeForStdVector = MilTraits<UserType>::TypeFlag;

#if M_MIL_USE_SAFE_TYPE
   if(M_GET_HLVLDATATYPE(ResultType) != 0)
      {
      SafeTypeError(MIL_TEXT("MregGetResult"), MIL_TEXT("Combination value for the required data type is not supported with std::vector overload."));
      }
#endif

   ResultType = M_STRIP_HLVLDATATYPE(ResultType) + InternalTrueDataTypeForStdVector;

   MIL_INT InternalNumberOfElementsForStdVector = 0;
   MregGetResult(ResultId, Index, M_STRIP_HLVLDATATYPE(ResultType) + M_NB_ELEMENTS + M_TYPE_MIL_INT, &InternalNumberOfElementsForStdVector);

   ValuePtr.resize(InternalNumberOfElementsForStdVector);

   if(InternalNumberOfElementsForStdVector > 0)
      {
      MregGetResult(ResultId, Index, ResultType, &ValuePtr[0]);
      }
   }

// ----------------------------------------------------------
// Overloads for std::vector in MregCalculate.
inline void MFTYPE MregCalculate(MIL_ID                     ContextId,
                                 const std::vector<MIL_ID>& ImageOrContainerArrayPtr,
                                 MIL_ID                     RegResultOrImageId,
                                 MIL_INT                    NumImages,
                                 MIL_INT64                  ControlFlag)
   {
#if M_MIL_USE_SAFE_TYPE
   if(ImageOrContainerArrayPtr.empty())
      {
      SafeTypeError(MIL_TEXT("MregCalculate"), MIL_TEXT("The input vectors cannot be empty."));
      }
   if(NumImages <= 0)
      {
      SafeTypeError(MIL_TEXT("MregCalculate"), MIL_TEXT("NumImages parameter must be greater than zero."));
      }
   if(NumImages > (MIL_INT)ImageOrContainerArrayPtr.size() && NumImages != M_DEFAULT)
      {
      SafeTypeError(MIL_TEXT("MregCalculate"), MIL_TEXT("NumImages parameter must be smaller or equal (M_DEFAULT) to the size of input vector."));
      }
#endif

   if(NumImages == M_DEFAULT || NumImages > (MIL_INT)ImageOrContainerArrayPtr.size())
      {
      NumImages = (MIL_INT)ImageOrContainerArrayPtr.size();
      }

   MregCalculate(ContextId,
                 ImageOrContainerArrayPtr.empty() ? nullptr : &ImageOrContainerArrayPtr[0],
                 RegResultOrImageId,
                 NumImages,
                 ControlFlag);
   }

// ----------------------------------------------------------
// Overloads for std::vector in MregTransformCoordinateList.
inline void MFTYPE MregTransformCoordinateList(MIL_ID                         RegResultId,
                                               MIL_INT                        Source,
                                               MIL_INT                        Destination,
                                               MIL_INT                        NumPoints,
                                               const std::vector<MIL_DOUBLE>& SrcCoordXArrayPtr,
                                               const std::vector<MIL_DOUBLE>& SrcCoordYArrayPtr,
                                               std::vector<MIL_DOUBLE>&       DstCoordXArrayPtr,
                                               std::vector<MIL_DOUBLE>&       DstCoordYArrayPtr,
                                               MIL_INT64                      ControlFlag)
   {
#if M_MIL_USE_SAFE_TYPE
   if(NumPoints <= 0)
      {
      SafeTypeError(MIL_TEXT("MregTransformCoordinateList"), MIL_TEXT("NumPoints parameter must be greater than zero."));
      }
   if(SrcCoordXArrayPtr.size() != SrcCoordYArrayPtr.size())
      {
      SafeTypeError(MIL_TEXT("MregTransformCoordinateList"), MIL_TEXT("SrcCoordXArrayPtr and SrcCoordYArrayPtr must have the same size."));
      }
   if(SrcCoordXArrayPtr.empty())
      {
      SafeTypeError(MIL_TEXT("MregTransformCoordinateList"), MIL_TEXT("The input vectors cannot be empty."));
      }
   if((MIL_UINT)NumPoints > SrcCoordXArrayPtr.size() && NumPoints != M_DEFAULT)
      {
      SafeTypeError(MIL_TEXT("MregTransformCoordinateList"), MIL_TEXT("NumPoints parameter must be smaller or equal (M_DEFAULT) to the size of input vectors."));
      }
#endif

   if(NumPoints == M_DEFAULT || (MIL_UINT)NumPoints > SrcCoordXArrayPtr.size())
      {
      NumPoints = (MIL_INT)SrcCoordXArrayPtr.size();
      }

   DstCoordXArrayPtr.resize((MIL_UINT)NumPoints);
   DstCoordYArrayPtr.resize((MIL_UINT)NumPoints);

   MregTransformCoordinateList(RegResultId,
                               Source,
                               Destination,
                               NumPoints,
                               SrcCoordXArrayPtr.empty() ? nullptr : &SrcCoordXArrayPtr[0],
                               SrcCoordYArrayPtr.empty() ? nullptr : &SrcCoordYArrayPtr[0],
                               DstCoordXArrayPtr.empty() ? nullptr : &DstCoordXArrayPtr[0],
                               DstCoordYArrayPtr.empty() ? nullptr : &DstCoordYArrayPtr[0],
                               ControlFlag);
   }

// ----------------------------------------------------------
// Overloads for std::vector in MregTransformImage.
inline void MFTYPE MregTransformImage(MIL_ID                     RegResultId,
                                      const std::vector<MIL_ID>& ImageOrContainerArrayPtr,
                                      MIL_ID                     DestImageBufId,
                                      MIL_INT                    NumImages,
                                      MIL_INT64                  InterpolationMode,
                                      MIL_INT64                  ControlFlag)
   {
#if M_MIL_USE_SAFE_TYPE
   if(NumImages <= 0)
      {
      SafeTypeError(MIL_TEXT("MregTransformImage"), MIL_TEXT("NumImages parameter must be greater than zero."));
      }
   if(ImageOrContainerArrayPtr.empty())
      {
      SafeTypeError(MIL_TEXT("MregTransformImage"), MIL_TEXT("The input vector cannot be empty."));
      }
   if(NumImages > (MIL_INT)ImageOrContainerArrayPtr.size() && NumImages != M_DEFAULT)
      {
      SafeTypeError(MIL_TEXT("MregTransformImage"), MIL_TEXT("NumImages parameter must be smaller or equal (M_DEFAULT) to the size of input vector."));
      }
#endif

   if(NumImages == M_DEFAULT || NumImages > (MIL_INT)ImageOrContainerArrayPtr.size())
      {
      NumImages = (MIL_INT)ImageOrContainerArrayPtr.size();
      }

   MregTransformImage(RegResultId,
                      ImageOrContainerArrayPtr.empty() ? nullptr : &ImageOrContainerArrayPtr[0],
                      DestImageBufId,
                      NumImages,
                      InterpolationMode,
                      ControlFlag);
   }

// ----------------------------------------------------------
// Overloads for std::vector in MxxxStream.
inline void MFTYPE MregStream(std::vector<MIL_UINT8>  &MemPtrOrFileName,
                               MIL_ID                 SysId,
                               MIL_INT64              Operation,
                               MIL_INT64              StreamType,
                               MIL_DOUBLE             Version,
                               MIL_INT64              ControlFlag,
                               MIL_ID*                McontextIdPtr,
                               MIL_INT*               SizeByteVarPtr)
   {
   MxxxStreamForStdVector(MemPtrOrFileName,
                          SysId,
                          Operation,
                          StreamType,
                          Version,
                          ControlFlag,
                          McontextIdPtr,
                          SizeByteVarPtr,
                          MregStream);
   }
#endif // defined(M_MIL_USE_VECTOR) && M_MIL_USE_VECTOR

#if M_MIL_USE_STRING
/***************************************************************************/
/* REGISTRATION MODULE                                                     */
/***************************************************************************/
#if M_MIL_USE_UNICODE
#if M_MIL_UNICODE_API
inline void  MregSaveW(const MIL_STRING& FileName, MIL_ID ContextOrResultId, MIL_INT64  ControlFlag)
   {
   return MregSaveW(FileName.c_str(), ContextOrResultId, ControlFlag);
   }

inline MIL_ID  MregRestoreW(const MIL_STRING& FileName, MIL_ID SystemId, MIL_INT64  ControlFlag, MIL_ID *ContextOrResultIdPtr)
   {
   return MregRestoreW(FileName.c_str(), SystemId, ControlFlag, ContextOrResultIdPtr);
   }

#else
inline void  MregSaveA(const MIL_STRING& FileName, MIL_ID ContextOrResultId, MIL_INT64  ControlFlag)
   {
   return MregSaveA(FileName.c_str(), ContextOrResultId, ControlFlag);
   }

inline MIL_ID  MregRestoreA(const MIL_STRING& FileName, MIL_ID SystemId, MIL_INT64  ControlFlag, MIL_ID *ContextOrResultIdPtr)
   {
   return MregRestoreA(FileName.c_str(), SystemId, ControlFlag, ContextOrResultIdPtr);
   }

#endif /* M_MIL_UNICODE_API */
#else
inline void  MregSave(const MIL_STRING& FileName, MIL_ID ContextOrResultId, MIL_INT64  ControlFlag)
   {
   return MregSave(FileName.c_str(), ContextOrResultId, ControlFlag);
   }

inline MIL_ID  MregRestore(const MIL_STRING& FileName, MIL_ID SystemId, MIL_INT64  ControlFlag, MIL_ID *ContextOrResultIdPtr)
   {
   return MregRestore(FileName.c_str(), SystemId, ControlFlag, ContextOrResultIdPtr);
   }

#endif /* M_MIL_USE_UNICODE */
#endif /* M_MIL_USE_STRING*/

////////////////////////////////////////////////////////////////////////////////
// MIL_UNIQUE_ID support

#if M_MIL_USE_MIL_UNIQUE_ID

#if M_MIL_USE_SAFE_TYPE
template <> inline bool MilIsCorrectObjectType<&MregFree>(MIL_INT64 ObjectType)
   {
   return (ObjectType & ~M_USER_DEFINE_LOW_ATTRIBUTE) == M_REG_OBJECT;
   }
#endif

typedef MIL_UNIQUE_ID<&MregFree> MIL_UNIQUE_REG_ID;

#if M_MIL_USE_MOVE_SEMANTICS

inline MIL_UNIQUE_REG_ID MregAlloc(MIL_ID SystemId, MIL_INT64 RegistrationType, MIL_INT64 ControlFlag, MIL_UNIQUE_ID_TAG)
   {
   return MIL_UNIQUE_REG_ID(MregAlloc(SystemId, RegistrationType, ControlFlag, M_NULL));
   }
inline MIL_UNIQUE_REG_ID MregAllocResult(MIL_ID SystemId, MIL_INT64 ControlFlag, MIL_UNIQUE_ID_TAG)
   {
   return MIL_UNIQUE_REG_ID(MregAllocResult(SystemId, ControlFlag, M_NULL));
   }
inline MIL_UNIQUE_REG_ID MregRestore(MIL_CONST_TEXT_PTR FileName, MIL_ID SystemId, MIL_INT64 ControlFlag, MIL_UNIQUE_ID_TAG)
   {
   return MIL_UNIQUE_REG_ID(MregRestore(FileName, SystemId, ControlFlag, M_NULL));
   }
#if M_MIL_USE_STRING
inline MIL_UNIQUE_REG_ID MregRestore(const MIL_STRING& FileName, MIL_ID SystemId, MIL_INT64 ControlFlag, MIL_UNIQUE_ID_TAG)
   {
   return MIL_UNIQUE_REG_ID(MregRestore(FileName, SystemId, ControlFlag, M_NULL));
   }
#endif // M_MIL_USE_STRING
template <MilFreeFuncType FreeFunc> inline void MregFree(const MIL_UNIQUE_ID<FreeFunc>&) = delete;

inline void MregCalculate(MIL_ID ContextId, MilConstArrayIdParam ImageOrContainerArrayPtr, MIL_ID RegResultOrImageId, MIL_INT NumImages, MIL_INT64  ControlFlag)
   {
   MregCalculate(ContextId, ImageOrContainerArrayPtr.m_IdArrayPtr, RegResultOrImageId, NumImages, ControlFlag);
   }

inline void MregStream(MilStreamParam     MemPtrOrFileName       ,
                       MIL_ID             SysId                  ,
                       MIL_INT64          Operation              ,
                       MIL_INT64          StreamType             ,
                       MIL_DOUBLE         Version                ,
                       MIL_INT64          ControlFlag            ,
                       MIL_UNIQUE_REG_ID* ContextOrResultRegIdPtr,
                       MIL_INT*           SizeByteVarPtr         )
   {
   MxxxStreamForMilUniqueId(MemPtrOrFileName, SysId, Operation, StreamType, Version, ControlFlag, ContextOrResultRegIdPtr, SizeByteVarPtr, MregStream);
   }

inline void MregTransformImage(MIL_ID RegResultId, MilConstArrayIdParam ImageOrContainerArrayPtr, MIL_ID DestImageBufId, MIL_INT NumImages, MIL_INT64 InterpolationMode, MIL_INT64 ControlFlag)
   {
   MregTransformImage(RegResultId, ImageOrContainerArrayPtr.m_IdArrayPtr, DestImageBufId, NumImages, InterpolationMode, ControlFlag);
   }


#endif // M_MIL_USE_MOVE_SEMANTICS
#endif // M_MIL_USE_MIL_UNIQUE_ID

// End of MIL_UNIQUE_ID support
////////////////////////////////////////////////////////////////////////////////

#endif // !M_MIL_LITE
#endif // __MILREG_H__
