Visual Servoing Platform  version 3.3.0
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)
115  HWND mainWindow;
116 #elif defined(VISP_HAVE_SOQT)
117  QWidget *mainWindow;
118 #elif defined(VISP_HAVE_SOXT)
119  Widget mainWindow;
120 #endif
121 
122  bool mainWindowInitialized;
123 
125  void initSoApplication();
126 
127 public:
128  typedef enum { grayImage, colorImage } vpImageType;
129  vpImageType typeImage;
130 
131  GLubyte *image_background;
133  virtual void mainLoop();
134 
135 protected:
137  vpViewer *internalView;
139  vpViewer *externalView;
140 
141 public:
143  virtual void initInternalViewer(unsigned int nlig, unsigned int ncol);
145  void initExternalViewer(unsigned int nlig, 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 
197  SoTransform *internalCameraPosition;
198 
200  SoTransform *extrenalCameraPosition;
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(float zoom);
231 
232 protected:
233  float zoomFactor;
234  //---------------------------------------------------
235  // camera description
236 protected:
237  bool cameraPositionInitialized;
241  vpCameraParameters internalCameraParameters;
243  vpCameraParameters externalCameraParameters;
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(float zoom, 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
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition: vpCameraParameters.h:232
vpSimulator::EXTERNAL
Definition: vpSimulator.h:267
vpImage< unsigned char >
vpSimulator
Implementation of a simulator based on Coin3d (www.coin3d.org).
Definition: vpSimulator.h:98
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition: vpHomogeneousMatrix.h:148
vpSimulator::vpSimulatorViewType
vpSimulatorViewType
Definition: vpSimulator.h:267
vpViewer
Viewer used by the simulator.
Definition: vpViewer.h:116