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 <QMainWindow>
28 #include <QDir>
29 #include <QList>
30 #include <QStringList>
31 #include <QPluginLoader>
32 #include <QDialog>
33 #include <QComboBox>
34 #include <QGridLayout>
35 #include <QStackedWidget>
36 #include <QSplitter>
37 #include <QPlainTextEdit>
38 #include <QMdiArea>
39 #include <QMutex>
40 #include <QSignalMapper>
41 #include <QActionGroup>
42 #include <QModelIndex>
43 #include <QListWidget>
44 #include <QDockWidget>
45 #include <QHBoxLayout>
46 #include <QDialogButtonBox>
47 #include <QProxyStyle>
48 #include <QPainter>
49 #include <QVector3D>
50 
51 #ifdef foreach
52 #undef foreach
53 #endif
54 
55 // Coin3D & SoQt
56 #include <Inventor/nodes/SoNode.h>
57 #include <Inventor/nodes/SoSeparator.h>
58 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
59 
60 // ArmarX
64 
66 
67 #include <SimDynamics/DynamicsEngine/DynamicsEngine.h>
68 #include <SimDynamics/DynamicsWorld.h>
69 #include <SimDynamics/DynamicsEngine/BulletEngine/BulletEngine.h>
70 #include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
71 #include <SimDynamics/DynamicsEngine/DynamicsObject.h>
72 
75 
76 #include <ArmarXSimulation/applications/SimulatorViewer/ui_ArmarXSimulatorWindow.h>
77 
78 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
79 
80 
81 // project
82 namespace armarx
83 {
84 
85  class CoinViewer;
86 
87 
88  /*!
89  * \class ArmarXSimulatorWindowPropertyDefinitions
90  * \brief
91  */
94  {
95  public:
98  {
99  defineOptionalProperty<bool>("ShowBaseCoordSystem", false, "Enable/disbale a coordinate visualization at the global root.");
100  defineOptionalProperty<int>("AntiAliasingRenderPasses", 4, "If >0 anti aliasing is enabled (may slow down the visualization). Defines the number of render passes.");
101 
102  defineOptionalProperty<float>("Camera.x", 0.f, "x component of initial camera position (mm)");
103  defineOptionalProperty<float>("Camera.y", 0.f, "y component of initial camera position (mm)");
104  defineOptionalProperty<float>("Camera.z", 0.f, "z component of initial camera position (mm)");
105  defineOptionalProperty<float>("Camera.roll", 0.f, "Initial camera pose: roll component of RPY angles (radian)");
106  defineOptionalProperty<float>("Camera.pitch", 0.f, "Initial camera pose: pitch component of RPY angles (radian)");
107  defineOptionalProperty<float>("Camera.yaw", 0.f, "Initial camera pose: yaw component of RPY angles (radian)");
108  defineOptionalProperty<std::string>("TempDir", "/tmp", "Local temp directory. Used for storing video files.");
109  defineOptionalProperty<bool>("SaveVideo", false, "Enable/disbale video recording (video is stored to tmp directory, currently only BMP files are supported.");
110  defineOptionalProperty<float>("Background.r", 1.f, "r component of initial background color [0, 1]");
111  defineOptionalProperty<float>("Background.g", 1.f, "g component of initial background color [0, 1]");
112  defineOptionalProperty<float>("Background.b", 1.f, "b component of initial background color [0, 1]");
113  }
114  };
115 
116 
117 
119  public QMainWindow,
120  virtual public SimulatorViewerControlInterface,
121  virtual public Component
122  {
123  Q_OBJECT
124 
125  public:
127  ~ArmarXSimulatorWindow() override;
128 
129  // inherited from Component
130  std::string getDefaultName() const override
131  {
132  return "ArmarXSimulatorWindow";
133  }
134  void onInitComponent() override;
135  void onConnectComponent() override;
136  void onDisconnectComponent() override;
137  void onExitComponent() override;
138 
139  /**
140  * @see PropertyUser::createPropertyDefinitions()
141  */
143  {
146  }
147 
148 
150 
151  /**
152  * emits the closeRequest signal
153  */
154  void closeEvent(QCloseEvent* event) override;
155 
156  // called by world (when its safe to access scene graph)
157  //void updateContacts(std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo> &c);
158 
160 
162 
163  SoNode* getScene();
164 
165  /*!
166  * \brief Protect access with this lock
167  * \return The lock that is automatically destructed when leaving the current scope.
168  */
170 
172 
173 
174 
175 
176  /* Inherited from SimulatorViewerControlInterface. */
177  void enableSimulatorWindow(bool show, const Ice::Current& c = Ice::emptyCurrent) override;
178  void showDebugDrawLayer(bool show, const Ice::Current& c = Ice::emptyCurrent) override;
179  void clearDebugDrawLayer(const Ice::Current& c = Ice::emptyCurrent) override;
180 
181  void clearLayer(const std::string& layerName, const ::Ice::Current& = Ice::emptyCurrent) override;
182  void removeLayer(const std::string& layerName, const ::Ice::Current& = Ice::emptyCurrent) override;
183  void enableLayerVisu(const std::string& layerName, bool visible, const ::Ice::Current& = Ice::emptyCurrent) override;
184  ::armarx::LayerInformationSequence layerInformation(const ::Ice::Current& = Ice::emptyCurrent) override;
185 
186  void setTempPath(const std::string& p, const ::Ice::Current& = Ice::emptyCurrent) override;
187  void saveScreenshots(bool enable, const ::Ice::Current& = Ice::emptyCurrent) override;
188 
189 
190  //! Switch between full/collision model
191  void selectVisuType(bool fullModel, const Ice::Current& c = Ice::emptyCurrent) override;
192  void showBaseCoordSystem(bool show, float scale = 1.0, const Ice::Current& c = Ice::emptyCurrent) override;
193  //void showContacts(bool show, const Ice::Current& c = Ice::emptyCurrent);
194  SimulatorViewerInformation getSimulatorInformation(const Ice::Current& c = Ice::emptyCurrent) override;
195 
196  void setAntiAliasing(int steps, const Ice::Current& c = Ice::emptyCurrent) override;
197 
198  PoseBasePtr getCameraPose(const Ice::Current& c = Ice::emptyCurrent) override;
199 
200  void setDrawTimeMeasured(float ms);
201 
202  void setCamPose(float x, float y, float z, float roll, float pitch, float yaw);
203  void setCamPoseFromConfig();
204 
205  public slots:
206  void slotEnableDebugDrawLayer(bool show);
208  void slotClearLayer(const QString layerName);
209  void slotRemoveLayer(const QString layerName);
210  void slotEnableLayerVisu(const QString layerName, bool visible);
211  void slotSelectVisuType(bool visible);
212 
213  void viewAll();
214 
215  // setup anti aliasing passes (0 == disable)
216  void setupAntiAliasing(int numPasses);
217 
218  void slotShowBaseCoord(bool show, float scale);
219 
220  signals:
221  /**
222  * emitted, when the main window should be closed
223  */
224  void closeRequest();
225 
226  protected:
227  Ui::MainWindowArmarXSimulator ui;
228 
230 
233 
234  void setupUI();
235 
236 
237  static void timerCB(void* data, SoSensor* sensor);
238  void saveScreenshot();
239 
240  SoSeparator* sceneSep;
241 
243 
244  armarx::SimulatorViewerInformation info;
245 
246  float drawTimeMS;
247 
248  bool saveVideo = false;
249  std::string tmpDir;
250 
251  private:
252  QString guiWindowBaseName;
253  };
254 
255 
257 }
DebugDrawerComponent.h
armarx::ArmarXSimulatorWindow::initialize
void initialize(ArmarXPhysicsWorldVisualizationPtr physicsVisu, DebugDrawerComponentPtr debugDrawer)
Definition: ArmarXSimulatorWindow.cpp:77
armarx::ArmarXSimulatorWindowPropertyDefinitions
Definition: ArmarXSimulatorWindow.h:92
armarx::ArmarXSimulatorWindow::sceneSep
SoSeparator * sceneSep
Definition: ArmarXSimulatorWindow.h:240
armarx::ArmarXSimulatorWindow::debugDrawer
DebugDrawerComponentPtr debugDrawer
Definition: ArmarXSimulatorWindow.h:232
armarx::ArmarXSimulatorWindow::drawTimeMS
float drawTimeMS
Definition: ArmarXSimulatorWindow.h:246
armarx::ArmarXSimulatorWindow::viewer
CoinViewer * viewer
Definition: ArmarXSimulatorWindow.h:229
armarx::ArmarXSimulatorWindow::setMutex
void setMutex(CoinViewer::RecursiveMutexPtr const &m)
Definition: ArmarXSimulatorWindow.cpp:356
armarx::ArmarXSimulatorWindow::slotSelectVisuType
void slotSelectVisuType(bool visible)
Definition: ArmarXSimulatorWindow.cpp:563
armarx::ArmarXSimulatorWindow::layerInformation
::armarx::LayerInformationSequence layerInformation(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:535
armarx::ArmarXSimulatorWindow::setTempPath
void setTempPath(const std::string &p, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:545
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::ArmarXSimulatorWindow::physicsVisu
ArmarXPhysicsWorldVisualizationPtr physicsVisu
Definition: ArmarXSimulatorWindow.h:231
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ArmarXSimulatorWindow::slotClearDebugDrawLayer
void slotClearDebugDrawLayer()
Definition: ArmarXSimulatorWindow.cpp:461
armarx::ArmarXSimulatorWindow::enableLayerVisu
void enableLayerVisu(const std::string &layerName, bool visible, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:500
RunningTask.h
armarx::ArmarXSimulatorWindow::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ArmarXSimulatorWindow.cpp:136
armarx::ArmarXSimulatorWindow::saveScreenshots
void saveScreenshots(bool enable, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:550
armarx::ArmarXSimulatorWindow::ui
Ui::MainWindowArmarXSimulator ui
Definition: ArmarXSimulatorWindow.h:227
armarx::ArmarXSimulatorWindow::setCamPose
void setCamPose(float x, float y, float z, float roll, float pitch, float yaw)
Definition: ArmarXSimulatorWindow.cpp:325
armarx::ArmarXSimulatorWindow::slotShowBaseCoord
void slotShowBaseCoord(bool show, float scale)
Definition: ArmarXSimulatorWindow.cpp:254
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:96
armarx::ArmarXSimulatorWindow::slotEnableDebugDrawLayer
void slotEnableDebugDrawLayer(bool show)
Definition: ArmarXSimulatorWindow.cpp:263
armarx::ArmarXSimulatorWindow::mutex
CoinViewer::RecursiveMutexPtr mutex
Definition: ArmarXSimulatorWindow.h:242
armarx::ArmarXSimulatorWindow::setAntiAliasing
void setAntiAliasing(int steps, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:430
ArmarXPhysicsWorldVisualization.h
armarx::ArmarXSimulatorWindow::setupUI
void setupUI()
Definition: ArmarXSimulatorWindow.cpp:144
armarx::ArmarXSimulatorWindow::showBaseCoordSystem
void showBaseCoordSystem(bool show, float scale=1.0, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:396
armarx::CoinViewer
Definition: CoinViewer.h:38
armarx::ArmarXSimulatorWindow::saveVideo
bool saveVideo
Definition: ArmarXSimulatorWindow.h:248
armarx::ArmarXSimulatorWindow::getViewer
CoinViewer * getViewer()
Definition: ArmarXSimulatorWindow.cpp:346
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:480
armarx::ArmarXSimulatorWindow::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ArmarXSimulatorWindow.cpp:121
armarx::ArmarXSimulatorWindow::showDebugDrawLayer
void showDebugDrawLayer(bool show, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:453
armarx::ArmarXSimulatorWindow::viewAll
void viewAll()
Definition: ArmarXSimulatorWindow.cpp:280
armarx::CoinViewer::RecursiveMutexPtr
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
Definition: CoinViewer.h:52
armarx::ArmarXSimulatorWindow::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ArmarXSimulatorWindow.cpp:140
armarx::ArmarXSimulatorWindow::removeLayer
void removeLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:490
armarx::ArmarXSimulatorWindow::ArmarXSimulatorWindow
ArmarXSimulatorWindow()
Definition: ArmarXSimulatorWindow.cpp:69
armarx::ArmarXSimulatorWindow::saveScreenshot
void saveScreenshot()
Definition: ArmarXSimulatorWindow.cpp:206
armarx::ArmarXSimulatorWindow::~ArmarXSimulatorWindow
~ArmarXSimulatorWindow() override
Definition: ArmarXSimulatorWindow.cpp:180
armarx::ArmarXSimulatorWindow::slotEnableLayerVisu
void slotEnableLayerVisu(const QString layerName, bool visible)
Definition: ArmarXSimulatorWindow.cpp:526
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::ArmarXSimulatorWindow::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ArmarXSimulatorWindow.h:130
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ArmarXSimulatorWindow::setCamPoseFromConfig
void setCamPoseFromConfig()
Definition: ArmarXSimulatorWindow.cpp:110
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::ArmarXSimulatorWindow::getSimulatorInformation
SimulatorViewerInformation getSimulatorInformation(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:406
armarx::ArmarXSimulatorWindow::slotClearLayer
void slotClearLayer(const QString layerName)
Definition: ArmarXSimulatorWindow.cpp:510
armarx::ArmarXSimulatorWindow::getCamPose
Eigen::Matrix4f getCamPose()
Definition: ArmarXSimulatorWindow.cpp:299
armarx::ArmarXSimulatorWindow::enableSimulatorWindow
void enableSimulatorWindow(bool show, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:374
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ArmarXSimulatorWindow::setDrawTimeMeasured
void setDrawTimeMeasured(float ms)
Definition: ArmarXSimulatorWindow.cpp:425
armarx::ArmarXSimulatorWindow::getScopedLock
CoinViewer::RecursiveMutexLockPtr getScopedLock()
Protect access with this lock.
Definition: ArmarXSimulatorWindow.cpp:366
armarx::ArmarXSimulatorWindow::tmpDir
std::string tmpDir
Definition: ArmarXSimulatorWindow.h:249
armarx::ArmarXSimulatorWindow::clearDebugDrawLayer
void clearDebugDrawLayer(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:471
armarx::ArmarXSimulatorWindow::timerCB
static void timerCB(void *data, SoSensor *sensor)
Definition: ArmarXSimulatorWindow.cpp:198
armarx::ArmarXSimulatorWindow::selectVisuType
void selectVisuType(bool fullModel, const Ice::Current &c=Ice::emptyCurrent) override
Switch between full/collision model.
Definition: ArmarXSimulatorWindow.cpp:555
armarx::CoinViewer::RecursiveMutexLockPtr
std::shared_ptr< RecursiveMutexLock > RecursiveMutexLockPtr
Definition: CoinViewer.h:54
armarx::ArmarXSimulatorWindow::slotRemoveLayer
void slotRemoveLayer(const QString layerName)
Definition: ArmarXSimulatorWindow.cpp:518
Logging.h
armarx::ArmarXSimulatorWindow::getScene
SoNode * getScene()
Definition: ArmarXSimulatorWindow.cpp:351
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ArmarXSimulatorWindow
Definition: ArmarXSimulatorWindow.h:118
armarx::ArmarXSimulatorWindow::closeEvent
void closeEvent(QCloseEvent *event) override
emits the closeRequest signal
Definition: ArmarXSimulatorWindow.cpp:191
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:28
armarx::ArmarXSimulatorWindow::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArmarXSimulatorWindow.h:142
armarx::ArmarXSimulatorWindow::setupAntiAliasing
void setupAntiAliasing(int numPasses)
Definition: ArmarXSimulatorWindow.cpp:243
Application.h
armarx::ArmarXSimulatorWindow::getCameraPose
PoseBasePtr getCameraPose(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXSimulatorWindow.cpp:445
armarx::ArmarXSimulatorWindow::info
armarx::SimulatorViewerInformation info
Definition: ArmarXSimulatorWindow.h:244