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