ViSP  2.9.0
vpMbTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbTracker.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  * 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 around 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  std::string poseSavingFilename;
121 
122 public:
123  vpMbTracker();
124  virtual ~vpMbTracker();
125 
137  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
138  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false)=0;
150  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
151  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false)=0;
152 
158  virtual void getCameraParameters(vpCameraParameters& camera) const { camera = this->cam;}
159 
163  virtual vpMatrix getCovarianceMatrix() const {
164  if(!computeCovariance)
165  vpTRACE("Warning : The covariance matrix has not been computed. See setCovarianceComputation() to do it.");
166 
167  return covarianceMatrix;
168  }
169 
177  inline void getPose(vpHomogeneousMatrix& cMo_) const {cMo_ = this->cMo;}
178 
186  inline vpHomogeneousMatrix getPose() const {return this->cMo;}
187 
188  /* PURE VIRTUAL METHODS */
189 
195  virtual void init(const vpImage<unsigned char>& I)=0;
196 
197  // Intializer
198 
199  virtual void initClick( const vpImage<unsigned char>& I, const std::string& initFile, const bool displayHelp = false );
200  virtual void initClick( const vpImage<unsigned char>& I, const std::vector<vpPoint> &points3D_list,
201  const std::string &displayFile = "" );
202 
203  virtual void initFromPoints( const vpImage<unsigned char>& I, const std::string& initFile );
204  virtual void initFromPoints( const vpImage<unsigned char>& I, const std::vector<vpImagePoint> &points2D_list, const std::vector<vpPoint> &points3D_list );
205 
206  virtual void initFromPose(const vpImage<unsigned char>& I, const std::string &initFile);
207  virtual void initFromPose(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo);
208  virtual void initFromPose(const vpImage<unsigned char>& I, const vpPoseVector &cPo);
209 
217  virtual void loadConfigFile(const std::string& configFile)=0;
218 
219  virtual void loadModel(const std::string& modelFile);
220 
224  virtual void resetTracker() = 0;
225 
226  void savePose(const std::string &filename);
227 
233  virtual void setCameraParameters(const vpCameraParameters& camera) {this->cam = camera;}
234 
240  virtual void setCovarianceComputation(const bool& flag) { computeCovariance = flag; }
241 
247  void setDisplayFeatures(const bool displayF) {displayFeatures = displayF;}
248 
258  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo) = 0;
259 
269  inline void setPoseSavingFilename(const std::string& filename){
270  poseSavingFilename = filename;
271  }
272 
278  virtual void testTracking() = 0;
279 
285  virtual void track(const vpImage<unsigned char>& I)=0;
286 
287 protected:
288  void computeJTR(const vpMatrix& J, const vpColVector& R, vpMatrix& JTR);
289 
290 #ifdef VISP_HAVE_COIN
291  virtual void extractGroup(SoVRMLGroup *sceneGraphVRML2, vpHomogeneousMatrix &transform, unsigned int &indexFace);
292  virtual void extractFaces(SoVRMLIndexedFaceSet* face_set, vpHomogeneousMatrix &transform, unsigned int &indexFace);
293  virtual void extractLines(SoVRMLIndexedLineSet* line_set);
294  virtual void extractCylinders(SoVRMLIndexedFaceSet* face_set, vpHomogeneousMatrix &transform);
295 #endif
296 
297  vpPoint getGravityCenter(const std::vector<vpPoint>& _pts);
298 
308  virtual void initCylinder(const vpPoint& p1, const vpPoint &p2, const double radius, const unsigned int indexCylinder=0)=0;
309 
318  virtual void initFaceFromCorners(const std::vector<vpPoint>& corners, const unsigned int indexFace = -1)=0;
319 
320  virtual void loadVRMLModel(const std::string& modelFile);
321  virtual void loadCAOModel(const std::string& modelFile);
322 };
323 
324 
325 #endif
326 
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:240
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:118
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpTRACE
Definition: vpDebug.h:418
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
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:186
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:116
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 &camera)
Definition: vpMbTracker.h:233
void getPose(vpHomogeneousMatrix &cMo_) const
Definition: vpMbTracker.h:177
virtual void getCameraParameters(vpCameraParameters &camera) const
Definition: vpMbTracker.h:158
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:114
bool displayFeatures
If true, the features are displayed.
Definition: vpMbTracker.h:120
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:269
void setDisplayFeatures(const bool displayF)
Definition: vpMbTracker.h:247
virtual vpMatrix getCovarianceMatrix() const
Definition: vpMbTracker.h:163