Visual Servoing Platform  version 3.0.0
vpSimulator.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Simulator based on Coin3d.
32  *
33  * Authors:
34  * Eric Marchand
35  * Anthony Saunier
36  *
37  *****************************************************************************/
38 
39 #ifndef vpSimulator_HH
40 #define vpSimulator_HH
41 
49 #include <visp3/core/vpConfig.h>
50 
51 #ifdef VISP_HAVE_COIN3D_AND_GUI
52 
53 #include <visp3/ar/vpViewer.h>
54 
55 /* KNOWN ISSUE DEALING WITH X11 and QT
56  If you get a strange compiler error on the line with None,
57  it's probably because you're also including X11 headers,
58  which #define the symbol None. Put the X11 includes after
59  the Qt includes to solve this problem.
60  */
61 
62 #include <Inventor/nodes/SoBaseColor.h>
63 #include <Inventor/nodes/SoTransform.h>
64 #include <Inventor/nodes/SoCone.h>
65 #include <Inventor/nodes/SoCube.h>
66 #include <Inventor/nodes/SoImage.h>
67 #include <Inventor/nodes/SoLightModel.h>
68 #include <Inventor/nodes/SoPerspectiveCamera.h>
69 #include <Inventor/nodes/SoRotationXYZ.h>
70 #include <Inventor/nodes/SoSeparator.h>
71 #include <Inventor/nodes/SoTranslation.h>
72 #include <Inventor/sensors/SoTimerSensor.h>
73 #include <Inventor/SoOffscreenRenderer.h>
74 #include <Inventor/fields/SoSFTime.h>
75 #include <Inventor/threads/SbThread.h>
76 
77 // visp
78 #include <visp3/core/vpDebug.h>
79 #include <visp3/core/vpHomogeneousMatrix.h>
80 #include <visp3/core/vpCameraParameters.h>
81 #include <visp3/core/vpImage.h>
82 #include <visp3/core/vpRGBa.h>
83 #include <visp3/core/vpImageConvert.h>
84 
98 class VISP_EXPORT vpSimulator
99 {
100 protected:
102  void init() ;
104  void kill() ;
105 
106 public:
108  vpSimulator() ;
109  virtual ~vpSimulator() ;
110 
111 protected:
113 #if defined(VISP_HAVE_SOWIN)
114  HWND mainWindow ;
115 #elif defined(VISP_HAVE_SOQT)
116  QWidget * mainWindow ;
117 #elif defined(VISP_HAVE_SOXT)
118  Widget mainWindow ;
119 #endif
120 
122 
124  void initSoApplication() ;
125 
126 public:
127  typedef enum {
129  colorImage
130  } vpImageType ;
132 
133  GLubyte * image_background;
135  virtual void mainLoop() ;
136 
137 protected:
142 
143 public:
145  virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol) ;
147  void initExternalViewer(const unsigned int nlig, const unsigned int ncol) ;
148 
149 protected:
151  SbThread * mainThread;
152  //pthread_t mainThread;
153 
154 public:
156  void initApplication(void *(*start_routine)(void *)) ;
157  void initApplication(void *(*start_routine)(void *), void* data);
159  void initMainApplication() ;
160  void closeMainApplication() ;
161 
162  //----------------------------------------------------
163  // scene description
164 protected:
165  unsigned int internal_width;
166  unsigned int internal_height;
167  unsigned int external_width;
168  unsigned int external_height;
169 
170 public:
176  unsigned int getInternalWidth() const { return internal_width; }
182  unsigned int getInternalHeight() const { return internal_height; }
183 
184 protected:
187  SoSeparator *scene;
189  SoSeparator *internalRoot;
191  SoSeparator *externalRoot;
192 
194  SoPerspectiveCamera *internalCamera ;
196  SoPerspectiveCamera *externalCamera ;
197 
199  SoTransform *internalCameraPosition ;
200 
202  SoTransform *extrenalCameraPosition ;
203 
205  SoSeparator *internalCameraObject;
206 
208  void initSceneGraph() ;
209 
211  void addObject(SoSeparator * object, const vpHomogeneousMatrix &fMo,
212  SoSeparator * root) ;
213 
214 public :
216  void addObject(SoSeparator * newObject, const vpHomogeneousMatrix &fMo) ;
217 
218 public:
220  void redraw() ;
222  void load(const char *file_name) ;
224  void load(const char *iv_filename,const vpHomogeneousMatrix &fMo) ;
226  void save(const char *name,bool binary=false) ;
227 
229  void addAbsoluteFrame (float zoom=1) ;
231  void addFrame (const vpHomogeneousMatrix &fMo, float zoom=1) ;
233  void setZoomFactor (const float zoom) ;
234 
235 protected:
236  float zoomFactor ;
237  //---------------------------------------------------
238  // camera description
239 protected:
247 
248 public:
250  void setCameraPosition(vpHomogeneousMatrix &cMf) ;
252  void getCameraPosition(vpHomogeneousMatrix &_cMf) { _cMf = cMf ; }
254  void moveInternalCamera(vpHomogeneousMatrix &cMf) ;
256  void setInternalCameraParameters(vpCameraParameters &cam) ;
258  void setExternalCameraParameters(vpCameraParameters &cam) ;
260  void getExternalCameraPosition(vpHomogeneousMatrix &cMf) ;
261 
263  void getInternalImage(vpImage<unsigned char> &I) ;
265  void getInternalImage(vpImage<vpRGBa> &I) ;
266  /* --- Off screen rendering --- */
267 
268  void changeZoomFactor(const float zoom, const int index);
269 public:
270  typedef enum { INTERNAL, EXTERNAL } vpSimulatorViewType ;
271 #ifdef VISP_HAVE_MODULE_IO
272  void write(const char * fileName);
273 #endif
274 protected:
275  SbTime * realtime ;
276  SoOffscreenRenderer * offScreenRenderer ;
277  void offScreenRendering (vpSimulatorViewType view=vpSimulator::EXTERNAL,
278  int * width = NULL,
279  int * height = NULL);
280 public:
282  unsigned char * bufferView;
283 
285  int get ;
286 public:
289  {
290  return bufferView;
291  }
292 
294  void getSizeInternalView(int& width, int& height);
295 
298  {
299  cam = internalCameraParameters;
300  }
301 } ;
302 
303 
304 #endif
305 #endif
HWND mainWindow
main Widget
Definition: vpSimulator.h:114
SoSeparator * externalRoot
root node of the external view
Definition: vpSimulator.h:191
SoPerspectiveCamera * internalCamera
internal camera
Definition: vpSimulator.h:194
bool cameraPositionInitialized
Definition: vpSimulator.h:240
SoTransform * internalCameraPosition
internal camera position
Definition: vpSimulator.h:199
int get
Flag to protect the read and write of the framebuffer (between the simulator and the viewer)...
Definition: vpSimulator.h:285
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a simulator based on Coin3d (www.coin3d.org).
Definition: vpSimulator.h:98
vpCameraParameters internalCameraParameters
internal camera parameters
Definition: vpSimulator.h:244
unsigned int getInternalHeight() const
Definition: vpSimulator.h:182
unsigned int external_height
Definition: vpSimulator.h:168
void getCameraParameters(vpCameraParameters &cam)
get the intrinsic parameters of the camera
Definition: vpSimulator.h:297
bool mainWindowInitialized
Definition: vpSimulator.h:121
vpViewer * internalView
view from the camera
Definition: vpSimulator.h:139
vpImageType typeImage
Definition: vpSimulator.h:131
SoSeparator * scene
Definition: vpSimulator.h:187
SoSeparator * internalRoot
root node of the internal view
Definition: vpSimulator.h:189
vpCameraParameters externalCameraParameters
internal camera parameters
Definition: vpSimulator.h:246
SbTime * realtime
Definition: vpSimulator.h:275
unsigned char * getBufferedOffScreenRenderer()
get the image corresponding to the internal view
Definition: vpSimulator.h:288
void getCameraPosition(vpHomogeneousMatrix &_cMf)
get the camera position (from an homogeneous matrix)
Definition: vpSimulator.h:252
SoTransform * extrenalCameraPosition
external camera position
Definition: vpSimulator.h:202
GLubyte * image_background
Definition: vpSimulator.h:133
Viewer used by the simulator.
Definition: vpViewer.h:117
Generic class defining intrinsic camera parameters.
vpViewer * externalView
view from an external camera
Definition: vpSimulator.h:141
SoPerspectiveCamera * externalCamera
external camera
Definition: vpSimulator.h:196
unsigned int external_width
Definition: vpSimulator.h:167
vpHomogeneousMatrix cMf
internal camera position
Definition: vpSimulator.h:242
unsigned char * bufferView
image of the internal view
Definition: vpSimulator.h:282
unsigned int internal_width
Definition: vpSimulator.h:165
unsigned int getInternalWidth() const
Definition: vpSimulator.h:176
SoOffscreenRenderer * offScreenRenderer
Definition: vpSimulator.h:276
unsigned int internal_height
Definition: vpSimulator.h:166
float zoomFactor
Definition: vpSimulator.h:236
SoSeparator * internalCameraObject
representation of the camera in the external view
Definition: vpSimulator.h:205
SbThread * mainThread
thread with the main program
Definition: vpSimulator.h:151