-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawLaser.cpp
More file actions
executable file
·160 lines (131 loc) · 5.33 KB
/
DrawLaser.cpp
File metadata and controls
executable file
·160 lines (131 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* @file DrawTelemeter.cpp
* @ingroup Drawing
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
* @copyright All right reserved.
*/
#include "DrawLaser.h"
#include "DrawingTools.h"
#include "Json/json_spirit.h"
#include <System/SimpleList.h>
#include <Messaging/Serializable.h>
using namespace cv;
using namespace MobileRGBD;
/**
* @class TelemeterInfo DrawLaserData.cpp
* @brief Unserialize JSON Data from laser timestamp file
*
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
*/
class TelemeterInfo : public Omiscid::Serializable
{
public:
float FirstAngle; /*!< First angle of the laser range finder */
float LastAngle; /*!< Last angle of the laser range finder */
float Step; /*!< Step between angles of the laser range finder */
int NbEchos; /*!< Number of laser echos */
Omiscid::SimpleList<float> LaserMap; /*!< NbEchos float values ordered from First angle to last angle */
/* @brief DeclareSerializeMapping declare association between Values and key string in JSON. Will be used
both for serialization and unserialiazation.
*/
virtual void DeclareSerializeMapping()
{
AddToSerialization( "FirstAngle", FirstAngle );
AddToSerialization( "LastAngle", LastAngle );
AddToSerialization( "Step", Step );
AddToSerialization( "NbEchos", NbEchos );
AddToSerialization( "LaserMap", LaserMap );
}
};
void DrawLaserData::Draw(float FirstAngle, float LastAngle, float Step, int NbEchos, Omiscid::SimpleList<float>& LaserMap, cv::Mat& WhereToDraw, int DrawingMode /*= PointToLine*/ )
{
#ifdef KINECT_2
double CurrentAngle;
int x,y;
Point Origin(WhereToDraw.cols/2,2*WhereToDraw.rows/3);
// Draw Kinect Infrared, Depth, Body
CurrentAngle = -70.6/2*Step;
const double DepthViewMax = 4.5;
x = X_CoordonateToPixelCentered(DepthViewMax*sin(CurrentAngle), WhereToDraw.cols);
y = Y_CoordonateToPixelCentered(-DepthViewMax*cos(CurrentAngle), WhereToDraw.rows);
Point P1(x,y);
CurrentAngle =70.6/2*Step;
x = X_CoordonateToPixelCentered(DepthViewMax*sin(CurrentAngle), WhereToDraw.cols);
y = Y_CoordonateToPixelCentered(-DepthViewMax*cos(CurrentAngle), WhereToDraw.rows);
Point P2(x,y);
// Draw Kinect RGB
CurrentAngle = -87.5/2*Step;
x = X_CoordonateToPixelCentered(10*sin(CurrentAngle), WhereToDraw.cols);
y = Y_CoordonateToPixelCentered(-10*cos(CurrentAngle), WhereToDraw.rows);
// cv::line( WhereToDraw, Origin, Point(x,y) ,CV_RGB(0,255,0), 2 );
CurrentAngle =87.5/2*Step;
x = X_CoordonateToPixelCentered(10*sin(CurrentAngle), WhereToDraw.cols);
y = Y_CoordonateToPixelCentered(-10*cos(CurrentAngle), WhereToDraw.rows);
// cv::line( WhereToDraw, Origin, Point(x,y) ,CV_RGB(0,255,0), 2 );
#else
// Draw Kinect
double CurrentAngle = FirstAngle + 100*Step;
int x = X_CoordonateToPixelCentered(10*sin(CurrentAngle), WhereToDraw.cols);
int y = Y_CoordonateToPixelCentered(-10*cos(CurrentAngle), WhereToDraw.rows);
cv::line( WhereToDraw, Point(WhereToDraw.cols/2,2*WhereToDraw.rows/3), Point(x,y) ,CV_RGB(0,255,0), 2 );
CurrentAngle = FirstAngle + 167*Step;
x = X_CoordonateToPixelCentered(10*sin(CurrentAngle), WhereToDraw.cols);
y = Y_CoordonateToPixelCentered(-10*cos(CurrentAngle), WhereToDraw.rows);
cv::line( WhereToDraw, Point(WhereToDraw.cols/2,2*WhereToDraw.rows/3), Point(x,y) ,CV_RGB(0,255,0), 2 );
#endif
switch( DrawingMode )
{
case PointToLine:
{
CurrentAngle = FirstAngle;
Point Precedent(WhereToDraw.cols/2,2*WhereToDraw.rows/3);
for( LaserMap.First(); LaserMap.NotAtEnd(); LaserMap.Next() )
{
double value = LaserMap.GetCurrent();
if ( value >= 10.0 )
{
// value = 10.0;
}
int x = X_CoordonateToPixelCentered(value*sin(CurrentAngle), WhereToDraw.cols );
int y = Y_CoordonateToPixelCentered(-value*cos(CurrentAngle), WhereToDraw.rows);
Point Courant(x,y);
cv::line( WhereToDraw, Precedent, Courant, CV_RGB(255,0,0), 2 );
Precedent = Courant;
CurrentAngle += Step;
}
cv::line( WhereToDraw, Precedent, Point(WhereToDraw.cols/2,2*WhereToDraw.rows/3), CV_RGB(255,0,0), 2 );
break;
}
case PointCloud:
{
CurrentAngle = FirstAngle;
for( LaserMap.First(); LaserMap.NotAtEnd(); LaserMap.Next() )
{
double value = LaserMap.GetCurrent();
if ( value >= 10.0 )
{
// value = 10.0;
}
int x = X_CoordonateToPixelCentered(value*sin(CurrentAngle), WhereToDraw.cols );
int y = Y_CoordonateToPixelCentered(-value*cos(CurrentAngle), WhereToDraw.rows);
Point Courant(x,y);
cv::circle( WhereToDraw, Courant, 2, CV_RGB(255,0,0), -1 );
CurrentAngle += Step;
}
break;
}
}
}
/** @brief ProcessElement is a callback function called by mother classes when data are ready.
*
* @param RequestTimestamp [in] The timestamp of the data.
* @param UserData [in] User pointer to working data. Here a pointer to a cv:Mat to draw in.
*/
bool DrawLaserData::ProcessElement( const TimeB &RequestTimestamp, void * UserData )
{
cv::Mat& WhereToDraw = *((cv::Mat*)UserData);
TelemeterInfo LaserData;
LaserData.Unserialize(Omiscid::SimpleString(DataBuffer));
Draw(LaserData.FirstAngle, LaserData.LastAngle, LaserData.Step, LaserData.NbEchos, LaserData.LaserMap, WhereToDraw, CurrentDrawingMode );
return true;
}