ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
vpMbEdgeTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbEdgeTracker.h 4338 2013-07-23 14:29:30Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 &me ) const { 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& cam) {
445  this->cam = cam;
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 lambda) {this->lambda = lambda;}
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