Go to the documentation of this file.00001
00060
00061
00062
00063
00064
00065 #include <ros/ros.h>
00066 #include <tf/transform_listener.h>
00067 #include <visualization_msgs/Marker.h>
00068
00069 #include <Eigen/Geometry>
00070 #include <tf_conversions/tf_eigen.h>
00071 #include <dynamic_reconfigure/server.h>
00072 #include <cob_3d_fov_segmentation/field_of_viewConfig.h>
00073 #include <cob_3d_fov_segmentation/field_of_view.h>
00074
00075 using namespace tf;
00076 using namespace cob_3d_mapping;
00077
00081 class FieldOfViewNode
00082 {
00083 public:
00087 FieldOfViewNode ()
00088 {
00089 config_server_.setCallback (boost::bind (&FieldOfViewNode::dynReconfCallback, this, _1, _2));
00090 fov_marker_pub_ = n_.advertise<visualization_msgs::Marker> ("fov_marker", 1);
00091
00092 }
00093
00095 ~FieldOfViewNode ()
00096 {
00098 }
00099
00101 void
00102 dynReconfCallback (cob_3d_fov_segmentation::field_of_viewConfig &config, uint32_t level)
00103 {
00104 fov_.setSensorFoV_hor (config.sensor_fov_hor_angle);
00105 fov_.setSensorFoV_ver (config.sensor_fov_ver_angle);
00106 fov_.setSensorMaxRange (config.sensor_max_range);
00107 camera_frame_ = config.camera_frame;
00108 target_frame_ = config.target_frame;
00109
00110
00111 fov_.computeFieldOfView ();
00112 }
00113
00124 void
00125 transformFOV ()
00126 {
00127
00128 StampedTransform st_trf;
00129 try
00130 {
00131 tf_listener_.waitForTransform (target_frame_, camera_frame_, ros::Time (0), ros::Duration (0.1));
00132 tf_listener_.lookupTransform (target_frame_, camera_frame_, ros::Time (0), st_trf);
00133 }
00134 catch (TransformException ex)
00135 {
00136 ROS_ERROR ("%s", ex.what ());
00137 }
00138 Eigen::Affine3d trafo;
00139 transformTFToEigen (st_trf, trafo);
00140 fov_.transformFOV (trafo);
00141 publishMarker ();
00142 }
00143
00154 void
00155 publishMarker ()
00156 {
00157 Eigen::Vector3d p_0;
00158 Eigen::Vector3d p_1;
00159 Eigen::Vector3d p_2;
00160 Eigen::Vector3d p_3;
00161 Eigen::Vector3d p_4;
00162 fov_.getFOV (p_0, p_1, p_2, p_3, p_4);
00163
00164 visualization_msgs::Marker marker;
00165 marker.header.frame_id = target_frame_;
00166 marker.header.stamp = ros::Time::now ();
00167
00168
00169 marker.action = visualization_msgs::Marker::ADD;
00170 marker.type = visualization_msgs::Marker::LINE_LIST;
00171 marker.lifetime = ros::Duration ();
00172 marker.scale.x = 0.01;
00173 marker.points.resize (16);
00174
00175 marker.points[0].x = p_0 (0);
00176 marker.points[0].y = p_0 (1);
00177 marker.points[0].z = p_0 (2);
00178
00179 marker.points[1].x = p_1 (0);
00180 marker.points[1].y = p_1 (1);
00181 marker.points[1].z = p_1 (2);
00182
00183 marker.points[2].x = p_0 (0);
00184 marker.points[2].y = p_0 (1);
00185 marker.points[2].z = p_0 (2);
00186
00187 marker.points[3].x = p_2 (0);
00188 marker.points[3].y = p_2 (1);
00189 marker.points[3].z = p_2 (2);
00190
00191 marker.points[4].x = p_0 (0);
00192 marker.points[4].y = p_0 (1);
00193 marker.points[4].z = p_0 (2);
00194
00195 marker.points[5].x = p_3 (0);
00196 marker.points[5].y = p_3 (1);
00197 marker.points[5].z = p_3 (2);
00198
00199 marker.points[6].x = p_0 (0);
00200 marker.points[6].y = p_0 (1);
00201 marker.points[6].z = p_0 (2);
00202
00203 marker.points[7].x = p_4 (0);
00204 marker.points[7].y = p_4 (1);
00205 marker.points[7].z = p_4 (2);
00206
00207 marker.points[8].x = p_1 (0);
00208 marker.points[8].y = p_1 (1);
00209 marker.points[8].z = p_1 (2);
00210
00211 marker.points[9].x = p_2 (0);
00212 marker.points[9].y = p_2 (1);
00213 marker.points[9].z = p_2 (2);
00214
00215 marker.points[10].x = p_2 (0);
00216 marker.points[10].y = p_2 (1);
00217 marker.points[10].z = p_2 (2);
00218
00219 marker.points[11].x = p_3 (0);
00220 marker.points[11].y = p_3 (1);
00221 marker.points[11].z = p_3 (2);
00222
00223 marker.points[12].x = p_3 (0);
00224 marker.points[12].y = p_3 (1);
00225 marker.points[12].z = p_3 (2);
00226
00227 marker.points[13].x = p_4 (0);
00228 marker.points[13].y = p_4 (1);
00229 marker.points[13].z = p_4 (2);
00230
00231 marker.points[14].x = p_4 (0);
00232 marker.points[14].y = p_4 (1);
00233 marker.points[14].z = p_4 (2);
00234
00235 marker.points[15].x = p_1 (0);
00236 marker.points[15].y = p_1 (1);
00237 marker.points[15].z = p_1 (2);
00238
00239 marker.color.r = 1.0;
00240 marker.color.g = 0.0;
00241 marker.color.b = 0.0;
00242 marker.color.a = 1.0;
00243
00244 fov_marker_pub_.publish (marker);
00245 }
00246
00247 protected:
00248 ros::NodeHandle n_;
00249 ros::Publisher fov_marker_pub_;
00250
00251 TransformListener tf_listener_;
00252 dynamic_reconfigure::Server<cob_3d_fov_segmentation::field_of_viewConfig> config_server_;
00253
00254 std::string camera_frame_;
00255 std::string target_frame_;
00256
00257 FieldOfView fov_;
00258
00259 };
00260
00261 int
00262 main (int argc, char** argv)
00263 {
00264 ros::init (argc, argv, "field_of_view");
00265
00266 FieldOfViewNode fov;
00267
00268 ros::Rate loop_rate (10);
00269 while (ros::ok ())
00270 {
00271 ros::spinOnce ();
00272 fov.transformFOV ();
00273 loop_rate.sleep ();
00274 }
00275 }
00276