automatic commit
[folded-ctf.git] / pi_referential.h
1
2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify  //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation.                         //
6 //                                                                       //
7 // This program is distributed in the hope that it will be useful, but   //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of            //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
10 // General Public License for more details.                              //
11 //                                                                       //
12 // You should have received a copy of the GNU General Public License     //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>.  //
14 //                                                                       //
15 // Written by Francois Fleuret                                           //
16 // (C) Idiap Research Institute                                          //
17 //                                                                       //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
19 ///////////////////////////////////////////////////////////////////////////
20
21 /*
22
23   This class factorizes the information from a PoseCell needed by a
24   PiFeature to be evaluated on an image. Since there can be in there
25   costly operations such as trigonometric mappings, it provides a
26   substantial cost optimization.
27
28 */
29
30 #ifndef PI_REFERENTIAL_H
31 #define PI_REFERENTIAL_H
32
33 #include "rectangle.h"
34 #include "pose_cell.h"
35 #include "rgb_image.h"
36
37 class PiReferential {
38   // The best scale so that the head size is
39   // ~global.reference_head_size. This is an integer scale as defined
40   // for the RichImage
41   int _common_scale;
42
43   scalar_t _horizontal_polarity;
44
45   // The head frame in _common_scale. The vectors are of length the _RADIUS_ of the head
46   scalar_t _head_xc, _head_yc, _head_radius;
47   scalar_t _head_window_scaling;
48   scalar_t _head_ux, _head_uy, _head_vx, _head_vy;
49   scalar_t _head_ux_nopolarity, _head_uy_nopolarity, _head_vx_nopolarity, _head_vy_nopolarity;
50
51   //**********************************************************************
52   // Useless fields, but they are necessary so that the optimized code
53   // with g++ gives the same results as some reference
54   // experiments. Sorry for that.
55   scalar_t _body_xc, _body_yc;
56   scalar_t _body_tilt;
57   //**********************************************************************
58
59   // The belly frame is defined by the belly location and head scale
60   scalar_t _belly_xc, _belly_yc;
61   scalar_t _belly_ux, _belly_uy, _belly_vx, _belly_vy;
62   scalar_t _belly_ux_nopolarity, _belly_uy_nopolarity, _belly_vx_nopolarity, _belly_vy_nopolarity;
63   scalar_t _belly_window_scaling;
64
65   // The head-belly frame is defined by the head location and the belly
66   scalar_t _head_belly_xc, _head_belly_yc;
67   scalar_t _head_belly_ux, _head_belly_uy, _head_belly_vx, _head_belly_vy;
68   int _head_belly_edge_shift;
69
70   void draw_frame(RGBImage *image,
71                   int registration_mode,
72                   int x1, int y1,
73                   int x2, int y2,
74                   int x3, int y3,
75                   int x4, int y4);
76
77 public:
78   PiReferential(PoseCell *cell);
79
80   enum {
81     // A square frame centered on the head, of size four times the
82     // head radius and, flipped horizontally if the belly is on the
83     // left of the head center
84     RM_HEAD,
85
86     // Same as above, without the flipping
87     RM_HEAD_NO_POLARITY,
88
89     // A frame centered on the belly, of size eight times the head
90     // radius, flipped horizontally if the belly is on the left of the
91     // head center
92     RM_BELLY,
93
94     // Same as above, without the flipping
95     RM_BELLY_NO_POLARITY,
96
97     // A frame centered on the middle point between the head center
98     // and the belly, of size twice the distance head center - belly
99     // in the head-belly direction, and of four times the head radius
100     // in the other
101     RM_HEAD_BELLY,
102
103     // Same as above with rotation of the edges
104     RM_HEAD_BELLY_EDGES
105   };
106
107   int common_scale();
108
109   // The rectangle coordinates are in the reference frames. For the
110   // head for instance [-0.5, 0.5] x [-0.5, 0.5] corresponds to the
111   // head bounding box
112
113   void register_rectangle(int registration_mode,
114                           Rectangle *original,
115                           Rectangle *result);
116
117   int register_edge(int registration_type, int edge_type);
118
119   void draw(RGBImage *image, int level);
120
121   void draw_window(RGBImage *image,
122                    int registration_mode, Rectangle *window,
123                    int filled);
124
125   static void print_registration_mode(ostream *out, int registration_mode);
126 };
127
128 #endif