hregions.hh
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2010
4  * Mayte Lázaro, Alejandro R. Mosteo
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef HREGIONS_H_
23 #define HREGIONS_H_
24 
25 #include <vector>
26 #include "scan.hh"
27 #include "types.hh"
28 
30 #define DF (20)
31 #define NALPHAS (6)
32 
33 const double
34 CHISQUARE[DF][NALPHAS] =
35 { { 7.88, 6.63, 5.02, 3.84, 2.71, 1.32 },
36  { 10.6, 9.21, 7.38, 5.99, 4.61, 2.77 },
37  { 12.8, 11.3, 9.35, 7.81, 6.25, 4.11 },
38  { 14.9, 13.3, 11.1, 9.49, 7.78, 5.39 },
39  { 16.7, 15.1, 12.8, 11.1, 9.24, 6.63 },
40  { 18.5, 16.8, 14.4, 12.6, 10.6, 7.84 },
41  { 20.3, 18.5, 16.0, 14.1, 12.0, 9.04 },
42  { 22.0, 20.1, 17.5, 15.5, 13.4, 10.2 },
43  { 23.6, 21.7, 19.0, 16.9, 14.7, 11.4 },
44  { 25.2, 23.2, 20.5, 18.3, 16.0, 12.5 },
45  { 26.8, 24.7, 21.9, 19.7, 17.3, 13.7 },
46  { 28.3, 26.2, 23.3, 21.0, 18.5, 14.8 },
47  { 29.8, 27.7, 24.7, 22.4, 19.8, 16.0 },
48  { 31.3, 29.1, 26.1, 23.7, 21.1, 17.1 },
49  { 32.8, 30.6, 27.5, 25.0, 22.3, 18.2 },
50  { 34.3, 32.0, 28.8, 26.3, 23.5, 19.4 },
51  { 35.7, 33.4, 30.2, 27.6, 24.8, 20.5 },
52  { 37.2, 34.8, 31.5, 28.9, 26.0, 21.6 },
53  { 38.6, 36.2, 32.9, 30.1, 27.2, 22.7 },
54  { 40.0, 37.6, 34.2, 31.4, 28.4, 23.8 }
55 };
56 
57 #define COLUMN(a) ((a) <= 5 ? 0 : ((a) <= 10 ? 1 : ((a) <= 20 ? 2 : ((a) <= 50 ? 3 : ((a) <= 100 ? 4 : 5)))))
58 #define RADIANS(d) ((d)*M_PI/180.0)
59 
60 // see params.hh
61 // const int D_MAX_LOST_PNT = 4;
62 // const double D_LASER_ANG_RES = 0.5;
63 
64 class Endpoint
65 {
66 public:
67  Endpoint(const Scan &s, int idx) : idx_(idx) {}
68 
69  const int idx(void) const { return idx_; }
70 
71  bool operator < (const Endpoint &rhs) const { return idx_ < rhs.idx_; }
72 
73 private:
74  int idx_;
75 };
76 
77 typedef std::vector<Endpoint> EndpointsVector;
78 
79 class HRegion
80 {
81 public:
82  HRegion(const Scan &s, int idxFrom, int idxTo);
83  virtual ~HRegion() {}
84 
85  const int NumEps(void) const { return endpoints_.size(); }
86  const Endpoint &Ep(int i) const { return endpoints_.at(i); }
87 
88  void IterativeLineSplit(int fromIdx, int toIdx);
89  void IterativeLineSplit(void); // Initiator of recursion
90 
91  void PushGuiData(GuiData *gui_data) const;
92 private:
93  GuiRegion GetGuiRegion(void) const;
94  GuiSplit GetGuiSplit(int i) const;
95 
96  const Scan *scan_;
97  EndpointsVector endpoints_;
98 };
99 
100 typedef std::vector<HRegion> RegionsVector;
101 
102 /*
103 #define RG_LEN(r) ((r).len)
104 #define RG_EP2(r, i) ((r).ep[i])
105 #define RG_NUM_EP(r, i) ((r).ep[i].len)
106 #define RG_EP(r, i, j) ((r).ep[i].idx[j])
107 #define RG_FROM(r, i) ((r).ep[i].idx[0])
108 #define RG_TO(r, i) ((r).ep[i].idx[(r).ep[i].len-1])
109 */
110 
111 /*
112 #define HRP(p) ((p).par)
113 #define HRP_MAX_EMPTY_ANGLE(p) ((p).maxEmptyAng)
114 #define HRP_ALPHA_HREG(p) ((p).alphaReg)
115 #define HRP_MIN_PNT_REG(p) ((p).minPntReg)
116 #define HRP_MIN_LEN_REG(p) ((p).minLenReg)
117 
118 #define HRP_ALPHA_ILF(p) ((p).alphaILF)
119 #define HRP_CHECK_RESIDUAL(p) ((p).checkResidual)
120 #define HRP_MIN_DIST_EP(p) ((p).minDistEP)
121 #define HRP_MAX_EBE_ANG(p) ((p).maxAngEBE)
122 */
123 
124 void FindHomogeneousRegions(const Scan &s, RegionsVector *r);
125 void IterativeLineFitting(const Scan &s, RegionsVector *r);
126 
127 #endif /* HREGIONS_H_ */
Definition: types.hh:81
Request to get an integer property.
Definition: player.h:459
#define PLAYER_WARN1(msg, a)
Definition: error.h:90
#define PLAYER_MSG1(level, msg, a)
Definition: error.h:106
#define PLAYER_MSG3(level, msg, a, b, c)
Definition: error.h:108
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
A rectangular bounding box, used to define the size of an object.
Definition: player.h:255
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
Boolean property class.
Definition: property.h:87
double ReadTupleLength(int section, const char *name, int index, double value)
Read a length from a tuple (includes units conversion)
Generic message header.
Definition: player.h:162
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:658
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:664
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
Definition: hregions.hh:80
virtual void Main(void)=0
Main method for driver thread.
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
int32_t value
The property value.
Definition: player.h:465
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
Definition: hregions.hh:65
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
bool ReadBool(int section, const char *name, bool value)
Read a boolean value (one of: yes, no, true, false, 1, 0)
Definition: types.hh:74
Definition: scan.hh:31
Definition: uloc.hh:32
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
#define PLAYER_MSGTYPE_RESP_NACK
A negative response message.
Definition: player.h:125
Integer property class.
Definition: property.h:115
double ReadTupleAngle(int section, const char *name, int index, double value)
Read an angle form a tuple (includes units conversion)
Class for loading configuration file information.
Definition: configfile.h:197
#define PLAYER_CAPABILITIES_REQ
Capability request message type.
Definition: player.h:397
An autopointer for the message queue.
Definition: message.h:74
Double property class.
Definition: property.h:143
#define PLAYER_ERROR1(msg, a)
Definition: error.h:82
A pose in space.
Definition: player.h:229
#define PLAYER_ERROR(msg)
Definition: error.h:81
Base class for drivers which oeprate with a thread.
Definition: driver.h:553
char * key
The property key.
Definition: player.h:463
Base class for all drivers.
Definition: driver.h:109
#define PLAYER_ERROR3(msg, a, b, c)
Definition: error.h:84
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
#define PLAYER_MSG2(level, msg, a, b)
Definition: error.h:107
Definition: types.hh:67
#define PLAYER_SET_INTPROP_REQ
Integer property set request subtype.
Definition: player.h:432
Definition: transf.hh:36
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76