33 #include <QtCore/QDirIterator>
34 #include <QFileDialog>
37 #include <QInputDialog>
38 #include <QPushButton>
41 #include <QToolButton>
48 #include <QMessageBox>
52 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
53 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h>
54 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
55 #include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
57 #include <Inventor/actions/SoBoxHighlightRenderAction.h>
58 #include <Inventor/nodes/SoUnits.h>
60 #define ARMARX_GUI_APPLICATION_NAME "ArmarXSimulator"
63 #define TIMER_MS 30.0f
67 using namespace SimDynamics;
81 setWindowTitle(guiWindowBaseName);
85 setAttribute(Qt::WA_QuitOnClose);
112 float x = getProperty<float>(
"Camera.x").getValue();
113 float y = getProperty<float>(
"Camera.y").getValue();
114 float z = getProperty<float>(
"Camera.z").getValue();
115 float ro = getProperty<float>(
"Camera.roll").getValue();
116 float pi = getProperty<float>(
"Camera.pitch").getValue();
117 float ya = getProperty<float>(
"Camera.yaw").getValue();
125 bool showBase = getProperty<bool>(
"ShowBaseCoordSystem").getValue();
128 int alias = getProperty<int>(
"AntiAliasingRenderPasses").getValue();
131 saveVideo = getProperty<bool>(
"SaveVideo").getValue();
132 tmpDir = getProperty<std::string>(
"TempDir").getValue();
148 viewer =
new CoinViewer(
ui.frameViewer,
"ArmarXSimulator", TRUE, SoQtExaminerViewer::BUILD_POPUP, SoQtExaminerViewer::BROWSER);
152 viewer->setBackgroundColor(
155 getProperty<float>(
"Background.r").getValue(),
156 getProperty<float>(
"Background.g").getValue(),
157 getProperty<float>(
"Background.b").getValue()
161 int numPasses = getProperty<int>(
"AntiAliasingRenderPasses").getValue();
162 viewer->setAccumulationBuffer(numPasses > 0);
165 viewer->setGLRenderAction(
new SoBoxHighlightRenderAction);
166 viewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
167 viewer->setFeedbackVisibility(
true);
173 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
174 SoTimerSensor* timer =
new SoTimerSensor(
timerCB,
this);
175 timer->setInterval(SbTime(
TIMER_MS / 1000.0f));
176 sensor_mgr->insertTimerSensor(timer);
213 static long counter = 0;
214 clock_t start = clock();
217 std::stringstream ss;
218 ss <<
tmpDir <<
"/armarx-render-frame-" << counter <<
".bmp";
219 std::string fn = ss.str();
223 viewer->getSceneManager()->render();
226 QGLWidget* w = (QGLWidget*)
viewer->getGLWidget();
228 QImage i = w->grabFrameBuffer();
229 QString fnQ(fn.c_str());
230 bool res = i.save(fnQ,
"BMP");
237 clock_t end = clock();
238 float timeMS = (
float)(end - start) / (
float)CLOCKS_PER_SEC * 1000.0f;
249 viewer->setAccumulationBuffer(numPasses > 0);
250 viewer->setAntialiasing((numPasses > 0), numPasses);
290 SoCamera* cam =
viewer->getCamera();
291 SoSeparator* sceneViewableSep =
physicsVisu->getViewableScene();
293 if (cam && sceneViewableSep)
295 cam->viewAll(sceneViewableSep,
viewer->getViewportRegion());
306 SbVec3f position =
viewer->getCamera()->position.getValue();
307 SbRotation orientation =
viewer->getCamera()->orientation.getValue();
310 orientation.getValue(rotAxis,
angle);
315 camPose = MathTools::axisangle2eigen4f(axE,
angle);
316 camPose(0, 3) = position[0];
317 camPose(1, 3) = position[1];
318 camPose(2, 3) = position[2];
332 SbVec3f position(x * 0.001f, y * 0.001f, z * 0.001f);
333 SbRotation orientation;
335 MathTools::rpy2eigen4f(roll, pitch, yaw, m);
338 MathTools::eigen4f2axisangle(m, ax, ang);
339 SbVec3f ax2(ax(0), ax(1), ax(2));
340 orientation.setValue(ax2, ang);
341 viewer->getCamera()->position.setValue(position);
342 viewer->getCamera()->orientation.setValue(orientation);
378 info.windowEnabled = show;
384 QMetaObject::invokeMethod(
this,
"show");
391 QMetaObject::invokeMethod(
this,
"hide");
398 QMetaObject::invokeMethod(
this,
"slotShowBaseCoord", Qt::QueuedConnection, Q_ARG(
bool, show), Q_ARG(
float, scale));
438 if (!QMetaObject::invokeMethod(
this,
"setupAntiAliasing", Qt::QueuedConnection, Q_ARG(
int, steps)))
455 if (!QMetaObject::invokeMethod(
this,
"slotEnableDebugDrawLayer", Qt::QueuedConnection, Q_ARG(
bool, show)))
473 if (!QMetaObject::invokeMethod(
this,
"slotClearDebugDrawLayer", Qt::QueuedConnection))
482 QString
s(layerName.c_str());
484 if (!QMetaObject::invokeMethod(
this,
"slotClearLayer", Qt::QueuedConnection, Q_ARG(QString,
s)))
492 QString
s(layerName.c_str());
494 if (!QMetaObject::invokeMethod(
this,
"slotRemoveLayer", Qt::QueuedConnection, Q_ARG(QString,
s)))
502 QString
s(layerName.c_str());
504 if (!QMetaObject::invokeMethod(
this,
"slotEnableLayerVisu", Qt::QueuedConnection, Q_ARG(QString,
s), Q_ARG(
bool, visible)))
530 debugDrawer->enableLayerVisu(layerName.toStdString(), visible);
542 return ::armarx::LayerInformationSequence {};
557 if (!QMetaObject::invokeMethod(
this,
"slotSelectVisuType", Qt::QueuedConnection, Q_ARG(
bool, fullModel)))