Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMbtDistanceLine.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  if (line == NULL) {
168  line = new vpLine ;
169  }
170 
171  poly.setNbPoint(2);
172  poly.addPoint(0, _p1);
173  poly.addPoint(1, _p2);
174 
175  p1 = &poly.p[0];
176  p2 = &poly.p[1];
177 
178  vpColVector V1(3);
179  vpColVector V2(3);
180  vpColVector V3(3);
181  vpColVector V4(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  {
193  {
194  V3[0]=double(rand()%1000)/100;
195  V3[1]=double(rand()%1000)/100;
196  V3[2]=double(rand()%1000)/100;
197 
198 
199  vpColVector v_tmp1,v_tmp2;
200  v_tmp1 = V2-V1;
201  v_tmp2 = V3-V1;
202  V4=vpColVector::cross(v_tmp1,v_tmp2);
203  }
204 
205  vpPoint P3(V3[0],V3[1],V3[2]);
206  vpPoint P4(V4[0],V4[1],V4[2]);
207  buildLine(*p1,*p2, P3,P4, *line) ;
208  }
209  else
210  {
211  vpPoint P3(V1[0],V1[1],V1[2]);
212  vpPoint P4(V2[0],V2[1],V2[2]);
213  buildLine(*p1,*p2,P3,P4,*line) ;
214  }
215 }
216 
222 void
224 {
225  Lindex_polygon.push_back(idx);
226  Lindex_polygon_tracked.push_back(true);
227 }
228 
236 void
237 vpMbtDistanceLine::setTracked(const std::string &polyname, const bool &track)
238 {
239  unsigned int ind = 0;
240  for(std::list<int>::const_iterator itpoly=Lindex_polygon.begin(); itpoly!=Lindex_polygon.end(); ++itpoly){
241  if((*hiddenface)[(unsigned)(*itpoly)]->getName() == polyname){
242  Lindex_polygon_tracked[ind] = track;
243  }
244  ind++;
245  }
246 
247  isTrackedLine = false;
248  for(unsigned int i = 0 ; i < Lindex_polygon_tracked.size() ; i++)
250  {
251  isTrackedLine = true;
252  break;
253  }
254 
255  if(!isTrackedLine){
256  isTrackedLineWithVisibility = false;
257  return;
258  }
259 
260  updateTracked();
261 }
262 
267 void
269 {
270  if(!isTrackedLine){
271  isTrackedLineWithVisibility = false;
272  return;
273  }
274 
275  unsigned int ind = 0;
276  isTrackedLineWithVisibility = false;
277  for(std::list<int>::const_iterator itpoly=Lindex_polygon.begin(); itpoly!=Lindex_polygon.end(); ++itpoly){
278  if((*hiddenface)[(unsigned)(*itpoly)]->isVisible() && Lindex_polygon_tracked[ind]){
279  isTrackedLineWithVisibility = true;
280  break;
281  }
282  ind++;
283  }
284 }
285 
291 void
293 {
294  me = _me ;
295 
296  for(unsigned int i = 0 ; i < meline.size() ; i++)
297  if (meline[i] != NULL)
298  {
299 // nbFeature[i] = 0;
300  meline[i]->reset();
301  meline[i]->setMe(me) ;
302  }
303 
304 // nbFeatureTotal = 0;
305 }
306 
307 
316 bool
318 {
319  for(unsigned int i = 0 ; i < meline.size() ; i++){
320  if (meline[i] != NULL) delete meline[i] ;
321  }
322 
323  meline.clear();
324  nbFeature.clear();
325  nbFeatureTotal = 0;
326 
327  if(isvisible)
328  {
329  p1->changeFrame(cMo);
330  p2->changeFrame(cMo);
331 
332  if(poly.getClipping() > 3) // Contains at least one FOV constraint
333  cam.computeFov(I.getWidth(), I.getHeight());
334 
335  poly.computePolygonClipped(cam);
336 
337  if(poly.polyClipped.size() == 2){ //Les points sont visibles.
338 
339  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
340 
341  if(useScanLine){
342  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst);
343  }
344  else{
345  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
346  }
347 
348  if(linesLst.size() == 0){
349 // isvisible = false;
350  return false;
351  }
352 
353  // 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.
354 // 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())))
355 // {
356 // std::vector<std::pair<vpPoint, vpPoint> > linesLstTmp;
357 // for(int i = linesLst.size()-1 ; i >= 0 ; i--)
358 // linesLstTmp.push_back(std::make_pair(linesLst[i].second,linesLst[i].first));
359 // linesLst = linesLstTmp;
360 // }
361 
362  line->changeFrame(cMo);
363  line->projection();
364  double rho,theta;
365  //rho theta uv
367 
368  while (theta > M_PI) { theta -= M_PI ; }
369  while (theta < -M_PI) { theta += M_PI ; }
370 
371  if (theta < -M_PI/2.0) theta = -theta - 3*M_PI/2.0;
372  else theta = M_PI/2.0 - theta;
373 
374 
375  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
376  vpImagePoint ip1, ip2;
377 
378  linesLst[i].first.project();
379  linesLst[i].second.project();
380 
381  vpMeterPixelConversion::convertPoint(cam,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
382  vpMeterPixelConversion::convertPoint(cam,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
383 
384  vpMbtMeLine *melinePt = new vpMbtMeLine ;
385  melinePt->setMe(me) ;
386 
387  // meline[i]->setDisplay(vpMeSite::RANGE_RESULT) ;
388  melinePt->setInitRange(0);
389 
390  int marge = /*10*/5; //ou 5 normalement
391  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 ; }
392  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 ; }
393 
394  try
395  {
396  melinePt->initTracking(I,ip1,ip2,rho,theta);
397  meline.push_back(melinePt);
398  // nbFeature.push_back((unsigned int) melinePt->getMeList().size());
399  // nbFeatureTotal += nbFeature.back();
400  }
401  catch(...)
402  {
403  //vpTRACE("the line can't be initialized");
404  delete melinePt;
405  isvisible = false;
406  return false;
407  }
408  }
409  }
410  else{
411  isvisible = false;
412 // return false;
413  }
414  }
415 
416 // trackMovingEdge(I,cMo) ;
417  return true;
418 }
419 
420 
421 
428 void
430 {
431 
432  if (isvisible)
433  {
434 // p1->changeFrame(cMo) ;
435 // p2->changeFrame(cMo) ;
436 //
437 // p1->projection() ;
438 // p2->projection() ;
439 //
440 // vpImagePoint ip1, ip2;
441 //
442 // vpMeterPixelConversion::convertPoint(*cam,p1->get_x(),p1->get_y(),ip1) ;
443 // vpMeterPixelConversion::convertPoint(*cam,p2->get_x(),p2->get_y(),ip2) ;
444 //
445 // int marge = /*10*/5; //ou 5 normalement
446 // if (ip1.get_j()<ip2.get_j()) { meline->jmin = ip1.get_j()-marge ; meline->jmax = ip2.get_j()+marge ; }
447 // else{ meline->jmin = ip2.get_j()-marge ; meline->jmax = ip1.get_j()+marge ; }
448 // if (ip1.get_i()<ip2.get_i()) { meline->imin = ip1.get_i()-marge ; meline->imax = ip2.get_i()+marge ; }
449 // else{ meline->imin = ip2.get_i()-marge ; meline->imax = ip1.get_i()+marge ; }
450 
451  try
452  {
453  nbFeatureTotal = 0;
454  for(unsigned int i = 0 ; i < meline.size() ; i++){
455  meline[i]->track(I) ;
456  nbFeature.push_back((unsigned int) meline[i]->getMeList().size());
457  nbFeatureTotal += (unsigned int) meline[i]->getMeList().size();
458  }
459  }
460  catch(...)
461  {
462  for(unsigned int i = 0 ; i < meline.size() ; i++){
463  if (meline[i] != NULL) delete meline[i] ;
464  }
465 
466  nbFeature.clear();
467  meline.clear();
468  nbFeatureTotal = 0;
469  Reinit = true;
470  isvisible = false;
471  }
472  }
473 }
474 
475 
482 void
484 {
485  if(isvisible){
486  p1->changeFrame(cMo);
487  p2->changeFrame(cMo);
488 
489  if(poly.getClipping() > 3) // Contains at least one FOV constraint
490  cam.computeFov(I.getWidth(), I.getHeight());
491 
492  poly.computePolygonClipped(cam);
493 
494  if(poly.polyClipped.size() == 2){ //Les points sont visibles.
495 
496  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
497 
498  if(useScanLine){
499  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst);
500  }
501  else{
502  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
503  }
504 
505  if(linesLst.size() != meline.size() || linesLst.size() == 0){
506  for(unsigned int i = 0 ; i < meline.size() ; i++){
507  if (meline[i] != NULL) delete meline[i] ;
508  }
509 
510  meline.clear();
511  nbFeature.clear();
512  nbFeatureTotal = 0;
513  isvisible = false;
514  Reinit = true;
515  }
516  else{
517 
518  // 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.
519 // 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())))
520 // {
521 // std::vector<std::pair<vpPoint, vpPoint> > linesLstTmp;
522 // for(int i = linesLst.size()-1 ; i >= 0 ; i--)
523 // linesLstTmp.push_back(std::make_pair(linesLst[i].second,linesLst[i].first));
524 // linesLst = linesLstTmp;
525 // }
526 
527  line->changeFrame(cMo);
528  line->projection();
529  double rho,theta;
530  //rho theta uv
532 
533  while (theta > M_PI) { theta -= M_PI ; }
534  while (theta < -M_PI) { theta += M_PI ; }
535 
536  if (theta < -M_PI/2.0) theta = -theta - 3*M_PI/2.0;
537  else theta = M_PI/2.0 - theta;
538 
539 
540  try
541  {
542  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
543  vpImagePoint ip1, ip2;
544 
545  linesLst[i].first.project();
546  linesLst[i].second.project();
547 
548  vpMeterPixelConversion::convertPoint(cam,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
549  vpMeterPixelConversion::convertPoint(cam,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
550 
551  int marge = /*10*/5; //ou 5 normalement
552  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 ; }
553  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 ; }
554 
555  meline[i]->updateParameters(I,ip1,ip2,rho,theta) ;
556  nbFeature[i] = (unsigned int)meline[i]->getMeList().size();
558  }
559  }
560  catch(...)
561  {
562  for(unsigned int j = 0 ; j < meline.size() ; j++){
563  if (meline[j] != NULL) delete meline[j] ;
564  }
565 
566  meline.clear();
567  nbFeature.clear();
568  nbFeatureTotal = 0;
569  isvisible = false;
570  Reinit = true;
571  }
572  }
573  }
574  else{
575  for(unsigned int i = 0 ; i < meline.size() ; i++){
576  if (meline[i] != NULL) delete meline[i] ;
577  }
578  nbFeature.clear();
579  meline.clear();
580  nbFeatureTotal = 0;
581  isvisible = false;
582  }
583  }
584 }
585 
586 
595 void
597 {
598  for(unsigned int i = 0 ; i < meline.size() ; i++){
599  if (meline[i] != NULL) delete meline[i] ;
600  }
601 
602  nbFeature.clear();
603  meline.clear();
604  nbFeatureTotal = 0;
605 
606  if (initMovingEdge(I,cMo) == false)
607  Reinit = true;
608 
609  Reinit = false;
610 }
611 
612 
623 void
625  const vpCameraParameters &camera, const vpColor col, const unsigned int thickness, const bool displayFullModel)
626 {
627  if( (isvisible && isTrackedLine) || displayFullModel){
628  p1->changeFrame(cMo);
629  p2->changeFrame(cMo);
630 
631  vpImagePoint ip1, ip2;
632  vpCameraParameters c = camera;
633  if(poly.getClipping() > 3) // Contains at least one FOV constraint
634  c.computeFov(I.getWidth(), I.getHeight());
635 
636  poly.computePolygonClipped(c);
637 
638  if( poly.polyClipped.size() == 2 &&
639  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
640  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
641  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
642  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
643  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
644  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)){
645 
646  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
647  if(useScanLine && !displayFullModel){
648  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst,true);
649  }
650  else{
651  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
652  }
653 
654  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
655  linesLst[i].first.project();
656  linesLst[i].second.project();
657 
658  vpMeterPixelConversion::convertPoint(camera,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
659  vpMeterPixelConversion::convertPoint(camera,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
660 
661  vpDisplay::displayLine(I,ip1,ip2,col, thickness);
662  }
663  }
664  }
665 }
666 
667 
678 void
680  const vpCameraParameters &camera, const vpColor col,
681  const unsigned int thickness, const bool displayFullModel)
682 {
683  if( (isvisible && isTrackedLine) || displayFullModel){
684  p1->changeFrame(cMo);
685  p2->changeFrame(cMo);
686 
687  vpImagePoint ip1, ip2;
688  vpCameraParameters c = camera;
689  if(poly.getClipping() > 3) // Contains at least one FOV constraint
690  c.computeFov(I.getWidth(), I.getHeight());
691 
692  poly.computePolygonClipped(c);
693 
694  if( poly.polyClipped.size() == 2 &&
695  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::NEAR_CLIPPING) == 0) &&
696  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::FAR_CLIPPING) == 0) &&
697  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::DOWN_CLIPPING) == 0) &&
698  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::UP_CLIPPING) == 0) &&
699  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::LEFT_CLIPPING) == 0) &&
700  ((poly.polyClipped[1].second & poly.polyClipped[0].second & vpPolygon3D::RIGHT_CLIPPING) == 0)){
701 
702  std::vector<std::pair<vpPoint, vpPoint> > linesLst;
703  if(useScanLine && !displayFullModel){
704  hiddenface->computeScanLineQuery(poly.polyClipped[0].first,poly.polyClipped[1].first,linesLst,true);
705  }
706  else{
707  linesLst.push_back(std::make_pair(poly.polyClipped[0].first,poly.polyClipped[1].first));
708  }
709 
710  for(unsigned int i = 0 ; i < linesLst.size() ; i++){
711  linesLst[i].first.project();
712  linesLst[i].second.project();
713 
714  vpMeterPixelConversion::convertPoint(camera,linesLst[i].first.get_x(),linesLst[i].first.get_y(),ip1);
715  vpMeterPixelConversion::convertPoint(camera,linesLst[i].second.get_x(),linesLst[i].second.get_y(),ip2);
716 
717  vpDisplay::displayLine(I,ip1,ip2,col, thickness);
718  }
719  }
720  }
721 }
722 
723 
734 void
736 {
737  for(unsigned int i = 0 ; i < meline.size() ; i++)
738  if (meline[i] != NULL)
739  {
740  meline[i]->display(I);
741  }
742 }
743 
747 void
749 {
750  if (isvisible == true)
751  {
752  L.resize(nbFeatureTotal,6) ;
754  }
755  else{
756  for(unsigned int i = 0 ; i < meline.size() ; i++)
757  nbFeature[i] = 0;
758  nbFeatureTotal = 0 ;
759  }
760 }
761 
765 void
767 {
768  if (isvisible)
769  {
770  // feature projection
771  line->changeFrame(cMo) ;
772  line->projection() ;
773 
774  vpFeatureBuilder::create(featureline,*line) ;
775 
776  double rho = featureline.getRho() ;
777  double theta = featureline.getTheta() ;
778 
779  double co = cos(theta);
780  double si = sin(theta);
781 
782  double mx = 1.0/cam.get_px() ;
783  double my = 1.0/cam.get_py() ;
784  double xc = cam.get_u0() ;
785  double yc = cam.get_v0() ;
786 
787  double alpha_ ;
788  vpMatrix H ;
789  H = featureline.interaction() ;
790 
791  double x,y ;
792  vpMeSite p ;
793  unsigned int j =0 ;
794 
795  for(unsigned int i = 0 ; i < meline.size() ; i++){
796  for(std::list<vpMeSite>::const_iterator it=meline[i]->getMeList().begin(); it!=meline[i]->getMeList().end(); ++it){
797  x = (double)it->j ;
798  y = (double)it->i ;
799 
800  x = (x-xc)*mx ;
801  y = (y-yc)*my ;
802 
803  alpha_ = x*si - y*co;
804 
805  double *Lrho = H[0] ;
806  double *Ltheta = H[1] ;
807  // Calculate interaction matrix for a distance
808  for (unsigned int k=0 ; k < 6 ; k++)
809  {
810  L[j][k] = (Lrho[k] + alpha_*Ltheta[k]);
811  }
812  error[j] = rho - ( x*co + y*si) ;
813  j++;
814  }
815  }
816  }
817 }
818 
826 bool
827 vpMbtDistanceLine::closeToImageBorder(const vpImage<unsigned char>& I, const unsigned int threshold)
828 {
829  if(threshold > I.getWidth() || threshold > I.getHeight()){
830  return true;
831  }
832  if (isvisible){
833 
834  for(unsigned int i = 0 ; i < meline.size() ; i++){
835  for(std::list<vpMeSite>::const_iterator it=meline[i]->getMeList().begin(); it!=meline[i]->getMeList().end(); ++it){
836  int i_ = it->i ;
837  int j_ = it->j ;
838 
839  if(i_ < 0 || j_ < 0){ //out of image.
840  return true;
841  }
842 
843  if( ((unsigned int)i_ > (I.getHeight()- threshold) ) || (unsigned int)i_ < threshold ||
844  ((unsigned int)j_ > (I.getWidth ()- threshold) ) || (unsigned int)j_ < threshold ) {
845  return true;
846  }
847  }
848  }
849  }
850  return false;
851 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
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:199
unsigned int getWidth() const
Definition: vpImage.h:226
bool Reinit
Indicates if the line has to be reinitialized.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:266
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:210
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:147
double getRho() const
Definition: vpLine.h:158
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:105
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:175
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
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
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:225
void computeFov(const unsigned int &w, const unsigned int &h)