Skip to content

Commit 05f2679

Browse files
authored
Merge pull request #215 from evankapi/region_marker
RegionFilter with markers (all test are working and region_markers are working too)
2 parents b6c0f21 + bb7efd3 commit 05f2679

File tree

2 files changed

+116
-18
lines changed

2 files changed

+116
-18
lines changed

robosherlock/descriptors/annotators/filter/RegionFilter.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ parameters:
1919
global_threshold: 0.12
2020
pixel_threshold: 0.15
2121
semantic_map_definition: "semantic_map_iai_kitchen.yaml"
22-
22+
# Markers:
23+
publish_marker: true
24+
marker_topic: "robosherlock/region_markers"

robosherlock/src/filter/src/RegionFilter.cpp

+113-17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#include <yaml-cpp/yaml.h>
4646

47+
#include <visualization_msgs/Marker.h>
48+
4749
using namespace uima;
4850

4951
/**
@@ -56,15 +58,15 @@ class RegionFilter : public DrawingAnnotator
5658
/**
5759
* @brief The SemanticMapItem struct
5860
* 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
6163
*/
6264
struct SemanticMapItem
6365
{
6466
tf::Transform transform;
6567
std::string reference_frame;
6668
std::string name, type;
67-
double y_dimention, z_dimension, x_dimention;
69+
double y_dimension, z_dimension, x_dimension;
6870
cv::Vec4f plane_eq;
6971
bool has_plane_equations = false;
7072
};
@@ -99,9 +101,56 @@ class RegionFilter : public DrawingAnnotator
99101
// for frustum culling
100102
sensor_msgs::CameraInfo camera_info_;
101103
pcl::visualization::Camera camera;
102-
103104
rs::TFListenerProxy listener_;
104105
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+
}
105154

106155
public:
107156
RegionFilter()
@@ -119,7 +168,22 @@ class RegionFilter : public DrawingAnnotator
119168
, filtered(0)
120169
, last_time_(ros::Time::now())
121170
, timeout(120)
171+
, marker_topic_("perception_marker/regions")
172+
, publish_marker_(false)
173+
{
174+
}
175+
176+
TyErrorId reconfigure()
122177
{
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;
123187
}
124188

125189
TyErrorId initialize(AnnotatorContext& ctx)
@@ -162,6 +226,27 @@ class RegionFilter : public DrawingAnnotator
162226
ctx.extractValue("semantic_map_definition", file);
163227
readSemanticMap(file);
164228
}
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+
165250
return UIMA_ERR_NONE;
166251
}
167252

@@ -200,8 +285,8 @@ class RegionFilter : public DrawingAnnotator
200285

201286
item.name = sem_map_entries[i];
202287
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
205290
item.z_dimension = entry["height"].as<double>(); // Z-dim
206291

207292
if (entry["reference_frame"])
@@ -242,6 +327,12 @@ class RegionFilter : public DrawingAnnotator
242327
private:
243328
TyErrorId processWithLock(CAS& tcas, ResultSpecification const& res_spec)
244329
{
330+
if (!enabled)
331+
{
332+
outInfo("process aborted -> Filter is disabled");
333+
return UIMA_ERR_NONE;
334+
}
335+
245336
MEASURE_TIME;
246337
outInfo("process begins");
247338
rs::SceneCas cas(tcas);
@@ -255,11 +346,16 @@ class RegionFilter : public DrawingAnnotator
255346
rs::SemanticMapObject obj = rs::create<rs::SemanticMapObject>(tcas);
256347
obj.name(item.name);
257348
obj.typeName(item.type);
258-
obj.width(static_cast<double>(item.y_dimention));
349+
obj.width(static_cast<double>(item.y_dimension));
259350
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));
261352
obj.transform(rs::conversion::to(tcas, item.transform));
262353
semantic_map.push_back(obj);
354+
355+
if (publish_marker_)
356+
{
357+
publishSemanticMapMarker(item);
358+
}
263359
}
264360
cas.set(VIEW_SEMANTIC_MAP, semantic_map);
265361

@@ -294,7 +390,7 @@ class RegionFilter : public DrawingAnnotator
294390
{
295391
rapidjson::Document json_doc;
296392
std::string json_string = qs.query();
297-
json_doc.Parse(json_string);
393+
json_doc.Parse(json_string.c_str());
298394
outWarn("query in CAS : " << json_string);
299395

300396
rapidjson::Pointer frame_pointer_in("/detect/location");
@@ -376,7 +472,7 @@ class RegionFilter : public DrawingAnnotator
376472
plane_model_as_std_vect[3] = new_plane_eq[3];
377473
supp_plane.model.set(plane_model_as_std_vect);
378474
supp_plane.source("RegionFilter");
379-
outDebug("Setting plane eq to CAS: "<<new_plane_eq);
475+
outDebug("Setting plane eq to CAS: " << new_plane_eq);
380476
scene.annotations.append(supp_plane);
381477
}
382478
}
@@ -480,8 +576,8 @@ class RegionFilter : public DrawingAnnotator
480576
}
481577

482578
// 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);
485581
pcl::visualization::FrustumCull res =
486582
(pcl::visualization::FrustumCull)pcl::visualization::cullFrustum(tFrustum, bbMin, bbMax);
487583
return res != pcl::visualization::PCL_OUTSIDE_FRUSTUM;
@@ -557,10 +653,10 @@ class RegionFilter : public DrawingAnnotator
557653

558654
void filterRegion(const SemanticMapItem& region)
559655
{
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_;
564660
const float minZ = -(region.z_dimension / 2);
565661
float maxZ = +(region.z_dimension / 2);
566662

@@ -692,7 +788,7 @@ class RegionFilter : public DrawingAnnotator
692788
tf::vectorTFToEigen(transform.getOrigin(), translation);
693789
tf::quaternionTFToEigen(transform.getRotation(), rotation);
694790

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,
696792
region.z_dimension, oss.str());
697793
visualizer.setRepresentationToWireframeForAllActors();
698794
}

0 commit comments

Comments
 (0)