Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMbtDistanceLine.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Make the complete tracking of an object by using its CAD model
32 *
33 * Authors:
34 * Romain Tallonneau
35 */
36#include <visp3/core/vpConfig.h>
37
42
43#include <stdlib.h>
44#include <visp3/core/vpMeterPixelConversion.h>
45#include <visp3/core/vpPlane.h>
46#include <visp3/mbt/vpMbtDistanceLine.h>
47#include <visp3/visual_features/vpFeatureBuilder.h>
48
50
51namespace
52{
53const unsigned int defaultRange = 0U;
54}
55
56void buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane);
57void buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L);
58
63 : name(), index(0), cam(), me(nullptr), isTrackedLine(true), isTrackedLineWithVisibility(true), wmean(1), featureline(),
64 poly(), useScanLine(false), meline(), line(nullptr), p1(nullptr), p2(nullptr), L(), error(), nbFeature(), nbFeatureTotal(0),
66{ }
67
72{
73 if (line != nullptr)
74 delete line;
75
76 for (unsigned int i = 0; i < meline.size(); i++)
77 if (meline[i] != nullptr)
78 delete meline[i];
79
80 meline.clear();
81}
82
89void vpMbtDistanceLine::project(const vpHomogeneousMatrix &cMo)
90{
91 line->project(cMo);
92 p1->project(cMo);
93 p2->project(cMo);
94}
95
105void buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane)
106{
107 vpColVector a(3);
108 vpColVector b(3);
109
110 // Calculate vector corresponding to PQ
111 a[0] = P.get_oX() - Q.get_oX();
112 a[1] = P.get_oY() - Q.get_oY();
113 a[2] = P.get_oZ() - Q.get_oZ();
114
115 // Calculate vector corresponding to PR
116 b[0] = P.get_oX() - R.get_oX();
117 b[1] = P.get_oY() - R.get_oY();
118 b[2] = P.get_oZ() - R.get_oZ();
119
120 // Calculate normal vector to plane PQ x PR
122
123 // Equation of the plane is given by:
124 double A = n[0];
125 double B = n[1];
126 double C = n[2];
127 double D = -(A * P.get_oX() + B * P.get_oY() + C * P.get_oZ());
128
129 double norm = sqrt(A * A + B * B + C * C);
130 plane.setA(A / norm);
131 plane.setB(B / norm);
132 plane.setC(C / norm);
133 plane.setD(D / norm);
134}
135
149void buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L)
150{
151 vpPlane plane1;
152 vpPlane plane2;
153 buildPlane(P1, P2, P3, plane1);
154 buildPlane(P1, P2, P4, plane2);
155
156 L.setWorldCoordinates(plane1.getA(), plane1.getB(), plane1.getC(), plane1.getD(), plane2.getA(), plane2.getB(),
157 plane2.getC(), plane2.getD());
158}
159
169{
170 if (line == nullptr) {
171 line = new vpLine;
172 }
173
174 poly.setNbPoint(2);
175 poly.addPoint(0, _p1);
176 poly.addPoint(1, _p2);
177
178 p1 = &poly.p[0];
179 p2 = &poly.p[1];
180
181 vpColVector V1(3);
182 vpColVector V2(3);
183
184 V1[0] = p1->get_oX();
185 V1[1] = p1->get_oY();
186 V1[2] = p1->get_oZ();
187 V2[0] = p2->get_oX();
188 V2[1] = p2->get_oY();
189 V2[2] = p2->get_oZ();
190
191 // if((V1-V2).sumSquare()!=0)
192 if (std::fabs((V1 - V2).sumSquare()) > std::numeric_limits<double>::epsilon()) {
193 vpColVector V3(3);
194 V3[0] = double(rand_gen.next() % 1000) / 100;
195 V3[1] = double(rand_gen.next() % 1000) / 100;
196 V3[2] = double(rand_gen.next() % 1000) / 100;
197
198 vpColVector v_tmp1, v_tmp2;
199 v_tmp1 = V2 - V1;
200 v_tmp2 = V3 - V1;
201 vpColVector V4 = vpColVector::cross(v_tmp1, v_tmp2);
202
203 vpPoint P3(V3[0], V3[1], V3[2]);
204 vpPoint P4(V4[0], V4[1], V4[2]);
205 buildLine(*p1, *p2, P3, P4, *line);
206 }
207 else {
208 vpPoint P3(V1[0], V1[1], V1[2]);
209 vpPoint P4(V2[0], V2[1], V2[2]);
210 buildLine(*p1, *p2, P3, P4, *line);
211 }
212}
213
220{
221 Lindex_polygon.push_back(idx);
222 Lindex_polygon_tracked.push_back(true);
223}
224
232void vpMbtDistanceLine::setTracked(const std::string &polyname, const bool &track)
233{
234 unsigned int ind = 0;
235 for (std::list<int>::const_iterator itpoly = Lindex_polygon.begin(); itpoly != Lindex_polygon.end(); ++itpoly) {
236 if ((*hiddenface)[static_cast<unsigned int>(*itpoly)]->getName() == polyname) {
237 Lindex_polygon_tracked[ind] = track;
238 }
239 ind++;
240 }
241
242 isTrackedLine = false;
243 for (unsigned int i = 0; i < Lindex_polygon_tracked.size(); i++)
244 if (Lindex_polygon_tracked[i]) {
245 isTrackedLine = true;
246 break;
247 }
248
249 if (!isTrackedLine) {
250 isTrackedLineWithVisibility = false;
251 return;
252 }
253
255}
256
262{
263 if (!isTrackedLine) {
264 isTrackedLineWithVisibility = false;
265 return;
266 }
267
268 unsigned int ind = 0;
269 isTrackedLineWithVisibility = false;
270 for (std::list<int>::const_iterator itpoly = Lindex_polygon.begin(); itpoly != Lindex_polygon.end(); ++itpoly) {
271 if ((*hiddenface)[static_cast<unsigned int>(*itpoly)]->isVisible() && Lindex_polygon_tracked[ind]) {
272 isTrackedLineWithVisibility = true;
273 break;
274 }
275 ind++;
276 }
277}
278
285{
286 me = _me;
287
288 for (unsigned int i = 0; i < meline.size(); i++)
289 if (meline[i] != nullptr) {
290 // nbFeature[i] = 0;
291 meline[i]->reset();
292 meline[i]->setMe(me);
293 }
294
295 // nbFeatureTotal = 0;
296}
297
312 const vpImage<bool> *mask, const int &initRange)
313{
314 for (unsigned int i = 0; i < meline.size(); i++) {
315 if (meline[i] != nullptr)
316 delete meline[i];
317 }
318
319 meline.clear();
320 nbFeature.clear();
321 nbFeatureTotal = 0;
322
323 if (isvisible) {
324 p1->changeFrame(cMo);
325 p2->changeFrame(cMo);
326
327 if (poly.getClipping() > 3) // Contains at least one FOV constraint
328 cam.computeFov(I.getWidth(), I.getHeight());
329
330 poly.computePolygonClipped(cam);
331
332 if (poly.polyClipped.size() == 2) { // Les points sont visibles.
333
334 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
335
336 if (useScanLine) {
337 hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst);
338 }
339 else {
340 linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
341 }
342
343 if (linesLst.size() == 0) {
344 return false;
345 }
346
347 line->changeFrame(cMo);
348 try {
349 line->projection();
350 }
351 catch (...) {
352 isvisible = false;
353 return false;
354 }
355 double rho, theta;
356 // rho theta uv
357 vpMeterPixelConversion::convertLine(cam, line->getRho(), line->getTheta(), rho, theta);
358
359 while (theta > M_PI) {
360 theta -= M_PI;
361 }
362 while (theta < -M_PI) {
363 theta += M_PI;
364 }
365
366 if (theta < -M_PI / 2.0)
367 theta = -theta - 3 * M_PI / 2.0;
368 else
369 theta = M_PI / 2.0 - theta;
370
371 for (unsigned int i = 0; i < linesLst.size(); i++) {
372 vpImagePoint ip1, ip2;
373
374 linesLst[i].first.project();
375 linesLst[i].second.project();
376
377 vpMeterPixelConversion::convertPoint(cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
378 vpMeterPixelConversion::convertPoint(cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
379
380 unsigned int initRange_;
381 if (initRange < 0) {
382 initRange_ = defaultRange;
383 }
384 else {
385 initRange_ = static_cast<unsigned int>(initRange);
386 }
387 int oldInitRange = me->getInitRange();
388 me->setInitRange(initRange_);
389 vpMbtMeLine *melinePt = new vpMbtMeLine;
390 melinePt->setMask(*mask);
391 melinePt->setMe(me);
392
393 int marge = /*10*/ 5; // ou 5 normalement
394 if (ip1.get_j() < ip2.get_j()) {
395 melinePt->jmin = static_cast<int>(ip1.get_j()) - marge;
396 melinePt->jmax = static_cast<int>(ip2.get_j()) + marge;
397 }
398 else {
399 melinePt->jmin = static_cast<int>(ip2.get_j()) - marge;
400 melinePt->jmax = static_cast<int>(ip1.get_j()) + marge;
401 }
402 if (ip1.get_i() < ip2.get_i()) {
403 melinePt->imin = static_cast<int>(ip1.get_i()) - marge;
404 melinePt->imax = static_cast<int>(ip2.get_i()) + marge;
405 }
406 else {
407 melinePt->imin = static_cast<int>(ip2.get_i()) - marge;
408 melinePt->imax = static_cast<int>(ip1.get_i()) + marge;
409 }
410
411 try {
412 melinePt->initTracking(I, ip1, ip2, rho, theta, doNotTrack);
413 me->setInitRange(oldInitRange);
414 meline.push_back(melinePt);
415 nbFeature.push_back(static_cast<unsigned int>(melinePt->getMeList().size()));
416 nbFeatureTotal += nbFeature.back();
417 }
418 catch (...) {
419 me->setInitRange(oldInitRange);
420 delete melinePt;
421 isvisible = false;
422 return false;
423 }
424 }
425 }
426 else {
427 isvisible = false;
428 }
429 }
430
431 return true;
432}
433
440{
441 int oldInitRange = me->getInitRange();
442 me->setInitRange(defaultRange);
443 if (isvisible) {
444 try {
445 nbFeature.clear();
446 nbFeatureTotal = 0;
447 for (size_t i = 0; i < meline.size(); i++) {
448 meline[i]->track(I);
449 nbFeature.push_back(static_cast<unsigned int>(meline[i]->getMeList().size()));
450 nbFeatureTotal += static_cast<unsigned int>(meline[i]->getMeList().size());
451 }
452 }
453 catch (...) {
454 for (size_t i = 0; i < meline.size(); i++) {
455 if (meline[i] != nullptr)
456 delete meline[i];
457 }
458
459 nbFeature.clear();
460 meline.clear();
461 nbFeatureTotal = 0;
462 Reinit = true;
463 isvisible = false;
464 }
465 }
466 me->setInitRange(oldInitRange);
467}
468
476{
477 int oldInitRange = me->getInitRange();
478 if (isvisible) {
479 p1->changeFrame(cMo);
480 p2->changeFrame(cMo);
481
482 if (poly.getClipping() > 3) // Contains at least one FOV constraint
483 cam.computeFov(I.getWidth(), I.getHeight());
484
485 poly.computePolygonClipped(cam);
486
487 if (poly.polyClipped.size() == 2) { // Les points sont visibles.
488
489 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
490
491 if (useScanLine) {
492 hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst);
493 }
494 else {
495 linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
496 }
497
498 if (linesLst.size() != meline.size() || linesLst.size() == 0) {
499 for (size_t i = 0; i < meline.size(); i++) {
500 if (meline[i] != nullptr)
501 delete meline[i];
502 }
503
504 meline.clear();
505 nbFeature.clear();
506 nbFeatureTotal = 0;
507 isvisible = false;
508 Reinit = true;
509 }
510 else {
511 line->changeFrame(cMo);
512 try {
513 line->projection();
514 }
515 catch (...) {
516 for (size_t j = 0; j < meline.size(); j++) {
517 if (meline[j] != nullptr)
518 delete meline[j];
519 }
520
521 meline.clear();
522 nbFeature.clear();
523 nbFeatureTotal = 0;
524 isvisible = false;
525 Reinit = true;
526 return;
527 }
528 double rho, theta;
529 // rho theta uv
530 vpMeterPixelConversion::convertLine(cam, line->getRho(), line->getTheta(), rho, theta);
531
532 while (theta > M_PI) {
533 theta -= M_PI;
534 }
535 while (theta < -M_PI) {
536 theta += M_PI;
537 }
538
539 if (theta < -M_PI / 2.0)
540 theta = -theta - 3 * M_PI / 2.0;
541 else
542 theta = M_PI / 2.0 - theta;
543
544 try {
545 for (unsigned int i = 0; i < linesLst.size(); i++) {
546 vpImagePoint ip1, ip2;
547
548 linesLst[i].first.project();
549 linesLst[i].second.project();
550
551 vpMeterPixelConversion::convertPoint(cam, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
552 vpMeterPixelConversion::convertPoint(cam, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
553
554 int marge = /*10*/ 5; // ou 5 normalement
555 if (ip1.get_j() < ip2.get_j()) {
556 meline[i]->jmin = static_cast<int>(ip1.get_j()) - marge;
557 meline[i]->jmax = static_cast<int>(ip2.get_j()) + marge;
558 }
559 else {
560 meline[i]->jmin = static_cast<int>(ip2.get_j()) - marge;
561 meline[i]->jmax = static_cast<int>(ip1.get_j()) + marge;
562 }
563 if (ip1.get_i() < ip2.get_i()) {
564 meline[i]->imin = static_cast<int>(ip1.get_i()) - marge;
565 meline[i]->imax = static_cast<int>(ip2.get_i()) + marge;
566 }
567 else {
568 meline[i]->imin = static_cast<int>(ip2.get_i()) - marge;
569 meline[i]->imax = static_cast<int>(ip1.get_i()) + marge;
570 }
571 me->setInitRange(defaultRange);
572 meline[i]->updateParameters(I, ip1, ip2, rho, theta);
573 nbFeature[i] = static_cast<unsigned int>(meline[i]->getMeList().size());
575 }
576 }
577 catch (...) {
578 for (size_t j = 0; j < meline.size(); j++) {
579 if (meline[j] != nullptr)
580 delete meline[j];
581 }
582
583 meline.clear();
584 nbFeature.clear();
585 nbFeatureTotal = 0;
586 isvisible = false;
587 Reinit = true;
588 }
589 }
590 }
591 else {
592 for (size_t i = 0; i < meline.size(); i++) {
593 if (meline[i] != nullptr)
594 delete meline[i];
595 }
596 nbFeature.clear();
597 meline.clear();
598 nbFeatureTotal = 0;
599 isvisible = false;
600 }
601 }
602 me->setInitRange(oldInitRange);
603}
604
617 const vpImage<bool> *mask)
618{
619 for (size_t i = 0; i < meline.size(); i++) {
620 if (meline[i] != nullptr)
621 delete meline[i];
622 }
623
624 nbFeature.clear();
625 meline.clear();
626 nbFeatureTotal = 0;
627
628 if (!initMovingEdge(I, cMo, false, mask))
629 Reinit = true;
630
631 Reinit = false;
632}
633
646 const vpCameraParameters &camera, const vpColor &col, unsigned int thickness,
647 bool displayFullModel)
648{
649 std::vector<std::vector<double> > models =
650 getModelForDisplay(I.getWidth(), I.getHeight(), cMo, camera, displayFullModel);
651
652 for (size_t i = 0; i < models.size(); i++) {
653 vpImagePoint ip1(models[i][1], models[i][2]);
654 vpImagePoint ip2(models[i][3], models[i][4]);
655 vpDisplay::displayLine(I, ip1, ip2, col, thickness);
656 }
657}
658
671 const vpCameraParameters &camera, const vpColor &col, unsigned int thickness,
672 bool displayFullModel)
673{
674 std::vector<std::vector<double> > models =
675 getModelForDisplay(I.getWidth(), I.getHeight(), cMo, camera, displayFullModel);
676
677 for (size_t i = 0; i < models.size(); i++) {
678 vpImagePoint ip1(models[i][1], models[i][2]);
679 vpImagePoint ip2(models[i][3], models[i][4]);
680 vpDisplay::displayLine(I, ip1, ip2, col, thickness);
681 }
682}
683
699{
700 for (size_t i = 0; i < meline.size(); i++) {
701 if (meline[i] != nullptr) {
702 meline[i]->display(I);
703 }
704 }
705}
706
708{
709 for (size_t i = 0; i < meline.size(); i++) {
710 if (meline[i] != nullptr) {
711 meline[i]->display(I);
712 }
713 }
714}
715
720std::vector<std::vector<double> > vpMbtDistanceLine::getFeaturesForDisplay()
721{
722 std::vector<std::vector<double> > features;
723
724 for (size_t i = 0; i < meline.size(); i++) {
725 vpMbtMeLine *me_l = meline[i];
726 if (me_l != nullptr) {
727 for (std::list<vpMeSite>::const_iterator it = me_l->getMeList().begin(); it != me_l->getMeList().end(); ++it) {
728 vpMeSite p_me_l = *it;
729#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
730 std::vector<double> params = { 0, //ME
731 p_me_l.get_ifloat(),
732 p_me_l.get_jfloat(),
733 static_cast<double>(p_me_l.getState()) };
734#else
735 std::vector<double> params;
736 params.push_back(0); // ME
737 params.push_back(p_me_l.get_ifloat());
738 params.push_back(p_me_l.get_jfloat());
739 params.push_back(static_cast<double>(p_me_l.getState()));
740#endif
741
742 features.push_back(params);
743 }
744 }
745 }
746
747 return features;
748}
749
761std::vector<std::vector<double> > vpMbtDistanceLine::getModelForDisplay(unsigned int width, unsigned int height,
762 const vpHomogeneousMatrix &cMo,
763 const vpCameraParameters &camera,
764 bool displayFullModel)
765{
766 std::vector<std::vector<double> > models;
767
768 if ((isvisible && isTrackedLine) || displayFullModel) {
769 p1->changeFrame(cMo);
770 p2->changeFrame(cMo);
771
772 vpImagePoint ip1, ip2;
773 vpCameraParameters c = camera;
774 if (poly.getClipping() > 3) // Contains at least one FOV constraint
775 c.computeFov(width, height);
776
777 poly.computePolygonClipped(c);
778
779 if (poly.polyClipped.size() == 2 &&
780 ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
781 ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
782 ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
783 ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
784 ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
785 ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)) {
786
787 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
788 if (useScanLine && !displayFullModel) {
789 hiddenface->computeScanLineQuery(poly.polyClipped[0].first, poly.polyClipped[1].first, linesLst, true);
790 }
791 else {
792 linesLst.push_back(std::make_pair(poly.polyClipped[0].first, poly.polyClipped[1].first));
793 }
794
795 for (unsigned int i = 0; i < linesLst.size(); i++) {
796 linesLst[i].first.project();
797 linesLst[i].second.project();
798
799 vpMeterPixelConversion::convertPoint(camera, linesLst[i].first.get_x(), linesLst[i].first.get_y(), ip1);
800 vpMeterPixelConversion::convertPoint(camera, linesLst[i].second.get_x(), linesLst[i].second.get_y(), ip2);
801
802#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
803 std::vector<double> params = { 0, //0 for line parameters
804 ip1.get_i(),
805 ip1.get_j(),
806 ip2.get_i(),
807 ip2.get_j() };
808#else
809 std::vector<double> params;
810 params.push_back(0); //0 for line parameters
811 params.push_back(ip1.get_i());
812 params.push_back(ip1.get_j());
813 params.push_back(ip2.get_i());
814 params.push_back(ip2.get_j());
815#endif
816
817 models.push_back(params);
818 }
819 }
820 }
821
822 return models;
823}
824
829{
830 if (isvisible) {
831 L.resize(nbFeatureTotal, 6);
832 error.resize(nbFeatureTotal);
833 }
834 else {
835 for (size_t i = 0; i < meline.size(); i++) {
836 nbFeature[i] = 0;
837 // To be consistent with nbFeature[i] = 0
838 std::list<vpMeSite> &me_site_list = meline[i]->getMeList();
839 me_site_list.clear();
840 }
841 nbFeatureTotal = 0;
842 }
843}
844
850{
851 if (isvisible) {
852 try {
853 // feature projection
854 line->changeFrame(cMo);
855 line->projection();
856
857 vpFeatureBuilder::create(featureline, *line);
858
859 double rho = featureline.getRho();
860 double theta = featureline.getTheta();
861
862 double co = cos(theta);
863 double si = sin(theta);
864
865 double mx = 1.0 / cam.get_px();
866 double my = 1.0 / cam.get_py();
867 double xc = cam.get_u0();
868 double yc = cam.get_v0();
869
870 double alpha_;
871 vpMatrix H = featureline.interaction();
872
873 double x, y;
874 unsigned int j = 0;
875
876 for (size_t i = 0; i < meline.size(); i++) {
877 for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin();
878 it != meline[i]->getMeList().end(); ++it) {
879 x = static_cast<double>(it->m_j);
880 y = static_cast<double>(it->m_i);
881
882 x = (x - xc) * mx;
883 y = (y - yc) * my;
884
885 alpha_ = x * si - y * co;
886
887 double *Lrho = H[0];
888 double *Ltheta = H[1];
889 // Calculate interaction matrix for a distance
890 for (unsigned int k = 0; k < 6; k++) {
891 L[j][k] = (Lrho[k] + alpha_ * Ltheta[k]);
892 }
893 error[j] = rho - (x * co + y * si);
894 j++;
895 }
896 }
897 }
898 catch (...) {
899 // Handle potential exception: due to a degenerate case: the image of the straight line is a point!
900 // Set the corresponding interaction matrix part to zero
901 unsigned int j = 0;
902 for (size_t i = 0; i < meline.size(); i++) {
903 for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin();
904 it != meline[i]->getMeList().end(); ++it) {
905 for (unsigned int k = 0; k < 6; k++) {
906 L[j][k] = 0.0;
907 }
908
909 error[j] = 0.0;
910 j++;
911 }
912 }
913 }
914 }
915}
916
925bool vpMbtDistanceLine::closeToImageBorder(const vpImage<unsigned char> &I, const unsigned int threshold)
926{
927 if (threshold > I.getWidth() || threshold > I.getHeight()) {
928 return true;
929 }
930 if (isvisible) {
931
932 for (size_t i = 0; i < meline.size(); i++) {
933 for (std::list<vpMeSite>::const_iterator it = meline[i]->getMeList().begin(); it != meline[i]->getMeList().end();
934 ++it) {
935 int i_ = it->m_i;
936 int j_ = it->m_j;
937
938 if (i_ < 0 || j_ < 0) { // out of image.
939 return true;
940 }
941
942 if ((static_cast<unsigned int>(i_) >(I.getHeight() - threshold)) || static_cast<unsigned int>(i_) < threshold ||
943 (static_cast<unsigned int>(j_) > (I.getWidth() - threshold)) || static_cast<unsigned int>(j_) < threshold) {
944 return true;
945 }
946 }
947 }
948 }
949 return false;
950}
951END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
void computeFov(const unsigned int &w, const unsigned int &h)
Implementation of column vector and the associated operations.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
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)
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 ...
double get_j() const
double get_i() const
Definition of the vpImage class member functions.
Definition vpImage.h:131
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition vpLine.h:103
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
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.
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, bool doNotTrack, const vpImage< bool > *mask=nullptr, const int &initRange=0)
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.
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)
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:75
vpMeSiteState getState() const
Definition vpMeSite.h:306
double get_ifloat() const
Definition vpMeSite.h:212
double get_jfloat() const
Definition vpMeSite.h:218
Definition vpMe.h:143
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:56
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:418
double get_oZ() const
Get the point oZ coordinate in the object frame.
Definition vpPoint.cpp:422
double get_oY() const
Get the point oY coordinate in the object frame.
Definition vpPoint.cpp:420
Class for generating random numbers with uniform probability density.
Definition vpUniRand.h:127
uint32_t next()
const unsigned int defaultRange