ArmarXSimulatorWindow.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 // Qt
27 #include <QActionGroup>
28 #include <QComboBox>
29 #include <QDialog>
30 #include <QDialogButtonBox>
31 #include <QDir>
32 #include <QDockWidget>
33 #include <QGridLayout>
34 #include <QHBoxLayout>
35 #include <QList>
36 #include <QListWidget>
37 #include <QMainWindow>
38 #include <QMdiArea>
39 #include <QModelIndex>
40 #include <QMutex>
41 #include <QPainter>
42 #include <QPlainTextEdit>
43 #include <QPluginLoader>
44 #include <QProxyStyle>
45 #include <QSignalMapper>
46 #include <QSplitter>
47 #include <QStackedWidget>
48 #include <QStringList>
49 #include <QVector3D>
50 
51 #ifdef foreach
52 #undef foreach
53 #endif
54 
55 // Coin3D & SoQt
56 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
57 #include <Inventor/nodes/SoNode.h>
58 #include <Inventor/nodes/SoSeparator.h>
59 
60 // ArmarX
64 
66 
68 
69 #include <ArmarXSimulation/applications/SimulatorViewer/ui_ArmarXSimulatorWindow.h>
71 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
72 
73 #include <SimDynamics/DynamicsEngine/BulletEngine/BulletEngine.h>
74 #include <SimDynamics/DynamicsEngine/DynamicsEngine.h>
75 #include <SimDynamics/DynamicsEngine/DynamicsObject.h>
76 #include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
77 #include <SimDynamics/DynamicsWorld.h>
78 
79 // project
80 namespace armarx
81 {
82 
83  class CoinViewer;
84 
85  /*!
86  * \class ArmarXSimulatorWindowPropertyDefinitions
87  * \brief
88  */
90  {
91  public:
94  {
95  defineOptionalProperty<bool>(
96  "ShowBaseCoordSystem",
97  false,
98  "Enable/disbale a coordinate visualization at the global root.");
99  defineOptionalProperty<int>("AntiAliasingRenderPasses",
100  4,
101  "If >0 anti aliasing is enabled (may slow down the "
102  "visualization). Defines the number of render passes.");
103 
104  defineOptionalProperty<float>(
105  "Camera.x", 0.f, "x component of initial camera position (mm)");
106  defineOptionalProperty<float>(
107  "Camera.y", 0.f, "y component of initial camera position (mm)");
108  defineOptionalProperty<float>(
109  "Camera.z", 0.f, "z component of initial camera position (mm)");
110  defineOptionalProperty<float>(
111  "Camera.roll", 0.f, "Initial camera pose: roll component of RPY angles (radian)");
112  defineOptionalProperty<float>(
113  "Camera.pitch", 0.f, "Initial camera pose: pitch component of RPY angles (radian)");
114  defineOptionalProperty<float>(
115  "Camera.yaw", 0.f, "Initial camera pose: yaw component of RPY angles (radian)");
116  defineOptionalProperty<std::string>(
117  "TempDir", "/tmp", "Local temp directory. Used for storing video files.");
118  defineOptionalProperty<bool>("SaveVideo",
119  false,
120  "Enable/disbale video recording (video is stored to tmp "
121  "directory, currently only BMP files are supported.");
122  defineOptionalProperty<float>(
123  "Background.r", 1.f, "r component of initial background color [0, 1]");
124  defineOptionalProperty<float>(
125  "Background.g", 1.f, "g component of initial background color [0, 1]");
126  defineOptionalProperty<float>(
127  "Background.b", 1.f, "b component of initial background color [0, 1]");
128  }
129  };
130 
132  public QMainWindow,
133  virtual public SimulatorViewerControlInterface,
134  virtual public Component
135  {
136  Q_OBJECT
137 
138  public:
140  ~ArmarXSimulatorWindow() override;
141 
142  // inherited from Component
143  std::string
144  getDefaultName() const override
145  {
146  return "ArmarXSimulatorWindow";
147  }
148 
149  void onInitComponent() override;
150  void onConnectComponent() override;
151  void onDisconnectComponent() override;
152  void onExitComponent() override;
153 
154  /**
155  * @see PropertyUser::createPropertyDefinitions()
156  */
159  {
160  return PropertyDefinitionsPtr(
162  }
163 
166 
167  /**
168  * emits the closeRequest signal
169  */
170  void closeEvent(QCloseEvent* event) override;
171 
172  // called by world (when its safe to access scene graph)
173  //void updateContacts(std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo> &c);
174 
176 
178 
179  SoNode* getScene();
180 
181  /*!
182  * \brief Protect access with this lock
183  * \return The lock that is automatically destructed when leaving the current scope.
184  */
186 
188 
189 
190  /* Inherited from SimulatorViewerControlInterface. */
191  void enableSimulatorWindow(bool show, const Ice::Current& c = Ice::emptyCurrent) override;
192  void showDebugDrawLayer(bool show, const Ice::Current& c = Ice::emptyCurrent) override;
193  void clearDebugDrawLayer(const Ice::Current& c = Ice::emptyCurrent) override;
194 
195  void clearLayer(const std::string& layerName,
196  const ::Ice::Current& = Ice::emptyCurrent) override;
197  void removeLayer(const std::string& layerName,
198  const ::Ice::Current& = Ice::emptyCurrent) override;
199  void enableLayerVisu(const std::string& layerName,
200  bool visible,
201  const ::Ice::Current& = Ice::emptyCurrent) override;
202  ::armarx::LayerInformationSequence
203  layerInformation(const ::Ice::Current& = Ice::emptyCurrent) override;
204 
205  void setTempPath(const std::string& p, const ::Ice::Current& = Ice::emptyCurrent) override;
206  void saveScreenshots(bool enable, const ::Ice::Current& = Ice::emptyCurrent) override;
207 
208 
209  //! Switch between full/collision model
210  void selectVisuType(bool fullModel, const Ice::Current& c = Ice::emptyCurrent) override;
211  void showBaseCoordSystem(bool show,
212  float scale = 1.0,
213  const Ice::Current& c = Ice::emptyCurrent) override;
214  //void showContacts(bool show, const Ice::Current& c = Ice::emptyCurrent);
215  SimulatorViewerInformation
216  getSimulatorInformation(const Ice::Current& c = Ice::emptyCurrent) override;
217 
218  void setAntiAliasing(int steps, const Ice::Current& c = Ice::emptyCurrent) override;
219 
220  PoseBasePtr getCameraPose(const Ice::Current& c = Ice::emptyCurrent) override;
221 
222  void setDrawTimeMeasured(float ms);
223 
224  void setCamPose(float x, float y, float z, float roll, float pitch, float yaw);
225  void setCamPoseFromConfig();
226 
227  public slots:
228  void slotEnableDebugDrawLayer(bool show);
230  void slotClearLayer(const QString layerName);
231  void slotRemoveLayer(const QString layerName);
232  void slotEnableLayerVisu(const QString layerName, bool visible);
233  void slotSelectVisuType(bool visible);
234 
235  void viewAll();
236 
237  // setup anti aliasing passes (0 == disable)
238  void setupAntiAliasing(int numPasses);
239 
240  void slotShowBaseCoord(bool show, float scale);
241 
242  signals:
243  /**
244  * emitted, when the main window should be closed
245  */
246  void closeRequest();
247 
248  protected:
249  Ui::MainWindowArmarXSimulator ui;
250 
252 
255 
256  void setupUI();
257 
258 
259  static void timerCB(void* data, SoSensor* sensor);
260  void saveScreenshot();
261 
262  SoSeparator* sceneSep;
263 
265 
266  armarx::SimulatorViewerInformation info;
267 
268  float drawTimeMS;
269 
270  bool saveVideo = false;
271  std::string tmpDir;
272 
273  private:
274  QString guiWindowBaseName;
275  };
276 
278 } // namespace armarx
DebugDrawerComponent.h
armarx::ArmarXSimulatorWindow::initialize
void initialize(ArmarXPhysicsWorldVisualizationPtr physicsVisu, DebugDrawerComponentPtr debugDrawer)
Definition: ArmarXSimulatorWindow.cpp:75
armarx::ArmarXSimulatorWindowPropertyDefinitions
Definition: ArmarXSimulatorWindow.h:89
armarx::ArmarXSimulatorWindow::sceneSep
SoSeparator * sceneSep
Definition: ArmarXSimulatorWindow.h:262
armarx::ArmarXSimulatorWindow::debugDrawer
DebugDrawerComponentPtr debugDrawer
Definition: ArmarXSimulatorWindow.h:254
armarx::ArmarXSimulatorWindow::drawTimeMS
float drawTimeMS
Definition: ArmarXSimulatorWindow.h:268
armarx::ArmarXSimulatorWindow::viewer
CoinViewer * viewer
Definition: ArmarXSimulatorWindow.h:251
armarx::ArmarXSimulatorWindow::setMutex
void setMutex(CoinViewer::RecursiveMutexPtr const &m)
Definition: ArmarXSimulatorWindow.cpp:367
armarx::ArmarXSimulatorWindow::slotSelectVisuType
void slotSelectVisuType(bool visible)
Definition: ArmarXSimulatorWindow.cpp:604
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::ArmarXSimulatorWindow::layerInformation
::armarx::LayerInformationSequence layerInformation(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:571
armarx::ArmarXSimulatorWindow::setTempPath
void setTempPath(const std::string &p, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:582
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::ArmarXSimulatorWindow::physicsVisu
ArmarXPhysicsWorldVisualizationPtr physicsVisu
Definition: ArmarXSimulatorWindow.h:253
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::ArmarXSimulatorWindow::slotClearDebugDrawLayer
void slotClearDebugDrawLayer()
Definition: ArmarXSimulatorWindow.cpp:484
armarx::ArmarXSimulatorWindow::enableLayerVisu
void enableLayerVisu(const std::string &layerName, bool visible, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:527
RunningTask.h
armarx::ArmarXSimulatorWindow::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ArmarXSimulatorWindow.cpp:138
armarx::ArmarXSimulatorWindow::saveScreenshots
void saveScreenshots(bool enable, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:588
armarx::ArmarXSimulatorWindow::ui
Ui::MainWindowArmarXSimulator ui
Definition: ArmarXSimulatorWindow.h:249
armarx::ArmarXSimulatorWindow::setCamPose
void setCamPose(float x, float y, float z, float roll, float pitch, float yaw)
Definition: ArmarXSimulatorWindow.cpp:332
armarx::ArmarXSimulatorWindow::slotShowBaseCoord
void slotShowBaseCoord(bool show, float scale)
Definition: ArmarXSimulatorWindow.cpp:259
armarx::ArmarXSimulatorWindow::closeRequest
void closeRequest()
emitted, when the main window should be closed
IceInternal::Handle< ArmarXPhysicsWorldVisualization >
armarx::ArmarXSimulatorWindowPropertyDefinitions::ArmarXSimulatorWindowPropertyDefinitions
ArmarXSimulatorWindowPropertyDefinitions(std::string prefix)
Definition: ArmarXSimulatorWindow.h:92
armarx::ArmarXSimulatorWindow::slotEnableDebugDrawLayer
void slotEnableDebugDrawLayer(bool show)
Definition: ArmarXSimulatorWindow.cpp:268
armarx::ArmarXSimulatorWindow::mutex
CoinViewer::RecursiveMutexPtr mutex
Definition: ArmarXSimulatorWindow.h:264
armarx::ArmarXSimulatorWindow::setAntiAliasing
void setAntiAliasing(int steps, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:449
ArmarXPhysicsWorldVisualization.h
armarx::ArmarXSimulatorWindow::setupUI
void setupUI()
Definition: ArmarXSimulatorWindow.cpp:148
armarx::ArmarXSimulatorWindow::showBaseCoordSystem
void showBaseCoordSystem(bool show, float scale=1.0, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:410
armarx::CoinViewer
Definition: CoinViewer.h:38
armarx::ArmarXSimulatorWindow::saveVideo
bool saveVideo
Definition: ArmarXSimulatorWindow.h:270
armarx::ArmarXSimulatorWindow::getViewer
CoinViewer * getViewer()
Definition: ArmarXSimulatorWindow.cpp:355
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::ArmarXSimulatorWindow::clearLayer
void clearLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:504
armarx::ArmarXSimulatorWindow::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ArmarXSimulatorWindow.cpp:123
armarx::ArmarXSimulatorWindow::showDebugDrawLayer
void showDebugDrawLayer(bool show, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:474
armarx::ArmarXSimulatorWindow::viewAll
void viewAll()
Definition: ArmarXSimulatorWindow.cpp:286
armarx::CoinViewer::RecursiveMutexPtr
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
Definition: CoinViewer.h:51
armarx::ArmarXSimulatorWindow::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ArmarXSimulatorWindow.cpp:143
armarx::ArmarXSimulatorWindow::removeLayer
void removeLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:515
armarx::ArmarXSimulatorWindow::ArmarXSimulatorWindow
ArmarXSimulatorWindow()
Definition: ArmarXSimulatorWindow.cpp:69
armarx::ArmarXSimulatorWindow::saveScreenshot
void saveScreenshot()
Definition: ArmarXSimulatorWindow.cpp:209
armarx::ArmarXSimulatorWindow::~ArmarXSimulatorWindow
~ArmarXSimulatorWindow() override
Definition: ArmarXSimulatorWindow.cpp:182
armarx::ArmarXSimulatorWindow::slotEnableLayerVisu
void slotEnableLayerVisu(const QString layerName, bool visible)
Definition: ArmarXSimulatorWindow.cpp:562
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ArmarXSimulatorWindow::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ArmarXSimulatorWindow.h:144
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::ArmarXSimulatorWindow::setCamPoseFromConfig
void setCamPoseFromConfig()
Definition: ArmarXSimulatorWindow.cpp:111
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::ArmarXSimulatorWindow::getSimulatorInformation
SimulatorViewerInformation getSimulatorInformation(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:423
armarx::ArmarXSimulatorWindow::slotClearLayer
void slotClearLayer(const QString layerName)
Definition: ArmarXSimulatorWindow.cpp:544
armarx::ArmarXSimulatorWindow::getCamPose
Eigen::Matrix4f getCamPose()
Definition: ArmarXSimulatorWindow.cpp:306
armarx::ArmarXSimulatorWindow::enableSimulatorWindow
void enableSimulatorWindow(bool show, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:385
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::ArmarXSimulatorWindow::setDrawTimeMeasured
void setDrawTimeMeasured(float ms)
Definition: ArmarXSimulatorWindow.cpp:443
armarx::ArmarXSimulatorWindow::getScopedLock
CoinViewer::RecursiveMutexLockPtr getScopedLock()
Protect access with this lock.
Definition: ArmarXSimulatorWindow.cpp:378
armarx::ArmarXSimulatorWindow::tmpDir
std::string tmpDir
Definition: ArmarXSimulatorWindow.h:271
armarx::ArmarXSimulatorWindow::clearDebugDrawLayer
void clearDebugDrawLayer(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:495
armarx::ArmarXSimulatorWindow::timerCB
static void timerCB(void *data, SoSensor *sensor)
Definition: ArmarXSimulatorWindow.cpp:200
armarx::ArmarXSimulatorWindow::selectVisuType
void selectVisuType(bool fullModel, const Ice::Current &c=Ice::emptyCurrent) override
Switch between full/collision model.
Definition: ArmarXSimulatorWindow.cpp:594
armarx::CoinViewer::RecursiveMutexLockPtr
std::shared_ptr< RecursiveMutexLock > RecursiveMutexLockPtr
Definition: CoinViewer.h:53
armarx::ArmarXSimulatorWindow::slotRemoveLayer
void slotRemoveLayer(const QString layerName)
Definition: ArmarXSimulatorWindow.cpp:553
Logging.h
armarx::ArmarXSimulatorWindow::getScene
SoNode * getScene()
Definition: ArmarXSimulatorWindow.cpp:361
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::ArmarXSimulatorWindow
Definition: ArmarXSimulatorWindow.h:131
armarx::ArmarXSimulatorWindow::closeEvent
void closeEvent(QCloseEvent *event) override
emits the closeRequest signal
Definition: ArmarXSimulatorWindow.cpp:193
armarx::ArmarXSimulatorWindow::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: ArmarXSimulatorWindow.cpp:106
CoinViewer.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ArmarXSimulatorWindow::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArmarXSimulatorWindow.h:158
armarx::ArmarXSimulatorWindow::setupAntiAliasing
void setupAntiAliasing(int numPasses)
Definition: ArmarXSimulatorWindow.cpp:247
Application.h
armarx::ArmarXSimulatorWindow::getCameraPose
PoseBasePtr getCameraPose(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:465
armarx::ArmarXSimulatorWindow::info
armarx::SimulatorViewerInformation info
Definition: ArmarXSimulatorWindow.h:266