Skip to content

Commit a12a242

Browse files
Fix RayTracing (#86)
2 parents 74a6a54 + badb752 commit a12a242

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

ed_sensor_integration/src/kinect/kinect_plugin.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
#include <ros/node_handle.h>
66

7-
#include <ed/uuid.h>
8-
#include <ed/world_model.h>
97
#include <ed/entity.h>
8+
#include <ed/error_context.h>
109
#include <ed/update_request.h>
10+
#include <ed/uuid.h>
11+
#include <ed/world_model.h>
1112

1213
#include <tue/config/reader.h>
1314

@@ -31,18 +32,21 @@
3132

3233
KinectPlugin::KinectPlugin()
3334
{
35+
ed::ErrorContext errc("RGBDPlugin", "constructor");
3436
}
3537

3638
// ----------------------------------------------------------------------------------------------------
3739

3840
KinectPlugin::~KinectPlugin()
3941
{
42+
ed::ErrorContext errc("RGBDPlugin", "destructor");
4043
}
4144

4245
// ----------------------------------------------------------------------------------------------------
4346

4447
void KinectPlugin::initialize(ed::InitData& init)
4548
{
49+
ed::ErrorContext errc("RGBDPlugin", "initialize");
4650
tue::Configuration& config = init.config;
4751

4852
std::string topic;
@@ -69,6 +73,7 @@ void KinectPlugin::initialize(ed::InitData& init)
6973

7074
void KinectPlugin::process(const ed::PluginInput& data, ed::UpdateRequest& req)
7175
{
76+
ed::ErrorContext errc("RGBDPlugin", "process");
7277
// - - - - - - - - - - - - - - - - - -
7378
// Fetch kinect image and pose
7479

@@ -94,6 +99,7 @@ void KinectPlugin::process(const ed::PluginInput& data, ed::UpdateRequest& req)
9499

95100
bool KinectPlugin::srvGetImage(ed_sensor_integration_msgs::GetImage::Request& req, ed_sensor_integration_msgs::GetImage::Response& res)
96101
{
102+
ed::ErrorContext errc("RGBDPlugin", "srvGetImage");
97103
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98104
// Get new image
99105

@@ -147,6 +153,7 @@ bool KinectPlugin::srvGetImage(ed_sensor_integration_msgs::GetImage::Request& re
147153

148154
bool KinectPlugin::srvUpdate(ed_sensor_integration_msgs::Update::Request& req, ed_sensor_integration_msgs::Update::Response& res)
149155
{
156+
ed::ErrorContext errc("RGBDPlugin", "srvUpdate");
150157
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
151158
// Get new image
152159

@@ -203,6 +210,7 @@ bool KinectPlugin::srvUpdate(ed_sensor_integration_msgs::Update::Request& req, e
203210

204211
bool KinectPlugin::srvRayTrace(ed_sensor_integration_msgs::RayTrace::Request& req, ed_sensor_integration_msgs::RayTrace::Response& res)
205212
{
213+
ed::ErrorContext errc("RGBDPlugin", "srvRayTrace");
206214
if (req.raytrace_pose.header.frame_id != "/map" && req.raytrace_pose.header.frame_id != "map")
207215
{
208216
ROS_ERROR("KinectPlugin::srvRayTrace only works with poses expressed in map frame");

ed_sensor_integration/src/kinect/ray_tracer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "ray_tracer.h"
22

3-
#include <ed/world_model.h>
43
#include <ed/entity.h>
4+
#include <ed/error_context.h>
5+
#include <ed/world_model.h>
56

67
#include <geolib/Shape.h>
78

@@ -47,6 +48,8 @@ class PointRenderResult : public geo::LaserRangeFinder::RenderResult
4748

4849
RayTraceResult ray_trace(const ed::WorldModel& world, const geo::Pose3D& raytrace_pose)
4950
{
51+
ed::ErrorContext errc("ray_trace");
52+
const geo::Pose3D raytrace_pose_inv = raytrace_pose.inverse();
5053
PointRenderResult res;
5154

5255
geo::LaserRangeFinder lrf;
@@ -61,7 +64,7 @@ RayTraceResult ray_trace(const ed::WorldModel& world, const geo::Pose3D& raytrac
6164
{
6265
const ed::EntityConstPtr& e = *it;
6366

64-
if (!e->visual() || !e->has_pose())
67+
if ((!e->collision() && !e->visual()) || !e->has_pose())
6568
continue;
6669

6770
res.active_entity_ = e->id().str();
@@ -73,15 +76,16 @@ RayTraceResult ray_trace(const ed::WorldModel& world, const geo::Pose3D& raytrac
7376
{
7477
ROS_DEBUG("Raytrace on_top_of array of %s included", e->id().c_str());
7578
geo::LaserRangeFinder::RenderOptions opt;
76-
opt.setMesh(shape->getMesh(), raytrace_pose.inverse() * e->pose());
79+
opt.setMesh(shape->getMesh(), raytrace_pose_inv * e->pose());
7780

7881
lrf.render(opt, res);
7982
}
8083
}
8184

82-
ROS_DEBUG_STREAM("Raytracing to " << e->id() << " mesh");
85+
ROS_DEBUG_STREAM("Raytracing to " << e->id() << " " << (e->collision() ? "collision" : "visual") << " mesh");
8386
geo::LaserRangeFinder::RenderOptions opt;
84-
opt.setMesh(e->collision()->getMesh(), raytrace_pose.inverse() * e->pose()); // Use mesh
87+
geo::ShapeConstPtr shape = e->collision() ? e->collision() : e->visual();
88+
opt.setMesh(shape->getMesh(), raytrace_pose_inv * e->pose()); // Use mesh
8589

8690
lrf.render(opt, res);
8791
}

0 commit comments

Comments
 (0)