2 #ifndef vpgl_ray_intersect_hxx_ 3 #define vpgl_ray_intersect_hxx_ 16 # include <vcl_msvc_warnings.h> 27 unsigned num_residuals);
53 unsigned num_residuals) :
56 f_cameras_(std::move(cams)),
57 f_image_pts_(std::move(image_pts))
70 std::size_t dim = static_cast<unsigned int>(image_errors.
size() / 2);
74 for (
unsigned i=0; i<image_errors.
size(); i++)
75 image_errors.
put(i, huge);
78 double intersection_point_x = intersection_point[0];
79 double intersection_point_y = intersection_point[1];
80 double intersection_point_z = intersection_point[2];
82 std::cout <<
"Error Vector (" << intersection_point_x <<
", " 83 << intersection_point_y <<
", " << intersection_point_z <<
") = ";
86 for (
unsigned image_no = 0; image_no < dim; image_no++)
90 double image_u = f_image_pts_[image_no].x(),
91 image_v = f_image_pts_[image_no].y();
93 T cur_image_u, cur_image_v;
94 cam->
project(intersection_point_x, intersection_point_y,
95 intersection_point_z, cur_image_u, cur_image_v);
97 image_errors.
put(2*image_no,
98 (cur_image_u - image_u));
99 image_errors.
put(2*image_no+1,
100 (cur_image_v - image_v));
102 std::cout <<
" x_err = " << cur_image_u <<
'-' << image_u <<
'=' 103 << image_errors[2*image_no]
104 <<
" y_err = " << cur_image_v <<
'-' << image_v <<
'=' 105 << image_errors[2*image_no+1];
133 std::cerr <<
"The dimension is too small. There must be at least 2 images" 139 if (cams.size() != dim_)
141 std::cerr <<
"Please provide correct number of cameras" <<
'\n';
146 if (image_pts.size() != dim_)
148 std::cerr <<
"Please provide correct number of image points" <<
'\n';
154 f_image_pts_ = image_pts;
160 std::cout <<
"Created LevenbergMarquardt minimizer ... setting tolerances\n";
176 vnl_double_3 intersection_pt;
177 intersection_pt[0]=initial_intersection.
x();
178 intersection_pt[1]=initial_intersection.
y();
179 intersection_pt[2]=initial_intersection.
z();
182 std::cout <<
"Initialized the intersection point " << intersection_pt
183 <<
" ... minimizing\n";
191 std::cout <<
"Min error of " << levmarq.
get_end_error() <<
" at " 192 <<
'(' << intersection_pt[0] <<
", " << intersection_pt[1]
193 <<
", " << intersection_pt[2] <<
")\n" 206 #define VPGL_RAY_INTERSECT_INSTANTIATE(T) \ 207 template class vpgl_ray_intersect<T >; 210 #endif // vpgl_ray_intersect_hxx_ void set_f_tolerance(double v)
vgl_homg_point_3d< Type > intersection(l const &l1, l const &l2)
int get_num_iterations() const
bool intersect(std::vector< const vpgl_camera< T > * > const &cams, std::vector< vgl_point_2d< T > > const &image_pts, vgl_point_3d< T > const &initial_intersection, vgl_point_3d< T > &intersection)
Intersect the rays. return false if intersection fails.
double get_end_error() const
int get_num_evaluations() const
vpgl_ray_intersect_lsqr()
void set_verbose(bool verb)
void f(vnl_vector< double > const &intersection_point, vnl_vector< double > &image_errors) override
The main function.
virtual void trace(int iteration, vnl_vector< double > const &x, vnl_vector< double > const &fx)
void set_max_function_evals(int v)
void put(size_t i, double const &v)
vpgl_ray_intersect(unsigned dim)
Find the 3-d point closest to the intersection of rays from >= 2 cameras.
std::vector< vgl_point_2d< T > > f_image_pts_
void set_epsilon_function(double v)
virtual void project(const T x, const T y, const T z, T &u, T &v) const =0
The generic camera interface. u represents image column, v image row.
void diagnose_outcome() const
std::vector< const vpgl_camera< T > * > f_cameras_
bool minimize(vnl_vector< double > &x)
~vpgl_ray_intersect_lsqr() override=default
Destructor.
void set_x_tolerance(double v)