Fawkes API  Fawkes Development Version
qa_hom_transform.cpp
1 
2 /***************************************************************************
3  * qa_matrix.cpp - DESC
4  *
5  * Created: Fri Feb 13 14:31:48 2009
6  * Copyright 2009 Christof Rath <christof.rath@gmail.com>
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 /// @cond EXAMPLES
23 
24 #include <geometry/hom_transform.h>
25 #include <geometry/hom_point.h>
26 #include <utils/time/tracker.h>
27 
28 #include <iostream>
29 #include <cmath>
30 
31 using namespace fawkes;
32 using namespace std;
33 
34 int
35 main(int argc, char **argv)
36 {
37  TimeTracker *tt = new TimeTracker();
38  unsigned int loop_count = 0;
39  unsigned int ttc_trans = tt->add_class("Tra");
40  unsigned int ttc_rot = tt->add_class("Rot");
41  unsigned int ttc_inv = tt->add_class("Inv");
42 
43  HomTransform ht;
44  for (loop_count = 0; loop_count < 10; ++loop_count) {
45  tt->ping_start(ttc_trans);
46  ht.trans(1, 2, 3);
47  tt->ping_end(ttc_trans);
48 
49  tt->ping_start(ttc_rot);
50  ht.rotate_x(M_PI_2);
51  tt->ping_end(ttc_rot);
52 
53  tt->ping_start(ttc_trans);
54  ht.trans(1, 2, 3);
55  tt->ping_end(ttc_trans);
56 
57  tt->ping_start(ttc_rot);
58  ht.rotate_y(23);
59  tt->ping_end(ttc_rot);
60 
61  tt->ping_start(ttc_trans);
62  ht.trans(1, 2, 3);
63  tt->ping_end(ttc_trans);
64 
65  tt->ping_start(ttc_rot);
66  ht.rotate_z(M_PI_2);
67  tt->ping_end(ttc_rot);
68 
69  tt->ping_start(ttc_inv);
70  ht.invert();
71  tt->ping_end(ttc_inv);
72 
73  tt->ping_start(ttc_inv);
74  ht.invert();
75  tt->ping_end(ttc_inv);
76  }
77 
78  ht.print_info("HomTransform");
79  HomPoint p0 = HomPoint(0.1f, 0.2f, 0.3f);
80  cout << "0: " << p0 << endl << endl << endl;
81 
82  HomPoint p = ht * p0;
83  cout << "p: " << p << endl << endl << endl;
84 
85  ht.invert().print_info("HomTransform inverted");
86  p0 = ht * p;
87  cout << "0': " << p0 << endl << endl << endl;
88 
89  ht.invert().print_info("HomTransform");
90  tt->print_to_stdout();
91 
92  ht *= ht;
93 
94  delete tt;
95 }
96 
97 
98 /// @endcond
void ping_start(unsigned int cls)
Start of given class task.
Definition: tracker.cpp:228
void trans(float dx, float dy, float dz=0.0)
Add translation to the transformation.
Fawkes library namespace.
STL namespace.
void rotate_z(float rad)
Add rotation around the z-axis.
This class describes a homogeneous transformation.
Definition: hom_transform.h:31
A homogeneous point.
Definition: hom_point.h:33
unsigned int add_class(std::string name)
Add a new class.
Definition: tracker.cpp:156
Time tracking utility.
Definition: tracker.h:38
void print_info(const char *name=0, const char *col_sep=0, const char *row_sep=0) const
Prints the matrix.
void ping_end(unsigned int cls)
End of given class task.
Definition: tracker.cpp:254
void rotate_y(float rad)
Add rotation around the y-axis.
void print_to_stdout()
Print results to stdout.
Definition: tracker.cpp:317
virtual HomTransform & invert()
Invert the transformation.
void rotate_x(float rad)
Add rotation around the x-axis.