Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_pmat.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2010-2019 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_pmat.h"
18 #include <sstream>
19 //---------------------------------------------------------------------------
20 const std::string a_pmat::help()
21 {
22  std::ostringstream o;
23  o << "******" << std::endl;
24  o << "a_pmat" << std::endl;
25  o << "*****" << std::endl;
26  o << "This is a P projective matrix class, representing a camera" << std::endl;
27  o << "3x4 matrix of the form:" << std::endl;
28  o << "----------------------" << std::endl;
29  o << "[p11 p12 p13 p14]" << std::endl;
30  o << "[p21 p22 p23 p24]" << std::endl;
31  o << "[p31 p32 p33 p34]" << std::endl;
32  o << "Commands:" << std::endl;
33  o << "--------" << std::endl;
34  o << "intern a_intern: set the camera (internal calibration)" << std::endl;
35  o << "move a_pos: place the camera in 3D (external calibration)" << std::endl;
36  o << "project a_3dh: project a 3D point (in homogeneous coordinate)" << std::endl;
37  return o.str();
38 }
39 //---------------------------------------------------------------------------
40 a_pmat::a_pmat(const a_intern& cam) : a_mat(3,4)
41 {
42  for (int i = 0; i<3; i++)
43  {
44  for (int j = 0; j<3; j++)
45  (*this)(i,j)= cam(i,j);
46  }
47 }
48 //---------------------------------------------------------------------------
49 a_pmat::a_pmat(const a_mat& m) : a_mat(3,4)
50 {
51  *this = m;
52 }
53 //---------------------------------------------------------------------------
55 {
56  if (m.maxi() != maxi_) throw compatibility_error();
57  if (m.maxj() != maxj_) throw compatibility_error();
58  for (int i = 0; i<3; i++)
59  {
60  for (int j = 0; j<4; j++)
61  (*this)(i,j)= m(i,j);
62  }
63  return (*this);
64 }
65 //---------------------------------------------------------------------------
66 void a_pmat::intern(const a_intern& m)
67 {
68  for (int i = 0; i<3; i++)
69  {
70  for (int j = 0; j<3; j++)
71  (*this)(i,j)= m(i,j);
72  }
73 }
74 //---------------------------------------------------------------------------
75 void a_pmat::move(const a_pos& m)
76 {
77  a_mat m2 = *this;
78  a_mat m3 = m;
79  a_mat m4 = m2*m3;
80  (*this) = m4;
81 }
82 //---------------------------------------------------------------------------
83 a_2dh a_pmat::project(const a_3dh& p3d) const
84 {
85  a_mat m2 = *this;
86  a_mat m3 = p3d;
87  a_mat m4 = m2*m3;
88  return m4;
89 }
an homogeneous 2d matrix class
Definition: a_2dh.h:30
an homogeneous 3d matrix class
Definition: a_3dh.h:30
intern calibration matrix
Definition: a_intern.h:29
Definition: a_mat.h:42
UI maxj_
Definition: a_mat.h:89
UI maxi_
Definition: a_mat.h:88
UI maxi() const
Definition: a_mat.h:49
UI maxj() const
Definition: a_mat.h:50
a projection matrix
Definition: a_pmat.h:32
a_pmat & operator=(const a_mat &m)
Definition: a_pmat.cxx:54
static const std::string help()
Definition: a_pmat.cxx:20
void move(const a_pos &m)
Definition: a_pmat.cxx:75
a_pmat()
Definition: a_pmat.h:34
a_2dh project(const a_3dh &p3d) const
Definition: a_pmat.cxx:83
void intern(const a_intern &in)
Definition: a_pmat.cxx:66
position matrix
Definition: a_pos.h:31