Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <cob_3d_segmentation/eval.h>
00009
00010 #ifndef PCL_VERSION_COMPARE
00011 #define KDTREE pcl::KdTreeFLANN
00012 #else
00013 #define KDTREE pcl::search::KdTree
00014 #endif
00015
00016
00017 template <typename Point, typename PointTypeNormal, typename PointLabel>
00018 bool Segmentation_MarchingCubes<Point, PointTypeNormal, PointLabel>::compute() {
00019 pcl::PolygonMesh mesh;
00020
00021 pcl::NormalEstimation<Point, PointTypeNormal> norm_est;
00022 boost::shared_ptr<pcl::PointCloud<PointTypeNormal> > pointcloudNormal (new pcl::PointCloud<PointTypeNormal>);
00023 boost::shared_ptr<KDTREE<Point> > tree (new KDTREE<Point>);
00024 tree->setInputCloud (input_);
00025 norm_est.setInputCloud (input_);
00026 norm_est.setSearchMethod (tree);
00027 norm_est.setKSearch (30);
00028 norm_est.compute (*pointcloudNormal);
00029
00030
00031 pcl::copyPointCloud (*input_, *pointcloudNormal);
00032
00033
00034 boost::shared_ptr<KDTREE<PointTypeNormal> > tree2 (new KDTREE<PointTypeNormal>);
00035 tree2->setInputCloud (pointcloudNormal);
00036
00037
00038 pcl::MARCHING_CUBES_INST<PointTypeNormal> mc;
00039
00040 #ifdef USE_GREEDY
00041 mc.setLeafSize(leafSize_);
00042 #else
00043 mc.setOffSurfaceDisplacement(leafSize_);
00044 mc.setGridResolution(1,1,1);
00045 mc.setPercentageExtendGrid(0.01f);
00046 #endif
00047 mc.setIsoLevel(isoLevel_);
00048 mc.setSearchMethod(tree2);
00049 mc.setInputCloud(pointcloudNormal);
00050
00051 mc.reconstruct (mesh);
00052
00053 mesh_ = mesh;
00054
00055
00056 std::cout<<mesh_.polygons.size()<<"\n";
00057
00058 return true;
00059 }
00060
00061 template <typename Point, typename PointTypeNormal, typename PointLabel>
00062 boost::shared_ptr<const pcl::PointCloud<PointLabel> > Segmentation_MarchingCubes<Point, PointTypeNormal, PointLabel>::getReconstructedOutputCloud() {
00063 boost::shared_ptr<pcl::PointCloud<PointLabel> > cloud (new pcl::PointCloud<PointLabel>);
00064 cloud->header = input_->header;
00065
00066 pcl::PointCloud<pcl::PointXYZ> tmp;
00067 pcl::fromROSMsg(mesh_.cloud, tmp);
00068
00069 pcl::copyPointCloud (tmp, *cloud);
00070
00071 return cloud;
00072 }
00073
00074 template <typename Point, typename PointTypeNormal, typename PointLabel>
00075 void Segmentation_MarchingCubes<Point, PointTypeNormal, PointLabel>::compute_accuracy(float &mean, float &var, size_t &used, size_t &mem, size_t &points, float &avg_dist) {
00076 RunningStat rstat;
00077 points = 0;
00078 avg_dist = 0;
00079 mem = 0;
00080
00081 pcl::PointCloud<pcl::PointXYZ> tmp;
00082 pcl::fromROSMsg(mesh_.cloud, tmp);
00083
00084 for(size_t j=0; j<input_->size(); j++) {
00085 Eigen::Vector3f s = (*input_)[j].getVector3fMap();
00086
00087 float dmax = std::numeric_limits<float>::max();
00088 for(size_t i=0; i<mesh_.polygons.size(); i++) {
00089 Eigen::Vector3f a,b,c,d;
00090
00091 a = tmp[mesh_.polygons[i].vertices[0]].getVector3fMap();
00092 b = tmp[mesh_.polygons[i].vertices[1]].getVector3fMap();
00093 c = tmp[mesh_.polygons[i].vertices[2]].getVector3fMap();
00094
00095 float x = (s-a).dot(b-a)/(b-a).squaredNorm();
00096 float y = (s-a).dot(c-a)/(c-a).squaredNorm();
00097
00098 if(x<0 || x>1 || y<0 || y>1) continue;
00099
00100 d = (b-a).cross(c-a);
00101 float t = std::abs(d.dot(s-a))/d.norm();
00102
00103 dmax = std::min(dmax,t);
00104
00105
00106 }
00107
00108 if(dmax<0.5) {
00109 mem+= 3*3*4;
00110 rstat.Push(dmax);
00111 }
00112
00113 if(pcl_isfinite(s(2))) {
00114 avg_dist += s(2);
00115 ++points;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 }
00149
00150
00151 used = rstat.NumDataValues();
00152
00153 mean = rstat.Mean();
00154 var = rstat.Variance();
00155 avg_dist /= points;
00156 used = tmp.size();
00157 }