ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
vpSimulator.h
1 /****************************************************************************
2  *
3  * $Id: vpSimulator.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  *
34  * Description:
35  * Simulator based on Coin3d.
36  *
37  * Authors:
38  * Eric Marchand
39  * Anthony Saunier
40  *
41  *****************************************************************************/
42 
43 #ifndef vpSimulator_HH
44 #define vpSimulator_HH
45 
53 #include <visp/vpConfig.h>
54 
55 #ifdef VISP_HAVE_COIN_AND_GUI
56 
57 #include <visp/vpViewer.h>
58 
59 /* KNOWN ISSUE DEALING WITH X11 and QT
60  If you get a strange compiler error on the line with None,
61  it's probably because you're also including X11 headers,
62  which #define the symbol None. Put the X11 includes after
63  the Qt includes to solve this problem.
64  */
65 
66 #include <Inventor/nodes/SoBaseColor.h>
67 #include <Inventor/nodes/SoTransform.h>
68 #include <Inventor/nodes/SoCone.h>
69 #include <Inventor/nodes/SoCube.h>
70 #include <Inventor/nodes/SoImage.h>
71 #include <Inventor/nodes/SoLightModel.h>
72 #include <Inventor/nodes/SoPerspectiveCamera.h>
73 #include <Inventor/nodes/SoRotationXYZ.h>
74 #include <Inventor/nodes/SoSeparator.h>
75 #include <Inventor/nodes/SoTranslation.h>
76 #include <Inventor/sensors/SoTimerSensor.h>
77 #include <Inventor/SoOffscreenRenderer.h>
78 #include <Inventor/fields/SoSFTime.h>
79 #include <Inventor/threads/SbThread.h>
80 
81 // visp
82 #include <visp/vpDebug.h>
83 #include <visp/vpHomogeneousMatrix.h>
84 #include <visp/vpCameraParameters.h>
85 #include <visp/vpImage.h>
86 #include <visp/vpRGBa.h>
87 #include <visp/vpImageConvert.h>
88 
102 class VISP_EXPORT vpSimulator
103 {
104 protected:
106  void init() ;
108  void kill() ;
109 
110 public:
112  vpSimulator() ;
113  virtual ~vpSimulator() ;
114 
115 protected:
117 #if defined(VISP_HAVE_SOWIN)
118  HWND mainWindow ;
119 #elif defined(VISP_HAVE_SOQT)
120  QWidget * mainWindow ;
121 #elif defined(VISP_HAVE_SOXT)
122  Widget mainWindow ;
123 #endif
124 
126 
128  void initSoApplication() ;
129 
130 public:
131  typedef enum {
133  colorImage
134  } vpImageType ;
136 
137  GLubyte * image_background;
139  virtual void mainLoop() ;
140 
141 protected:
146 
147 public:
149  virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol) ;
151  void initExternalViewer(const unsigned int nlig, const unsigned int ncol) ;
152 
153 protected:
155  SbThread * mainThread;
156  //pthread_t mainThread;
157 
158 public:
160  void initApplication(void *(*start_routine)(void *)) ;
161  void initApplication(void *(*start_routine)(void *), void* data);
163  void initMainApplication() ;
164  void closeMainApplication() ;
165 
166  //----------------------------------------------------
167  // scene description
168 protected:
169  unsigned int internal_width;
170  unsigned int internal_height;
171  unsigned int external_width;
172  unsigned int external_height;
173 
174 public:
180  unsigned int getInternalWidth() const { return internal_width; }
186  unsigned int getInternalHeight() const { return internal_height; }
187 
188 protected:
191  SoSeparator *scene;
193  SoSeparator *internalRoot;
195  SoSeparator *externalRoot;
196 
198  SoPerspectiveCamera *internalCamera ;
200  SoPerspectiveCamera *externalCamera ;
201 
203  SoTransform *internalCameraPosition ;
204 
206  SoTransform *extrenalCameraPosition ;
207 
209  SoSeparator *internalCameraObject;
210 
212  void initSceneGraph() ;
213 
215  void addObject(SoSeparator * object, const vpHomogeneousMatrix &fMo,
216  SoSeparator * root) ;
217 
218 public :
220  void addObject(SoSeparator * newObject, const vpHomogeneousMatrix &fMo) ;
221 
222 public:
224  void redraw() ;
226  void load(const char *file_name) ;
228  void load(const char *iv_filename,const vpHomogeneousMatrix &fMo) ;
230  void save(const char *name,bool binary=false) ;
231 
233  void addAbsoluteFrame (float zoom=1) ;
235  void addFrame (const vpHomogeneousMatrix &fMo, float zoom=1) ;
237  void setZoomFactor (const float zoom) ;
238 
239 protected:
240  float zoomFactor ;
241  //---------------------------------------------------
242  // camera description
243 protected:
251 
252 public:
254  void setCameraPosition(vpHomogeneousMatrix &cMf) ;
256  void getCameraPosition(vpHomogeneousMatrix &_cMf) { _cMf = cMf ; }
258  void moveInternalCamera(vpHomogeneousMatrix &cMf) ;
260  void setInternalCameraParameters(vpCameraParameters &cam) ;
262  void setExternalCameraParameters(vpCameraParameters &cam) ;
264  void getExternalCameraPosition(vpHomogeneousMatrix &cMf) ;
265 
267  void getInternalImage(vpImage<unsigned char> &I) ;
269  void getInternalImage(vpImage<vpRGBa> &I) ;
270  /* --- Off screen rendering --- */
271 
272  void changeZoomFactor(const float zoom, const int index);
273 public:
274  typedef enum { INTERNAL, EXTERNAL } vpSimulatorViewType ;
275  void write(const char * fileName);
276 protected:
277  SbTime * realtime ;
278  SoOffscreenRenderer * offScreenRenderer ;
279  void offScreenRendering (vpSimulatorViewType view=vpSimulator::EXTERNAL,
280  int * width = NULL,
281  int * height = NULL);
282 public:
284  unsigned char * bufferView;
285 
287  int get ;
288 public:
291  {
292  return bufferView;
293  }
294 
296  void getSizeInternalView(int& width, int& height);
297 
300  {
301  cam = internalCameraParameters;
302  }
303 } ;
304 
305 
306 #endif
307 #endif