8template <
class DataPo
int,
class _WFunctor,
typename T>
21template<
class DataPo
int,
class _WFunctor,
typename T>
25 const DataPoint &attributes) {
26 if( Base::addLocalNeighbor(w, localQ, attributes) ) {
27 m_sumDotPN += w * attributes.normal().dot(localQ);
28 m_sumDotPP += w * localQ.squaredNorm();
35template <
class DataPo
int,
class _WFunctor,
typename T>
39 PONCA_MULTIARCH_STD_MATH(sqrt);
40 PONCA_MULTIARCH_STD_MATH(max);
41 PONCA_MULTIARCH_STD_MATH(abs);
44 if(Base::finalize() !=
STABLE)
45 return Base::m_eCurrentState;
46 if(Base::getNumNeighbors() < DataPoint::Dim)
48 if (Base::algebraicSphere().isValid())
51 Base::m_eCurrentState = Base::getNumNeighbors() < 2*DataPoint::Dim ?
UNSTABLE :
STABLE;
54 Scalar epsilon = Eigen::NumTraits<Scalar>::dummy_precision();
58 m_nume = (m_sumDotPN - invSumW * Base::m_sumP.dot(Base::m_sumN));
59 Scalar den1 = invSumW * Base::m_sumP.dot(Base::m_sumP);
60 m_deno = m_sumDotPP - den1;
63 if(abs(m_deno) < epsilon * max(m_sumDotPP, den1))
67 Base::m_ul = s*Base::m_ul;
68 Base::m_uc = s*Base::m_uc;
74 Base::m_uq =
Scalar(.5) * m_nume / m_deno;
75 Base::m_ul = (Base::m_sumN - Base::m_sumP * (
Scalar(2.) * Base::m_uq)) * invSumW;
76 Base::m_uc = -invSumW * (Base::m_ul.dot(Base::m_sumP) + m_sumDotPP * Base::m_uq);
79 Base::m_isNormalized =
false;
81 return Base::m_eCurrentState;
84template <
class DataPo
int,
class _WFunctor,
int DiffType,
typename T>
92 m_dSumDotPN.setZero();
93 m_dSumDotPP.setZero();
103template <
class DataPo
int,
class _WFunctor,
int DiffType,
typename T>
107 const DataPoint &attributes,
109 if( Base::addLocalNeighbor(w, localQ, attributes, dw) ) {
111 m_dSumN += attributes.normal() * dw;
112 m_dSumDotPN += dw * attributes.normal().dot(localQ);
113 m_dSumDotPP += dw * localQ.squaredNorm();
121template <
class DataPo
int,
class _WFunctor,
int DiffType,
typename T>
125 PONCA_MULTIARCH_STD_MATH(sqrt);
133 Scalar nume = Base::m_sumDotPN - invSumW*Base::m_sumP.dot(Base::m_sumN);
134 Scalar deno = Base::m_sumDotPP - invSumW*Base::m_sumP.dot(Base::m_sumP);
139 m_dNume = m_dSumDotPN
140 - invSumW*invSumW * ( Base::getWeightSum() * ( Base::m_sumN.transpose() * Base::m_dSumP + Base::m_sumP.transpose() * m_dSumN )
141 - Base::m_dSumW*Base::m_sumP.dot(Base::m_sumN) );
143 m_dDeno = m_dSumDotPP
144 - invSumW*invSumW*(
Scalar(2.) * Base::getWeightSum() * Base::m_sumP.transpose() * Base::m_dSumP
145 - Base::m_dSumW*Base::m_sumP.dot(Base::m_sumP) );
147 m_dUq =
Scalar(.5) * (deno * m_dNume - m_dDeno * nume)/(deno*deno);
151 m_dUl = invSumW * ( m_dSumN - Base::m_ul*Base::m_dSumW -
Scalar(2.)*(Base::m_dSumP * Base::m_uq + Base::m_sumP * m_dUq) );
152 m_dUc = -invSumW*( Base::m_sumP.transpose() * m_dUl
153 + Base::m_sumDotPP * m_dUq
154 + Base::m_ul.transpose() * Base::m_dSumP
155 + Base::m_uq * m_dSumDotPP
156 + Base::m_dSumW * Base::m_uc);
159 return Base::m_eCurrentState;
162template <
class DataPo
int,
class _WFunctor,
int DiffType,
typename T>
163typename OrientedSphereDerImpl <DataPoint, _WFunctor, DiffType, T>::VectorArray
170 if(Base::isSpaceDer())
171 dgrad.template rightCols<DataPoint::Dim>().diagonal().array() +=
Scalar(2)*Base::m_uq;
172 Scalar norm = Base::m_ul.norm();
173 Scalar norm3 = norm*norm*norm;
174 return dgrad / norm - Base::m_ul * (Base::m_ul.transpose() * dgrad) / norm3;
177template <
class DataPo
int,
class _WFunctor,
int DiffType,
typename T>
178typename OrientedSphereDerImpl <DataPoint, _WFunctor, DiffType, T>::ScalarArray
182 if(Base::isSpaceDer())
183 dfield.template tail<DataPoint::Dim>() += Base::m_ul;
187template <
class DataPo
int,
class _WFunctor,
int DiffType,
typename T>
191 if(Base::isNormalized())
194 PONCA_MULTIARCH_STD_MATH(sqrt);
195 Scalar pn2 = Base::prattNorm2();
201 m_dUc = ( m_dUc * pn - Base::m_uc * factor ) / pn2;
202 m_dUl = ( m_dUl * pn - Base::m_ul * factor ) / pn2;
203 m_dUq = ( m_dUq * pn - Base::m_uq * factor ) / pn2;
205 Base::applyPrattNorm();
[OrientedSphereFit Definition]
typename DataPoint::Scalar Scalar
Alias to scalar type.
typename Base::ScalarArray ScalarArray
Alias to scalar derivatives array.
typename Base::VectorType VectorType
Alias to vector type.
typename Base::VectorArray VectorArray
Alias to vector derivatives array.
Algebraic Sphere fitting procedure on oriented point sets.
typename DataPoint::Scalar Scalar
Alias to scalar type.
typename Base::VectorType VectorType
Alias to vector type.
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns)
@ UNDEFINED
The fitting is undefined, you can't use it for valid results.
@ CONFLICT_ERROR_FOUND
Multiple classes of the fitting procedure initialize the primitive.
@ STABLE
The fitting is stable and ready to use.
@ UNSTABLE
The fitting is ready to use but it is considered as unstable (if the number of neighbors is low for e...