Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_persp_mes.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2000-18 Pierre SMARS (smars@yuntech.edu.tw)
3  This program is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 #include "a_persp_mes.h"
18 #include "a_2dh.h"
19 #include "a_3dh.h"
20 
21 //---------------------------------------------------------------------------
22 class a_mat_test : public a_mat
23 {
24  public:
25  a_mat_test() : a_mat(3,4) {for (int i = 0; i < 3; i++) (*this)(i,i) = 1;}
26 };
27 //---------------------------------------------------------------------------
29 //---------------------------------------------------------------------------
31 {
32  for (int i = 0; i < 2; i++)
33  p2_[i] = p3_[i] = 0;
34  p3_[2] = 0;
35  ref_pos_ = 0;
36  ref_cam_ = 0;
37 }
38 //---------------------------------------------------------------------------
39 a_persp_mes::a_persp_mes(double mx, double my, double mz, double mu, double mv, int pos, int cam)
40 {
41  p3_[0] = mx; p3_[1] = my; p3_[2] = mz;
42  p2_[0] = mu; p2_[1] = mv;
43  ref_pos_ = pos;
44  ref_cam_ = cam;
45 }
46 //---------------------------------------------------------------------------
47 double a_persp_mes::residual(a_unwarp * unwarp,a_intern * intern, a_pos2 * pos)
48 {
49  double un,vn;
50  unwarp->unwarp(p3_[0],p3_[1],un,vn);
51  a_3dh p3d(p3_[0],p3_[1],p3_[2]);
52  a_mat a = (*pos)*p3d;
53  a_mat b = (*T_)*a;
54  a_mat c = (*intern)*b;
55  double rx = un-c(0,0)/c(2,0);
56  double ry = vn-c(1,0)/c(2,0);
57  return (rx*rx+ry*ry);
58 }
59 //---------------------------------------------------------------------------
60 std::istream& operator>> (std::istream& i, a_persp_mes& l)
61 {
62  for (int k = 0; k < 3; k++)
63  i >> l.p3_[k];
64  for (int k = 0; k < 2; k++)
65  i >> l.p2_[k];
66  i >> l.ref_cam_ >> l.ref_pos_;
67  return i;
68 }
69 //---------------------------------------------------------------------------
70 std::ostream& operator<< (std::ostream& o, const a_persp_mes& l)
71 {
72  for (int k = 0; k < 3; k++)
73  o << l.p3_[k] << " ";
74  for (int k = 0; k < 2; k++)
75  o << l.p2_[k] << " ";
76  o << l.ref_cam_ << " " << l.ref_pos_ << std::endl;
77  return o;
78 }
std::istream & operator>>(std::istream &i, a_persp_mes &l)
Definition: a_persp_mes.cxx:60
std::ostream & operator<<(std::ostream &o, const a_persp_mes &l)
Definition: a_persp_mes.cxx:70
an homogeneous 3d matrix class
Definition: a_3dh.h:30
intern calibration matrix
Definition: a_intern.h:29
Definition: a_mat.h:42
a_persp_mes
Definition: a_persp_mes.h:33
int pos() const
Definition: a_persp_mes.h:41
int cam() const
Definition: a_persp_mes.h:40
double p2_[2]
Definition: a_persp_mes.h:52
static a_mat_test * T_
Definition: a_persp_mes.h:50
double p3_[3]
Definition: a_persp_mes.h:51
double residual(a_unwarp *, a_intern *, a_pos2 *)
Definition: a_persp_mes.cxx:47
a position matrix
Definition: a_pos2.h:29
void unwarp(double u, double v, double &un, double &vn)
Definition: a_unwarp.cxx:18