00001 #include "shape_reconstruction/ShapeRecPlotter.h"
00002
00003 #include <pcl/conversions.h>
00004 #include <pcl/io/pcd_io.h>
00005 #include <pcl/filters/filter_indices.h>
00006 #include <sensor_msgs/Image.h>
00007
00008 #include <opencv2/imgproc/imgproc.hpp>
00009 #include <opencv2/video/tracking.hpp>
00010 #include <opencv2/highgui/highgui.hpp>
00011 #include <opencv2/video/tracking.hpp>
00012
00013 #include <pcl_conversions/pcl_conversions.h>
00014
00015 #include <ros/package.h>
00016
00017 #include <cmath>
00018
00019 #include <ros/console.h>
00020
00021 #include "shape_reconstruction/RangeImagePlanar.hpp"
00022
00023 #include <pcl/point_cloud.h>
00024 #include <pcl/point_types.h>
00025 #include <pcl/io/pcd_io.h>
00026 #include <pcl/visualization/pcl_visualizer.h>
00027 #include <pcl/filters/passthrough.h>
00028
00029 #include <boost/filesystem.hpp>
00030 #include <ctime>
00031
00032 #include <std_msgs/Bool.h>
00033
00034 #include <iostream>
00035 #include <pcl/common/common.h>
00036 #include <pcl/io/pcd_io.h>
00037 #include <pcl/io/ply_io.h>
00038 #include <pcl/search/kdtree.h>
00039 #include <pcl/features/normal_3d_omp.h>
00040 #include <pcl/point_types.h>
00041 #include <pcl/surface/mls.h>
00042 #include <pcl/surface/poisson.h>
00043 #include <pcl/surface/marching_cubes.h>
00044 #include <pcl/surface/marching_cubes_rbf.h>
00045 #include <pcl/surface/marching_cubes_hoppe.h>
00046 #include <pcl/surface/ear_clipping.h>
00047 #include <pcl/surface/vtk_smoothing/vtk_mesh_smoothing_laplacian.h>
00048 #include <pcl/surface/vtk_smoothing/vtk_mesh_smoothing_windowed_sinc.h>
00049 #include <pcl/surface/vtk_smoothing/vtk_mesh_subdivision.h>
00050 #include <pcl/filters/passthrough.h>
00051
00052 #include <pcl/io/vtk_lib_io.h>
00053 #include <pcl/visualization/pcl_visualizer.h>
00054
00055
00056 #include <vcg/complex/complex.h>
00057 #include <vcg/complex/all_types.h>
00058 #include <vcg/complex/algorithms/clean.h>
00059
00060 #include <vcg/complex/algorithms/update/bounding.h>
00061 #include <vcg/complex/algorithms/update/normal.h>
00062 #include <vcg/complex/algorithms/update/topology.h>
00063
00064 #include <pcl/surface/convex_hull.h>
00065 #include <pcl/surface/concave_hull.h>
00066
00067 #include <pcl/filters/normal_refinement.h>
00068
00069 #include <pcl/surface/simplification_remove_unused_vertices.h>
00070
00071 #include <sensor_msgs/PointCloud2.h>
00072 #include <geometry_msgs/TransformStamped.h>
00073
00074 #include <pcl_ros/transforms.h>
00075
00076
00077 using namespace omip;
00078
00079 ShapeRecPlotter::ShapeRecPlotter()
00080 {
00081 std::string topic_name = std::string("");
00082
00083 ROS_INFO_STREAM_NAMED("ShapeRecPlotter","topic_name: " << topic_name);
00084 this->_pc_subscriber = this->_node_handle.subscribe(topic_name, 1,
00085 &ShapeRecPlotter::InputPCmeasurementCallback, this);
00086
00087 std::string topic_name2 = std::string("moved_pc");
00088 this->_pc_publisher = this->_node_handle.advertise<sensor_msgs::PointCloud2>(topic_name2,10, true);
00089
00090 this->_current_pc.reset(new SRPointCloud());
00091
00092
00093
00094 _tf_listener = new tf::TransformListener();
00095
00096 }
00097
00098 ShapeRecPlotter::~ShapeRecPlotter()
00099 {
00100 }
00101
00102 void ShapeRecPlotter::plotShape()
00103 {
00104 if(_current_pc->size())
00105 {
00106 sensor_msgs::PointCloud2 pc2, pcout;
00107
00108 pcl::toROSMsg(*this->_current_pc, pc2);
00109
00110 _tf_listener->waitForTransform("/camera_rgb_optical_frame", "/ip/rb2", ros::Time(0), ros::Duration(0.1));
00111
00112 bool nooo = false;
00113 tf::StampedTransform tfTransform;
00114 try{
00115
00116 _tf_listener->lookupTransform ("/camera_rgb_optical_frame", "/ip/rb2",ros::Time(0), tfTransform);
00117
00118 }catch(...){
00119 nooo = true;
00120 std::cout << "." << std::endl ;
00121 }
00122
00123 if(!nooo)
00124 {
00125 std::cout << std::endl ;
00126 Eigen::Matrix4f transform;
00127 transform(0,0) = tfTransform.getBasis()[0][0];
00128 transform(0,1) = tfTransform.getBasis()[0][1];
00129 transform(0,2) = tfTransform.getBasis()[0][2];
00130 transform(1,0) = tfTransform.getBasis()[1][0];
00131 transform(1,1) = tfTransform.getBasis()[1][1];
00132 transform(1,2) = tfTransform.getBasis()[1][2];
00133 transform(2,0) = tfTransform.getBasis()[2][0];
00134 transform(2,1) = tfTransform.getBasis()[2][1];
00135 transform(2,2) = tfTransform.getBasis()[2][2];
00136 transform(0,3) = tfTransform.getOrigin()[0];
00137 transform(1,3) = tfTransform.getOrigin()[1];
00138 transform(2,3) = tfTransform.getOrigin()[2];
00139 transform(3,0) = 0;
00140 transform(3,1) = 0;
00141 transform(3,2) = 0;
00142 transform(3,3) = 1;
00143
00144 std::cout << transform << std::endl;
00145 pcl_ros::transformPointCloud(transform, pc2, pcout);
00146
00147 _pc_publisher.publish(pcout);
00148 }else{
00149 std::cout << std::endl ;
00150 Eigen::Matrix4f transform;
00151 transform(0,0) = 1;
00152 transform(0,1) = 0;
00153 transform(0,2) = 0;
00154 transform(1,0) = 0;
00155 transform(1,1) = 1;
00156 transform(1,2) = 0;
00157 transform(2,0) = 0;
00158 transform(2,1) = 0;
00159 transform(2,2) = 1;
00160 transform(0,3) = 0;
00161 transform(1,3) = 0;
00162 transform(2,3) = 0;
00163 transform(3,0) = 0;
00164 transform(3,1) = 0;
00165 transform(3,2) = 0;
00166 transform(3,3) = 1;
00167 pcl_ros::transformPointCloud(transform, pc2, pcout);
00168
00169 _pc_publisher.publish(pcout);
00170 }
00171 }
00172
00173 }
00174
00175 void ShapeRecPlotter::InputPCmeasurementCallback(const sensor_msgs::PointCloud2ConstPtr &pc_msg)
00176 {
00177 std::cout << "received" << std::endl;
00178
00179 pcl::fromROSMsg(*pc_msg, *this->_current_pc);
00180
00181 }
00182
00183
00184 int main(int argc, char** argv)
00185 {
00186 ros::init(argc, argv, "ShapeRecPlotter");
00187 ShapeRecPlotter sr_node;
00188
00189 ros::Rate r(30);
00190 while (ros::ok())
00191 {
00192 ros::spinOnce();
00193 sr_node.plotShape();
00194 r.sleep();
00195 }
00196
00197 std::cout << " Shutting down ShapeRecPlotter " << std::endl;
00198
00199 return (0);
00200 }