From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Mon, 11 Nov 2024 00:15:05 -0500 Subject: [PATCH 1/8] Fix MSVC build errors --- autodiff.hh | 4 ++-- mrcal-internal.h | 22 +++++++++++----------- mrcal-types.h | 26 ++++++++++---------------- mrcal.c | 9 --------- 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/autodiff.hh b/autodiff.hh index b6f217354c9de45493d50f776082fe2151330a1d..37aa8c5a048a538ccdf500a43bbd8d788c953a05 100644 --- a/autodiff.hh +++ b/autodiff.hh @@ -26,7 +26,7 @@ template struct val_withgrad_t { double x; - double j[NGRAD]; + double j[NGRAD == 0 ? 1 : NGRAD]; __attribute__ ((visibility ("hidden"))) val_withgrad_t(double _x = 0.0) : x(_x) @@ -281,7 +281,7 @@ struct val_withgrad_t template struct vec_withgrad_t { - val_withgrad_t v[NVEC]; + val_withgrad_t v[NVEC == 0 ? 1 : NVEC]; vec_withgrad_t() {} diff --git a/mrcal-internal.h b/mrcal-internal.h index 4ec6acadb5fc92ec264fb460e1fcc882dd3face3..8fc2857758ef7763cc1ef5b79a495aec7b7bc1bd 100644 --- a/mrcal-internal.h +++ b/mrcal-internal.h @@ -12,16 +12,16 @@ // wrapper only // These models have no precomputed data -typedef struct {} mrcal_LENSMODEL_PINHOLE__precomputed_t; -typedef struct {} mrcal_LENSMODEL_STEREOGRAPHIC__precomputed_t; -typedef struct {} mrcal_LENSMODEL_LONLAT__precomputed_t; -typedef struct {} mrcal_LENSMODEL_LATLON__precomputed_t; -typedef struct {} mrcal_LENSMODEL_OPENCV4__precomputed_t; -typedef struct {} mrcal_LENSMODEL_OPENCV5__precomputed_t; -typedef struct {} mrcal_LENSMODEL_OPENCV8__precomputed_t; -typedef struct {} mrcal_LENSMODEL_OPENCV12__precomputed_t; -typedef struct {} mrcal_LENSMODEL_CAHVOR__precomputed_t; -typedef struct {} mrcal_LENSMODEL_CAHVORE__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_PINHOLE__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_STEREOGRAPHIC__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_LONLAT__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_LATLON__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV4__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV5__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV8__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV12__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_CAHVOR__precomputed_t; +typedef struct { int dummy; } mrcal_LENSMODEL_CAHVORE__precomputed_t; // The splined stereographic models configuration parameters can be used to // compute the segment size. I cache this computation @@ -38,7 +38,7 @@ typedef struct union { #define PRECOMPUTED_STRUCT(s,n) mrcal_ ##s##__precomputed_t s##__precomputed; - MRCAL_LENSMODEL_LIST(PRECOMPUTED_STRUCT); + MRCAL_LENSMODEL_LIST(PRECOMPUTED_STRUCT) #undef PRECOMPUTED_STRUCT }; } mrcal_projection_precomputed_t; diff --git a/mrcal-types.h b/mrcal-types.h index e5cf6c637f8f2bf9e4bbe4ad443661159c511887..7e43319b882c3e29eb3429f95c77fc8bd664ce1a 100644 --- a/mrcal-types.h +++ b/mrcal-types.h @@ -45,24 +45,18 @@ // parametric models have no extra configuration -typedef struct {} mrcal_LENSMODEL_PINHOLE__config_t; -typedef struct {} mrcal_LENSMODEL_STEREOGRAPHIC__config_t; -typedef struct {} mrcal_LENSMODEL_LONLAT__config_t; -typedef struct {} mrcal_LENSMODEL_LATLON__config_t; -typedef struct {} mrcal_LENSMODEL_OPENCV4__config_t; -typedef struct {} mrcal_LENSMODEL_OPENCV5__config_t; -typedef struct {} mrcal_LENSMODEL_OPENCV8__config_t; -typedef struct {} mrcal_LENSMODEL_OPENCV12__config_t; -typedef struct {} mrcal_LENSMODEL_CAHVOR__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_PINHOLE__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_STEREOGRAPHIC__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_LONLAT__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_LATLON__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV4__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV5__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV8__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_OPENCV12__config_t; +typedef struct { int dummy; } mrcal_LENSMODEL_CAHVOR__config_t; #define _MRCAL_ITEM_DEFINE_ELEMENT(name, type, pybuildvaluecode, PRIcode,SCNcode, bitfield, cookie) type name bitfield; -#ifndef __cplusplus -// This barfs with g++ 4.8, so I disable it for C++ in general. Checking it for -// C code is sufficient -_Static_assert(sizeof(uint16_t) == sizeof(unsigned short int), "I need a short to be 16-bit. Py_BuildValue doesn't let me just specify that. H means 'unsigned short'"); -#endif - // Configuration for CAHVORE. These are given as an an // "X macro": https://en.wikipedia.org/wiki/X_Macro #define MRCAL_LENSMODEL_CAHVORE_CONFIG_LIST(_, cookie) \ @@ -128,7 +122,7 @@ typedef struct union { #define CONFIG_STRUCT(s,n) mrcal_ ##s##__config_t s##__config; - MRCAL_LENSMODEL_LIST(CONFIG_STRUCT); + MRCAL_LENSMODEL_LIST(CONFIG_STRUCT) #undef CONFIG_STRUCT }; } mrcal_lensmodel_t; diff --git a/mrcal.c b/mrcal.c index d1195a36050e5cbde393ed033e4d5699ce52225a..85ab4e26a5ab487fc13e66ebd486bd7c00480c05 100644 --- a/mrcal.c +++ b/mrcal.c @@ -2674,8 +2674,6 @@ void project( // out if(!camera_at_identity) { // make sure I can pass mrcal_pose_t.r as an rt[] transformation - _Static_assert( offsetof(mrcal_pose_t, r) == 0, "mrcal_pose_t has expected structure"); - _Static_assert( offsetof(mrcal_pose_t, t) == 3*sizeof(double), "mrcal_pose_t has expected structure"); mrcal_compose_rt( _joint_rt, gg._d_rj_rc, gg._d_rj_rf, gg._d_tj_rc, gg._d_tj_tf, @@ -3465,8 +3463,6 @@ void mrcal_pack_solver_state_vector( // out, in lensmodel, problem_selections, Ncameras_intrinsics ); - _Static_assert( offsetof(mrcal_pose_t, r) == 0, "mrcal_pose_t has expected structure"); - _Static_assert( offsetof(mrcal_pose_t, t) == 3*sizeof(double), "mrcal_pose_t has expected structure"); if( problem_selections.do_optimize_extrinsics ) for(int icam_extrinsics=0; icam_extrinsics < Ncameras_extrinsics; icam_extrinsics++) { @@ -3715,11 +3711,6 @@ void mrcal_unpack_solver_state_vector( // out, in if( problem_selections.do_optimize_extrinsics ) { - _Static_assert( offsetof(mrcal_pose_t, r) == 0, - "mrcal_pose_t has expected structure"); - _Static_assert( offsetof(mrcal_pose_t, t) == 3*sizeof(double), - "mrcal_pose_t has expected structure"); - mrcal_pose_t* extrinsics_fromref = (mrcal_pose_t*)(&b[i_state]); for(int icam_extrinsics=0; icam_extrinsics < Ncameras_extrinsics; icam_extrinsics++) i_state += unpack_solver_state_extrinsics_one( &extrinsics_fromref[icam_extrinsics], &b[i_state] );