18 #include <mrpt/config.h> 21 #include <Eigen/Dense> 24 #include <pcl/point_cloud.h> 25 #include <pcl/point_types.h> 37 template <
class po
intPCL>
40 return Eigen::Vector3f(pt.x, pt.y, pt.z);
43 template <
class POINT>
44 inline Eigen::Vector3f
diffPoints(
const POINT& P1,
const POINT& P2)
47 diff[0] = P1.x - P2.x;
48 diff[1] = P1.y - P2.y;
49 diff[2] = P1.z - P2.z;
54 template <
class dataType>
59 pose.template block<3, 3>(0, 0) * point +
60 pose.template block<3, 1>(0, 3);
61 return transformedPoint;
65 template <
class dataType>
70 transformedPose.template block<3, 3>(0, 0) =
71 pose1.template block<3, 3>(0, 0) * pose2.template block<3, 3>(0, 0);
72 transformedPose.block(0, 3, 3, 1) =
73 pose1.block(0, 3, 3, 1) +
74 pose1.template block<3, 3>(0, 0) * pose2.block(0, 3, 3, 1);
75 transformedPose.row(3) << 0, 0, 0, 1;
76 return transformedPose;
80 template <
class dataType>
84 inverse.template block<3, 3>(0, 0) =
85 pose.template block<3, 3>(0, 0).transpose();
87 -(
inverse.template block<3, 3>(0, 0) * pose.block(0, 3, 3, 1));
103 bool isInHull(
PointT& point3D, pcl::PointCloud<PointT>::Ptr hull3D);
105 template <
typename dataType>
108 float normalizeConst = 255.0 /
range;
109 std::vector<int> data2(
data.size());
110 for (
size_t i = 0; i <
data.size(); i++)
111 data2[i] = (
int)(
data[i] * normalizeConst);
114 for (
size_t i = 0; i < data2.size(); i++)
122 if (bin->second >
count)
128 return (dataType)
mode / normalizeConst;
152 template <
typename dataType>
154 std::vector<Eigen::Vector4f>&
data, dataType& stdDevHist,
155 dataType& concentration)
159 std::vector<Eigen::Vector4f> dataTemp =
data;
163 Eigen::Vector3f
sum = Eigen::Vector3f::Zero();
164 for (
size_t i = 0; i <
data.size(); i++)
168 Eigen::Vector3f meanShift =
sum /
size;
171 Eigen::Matrix3f
cov = Eigen::Matrix3f::Zero();
172 for (
size_t i = 0; i <
data.size(); i++)
174 Eigen::Vector3f diff =
data[i].head(3) - meanShift;
178 Eigen::JacobiSVD<Eigen::Matrix3f> svd(
cov);
179 stdDevHist = svd.singularValues().maxCoeff() / sqrt((
double)
size);
183 int iteration_counter = 0;
184 double convergence = 0.001;
185 while (2 * dataTemp.size() >
size && shift > convergence)
190 for (
auto it = dataTemp.begin(); it != dataTemp.end();)
193 Eigen::Vector3f diff = (*it).head(3) - meanShift;
194 if (diff.norm() > stdDevHist)
196 sum -= (*it).head(3);
205 Eigen::Vector3f meanUpdated =
sum / dataTemp.size();
206 shift = (meanUpdated - meanShift).
norm();
207 meanShift = meanUpdated;
208 svd = Eigen::JacobiSVD<Eigen::Matrix3f>(
cov);
211 svd.singularValues().maxCoeff() / sqrt((
double)dataTemp.size());
222 Eigen::Vector4f dominantColor;
223 dominantColor.head(3) = meanShift;
224 float averageIntensity = 0;
225 for (
unsigned i = 0; i < dataTemp.size(); i++)
226 averageIntensity += dataTemp[i][3];
227 averageIntensity /= dataTemp.size();
228 dominantColor(3) = averageIntensity;
231 int countFringe05 = 0;
232 for (
auto it =
data.begin(); it !=
data.end(); it++)
233 if ((it->head(3) - meanShift).
norm() <
236 concentration =
static_cast<dataType
>(countFringe05) /
data.size();
238 return dominantColor;
243 template <
typename dataType>
245 std::vector<dataType>&
data,
double range,
246 dataType& stdDevHist_out)
252 std::vector<dataType> dataTemp =
data;
255 for (
size_t i = 0; i <
data.size(); i++)
259 dataType meanShift =
sum /
size;
270 int iteration_counter = 0;
271 double convergence =
range * 0.001;
272 while (2 * dataTemp.size() >
size && shift > convergence)
276 for (
auto it = dataTemp.begin(); it != dataTemp.end();)
279 if (fabs(*it - meanShift) > stdDevHist)
289 double meanUpdated =
sum / dataTemp.size();
290 shift = fabs(meanUpdated - meanShift);
291 meanShift = meanUpdated;
312 return static_cast<dataType
>(meanShift);
337 std::ostream& operator<<(std::ostream& os, const std::vector<T>&
v)
339 std::copy(
v.begin(),
v.end(), std::ostream_iterator<T>(os,
" "));
Eigen::Vector4f getMultiDimMeanShift_color(std::vector< Eigen::Vector4f > &data, dataType &stdDevHist, dataType &concentration)
GLuint GLuint GLsizei count
Eigen::Vector3f diffPoints(const POINT &P1, const POINT &P2)
double stddev(const VECTORLIKE &v, bool unbiased=true)
Computes the standard deviation of a vector.
This file implements several operations that operate element-wise on individual or pairs of container...
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
dataType getHistogramMeanShift(std::vector< dataType > &data, double range, dataType &stdDevHist_out)
Segment(PointT p0, PointT p1)
CMatrixDouble cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
float dist3D_Segment_to_Segment2(Segment S1, Segment S2)
bool isInHull(PointT &point3D, pcl::PointCloud< PointT >::Ptr hull3D)
dataType getMode(std::vector< dataType > data, dataType range)
std::vector< double > histogram(const CONTAINER &v, double limit_min, double limit_max, size_t number_bins, bool do_normalization=false, std::vector< double > *out_bin_centers=nullptr)
Computes the normalized or normal histogram of a sequence of numbers given the number of bins and the...
GLsizei GLsizei GLenum GLenum const GLvoid * data
CONTAINER::Scalar norm(const CONTAINER &v)
Eigen::Vector3f getVector3fromPointXYZ(pointPCL &pt)
Eigen::Matrix< dataType, 3, 1 > compose(Eigen::Matrix< dataType, 4, 4 > &pose, Eigen::Matrix< dataType, 3, 1 > &point)