ViSP  2.9.0
vpMbEdgeTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbEdgeTracker.h 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Make the complete tracking of an object by using its CAD model
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Romain Tallonneau
40  * Eric Marchand
41  *
42  *****************************************************************************/
43 
49 #ifndef vpMbEdgeTracker_HH
50 #define vpMbEdgeTracker_HH
51 
52 #include <visp/vpPoint.h>
53 #include <visp/vpMbTracker.h>
54 #include <visp/vpMe.h>
55 #include <visp/vpMbtMeLine.h>
56 #include <visp/vpMbtDistanceLine.h>
57 #include <visp/vpMbtDistanceCylinder.h>
58 #include <visp/vpXmlParser.h>
59 
60 #include <iostream>
61 #include <fstream>
62 #include <vector>
63 #include <list>
64 
65 #if defined(VISP_HAVE_COIN)
66 //Inventor includes
67 #include <Inventor/nodes/SoSeparator.h>
68 #include <Inventor/VRMLnodes/SoVRMLIndexedFaceSet.h>
69 #include <Inventor/VRMLnodes/SoVRMLIndexedLineSet.h>
70 #include <Inventor/VRMLnodes/SoVRMLCoordinate.h>
71 #include <Inventor/actions/SoWriteAction.h>
72 #include <Inventor/actions/SoSearchAction.h>
73 #include <Inventor/misc/SoChildList.h>
74 #include <Inventor/actions/SoGetMatrixAction.h>
75 #include <Inventor/actions/SoGetPrimitiveCountAction.h>
76 #include <Inventor/actions/SoToVRML2Action.h>
77 #include <Inventor/VRMLnodes/SoVRMLGroup.h>
78 #include <Inventor/VRMLnodes/SoVRMLShape.h>
79 #endif
80 
81 #ifdef VISP_HAVE_OPENCV
82 # if VISP_HAVE_OPENCV_VERSION >= 0x020101
83 # include <opencv2/core/core.hpp>
84 # include <opencv2/imgproc/imgproc.hpp>
85 # include <opencv2/imgproc/imgproc_c.h>
86 # else
87 # include <cv.h>
88 # endif
89 #endif
90 
91 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
92 # include <visp/vpList.h>
93 #endif
94 
267 class VISP_EXPORT vpMbEdgeTracker: virtual public vpMbTracker
268 {
269  protected :
270 
277  double lambda;
278 
282  std::vector< std::list< vpMbtDistanceLine*> > lines;
284  std::vector< std::list< vpMbtDistanceCylinder*> > cylinders;
285 
287  unsigned int nline;
288 
290  unsigned int ncylinder;
291 
294 
297 
299  unsigned int nbvisiblepolygone;
300 
303 
305  std::vector<bool> scales;
306 
308  std::vector< const vpImage<unsigned char>* > Ipyramid;
309 
311  unsigned int scaleLevel;
312 
314  bool useOgre;
315 
317  double angleAppears;
318 
321 
323  double distNearClip;
324 
326  double distFarClip;
327 
329  unsigned int clippingFlag;
330 
331 public:
332 
333  vpMbEdgeTracker();
334  virtual ~vpMbEdgeTracker();
335 
336  void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
337  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false);
338  void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
339  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false);
340 
342  virtual inline double getAngleAppear() const { return angleAppears; }
343 
345  virtual inline double getAngleDisappear() const { return angleDisappears; }
346 
354  virtual inline unsigned int getClipping() const { return clippingFlag; }
355 
357  inline vpMbHiddenFaces<vpMbtPolygon>& getFaces() { return faces; }
358 
364  virtual inline double getFarClippingDistance() const { return distFarClip; }
365 
366  inline double getFirstThreshold() const { return percentageGdPt;}
367 
373  virtual inline double getLambda() const {return lambda;}
374 
375  void getLline(std::list<vpMbtDistanceLine *>& linesList, const unsigned int level = 0);
376  void getLcylinder(std::list<vpMbtDistanceCylinder *>& cylindersList, const unsigned int level = 0);
377 
383  inline void getMovingEdge(vpMe &p_me ) const { p_me = this->me;}
384 
390  virtual inline double getNearClippingDistance() const { return distNearClip; }
391 
392  unsigned int getNbPoints(const unsigned int level=0) const;
393  unsigned int getNbPolygon() const ;
394  vpMbtPolygon* getPolygon(const unsigned int index);
395 
401  std::vector<bool> getScales() const {return scales;}
402 
403  void loadConfigFile(const std::string &configFile);
404  void loadConfigFile(const char* configFile);
405  void loadModel(const std::string &cad_name);
406  void loadModel(const char* cad_name);
407 
408  void reInitModel(const vpImage<unsigned char>& I, const char* cad_name, const vpHomogeneousMatrix& cMo);
409  void resetTracker();
410 
423  virtual inline void setAngleAppear(const double &a) { angleAppears = a; }
424 
437  virtual inline void setAngleDisappear(const double &a) { angleDisappears = a; }
438 
444  virtual void setCameraParameters(const vpCameraParameters& camera) {
445  this->cam = camera;
446 
447  for (unsigned int i = 0; i < scales.size(); i += 1){
448  if(scales[i]){
449  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[i].begin(); it!=lines[i].end(); ++it){
450  (*it)->setCameraParameters(cam);
451  }
452 
453  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[i].begin(); it!=cylinders[i].end(); ++it){
454  (*it)->setCameraParameters(cam);
455  }
456  }
457  }
458  }
459 
460  virtual void setClipping(const unsigned int &flags);
461 
472  void setDisplayMovingEdges(const bool displayMe) {displayFeatures = displayMe;}
473 
474  virtual void setFarClippingDistance(const double &dist);
475 
485  void setFirstThreshold(const double threshold1) {percentageGdPt = threshold1;}
486 
492  virtual inline void setLambda(const double gain) {this->lambda = gain;}
493 
494  void setMovingEdge(const vpMe &me);
495 
496  virtual void setNearClippingDistance(const double &dist);
497 
498  virtual void setOgreVisibilityTest(const bool &v);
499 
500  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
501 
502  void setScales(const std::vector<bool>& _scales);
503 
504  void track(const vpImage<unsigned char> &I);
505 
506 protected:
507  void addCylinder(const vpPoint &P1, const vpPoint &P2, const double r, const std::string& name = "");
508  void addLine(vpPoint &p1, vpPoint &p2, int polygone = -1, std::string name = "");
509  void addPolygon(vpMbtPolygon &p) ;
510  void cleanPyramid(std::vector<const vpImage<unsigned char>* >& _pyramid);
511  void computeVVS(const vpImage<unsigned char>& _I);
512  void downScale(const unsigned int _scale);
513  void init(const vpImage<unsigned char>& I);
514  virtual void initCylinder(const vpPoint& p1, const vpPoint &p2, const double radius, const unsigned int indexCylinder=0);
515  virtual void initFaceFromCorners(const std::vector<vpPoint>& _corners, const unsigned int _indexFace = -1);
516  void initMovingEdge(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &_cMo) ;
517  void initPyramid(const vpImage<unsigned char>& _I, std::vector<const vpImage<unsigned char>* >& _pyramid);
518  void reInitLevel(const unsigned int _lvl);
519  void reinitMovingEdge(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &_cMo);
520  void removeCylinder(const std::string& name);
521  void removeLine(const std::string& name);
522  void testTracking();
523  void trackMovingEdge(const vpImage<unsigned char> &I) ;
524  void updateMovingEdge(const vpImage<unsigned char> &I) ;
525  void upScale(const unsigned int _scale);
526  void visibleFace(const vpImage<unsigned char> &_I, const vpHomogeneousMatrix &_cMo, bool &newvisibleline) ;
527 
528 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
529 
532  vp_deprecated void visibleFace(const vpHomogeneousMatrix &_cMo, bool &newvisibleline);
533 #endif
534 };
535 
536 #endif
537 
std::vector< bool > getScales() const
void setDisplayMovingEdges(const bool displayMe)
double distFarClip
Distance for near clipping.
unsigned int ncylinder
Index of the cylinder to add, and total number of polygon extracted so far.
virtual void track(const vpImage< unsigned char > &I)=0
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
virtual void setAngleAppear(const double &a)
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)=0
double lambda
The gain of the virtual visual servoing stage.
unsigned int scaleLevel
Current scale level used. This attribute must not be modified outside of the downScale() and upScale(...
virtual void setAngleDisappear(const double &a)
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
virtual double getFarClippingDistance() const
double distNearClip
Distance for near clipping.
Contains predetermined masks for sites and holds moving edges tracking parameters.
Definition: vpMe.h:70
Make the complete tracking of an object by using its CAD model.
std::vector< const vpImage< unsigned char > * > Ipyramid
Pyramid of image associated to the current image. This pyramid is computed in the init() and in the t...
virtual void setCameraParameters(const vpCameraParameters &camera)
double angleDisappears
Angle used to detect a face disappearance.
virtual double getAngleAppear() const
vpMe me
The moving edges parameters.
virtual void resetTracker()=0
std::vector< std::list< vpMbtDistanceLine * > > lines
Vector of list of all the lines tracked (each line is linked to a list of moving edges). Each element of the vector is for a scale (element 0 = level 0 = no subsampling).
void setFirstThreshold(const double threshold1)
double getFirstThreshold() const
virtual double getNearClippingDistance() const
bool useOgre
Use Ogre3d for visibility tests.
Class that defines what is a point.
Definition: vpPoint.h:65
virtual void init(const vpImage< unsigned char > &I)=0
int index_polygon
Index of the polygon to add, and total number of polygon extracted so far. Cannot be unsigned because...
virtual 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)=0
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
void getMovingEdge(vpMe &p_me) const
virtual double getAngleDisappear() const
Generic class defining intrinsic camera parameters.
virtual void loadModel(const std::string &modelFile)
Main methods for a model-based tracker.
Definition: vpMbTracker.h:102
double percentageGdPt
Percentage of good points over total number of points below which tracking is supposed to have failed...
double angleAppears
Angle used to detect a face appearance.
virtual void loadConfigFile(const std::string &configFile)=0
vpMbHiddenFaces< vpMbtPolygon > & getFaces()
virtual double getLambda() const
std::vector< std::list< vpMbtDistanceCylinder * > > cylinders
Vector of the tracked cylinders.
virtual void testTracking()=0
unsigned int nbvisiblepolygone
Number of polygon (face) currently visible.
virtual unsigned int getClipping() const
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
unsigned int nline
Index of the polygon to add, and total number of polygon extracted so far.
unsigned int clippingFlag
Flags specifying which clipping to used.
virtual void setLambda(const double gain)
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const unsigned int indexCylinder=0)=0