Go to the documentation of this file.00001
00063 #ifndef __IMPL_CLUSTER_HANDLER_HPP__
00064 #define __IMPL_CLUSTER_HANDLER_HPP__
00065
00066 #include "cob_3d_segmentation/cluster_handler.h"
00067
00068
00069 template<typename LabelT, typename PointT, typename PointNT> void
00070 cob_3d_segmentation::DepthClusterHandler<LabelT,PointT,PointNT>::computeClusterComponents(ClusterPtr c)
00071 {
00072 Eigen::Matrix3f cov = Eigen::Matrix3f::Zero();
00073 Eigen::Vector3f centroid = c->getCentroid();
00074 for (ClusterType::iterator idx = c->begin(); idx != c->end(); ++idx)
00075 {
00076 Eigen::Vector3f demean = surface_->points[*idx].getVector3fMap() - centroid;
00077 cov += demean * demean.transpose();
00078 }
00079
00080 Eigen::Matrix3f eigenvectors;
00081 Eigen::Vector3f eigenvalues;
00082 pcl::eigen33(cov, eigenvectors, eigenvalues);
00083 eigenvalues /= c->size();
00084 c->pca_point_comp1 = eigenvectors.col(2);
00085 c->pca_point_comp2 = eigenvectors.col(1);
00086 c->pca_point_comp3 = eigenvectors.col(0);
00087 c->pca_point_values = eigenvalues;
00088
00089
00090 if ( eigenvalues(0) / (eigenvalues(0)+eigenvalues(1)+eigenvalues(2)) < 0.001 * centroid(2) * centroid(2) )
00091 {
00092 c->type = I_PLANE;
00093 c->is_planar_ = true;
00094 }
00095
00096 }
00097
00098 template<typename LabelT, typename PointT, typename PointNT> void
00099 cob_3d_segmentation::DepthClusterHandler<LabelT,PointT,PointNT>::computeCurvature(ClusterPtr c)
00100 {
00101
00102 Eigen::Matrix3f M = Eigen::Matrix3f::Identity() - c->getOrientation() * c->getOrientation().transpose();
00103 std::vector<Eigen::Vector3f> normals_projected;
00104 Eigen::Vector3f n_centroid = Eigen::Vector3f::Zero();
00105 for (ClusterType::iterator idx = c->begin(); idx != c->end(); ++ idx)
00106 {
00107 if (pcl_isnan(normals_->points[*idx].normal[2])) continue;
00108 normals_projected.push_back( M * Eigen::Vector3f(normals_->points[*idx].normal) );
00109 n_centroid += normals_projected.back();
00110 }
00111 float num_p_inv = 1.0f / normals_projected.size();
00112 n_centroid *= num_p_inv;
00113 Eigen::Matrix3f cov = Eigen::Matrix3f::Zero();
00114 for (std::vector<Eigen::Vector3f>::iterator n_it = normals_projected.begin(); n_it != normals_projected.end(); ++n_it)
00115 {
00116 Eigen::Vector3f demean = *n_it - n_centroid;
00117 cov += demean * demean.transpose();
00118 }
00119 Eigen::Vector3f eigenvalues;
00120 Eigen::Matrix3f eigenvectors;
00121 pcl::eigen33(cov, eigenvectors, eigenvalues);
00122 c->max_curvature = eigenvalues(2) * num_p_inv;
00123 c->min_curvature = eigenvalues(1) * num_p_inv;
00124
00125 }
00126
00127 template<typename LabelT, typename PointT, typename PointNT> void
00128 cob_3d_segmentation::DepthClusterHandler<LabelT,PointT,PointNT>::computeNormalIntersections(ClusterPtr c)
00129 {
00130 const std::size_t idx_steps = 1;
00131 const float rand_max_inv = 1.0f / RAND_MAX;
00132 std::size_t front = 0, back = c->size()-1;
00133 Eigen::Vector3f p_mean = Eigen::Vector3f::Zero();
00134 std::vector<Eigen::Vector3f> p_list;
00135
00136 while(front < c->size())
00137 {
00138
00139 back = (std::size_t)( (float)(c->size()-1) * (float)rand() * (float)rand_max_inv );
00140 while (back == front) back = (std::size_t)( (float)(c->size()-1) * (float)rand() * (float)rand_max_inv );
00141
00142 Eigen::Vector3f x1(surface_->points[(*c)[front]].getVector3fMap());
00143 Eigen::Vector3f x2(surface_->points[(*c)[back]].getVector3fMap());
00144 Eigen::Vector3f n1(normals_->points[(*c)[front]].getNormalVector3fMap());
00145 Eigen::Vector3f n2(normals_->points[(*c)[back]].getNormalVector3fMap());
00146
00147
00148
00149
00150 Eigen::Vector3f cross_n = n2.cross(n1);
00151 Eigen::Vector3f dist_x = x1 - x2;
00152
00153
00154
00155
00156
00157
00158
00159
00160 if ( !((cross_n(0) == cross_n(1)) && (cross_n(1) == cross_n(2)) && (cross_n(2) == 0)) )
00161 {
00162 float cross_n_denom = 1.0f / (cross_n(0)*cross_n(0) + cross_n(1)*cross_n(1) + cross_n(2)*cross_n(2));
00163
00164 Eigen::Matrix3f m_s, m_t;
00165 m_s << dist_x, n2, cross_n;
00166 m_t << dist_x, n1, cross_n;
00167 float s = m_s.determinant() * cross_n_denom;
00168 float t = m_t.determinant() * cross_n_denom;
00169
00170
00171 Eigen::Vector3f p1 = x1 + n1 * s;
00172 Eigen::Vector3f p2 = x2 + n2 * t;
00173 p_mean += p1 + p2;
00174 p_list.push_back(p1);
00175 p_list.push_back(p2);
00176 }
00177 front += idx_steps;
00178 }
00179
00180 float num_p_inv = 1.0f / (float)p_list.size();
00181 c->pca_inter_centroid = p_mean * num_p_inv;
00182
00183 Eigen::Matrix3f cov = Eigen::Matrix3f::Zero();
00184 for (std::vector<Eigen::Vector3f>::iterator p_it = p_list.begin(); p_it != p_list.end(); ++p_it)
00185 {
00186 Eigen::Vector3f demean = *p_it;
00187 cov += demean * demean.transpose();
00188 }
00189 Eigen::Vector3f eigenvalues;
00190 Eigen::Matrix3f eigenvectors;
00191 pcl::eigen33(cov, eigenvectors, eigenvalues);
00192 eigenvalues *= num_p_inv;
00193
00194 c->pca_inter_comp1 = eigenvectors.col(2);
00195 c->pca_inter_comp2 = eigenvectors.col(1);
00196 c->pca_inter_comp3 = eigenvectors.col(0);
00197 c->pca_inter_values = eigenvalues;
00198
00199
00200 }
00201
00202 #endif