Skip to content

Commit

Permalink
2x2 C+ example almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
rfabbri committed Jun 16, 2024
1 parent 42f1503 commit 7cbbe50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion minus/linecircle-io.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct minus_io<linecircle, F> : public minus_io_14a<linecircle, F> {
static constexpr unsigned nviews = pp::nviews;
static constexpr unsigned npoints = pp::npoints;
// Input ---------------------------------------------------------------------
static void gammify(C<F> * __restrict params/*[ chicago: M::nparams]*/);
static void gammify(C<F> * __restrict params/*[ M::nparams]*/);
// problem-specific input
// Any function to convert data to parameters would go here
// see point_tangents2params
Expand Down
39 changes: 5 additions & 34 deletions minus/linecircle.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace MiNuS {
template <typename F>
inline bool
minus<linecircle, F>::solve(
const F tgt[pp::nviews][pp::npoints][io::ncoords2d],
const C<F> 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,
Expand All @@ -129,8 +129,7 @@ minus<linecircle, F>::solve(
alignas(64) C<F> params[2*M::f::nparams];
memcpy(params, data::params_start_target_, M::f::nparams*sizeof(C<F>));

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;
Expand All @@ -153,38 +152,10 @@ minus<linecircle, F>::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 <typename F>
inline bool
minus<linecircle, F>::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;
}

//
Expand Down
20 changes: 20 additions & 0 deletions minus/minus.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <problem P, typename F>
inline void
minus_io_14a<P, F>::
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<M::nve,F> 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]
//
Expand Down

0 comments on commit 7cbbe50

Please sign in to comment.