Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpSimulator.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Simulator based on Coin3d.
33  *
34  * Authors:
35  * Eric Marchand
36  * Anthony Saunier
37  *
38  *****************************************************************************/
39 
40 #ifndef vpSimulator_HH
41 #define vpSimulator_HH
42 
50 #include <visp3/core/vpConfig.h>
51 
52 #ifdef VISP_HAVE_COIN3D_AND_GUI
53 
54 #include <visp3/ar/vpViewer.h>
55 
56 /* KNOWN ISSUE DEALING WITH X11 and QT
57  If you get a strange compiler error on the line with None,
58  it's probably because you're also including X11 headers,
59  which #define the symbol None. Put the X11 includes after
60  the Qt includes to solve this problem.
61  */
62 
63 #include <Inventor/SoOffscreenRenderer.h>
64 #include <Inventor/fields/SoSFTime.h>
65 #include <Inventor/nodes/SoBaseColor.h>
66 #include <Inventor/nodes/SoCone.h>
67 #include <Inventor/nodes/SoCube.h>
68 #include <Inventor/nodes/SoImage.h>
69 #include <Inventor/nodes/SoLightModel.h>
70 #include <Inventor/nodes/SoPerspectiveCamera.h>
71 #include <Inventor/nodes/SoRotationXYZ.h>
72 #include <Inventor/nodes/SoSeparator.h>
73 #include <Inventor/nodes/SoTransform.h>
74 #include <Inventor/nodes/SoTranslation.h>
75 #include <Inventor/sensors/SoTimerSensor.h>
76 #include <Inventor/threads/SbThread.h>
77 
78 // visp
79 #include <visp3/core/vpCameraParameters.h>
80 #include <visp3/core/vpDebug.h>
81 #include <visp3/core/vpHomogeneousMatrix.h>
82 #include <visp3/core/vpImage.h>
83 #include <visp3/core/vpImageConvert.h>
84 #include <visp3/core/vpRGBa.h>
85 
99 class VISP_EXPORT vpSimulator
100 {
101 protected:
103  void init();
105  void kill();
106 
107 public:
109  vpSimulator();
110  virtual ~vpSimulator();
111 
112 protected:
114 #if defined(VISP_HAVE_SOWIN)
116 #elif defined(VISP_HAVE_SOQT)
117  QWidget *mainWindow;
118 #elif defined(VISP_HAVE_SOXT)
119  Widget mainWindow;
120 #endif
121 
123 
125  void initSoApplication();
126 
127 public:
128  typedef enum { grayImage, colorImage } vpImageType;
129  vpImageType typeImage;
130 
133  virtual void mainLoop();
134 
135 protected:
140 
141 public:
143  virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol);
145  void initExternalViewer(const unsigned int nlig, const unsigned int ncol);
146 
147 protected:
149  SbThread *mainThread;
150  // pthread_t mainThread;
151 
152 public:
154  void initApplication(void *(*start_routine)(void *));
155  void initApplication(void *(*start_routine)(void *), void *data);
157  void initMainApplication();
158  void closeMainApplication();
159 
160  //----------------------------------------------------
161  // scene description
162 protected:
163  unsigned int internal_width;
164  unsigned int internal_height;
165  unsigned int external_width;
166  unsigned int external_height;
167 
168 public:
174  unsigned int getInternalWidth() const { return internal_width; }
180  unsigned int getInternalHeight() const { return internal_height; }
181 
182 protected:
185  SoSeparator *scene;
187  SoSeparator *internalRoot;
189  SoSeparator *externalRoot;
190 
192  SoPerspectiveCamera *internalCamera;
194  SoPerspectiveCamera *externalCamera;
195 
198 
201 
203  SoSeparator *internalCameraObject;
204 
206  void initSceneGraph();
207 
209  void addObject(SoSeparator *object, const vpHomogeneousMatrix &fMo, SoSeparator *root);
210 
211 public:
213  void addObject(SoSeparator *newObject, const vpHomogeneousMatrix &fMo);
214 
215 public:
217  void redraw();
219  void load(const char *file_name);
221  void load(const char *iv_filename, const vpHomogeneousMatrix &fMo);
223  void save(const char *name, bool binary = false);
224 
226  void addAbsoluteFrame(float zoom = 1);
228  void addFrame(const vpHomogeneousMatrix &fMo, float zoom = 1);
230  void setZoomFactor(const float zoom);
231 
232 protected:
233  float zoomFactor;
234  //---------------------------------------------------
235  // camera description
236 protected:
244 
245 public:
247  void setCameraPosition(vpHomogeneousMatrix &cMf);
249  void getCameraPosition(vpHomogeneousMatrix &_cMf) { _cMf = cMf; }
251  void moveInternalCamera(vpHomogeneousMatrix &cMf);
253  void setInternalCameraParameters(vpCameraParameters &cam);
255  void setExternalCameraParameters(vpCameraParameters &cam);
257  void getExternalCameraPosition(vpHomogeneousMatrix &cMf);
258 
260  void getInternalImage(vpImage<unsigned char> &I);
262  void getInternalImage(vpImage<vpRGBa> &I);
263  /* --- Off screen rendering --- */
264 
265  void changeZoomFactor(const float zoom, const int index);
266 
267 public:
268  typedef enum { INTERNAL, EXTERNAL } vpSimulatorViewType;
269 #ifdef VISP_HAVE_MODULE_IO
270  void write(const char *fileName);
271 #endif
272 protected:
273  SbTime *realtime;
274  SoOffscreenRenderer *offScreenRenderer;
275  void offScreenRendering(vpSimulatorViewType view = vpSimulator::EXTERNAL, int *width = NULL, int *height = NULL);
276 
277 public:
279  unsigned char *bufferView;
280 
283  int get;
284 
285 public:
287  unsigned char *getBufferedOffScreenRenderer() { return bufferView; }
288 
290  void getSizeInternalView(int &width, int &height);
291 
293  void getCameraParameters(vpCameraParameters &cam) { cam = internalCameraParameters; }
294 };
295 
296 #endif
297 #endif
HWND mainWindow
main Widget
Definition: vpSimulator.h:115
SoSeparator * externalRoot
root node of the external view
Definition: vpSimulator.h:189
SoPerspectiveCamera * internalCamera
internal camera
Definition: vpSimulator.h:192
bool cameraPositionInitialized
Definition: vpSimulator.h:237
SoTransform * internalCameraPosition
internal camera position
Definition: vpSimulator.h:197
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:99
vpCameraParameters internalCameraParameters
internal camera parameters
Definition: vpSimulator.h:241
unsigned int getInternalHeight() const
Definition: vpSimulator.h:180
unsigned int external_height
Definition: vpSimulator.h:166
void getCameraParameters(vpCameraParameters &cam)
get the intrinsic parameters of the camera
Definition: vpSimulator.h:293
bool mainWindowInitialized
Definition: vpSimulator.h:122
vpViewer * internalView
view from the camera
Definition: vpSimulator.h:137
vpImageType typeImage
Definition: vpSimulator.h:129
SoSeparator * scene
Definition: vpSimulator.h:185
SoSeparator * internalRoot
root node of the internal view
Definition: vpSimulator.h:187
vpCameraParameters externalCameraParameters
internal camera parameters
Definition: vpSimulator.h:243
SbTime * realtime
Definition: vpSimulator.h:273
unsigned char * getBufferedOffScreenRenderer()
get the image corresponding to the internal view
Definition: vpSimulator.h:287
void getCameraPosition(vpHomogeneousMatrix &_cMf)
get the camera position (from an homogeneous matrix)
Definition: vpSimulator.h:249
SoTransform * extrenalCameraPosition
external camera position
Definition: vpSimulator.h:200
GLubyte * image_background
Definition: vpSimulator.h:131
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:139
SoPerspectiveCamera * externalCamera
external camera
Definition: vpSimulator.h:194
unsigned int external_width
Definition: vpSimulator.h:165
vpHomogeneousMatrix cMf
internal camera position
Definition: vpSimulator.h:239
unsigned char * bufferView
image of the internal view
Definition: vpSimulator.h:279
unsigned int internal_width
Definition: vpSimulator.h:163
unsigned int getInternalWidth() const
Definition: vpSimulator.h:174
SoOffscreenRenderer * offScreenRenderer
Definition: vpSimulator.h:274
unsigned int internal_height
Definition: vpSimulator.h:164
float zoomFactor
Definition: vpSimulator.h:233
SoSeparator * internalCameraObject
representation of the camera in the external view
Definition: vpSimulator.h:203
SbThread * mainThread
thread with the main program
Definition: vpSimulator.h:149