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, (C) IDIAP                                //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
17 ///////////////////////////////////////////////////////////////////////////
18
19 /*
20
21   This class factorizes the information from a PoseCell needed by a
22   PiFeature to be evaluated on an image. Since there can be in there
23   costly operations such as trigonometric mappings, it provides a
24   substantial cost optimization.
25
26 */
27
28 #ifndef PI_REFERENTIAL_H
29 #define PI_REFERENTIAL_H
30
31 #include "rectangle.h"
32 #include "pose_cell.h"
33 #include "rgb_image.h"
34
35 class PiReferential {
36   // The best scale so that the head size is
37   // ~global.reference_head_size. This is an integer scale as defined
38   // for the RichImage
39   int _common_scale;
40
41   scalar_t _horizontal_polarity;
42
43   // The head frame in _common_scale. The vectors are of length the _RADIUS_ of the head
44   scalar_t _head_xc, _head_yc, _head_radius;
45   scalar_t _head_window_scaling;
46   scalar_t _head_ux, _head_uy, _head_vx, _head_vy;
47   scalar_t _head_ux_nopolarity, _head_uy_nopolarity, _head_vx_nopolarity, _head_vy_nopolarity;
48
49   // The body frame in that _common_scale. The vectors are of length the radii of the ellipse
50   scalar_t _body_xc, _body_yc;
51   scalar_t _body_radius_1, _body_radius_2, _body_tilt;
52   scalar_t _body_ux, _body_uy, _body_vx, _body_vy;
53 //   scalar_t _body_window_scaling;
54   int _body_edge_shift;
55
56   // The belly frame is defined by the body location and head scale
57   scalar_t _belly_xc, _belly_yc;
58   scalar_t _belly_ux, _belly_uy, _belly_vx, _belly_vy;
59   scalar_t _belly_ux_nopolarity, _belly_uy_nopolarity, _belly_vx_nopolarity, _belly_vy_nopolarity;
60   scalar_t _belly_window_scaling;
61
62   // The head-belly frame is defined by the head location and the body
63   // center location
64   scalar_t _head_belly_xc, _head_belly_yc;
65   scalar_t _head_belly_ux, _head_belly_uy, _head_belly_vx, _head_belly_vy;
66   int _head_belly_edge_shift;
67
68   void draw_frame(RGBImage *image,
69                   int registration_mode,
70                   int x1, int y1,
71                   int x2, int y2,
72                   int x3, int y3,
73                   int x4, int y4);
74
75 public:
76   PiReferential(PoseCell *cell);
77
78   enum {
79     // A frame centered on the head, of size four times the head radius
80     // and, flipped verically if the body center is on the left of the
81     // head center
82     RM_HEAD,
83
84     // Same as above, without the flipping
85     RM_HEAD_NO_POLARITY,
86     // A frame centered on the body center, of size size times the
87     // head rardius, flipped vertically if the body center is on the
88     // left of the head center
89     RM_BELLY,
90
91     // Same as above, without the flipping
92     RM_BELLY_NO_POLARITY,
93
94     // A frame centered on the middle point between the head center
95     // and the body center, of size twice the distance head center -
96     // body center in the head-body direction, and of four times the
97     // head radius in the other
98     RM_HEAD_BELLY,
99
100     // Same as above with rotation of the edges
101     RM_HEAD_BELLY_EDGES,
102   };
103
104   int common_scale();
105
106   // The rectangle coordinates are in the reference frames. For the
107   // head for instance , [-1,1] x [-1,1] corresponds to the head
108   // bounding box
109
110   void register_rectangle(int registration_mode,
111                           Rectangle *original,
112                           Rectangle *result);
113
114   int register_edge(int registration_type, int edge_type);
115
116   void draw(RGBImage *image, int level);
117
118   void draw_window(RGBImage *image,
119                    int registration_mode, Rectangle *window,
120                    int filled);
121
122   void draw_edge_and_scale(RGBImage *image,
123                            int registration_mode, Rectangle *window,
124                            int _tag, int _edge_scale);
125
126   static void print_registration_mode(ostream *out, int registration_mode);
127 };
128
129 #endif