38 #include <QFileDialog>
41 #include <QInputDialog>
44 #include <QMessageBox>
45 #include <QPushButton>
47 #include <QToolButton>
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"
63 #define TIMER_MS 30.0f
67 using namespace SimDynamics;
70 QMainWindow(NULL), viewer(nullptr), sceneSep(nullptr)
80 setWindowTitle(guiWindowBaseName);
84 setAttribute(Qt::WA_QuitOnClose);
113 float x = getProperty<float>(
"Camera.x").getValue();
114 float y = getProperty<float>(
"Camera.y").getValue();
115 float z = getProperty<float>(
"Camera.z").getValue();
116 float ro = getProperty<float>(
"Camera.roll").getValue();
117 float pi = getProperty<float>(
"Camera.pitch").getValue();
118 float ya = getProperty<float>(
"Camera.yaw").getValue();
127 bool showBase = getProperty<bool>(
"ShowBaseCoordSystem").getValue();
130 int alias = getProperty<int>(
"AntiAliasingRenderPasses").getValue();
133 saveVideo = getProperty<bool>(
"SaveVideo").getValue();
134 tmpDir = getProperty<std::string>(
"TempDir").getValue();
155 SoQtExaminerViewer::BUILD_POPUP,
156 SoQtExaminerViewer::BROWSER);
160 viewer->setBackgroundColor(SbColor{getProperty<float>(
"Background.r").getValue(),
161 getProperty<float>(
"Background.g").getValue(),
162 getProperty<float>(
"Background.b").getValue()});
164 int numPasses = getProperty<int>(
"AntiAliasingRenderPasses").getValue();
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());
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));
422 armarx::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)))