16 # include <vcl_msvc_warnings.h> 21 static const double vpgl_trans_z_step = 2.0;
23 #if 0 // replace with weighted version 28 double elevation,
double& xm,
double& ym)
30 unsigned int n = cams.size();
32 double xsq = 0, ysq = 0;
34 for (
unsigned int i = 0; i<n; ++i)
41 double x = pb_pt.
x(), y = pb_pt.
y();
46 double xvar = xsq-(n*xm*xm);
47 double yvar = ysq-(n*ym*ym);
49 double var = std::sqrt(xvar*xvar + yvar*yvar);
56 std::vector<float>
const& cam_weights,
59 double elevation,
double& xm,
double& ym,
60 double const& relative_diameter = 1.0)
62 unsigned int n = cams.size();
64 double xsq = 0, ysq = 0;
66 std::vector<vgl_point_3d<double> > pb_pts;
67 for (
unsigned int i = 0; i<n; ++i)
70 if (cam_weights[i] == 0)
72 pb_pts.emplace_back(0,0,0);
80 pb_pts.push_back(pb_pt);
82 double weight_sum = 0.0;
83 for (
unsigned i = 0; i < n; i++)
85 double x = pb_pts[i].x(), y = pb_pts[i].y();
86 xm+=cam_weights[i]*x; ym +=cam_weights[i]*y;
87 weight_sum += cam_weights[i];
91 for (
unsigned i = 0; i < n; i++)
93 double x = pb_pts[i].x(), y = pb_pts[i].y();
94 xsq+=cam_weights[i]*(x-xm)*(x-xm); ysq+=cam_weights[i]*(y-ym)*(y-ym);
97 xsq /= weight_sum; ysq /= weight_sum;
98 double var = std::sqrt(xsq*xsq + ysq*ysq);
106 std::vector<float> cam_weights,
109 double const& relative_diameter)
112 initial_pt_(initial_pt),
113 cameras_(std::move(cams)),
114 cam_weights_(std::move(cam_weights)),
115 image_pts_(std::move(image_pts)),
117 relative_diameter_(relative_diameter)
128 std::vector<float>
const& cam_weights,
132 unsigned int n = cams.size();
133 if (!n || n!=corrs.size())
139 for (
const auto & cam : cams)
146 double zplus = zoff+zscale;
147 double zminus = zoff-zscale;
148 if (zminus>zmin) zmin = zminus;
149 if (zplus<zmax) zmax = zplus;
156 double xopt=0, yopt=0, zopt = zmin;
157 for (
double z = zmin; z<=zmax; z+=vpgl_trans_z_step)
159 double xm = 0, ym = 0;
161 double var = scatter_var(cams, cam_weights, corrs,initial_point, z, xm, ym);
169 initial_point.
set(xm, ym, z);
170 #ifdef TRANS_ONE_DEBUG 171 std::cout << z <<
'\t' << var <<
'\n';
176 if (zopt == zmin||zopt == zmax)
178 p_3d.
set(xopt, yopt, zopt);
184 std::vector<float>
const& cam_weights,
190 double const& relative_diameter)
192 auto n = static_cast<unsigned int>(cams.size());
193 if (!n || n != corrs.size())
196 double min_z = zmin - vpgl_trans_z_step;
197 double max_z = zmax + vpgl_trans_z_step;
198 if (min_z > initial_pt.
z()) min_z = initial_pt.
z() - vpgl_trans_z_step;
199 if (max_z < initial_pt.
z()) max_z = initial_pt.
z() + vpgl_trans_z_step;
202 initial_point.
set(initial_pt.
x(), initial_pt.
y(), min_z);
203 double xopt=0, yopt=0, zopt = min_z;
204 for (
double z = min_z; z <= max_z; z += vpgl_trans_z_step)
206 double xm = 0, ym = 0;
207 double var = scatter_var(cams, cam_weights, corrs, initial_point, z, xm, ym, relative_diameter);
215 initial_point.
set(xm, ym, z);
216 #ifdef TRANS_ONE_DEBUG 217 std::cout << z <<
'\t' << var <<
'\t' << initial_point <<
'\n';
222 if (zopt == min_z || zopt == max_z)
224 p_3d.
set(xopt, yopt, zopt);
230 std::vector<float>
const& cam_weights,
234 double const& relative_diameter)
238 #ifdef TRANS_ONE_DEBUG 256 elevation[0]=initial_pt.
z();
260 #ifdef TRANS_ONE_DEBUG 263 final_pt.
set(zsf.
xm(), zsf.
ym(), elevation[0]);
273 cam_translations.clear();
275 std::vector<float> cam_weights(cams.size(), 1.0f/cams.size());
281 auto cit = cams.begin();
282 auto rit = corrs.begin();
283 for (; cit!=cams.end() && rit!=corrs.end(); ++cit, ++rit)
288 cam_translations.push_back(t);
301 double const& relative_diameter)
303 cam_translations.clear();
305 std::vector<float> cam_weights(cams.size(), 1.0f/cams.size());
312 auto cit = cams.begin();
313 auto rit = corrs.begin();
314 for (; cit != cams.end() && rit != corrs.end(); ++cit, ++rit)
319 cam_translations.push_back(t);
327 std::vector<float> weights,
332 cam_translations.clear();
338 auto cit = cams.begin();
339 auto rit = corrs.begin();
340 std::vector<float>::const_iterator wit = weights.begin();
341 for (; cit!=cams.end() && rit!=corrs.end(); ++cit, ++rit, ++wit)
344 if ((*wit) == 1.0f) {
346 cam_translations.push_back(t);
352 cam_translations.push_back(t);
365 double const& relative_diameter)
367 cam_translations.clear();
373 auto cit = cams.begin();
374 auto rit = corrs.begin();
375 auto wit = weights.begin();
376 for (; cit != cams.end() && rit != corrs.end(); ++cit, ++rit, ++wit)
379 if ((*wit) == 1.0f) {
381 cam_translations.push_back(t);
387 cam_translations.push_back(t);
void set_f_tolerance(double v)
static bool adjust(std::vector< vpgl_rational_camera< double > > const &cams, std::vector< vgl_point_2d< double > > const &corrs, std::vector< vgl_vector_2d< double > > &cam_translations, vgl_point_3d< double > &intersection)
static bool adjust_with_weights(std::vector< vpgl_rational_camera< double > > const &cams, std::vector< float > weights, std::vector< vgl_point_2d< double > > const &corrs, std::vector< vgl_vector_2d< double > > &cam_translations, vgl_point_3d< double > &intersection)
vgl_homg_point_3d< Type > intersection(l const &l1, l const &l2)
The image offsets of rational cameras typically must be adjusted to compensate for errors in geograph...
void set_verbose(bool verb)
void f(vnl_vector< double > const &elevation, vnl_vector< double > &projection_error) override
The main function.
double relative_diameter_
void set_max_function_evals(int v)
static bool find_intersection_point(std::vector< vpgl_rational_camera< double > > const &cams, std::vector< float > const &cam_weights, std::vector< vgl_point_2d< double > > const &corrs, vgl_point_3d< double > &p_3d)
Find the 3-d point closest to the intersection of rays from >= 2 cameras.
Adjust image offsets to register a set of rational cameras.
void set_epsilon_function(double v)
vgl_point_3d< double > initial_pt_
void diagnose_outcome() const
std::vector< float > cam_weights_
void set(Type px, Type py, Type pz)
std::vector< vgl_point_2d< double > > image_pts_
static bool refine_intersection_pt(std::vector< vpgl_rational_camera< double > > const &cams, std::vector< float > const &cam_weights, std::vector< vgl_point_2d< double > > const &image_pts, vgl_point_3d< double > const &initial_pt, vgl_point_3d< double > &final_pt, double const &relative_diameter=1.0)
bool minimize(vnl_vector< double > &x)
static bool bproj_plane(const vpgl_camera< double > *cam, vnl_double_2 const &image_point, vnl_double_4 const &plane, vnl_double_3 const &initial_guess, vnl_double_3 &world_point, double error_tol=0.05, double relative_diameter=1.0)
Generic camera interfaces (pointer for abstract class).
Methods for back_projecting from cameras to 3-d geometric structures.
std::vector< vpgl_rational_camera< double > > cameras_
void set_x_tolerance(double v)