Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpSimulator.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
34#ifndef VP_SIMULATOR_H
35#define VP_SIMULATOR_H
44#include <visp3/core/vpConfig.h>
45
46#ifdef VISP_HAVE_COIN3D_AND_GUI
47
48#include <visp3/ar/vpViewer.h>
49
50/* KNOWN ISSUE DEALING WITH X11 and QT
51 If you get a strange compiler error on the line with None,
52 it's probably because you're also including X11 headers,
53 which #define the symbol None. Put the X11 includes after
54 the Qt includes to solve this problem.
55 */
56
57#include <Inventor/SoOffscreenRenderer.h>
58#include <Inventor/fields/SoSFTime.h>
59#include <Inventor/nodes/SoBaseColor.h>
60#include <Inventor/nodes/SoCone.h>
61#include <Inventor/nodes/SoCube.h>
62#include <Inventor/nodes/SoImage.h>
63#include <Inventor/nodes/SoLightModel.h>
64#include <Inventor/nodes/SoPerspectiveCamera.h>
65#include <Inventor/nodes/SoRotationXYZ.h>
66#include <Inventor/nodes/SoSeparator.h>
67#include <Inventor/nodes/SoTransform.h>
68#include <Inventor/nodes/SoTranslation.h>
69#include <Inventor/sensors/SoTimerSensor.h>
70#include <Inventor/threads/SbThread.h>
71
72// visp
73#include <visp3/core/vpCameraParameters.h>
74#include <visp3/core/vpDebug.h>
75#include <visp3/core/vpHomogeneousMatrix.h>
76#include <visp3/core/vpImage.h>
77#include <visp3/core/vpImageConvert.h>
78#include <visp3/core/vpRGBa.h>
79
93
94class VISP_EXPORT vpSimulator
95{
96protected:
98 void init();
100 void kill();
101
102public:
104 vpSimulator();
105 virtual ~vpSimulator();
106
107protected:
109#if defined(VISP_HAVE_SOWIN)
111#elif defined(VISP_HAVE_SOQT)
112 QWidget *mainWindow;
113#elif defined(VISP_HAVE_SOXT)
114 Widget mainWindow;
115#endif
116
118
120 void initSoApplication();
121
122public:
123 typedef enum { grayImage, colorImage } vpImageType;
125
128 virtual void mainLoop();
129
130protected:
135
136public:
138 virtual void initInternalViewer(unsigned int nlig, unsigned int ncol);
140 void initExternalViewer(unsigned int nlig, unsigned int ncol);
141
142protected:
144 SbThread *mainThread;
145 // pthread_t mainThread;
146
147public:
149 void initApplication(void *(*start_routine)(void *));
150 void initApplication(void *(*start_routine)(void *), void *data);
152 void initMainApplication();
154
155 //----------------------------------------------------
156 // scene description
157protected:
158 unsigned int internal_width;
159 unsigned int internal_height;
160 unsigned int external_width;
161 unsigned int external_height;
162
163public:
169 unsigned int getInternalWidth() const { return internal_width; }
175 unsigned int getInternalHeight() const { return internal_height; }
176
177protected:
180 SoSeparator *scene;
182 SoSeparator *internalRoot;
184 SoSeparator *externalRoot;
185
187 SoPerspectiveCamera *internalCamera;
189 SoPerspectiveCamera *externalCamera;
190
193
196
199
201 void initSceneGraph();
202
204 void addObject(SoSeparator *object, const vpHomogeneousMatrix &fMo, SoSeparator *root);
205
206public:
208 void addObject(SoSeparator *newObject, const vpHomogeneousMatrix &fMo);
209
210public:
212 void redraw();
214 void load(const char *file_name);
216 void load(const char *iv_filename, const vpHomogeneousMatrix &fMo);
218 void save(const char *name, bool binary = false);
219
221 void addAbsoluteFrame(float zoom = 1);
223 void addFrame(const vpHomogeneousMatrix &fMo, float zoom = 1);
225 void setZoomFactor(float zoom);
226
227protected:
229 //---------------------------------------------------
230 // camera description
231protected:
239
240public:
246 void moveInternalCamera(vpHomogeneousMatrix &cMf);
248 void setInternalCameraParameters(vpCameraParameters &cam);
250 void setExternalCameraParameters(vpCameraParameters &cam);
252 void getExternalCameraPosition(vpHomogeneousMatrix &cMf);
253
255 void getInternalImage(vpImage<unsigned char> &I);
257 void getInternalImage(vpImage<vpRGBa> &I);
258 /* --- Off screen rendering --- */
259
260 void changeZoomFactor(float zoom, int index);
261
262public:
263 typedef enum { INTERNAL, EXTERNAL } vpSimulatorViewType;
264#ifdef VISP_HAVE_MODULE_IO
265 void write(const char *fileName);
266#endif
267protected:
268 SbTime *realtime;
269 SoOffscreenRenderer *offScreenRenderer;
270 void offScreenRendering(vpSimulatorViewType view = vpSimulator::EXTERNAL, int *width = nullptr, int *height = nullptr);
271
272public:
274 unsigned char *bufferView;
275
278 int get;
279
280public:
282 unsigned char *getBufferedOffScreenRenderer() { return bufferView; }
283
285 void getSizeInternalView(int &width, int &height);
286
289};
290END_VISP_NAMESPACE
291#endif
292#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:131
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 offScreenRendering(vpSimulatorViewType view=vpSimulator::EXTERNAL, int *width=nullptr, int *height=nullptr)
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
Viewer used by the simulator.
Definition vpViewer.h:120