Visual Servoing Platform  version 3.0.0
vpMbtDistanceLine.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Nicolas Melchior
35  * Romain Tallonneau
36  * Eric Marchand
37  *
38  *****************************************************************************/
39 #include <visp3/core/vpConfig.h>
40 
46 #include <visp3/mbt/vpMbtDistanceLine.h>
47 #include <visp3/core/vpPlane.h>
48 #include <visp3/core/vpMeterPixelConversion.h>
49 #include <visp3/visual_features/vpFeatureBuilder.h>
50 #include <stdlib.h>
51 
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(NULL), isTrackedLine(true), isTrackedLineWithVisibility(true),
60  wmean(1), featureline(), poly(), useScanLine(false), meline(), line(NULL), p1(NULL), p2(NULL), L(),
61  error(), nbFeature(), nbFeatureTotal(0), Reinit(false), hiddenface(NULL), Lindex_polygon(),
62  Lindex_polygon_tracked(), isvisible(false)
63 {
64 }
65 
70 {
71 // cout << "Deleting line " << index << endl ;
72  if (line != NULL) delete line ;
73 
74  for(unsigned int i = 0 ; i < meline.size() ; i++)
75  if (meline[i] != NULL) delete meline[i] ;
76 
77  meline.clear();
78 }
79 
85 void
86 vpMbtDistanceLine::project(const vpHomogeneousMatrix &cMo)
87 {
88  line->project(cMo) ;
89  p1->project(cMo) ;
90  p2->project(cMo) ;
91 }
92 
101 void
102 buildPlane(vpPoint &P, vpPoint &Q, vpPoint &R, vpPlane &plane)
103 {
104  vpColVector a(3);
105  vpColVector b(3);
106  vpColVector n(3);
107  //Calculate vector corresponding to PQ
108  a[0]=P.get_oX()-Q.get_oX();
109  a[1]=P.get_oY()-Q.get_oY();
110  a[2]=P.get_oZ()-Q.get_oZ();
111 
112  //Calculate vector corresponding to PR
113  b[0]=P.get_oX()-R.get_oX();
114  b[1]=P.get_oY()-R.get_oY();
115  b[2]=P.get_oZ()-R.get_oZ();
116 
117  //Calculate normal vector to plane PQ x PR
118  n=vpColVector::cross(a,b);
119 
120  //Equation of the plane is given by:
121  double A = n[0];
122  double B = n[1];
123  double C = n[2];
124  double D=-(A*P.get_oX()+B*P.get_oY()+C*P.get_oZ());
125 
126  double norm = sqrt(A*A+B*B+C*C) ;
127  plane.setA(A/norm) ;
128  plane.setB(B/norm) ;
129  plane.setC(C/norm) ;
130  plane.setD(D/norm) ;
131 }
132 
133 
145 void
146 buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L)
147 {
148  vpPlane plane1;
149  vpPlane plane2 ;
150  buildPlane(P1,P2,P3,plane1) ;
151  buildPlane(P1,P2,P4,plane2) ;
152 
153  L.setWorldCoordinates(plane1.getA(),plane1.getB(), plane1.getC(),plane1.getD(),
154  plane2.getA(),plane2.getB(), plane2.getC(),plane2.getD()) ;
155 }
156 
157 
164 void
166 {
167  line = new vpLine ;
168  poly.setNbPoint(2);
169  poly.addPoint(0, _p1);
170  poly.addPoint(1, _p2);
171 
172  p1 = &poly.p[0];
173  p2 = &poly.p[1];
174 
175  vpColVector V1(3);
176  vpColVector V2(3);
177  vpColVector V3(3);
178  vpColVector V4(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  {
190  {
191  V3[0]=double(rand()%1000)/100;
192  V3[1]=double(rand()%1000)/100;
193  V3[2]=double(rand()%1000)/100;
194 
195 
196  vpColVector v_tmp1,v_tmp2;
197  v_tmp1 = V2-V1;
198  v_tmp2 = V3-V1;
199  V4=vpColVector::cross(v_tmp1,v_tmp2);
200  }
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  }
206  else
207  {
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 
219 void
221 {
222  Lindex_polygon.push_back(idx);
223  Lindex_polygon_tracked.push_back(true);
224 }
225 
233 void
234 vpMbtDistanceLine::setTracked(const std::string &polyname, const bool &track)
235 {
236  unsigned int ind = 0;
237  for(std::list<int>::const_iterator itpoly=Lindex_polygon.begin(); itpoly!=Lindex_polygon.end(); ++itpoly){
238  if((*hiddenface)[(unsigned)(*itpoly)]->getName() == polyname){
239  Lindex_polygon_tracked[ind] = track;
240  }
241  ind++;
242  }
243 
244  isTrackedLine = false;
245  for(unsigned int i = 0 ; i < Lindex_polygon_tracked.size() ; i++)
247  {
248  isTrackedLine = true;
249  break;
250  }
251 
252  if(!isTrackedLine){
253  isTrackedLineWithVisibility = false;
254  return;
255  }
256 
257  updateTracked();
258 }
259 
264 void
266 {
267  if(!isTrackedLine){
268  isTrackedLineWithVisibility = false;
269  return;
270  }
271 
272  unsigned int ind = 0;
273  isTrackedLineWithVisibility = false;
274  for(std::list<int>::const_iterator itpoly=Lindex_polygon.begin(); itpoly!=Lindex_polygon.end(); ++itpoly){
275  if((*hiddenface)[(unsigned)(*itpoly)]->isVisible() && Lindex_polygon_tracked[ind]){
276  isTrackedLineWithVisibility = true;
277  break;
278  }
279  ind++;
280  }
281 }
282 
288 void
290 {
291  me = _me ;
292 
293  for(unsigned int i = 0 ; i < meline.size() ; i++)
294  if (meline[i] != NULL)
295  {
296 // nbFeature[i] = 0;
297  meline[i]->reset();
298  meline[i]->setMe(me) ;
299  }
300 
301 // nbFeatureTotal = 0;
302 }
303 
304 
313 bool
315 {
316  for(unsigned int i = 0 ; i < meline.size() ; i++){
317  if (meline[i] != NULL) delete meline[i] ;
318  }
319 
320  meline.clear();
321  nbFeature.clear();
322  nbFeatureTotal = 0;
323 
324  if(isvisible)
325  {
326  p1->changeFrame(cMo);
327  p2->changeFrame(cMo);
328 
329  if(poly.getClipping() > 3) // Contains at least one FOV constraint
330  cam.computeFov(I.getWidth(), I.getHeight());
331 
332  poly.computePolygonClipped(cam);
333 
334  if(poly.polyClipped.size() == 2){ //Les points sont visibles.
335 
336  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
337 
338  if(useScanLine){
339  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst);
340  }
341  else{
342  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
343  }
344 
345  if(linesLst.size() == 0){
346 // isvisible = false;
347  return false;
348  }
349 
350  // To have the exact same pose values as the old version (angle or ogre visibility test only), points should be reorganised when using scanline algorithm.
351 // if(sqrt(vpMath::sqr(poly.polyClipped[0].first.get_X() - linesLst[0].first.get_X())) > sqrt(vpMath::sqr(poly.polyClipped[0].first.get_X() - linesLst[0].second.get_X())))
352 // {
353 // std::vector<std::pair<vpPoint, vpPoint> > linesLstTmp;
354 // for(int i = linesLst.size()-1 ; i >= 0 ; i--)
355 // linesLstTmp.push_back(std::make_pair(linesLst[i].second,linesLst[i].first));
356 // linesLst = linesLstTmp;
357 // }
358 
359  line->changeFrame(cMo);
360  line->projection();
361  double rho,theta;
362  //rho theta uv
364 
365  while (theta > M_PI) { theta -= M_PI ; }
366  while (theta < -M_PI) { theta += M_PI ; }
367 
368  if (theta < -M_PI/2.0) theta = -theta - 3*M_PI/2.0;
369  else theta = M_PI/2.0 - theta;
370 
371 
372  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
373  vpImagePoint ip1, ip2;
374 
375  linesLst[i].first.project();
376  linesLst[i].second.project();
377 
378  vpMeterPixelConversion::convertPoint(cam,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
379  vpMeterPixelConversion::convertPoint(cam,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
380 
381  vpMbtMeLine *melinePt = new vpMbtMeLine ;
382  melinePt->setMe(me) ;
383 
384  // meline[i]->setDisplay(vpMeSite::RANGE_RESULT) ;
385  melinePt->setInitRange(0);
386 
387  int marge = /*10*/5; //ou 5 normalement
388  if (ip1.get_j()<ip2.get_j()) { melinePt->jmin = (int)ip1.get_j()-marge ; melinePt->jmax = (int)ip2.get_j()+marge ; } else{ melinePt->jmin = (int)ip2.get_j()-marge ; melinePt->jmax = (int)ip1.get_j()+marge ; }
389  if (ip1.get_i()<ip2.get_i()) { melinePt->imin = (int)ip1.get_i()-marge ; melinePt->imax = (int)ip2.get_i()+marge ; } else{ melinePt->imin = (int)ip2.get_i()-marge ; melinePt->imax = (int)ip1.get_i()+marge ; }
390 
391  try
392  {
393  melinePt->initTracking(I,ip1,ip2,rho,theta);
394  meline.push_back(melinePt);
395  // nbFeature.push_back((unsigned int) melinePt->getMeList().size());
396  // nbFeatureTotal += nbFeature.back();
397  }
398  catch(...)
399  {
400  //vpTRACE("the line can't be initialized");
401  // if (melinePt!=NULL) delete melinePt;
402  // melinePt=NULL;
403  // isvisible = false;
404  return false;
405  }
406  }
407  }
408  else{
409  isvisible = false;
410 // return false;
411  }
412  }
413 
414 // trackMovingEdge(I,cMo) ;
415  return true;
416 }
417 
418 
419 
426 void
428 {
429 
430  if (isvisible)
431  {
432 // p1->changeFrame(cMo) ;
433 // p2->changeFrame(cMo) ;
434 //
435 // p1->projection() ;
436 // p2->projection() ;
437 //
438 // vpImagePoint ip1, ip2;
439 //
440 // vpMeterPixelConversion::convertPoint(*cam,p1->get_x(),p1->get_y(),ip1) ;
441 // vpMeterPixelConversion::convertPoint(*cam,p2->get_x(),p2->get_y(),ip2) ;
442 //
443 // int marge = /*10*/5; //ou 5 normalement
444 // if (ip1.get_j()<ip2.get_j()) { meline->jmin = ip1.get_j()-marge ; meline->jmax = ip2.get_j()+marge ; }
445 // else{ meline->jmin = ip2.get_j()-marge ; meline->jmax = ip1.get_j()+marge ; }
446 // if (ip1.get_i()<ip2.get_i()) { meline->imin = ip1.get_i()-marge ; meline->imax = ip2.get_i()+marge ; }
447 // else{ meline->imin = ip2.get_i()-marge ; meline->imax = ip1.get_i()+marge ; }
448 
449  try
450  {
451  nbFeatureTotal = 0;
452  for(unsigned int i = 0 ; i < meline.size() ; i++){
453  meline[i]->track(I) ;
454  nbFeature.push_back((unsigned int) meline[i]->getMeList().size());
455  nbFeatureTotal += (unsigned int) meline[i]->getMeList().size();
456  }
457  }
458  catch(...)
459  {
460  for(unsigned int i = 0 ; i < meline.size() ; i++){
461  if (meline[i] != NULL) delete meline[i] ;
462  }
463 
464  nbFeature.clear();
465  meline.clear();
466  nbFeatureTotal = 0;
467  Reinit = true;
468  isvisible = false;
469  }
470  }
471 }
472 
473 
480 void
482 {
483  if(isvisible){
484  p1->changeFrame(cMo);
485  p2->changeFrame(cMo);
486 
487  if(poly.getClipping() > 3) // Contains at least one FOV constraint
488  cam.computeFov(I.getWidth(), I.getHeight());
489 
490  poly.computePolygonClipped(cam);
491 
492  if(poly.polyClipped.size() == 2){ //Les points sont visibles.
493 
494  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
495 
496  if(useScanLine){
497  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst);
498  }
499  else{
500  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
501  }
502 
503  if(linesLst.size() != meline.size() || linesLst.size() == 0){
504  for(unsigned int i = 0 ; i < meline.size() ; i++){
505  if (meline[i] != NULL) delete meline[i] ;
506  }
507 
508  meline.clear();
509  nbFeature.clear();
510  nbFeatureTotal = 0;
511  isvisible = false;
512  Reinit = true;
513  }
514  else{
515 
516  // To have the exact same pose values as the old version (angle or ogre visibility test only), points should be reorganised when using scanline algorithm.
517 // if(sqrt(vpMath::sqr(poly.polyClipped[0].first.get_X() - linesLst[0].first.get_X())) > sqrt(vpMath::sqr(poly.polyClipped[0].first.get_X() - linesLst[0].second.get_X())))
518 // {
519 // std::vector<std::pair<vpPoint, vpPoint> > linesLstTmp;
520 // for(int i = linesLst.size()-1 ; i >= 0 ; i--)
521 // linesLstTmp.push_back(std::make_pair(linesLst[i].second,linesLst[i].first));
522 // linesLst = linesLstTmp;
523 // }
524 
525  line->changeFrame(cMo);
526  line->projection();
527  double rho,theta;
528  //rho theta uv
530 
531  while (theta > M_PI) { theta -= M_PI ; }
532  while (theta < -M_PI) { theta += M_PI ; }
533 
534  if (theta < -M_PI/2.0) theta = -theta - 3*M_PI/2.0;
535  else theta = M_PI/2.0 - theta;
536 
537 
538  try
539  {
540  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
541  vpImagePoint ip1, ip2;
542 
543  linesLst[i].first.project();
544  linesLst[i].second.project();
545 
546  vpMeterPixelConversion::convertPoint(cam,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
547  vpMeterPixelConversion::convertPoint(cam,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
548 
549  int marge = /*10*/5; //ou 5 normalement
550  if (ip1.get_j()<ip2.get_j()) { meline[i]->jmin = (int)ip1.get_j()-marge ; meline[i]->jmax = (int)ip2.get_j()+marge ; } else{ meline[i]->jmin = (int)ip2.get_j()-marge ; meline[i]->jmax = (int)ip1.get_j()+marge ; }
551  if (ip1.get_i()<ip2.get_i()) { meline[i]->imin = (int)ip1.get_i()-marge ; meline[i]->imax = (int)ip2.get_i()+marge ; } else{ meline[i]->imin = (int)ip2.get_i()-marge ; meline[i]->imax = (int)ip1.get_i()+marge ; }
552 
553  meline[i]->updateParameters(I,ip1,ip2,rho,theta) ;
554  nbFeature[i] = (unsigned int)meline[i]->getMeList().size();
556  }
557  }
558  catch(...)
559  {
560  for(unsigned int j = 0 ; j < meline.size() ; j++){
561  if (meline[j] != NULL) 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(unsigned int i = 0 ; i < meline.size() ; i++){
574  if (meline[i] != NULL) delete meline[i] ;
575  }
576  nbFeature.clear();
577  meline.clear();
578  nbFeatureTotal = 0;
579  isvisible = false;
580  }
581  }
582 }
583 
584 
593 void
595 {
596  for(unsigned int i = 0 ; i < meline.size() ; i++){
597  if (meline[i] != NULL) delete meline[i] ;
598  }
599 
600  nbFeature.clear();
601  meline.clear();
602  nbFeatureTotal = 0;
603 
604  if (initMovingEdge(I,cMo) == false)
605  Reinit = true;
606 
607  Reinit = false;
608 }
609 
610 
621 void
623  const vpCameraParameters &camera, const vpColor col, const unsigned int thickness, const bool displayFullModel)
624 {
625  if(isvisible || displayFullModel){
626  p1->changeFrame(cMo);
627  p2->changeFrame(cMo);
628 
629  vpImagePoint ip1, ip2;
630  vpCameraParameters c = camera;
631  if(poly.getClipping() > 3) // Contains at least one FOV constraint
632  c.computeFov(I.getWidth(), I.getHeight());
633 
634  poly.computePolygonClipped(c);
635 
636  if( poly.polyClipped.size() == 2 &&
637  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
638  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
639  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
640  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
641  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
642  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)){
643 
644  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
645  if(useScanLine && !displayFullModel){
646  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst,true);
647  }
648  else{
649  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
650  }
651 
652  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
653  linesLst[i].first.project();
654  linesLst[i].second.project();
655 
656  vpMeterPixelConversion::convertPoint(camera,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
657  vpMeterPixelConversion::convertPoint(camera,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
658 
659  vpDisplay::displayLine(I,ip1,ip2,col, thickness);
660  }
661  }
662  }
663 }
664 
665 
676 void
678  const vpCameraParameters &camera, const vpColor col,
679  const unsigned int thickness, const bool displayFullModel)
680 {
681  if(isvisible || displayFullModel){
682  p1->changeFrame(cMo);
683  p2->changeFrame(cMo);
684 
685  vpImagePoint ip1, ip2;
686  vpCameraParameters c = camera;
687  if(poly.getClipping() > 3) // Contains at least one FOV constraint
688  c.computeFov(I.getWidth(), I.getHeight());
689 
690  poly.computePolygonClipped(c);
691 
692  if( poly.polyClipped.size() == 2 &&
693  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
694  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
695  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
696  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
697  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
698  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)){
699 
700  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
701  if(useScanLine && !displayFullModel){
702  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst,true);
703  }
704  else{
705  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
706  }
707 
708  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
709  linesLst[i].first.project();
710  linesLst[i].second.project();
711 
712  vpMeterPixelConversion::convertPoint(camera,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
713  vpMeterPixelConversion::convertPoint(camera,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
714 
715  vpDisplay::displayLine(I,ip1,ip2,col, thickness);
716  }
717  }
718  }
719 }
720 
721 
732 void
734 {
735  for(unsigned int i = 0 ; i < meline.size() ; i++)
736  if (meline[i] != NULL)
737  {
738  meline[i]->display(I);
739  }
740 }
741 
745 void
747 {
748  if (isvisible == true)
749  {
750  L.resize(nbFeatureTotal,6) ;
752  }
753  else{
754  for(unsigned int i = 0 ; i < meline.size() ; i++)
755  nbFeature[i] = 0;
756  nbFeatureTotal = 0 ;
757  }
758 }
759 
763 void
765 {
766  if (isvisible)
767  {
768  // feature projection
769  line->changeFrame(cMo) ;
770  line->projection() ;
771 
772  vpFeatureBuilder::create(featureline,*line) ;
773 
774  double rho = featureline.getRho() ;
775  double theta = featureline.getTheta() ;
776 
777  double co = cos(theta);
778  double si = sin(theta);
779 
780  double mx = 1.0/cam.get_px() ;
781  double my = 1.0/cam.get_py() ;
782  double xc = cam.get_u0() ;
783  double yc = cam.get_v0() ;
784 
785  double alpha_ ;
786  vpMatrix H ;
787  H = featureline.interaction() ;
788 
789  double x,y ;
790  vpMeSite p ;
791  unsigned int j =0 ;
792 
793  for(unsigned int i = 0 ; i < meline.size() ; i++){
794  for(std::list<vpMeSite>::const_iterator it=meline[i]->getMeList().begin(); it!=meline[i]->getMeList().end(); ++it){
795  x = (double)it->j ;
796  y = (double)it->i ;
797 
798  x = (x-xc)*mx ;
799  y = (y-yc)*my ;
800 
801  alpha_ = x*si - y*co;
802 
803  double *Lrho = H[0] ;
804  double *Ltheta = H[1] ;
805  // Calculate interaction matrix for a distance
806  for (unsigned int k=0 ; k < 6 ; k++)
807  {
808  L[j][k] = (Lrho[k] + alpha_*Ltheta[k]);
809  }
810  error[j] = rho - ( x*co + y*si) ;
811  j++;
812  }
813  }
814  }
815 }
816 
824 bool
825 vpMbtDistanceLine::closeToImageBorder(const vpImage<unsigned char>& I, const unsigned int threshold)
826 {
827  if(threshold > I.getWidth() || threshold > I.getHeight()){
828  return true;
829  }
830  if (isvisible){
831 
832  for(unsigned int i = 0 ; i < meline.size() ; i++){
833  for(std::list<vpMeSite>::const_iterator it=meline[i]->getMeList().begin(); it!=meline[i]->getMeList().end(); ++it){
834  int i_ = it->i ;
835  int j_ = it->j ;
836 
837  if(i_ < 0 || j_ < 0){ //out of image.
838  return true;
839  }
840 
841  if( ((unsigned int)i_ > (I.getHeight()- threshold) ) || (unsigned int)i_ < threshold ||
842  ((unsigned int)j_ > (I.getWidth ()- threshold) ) || (unsigned int)j_ < threshold ) {
843  return true;
844  }
845  }
846  }
847  }
848  return false;
849 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
void setD(const double d)
Definition: vpPlane.h:91
double get_u0() const
virtual void setNbPoint(const unsigned int nb)
unsigned int nbFeatureTotal
The number of moving edges.
vpLine * line
The 3D line.
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
double get_i() const
Definition: vpImagePoint.h:190
unsigned int getWidth() const
Definition: vpImage.h:161
bool Reinit
Indicates if the line has to be reinitialized.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:257
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.
void setWorldCoordinates(const double &A1, const double &B1, const double &C1, const double &D1, const double &A2, const double &B2, const double &C2, const double &D2)
Definition: vpLine.cpp:94
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Definition: vpMeSite.h:72
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void trackMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
std::vector< bool > Lindex_polygon_tracked
Vector of bool associated with Lindex_polygon to know if Lindex_polygon[i] is tracked.
vpPoint * p1
The first extremity.
void displayMovingEdges(const vpImage< unsigned char > &I)
double get_oY() const
Get the point Y coordinate in the object frame.
Definition: vpPoint.cpp:449
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
Definition: vpMe.h:59
double getRho() const
double get_py() const
double getTheta() const
bool isvisible
Indicates if the line is visible or not.
double get_j() const
Definition: vpImagePoint.h:201
Class that defines what is a point.
Definition: vpPoint.h:59
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor col, const unsigned int thickness=1, const bool displayFullModel=false)
double getTheta() const
Definition: vpLine.h:162
double getRho() const
Definition: vpLine.h:173
std::vector< vpMbtMeLine * > meline
The moving edge container.
void setTracked(const std::string &name, const bool &track)
Class that defines a line in the object frame, the camera frame and the image plane. All the parameters must be set in meter.
Definition: vpLine.h:120
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
double get_v0() const
vpPoint * p2
The second extremity.
vpColVector error
The error vector.
void addPoint(const unsigned int n, const vpPoint &P)
Generic class defining intrinsic camera parameters.
double get_oZ() const
Get the point Z coordinate in the object frame.
Definition: vpPoint.cpp:451
unsigned int getClipping() const
Definition: vpPolygon3D.h:121
void setA(const double a)
Definition: vpPlane.h:85
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
void projection()
Definition: vpLine.cpp:212
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP)
Definition: vpLine.cpp:362
double get_px() const
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition: vpPolygon3D.h:83
void setC(const double c)
Definition: vpPlane.h:89
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
Line coordinates conversion (rho,theta).
double get_oX() const
Get the point X coordinate in the object frame.
Definition: vpPoint.cpp:447
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
int j
Definition: vpMeSite.h:94
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setMovingEdge(vpMe *Me)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
double getB() const
Definition: vpPlane.h:108
void setB(const double b)
Definition: vpPlane.h:87
double getA() const
Definition: vpPlane.h:106
void addPolygon(const int &index)
unsigned int getHeight() const
Definition: vpImage.h:152
double getC() const
Definition: vpPlane.h:110
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
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 changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
Definition: vpPoint.cpp:247
std::vector< unsigned int > nbFeature
The number of moving edges.
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
bool useScanLine
Use scanline rendering.
void buildFrom(vpPoint &_p1, vpPoint &_p2)
double getD() const
Definition: vpPlane.h:112
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:217
void computeFov(const unsigned int &w, const unsigned int &h)