Skip to content

Commit 2e8a5ae

Browse files
fjonath1cpaxton
authored andcommitted
Add scene graph publisher, fix data compliance check, add sim freq param
1 parent 1d8c3f9 commit 2e8a5ae

11 files changed

+113
-31
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(sequential_scene_parsing)
33

4+
SET(CMAKE_BUILD_TYPE "Debug")
5+
46
## Find catkin macros and libraries
57
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
68
## is used, also find other catkin packages
9+
710
find_package(VTK REQUIRED)
811
find_package(PCL REQUIRED)
912
find_package(Boost REQUIRED)
@@ -30,14 +33,18 @@ find_package(catkin REQUIRED COMPONENTS
3033
sensor_msgs
3134
costar_objrec_msgs
3235
objrec_hypothesis_msgs
33-
std_msgs message_generation
36+
std_msgs geometry_msgs message_generation
3437
)
3538

3639
add_service_files(
3740
FILES hypothesis_request.srv
3841
)
3942

40-
generate_messages( DEPENDENCIES std_msgs )
43+
add_message_files(
44+
FILES SceneNodes.msg StructureGraph.msg SceneGraph.msg
45+
)
46+
47+
generate_messages( DEPENDENCIES std_msgs geometry_msgs)
4148

4249
catkin_package(
4350
# INCLUDE_DIRS include

include/physics_world_parameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define GRAVITY_MAGNITUDE 9.807
1010
static int GRAVITY_SCALE_COMPENSATION = 3;
1111
static double SCALED_GRAVITY_MAGNITUDE = SCALING * GRAVITY_MAGNITUDE / GRAVITY_SCALE_COMPENSATION;
12+
static double SIMULATION_FREQUENCY_MULTIPLIER = 1.;
1213

1314
enum SimulationMode {
1415
// RUN THE SIMULATION UNTIL THE NUMBER OF SIMULATION STEP IS REACHED OR ALL OBJECT IS IN DEACTIVATED STATE

include/ros_sequential_scene_parsing.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include "sequential_scene_parsing.h"
2929
#include "symmetric_orientation_realignment.h"
3030

31+
#include "sequential_scene_parsing/SceneNodes.h"
32+
#include "sequential_scene_parsing/StructureGraph.h"
33+
#include "sequential_scene_parsing/SceneGraph.h"
34+
35+
3136
// Ros bundling for scene parsing
3237
class RosSceneHypothesisAssessor : public SceneHypothesisAssessor
3338
{
@@ -54,6 +59,7 @@ class RosSceneHypothesisAssessor : public SceneHypothesisAssessor
5459
void processHypotheses();
5560
void updateTfFromObjTransformMap(const std::map<std::string, ObjectParameter> &input_tf_map);
5661

62+
sequential_scene_parsing::SceneGraph generateSceneGraphMsgs() const;
5763
// void initialize();
5864
// bool debug_messages_;
5965
bool class_ready_;
@@ -79,6 +85,7 @@ class RosSceneHypothesisAssessor : public SceneHypothesisAssessor
7985
ros::Subscriber background_pcl_sub;
8086
ros::Subscriber scene_pcl_sub;
8187
ros::Publisher done_message_pub;
88+
ros::Publisher scene_graph_pub;
8289

8390
ros::NodeHandle nh_;
8491
tf::TransformListener listener_;

include/scene_physics_engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PhysicsEngine : public PlatformDemoApplication
5757

5858
void setObjectPenaltyDatabase(std::map<std::string, ObjectPenaltyParameters> * penalty_database);
5959

60-
void setSimulationMode(const int &simulation_mode, const double simulation_step = 1./200,
60+
void setSimulationMode(const int &simulation_mode, const double simulation_step = 1./120,
6161
const unsigned int &number_of_world_tick = 100);
6262

6363
void setDebugMode(bool debug);

include/sequential_scene_parsing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class SceneHypothesisAssessor
6666
btScalar(forces_magnitude_per_point),btScalar(max_point_distance_threshold));
6767
}
6868

69+
SceneSupportGraph getSceneGraphData(std::map<std::string, vertex_t> &vertex_map) const;
70+
6971
ObjectDatabase obj_database_;
7072

7173
private:

launch/block_scene.launch

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717
<arg name="objransac_model_directory" default="$(find sequential_scene_parsing)/mesh"/>
1818
<arg name="objransac_model_names" default="wood_cube" />
1919

20-
<arg name="data_forces_magnitude" default="0.25"/>
20+
<arg name="data_forces_magnitude" default="0.15"/>
2121
<arg name="data_forces_max_distance" default="0.015"/>
2222

2323
<arg name="best_hypothesis_only" default="true"/>
24-
<arg name="small_obj_g_comp" default="1"/>
24+
<arg name="small_obj_g_comp" default="5"/>
25+
<arg name="sim_freq_multiplier" default="1."/>
2526

26-
<node pkg="sequential_scene_parsing" type="sequential_scene_ros" name="sequential_scene_ros"
27+
<node pkg="sequential_scene_parsing" type="sequential_scene_ros" name="sequential_scene_parsing"
2728
output="screen"
2829
>
2930
<!-- sequential_scene_ros common Node arg pass -->
3031
<param name="small_obj_g_comp" type="int" value="$(arg small_obj_g_comp)"/>
32+
<param name="sim_freq_multiplier" type="double" value="$(arg sim_freq_multiplier)"/>
3133

3234
<param name="background_pcl2_topic" type="str" value="$(arg background_pcl2_topic)" />
3335
<param name="scene_pcl2_topic" type="str" value="$(arg scene_pcl2_topic)" />

launch/ros_scene.launch

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222

2323
<arg name="best_hypothesis_only" default="false"/>
2424
<arg name="small_obj_g_comp" default="3"/>
25+
<arg name="sim_freq_multiplier" default="1."/>
2526

26-
<node pkg="sequential_scene_parsing" type="sequential_scene_ros" name="sequential_scene_ros"
27+
<node pkg="sequential_scene_parsing" type="sequential_scene_ros" name="sequential_scene_parsing"
2728
output="screen"
2829
>
2930
<!-- sequential_scene_ros common Node arg pass -->
3031
<param name="small_obj_g_comp" type="int" value="$(arg small_obj_g_comp)"/>
32+
<param name="sim_freq_multiplier" type="double" value="$(arg sim_freq_multiplier)"/>
3133

3234
<param name="background_pcl2_topic" type="str" value="$(arg background_pcl2_topic)" />
3335
<param name="scene_pcl2_topic" type="str" value="$(arg scene_pcl2_topic)" />

src/ros_sequential_scene_parsing.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void RosSceneHypothesisAssessor::setNodeHandle(const ros::NodeHandle &nh)
7676

7777
nh.param("best_hypothesis_only",best_hypothesis_only_,false);
7878
nh.param("small_obj_g_comp",GRAVITY_SCALE_COMPENSATION,3);
79+
nh.param("sim_freq_multiplier",SIMULATION_FREQUENCY_MULTIPLIER,1.);
80+
7981
SCALED_GRAVITY_MAGNITUDE = SCALING * GRAVITY_MAGNITUDE / GRAVITY_SCALE_COMPENSATION;
8082

8183
if (load_table){
@@ -104,6 +106,7 @@ void RosSceneHypothesisAssessor::setNodeHandle(const ros::NodeHandle &nh)
104106
this->scene_pcl_sub = this->nh_.subscribe(scene_pcl2_topic,1,&RosSceneHypothesisAssessor::addSceneCloud,this);
105107

106108
this->done_message_pub = this->nh_.advertise<std_msgs::Empty>("done_hypothesis_msg",1);
109+
this->scene_graph_pub = this->nh_.advertise<sequential_scene_parsing::SceneGraph>("scene_structure_list",1);
107110

108111
// setup objrecransac tool
109112
boost::split(object_names,objransac_model_list,boost::is_any_of(","));
@@ -334,6 +337,12 @@ void RosSceneHypothesisAssessor::processDetectedObjectMsgs()
334337
std::cerr << "Getting corrected object transform...\n";
335338
std::map<std::string, ObjectParameter> object_transforms = this->getCorrectedObjectTransform(best_hypothesis_only_);
336339
this->updateTfFromObjTransformMap(object_transforms);
340+
341+
if (best_hypothesis_only_)
342+
{
343+
this->scene_graph_pub.publish(this->generateSceneGraphMsgs());
344+
}
345+
337346
this->mtx_.unlock();
338347

339348
this->has_tf_ = true;
@@ -415,5 +424,44 @@ void RosSceneHypothesisAssessor::processHypotheses()
415424
std_msgs::Empty done_msg;
416425
this->done_message_pub.publish(done_msg);
417426

427+
this->scene_graph_pub.publish(this->generateSceneGraphMsgs());
428+
418429
this->mtx_.unlock();
419430
}
431+
432+
433+
sequential_scene_parsing::SceneGraph RosSceneHypothesisAssessor::generateSceneGraphMsgs() const
434+
{
435+
std::map<std::string, vertex_t> vertex_map;
436+
SceneSupportGraph current_graph = this->getSceneGraphData(vertex_map);
437+
std::vector<vertex_t> all_base_structs = getAllChildVertices(current_graph, vertex_map["background"]);
438+
sequential_scene_parsing::SceneGraph structure_graph_msg;
439+
structure_graph_msg.structure.reserve(all_base_structs.size());
440+
structure_graph_msg.base_objects_id.reserve(all_base_structs.size());
441+
for (std::vector<vertex_t>::const_iterator it = all_base_structs.begin(); it != all_base_structs.end(); ++it)
442+
{
443+
sequential_scene_parsing::StructureGraph new_structure;
444+
OrderedVertexVisitor all_connected_structures = getOrderedVertexList(current_graph, *it, true);
445+
std::map<std::size_t, std::vector<vertex_t> > vertex_visit_by_distances = all_connected_structures.getVertexVisitOrderByDistances();
446+
for (std::map<std::size_t, std::vector<vertex_t> >::const_iterator dist_it = vertex_visit_by_distances.begin();
447+
dist_it != vertex_visit_by_distances.end(); ++dist_it)
448+
{
449+
// Do nothing for disconnected vertices;
450+
if (dist_it->first == 0) continue;
451+
452+
sequential_scene_parsing::SceneNodes nodes;
453+
nodes.object_names.reserve(dist_it->second.size());
454+
for (std::vector<vertex_t>::const_iterator node_it = dist_it->second.begin(); node_it != dist_it->second.end(); ++node_it)
455+
{
456+
nodes.object_names.push_back(current_graph[*node_it].object_id_);
457+
}
458+
new_structure.nodes_level.push_back(nodes);
459+
}
460+
461+
structure_graph_msg.structure.push_back(new_structure);
462+
structure_graph_msg.base_objects_id.push_back(current_graph[*it].object_id_);
463+
}
464+
465+
return structure_graph_msg;
466+
}
467+

src/scene_data_forces.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,14 @@ PointCloudXYZPtr FeedbackDataForcesGenerator::generateCorrespondenceCloud(PointC
346346
{
347347
std::vector< int > k_indices(1);
348348
std::vector< float > distances(1);
349-
this->scene_data_tree_.nearestKSearch(*input_cloud, i, 1, k_indices, distances);
350-
if (!use_filter_distance || (use_filter_distance && distances[0] < max_squared_distance))
349+
350+
// any neighbor is found
351+
if (this->scene_data_tree_.nearestKSearch(*input_cloud, i, 1, k_indices, distances) > 0)
351352
{
352-
nearest_point_correspondence_cloud->points.push_back(scene_data_->points[k_indices[0]]);
353+
if (!use_filter_distance || (use_filter_distance && distances[0] < max_squared_distance))
354+
{
355+
nearest_point_correspondence_cloud->points.push_back(scene_data_->points[k_indices[0]]);
356+
}
353357
}
354358
}
355359
nearest_point_correspondence_cloud->width = nearest_point_correspondence_cloud->size();

src/sequential_scene_hypothesis.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,16 @@ int SequentialSceneHypothesis::updateRemovedObjectStatus(const std::string &obje
153153

154154
// object is not detected by pose estimator
155155
std::cerr << object_name;
156-
// bool object_visible = checkObjectVisible(model_name,object_pose);
157-
// if (object_visible)
158-
// {
159-
// std::cerr << " is visible, thus it will not be removed.\n";
160-
// return NOT_REMOVED;
161-
// }
162-
// else
163-
// {
164-
// std::cerr << " is not visible,";
165-
// }
156+
bool object_visible = checkObjectVisible(model_name,object_pose);
157+
if (object_visible)
158+
{
159+
std::cerr << " is visible, thus it will not be removed.\n";
160+
return NOT_REMOVED;
161+
}
162+
else
163+
{
164+
std::cerr << " is not visible,";
165+
}
166166

167167
bool object_obstructed = checkObjectObstruction(model_name,object_pose);
168168

@@ -220,9 +220,10 @@ bool SequentialSceneHypothesis::checkObjectObstruction(const std::string &model_
220220
bool SequentialSceneHypothesis::checkObjectReplaced(const std::string &object_name,
221221
const std::string &model_name, const btTransform &object_pose)
222222
{
223+
// disabled for now. Will be updated to OBB test instead
224+
return false;
225+
223226
// use AABB to check if the original object volume has been occupied by something else
224-
// TODO: IMPLEMENT THIS!!
225-
// use bullet contactTest;
226227
if (!obj_database_)
227228
{
228229
std::cerr << "Error! Cannot check for replaced objects since no object database has been set.\n";
@@ -247,6 +248,7 @@ bool SequentialSceneHypothesis::checkObjectReplaced(const std::string &object_na
247248
Object target_model = obj_database_->getObjectProperty(model_name);
248249
col_obj->setCollisionShape(target_model.getCollisionShape());
249250
col_obj->setWorldTransform(object_pose);
251+
250252
// Replace AABB with OBB!!
251253
OverlappingObjectSensor result(*col_obj, object_name);
252254
this->physics_engine_->contactTest(col_obj,result);

0 commit comments

Comments
 (0)