42 #include <visp3/core/vpColVector.h>
43 #include <visp3/core/vpMath.h>
44 #include <visp3/me/vpMe.h>
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 template <
class Type>
inline void permute(Type &a, Type &b)
65 static droite droite_cartesienne(point P, point Q)
71 PQ.c = Q.y * P.x - Q.x * P.y;
76 static point point_intersection(droite D1, droite D2)
81 det = (D1.a * D2.b - D2.a * D1.b);
82 I.x = (D2.c * D1.b - D1.c * D2.b) / det;
83 I.y = (D1.c * D2.a - D2.c * D1.a) / det;
88 static void recale(point &P,
double Xmin,
double Ymin,
double Xmax,
double Ymax)
101 static void permute(point &A, point &B)
114 static bool clipping(point A, point B,
double Xmin,
double Ymin,
double Xmax,
double Ymax, point &Ac,
138 AB = droite_cartesienne(A, B);
144 for (n = 0; n < 2; n++) {
159 if ((code_P[0] | code_P[1]) == 0000)
174 if ((code_P[0] & code_P[1]) != 0000)
183 if (code_P[0] != 0000) {
185 for (i = 0, bit_i = 1; !(code_P[0] & bit_i); i++, bit_i <<= 1) {
189 for (i = 0, bit_i = 1; !(code_P[1] & bit_i); i++, bit_i <<= 1) {
193 P[n] = point_intersection(AB, D[i]);
198 recale(P[n], Xmin, Ymin, Xmax, Ymax);
205 static double S_relative(point P, point Q,
double Xmin,
double Ymin,
double Xmax,
double Ymax)
211 recale(P, Xmin, Ymin, Xmax, Ymax);
212 recale(Q, Xmin, Ymin, Xmax, Ymax);
215 if ((std::fabs(P.x - Xmin) <=
216 vpMath::maximum(std::fabs(P.x), std::fabs(Xmin)) * std::numeric_limits<double>::epsilon()) &&
217 (std::fabs(Q.x - Xmax) <=
218 vpMath::maximum(std::fabs(Q.x), std::fabs(Xmax)) * std::numeric_limits<double>::epsilon()))
219 return (fabs(Ymax + Ymin - P.y - Q.y));
223 if (((std::fabs(P.y - Ymin) <=
224 vpMath::maximum(std::fabs(P.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon()) &&
225 (std::fabs(Q.y - Ymax) <=
226 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon())) ||
227 ((std::fabs(Q.y - Ymin) <=
228 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon()) &&
229 (std::fabs(P.y - Ymax) <=
230 vpMath::maximum(std::fabs(P.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon())))
231 return (fabs(Xmax + Xmin - P.x - Q.x));
234 if (std::fabs(P.x - Xmin) <=
235 vpMath::maximum(std::fabs(P.x), std::fabs(Xmin)) * std::numeric_limits<double>::epsilon() &&
236 std::fabs(Q.y - Ymax) <=
237 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon())
238 return (1 - (Ymax - P.y) * (Q.x - Xmin));
240 if (std::fabs(P.x - Xmin) <=
241 vpMath::maximum(std::fabs(P.x), std::fabs(Xmin)) * std::numeric_limits<double>::epsilon() &&
242 std::fabs(Q.y - Ymin) <=
243 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon())
244 return (1 - (P.y - Ymin) * (Q.x - Xmin));
246 if (std::fabs(P.y - Ymin) <=
247 vpMath::maximum(std::fabs(P.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon() &&
248 std::fabs(Q.x - Xmax) <=
249 vpMath::maximum(std::fabs(Q.x), std::fabs(Xmax)) * std::numeric_limits<double>::epsilon())
250 return (1 - (Xmax - P.x) * (Q.y - Ymin));
252 if (std::fabs(P.y - Ymax) <=
253 vpMath::maximum(std::fabs(P.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon() &&
254 std::fabs(Q.x - Xmax) <=
255 vpMath::maximum(std::fabs(Q.x), std::fabs(Xmax)) * std::numeric_limits<double>::epsilon())
256 return (1 - (Xmax - P.x) * (Ymax - Q.y));
258 throw(
vpException(
vpException::fatalError,
"utils_ecm: error in S_relative (%f,%f) (%f,%f) %f %f %f %f", P.x, P.y, Q.x, Q.y, Xmin, Ymin, Xmax, Ymax));
267 unsigned int i_theta,
270 moitie = ((double)n) / 2.0;
275 unsigned int nb_theta = angle.
getRows();
277 for (i_theta = 0; i_theta < nb_theta; i_theta++) {
278 double theta = M_PI / 180 * angle[i_theta];
280 double cos_theta = cos(theta);
281 double sin_theta = sin(theta);
286 if (std::fabs(angle[i_theta] - 90) <=
vpMath::maximum(std::fabs(angle[i_theta]), 90.) *
287 std::numeric_limits<double>::epsilon())
294 double tan_theta = sin_theta / cos_theta;
296 P1.y = tan_theta * (-(int)n);
298 Q1.y = tan_theta * n;
305 for (i = 0, Y = -moitie + 0.5; i < n; i++, Y++) {
306 for (j = 0, X = -moitie + 0.5; j < n; j++, X++) {
311 if (clipping(P1, Q1, X - 0.5, Y - 0.5, X + 0.5, Y + 0.5, P, Q)) {
313 v = S_relative(P, Q, X - 0.5, Y - 0.5, X + 0.5, Y + 0.5);
343 unsigned int angle_pas;
347 for (
unsigned int i = 0; k <
n_mask; i += angle_pas)
356 std::cout << std::endl;
357 std::cout <<
"Moving edges settings " << std::endl;
358 std::cout << std::endl;
359 std::cout <<
" Size of the convolution masks...." <<
mask_size <<
"x" <<
mask_size <<
" pixels" << std::endl;
360 std::cout <<
" Number of masks.................." <<
n_mask <<
" " << std::endl;
361 std::cout <<
" Query range +/- J................" <<
range <<
" pixels " << std::endl;
362 std::cout <<
" Likelihood test ratio............" <<
threshold << std::endl;
363 std::cout <<
" Contrast tolerance +/-..........." <<
mu1 * 100 <<
"% and " <<
mu2 * 100 <<
"% " << std::endl;
364 std::cout <<
" Sample step......................" <<
sample_step <<
" pixels" << std::endl;
365 std::cout <<
" Strip............................" <<
strip <<
" pixels " << std::endl;
366 std::cout <<
" Min_Samplestep..................." <<
min_samplestep <<
" pixels " << std::endl;
370 : threshold(1500), mu1(0.5), mu2(0.5), min_samplestep(4), anglestep(1), mask_sign(0), range(4), sample_step(10),
371 ntotal_sample(0), points_to_track(500), mask_size(5), n_mask(180), strip(2), mask(NULL)
381 : threshold(1500), mu1(0.5), mu2(0.5), min_samplestep(4), anglestep(1), mask_sign(0), range(4), sample_step(10),
382 ntotal_sample(0), points_to_track(500), mask_size(5), n_mask(180), strip(2), mask(NULL)
412 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
421 mu1 = std::move(me.mu1);
422 mu2 = std::move(me.mu2);
426 n_mask = std::move(me.n_mask);
428 range = std::move(me.range);
432 strip = std::move(me.strip);
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Implementation of column vector and the associated operations.
error that can be emited by ViSP classes.
static Type maximum(const Type &a, const Type &b)
static bool equal(double x, double y, double threshold=0.001)
static int round(double x)
static int sign(double x)
Implementation of a matrix and operations on matrices.
int ntotal_sample
Distance between sampled points (in pixels)
double sample_step
Seek range - on both sides of the reference pixel.
double min_samplestep
Contrast continuity parameter (right boundary)
void setMaskSize(const unsigned int &a)
double mu1
Likelihood ratio threshold.
double mu2
Contrast continuity parameter (left boundary)
vpMe & operator=(const vpMe &me)
Copy operator.
void setMaskNumber(const unsigned int &a)