42 #include <visp/vpMomentAlpha.h>
43 #include <visp/vpMomentGravityCenter.h>
44 #include <visp/vpMomentCentered.h>
64 :
vpMoment(),isRef(false),symmetric(false),ref(ref_),alphaRef(alpha_ref)
66 for (std::vector<double>::iterator it = ref_.begin(); it!=ref_.end(); it++)
79 bool found_moment_centered;
82 found_moment_centered)));
84 if (!found_moment_centered)
87 double alpha = 0.5 * atan2(2.0 * momentCentered.
get(1, 1), (momentCentered.
get(2, 0) - momentCentered.
get(0, 2)));
89 unsigned int order = 4;
90 std::vector<double> rotMu(4);
91 std::vector<double> realMu(4);
101 double r11 = cos(alpha - alphaRef);
102 double r12 = sin(alpha - alphaRef);
103 double r21 = -sin(alpha - alphaRef);
104 double r22 = cos(alpha - alphaRef);
105 unsigned int idx = 0;
106 for (
register unsigned int c = 0; c < (order) * (order); c++)
108 unsigned int i = c % order;
109 unsigned int j = c / order;
114 for (
register unsigned int k = 0; k <= i; k++)
116 double r12_i_k = pow(r12, (
int)(i - k));
117 double comb_i_k =
static_cast<double> (
vpMath::comb(i, k));
118 for (
register unsigned int l = 0; l <= j; l++)
120 rotMu[idx] +=
static_cast<double> (comb_i_k *
vpMath::comb(j, l) * r11_k * pow(r21, (
int)l) * r12_i_k
121 * pow(r22, (
int)(j - l)) * momentCentered.
get(k + l, (
unsigned int)(
int)(i + j - k - l)));
125 realMu[idx] = momentCentered.
get(i, j);
131 bool signChange =
true;
132 for (
register unsigned int i = 0; i < 4; i++)
134 if (std::abs(rotMu[i]) > 1e10 * std::numeric_limits<double>::epsilon() && std::abs(ref[i]) > 1e10
135 * std::numeric_limits<double>::epsilon() && rotMu[i] * ref[i] > 0)
137 sum += std::abs(rotMu[i] * ref[i]);
140 if (sum < 1e4 * std::numeric_limits<double>::epsilon())
143 alpha = alpha + M_PI;
152 VISP_EXPORT std::ostream & operator<<(std::ostream & os,
const vpMomentAlpha& c){
153 os << (__FILE__) << std::endl;
162 os << (__FILE__) << std::endl;
163 bool found_moment_centered;
165 found_moment_centered)));
166 if (!found_moment_centered)
169 os <<
"mu11 = " << momentCentered.
get(1, 1) <<
"\t";
170 os <<
"mu20 = " << momentCentered.
get(2, 0) <<
"\t";
171 os <<
"mu02 = " << momentCentered.
get(0, 2) << std::endl;
error that can be emited by ViSP classes.
This class defines shared methods/attributes for 2D moments.
const vpMoment & get(const char *type, bool &found) const
This class defines the double-indexed centered moment descriptor .
This class defines the orientation of the object inside the plane parallel to the object...
double get(unsigned int i, unsigned int j) const
vpMomentDatabase & getMoments() const
void printDependencies(std::ostream &os) const
static long double comb(unsigned int n, unsigned int p)
static double deg(double rad)
std::vector< double > values