Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpSimulator.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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 * Anthony Saunier
36 *
37*****************************************************************************/
38
39#ifndef vpSimulator_HH
40#define vpSimulator_HH
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/SoOffscreenRenderer.h>
63#include <Inventor/fields/SoSFTime.h>
64#include <Inventor/nodes/SoBaseColor.h>
65#include <Inventor/nodes/SoCone.h>
66#include <Inventor/nodes/SoCube.h>
67#include <Inventor/nodes/SoImage.h>
68#include <Inventor/nodes/SoLightModel.h>
69#include <Inventor/nodes/SoPerspectiveCamera.h>
70#include <Inventor/nodes/SoRotationXYZ.h>
71#include <Inventor/nodes/SoSeparator.h>
72#include <Inventor/nodes/SoTransform.h>
73#include <Inventor/nodes/SoTranslation.h>
74#include <Inventor/sensors/SoTimerSensor.h>
75#include <Inventor/threads/SbThread.h>
76
77// visp
78#include <visp3/core/vpCameraParameters.h>
79#include <visp3/core/vpDebug.h>
80#include <visp3/core/vpHomogeneousMatrix.h>
81#include <visp3/core/vpImage.h>
82#include <visp3/core/vpImageConvert.h>
83#include <visp3/core/vpRGBa.h>
84
97
98class VISP_EXPORT vpSimulator
99{
100protected:
102 void init();
104 void kill();
105
106public:
108 vpSimulator();
109 virtual ~vpSimulator();
110
111protected:
113#if defined(VISP_HAVE_SOWIN)
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
126public:
127 typedef enum { grayImage, colorImage } vpImageType;
129
132 virtual void mainLoop();
133
134protected:
139
140public:
142 virtual void initInternalViewer(unsigned int nlig, unsigned int ncol);
144 void initExternalViewer(unsigned int nlig, unsigned int ncol);
145
146protected:
148 SbThread *mainThread;
149 // pthread_t mainThread;
150
151public:
153 void initApplication(void *(*start_routine)(void *));
154 void initApplication(void *(*start_routine)(void *), void *data);
156 void initMainApplication();
158
159 //----------------------------------------------------
160 // scene description
161protected:
162 unsigned int internal_width;
163 unsigned int internal_height;
164 unsigned int external_width;
165 unsigned int external_height;
166
167public:
173 unsigned int getInternalWidth() const { return internal_width; }
179 unsigned int getInternalHeight() const { return internal_height; }
180
181protected:
184 SoSeparator *scene;
186 SoSeparator *internalRoot;
188 SoSeparator *externalRoot;
189
191 SoPerspectiveCamera *internalCamera;
193 SoPerspectiveCamera *externalCamera;
194
197
200
203
205 void initSceneGraph();
206
208 void addObject(SoSeparator *object, const vpHomogeneousMatrix &fMo, SoSeparator *root);
209
210public:
212 void addObject(SoSeparator *newObject, const vpHomogeneousMatrix &fMo);
213
214public:
216 void redraw();
218 void load(const char *file_name);
220 void load(const char *iv_filename, const vpHomogeneousMatrix &fMo);
222 void save(const char *name, bool binary = false);
223
225 void addAbsoluteFrame(float zoom = 1);
227 void addFrame(const vpHomogeneousMatrix &fMo, float zoom = 1);
229 void setZoomFactor(float zoom);
230
231protected:
233 //---------------------------------------------------
234 // camera description
235protected:
243
244public:
250 void moveInternalCamera(vpHomogeneousMatrix &cMf);
252 void setInternalCameraParameters(vpCameraParameters &cam);
254 void setExternalCameraParameters(vpCameraParameters &cam);
256 void getExternalCameraPosition(vpHomogeneousMatrix &cMf);
257
259 void getInternalImage(vpImage<unsigned char> &I);
261 void getInternalImage(vpImage<vpRGBa> &I);
262 /* --- Off screen rendering --- */
263
264 void changeZoomFactor(float zoom, int index);
265
266public:
267 typedef enum { INTERNAL, EXTERNAL } vpSimulatorViewType;
268#ifdef VISP_HAVE_MODULE_IO
269 void write(const char *fileName);
270#endif
271protected:
272 SbTime *realtime;
273 SoOffscreenRenderer *offScreenRenderer;
274 void offScreenRendering(vpSimulatorViewType view = vpSimulator::EXTERNAL, int *width = NULL, int *height = NULL);
275
276public:
278 unsigned char *bufferView;
279
282 int get;
283
284public:
286 unsigned char *getBufferedOffScreenRenderer() { return bufferView; }
287
289 void getSizeInternalView(int &width, int &height);
290
293};
294
295#endif
296#endif
Generic class defining intrinsic camera parameters.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getInternalWidth() const
SoPerspectiveCamera * internalCamera
internal camera
void save(const char *name, bool binary=false)
save the scene in an iv file
unsigned int internal_height
GLubyte * image_background
vpCameraParameters internalCameraParameters
internal camera parameters
void load(const char *file_name)
load an iv file
unsigned char * bufferView
image of the internal view
SoTransform * extrenalCameraPosition
external camera position
void addFrame(const vpHomogeneousMatrix &fMo, float zoom=1)
Add the representation of a frame.
void kill()
perform some destruction
float zoomFactor
virtual void mainLoop()
activate the mainloop
void getCameraParameters(vpCameraParameters &cam)
get the intrinsic parameters of the camera
unsigned int external_height
unsigned int internal_width
void initMainApplication()
perform some initialization in the main program thread
bool cameraPositionInitialized
void initSoApplication()
open the SoGui application
vpImageType typeImage
void redraw()
display the scene (handle with care)
void initApplication(void *(*start_routine)(void *))
begin the main program
vpViewer * internalView
view from the camera
void init()
perform some initialization
vpHomogeneousMatrix cMf
internal camera position
SoSeparator * internalCameraObject
representation of the camera in the external view
SoSeparator * scene
void getCameraPosition(vpHomogeneousMatrix &_cMf)
get the camera position (from an homogeneous matrix)
SbThread * mainThread
thread with the main program
vpViewer * externalView
view from an external camera
void setZoomFactor(float zoom)
set the size of the camera/frame
SoPerspectiveCamera * externalCamera
external camera
void setCameraPosition(vpHomogeneousMatrix &cMf)
set the camera position (from an homogeneous matrix)
HWND mainWindow
main Widget
void initExternalViewer(unsigned int nlig, unsigned int ncol)
initialize the external view
SoSeparator * externalRoot
root node of the external view
unsigned int getInternalHeight() const
virtual void initInternalViewer(unsigned int nlig, unsigned int ncol)
initialize the camera view
bool mainWindowInitialized
void addObject(SoSeparator *object, const vpHomogeneousMatrix &fMo, SoSeparator *root)
Add a new object in the scene graph ad a given location.
vpCameraParameters externalCameraParameters
internal camera parameters
vpSimulator()
constructor
void initSceneGraph()
initialize the scene graph
SoOffscreenRenderer * offScreenRenderer
unsigned char * getBufferedOffScreenRenderer()
get the image corresponding to the internal view
SoTransform * internalCameraPosition
internal camera position
SoSeparator * internalRoot
root node of the internal view
void closeMainApplication()
SbTime * realtime
void addAbsoluteFrame(float zoom=1)
Add the representation of the absolute frame.
unsigned int external_width
void offScreenRendering(vpSimulatorViewType view=vpSimulator::EXTERNAL, int *width=NULL, int *height=NULL)
Viewer used by the simulator.
Definition vpViewer.h:120