41#include <QInputDialog>
48#include <QtCore/QDirIterator>
50#include <VirtualRobot/MathTools.h>
51#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
52#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
53#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h>
55#include <Inventor/actions/SoBoxHighlightRenderAction.h>
56#include <Inventor/nodes/SoCamera.h>
57#include <Inventor/nodes/SoUnits.h>
58#include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
60#define ARMARX_GUI_APPLICATION_NAME "ArmarXSimulator"
67using namespace SimDynamics;
79 guiWindowBaseName = ARMARX_GUI_APPLICATION_NAME;
80 setWindowTitle(guiWindowBaseName);
81 setTag(ARMARX_GUI_APPLICATION_NAME);
84 setAttribute(Qt::WA_QuitOnClose);
155 SoQtExaminerViewer::BUILD_POPUP,
156 SoQtExaminerViewer::BROWSER);
165 viewer->setAccumulationBuffer(numPasses > 0);
168 viewer->setGLRenderAction(
new SoBoxHighlightRenderAction);
169 viewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
170 viewer->setFeedbackVisibility(
true);
176 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
177 SoTimerSensor* timer =
new SoTimerSensor(
timerCB,
this);
178 timer->setInterval(SbTime(
TIMER_MS / 1000.0f));
179 sensor_mgr->insertTimerSensor(timer);
216 static long counter = 0;
217 clock_t start = clock();
220 std::stringstream ss;
221 ss <<
tmpDir <<
"/armarx-render-frame-" << counter <<
".bmp";
222 std::string fn = ss.str();
226 viewer->getSceneManager()->render();
229 QGLWidget* w = (QGLWidget*)
viewer->getGLWidget();
231 QImage i = w->grabFrameBuffer();
232 QString fnQ(fn.c_str());
233 bool res = i.save(fnQ,
"BMP");
240 clock_t end = clock();
241 float timeMS = (
float)(end - start) / (
float)CLOCKS_PER_SEC * 1000.0f;
253 viewer->setAccumulationBuffer(numPasses > 0);
254 viewer->setAntialiasing((numPasses > 0), numPasses);
296 SoCamera* cam =
viewer->getCamera();
297 SoSeparator* sceneViewableSep =
physicsVisu->getViewableScene();
299 if (cam && sceneViewableSep)
301 cam->viewAll(sceneViewableSep,
viewer->getViewportRegion());
309 Eigen::Matrix4f camPose = Eigen::Matrix4f::Identity();
313 SbVec3f position =
viewer->getCamera()->position.getValue();
314 SbRotation orientation =
viewer->getCamera()->orientation.getValue();
317 orientation.getValue(rotAxis,
angle);
322 camPose = MathTools::axisangle2eigen4f(axE,
angle);
323 camPose(0, 3) = position[0];
324 camPose(1, 3) = position[1];
325 camPose(2, 3) = position[2];
340 SbVec3f position(
x * 0.001f, y * 0.001f, z * 0.001f);
341 SbRotation orientation;
343 MathTools::rpy2eigen4f(roll, pitch, yaw, m);
346 MathTools::eigen4f2axisangle(m, ax, ang);
347 SbVec3f ax2(ax(0), ax(1), ax(2));
348 orientation.setValue(ax2, ang);
349 viewer->getCamera()->position.setValue(position);
350 viewer->getCamera()->orientation.setValue(orientation);
389 info.windowEnabled = show;
395 QMetaObject::invokeMethod(
404 QMetaObject::invokeMethod(
this,
"hide");
412 QMetaObject::invokeMethod(
413 this,
"slotShowBaseCoord", Qt::QueuedConnection, Q_ARG(
bool, show), Q_ARG(
float, scale));
422armarx::SimulatorViewerInformation
457 if (!QMetaObject::invokeMethod(
458 this,
"setupAntiAliasing", Qt::QueuedConnection, Q_ARG(
int, steps)))
476 if (!QMetaObject::invokeMethod(
477 this,
"slotEnableDebugDrawLayer", Qt::QueuedConnection, Q_ARG(
bool, show)))
497 if (!QMetaObject::invokeMethod(
this,
"slotClearDebugDrawLayer", Qt::QueuedConnection))
506 QString s(layerName.c_str());
508 if (!QMetaObject::invokeMethod(
this,
"slotClearLayer", Qt::QueuedConnection, Q_ARG(QString, s)))
517 QString s(layerName.c_str());
519 if (!QMetaObject::invokeMethod(
520 this,
"slotRemoveLayer", Qt::QueuedConnection, Q_ARG(QString, s)))
529 const ::Ice::Current&)
531 QString s(layerName.c_str());
533 if (!QMetaObject::invokeMethod(
this,
534 "slotEnableLayerVisu",
535 Qt::QueuedConnection,
537 Q_ARG(
bool, visible)))
566 debugDrawer->enableLayerVisu(layerName.toStdString(), visible);
570::armarx::LayerInformationSequence
578 return ::armarx::LayerInformationSequence{};
596 if (!QMetaObject::invokeMethod(
597 this,
"slotSelectVisuType", Qt::QueuedConnection, Q_ARG(
bool, fullModel)))
void onInitComponent() override
Pure virtual hook for the subclass.
void showDebugDrawLayer(bool show, const Ice::Current &c=Ice::emptyCurrent) override
PoseBasePtr getCameraPose(const Ice::Current &c=Ice::emptyCurrent) override
void setAntiAliasing(int steps, const Ice::Current &c=Ice::emptyCurrent) override
void slotClearDebugDrawLayer()
void setDrawTimeMeasured(float ms)
void slotShowBaseCoord(bool show, float scale)
void saveScreenshots(bool enable, const ::Ice::Current &=Ice::emptyCurrent) override
void enableLayerVisu(const std::string &layerName, bool visible, const ::Ice::Current &=Ice::emptyCurrent) override
void initialize(ArmarXPhysicsWorldVisualizationPtr physicsVisu, DebugDrawerComponentPtr debugDrawer)
void slotEnableDebugDrawLayer(bool show)
armarx::SimulatorViewerInformation info
void onDisconnectComponent() override
Hook for subclass.
void setMutex(CoinViewer::RecursiveMutexPtr const &m)
::armarx::LayerInformationSequence layerInformation(const ::Ice::Current &=Ice::emptyCurrent) override
DebugDrawerComponentPtr debugDrawer
void closeRequest()
emitted, when the main window should be closed
void closeEvent(QCloseEvent *event) override
emits the closeRequest signal
void slotClearLayer(const QString layerName)
void setupAntiAliasing(int numPasses)
void setCamPoseFromConfig()
void setCamPose(float x, float y, float z, float roll, float pitch, float yaw)
CoinViewer::RecursiveMutexLockPtr getScopedLock()
Protect access with this lock.
void slotSelectVisuType(bool visible)
void onConnectComponent() override
Pure virtual hook for the subclass.
~ArmarXSimulatorWindow() override
CoinViewer::RecursiveMutexPtr mutex
void selectVisuType(bool fullModel, const Ice::Current &c=Ice::emptyCurrent) override
Switch between full/collision model.
void clearDebugDrawLayer(const Ice::Current &c=Ice::emptyCurrent) override
void slotRemoveLayer(const QString layerName)
Eigen::Matrix4f getCamPose()
void clearLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
void setTempPath(const std::string &p, const ::Ice::Current &=Ice::emptyCurrent) override
void slotEnableLayerVisu(const QString layerName, bool visible)
void enableSimulatorWindow(bool show, const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
Hook for subclass.
void removeLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Ui::MainWindowArmarXSimulator ui
void showBaseCoordSystem(bool show, float scale=1.0, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorViewerInformation getSimulatorInformation(const Ice::Current &c=Ice::emptyCurrent) override
ArmarXPhysicsWorldVisualizationPtr physicsVisu
static void timerCB(void *data, SoSensor *sensor)
std::shared_ptr< RecursiveMutexLock > RecursiveMutexLockPtr
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
std::unique_lock< RecursiveMutex > RecursiveMutexLock
Property< PropertyType > getProperty(const std::string &name)
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void setTag(const LogTag &tag)
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Pose > PosePtr
IceInternal::Handle< DebugDrawerComponent > DebugDrawerComponentPtr
IceInternal::Handle< ArmarXPhysicsWorldVisualization > ArmarXPhysicsWorldVisualizationPtr
const LogSender::manipulator flush
double angle(const Point &a, const Point &b, const Point &c)