1#ifndef __GfxTL_COVARIANCE_HEADER__
2#define __GfxTL_COVARIANCE_HEADER__
9 template <
class MatrixT>
24 template <
class Po
intT>
31 template <
class WeightT,
class Po
intT>
33 Add(WeightT w,
const PointT& p)
47 if (m_totalWeight > 0)
80 template <
class ScalarT>
95 template <
class Po
intT>
102 template <
class WeightT,
class Po
intT>
104 Add(WeightT w,
const PointT& p)
112 m_matrix[0][0] += (dummy = oldTotalWeight * diff[0]) * r[0];
113 m_matrix[0][1] += dummy * r[1];
114 m_matrix[0][2] += dummy * r[2];
115 m_matrix[1][1] += (dummy = oldTotalWeight * diff[1]) * r[1];
116 m_matrix[1][2] += dummy * r[2];
117 m_matrix[2][2] += oldTotalWeight * diff[2] * r[2];
123 if (m_totalWeight > 0)
125 (*m)[0][0] = m_matrix[0][0] / m_totalWeight;
126 (*m)[0][1] = m_matrix[0][1] / m_totalWeight;
127 (*m)[0][2] = m_matrix[0][2] / m_totalWeight;
128 (*m)[1][1] = m_matrix[1][1] / m_totalWeight;
129 (*m)[1][2] = m_matrix[1][2] / m_totalWeight;
130 (*m)[2][2] = m_matrix[2][2] / m_totalWeight;
134 (*m)[0][0] = m_matrix[0][0];
135 (*m)[0][1] = m_matrix[0][1];
136 (*m)[0][2] = m_matrix[0][2];
137 (*m)[1][1] = m_matrix[1][1];
138 (*m)[1][2] = m_matrix[1][2];
139 (*m)[2][2] = m_matrix[2][2];
141 (*m)[1][0] = (*m)[0][1];
142 (*m)[2][0] = (*m)[0][2];
143 (*m)[2][1] = (*m)[1][2];
173 template <
class Po
intT,
class Po
intsForwardIt,
class WeightsForwardIt,
class MatrixT>
176 PointsForwardIt begin,
178 WeightsForwardIt weights,
181 typedef typename MatrixT::ScalarType
ScalarType;
184 for (; begin != end; ++begin, ++weights)
186 typename PointT::TransposedType diffT;
187 PointT diff = ((PointT)(*begin));
189 diff.Transpose(&diffT);
193 MatrixT dd = diff * diffT;
196 *matrix /= totalWeight;
199 template <
class Po
intT,
class Po
intsForwardIt,
class WeightsForwardIt>
202 PointsForwardIt begin,
204 WeightsForwardIt weights,
207 typedef typename PointT::ScalarType
ScalarType;
210 for (; begin != end; ++begin, ++weights)
212 PointT diff = PointT(*begin);
215 (*matrix)[0][0] += (dummy = w * diff[0]) * diff[0];
216 (*matrix)[0][1] += dummy * diff[1];
217 (*matrix)[0][2] += dummy * diff[2];
218 (*matrix)[1][1] += (dummy = w * diff[1]) * diff[1];
219 (*matrix)[1][2] += dummy * diff[2];
220 (*matrix)[2][2] += w * diff[2] * diff[2];
223 (*matrix)[1][0] = (*matrix)[0][1];
224 (*matrix)[2][0] = (*matrix)[0][2];
225 (*matrix)[2][1] = (*matrix)[1][2];
226 (*matrix) /= totalWeight;
229 template <
class Po
intT,
class Po
intsForwardIt,
class MatrixT>
232 PointsForwardIt begin,
240 template <
class Po
intsIteratorT,
class WeightsIteratorT,
class Po
intT,
class MatrixT>
244 WeightsIteratorT weights,
249 for (; begin != end; ++begin, ++weights)
251 cov.
Add(*weights, *begin);
257 template <
class Po
intsIteratorT,
class WeightsIteratorT,
class Po
intT,
class ScalarT>
261 WeightsIteratorT weights,
265 typedef typename std::iterator_traits<WeightsIteratorT>::value_type WeightType;
273 WeightType w, totalWeight, oldTotalWeight;
277 for (++begin, ++weights; begin != end; ++begin, ++weights)
279 oldTotalWeight = totalWeight;
283 for (
unsigned int i = 0; i < 3; ++i)
285 diff[i] = (*begin)[i] - (*mean)[i];
291 (*matrix)[0][0] += (dummy = ww * diff[0]) * r[0];
292 (*matrix)[0][1] += dummy * r[1];
293 (*matrix)[0][2] += dummy * r[2];
294 (*matrix)[1][1] += (dummy = ww * diff[1]) * r[1];
295 (*matrix)[1][2] += dummy * r[2];
296 (*matrix)[2][2] += ww * diff[2] * r[2];
304 (*matrix)[1][0] = (*matrix)[0][1];
305 (*matrix)[2][0] = (*matrix)[0][2];
306 (*matrix)[2][1] = (*matrix)[1][2];
Eigen::Matrix< T, 3, 3 > Matrix
void Add(const PointT &p)
void Add(WeightT w, const PointT &p)
VectorXD< 3, ScalarType > PointType
MatrixXX< 3, 3, ScalarT > MatrixType
void Mean(PointType *mean) const
IncrementalCovarianceMatrix()
void MeanAndMatrix(PointType *mean, MatrixType *m) const
void Matrix(MatrixType *m) const
void Add(const PointT &p)
void MeanAndMatrix(PointType *mean, MatrixT *m) const
void Add(WeightT w, const PointT &p)
VectorXD< MatrixT::Rows, ScalarType > PointType
MatrixT::ScalarType ScalarType
void Mean(PointType *mean) const
IncrementalCovarianceMatrix()
void Matrix(MatrixT *m) const
void CovarianceMatrix(const PointT ¢er, PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights, MatrixT *matrix)
MatrixXX< B, A, T > OuterProduct(const VectorXD< A, T > &a, const VectorXD< B, T > &b)