Visual Servoing Platform  version 3.5.1 under development (2022-05-22)
vpMbtDistanceLine.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Make the complete tracking of an object by using its CAD model
33  *
34  * Authors:
35  * Nicolas Melchior
36  * Romain Tallonneau
37  * Eric Marchand
38  *
39  *****************************************************************************/
40 #include <visp3/core/vpConfig.h>
41 
47 #include <stdlib.h>
48 #include <visp3/core/vpMeterPixelConversion.h>
49 #include <visp3/core/vpPlane.h>
50 #include <visp3/mbt/vpMbtDistanceLine.h>
51 #include <visp3/visual_features/vpFeatureBuilder.h>
52 
53 void buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane);
54 void buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L);
55 
60  : name(), index(0), cam(), me(NULL), isTrackedLine(true), isTrackedLineWithVisibility(true), wmean(1), featureline(),
61  poly(), useScanLine(false), meline(), line(NULL), p1(NULL), p2(NULL), L(), error(), nbFeature(), nbFeatureTotal(0),
62  Reinit(false), hiddenface(NULL), Lindex_polygon(), Lindex_polygon_tracked(), isvisible(false)
63 {
64 }
65 
70 {
71  // cout << "Deleting line " << index << endl;
72  if (line != NULL)
73  delete line;
74 
75  for (unsigned int i = 0; i < meline.size(); i++)
76  if (meline[i] != NULL)
77  delete meline[i];
78 
79  meline.clear();
80 }
81 
88 void vpMbtDistanceLine::project(const vpHomogeneousMatrix &cMo)
89 {
90  line->project(cMo);
91  p1->project(cMo);
92  p2->project(cMo);
93 }
94 
104 void buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane)
105 {
106  vpColVector a(3);
107  vpColVector b(3);
108 
109  // Calculate vector corresponding to PQ
110  a[0] = P.get_oX() - Q.get_oX();
111  a[1] = P.get_oY() - Q.get_oY();
112  a[2] = P.get_oZ() - Q.get_oZ();
113 
114  // Calculate vector corresponding to PR
115  b[0] = P.get_oX() - R.get_oX();
116  b[1] = P.get_oY() - R.get_oY();
117  b[2] = P.get_oZ() - R.get_oZ();
118 
119  // Calculate normal vector to plane PQ x PR
121 
122  // Equation of the plane is given by:
123  double A = n[0];
124  double B = n[1];
125  double C = n[2];
126  double D = -(A * P.get_oX() + B * P.get_oY() + C * P.get_oZ());
127 
128  double norm = sqrt(A * A + B * B + C * C);
129  plane.setA(A / norm);
130  plane.setB(B / norm);
131  plane.setC(C / norm);
132  plane.setD(D / norm);
133 }
134 
148 void buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L)
149 {
150  vpPlane plane1;
151  vpPlane plane2;
152  buildPlane(P1, P2, P3, plane1);
153  buildPlane(P1, P2, P4, plane2);
154 
155  L.setWorldCoordinates(plane1.getA(), plane1.getB(), plane1.getC(), plane1.getD(), plane2.getA(), plane2.getB(),
156  plane2.getC(), plane2.getD());
157 }
158 
168 {
169  if (line == NULL) {
170  line = new vpLine;
171  }
172 
173  poly.setNbPoint(2);
174  poly.addPoint(0, _p1);
175  poly.addPoint(1, _p2);
176 
177  p1 = &poly.p[0];
178  p2 = &poly.p[1];
179 
180  vpColVector V1(3);
181  vpColVector V2(3);
182 
183  V1[0] = p1->get_oX();
184  V1[1] = p1->get_oY();
185  V1[2] = p1->get_oZ();
186  V2[0] = p2->get_oX();
187  V2[1] = p2->get_oY();
188  V2[2] = p2->get_oZ();
189 
190  // if((V1-V2).sumSquare()!=0)
191  if (std::fabs((V1 - V2).sumSquare()) > std::numeric_limits<double>::epsilon()) {
192  vpColVector V3(3);
193  V3[0] = double(rand_gen.next() % 1000) / 100;
194  V3[1] = double(rand_gen.next() % 1000) / 100;
195  V3[2] = double(rand_gen.next() % 1000) / 100;
196 
197  vpColVector v_tmp1, v_tmp2;
198  v_tmp1 = V2 - V1;
199  v_tmp2 = V3 - V1;
200  vpColVector V4 = vpColVector::cross(v_tmp1, v_tmp2);
201 
202  vpPoint P3(V3[0], V3[1], V3[2]);
203  vpPoint P4(V4[0], V4[1], V4[2]);
204  buildLine(*p1, *p2, P3, P4, *line);
205  } else {
206  vpPoint P3(V1[0], V1[1], V1[2]);
207  vpPoint P4(V2[0], V2[1], V2[2]);
208  buildLine(*p1, *p2, P3, P4, *line);
209  }
210 }
211 
217 void vpMbtDistanceLine::addPolygon(const int &idx)
218 {
219  Lindex_polygon.push_back(idx);
220  Lindex_polygon_tracked.push_back(true);
221 }
222 
230 void vpMbtDistanceLine::setTracked(const std::string &polyname, const bool &track)
231 {
232  unsigned int ind = 0;
233  for (std::list<int>::const_iterator itpoly = Lindex_polygon.begin(); itpoly != Lindex_polygon.end(); ++itpoly) {
234  if ((*hiddenface)[(unsigned)(*itpoly)]->getName() == polyname) {
235  Lindex_polygon_tracked[ind] = track;
236  }
237  ind++;
238  }
239 
240  isTrackedLine = false;
241  for (unsigned int i = 0; i < Lindex_polygon_tracked.size(); i++)
242  if (Lindex_polygon_tracked[i]) {
243  isTrackedLine = true;
244  break;
245  }
246 
247  if (!isTrackedLine) {
248  isTrackedLineWithVisibility = false;
249  return;
250  }
251 
252  updateTracked();
253 }
254 
261 {
262  if (!isTrackedLine) {
263  isTrackedLineWithVisibility = false;
264  return;
265  }
266 
267  unsigned int ind = 0;
268  isTrackedLineWithVisibility = false;
269  for (std::list<int>::const_iterator itpoly = Lindex_polygon.begin(); itpoly != Lindex_polygon.end(); ++itpoly) {
270  if ((*hiddenface)[(unsigned)(*itpoly)]->isVisible() && Lindex_polygon_tracked[ind]) {
271  isTrackedLineWithVisibility = true;
272  break;
273  }
274  ind++;
275  }
276 }
277 
284 {
285  me = _me;
286 
287  for (unsigned int i = 0; i < meline.size(); i++)
288  if (meline[i] != NULL) {
289  // nbFeature[i] = 0;
290  meline[i]->reset();
291  meline[i]->setMe(me);
292  }
293 
294  // nbFeatureTotal = 0;
295 }
296 
309  const vpImage<bool> *mask)
310 {
311  for (unsigned int i = 0; i < meline.size(); i++) {
312  if (meline[i] != NULL)
313  delete meline[i];
314  }
315 
316  meline.clear();
317  nbFeature.clear();
318  nbFeatureTotal = 0;
319 
320  if (isvisible) {
321  p1->changeFrame(cMo);
322  p2->changeFrame(cMo);
323 
324  if (poly.getClipping() > 3) // Contains at least one FOV constraint
325  cam.computeFov(I.getWidth(), I.getHeight());
326 
327  poly.computePolygonClipped(cam);
328 
329  if (poly.polyClipped.size() == 2) { // Les points sont visibles.
330 
331  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
332 
333  if (useScanLine) {
334  hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst);
335  } else {
336  linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
337  }
338 
339  if (linesLst.size() == 0) {
340  return false;
341  }
342 
343  line->changeFrame(cMo);
344  try {
345  line->projection();
346  } catch (...) {
347  isvisible = false;
348  return false;
349  }
350  double rho, theta;
351  // rho theta uv
353 
354  while (theta > M_PI) {
355  theta -= M_PI;
356  }
357  while (theta < -M_PI) {
358  theta += M_PI;
359  }
360 
361  if (theta < -M_PI / 2.0)
362  theta = -theta - 3 * M_PI / 2.0;
363  else
364  theta = M_PI / 2.0 - theta;
365 
366  for (unsigned int i = 0; i < linesLst.size(); i++) {
367  vpImagePoint ip1, ip2;
368 
369  linesLst[i].first.project();
370  linesLst[i].second.project();
371 
372  vpMeterPixelConversion::convertPoint(cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
373  vpMeterPixelConversion::convertPoint(cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
374 
375  vpMbtMeLine *melinePt = new vpMbtMeLine;
376  melinePt->setMask(*mask);
377  melinePt->setMe(me);
378 
379  melinePt->setInitRange(0);
380 
381  int marge = /*10*/ 5; // ou 5 normalement
382  if (ip1.get_j() < ip2.get_j()) {
383  melinePt->jmin = (int)ip1.get_j() - marge;
384  melinePt->jmax = (int)ip2.get_j() + marge;
385  } else {
386  melinePt->jmin = (int)ip2.get_j() - marge;
387  melinePt->jmax = (int)ip1.get_j() + marge;
388  }
389  if (ip1.get_i() < ip2.get_i()) {
390  melinePt->imin = (int)ip1.get_i() - marge;
391  melinePt->imax = (int)ip2.get_i() + marge;
392  } else {
393  melinePt->imin = (int)ip2.get_i() - marge;
394  melinePt->imax = (int)ip1.get_i() + marge;
395  }
396 
397  try {
398  melinePt->initTracking(I, ip1, ip2, rho, theta, doNotTrack);
399  meline.push_back(melinePt);
400  nbFeature.push_back((unsigned int)melinePt->getMeList().size());
401  nbFeatureTotal += nbFeature.back();
402  } catch (...) {
403  delete melinePt;
404  isvisible = false;
405  return false;
406  }
407  }
408  } else {
409  isvisible = false;
410  }
411  }
412 
413  return true;
414 }
415 
422 {
423  if (isvisible) {
424  try {
425  nbFeature.clear();
426  nbFeatureTotal = 0;
427  for (size_t i = 0; i < meline.size(); i++) {
428  meline[i]->track(I);
429  nbFeature.push_back((unsigned int)meline[i]->getMeList().size());
430  nbFeatureTotal += (unsigned int)meline[i]->getMeList().size();
431  }
432  } catch (...) {
433  for (size_t i = 0; i < meline.size(); i++) {
434  if (meline[i] != NULL)
435  delete meline[i];
436  }
437 
438  nbFeature.clear();
439  meline.clear();
440  nbFeatureTotal = 0;
441  Reinit = true;
442  isvisible = false;
443  }
444  }
445 }
446 
454 {
455  if (isvisible) {
456  p1->changeFrame(cMo);
457  p2->changeFrame(cMo);
458 
459  if (poly.getClipping() > 3) // Contains at least one FOV constraint
460  cam.computeFov(I.getWidth(), I.getHeight());
461 
462  poly.computePolygonClipped(cam);
463 
464  if (poly.polyClipped.size() == 2) { // Les points sont visibles.
465 
466  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
467 
468  if (useScanLine) {
469  hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst);
470  } else {
471  linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
472  }
473 
474  if (linesLst.size() != meline.size() || linesLst.size() == 0) {
475  for (size_t i = 0; i < meline.size(); i++) {
476  if (meline[i] != NULL)
477  delete meline[i];
478  }
479 
480  meline.clear();
481  nbFeature.clear();
482  nbFeatureTotal = 0;
483  isvisible = false;
484  Reinit = true;
485  } else {
486  line->changeFrame(cMo);
487  try {
488  line->projection();
489  } catch (...) {
490  for (size_t j = 0; j < meline.size(); j++) {
491  if (meline[j] != NULL)
492  delete meline[j];
493  }
494 
495  meline.clear();
496  nbFeature.clear();
497  nbFeatureTotal = 0;
498  isvisible = false;
499  Reinit = true;
500  return;
501  }
502  double rho, theta;
503  // rho theta uv
505 
506  while (theta > M_PI) {
507  theta -= M_PI;
508  }
509  while (theta < -M_PI) {
510  theta += M_PI;
511  }
512 
513  if (theta < -M_PI / 2.0)
514  theta = -theta - 3 * M_PI / 2.0;
515  else
516  theta = M_PI / 2.0 - theta;
517 
518  try {
519  for (unsigned int i = 0; i < linesLst.size(); i++) {
520  vpImagePoint ip1, ip2;
521 
522  linesLst[i].first.project();
523  linesLst[i].second.project();
524 
525  vpMeterPixelConversion::convertPoint(cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
526  vpMeterPixelConversion::convertPoint(cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
527 
528  int marge = /*10*/ 5; // ou 5 normalement
529  if (ip1.get_j() < ip2.get_j()) {
530  meline[i]->jmin = (int)ip1.get_j() - marge;
531  meline[i]->jmax = (int)ip2.get_j() + marge;
532  } else {
533  meline[i]->jmin = (int)ip2.get_j() - marge;
534  meline[i]->jmax = (int)ip1.get_j() + marge;
535  }
536  if (ip1.get_i() < ip2.get_i()) {
537  meline[i]->imin = (int)ip1.get_i() - marge;
538  meline[i]->imax = (int)ip2.get_i() + marge;
539  } else {
540  meline[i]->imin = (int)ip2.get_i() - marge;
541  meline[i]->imax = (int)ip1.get_i() + marge;
542  }
543 
544  meline[i]->updateParameters(I, ip1, ip2, rho, theta);
545  nbFeature[i] = (unsigned int)meline[i]->getMeList().size();
547  }
548  } catch (...) {
549  for (size_t j = 0; j < meline.size(); j++) {
550  if (meline[j] != NULL)
551  delete meline[j];
552  }
553 
554  meline.clear();
555  nbFeature.clear();
556  nbFeatureTotal = 0;
557  isvisible = false;
558  Reinit = true;
559  }
560  }
561  } else {
562  for (size_t i = 0; i < meline.size(); i++) {
563  if (meline[i] != NULL)
564  delete meline[i];
565  }
566  nbFeature.clear();
567  meline.clear();
568  nbFeatureTotal = 0;
569  isvisible = false;
570  }
571  }
572 }
573 
586  const vpImage<bool> *mask)
587 {
588  for (size_t i = 0; i < meline.size(); i++) {
589  if (meline[i] != NULL)
590  delete meline[i];
591  }
592 
593  nbFeature.clear();
594  meline.clear();
595  nbFeatureTotal = 0;
596 
597  if (!initMovingEdge(I, cMo, false, mask))
598  Reinit = true;
599 
600  Reinit = false;
601 }
602 
615  const vpCameraParameters &camera, const vpColor &col, unsigned int thickness,
616  bool displayFullModel)
617 {
618  std::vector<std::vector<double> > models =
619  getModelForDisplay(I.getWidth(), I.getHeight(), cMo, camera, displayFullModel);
620 
621  for (size_t i = 0; i < models.size(); i++) {
622  vpImagePoint ip1(models[i][1], models[i][2]);
623  vpImagePoint ip2(models[i][3], models[i][4]);
624  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
625  }
626 }
627 
640  const vpCameraParameters &camera, const vpColor &col, unsigned int thickness,
641  bool displayFullModel)
642 {
643  std::vector<std::vector<double> > models =
644  getModelForDisplay(I.getWidth(), I.getHeight(), cMo, camera, displayFullModel);
645 
646  for (size_t i = 0; i < models.size(); i++) {
647  vpImagePoint ip1(models[i][1], models[i][2]);
648  vpImagePoint ip2(models[i][3], models[i][4]);
649  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
650  }
651 }
652 
668 {
669  for (size_t i = 0; i < meline.size(); i++) {
670  if (meline[i] != NULL) {
671  meline[i]->display(I);
672  }
673  }
674 }
675 
677 {
678  for (size_t i = 0; i < meline.size(); i++) {
679  if (meline[i] != NULL) {
680  meline[i]->display(I);
681  }
682  }
683 }
684 
689 std::vector<std::vector<double> > vpMbtDistanceLine::getFeaturesForDisplay()
690 {
691  std::vector<std::vector<double> > features;
692 
693  for (size_t i = 0; i < meline.size(); i++) {
694  vpMbtMeLine *me_l = meline[i];
695  if (me_l != NULL) {
696  for (std::list<vpMeSite>::const_iterator it = me_l->getMeList().begin(); it != me_l->getMeList().end(); ++it) {
697  vpMeSite p_me_l = *it;
698 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
699  std::vector<double> params = {0, // ME
700  p_me_l.get_ifloat(), p_me_l.get_jfloat(), static_cast<double>(p_me_l.getState())};
701 #else
702  std::vector<double> params;
703  params.push_back(0); // ME
704  params.push_back(p_me_l.get_ifloat());
705  params.push_back(p_me_l.get_jfloat());
706  params.push_back(static_cast<double>(p_me_l.getState()));
707 #endif
708  features.push_back(params);
709  }
710  }
711  }
712 
713  return features;
714 }
715 
727 std::vector<std::vector<double> > vpMbtDistanceLine::getModelForDisplay(unsigned int width, unsigned int height,
728  const vpHomogeneousMatrix &cMo,
729  const vpCameraParameters &camera,
730  bool displayFullModel)
731 {
732  std::vector<std::vector<double> > models;
733 
734  if ((isvisible && isTrackedLine) || displayFullModel) {
735  p1->changeFrame(cMo);
736  p2->changeFrame(cMo);
737 
738  vpImagePoint ip1, ip2;
739  vpCameraParameters c = camera;
740  if (poly.getClipping() > 3) // Contains at least one FOV constraint
741  c.computeFov(width, height);
742 
743  poly.computePolygonClipped(c);
744 
745  if (poly.polyClipped.size() == 2 &&
746  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
747  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
748  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
749  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
750  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
751  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)) {
752 
753  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
754  if (useScanLine && !displayFullModel) {
755  hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst, true);
756  } else {
757  linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
758  }
759 
760  for (unsigned int i = 0; i < linesLst.size(); i++) {
761  linesLst[i].first.project();
762  linesLst[i].second.project();
763 
764  vpMeterPixelConversion::convertPoint(camera, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
765  vpMeterPixelConversion::convertPoint(camera, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
766 
767 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
768  std::vector<double> params = {0, // 0 for line parameters
769  ip1.get_i(), ip1.get_j(), ip2.get_i(), ip2.get_j()};
770 #else
771  std::vector<double> params;
772  params.push_back(0); // 0 for line parameters
773  params.push_back(ip1.get_i());
774  params.push_back(ip1.get_j());
775  params.push_back(ip2.get_i());
776  params.push_back(ip2.get_j());
777 #endif
778  models.push_back(params);
779  }
780  }
781  }
782 
783  return models;
784 }
785 
790 {
791  if (isvisible) {
792  L.resize(nbFeatureTotal, 6);
794  } else {
795  for (size_t i = 0; i < meline.size(); i++) {
796  nbFeature[i] = 0;
797  // To be consistent with nbFeature[i] = 0
798  std::list<vpMeSite> &me_site_list = meline[i]->getMeList();
799  me_site_list.clear();
800  }
801  nbFeatureTotal = 0;
802  }
803 }
804 
810 {
811  if (isvisible) {
812  try {
813  // feature projection
814  line->changeFrame(cMo);
815  line->projection();
816 
817  vpFeatureBuilder::create(featureline, *line);
818 
819  double rho = featureline.getRho();
820  double theta = featureline.getTheta();
821 
822  double co = cos(theta);
823  double si = sin(theta);
824 
825  double mx = 1.0 / cam.get_px();
826  double my = 1.0 / cam.get_py();
827  double xc = cam.get_u0();
828  double yc = cam.get_v0();
829 
830  double alpha_;
831  vpMatrix H = featureline.interaction();
832 
833  double x, y;
834  unsigned int j = 0;
835 
836  for (size_t i = 0; i < meline.size(); i++) {
837  for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin();
838  it != meline[i]->getMeList().end(); ++it) {
839  x = (double)it->j;
840  y = (double)it->i;
841 
842  x = (x - xc) * mx;
843  y = (y - yc) * my;
844 
845  alpha_ = x * si - y * co;
846 
847  double *Lrho = H[0];
848  double *Ltheta = H[1];
849  // Calculate interaction matrix for a distance
850  for (unsigned int k = 0; k < 6; k++) {
851  L[j][k] = (Lrho[k] + alpha_ * Ltheta[k]);
852  }
853  error[j] = rho - (x * co + y * si);
854  j++;
855  }
856  }
857  } catch (...) {
858  // Handle potential exception: due to a degenerate case: the image of the straight line is a point!
859  // Set the corresponding interaction matrix part to zero
860  unsigned int j = 0;
861  for (size_t i = 0; i < meline.size(); i++) {
862  for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin();
863  it != meline[i]->getMeList().end(); ++it) {
864  for (unsigned int k = 0; k < 6; k++) {
865  L[j][k] = 0.0;
866  }
867 
868  error[j] = 0.0;
869  j++;
870  }
871  }
872  }
873  }
874 }
875 
884 bool vpMbtDistanceLine::closeToImageBorder(const vpImage<unsigned char> &I, const unsigned int threshold)
885 {
886  if (threshold > I.getWidth() || threshold > I.getHeight()) {
887  return true;
888  }
889  if (isvisible) {
890 
891  for (size_t i = 0; i < meline.size(); i++) {
892  for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin(); it != meline[i]->getMeList().end();
893  ++it) {
894  int i_ = it->i;
895  int j_ = it->j;
896 
897  if (i_ < 0 || j_ < 0) { // out of image.
898  return true;
899  }
900 
901  if (((unsigned int)i_ > (I.getHeight() - threshold)) || (unsigned int)i_ < threshold ||
902  ((unsigned int)j_ > (I.getWidth() - threshold)) || (unsigned int)j_ < threshold) {
903  return true;
904  }
905  }
906  }
907  }
908  return false;
909 }
void addPoint(unsigned int n, const vpPoint &P)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
double get_i() const
Definition: vpImagePoint.h:121
void trackMovingEdge(const vpImage< unsigned char > &I)
double get_oY() const
Get the point oY coordinate in the object frame.
Definition: vpPoint.cpp:463
vpMeSiteState getState() const
Definition: vpMeSite.h:190
vpMatrix interaction(unsigned int select=FEATURE_ALL)
unsigned int nbFeatureTotal
The number of moving edges.
void buildFrom(vpPoint &_p1, vpPoint &_p2, vpUniRand &rand_gen)
uint32_t next()
Definition: vpUniRand.cpp:146
vpLine * line
The 3D line.
void setD(double d)
Definition: vpPlane.h:91
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const
Definition: vpLine.cpp:330
bool Reinit
Indicates if the line has to be reinitialized.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:350
void setC(double c)
Definition: vpPlane.h:89
Implementation of an homogeneous matrix and operations on such kind of matrices.
std::list< int > Lindex_polygon
Index of the faces which contain the line.
Performs search in a given direction(normal) for a given distance(pixels) for a given &#39;site&#39;...
Definition: vpMeSite.h:71
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
virtual void setNbPoint(unsigned int nb)
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
std::vector< bool > Lindex_polygon_tracked
vpPoint * p1
The first extremity.
void displayMovingEdges(const vpImage< unsigned char > &I)
double getRho() const
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
Definition: vpMe.h:60
double get_oX() const
Get the point oX coordinate in the object frame.
Definition: vpPoint.cpp:461
bool isvisible
Indicates if the line is visible or not.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:81
void setA(double a)
Definition: vpPlane.h:85
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition: vpPolygon3D.h:83
void setTracked(const std::string &name, const bool &track)
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition: vpLine.h:104
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
void setWorldCoordinates(const double &oA1, const double &oB1, const double &oC1, const double &oD1, const double &oA2, const double &oB2, const double &oC2, const double &oD2)
Definition: vpLine.cpp:85
double getD() const
Definition: vpPlane.h:111
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
vpPoint * p2
The second extremity.
unsigned int getClipping() const
Definition: vpPolygon3D.h:118
vpColVector error
The error vector.
double getB() const
Definition: vpPlane.h:107
double get_j() const
Definition: vpImagePoint.h:132
Generic class defining intrinsic camera parameters.
double getTheta() const
double get_jfloat() const
Definition: vpMeSite.h:167
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const
Definition: vpPoint.cpp:239
double get_oZ() const
Get the point oZ coordinate in the object frame.
Definition: vpPoint.cpp:465
void projection()
Definition: vpLine.cpp:193
double getA() const
Definition: vpPlane.h:105
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:310
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
double getTheta() const
Definition: vpLine.h:146
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
unsigned int getHeight() const
Definition: vpImage.h:188
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void setMovingEdge(vpMe *Me)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
std::vector< std::vector< double > > getFeaturesForDisplay()
double getRho() const
Definition: vpLine.h:134
double getC() const
Definition: vpPlane.h:109
double get_ifloat() const
Definition: vpMeSite.h:160
void addPolygon(const int &index)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
Class for generating random numbers with uniform probability density.
Definition: vpUniRand.h:100
std::vector< vpMbtMeLine * > meline
The moving edge container.
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:58
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setB(double b)
Definition: vpPlane.h:87
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpImage< bool > *mask=NULL)
unsigned int getWidth() const
Definition: vpImage.h:246
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
vpMatrix L
The interaction matrix.
std::vector< unsigned int > nbFeature
The number of moving edges.
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, bool doNotTrack, const vpImage< bool > *mask=NULL)
bool useScanLine
Use scanline rendering.
void computeFov(const unsigned int &w, const unsigned int &h)