Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpMbtDistanceLine.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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  * Romain Tallonneau
36  *
37 *****************************************************************************/
38 #include <visp3/core/vpConfig.h>
39 
45 #include <stdlib.h>
46 #include <visp3/core/vpMeterPixelConversion.h>
47 #include <visp3/core/vpPlane.h>
48 #include <visp3/mbt/vpMbtDistanceLine.h>
49 #include <visp3/visual_features/vpFeatureBuilder.h>
50 
52 void buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane);
53 void buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L);
54 
59  : name(), index(0), cam(), me(nullptr), isTrackedLine(true), isTrackedLineWithVisibility(true), wmean(1), featureline(),
60  poly(), useScanLine(false), meline(), line(nullptr), p1(nullptr), p2(nullptr), L(), error(), nbFeature(), nbFeatureTotal(0),
61  Reinit(false), hiddenface(nullptr), Lindex_polygon(), Lindex_polygon_tracked(), isvisible(false)
62 { }
63 
68 {
69  if (line != nullptr)
70  delete line;
71 
72  for (unsigned int i = 0; i < meline.size(); i++)
73  if (meline[i] != nullptr)
74  delete meline[i];
75 
76  meline.clear();
77 }
78 
85 void vpMbtDistanceLine::project(const vpHomogeneousMatrix &cMo)
86 {
87  line->project(cMo);
88  p1->project(cMo);
89  p2->project(cMo);
90 }
91 
101 void buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane)
102 {
103  vpColVector a(3);
104  vpColVector b(3);
105 
106  // Calculate vector corresponding to PQ
107  a[0] = P.get_oX() - Q.get_oX();
108  a[1] = P.get_oY() - Q.get_oY();
109  a[2] = P.get_oZ() - Q.get_oZ();
110 
111  // Calculate vector corresponding to PR
112  b[0] = P.get_oX() - R.get_oX();
113  b[1] = P.get_oY() - R.get_oY();
114  b[2] = P.get_oZ() - R.get_oZ();
115 
116  // Calculate normal vector to plane PQ x PR
118 
119  // Equation of the plane is given by:
120  double A = n[0];
121  double B = n[1];
122  double C = n[2];
123  double D = -(A * P.get_oX() + B * P.get_oY() + C * P.get_oZ());
124 
125  double norm = sqrt(A * A + B * B + C * C);
126  plane.setA(A / norm);
127  plane.setB(B / norm);
128  plane.setC(C / norm);
129  plane.setD(D / norm);
130 }
131 
145 void buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L)
146 {
147  vpPlane plane1;
148  vpPlane plane2;
149  buildPlane(P1, P2, P3, plane1);
150  buildPlane(P1, P2, P4, plane2);
151 
152  L.setWorldCoordinates(plane1.getA(), plane1.getB(), plane1.getC(), plane1.getD(), plane2.getA(), plane2.getB(),
153  plane2.getC(), plane2.getD());
154 }
155 
165 {
166  if (line == nullptr) {
167  line = new vpLine;
168  }
169 
170  poly.setNbPoint(2);
171  poly.addPoint(0, _p1);
172  poly.addPoint(1, _p2);
173 
174  p1 = &poly.p[0];
175  p2 = &poly.p[1];
176 
177  vpColVector V1(3);
178  vpColVector V2(3);
179 
180  V1[0] = p1->get_oX();
181  V1[1] = p1->get_oY();
182  V1[2] = p1->get_oZ();
183  V2[0] = p2->get_oX();
184  V2[1] = p2->get_oY();
185  V2[2] = p2->get_oZ();
186 
187  // if((V1-V2).sumSquare()!=0)
188  if (std::fabs((V1 - V2).sumSquare()) > std::numeric_limits<double>::epsilon()) {
189  vpColVector V3(3);
190  V3[0] = double(rand_gen.next() % 1000) / 100;
191  V3[1] = double(rand_gen.next() % 1000) / 100;
192  V3[2] = double(rand_gen.next() % 1000) / 100;
193 
194  vpColVector v_tmp1, v_tmp2;
195  v_tmp1 = V2 - V1;
196  v_tmp2 = V3 - V1;
197  vpColVector V4 = vpColVector::cross(v_tmp1, v_tmp2);
198 
199  vpPoint P3(V3[0], V3[1], V3[2]);
200  vpPoint P4(V4[0], V4[1], V4[2]);
201  buildLine(*p1, *p2, P3, P4, *line);
202  }
203  else {
204  vpPoint P3(V1[0], V1[1], V1[2]);
205  vpPoint P4(V2[0], V2[1], V2[2]);
206  buildLine(*p1, *p2, P3, P4, *line);
207  }
208 }
209 
215 void vpMbtDistanceLine::addPolygon(const int &idx)
216 {
217  Lindex_polygon.push_back(idx);
218  Lindex_polygon_tracked.push_back(true);
219 }
220 
228 void vpMbtDistanceLine::setTracked(const std::string &polyname, const bool &track)
229 {
230  unsigned int ind = 0;
231  for (std::list<int>::const_iterator itpoly = Lindex_polygon.begin(); itpoly != Lindex_polygon.end(); ++itpoly) {
232  if ((*hiddenface)[(unsigned)(*itpoly)]->getName() == polyname) {
233  Lindex_polygon_tracked[ind] = track;
234  }
235  ind++;
236  }
237 
238  isTrackedLine = false;
239  for (unsigned int i = 0; i < Lindex_polygon_tracked.size(); i++)
240  if (Lindex_polygon_tracked[i]) {
241  isTrackedLine = true;
242  break;
243  }
244 
245  if (!isTrackedLine) {
246  isTrackedLineWithVisibility = false;
247  return;
248  }
249 
250  updateTracked();
251 }
252 
258 {
259  if (!isTrackedLine) {
260  isTrackedLineWithVisibility = false;
261  return;
262  }
263 
264  unsigned int ind = 0;
265  isTrackedLineWithVisibility = false;
266  for (std::list<int>::const_iterator itpoly = Lindex_polygon.begin(); itpoly != Lindex_polygon.end(); ++itpoly) {
267  if ((*hiddenface)[(unsigned)(*itpoly)]->isVisible() && Lindex_polygon_tracked[ind]) {
268  isTrackedLineWithVisibility = true;
269  break;
270  }
271  ind++;
272  }
273 }
274 
281 {
282  me = _me;
283 
284  for (unsigned int i = 0; i < meline.size(); i++)
285  if (meline[i] != nullptr) {
286  // nbFeature[i] = 0;
287  meline[i]->reset();
288  meline[i]->setMe(me);
289  }
290 
291  // nbFeatureTotal = 0;
292 }
293 
306  const vpImage<bool> *mask)
307 {
308  for (unsigned int i = 0; i < meline.size(); i++) {
309  if (meline[i] != nullptr)
310  delete meline[i];
311  }
312 
313  meline.clear();
314  nbFeature.clear();
315  nbFeatureTotal = 0;
316 
317  if (isvisible) {
318  p1->changeFrame(cMo);
319  p2->changeFrame(cMo);
320 
321  if (poly.getClipping() > 3) // Contains at least one FOV constraint
322  cam.computeFov(I.getWidth(), I.getHeight());
323 
324  poly.computePolygonClipped(cam);
325 
326  if (poly.polyClipped.size() == 2) { // Les points sont visibles.
327 
328  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
329 
330  if (useScanLine) {
331  hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst);
332  }
333  else {
334  linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
335  }
336 
337  if (linesLst.size() == 0) {
338  return false;
339  }
340 
341  line->changeFrame(cMo);
342  try {
343  line->projection();
344  }
345  catch (...) {
346  isvisible = false;
347  return false;
348  }
349  double rho, theta;
350  // rho theta uv
352 
353  while (theta > M_PI) {
354  theta -= M_PI;
355  }
356  while (theta < -M_PI) {
357  theta += M_PI;
358  }
359 
360  if (theta < -M_PI / 2.0)
361  theta = -theta - 3 * M_PI / 2.0;
362  else
363  theta = M_PI / 2.0 - theta;
364 
365  for (unsigned int i = 0; i < linesLst.size(); i++) {
366  vpImagePoint ip1, ip2;
367 
368  linesLst[i].first.project();
369  linesLst[i].second.project();
370 
371  vpMeterPixelConversion::convertPoint(cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
372  vpMeterPixelConversion::convertPoint(cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
373 
374  vpMbtMeLine *melinePt = new vpMbtMeLine;
375  melinePt->setMask(*mask);
376  melinePt->setMe(me);
377 
378  melinePt->setInitRange(0);
379 
380  int marge = /*10*/ 5; // ou 5 normalement
381  if (ip1.get_j() < ip2.get_j()) {
382  melinePt->jmin = (int)ip1.get_j() - marge;
383  melinePt->jmax = (int)ip2.get_j() + marge;
384  }
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  }
393  else {
394  melinePt->imin = (int)ip2.get_i() - marge;
395  melinePt->imax = (int)ip1.get_i() + marge;
396  }
397 
398  try {
399  melinePt->initTracking(I, ip1, ip2, rho, theta, doNotTrack);
400  meline.push_back(melinePt);
401  nbFeature.push_back((unsigned int)melinePt->getMeList().size());
402  nbFeatureTotal += nbFeature.back();
403  }
404  catch (...) {
405  delete melinePt;
406  isvisible = false;
407  return false;
408  }
409  }
410  }
411  else {
412  isvisible = false;
413  }
414  }
415 
416  return true;
417 }
418 
425 {
426  if (isvisible) {
427  try {
428  nbFeature.clear();
429  nbFeatureTotal = 0;
430  for (size_t i = 0; i < meline.size(); i++) {
431  meline[i]->track(I);
432  nbFeature.push_back((unsigned int)meline[i]->getMeList().size());
433  nbFeatureTotal += (unsigned int)meline[i]->getMeList().size();
434  }
435  }
436  catch (...) {
437  for (size_t i = 0; i < meline.size(); i++) {
438  if (meline[i] != nullptr)
439  delete meline[i];
440  }
441 
442  nbFeature.clear();
443  meline.clear();
444  nbFeatureTotal = 0;
445  Reinit = true;
446  isvisible = false;
447  }
448  }
449 }
450 
458 {
459  if (isvisible) {
460  p1->changeFrame(cMo);
461  p2->changeFrame(cMo);
462 
463  if (poly.getClipping() > 3) // Contains at least one FOV constraint
464  cam.computeFov(I.getWidth(), I.getHeight());
465 
466  poly.computePolygonClipped(cam);
467 
468  if (poly.polyClipped.size() == 2) { // Les points sont visibles.
469 
470  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
471 
472  if (useScanLine) {
473  hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst);
474  }
475  else {
476  linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
477  }
478 
479  if (linesLst.size() != meline.size() || linesLst.size() == 0) {
480  for (size_t i = 0; i < meline.size(); i++) {
481  if (meline[i] != nullptr)
482  delete meline[i];
483  }
484 
485  meline.clear();
486  nbFeature.clear();
487  nbFeatureTotal = 0;
488  isvisible = false;
489  Reinit = true;
490  }
491  else {
492  line->changeFrame(cMo);
493  try {
494  line->projection();
495  }
496  catch (...) {
497  for (size_t j = 0; j < meline.size(); j++) {
498  if (meline[j] != nullptr)
499  delete meline[j];
500  }
501 
502  meline.clear();
503  nbFeature.clear();
504  nbFeatureTotal = 0;
505  isvisible = false;
506  Reinit = true;
507  return;
508  }
509  double rho, theta;
510  // rho theta uv
512 
513  while (theta > M_PI) {
514  theta -= M_PI;
515  }
516  while (theta < -M_PI) {
517  theta += M_PI;
518  }
519 
520  if (theta < -M_PI / 2.0)
521  theta = -theta - 3 * M_PI / 2.0;
522  else
523  theta = M_PI / 2.0 - theta;
524 
525  try {
526  for (unsigned int i = 0; i < linesLst.size(); i++) {
527  vpImagePoint ip1, ip2;
528 
529  linesLst[i].first.project();
530  linesLst[i].second.project();
531 
532  vpMeterPixelConversion::convertPoint(cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
533  vpMeterPixelConversion::convertPoint(cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
534 
535  int marge = /*10*/ 5; // ou 5 normalement
536  if (ip1.get_j() < ip2.get_j()) {
537  meline[i]->jmin = (int)ip1.get_j() - marge;
538  meline[i]->jmax = (int)ip2.get_j() + marge;
539  }
540  else {
541  meline[i]->jmin = (int)ip2.get_j() - marge;
542  meline[i]->jmax = (int)ip1.get_j() + marge;
543  }
544  if (ip1.get_i() < ip2.get_i()) {
545  meline[i]->imin = (int)ip1.get_i() - marge;
546  meline[i]->imax = (int)ip2.get_i() + marge;
547  }
548  else {
549  meline[i]->imin = (int)ip2.get_i() - marge;
550  meline[i]->imax = (int)ip1.get_i() + marge;
551  }
552 
553  meline[i]->updateParameters(I, ip1, ip2, rho, theta);
554  nbFeature[i] = (unsigned int)meline[i]->getMeList().size();
556  }
557  }
558  catch (...) {
559  for (size_t j = 0; j < meline.size(); j++) {
560  if (meline[j] != nullptr)
561  delete meline[j];
562  }
563 
564  meline.clear();
565  nbFeature.clear();
566  nbFeatureTotal = 0;
567  isvisible = false;
568  Reinit = true;
569  }
570  }
571  }
572  else {
573  for (size_t i = 0; i < meline.size(); i++) {
574  if (meline[i] != nullptr)
575  delete meline[i];
576  }
577  nbFeature.clear();
578  meline.clear();
579  nbFeatureTotal = 0;
580  isvisible = false;
581  }
582  }
583 }
584 
597  const vpImage<bool> *mask)
598 {
599  for (size_t i = 0; i < meline.size(); i++) {
600  if (meline[i] != nullptr)
601  delete meline[i];
602  }
603 
604  nbFeature.clear();
605  meline.clear();
606  nbFeatureTotal = 0;
607 
608  if (!initMovingEdge(I, cMo, false, mask))
609  Reinit = true;
610 
611  Reinit = false;
612 }
613 
626  const vpCameraParameters &camera, const vpColor &col, unsigned int thickness,
627  bool displayFullModel)
628 {
629  std::vector<std::vector<double> > models =
630  getModelForDisplay(I.getWidth(), I.getHeight(), cMo, camera, displayFullModel);
631 
632  for (size_t i = 0; i < models.size(); i++) {
633  vpImagePoint ip1(models[i][1], models[i][2]);
634  vpImagePoint ip2(models[i][3], models[i][4]);
635  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
636  }
637 }
638 
651  const vpCameraParameters &camera, const vpColor &col, unsigned int thickness,
652  bool displayFullModel)
653 {
654  std::vector<std::vector<double> > models =
655  getModelForDisplay(I.getWidth(), I.getHeight(), cMo, camera, displayFullModel);
656 
657  for (size_t i = 0; i < models.size(); i++) {
658  vpImagePoint ip1(models[i][1], models[i][2]);
659  vpImagePoint ip2(models[i][3], models[i][4]);
660  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
661  }
662 }
663 
679 {
680  for (size_t i = 0; i < meline.size(); i++) {
681  if (meline[i] != nullptr) {
682  meline[i]->display(I);
683  }
684  }
685 }
686 
688 {
689  for (size_t i = 0; i < meline.size(); i++) {
690  if (meline[i] != nullptr) {
691  meline[i]->display(I);
692  }
693  }
694 }
695 
700 std::vector<std::vector<double> > vpMbtDistanceLine::getFeaturesForDisplay()
701 {
702  std::vector<std::vector<double> > features;
703 
704  for (size_t i = 0; i < meline.size(); i++) {
705  vpMbtMeLine *me_l = meline[i];
706  if (me_l != nullptr) {
707  for (std::list<vpMeSite>::const_iterator it = me_l->getMeList().begin(); it != me_l->getMeList().end(); ++it) {
708  vpMeSite p_me_l = *it;
709 #if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
710  std::vector<double> params = { 0, //ME
711  p_me_l.get_ifloat(),
712  p_me_l.get_jfloat(),
713  static_cast<double>(p_me_l.getState()) };
714 #else
715  std::vector<double> params;
716  params.push_back(0); // ME
717  params.push_back(p_me_l.get_ifloat());
718  params.push_back(p_me_l.get_jfloat());
719  params.push_back(static_cast<double>(p_me_l.getState()));
720 #endif
721 
722  features.push_back(params);
723  }
724  }
725  }
726 
727  return features;
728 }
729 
741 std::vector<std::vector<double> > vpMbtDistanceLine::getModelForDisplay(unsigned int width, unsigned int height,
742  const vpHomogeneousMatrix &cMo,
743  const vpCameraParameters &camera,
744  bool displayFullModel)
745 {
746  std::vector<std::vector<double> > models;
747 
748  if ((isvisible && isTrackedLine) || displayFullModel) {
749  p1->changeFrame(cMo);
750  p2->changeFrame(cMo);
751 
752  vpImagePoint ip1, ip2;
753  vpCameraParameters c = camera;
754  if (poly.getClipping() > 3) // Contains at least one FOV constraint
755  c.computeFov(width, height);
756 
757  poly.computePolygonClipped(c);
758 
759  if (poly.polyClipped.size() == 2 &&
760  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
761  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
762  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
763  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
764  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
765  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)) {
766 
767  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
768  if (useScanLine && !displayFullModel) {
769  hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst, true);
770  }
771  else {
772  linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
773  }
774 
775  for (unsigned int i = 0; i < linesLst.size(); i++) {
776  linesLst[i].first.project();
777  linesLst[i].second.project();
778 
779  vpMeterPixelConversion::convertPoint(camera, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
780  vpMeterPixelConversion::convertPoint(camera, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
781 
782 #if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
783  std::vector<double> params = { 0, //0 for line parameters
784  ip1.get_i(),
785  ip1.get_j(),
786  ip2.get_i(),
787  ip2.get_j() };
788 #else
789  std::vector<double> params;
790  params.push_back(0); //0 for line parameters
791  params.push_back(ip1.get_i());
792  params.push_back(ip1.get_j());
793  params.push_back(ip2.get_i());
794  params.push_back(ip2.get_j());
795 #endif
796 
797  models.push_back(params);
798  }
799  }
800  }
801 
802  return models;
803 }
804 
809 {
810  if (isvisible) {
811  L.resize(nbFeatureTotal, 6);
813  }
814  else {
815  for (size_t i = 0; i < meline.size(); i++) {
816  nbFeature[i] = 0;
817  // To be consistent with nbFeature[i] = 0
818  std::list<vpMeSite> &me_site_list = meline[i]->getMeList();
819  me_site_list.clear();
820  }
821  nbFeatureTotal = 0;
822  }
823 }
824 
830 {
831  if (isvisible) {
832  try {
833  // feature projection
834  line->changeFrame(cMo);
835  line->projection();
836 
837  vpFeatureBuilder::create(featureline, *line);
838 
839  double rho = featureline.getRho();
840  double theta = featureline.getTheta();
841 
842  double co = cos(theta);
843  double si = sin(theta);
844 
845  double mx = 1.0 / cam.get_px();
846  double my = 1.0 / cam.get_py();
847  double xc = cam.get_u0();
848  double yc = cam.get_v0();
849 
850  double alpha_;
851  vpMatrix H = featureline.interaction();
852 
853  double x, y;
854  unsigned int j = 0;
855 
856  for (size_t i = 0; i < meline.size(); i++) {
857  for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin();
858  it != meline[i]->getMeList().end(); ++it) {
859  x = (double)it->m_j;
860  y = (double)it->m_i;
861 
862  x = (x - xc) * mx;
863  y = (y - yc) * my;
864 
865  alpha_ = x * si - y * co;
866 
867  double *Lrho = H[0];
868  double *Ltheta = H[1];
869  // Calculate interaction matrix for a distance
870  for (unsigned int k = 0; k < 6; k++) {
871  L[j][k] = (Lrho[k] + alpha_ * Ltheta[k]);
872  }
873  error[j] = rho - (x * co + y * si);
874  j++;
875  }
876  }
877  }
878  catch (...) {
879  // Handle potential exception: due to a degenerate case: the image of the straight line is a point!
880  // Set the corresponding interaction matrix part to zero
881  unsigned int j = 0;
882  for (size_t i = 0; i < meline.size(); i++) {
883  for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin();
884  it != meline[i]->getMeList().end(); ++it) {
885  for (unsigned int k = 0; k < 6; k++) {
886  L[j][k] = 0.0;
887  }
888 
889  error[j] = 0.0;
890  j++;
891  }
892  }
893  }
894  }
895 }
896 
905 bool vpMbtDistanceLine::closeToImageBorder(const vpImage<unsigned char> &I, const unsigned int threshold)
906 {
907  if (threshold > I.getWidth() || threshold > I.getHeight()) {
908  return true;
909  }
910  if (isvisible) {
911 
912  for (size_t i = 0; i < meline.size(); i++) {
913  for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin(); it != meline[i]->getMeList().end();
914  ++it) {
915  int i_ = it->m_i;
916  int j_ = it->m_j;
917 
918  if (i_ < 0 || j_ < 0) { // out of image.
919  return true;
920  }
921 
922  if (((unsigned int)i_ >(I.getHeight() - threshold)) || (unsigned int)i_ < threshold ||
923  ((unsigned int)j_ >(I.getWidth() - threshold)) || (unsigned int)j_ < threshold) {
924  return true;
925  }
926  }
927  }
928  }
929  return false;
930 }
931 END_VISP_NAMESPACE
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:362
Generic class defining intrinsic camera parameters.
void computeFov(const unsigned int &w, const unsigned int &h)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:1259
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:1143
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
double getTheta() const
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
double getRho() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
double get_j() const
Definition: vpImagePoint.h:125
double get_i() const
Definition: vpImagePoint.h:114
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition: vpLine.h:103
double getRho() const
Definition: vpLine.h:132
void projection() VP_OVERRIDE
Definition: vpLine.cpp:200
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE
Definition: vpLine.cpp:345
double getTheta() const
Definition: vpLine.h:143
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
void setMovingEdge(vpMe *Me)
std::vector< unsigned int > nbFeature
The number of moving edges.
void displayMovingEdges(const vpImage< unsigned char > &I)
std::vector< bool > Lindex_polygon_tracked
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
bool isvisible
Indicates if the line is visible or not.
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
vpPoint * p2
The second extremity.
vpLine * line
The 3D line.
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
std::list< int > Lindex_polygon
Index of the faces which contain the line.
bool isVisible() const
void buildFrom(vpPoint &_p1, vpPoint &_p2, vpUniRand &rand_gen)
unsigned int nbFeatureTotal
The number of moving edges.
bool Reinit
Indicates if the line has to be reinitialized.
std::string getName() const
vpColVector error
The error vector.
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, bool doNotTrack, const vpImage< bool > *mask=nullptr)
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
std::vector< std::vector< double > > getFeaturesForDisplay()
bool useScanLine
Use scanline rendering.
vpPoint * p1
The first extremity.
std::vector< vpMbtMeLine * > meline
The moving edge container.
vpMatrix L
The interaction matrix.
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpImage< bool > *mask=nullptr)
void setTracked(const std::string &name, const bool &track)
void addPolygon(const int &index)
void trackMovingEdge(const vpImage< unsigned char > &I)
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'....
Definition: vpMeSite.h:68
vpMeSiteState getState() const
Definition: vpMeSite.h:269
double get_ifloat() const
Definition: vpMeSite.h:195
double get_jfloat() const
Definition: vpMeSite.h:201
Definition: vpMe.h:134
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:57
void setA(double a)
Definition: vpPlane.h:80
void setD(double d)
Definition: vpPlane.h:86
double getD() const
Definition: vpPlane.h:106
void setC(double c)
Definition: vpPlane.h:84
double getA() const
Definition: vpPlane.h:100
double getC() const
Definition: vpPlane.h:104
double getB() const
Definition: vpPlane.h:102
void setB(double b)
Definition: vpPlane.h:82
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:79
double get_oX() const
Get the point oX coordinate in the object frame.
Definition: vpPoint.cpp:411
double get_oZ() const
Get the point oZ coordinate in the object frame.
Definition: vpPoint.cpp:415
double get_oY() const
Get the point oY coordinate in the object frame.
Definition: vpPoint.cpp:413
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE
Definition: vpPoint.cpp:267
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:79
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
virtual void setNbPoint(unsigned int nb)
unsigned int getClipping() const
Definition: vpPolygon3D.h:116
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition: vpPolygon3D.h:81
void addPoint(unsigned int n, const vpPoint &P)
Class for generating random numbers with uniform probability density.
Definition: vpUniRand.h:125
uint32_t next()
Definition: vpUniRand.cpp:145