ViSP  2.7.0
vpMbTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbTracker.h 4122 2013-02-08 10:45:54Z ayol $
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  * Description:
34  * Generic model based tracker. This class declares the methods to implement in
35  * order to have a model based tracker.
36  *
37  * Authors:
38  * Romain Tallonneau
39  * AurĂ©lien Yol
40  *
41  *****************************************************************************/
42 
47 #ifndef vpMbTracker_hh
48 #define vpMbTracker_hh
49 
50 #include <visp/vpHomogeneousMatrix.h>
51 #include <visp/vpImage.h>
52 #include <visp/vpImagePoint.h>
53 #include <visp/vpColVector.h>
54 #include <visp/vpMatrix.h>
55 #include <visp/vpRGBa.h>
56 #include <visp/vpCameraParameters.h>
57 #include <visp/vpPoint.h>
58 #include <visp/vpMbtPolygon.h>
59 #include <visp/vpMbHiddenFaces.h>
60 
61 #ifdef VISP_HAVE_COIN
62 //Work arround to avoid type redefinition int8_t with Coin
63 // #if defined(WIN32) && defined(VISP_HAVE_OGRE) && (_MSC_VER >= 1600) // Visual Studio 2010
64 // #define HAVE_INT8_T 1
65 // #endif
66 
67 //Inventor includes
68 # include <Inventor/VRMLnodes/SoVRMLGroup.h>
69 # include <Inventor/VRMLnodes/SoVRMLIndexedFaceSet.h>
70 # include <Inventor/VRMLnodes/SoVRMLIndexedLineSet.h>
71 #endif
72 
73 #include <vector>
74 #include <string>
75 
102 class VISP_EXPORT vpMbTracker
103 {
104 protected:
110  std::string modelFileName;
114  bool coinUsed;
116  std::string poseSavingFilename;
123 
124 public:
125  vpMbTracker();
126  virtual ~vpMbTracker();
127 
139  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
140  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false)=0;
152  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
153  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false)=0;
154 
160  virtual void getCameraParameters(vpCameraParameters& cam) const { cam = this->cam;}
161 
165  virtual vpMatrix getCovarianceMatrix() const {
166  if(!computeCovariance)
167  vpTRACE("Warning : The covariance matrix has not been computed. See setCovarianceComputation() to do it.");
168 
169  return covarianceMatrix;
170  }
171 
179  inline void getPose(vpHomogeneousMatrix& cMo) const {cMo = this->cMo;}
180 
188  inline vpHomogeneousMatrix getPose() const {return this->cMo;}
189 
190  /* PURE VIRTUAL METHODS */
191 
197  virtual void init(const vpImage<unsigned char>& I)=0;
198 
199  // Intializer
200 
201  virtual void initClick( const vpImage<unsigned char>& I, const std::string& initFile, const bool displayHelp = false );
202  virtual void initClick( const vpImage<unsigned char>& I, const std::vector<vpPoint> &points3D_list,
203  const std::string &displayFile = "" );
204 
205  virtual void initFromPoints( const vpImage<unsigned char>& I, const std::string& initFile );
206  virtual void initFromPoints( const vpImage<unsigned char>& I, const std::vector<vpImagePoint> &points2D_list, const std::vector<vpPoint> &points3D_list );
207 
208  virtual void initFromPose(const vpImage<unsigned char>& I, const std::string &initFile);
209  virtual void initFromPose(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo);
210  virtual void initFromPose(const vpImage<unsigned char>& I, const vpPoseVector &cPo);
211 
219  virtual void loadConfigFile(const std::string& configFile)=0;
220 
221  virtual void loadModel(const std::string& modelFile);
222 
226  virtual void resetTracker() = 0;
227 
228  void savePose(const std::string &filename);
229 
235  virtual void setCameraParameters(const vpCameraParameters& cam) {this->cam = cam;}
236 
242  virtual void setCovarianceComputation(const bool& flag) { computeCovariance = flag; }
243 
249  void setDisplayFeatures(const bool displayF) {displayFeatures = displayF;}
250 
260  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo) = 0;
261 
271  inline void setPoseSavingFilename(const std::string& filename){
272  poseSavingFilename = filename;
273  }
274 
280  virtual void testTracking() = 0;
281 
287  virtual void track(const vpImage<unsigned char>& I)=0;
288 
289 protected:
290  void computeJTR(const vpMatrix& J, const vpColVector& R, vpMatrix& JTR);
291 
292 #ifdef VISP_HAVE_COIN
293  virtual void extractGroup(SoVRMLGroup *sceneGraphVRML2, vpHomogeneousMatrix &transform, unsigned int &indexFace);
294  virtual void extractFaces(SoVRMLIndexedFaceSet* face_set, vpHomogeneousMatrix &transform, unsigned int &indexFace);
295  virtual void extractLines(SoVRMLIndexedLineSet* line_set);
296  virtual void extractCylinders(SoVRMLIndexedFaceSet* face_set, vpHomogeneousMatrix &transform);
297 #endif
298 
299  vpPoint getGravityCenter(const std::vector<vpPoint>& _pts);
300 
310  virtual void initCylinder(const vpPoint& p1, const vpPoint p2, const double radius, const unsigned int indexCylinder=0)=0;
311 
320  virtual void initFaceFromCorners(const std::vector<vpPoint>& corners, const unsigned int indexFace = -1)=0;
321 
322  virtual void loadVRMLModel(const std::string& modelFile);
323  virtual void loadCAOModel(const std::string& modelFile);
324 };
325 
326 
327 #endif
328 
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:242
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:120
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpTRACE
Definition: vpDebug.h:401
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
vpHomogeneousMatrix cMo
The current pose.
Definition: vpMbTracker.h:108
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
Definition: vpMbTracker.h:112
vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:188
std::string modelFileName
The name of the file containing the model (it is used to create a file name.0.pos used to store the c...
Definition: vpMbTracker.h:110
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:118
Class that defines what is a point.
Definition: vpPoint.h:65
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:106
virtual void setCameraParameters(const vpCameraParameters &cam)
Definition: vpMbTracker.h:235
Generic class defining intrinsic camera parameters.
Main methods for a model-based tracker.
Definition: vpMbTracker.h:102
std::string poseSavingFilename
Filename used to save the initial pose computed using the initClick() method. It is also used to read...
Definition: vpMbTracker.h:116
virtual void getCameraParameters(vpCameraParameters &cam) const
Definition: vpMbTracker.h:160
bool coinUsed
Flag used to specify that the Coin library has been loaded in order to load a vrml model (used to fre...
Definition: vpMbTracker.h:114
bool displayFeatures
If true, the features are displayed.
Definition: vpMbTracker.h:122
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
The pose is a complete representation of every rigid motion in the euclidian space.
Definition: vpPoseVector.h:92
void setPoseSavingFilename(const std::string &filename)
Definition: vpMbTracker.h:271
void setDisplayFeatures(const bool displayF)
Definition: vpMbTracker.h:249
void getPose(vpHomogeneousMatrix &cMo) const
Definition: vpMbTracker.h:179
virtual vpMatrix getCovarianceMatrix() const
Definition: vpMbTracker.h:165