From 7cbbe50dd858c7508fcd98fc77170295ca6ea82e Mon Sep 17 00:00:00 2001 From: Ricardo Fabbri Date: Sat, 15 Jun 2024 23:30:33 -0700 Subject: [PATCH] 2x2 C+ example almost there --- minus/linecircle-io.hxx | 2 +- minus/linecircle.hxx | 39 +++++---------------------------------- minus/minus.hxx | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/minus/linecircle-io.hxx b/minus/linecircle-io.hxx index 93619e9..401c899 100644 --- a/minus/linecircle-io.hxx +++ b/minus/linecircle-io.hxx @@ -14,7 +14,7 @@ struct minus_io : public minus_io_14a { static constexpr unsigned nviews = pp::nviews; static constexpr unsigned npoints = pp::npoints; // Input --------------------------------------------------------------------- - static void gammify(C * __restrict params/*[ chicago: M::nparams]*/); + static void gammify(C * __restrict params/*[ M::nparams]*/); // problem-specific input // Any function to convert data to parameters would go here // see point_tangents2params diff --git a/minus/linecircle.hxx b/minus/linecircle.hxx index fb5db07..394ab85 100644 --- a/minus/linecircle.hxx +++ b/minus/linecircle.hxx @@ -118,7 +118,7 @@ namespace MiNuS { template inline bool minus::solve( - const F tgt[pp::nviews][pp::npoints][io::ncoords2d], + const C params_final, // p1 in linecircle-end.m2 F solutions[M::nsols], // first camera is always [I | 0] unsigned id_sols[M::nsols], unsigned *nsols_final, @@ -129,8 +129,7 @@ minus::solve( alignas(64) C params[2*M::f::nparams]; memcpy(params, data::params_start_target_, M::f::nparams*sizeof(C)); - if (!io::point_tangents2params(p, tgt, id_tgt0, id_tgt1, params)) - return false; + // You may want to convert your data e.g. points into params here alignas(64) typename M::solution solutions[M::nsols]; alignas(64) typename M::track_settings settings = M::DEFAULT; @@ -153,38 +152,10 @@ minus::solve( if (!io::has_valid_solutions(solutions)) return false; - // you may want to decode solutions into a standar format, eg convert quaternions to 3x4 cams - return true; -} + // you may want to decode solutions into a standard format, eg convert quaternions to 3x4 cams + io::all_real_solutions(solutions, solutions_real, id_sols, nsols_final); -// -// same as solve() but intrinsics not inverted (input is in actual pixel units) -// returns false in case of numerical failure to find valid real solutions -// -template -inline bool -minus::solve_img( - const F K[/*3 or 2 ignoring last line*/][io::ncoords2d_h], - const F p[pp::nviews][pp::npoints][io::ncoords2d], - const F tgt[pp::nviews][pp::npoints][io::ncoords2d], - F solutions_cams[M::nsols][pp::nviews-1][4][3], // first camera is always [I | 0] - unsigned id_sols[M::nsols], - unsigned *nsols_final, - unsigned nthreads) -{ - F pn[pp::nviews][pp::npoints][io::ncoords2d]; - F tn[pp::nviews][pp::npoints][io::ncoords2d]; - - // see if uno minus default_gammas_m2 is less than 1 - io::invert_intrinsics(K, p[0], pn[0], pp::npoints); - io::invert_intrinsics(K, p[1], pn[1], pp::npoints); - io::invert_intrinsics(K, p[2], pn[2], pp::npoints); - // don't use all three, but just invert all anyways. - io::invert_intrinsics_tgt(K, tgt[0], tn[0], pp::npoints); - io::invert_intrinsics_tgt(K, tgt[1], tn[1], pp::npoints); - io::invert_intrinsics_tgt(K, tgt[2], tn[2], pp::npoints); - - return solve(pn, tn, solutions_cams, id_sols, nsols_final, nthreads); + return true; } // diff --git a/minus/minus.hxx b/minus/minus.hxx index 9f9b6ee..9a82546 100644 --- a/minus/minus.hxx +++ b/minus/minus.hxx @@ -301,6 +301,26 @@ RC_to_QT_format(const F rc[pp::nviews][4][3], F qt[M::nve]) u::quat_transform(q2,dc, qt + 8 + 3); } +// Returns all real solutions +// The real_solutions array is fixed in size to NSOLS which is the max +// number of solutions, which perfectly fits in memory. The caller must pass an +// array with that minimum. +template +inline void +minus_io_14a:: +all_real_solutions(solution raw_solutions[M::nsols], F real_solutions[M::nsols][M::nve], + unsigned id_sols[M::nsols], unsigned *nsols_real) +{ + typedef minus_array v; + *nsols_final = 0; + id_sols[*nsols_final] = 0; + for (unsigned sol=0; sol < M::nsols; ++sol) { + if (raw_solutions[sol].status == M::REGULAR && v::get_real(raw_solutions[sol].x, real_solutions[*id_sols[nsols_final]])) + id_sols[(*nsols_final)++] = sol; + } +} + + // // returns cameras[0:nsols_final][2][4][3] //