visualization.cpp
Go to the documentation of this file.
00001 #include <sparse_bundle_adjustment/visualization.h>
00002 
00003 namespace sba {
00004 
00005 void drawGraph(const SysSBA &sba, const ros::Publisher &camera_pub,
00006                const ros::Publisher &point_pub, int decimation, int bicolor)
00007 {
00008   int num_points = sba.tracks.size();
00009   int num_cameras = sba.nodes.size();
00010   if (num_points == 0 && num_cameras == 0) return;
00011   
00012   visualization_msgs::Marker camera_marker, point_marker;
00013   camera_marker.header.frame_id = "/pgraph";
00014   camera_marker.header.stamp = ros::Time::now();
00015   camera_marker.ns = "pgraph";
00016   camera_marker.id = 0;
00017   camera_marker.action = visualization_msgs::Marker::ADD;
00018   camera_marker.pose.position.x = 0;
00019   camera_marker.pose.position.y = 0;
00020   camera_marker.pose.position.z = 0;
00021   camera_marker.pose.orientation.x = 0.0;
00022   camera_marker.pose.orientation.y = 0.0;
00023   camera_marker.pose.orientation.z = 0.0;
00024   camera_marker.pose.orientation.w = 1.0;
00025   camera_marker.scale.x = 0.02;
00026   camera_marker.scale.y = 0.02;
00027   camera_marker.scale.z = 0.02;
00028   camera_marker.color.r = 0.0f;
00029   camera_marker.color.g = 1.0f;
00030   camera_marker.color.b = 1.0f;
00031   camera_marker.color.a = 1.0f;
00032   camera_marker.lifetime = ros::Duration();
00033   camera_marker.type = visualization_msgs::Marker::LINE_LIST;
00034 
00035   point_marker = camera_marker;
00036   point_marker.color.r = 1.0f;
00037   point_marker.color.g = 0.0f;
00038   point_marker.color.b = 0.0f;
00039   point_marker.color.a = 0.5f;
00040   point_marker.scale.x = 0.02;
00041   point_marker.scale.y = 0.02;
00042   point_marker.scale.z = 0.02;
00043   point_marker.type = visualization_msgs::Marker::POINTS;
00044 
00045   // draw points, decimated
00046   point_marker.points.resize((int)(num_points/(double)decimation + 0.5));
00047   point_marker.colors.resize((int)(num_points/(double)decimation + 0.5));
00048   for (int i=0, ii=0; i < num_points; i += decimation, ii++)
00049     {
00050       const Vector4d &pt = sba.tracks[i].point;
00051       point_marker.colors[ii].r = 1.0f;
00052       if (bicolor > 0 && i >= bicolor)
00053         point_marker.colors[ii].g = 1.0f;
00054       else
00055         point_marker.colors[ii].g = 0.0f;
00056       point_marker.colors[ii].b = 0.0f;
00057       point_marker.points[ii].x = pt(2);
00058       point_marker.points[ii].y = -pt(0);
00059       point_marker.points[ii].z = -pt(1);
00060     }
00061 
00062   // draw cameras
00063   camera_marker.points.resize(num_cameras*6);
00064   for (int i=0, ii=0; i < num_cameras; i++)
00065     {
00066       const Node &nd = sba.nodes[i];
00067       Vector3d opt;
00068       Matrix<double,3,4> tr;
00069       transformF2W(tr,nd.trans,nd.qrot);
00070 
00071       camera_marker.points[ii].x = nd.trans.z();
00072       camera_marker.points[ii].y = -nd.trans.x();
00073       camera_marker.points[ii++].z = -nd.trans.y();
00074       opt = tr*Vector4d(0,0,0.3,1);
00075       camera_marker.points[ii].x = opt.z();
00076       camera_marker.points[ii].y = -opt.x();
00077       camera_marker.points[ii++].z = -opt.y();
00078 
00079       camera_marker.points[ii].x = nd.trans.z();
00080       camera_marker.points[ii].y = -nd.trans.x();
00081       camera_marker.points[ii++].z = -nd.trans.y();
00082       opt = tr*Vector4d(0.2,0,0,1);
00083       camera_marker.points[ii].x = opt.z();
00084       camera_marker.points[ii].y = -opt.x();
00085       camera_marker.points[ii++].z = -opt.y();
00086 
00087       camera_marker.points[ii].x = nd.trans.z();
00088       camera_marker.points[ii].y = -nd.trans.x();
00089       camera_marker.points[ii++].z = -nd.trans.y();
00090       opt = tr*Vector4d(0,0.1,0,1);
00091       camera_marker.points[ii].x = opt.z();
00092       camera_marker.points[ii].y = -opt.x();
00093       camera_marker.points[ii++].z = -opt.y();
00094     }
00095 
00096   // draw point-plane projections
00097   int num_tracks = sba.tracks.size();
00098   int ii = camera_marker.points.size();
00099 
00100   for (int i=0; i < num_tracks; i++)
00101     {
00102       const ProjMap &prjs = sba.tracks[i].projections;
00103       for (ProjMap::const_iterator itr = prjs.begin(); itr != prjs.end(); itr++)
00104         {
00105           const Proj &prj = (*itr).second;
00106           if (prj.pointPlane)   // have a ptp projection
00107             {
00108               camera_marker.points.resize(ii+2);
00109               Point pt0 = sba.tracks[i].point;
00110               Vector3d plane_point = prj.plane_point;
00111               Vector3d plane_normal = prj.plane_normal;
00112               Eigen::Vector3d w = pt0.head<3>()-plane_point;
00113               //              Eigen::Vector3d projpt = plane_point+(w.dot(plane_normal))*plane_normal;
00114               Eigen::Vector3d projpt = pt0.head<3>() - (w.dot(plane_normal))*plane_normal;
00115               //              Vector3d pt1 = pt0.head<3>()+0.1*plane_normal;
00116               Vector3d pt1 = projpt;
00117                   
00118               camera_marker.points[ii].x = pt0.z();
00119               camera_marker.points[ii].y = -pt0.x();
00120               camera_marker.points[ii++].z = -pt0.y();
00121               camera_marker.points[ii].x = pt1.z();
00122               camera_marker.points[ii].y = -pt1.x();
00123               camera_marker.points[ii++].z = -pt1.y();
00124             }
00125         } 
00126     }
00127 
00128   camera_pub.publish(camera_marker);
00129   point_pub.publish(point_marker);
00130 }
00131 
00132 } // namespace sba


sparse_bundle_adjustment
Author(s):
autogenerated on Wed Aug 24 2016 03:37:37