visualization.cpp
Go to the documentation of this file.
1 /*
2  * visualiser.cpp
3  *
4  * Created on: May 7, 2012
5  * Author: sdries
6  */
7 
8 
9 #include "ros/ros.h"
10 #include "tf/transform_listener.h"
11 
12 // World model messages
13 #include "wire_msgs/WorldEvidence.h"
14 #include "wire_msgs/WorldState.h"
15 
16 // Visualizer class
17 #include "Visualizer.h"
18 
19 // Conversions
20 #include "problib/conversions.h"
21 
22 using namespace std;
23 
25 
26 // Visualizer instances for world model input and output
29 
30 // Marker publishers
33 
34 // Marker frame
35 string marker_frame_ = "";
36 const string DEFAULT_MARKER_FRAME = "/map";
37 
38 
39 /*
40  * World evidence callback. Creates a marker for each of the world model objects
41  */
42 void worldEvidenceCallback(const wire_msgs::WorldEvidence::ConstPtr& msg) {
43 
44  // ID for marker administration
45  long ID = 0;
46 
47  // Iterate over all elements of evidence
48  for (vector<wire_msgs::ObjectEvidence>::const_iterator it = msg->object_evidence.begin(); it != msg->object_evidence.end(); ++it) {
49 
50  // Get current evidence
51  const wire_msgs::ObjectEvidence& obj_ev = *it;
52 
53  // Create marker
54  visualization_msgs::MarkerArray markers_msg;
55  world_evidence_visualizer_.createMarkers(msg->header, ID++, obj_ev.properties, markers_msg.markers, marker_frame_);
56 
57  // Publish marker
58  world_evidence_marker_pub_.publish(markers_msg);
59 
60  }
61 }
62 
63 
64 /*
65  * World state callback. Creates a marker for each detection.
66  */
67 void worldStateCallback(const wire_msgs::WorldState::ConstPtr& msg) {
68 
69 
70  // Iterate over world state objects
71  for (vector<wire_msgs::ObjectState>::const_iterator it = msg->objects.begin(); it != msg->objects.end(); ++it) {
72 
73  // Get current object
74  const wire_msgs::ObjectState& obj = *it;
75 
76  // Create marker
77  visualization_msgs::MarkerArray markers_msg;
78  world_state_visualizer_.createMarkers(msg->header, obj.ID, obj.properties, markers_msg.markers, marker_frame_);
79 
80  // Publish marker
81  world_state_marker_pub_.publish(markers_msg);
82 
83  }
84 }
85 
86 
87 /*
88  * Loads the marker frame from the parameter server. Uses the default frame is it is not defined.
89  */
91 
92  // Get marker frame from the parameter server
93  XmlRpc::XmlRpcValue marker_frame;
94  if (!n.getParam("marker_frame", marker_frame)) {
95  ROS_WARN("No marker_frame defined, using default frame");
96  return false;
97  }
98 
99  // Check if the marker frame is of type string
100  if (marker_frame.getType() != XmlRpc::XmlRpcValue::TypeString) {
101  ROS_ERROR("Parameter marker_frame must be of type string, using default frame");
102  return false;
103  }
104 
105  // Store marker frame
106  marker_frame_ = (string)marker_frame;
107 
108  return true;
109 }
110 
111 
112 
113 int main(int argc, char **argv) {
114  ros::init(argc, argv, "wire_viz");
115  ros::NodeHandle n("~");
116 
117  // Set parameters for visualizers
118  if (!world_evidence_visualizer_.setParameters(n, "world_evidence")) {
119  return 0;
120  }
121  if (!world_state_visualizer_.setParameters(n, "world_state")) {
122  return 0;
123  }
124 
125  // Set tf listeners
126  tf::TransformListener tf_listener;
127  world_evidence_visualizer_.setTFListener(&tf_listener);
128  world_state_visualizer_.setTFListener(&tf_listener);
129 
130  // Get marker frame from parameter server
132 
133  // Subscribe to world evidence and world state topics
134  ros::Subscriber sub_world_ev = n.subscribe("/world_evidence", 10, &worldEvidenceCallback);
135  ros::Subscriber sub_world_st = n.subscribe("/world_state", 10, &worldStateCallback);
136 
137  // Advertise to marker topics
138  world_evidence_marker_pub_ = n.advertise<visualization_msgs::MarkerArray>("/visualization_markers/world_evidence", 10);
139  world_state_marker_pub_ = n.advertise<visualization_msgs::MarkerArray>("/visualization_markers/world_state", 10);
140 
141  ros::spin();
142  return 0;
143 }
int main(int argc, char **argv)
void worldStateCallback(const wire_msgs::WorldState::ConstPtr &msg)
void publish(const boost::shared_ptr< M > &message) const
Visualizer world_state_visualizer_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setTFListener(tf::TransformListener *tf_listener)
Definition: Visualizer.cpp:220
Type const & getType() const
#define ROS_WARN(...)
ROSCPP_DECL void spin(Spinner &spinner)
bool setParameters(ros::NodeHandle &n, const std::string &ns)
Definition: Visualizer.cpp:310
void worldEvidenceCallback(const wire_msgs::WorldEvidence::ConstPtr &msg)
Visualizer world_evidence_visualizer_
const string DEFAULT_MARKER_FRAME
const_iterator(const field< oT > &in_M, const bool at_end=false)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
string marker_frame_
bool createMarkers(const std_msgs::Header &header, long ID, const std::vector< wire_msgs::Property > &props, std::vector< visualization_msgs::Marker > &markers_out, const std::string &frame_id)
Definition: Visualizer.cpp:38
bool getParam(const std::string &key, std::string &s) const
bool getMarkerFrame(ros::NodeHandle &n)
ros::Publisher world_evidence_marker_pub_
ros::Publisher world_state_marker_pub_
#define ROS_ERROR(...)


wire_viz
Author(s): Sjoerd van den Dries, Jos Elfring
autogenerated on Fri Apr 16 2021 02:32:41