ViSP  2.6.2
vpMbTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbTracker.h 3837 2012-07-05 09:38:56Z ayol $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 
59 #ifdef VISP_HAVE_COIN
60 //Inventor includes
61 # include <Inventor/VRMLnodes/SoVRMLIndexedFaceSet.h>
62 # include <Inventor/VRMLnodes/SoVRMLIndexedLineSet.h>
63 #endif
64 
65 #include <vector>
66 #include <string>
67 
95 class VISP_EXPORT vpMbTracker
96 {
97 protected:
103  std::string modelFileName;
109  bool coinUsed;
111  std::string poseSavingFilename;
116 
117 public:
118  vpMbTracker();
119  virtual ~vpMbTracker();
120 
121  // Intializer
122 
123  virtual void initClick( const vpImage<unsigned char>& _I, const std::string& _initFile, const bool _displayHelp = false );
124  virtual void initClick( const vpImage<unsigned char>& _I, const std::vector<vpPoint> &points3D_list, const std::string &displayFile = "" );
125 
126  virtual void initFromPoints( const vpImage<unsigned char>& _I, const std::string& _initFile );
127  virtual void initFromPoints( const vpImage<unsigned char>& _I, const std::vector<vpImagePoint> &points2D_list, const std::vector<vpPoint> &points3D_list );
128 
129  virtual void initFromPose(const vpImage<unsigned char>& _I, const std::string &_initFile);
130  virtual void initFromPose(const vpImage<unsigned char>& _I, const vpHomogeneousMatrix &_cMo);
131  virtual void initFromPose(const vpImage<unsigned char>& _I, const vpPoseVector &cPo);
132 
133  /* PURE VIRTUAL METHODS */
134 
140  virtual void init(const vpImage<unsigned char>& _I)=0;
141 
147  virtual void testTracking() = 0;
148 
156  virtual void loadConfigFile(const std::string& _configFile)=0;
157 
163  virtual void track(const vpImage<unsigned char>& _I)=0;
164 
165  /* GENERIC METHODS */
166 
167  virtual void loadModel(const std::string& _modelFile);
168 
180  virtual void display(const vpImage<unsigned char>& _I, const vpHomogeneousMatrix &_cMo, const vpCameraParameters &_cam, const vpColor& _col , const unsigned int _l=1, const bool displayFullModel = false)=0;
181 
182  /* ACCESSORS */
183 
189  virtual void setCameraParameters(const vpCameraParameters& _cam) {this->cam = _cam; cameraInitialised = true;}
190 
196  virtual void setCovarianceComputation(const bool& flag) { computeCovariance = flag; }
197 
203  virtual void getCameraParameters(vpCameraParameters& _cam) const { _cam = this->cam;}
204 
208  virtual vpMatrix getCovarianceMatrix() const {
209  if(!computeCovariance)
210  vpTRACE("Warning : The covariance matrix has not been computed. See setCovarianceComputation() to do it.");
211 
212  return covarianceMatrix;
213  }
214 
222  inline void getPose(vpHomogeneousMatrix& _cMo) const {_cMo = this->cMo;}
223 
231  inline vpHomogeneousMatrix getPose() const {return this->cMo;}
232 
242  inline void setPoseSavingFilename(const std::string& filename){
243  poseSavingFilename = filename;
244  }
245 
246  void savePose(const std::string &filename);
247 
248 protected:
249  virtual void loadVRMLModel(const std::string& _modelFile);
250  virtual void loadCAOModel(const std::string& _modelFile);
251 
252  void computeJTR(const vpMatrix& _J, const vpColVector& _R, vpMatrix& _JTR);
253 
254 #ifdef VISP_HAVE_COIN
255  virtual void extractFaces(SoVRMLIndexedFaceSet* _face_set);
256  virtual void extractLines(SoVRMLIndexedLineSet* _line_set);
257  virtual void extractCylinders(SoVRMLIndexedFaceSet* _face_set);
258 #endif
259  vpPoint getGravityCenter(const std::vector<vpPoint>& _pts);
260 
269  virtual void initFaceFromCorners(const std::vector<vpPoint>& _corners, const unsigned int _indexFace = -1)=0;
270 
280  virtual void initCylinder(const vpPoint& _p1, const vpPoint _p2, const double _radius, const unsigned int _indexCylinder=0)=0;
281 
282 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
283 
296  /* vp_deprecated */ virtual void init(const vpImage<unsigned char>& _I, const vpHomogeneousMatrix& _c0Mo)=0;
297 #endif
298 };
299 
300 
301 #endif
302 
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:196
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:115
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:101
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
Definition: vpMbTracker.h:105
vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:231
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:103
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:113
bool cameraInitialised
Flag used to ensure that the camera is set before the initialisation.
Definition: vpMbTracker.h:107
Class that defines what is a point.
Definition: vpPoint.h:65
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:99
virtual void getCameraParameters(vpCameraParameters &_cam) const
Definition: vpMbTracker.h:203
Generic class defining intrinsic camera parameters.
Main methods for a model-based tracker.
Definition: vpMbTracker.h:95
std::string poseSavingFilename
Filename used to save the initial pose computed using the initClick() method. It is also used to read...
Definition: vpMbTracker.h:111
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:109
virtual void setCameraParameters(const vpCameraParameters &_cam)
Definition: vpMbTracker.h:189
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:242
void getPose(vpHomogeneousMatrix &_cMo) const
Definition: vpMbTracker.h:222
virtual vpMatrix getCovarianceMatrix() const
Definition: vpMbTracker.h:208