44
44
45
45
#include < yaml-cpp/yaml.h>
46
46
47
+ #include < visualization_msgs/Marker.h>
48
+
47
49
using namespace uima ;
48
50
49
51
/* *
@@ -56,15 +58,15 @@ class RegionFilter : public DrawingAnnotator
56
58
/* *
57
59
* @brief The SemanticMapItem struct
58
60
* transform describing transformation from reference frame to center of region you are definging
59
- * Dimensions are defined on each axis. If defining a regins that should have a supporting plane you
60
- * can optionally add the equation of the plane to the map entry
61
+ * Dimensions are defined on each axis. If defining a regins that should have a supporting plane
62
+ * you can optionally add the equation of the plane to the map entry
61
63
*/
62
64
struct SemanticMapItem
63
65
{
64
66
tf::Transform transform;
65
67
std::string reference_frame;
66
68
std::string name, type;
67
- double y_dimention , z_dimension, x_dimention ;
69
+ double y_dimension , z_dimension, x_dimension ;
68
70
cv::Vec4f plane_eq;
69
71
bool has_plane_equations = false ;
70
72
};
@@ -99,9 +101,56 @@ class RegionFilter : public DrawingAnnotator
99
101
// for frustum culling
100
102
sensor_msgs::CameraInfo camera_info_;
101
103
pcl::visualization::Camera camera;
102
-
103
104
rs::TFListenerProxy listener_;
104
105
double frustum[24 ];
106
+ bool enabled = true ;
107
+
108
+ // Markers for regions:
109
+ std::string marker_topic_;
110
+ bool publish_marker_;
111
+ ros::Publisher marker_publisher_;
112
+
113
+ void publishSemanticMapMarker (const SemanticMapItem& item)
114
+ {
115
+ visualization_msgs::Marker m, m_text;
116
+ m.header .frame_id = m_text.header .frame_id = item.reference_frame ;
117
+ m.header .stamp = m_text.header .stamp = ros::Time::now ();
118
+ m_text.text = item.name ;
119
+
120
+ m.ns = m_text.ns = item.name ;
121
+ m.id = 0 ;
122
+ m_text.id = 1 ;
123
+ m.lifetime = m_text.lifetime = ros::Duration ();
124
+
125
+ m.type = visualization_msgs::Marker::CUBE;
126
+ m_text.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
127
+ m.color .r = 0 .0f ;
128
+ m.color .g = 0 .0f ;
129
+ m.color .b = 1 .0f ;
130
+ m.color .a = 0 .75f ;
131
+ m_text.color .a = 1 ;
132
+
133
+ auto transform = item.transform ;
134
+ auto origin = transform.getOrigin ();
135
+ auto rotation = transform.getRotation ();
136
+
137
+ m.pose .position .x = m_text.pose .position .x = origin.x ();
138
+ m.pose .position .y = m_text.pose .position .y = origin.y ();
139
+ m.pose .position .z = m_text.pose .position .z = origin.z ();
140
+ m.pose .orientation .x = rotation.getX ();
141
+ m.pose .orientation .y = rotation.getY ();
142
+ m.pose .orientation .z = rotation.getZ ();
143
+ m.pose .orientation .w = rotation.getW ();
144
+ m_text.pose .orientation .w = 1 ;
145
+
146
+ m.scale .x = item.x_dimension ;
147
+ m.scale .y = item.y_dimension ;
148
+ m.scale .z = item.z_dimension ;
149
+ m_text.scale .z = 0 .1f ;
150
+
151
+ marker_publisher_.publish (m);
152
+ marker_publisher_.publish (m_text);
153
+ }
105
154
106
155
public:
107
156
RegionFilter ()
@@ -119,7 +168,22 @@ class RegionFilter : public DrawingAnnotator
119
168
, filtered(0 )
120
169
, last_time_(ros::Time::now())
121
170
, timeout(120 )
171
+ , marker_topic_(" perception_marker/regions" )
172
+ , publish_marker_(false )
173
+ {
174
+ }
175
+
176
+ TyErrorId reconfigure ()
122
177
{
178
+ outInfo (" Reconfigure.." );
179
+ AnnotatorContext& ctx = getAnnotatorContext ();
180
+
181
+ if (ctx.isParameterDefined (" enabled" ))
182
+ {
183
+ ctx.extractValue (" enabled" , enabled);
184
+ }
185
+
186
+ return UIMA_ERR_NONE;
123
187
}
124
188
125
189
TyErrorId initialize (AnnotatorContext& ctx)
@@ -162,6 +226,27 @@ class RegionFilter : public DrawingAnnotator
162
226
ctx.extractValue (" semantic_map_definition" , file);
163
227
readSemanticMap (file);
164
228
}
229
+ if (ctx.isParameterDefined (" enabled" ))
230
+ {
231
+ ctx.extractValue (" enabled" , enabled);
232
+ }
233
+
234
+ // Marker for regions:
235
+ if (ctx.isParameterDefined (" publish_marker" ))
236
+ {
237
+ ctx.extractValue (" publish_marker" , publish_marker_);
238
+ }
239
+ if (ctx.isParameterDefined (" marker_topic" ))
240
+ {
241
+ ctx.extractValue (" marker_topic" , marker_topic_);
242
+ }
243
+
244
+ if (publish_marker_)
245
+ {
246
+ ros::NodeHandle n;
247
+ marker_publisher_ = n.advertise <visualization_msgs::Marker>(marker_topic_, 100 );
248
+ }
249
+
165
250
return UIMA_ERR_NONE;
166
251
}
167
252
@@ -200,8 +285,8 @@ class RegionFilter : public DrawingAnnotator
200
285
201
286
item.name = sem_map_entries[i];
202
287
item.type = entry[" type" ].as <std::string>();
203
- item.x_dimention = entry[" depth" ].as <double >(); // X-dim
204
- item.y_dimention = entry[" width" ].as <double >(); // Y-dim
288
+ item.x_dimension = entry[" depth" ].as <double >(); // X-dim
289
+ item.y_dimension = entry[" width" ].as <double >(); // Y-dim
205
290
item.z_dimension = entry[" height" ].as <double >(); // Z-dim
206
291
207
292
if (entry[" reference_frame" ])
@@ -242,6 +327,12 @@ class RegionFilter : public DrawingAnnotator
242
327
private:
243
328
TyErrorId processWithLock (CAS& tcas, ResultSpecification const & res_spec)
244
329
{
330
+ if (!enabled)
331
+ {
332
+ outInfo (" process aborted -> Filter is disabled" );
333
+ return UIMA_ERR_NONE;
334
+ }
335
+
245
336
MEASURE_TIME;
246
337
outInfo (" process begins" );
247
338
rs::SceneCas cas (tcas);
@@ -255,11 +346,16 @@ class RegionFilter : public DrawingAnnotator
255
346
rs::SemanticMapObject obj = rs::create<rs::SemanticMapObject>(tcas);
256
347
obj.name (item.name );
257
348
obj.typeName (item.type );
258
- obj.width (static_cast <double >(item.y_dimention ));
349
+ obj.width (static_cast <double >(item.y_dimension ));
259
350
obj.height (static_cast <double >(item.z_dimension ));
260
- obj.depth (static_cast <double >(item.x_dimention ));
351
+ obj.depth (static_cast <double >(item.x_dimension ));
261
352
obj.transform (rs::conversion::to (tcas, item.transform ));
262
353
semantic_map.push_back (obj);
354
+
355
+ if (publish_marker_)
356
+ {
357
+ publishSemanticMapMarker (item);
358
+ }
263
359
}
264
360
cas.set (VIEW_SEMANTIC_MAP, semantic_map);
265
361
@@ -294,7 +390,7 @@ class RegionFilter : public DrawingAnnotator
294
390
{
295
391
rapidjson::Document json_doc;
296
392
std::string json_string = qs.query ();
297
- json_doc.Parse (json_string);
393
+ json_doc.Parse (json_string. c_str () );
298
394
outWarn (" query in CAS : " << json_string);
299
395
300
396
rapidjson::Pointer frame_pointer_in (" /detect/location" );
@@ -376,7 +472,7 @@ class RegionFilter : public DrawingAnnotator
376
472
plane_model_as_std_vect[3 ] = new_plane_eq[3 ];
377
473
supp_plane.model .set (plane_model_as_std_vect);
378
474
supp_plane.source (" RegionFilter" );
379
- outDebug (" Setting plane eq to CAS: " << new_plane_eq);
475
+ outDebug (" Setting plane eq to CAS: " << new_plane_eq);
380
476
scene.annotations .append (supp_plane);
381
477
}
382
478
}
@@ -480,8 +576,8 @@ class RegionFilter : public DrawingAnnotator
480
576
}
481
577
482
578
// check region bounding box
483
- Eigen::Vector3d bbMin (-(region.y_dimention / 2 ), -(region.z_dimension / 2 ), -(region.x_dimention / 2 ));
484
- Eigen::Vector3d bbMax ((region.y_dimention / 2 ), (region.z_dimension / 2 ), 0.5 );
579
+ Eigen::Vector3d bbMin (-(region.y_dimension / 2 ), -(region.z_dimension / 2 ), -(region.x_dimension / 2 ));
580
+ Eigen::Vector3d bbMax ((region.y_dimension / 2 ), (region.z_dimension / 2 ), 0.5 );
485
581
pcl::visualization::FrustumCull res =
486
582
(pcl::visualization::FrustumCull)pcl::visualization::cullFrustum (tFrustum, bbMin, bbMax);
487
583
return res != pcl::visualization::PCL_OUTSIDE_FRUSTUM;
@@ -557,10 +653,10 @@ class RegionFilter : public DrawingAnnotator
557
653
558
654
void filterRegion (const SemanticMapItem& region)
559
655
{
560
- const float minX = -(region.x_dimention / 2 ) + border_;
561
- const float maxX = (region.x_dimention / 2 ) - border_;
562
- float minY = -(region.y_dimention / 2 ) + border_;
563
- const float maxY = (region.y_dimention / 2 ) - border_;
656
+ const float minX = -(region.x_dimension / 2 ) + border_;
657
+ const float maxX = (region.x_dimension / 2 ) - border_;
658
+ float minY = -(region.y_dimension / 2 ) + border_;
659
+ const float maxY = (region.y_dimension / 2 ) - border_;
564
660
const float minZ = -(region.z_dimension / 2 );
565
661
float maxZ = +(region.z_dimension / 2 );
566
662
@@ -692,7 +788,7 @@ class RegionFilter : public DrawingAnnotator
692
788
tf::vectorTFToEigen (transform.getOrigin (), translation);
693
789
tf::quaternionTFToEigen (transform.getRotation (), rotation);
694
790
695
- visualizer.addCube (translation.cast <float >(), rotation.cast <float >(), region.x_dimention , region.y_dimention ,
791
+ visualizer.addCube (translation.cast <float >(), rotation.cast <float >(), region.x_dimension , region.y_dimension ,
696
792
region.z_dimension , oss.str ());
697
793
visualizer.setRepresentationToWireframeForAllActors ();
698
794
}
0 commit comments