Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00877_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00877_source.php on line 2
The ARGoS Website

qtopengl_render.cpp
Go to the documentation of this file.
1 
7 #include "qtopengl_render.h"
8 #include "qtopengl_application.h"
9 
10 #include <argos3/core/utility/logging/argos_log.h>
11 #include <argos3/core/utility/string_utilities.h>
12 #include <cstring>
13 
14 #include <QPixmap>
15 #include <QSplashScreen>
16 
17 namespace argos {
18 
19  /****************************************/
20  /****************************************/
21 
23  /* Parse options from the XML */
24 #ifdef ARGOS_WITH_LUA
25  GetNodeAttributeOrDefault(t_tree, "lua_editor", m_bLuaEditor, m_bLuaEditor);
26 #endif
27  /* Save the configuration for later */
28  m_tConfTree = t_tree;
29  /* Set up dummy arguments for QApplication */
30  m_nOptionNum = 1;
31  m_ppcOptions = new char*[m_nOptionNum];
32  m_ppcOptions[0] = new char[7];
33  ::strcpy(m_ppcOptions[0], "argos3");
34  /* Create the QT application */
35  m_pcApplication = new CQTOpenGLApplication(m_nOptionNum, m_ppcOptions);
36  /* Set some data about the application */
37  m_pcApplication->setApplicationName("ARGoS");
38  m_pcApplication->setApplicationVersion("3.0");
39  m_pcApplication->setOrganizationName("ARGoS");
40  m_pcApplication->setOrganizationDomain("argos-sim.info");
41  /* Draw the main window */
42  m_pcMainWindow = new CQTOpenGLMainWindow(m_tConfTree);
43 #ifdef ARGOS_WITH_LUA
44  /* Create Lua editor if required */
45  if(m_bLuaEditor) {
46  m_pcQTOpenGLLuaMainWindow = new CQTOpenGLLuaMainWindow(m_pcMainWindow);
47  }
48 #endif
49  LOG.Flush();
50  LOGERR.Flush();
51  }
52 
53  /****************************************/
54  /****************************************/
55 
57  try {
58  /* This effectively starts the experiment */
59  m_pcMainWindow->show();
60 #ifdef ARGOS_WITH_LUA
61  if(m_bLuaEditor) {
62  m_pcQTOpenGLLuaMainWindow->show();
63  }
64 #endif
65  m_pcApplication->exec();
66  }
67  catch(CARGoSException& ex) {
68  THROW_ARGOSEXCEPTION_NESTED("Error while executing the experiment.", ex);
69  }
70  }
71 
72  /****************************************/
73  /****************************************/
74 
76 #ifdef ARGOS_WITH_LUA
77  /* Destroy the Lua editor */
78  if(m_bLuaEditor) {
79  delete m_pcQTOpenGLLuaMainWindow;
80  }
81 #endif
82  /* Destroy the main window */
83  delete m_pcMainWindow;
84  /* Destroy the QT application */
85  delete m_pcApplication;
86  /* Get rid of the factory */
88  }
89 
90  /****************************************/
91  /****************************************/
92 
94  if(m_pcMainWindow == NULL) {
95  THROW_ARGOSEXCEPTION("CQTOpenGLRender::GetMainWindow(): no main window created");
96  }
97  return *m_pcMainWindow;
98  }
99 
100  /****************************************/
101  /****************************************/
102 
103 #ifdef ARGOS_WITH_LUA
104  CQTOpenGLLuaMainWindow& CQTOpenGLRender::GetLuaMainWindow() {
105  if(m_pcQTOpenGLLuaMainWindow == NULL) {
106  THROW_ARGOSEXCEPTION("CQTOpenGLRender::GetLuaMainWindow(): no Lua main window created");
107  }
108  return *m_pcQTOpenGLLuaMainWindow;
109  }
110 #endif
111 
112  /****************************************/
113  /****************************************/
114 
115  REGISTER_VISUALIZATION(CQTOpenGLRender,
116  "qt-opengl",
117  "Carlo Pinciroli [ilpincy@gmail.com]",
118  "1.0",
119  "An interactive graphical renderer based on QT and OpenGL.",
120  "The QT-OpenGL renderer is a graphical renderer based on QT >= 4.5 and OpenGL.\n"
121  "It allows the user to watch and modify the simulation as it's running in an\n"
122  "intuitive way.\n\n"
123  "REQUIRED XML CONFIGURATION\n\n"
124  " <visualization>\n"
125  " <qt-opengl />\n"
126  " </visualization>\n\n"
127  "OPTIONAL XML CONFIGURATION\n\n"
128  "You can auto-play the simulation at startup by specifying the 'autoplay'\n"
129  "attribute as follows:\n\n"
130  " <visualization>\n"
131  " <qt-opengl autoplay=\"true\" />\n"
132  " </visualization>\n\n"
133  "It is also possible to set some camera parameters. There are 10 available\n"
134  "cameras to use. You can switch from one to the other by clicking on the\n"
135  "graphical view (to give it focus) and then pressing the keys 0-9.\n"
136  "To configure position and orientation of specific cameras, say cameras 0 to 3,\n"
137  "you have to include the following XML code:\n\n"
138  " <visualization>\n"
139  " <qt-opengl>\n"
140  " <camera>\n"
141  " <placement idx=\"0\" position=\"2,2,2\" look_at=\"1,1,1\" />\n"
142  " <placement idx=\"1\" position=\"1,0,7\" look_at=\"1,0,0\" />\n"
143  " <placement idx=\"2\" position=\"3,3,4\" look_at=\"1,6,0\" />\n"
144  " <placement idx=\"3\" position=\"2,3,2\" look_at=\"0,1,0\" />\n"
145  " </camera>\n"
146  " </qt-opengl>\n"
147  " </visualization>\n\n"
148  "The 'idx' attribute specifies the camera index (and the key to press to switch\n"
149  "to that camera).\n"
150  "The 'position' attribute contains the position of the camera in the arena.\n"
151  "The 'look_at' attribute sets the point the camera is looking at.\n"
152  "Sometimes, specifying a camera positioning with only 'position' and 'look_at'\n"
153  "generates ambiguous configurations, which ARGoS resolves in a default way after\n"
154  "printing a warning message. To place the camera without ambiguities, specify\n"
155  "also the 'up' vector of the camera. If the camera is your head, imagine this\n"
156  "vector as an arrow that stems from the center of your head and extends upwards\n."
157  "The 'up' vector must be perpendicular to the difference between the 'look_at'\n"
158  "and the 'position' vectors."
159  "You can set some optical parameters of real cameras, namely the focal length\n"
160  "and the length of the frame diagonal. For example:\n\n"
161  " <visualization>\n"
162  " <qt-opengl>\n"
163  " <camera>\n"
164  " ...\n"
165  " <placement idx=\"4\"\n"
166  " position=\"4,1,4\"\n"
167  " look_at=\"2,1,0\"\n"
168  " lens_focal_length=\"50\"\n"
169  " frame_diagonal=\"40\" />\n"
170  " ...\n"
171  " </camera>\n"
172  " </qt-opengl>\n"
173  " </visualization>\n\n"
174  "The 'lens_focal_length' attribute controls the focal length of the lens of the\n"
175  "simulated camera. The value is in millimeters and it defaults, if not set in\n"
176  "XML, to 20mm.\n"
177  "The 'frame_diagonal' attribute specifies the length of the frame diagonal of\n"
178  "the image film. The value is in millimeters and it defaults, if not set in\n"
179  "XML, to 35mm.\n"
180  "This visualization also allows for user customization. In a similar fashion to\n"
181  "the loop functions, you can set a plug-in that derives from the\n"
182  "CQTOpenGLUserFunctions class. To load it in the system, follow this example:\n\n"
183  " <visualization>\n"
184  " <qt-opengl>\n"
185  " <user_functions library=\"/path/to/libmyuserfunctions.so\"\n"
186  " label=\"my_user_functions\" />\n"
187  " </qt-opengl>\n"
188  " </visualization>\n\n"
189  "The 'library' attribute points to the library where the user functions are\n"
190  "stored. This library can be the same as the loop functions, or a new one.\n"
191  "There is no limitation to where the code is to be found.\n"
192  "The 'label' attribute identifies the user function class to use. In this way,\n"
193  "in a single library you can have multiple user function implementations, if\n"
194  "you wish.\n"
195  "You can also grab frames and store them into image files, for example to create\n"
196  "videos in a fast way. To do it, you just need to press the red capture button\n"
197  "and frame grabbing will be on. By default, the frames are named\n"
198  "'frame_NNNNN.png' and are stored in the current directory, i.e. the directory\n"
199  "where you run the 'argos' command. If you want to override this behavior, you\n"
200  "can add the optional 'frame_grabbing' section as follows:\n\n"
201  " <visualization>\n"
202  " <qt-opengl>\n"
203  " <frame_grabbing directory=\"frames\"\n"
204  " base_name=\"myframe_\"\n"
205  " format=\"png\"\n"
206  " quality=\"100\" />\n"
207  " </qt-opengl>\n"
208  " </visualization>\n\n"
209  "All the attributes in this section are optional. If you don't specify one of\n"
210  "them, the default is taken.\n"
211  "The 'directory' attribute stores the directory where the frames are saved. If\n"
212  "the directory does not exist, a fatal error occurs. The directory must exist\n"
213  "and be writable. Both absolute and relative paths are allowed. The default\n"
214  "value is '.'\n"
215  "The 'base_name' attribute is the string to prepend to the file name. After this\n"
216  "string, the frame number (padded to 5 digits) is added. The default value is\n"
217  "'frame_', so a typical resulting name is 'frame_00165'.\n"
218  "The 'format' attribute specifies the format. The default value is 'png' but you\n"
219  "can put any format supported by Qt>=4.5. Refer to the Qt documentation for the\n"
220  "complete list of supported formats.\n"
221  "The 'quality' attribute dictates the quality of the image. Its value is in the\n"
222  "range [0:100] where 0 means maximum compression and minimum quality, and 100\n"
223  "means maximum quality and no compression at all. The default value is '-1',\n"
224  "which means to use Qt's default quality. For videos, it's best to use 100 to\n"
225  "avoid artifacts due to compression. For a normal screenshot, the default is the\n"
226  "safest choice.\n",
227  "Usable"
228  );
229 
230 }
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
CQTOpenGLMainWindow & GetMainWindow()
static void Destroy()
Frees up all used memory.
Definition: factory_impl.h:85
CARGoSLog LOG(std::cout, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_GREEN))
Definition: argos_log.h:179
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception...
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
Definition: argos_log.h:180
The exception that wraps all errors in ARGoS.
virtual void Destroy()
Undoes whatever was done by Init().
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
REGISTER_VISUALIZATION(CQTOpenGLRender,"qt-opengl","Carlo Pinciroli [ilpincy@gmail.com]","1.0","An interactive graphical renderer based on QT and OpenGL.","The QT-OpenGL renderer is a graphical renderer based on QT >= 4.5 and OpenGL.\n""It allows the user to watch and modify the simulation as it's running in an\n""intuitive way.\n\n""REQUIRED XML CONFIGURATION\n\n"" <visualization>\n"" <qt-opengl />\n"" </visualization>\n\n""OPTIONAL XML CONFIGURATION\n\n""You can auto-play the simulation at startup by specifying the 'autoplay'\n""attribute as follows:\n\n"" <visualization>\n"" <qt-opengl autoplay=\"true\" />\n"" </visualization>\n\n""It is also possible to set some camera parameters. There are 10 available\n""cameras to use. You can switch from one to the other by clicking on the\n""graphical view (to give it focus) and then pressing the keys 0-9.\n""To configure position and orientation of specific cameras, say cameras 0 to 3,\n""you have to include the following XML code:\n\n"" <visualization>\n"" <qt-opengl>\n"" <camera>\n"" <placement idx=\"0\" position=\"2,2,2\" look_at=\"1,1,1\" />\n"" <placement idx=\"1\" position=\"1,0,7\" look_at=\"1,0,0\" />\n"" <placement idx=\"2\" position=\"3,3,4\" look_at=\"1,6,0\" />\n"" <placement idx=\"3\" position=\"2,3,2\" look_at=\"0,1,0\" />\n"" </camera>\n"" </qt-opengl>\n"" </visualization>\n\n""The 'idx' attribute specifies the camera index (and the key to press to switch\n""to that camera).\n""The 'position' attribute contains the position of the camera in the arena.\n""The 'look_at' attribute sets the point the camera is looking at.\n""Sometimes, specifying a camera positioning with only 'position' and 'look_at'\n""generates ambiguous configurations, which ARGoS resolves in a default way after\n""printing a warning message. To place the camera without ambiguities, specify\n""also the 'up' vector of the camera. If the camera is your head, imagine this\n""vector as an arrow that stems from the center of your head and extends upwards\n.""The 'up' vector must be perpendicular to the difference between the 'look_at'\n""and the 'position' vectors.""You can set some optical parameters of real cameras, namely the focal length\n""and the length of the frame diagonal. For example:\n\n"" <visualization>\n"" <qt-opengl>\n"" <camera>\n"" ...\n"" <placement idx=\"4\"\n"" position=\"4,1,4\"\n"" look_at=\"2,1,0\"\n"" lens_focal_length=\"50\"\n"" frame_diagonal=\"40\" />\n"" ...\n"" </camera>\n"" </qt-opengl>\n"" </visualization>\n\n""The 'lens_focal_length' attribute controls the focal length of the lens of the\n""simulated camera. The value is in millimeters and it defaults, if not set in\n""XML, to 20mm.\n""The 'frame_diagonal' attribute specifies the length of the frame diagonal of\n""the image film. The value is in millimeters and it defaults, if not set in\n""XML, to 35mm.\n""This visualization also allows for user customization. In a similar fashion to\n""the loop functions, you can set a plug-in that derives from the\n""CQTOpenGLUserFunctions class. To load it in the system, follow this example:\n\n"" <visualization>\n"" <qt-opengl>\n"" <user_functions library=\"/path/to/libmyuserfunctions.so\"\n"" label=\"my_user_functions\" />\n"" </qt-opengl>\n"" </visualization>\n\n""The 'library' attribute points to the library where the user functions are\n""stored. This library can be the same as the loop functions, or a new one.\n""There is no limitation to where the code is to be found.\n""The 'label' attribute identifies the user function class to use. In this way,\n""in a single library you can have multiple user function implementations, if\n""you wish.\n""You can also grab frames and store them into image files, for example to create\n""videos in a fast way. To do it, you just need to press the red capture button\n""and frame grabbing will be on. By default, the frames are named\n""'frame_NNNNN.png' and are stored in the current directory, i.e. the directory\n""where you run the 'argos' command. If you want to override this behavior, you\n""can add the optional 'frame_grabbing' section as follows:\n\n"" <visualization>\n"" <qt-opengl>\n"" <frame_grabbing directory=\"frames\"\n"" base_name=\"myframe_\"\n"" format=\"png\"\n"" quality=\"100\" />\n"" </qt-opengl>\n"" </visualization>\n\n""All the attributes in this section are optional. If you don't specify one of\n""them, the default is taken.\n""The 'directory' attribute stores the directory where the frames are saved. If\n""the directory does not exist, a fatal error occurs. The directory must exist\n""and be writable. Both absolute and relative paths are allowed. The default\n""value is '.'\n""The 'base_name' attribute is the string to prepend to the file name. After this\n""string, the frame number (padded to 5 digits) is added. The default value is\n""'frame_', so a typical resulting name is 'frame_00165'.\n""The 'format' attribute specifies the format. The default value is 'png' but you\n""can put any format supported by Qt>=4.5. Refer to the Qt documentation for the\n""complete list of supported formats.\n""The 'quality' attribute dictates the quality of the image. Its value is in the\n""range [0:100] where 0 means maximum compression and minimum quality, and 100\n""means maximum quality and no compression at all. The default value is '-1',\n""which means to use Qt's default quality. For videos, it's best to use 100 to\n""avoid artifacts due to compression. For a normal screenshot, the default is the\n""safest choice.\n","Usable")