diff --git a/VirtualRobot/examples/CMakeLists.txt b/VirtualRobot/examples/CMakeLists.txt index 15e41a7d0b4c33787f3bdc90b7565332075708e7..eb3f201c0a7c2e71822f02dfd35def254b533928 100644 --- a/VirtualRobot/examples/CMakeLists.txt +++ b/VirtualRobot/examples/CMakeLists.txt @@ -25,5 +25,6 @@ ADD_SUBDIRECTORY(RobotViewerOSG) ADD_SUBDIRECTORY(SceneViewer) ADD_SUBDIRECTORY(Simox2Mjcf) ADD_SUBDIRECTORY(stability) - - +ADD_SUBDIRECTORY(CoinViewer) +ADD_SUBDIRECTORY(RGBOffscreenRendering) +ADD_SUBDIRECTORY(DepthOffscreenRendering) diff --git a/VirtualRobot/examples/CoinViewer/CMakeLists.txt b/VirtualRobot/examples/CoinViewer/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d1e4af03e200e6bb5c69d8f3ea82b8acda1c898b --- /dev/null +++ b/VirtualRobot/examples/CoinViewer/CMakeLists.txt @@ -0,0 +1,36 @@ +PROJECT ( CoinViewer ) + +IF(Simox_VISUALIZATION AND Simox_USE_COIN_VISUALIZATION) + + set(demo_SRCS CoinViewer.cpp main.cpp) + set(demo_INCS CoinViewer.h) + set(GUI_MOC_HDRS CoinViewer.h) + + set(GUI_UIS CoinViewer.ui) + + # create the executable + VirtualRobotQtApplication(${PROJECT_NAME} "${demo_SRCS}" "${demo_INCS}" "${GUI_MOC_HDRS}" "${GUI_UIS}") + + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${Simox_BIN_DIR}) + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES FOLDER "Examples") + + find_package(OpenGL REQUIRED) + if(OPENGL_FOUND) + target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${OPENGL_INCLUDE_DIR}) + TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES}) + endif(OPENGL_FOUND) + + + ####################################################################################### + ############################ Setup for installation ################################### + ####################################################################################### + install(TARGETS ${PROJECT_NAME} + # IMPORTANT: Add the library to the "export-set" + EXPORT SimoxTargets + RUNTIME DESTINATION bin COMPONENT bin + COMPONENT dev) + + MESSAGE( STATUS " ** Simox application ${PROJECT_NAME} will be placed into " ${Simox_BIN_DIR}) + MESSAGE( STATUS " ** Simox application ${PROJECT_NAME} will be installed into " bin) + +ENDIF() diff --git a/VirtualRobot/examples/CoinViewer/CoinViewer.cpp b/VirtualRobot/examples/CoinViewer/CoinViewer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76be9e52acfcd745f70fea004148df56a434e46a --- /dev/null +++ b/VirtualRobot/examples/CoinViewer/CoinViewer.cpp @@ -0,0 +1,96 @@ +#include <chrono> +#include <cmath> + +#include <Eigen/Core> + +#include <Inventor/actions/SoLineHighlightRenderAction.h> + +#include <VirtualRobot/Obstacle.h> +#include <VirtualRobot/Visualization/VisualizationFactory.h> +#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h> +#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h> + +#include "CoinViewer.h" + +CoinViewerExample::CoinViewerExample() + : QMainWindow(nullptr) +{ + //setup scene + { + sceneSep = new SoSeparator; + sceneSep->ref(); + + auto addSphere = [&](int x, int y, int z, int r) + { + Eigen::Matrix4f m = Eigen::Matrix4f::Identity(); + m(0, 3) = x; + m(1, 3) = y; + m(2, 3) = z; + + auto s = VirtualRobot::Obstacle::createSphere(r); + s->setGlobalPose(m); + sceneSep->addChild( + VirtualRobot::CoinVisualizationFactory::getCoinVisualization( + s, VirtualRobot::SceneObject::Full)); + }; + + addSphere(0, 1500, 1500, 400); + addSphere(700, 900, 1500, 300); + addSphere(0, 2000, 2000, 200); + addSphere(500, 1500, 2000, 200); + } + + //setup ui + { + UI.setupUi(this); + viewer = new SoQtExaminerViewer(UI.frameViewer, "", TRUE, SoQtExaminerViewer::BUILD_POPUP); + viewer->setBackgroundColor(SbColor(1.0f, 1.0f, 1.0f)); + viewer->setAccumulationBuffer(true); + + viewer->setAntialiasing(true, 4); + + viewer->setGLRenderAction(new SoLineHighlightRenderAction); + viewer->setTransparencyType(SoGLRenderAction::BLEND); + viewer->setFeedbackVisibility(true); + viewer->setSceneGraph(sceneSep); + + viewer->viewAll(); + } + startTimer(10); +} + +CoinViewerExample::~CoinViewerExample() +{ + sceneSep->unref(); +} + +void CoinViewerExample::closeEvent(QCloseEvent* event) +{ + quit(); + QMainWindow::closeEvent(event); +} + +int CoinViewerExample::main() +{ + SoQt::show(this); + SoQt::mainLoop(); + return 0; +} + +void CoinViewerExample::quit() +{ + std::cout << "CShowRobotWindow: Closing" << std::endl; + this->close(); + SoQt::exitMainLoop(); +} + +void CoinViewerExample::timerEvent(QTimerEvent*) +{ + static const auto first = std::chrono::high_resolution_clock::now(); + const auto now = std::chrono::high_resolution_clock::now(); + const float x = (now - first).count() / 1e9; + const float r = 0.5f + std::sin(x); + const float g = 0.5f + std::cos(x); + viewer->setBackgroundColor(SbColor(r, g, 1.0f)); + viewer->scheduleRedraw(); +} diff --git a/VirtualRobot/examples/CoinViewer/CoinViewer.h b/VirtualRobot/examples/CoinViewer/CoinViewer.h new file mode 100644 index 0000000000000000000000000000000000000000..1123e1e90eee486bf2bc805b95c08868ccb77957 --- /dev/null +++ b/VirtualRobot/examples/CoinViewer/CoinViewer.h @@ -0,0 +1,30 @@ +#pragma once +#include <QtCore/QtGlobal> +#include <QtGui/QtGui> + +#include <Inventor/Qt/viewers/SoQtExaminerViewer.h> +#include <Inventor/Qt/SoQt.h> +#include <Inventor/nodes/SoSeparator.h> + +#include "ui_CoinViewer.h" + +class CoinViewerExample : public QMainWindow +{ + Q_OBJECT +public: + CoinViewerExample(); + ~CoinViewerExample() override; + int main(); + +public slots: + void quit(); + void closeEvent(QCloseEvent* event) override; + +protected: + void timerEvent(QTimerEvent* event) override; + + Ui::MainWindowCamera UI; + SoQtExaminerViewer* viewer; + SoSeparator* sceneSep; +}; + diff --git a/VirtualRobot/examples/CoinViewer/CoinViewer.ui b/VirtualRobot/examples/CoinViewer/CoinViewer.ui new file mode 100644 index 0000000000000000000000000000000000000000..b1f224d97dbb9b247508554b1029ebe4ac979873 --- /dev/null +++ b/VirtualRobot/examples/CoinViewer/CoinViewer.ui @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindowCamera</class> + <widget class="QMainWindow" name="MainWindowCamera"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1178</width> + <height>955</height> + </rect> + </property> + <property name="windowTitle"> + <string>Simox - VirtualRobot - Show Robot</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QFrame" name="frameViewer"> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/VirtualRobot/examples/CoinViewer/main.cpp b/VirtualRobot/examples/CoinViewer/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf2b0477eea2ae56036cd281fb9838ec958b3a95 --- /dev/null +++ b/VirtualRobot/examples/CoinViewer/main.cpp @@ -0,0 +1,11 @@ +#include <VirtualRobot/RuntimeEnvironment.h> + +#include "CoinViewer.h" + +int main(int argc, char* argv[]) +{ + VirtualRobot::init(argc, argv, "CoinViewer"); + CoinViewerExample w; + w.main(); + return 0; +} diff --git a/VirtualRobot/examples/DepthOffscreenRendering/CMakeLists.txt b/VirtualRobot/examples/DepthOffscreenRendering/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4ba090a12fe7c64044b5c201191b2893cabb548c --- /dev/null +++ b/VirtualRobot/examples/DepthOffscreenRendering/CMakeLists.txt @@ -0,0 +1,33 @@ +PROJECT ( DepthOffscreenRendering ) + +IF(Simox_VISUALIZATION AND Simox_USE_COIN_VISUALIZATION) + set(demo_SRCS DepthOffscreenRendering.cpp main.cpp) + set(demo_INCS DepthOffscreenRendering.h) + set(GUI_MOC_HDRS DepthOffscreenRendering.h) + set(GUI_UIS DepthOffscreenRendering.ui) + + # create the executable + VirtualRobotQtApplication(${PROJECT_NAME} "${demo_SRCS}" "${demo_INCS}" "${GUI_MOC_HDRS}" "${GUI_UIS}") + + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${Simox_BIN_DIR}) + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES FOLDER "Examples") + + find_package(OpenGL REQUIRED) + if(OPENGL_FOUND) + target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${OPENGL_INCLUDE_DIR}) + TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES}) + endif() + + ####################################################################################### + ############################ Setup for installation ################################### + ####################################################################################### + install(TARGETS ${PROJECT_NAME} + # IMPORTANT: Add the library to the "export-set" + EXPORT SimoxTargets + RUNTIME DESTINATION bin COMPONENT bin + COMPONENT dev) + + MESSAGE( STATUS " ** Simox application ${PROJECT_NAME} will be placed into " ${Simox_BIN_DIR}) + MESSAGE( STATUS " ** Simox application ${PROJECT_NAME} will be installed into " bin) + +ENDIF() diff --git a/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.cpp b/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5f7a824e1a663f7a1b1e5e56633217785ba8326 --- /dev/null +++ b/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.cpp @@ -0,0 +1,114 @@ +#include <Eigen/Core> + +#include <Inventor/Qt/SoQt.h> + +#include <SimoxUtility/math/convert/pos_rpy_to_mat4f.h> + +#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h> +#include <VirtualRobot/Visualization/VisualizationFactory.h> +#include <VirtualRobot/Obstacle.h> + +#include "DepthOffscreenRendering.h" + +DepthOffscreenRenderingExample::DepthOffscreenRenderingExample() + : QMainWindow(nullptr) +{ + camRenderer = nullptr; + //setup scene + { + sceneSep = new SoSeparator; + sceneSep->ref(); + + auto addSphere = [&](int x, int y, int z, int r) + { + Eigen::Matrix4f m = Eigen::Matrix4f::Identity(); + m(0, 3) = x; + m(1, 3) = y; + m(2, 3) = z; + + auto s = VirtualRobot::Obstacle::createSphere(r); + s->setGlobalPose(m); + sceneSep->addChild( + VirtualRobot::CoinVisualizationFactory::getCoinVisualization( + s, VirtualRobot::SceneObject::Full)); + }; + addSphere(0, 1500, 1500, 400); + addSphere(700, 900, 1500, 300); + addSphere(0, 2000, 2000, 200); + addSphere(500, 1500, 2000, 200); + } + + //setup ui + { + UI.setupUi(this); + connect(UI.doubleSpinBoxCamYaw, SIGNAL(valueChanged(double)), + this, SLOT(camYawUpdated(double))); + } + camYawUpdated(UI.doubleSpinBoxCamYaw->value()); +} + +DepthOffscreenRenderingExample::~DepthOffscreenRenderingExample() +{ + sceneSep->unref(); +} + +void DepthOffscreenRenderingExample::closeEvent(QCloseEvent* event) +{ + quit(); + QMainWindow::closeEvent(event); +} + +int DepthOffscreenRenderingExample::main() +{ + SoQt::show(this); + SoQt::mainLoop(); + return 0; +} + +void DepthOffscreenRenderingExample::quit() +{ + std::cout << "CShowRobotWindow: Closing" << std::endl; + this->close(); + SoQt::exitMainLoop(); +} + +void DepthOffscreenRenderingExample::camYawUpdated(double yaw) +{ + const short width = 640; + const short height = 480; + + //cam + buffer setup + if (!camRenderer) + { + const auto pixelCount = width * height; + camDepthBuffer.resize(pixelCount); + camRenderer = VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(width, height); + } + + const float zNear = 10; + const float zFar = 100000; + const float fov = M_PI / 4; + + const Eigen::Matrix4f pose = + simox::math::pos_rpy_to_mat4f(0, 0, 1500, 0, 0, yaw) * + simox::math::pos_rpy_to_mat4f(0, 0, 0, 0, -M_PI / 2, 0); + + std::vector<unsigned char> rgbImage; + std::vector<Eigen::Vector3f> pointCloud; + VirtualRobot::CoinVisualizationFactory::renderOffscreenRgbDepthPointcloud( + camRenderer, pose, sceneSep, width, height, + false, rgbImage, + true, camDepthBuffer, + false, pointCloud, + zNear, zFar, fov + ); + + QImage img(width, height, QImage::Format_Grayscale8); + for (std::size_t i = 0; i < camDepthBuffer.size(); ++i) + { + static constexpr float maxdepth = 5000; + const float c = std::min(camDepthBuffer.at(i), maxdepth) / maxdepth * 255; + img.bits()[i] = static_cast<uchar>(c); + } + UI.labelImg->setPixmap(QPixmap::fromImage(img.mirrored(false, true))); +} diff --git a/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.h b/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.h new file mode 100644 index 0000000000000000000000000000000000000000..0d1c099d4ee96c62a60e8691ae92e5619994f7d6 --- /dev/null +++ b/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.h @@ -0,0 +1,31 @@ +#pragma once + +#include <vector> + +#include <QtCore/QtGlobal> +#include <QtGui/QtGui> + +#include <Inventor/nodes/SoSeparator.h> +#include <Inventor/SoOffscreenRenderer.h> + +#include "ui_DepthOffscreenRendering.h" + +class DepthOffscreenRenderingExample : public QMainWindow +{ + Q_OBJECT +public: + DepthOffscreenRenderingExample(); + ~DepthOffscreenRenderingExample() override; + int main(); + +public slots: + void quit(); + void closeEvent(QCloseEvent* event) override; + void camYawUpdated(double y); +protected: + Ui::MainWindowCamera UI; + SoSeparator* sceneSep; + SoOffscreenRenderer* camRenderer; + std::vector<float> camDepthBuffer; +}; + diff --git a/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.ui b/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.ui new file mode 100644 index 0000000000000000000000000000000000000000..79b7571106dacc2e493b4e66e1f8c536750b5f9f --- /dev/null +++ b/VirtualRobot/examples/DepthOffscreenRendering/DepthOffscreenRendering.ui @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindowCamera</class> + <widget class="QMainWindow" name="MainWindowCamera"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>667</width> + <height>503</height> + </rect> + </property> + <property name="windowTitle"> + <string>Simox - VirtualRobot - Show Robot</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxCamYaw"> + <property name="minimum"> + <double>-3.150000000000000</double> + </property> + <property name="maximum"> + <double>3.150000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + <property name="value"> + <double>-1.750000000000000</double> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Camera yaw</string> + </property> + </widget> + </item> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="labelImg"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/VirtualRobot/examples/DepthOffscreenRendering/main.cpp b/VirtualRobot/examples/DepthOffscreenRendering/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc309f9564111f3364720c899f59c0e3b24d88b5 --- /dev/null +++ b/VirtualRobot/examples/DepthOffscreenRendering/main.cpp @@ -0,0 +1,11 @@ +#include <VirtualRobot/RuntimeEnvironment.h> + +#include "DepthOffscreenRendering.h" + +int main(int argc, char* argv[]) +{ + VirtualRobot::init(argc, argv, "DepthOffscreenRendering"); + DepthOffscreenRenderingExample w; + w.main(); + return 0; +} diff --git a/VirtualRobot/examples/RGBOffscreenRendering/CMakeLists.txt b/VirtualRobot/examples/RGBOffscreenRendering/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..05198ed60e078497aa103447f55f308f77db056a --- /dev/null +++ b/VirtualRobot/examples/RGBOffscreenRendering/CMakeLists.txt @@ -0,0 +1,33 @@ +PROJECT ( RGBOffscreenRendering ) + +IF(Simox_VISUALIZATION AND Simox_USE_COIN_VISUALIZATION) + set(demo_SRCS RGBOffscreenRendering.cpp main.cpp) + set(demo_INCS RGBOffscreenRendering.h) + set(GUI_MOC_HDRS RGBOffscreenRendering.h) + set(GUI_UIS RGBOffscreenRendering.ui) + + # create the executable + VirtualRobotQtApplication(${PROJECT_NAME} "${demo_SRCS}" "${demo_INCS}" "${GUI_MOC_HDRS}" "${GUI_UIS}") + + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${Simox_BIN_DIR}) + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES FOLDER "Examples") + + find_package(OpenGL REQUIRED) + if(OPENGL_FOUND) + target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${OPENGL_INCLUDE_DIR}) + TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES}) + endif() + + ####################################################################################### + ############################ Setup for installation ################################### + ####################################################################################### + install(TARGETS ${PROJECT_NAME} + # IMPORTANT: Add the library to the "export-set" + EXPORT SimoxTargets + RUNTIME DESTINATION bin COMPONENT bin + COMPONENT dev) + + MESSAGE( STATUS " ** Simox application ${PROJECT_NAME} will be placed into " ${Simox_BIN_DIR}) + MESSAGE( STATUS " ** Simox application ${PROJECT_NAME} will be installed into " bin) + +ENDIF() diff --git a/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.cpp b/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6db6af9b979e94934c82cef071ec6c414e0eb60 --- /dev/null +++ b/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.cpp @@ -0,0 +1,108 @@ +#include <Eigen/Core> + +#include <Inventor/Qt/SoQt.h> + +#include <SimoxUtility/math/convert/pos_rpy_to_mat4f.h> + +#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h> +#include <VirtualRobot/Visualization/VisualizationFactory.h> +#include <VirtualRobot/Obstacle.h> + +#include "RGBOffscreenRendering.h" + +RGBOffscreenRenderingExample::RGBOffscreenRenderingExample() + : QMainWindow(nullptr) +{ + camRenderer = nullptr; + //setup scene + { + sceneSep = new SoSeparator; + sceneSep->ref(); + + auto addSphere = [&](int x, int y, int z, int r) + { + Eigen::Matrix4f m = Eigen::Matrix4f::Identity(); + m(0, 3) = x; + m(1, 3) = y; + m(2, 3) = z; + + auto s = VirtualRobot::Obstacle::createSphere(r); + s->setGlobalPose(m); + sceneSep->addChild( + VirtualRobot::CoinVisualizationFactory::getCoinVisualization( + s, VirtualRobot::SceneObject::Full)); + }; + addSphere(0, 1500, 1500, 400); + addSphere(700, 900, 1500, 300); + addSphere(0, 2000, 2000, 200); + addSphere(500, 1500, 2000, 200); + } + + //setup ui + { + UI.setupUi(this); + connect(UI.doubleSpinBoxCamYaw, SIGNAL(valueChanged(double)), + this, SLOT(camYawUpdated(double))); + } + camYawUpdated(UI.doubleSpinBoxCamYaw->value()); +} + +RGBOffscreenRenderingExample::~RGBOffscreenRenderingExample() +{ + sceneSep->unref(); +} + +void RGBOffscreenRenderingExample::closeEvent(QCloseEvent* event) +{ + quit(); + QMainWindow::closeEvent(event); +} + +int RGBOffscreenRenderingExample::main() +{ + SoQt::show(this); + SoQt::mainLoop(); + return 0; +} + +void RGBOffscreenRenderingExample::quit() +{ + std::cout << "CShowRobotWindow: Closing" << std::endl; + this->close(); + SoQt::exitMainLoop(); +} + +void RGBOffscreenRenderingExample::camYawUpdated(double yaw) +{ + const short width = 640; + const short height = 480; + + //cam + buffer setup + if (!camRenderer) + { + const auto pixelCount = width * height; + camRGBBuffer.resize(pixelCount * 3); + camRenderer = VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(width, height); + } + + const float zNear = 10; + const float zFar = 100000; + const float fov = M_PI / 4; + + const Eigen::Matrix4f pose = + simox::math::pos_rpy_to_mat4f(0, 0, 1500, 0, 0, yaw) * + simox::math::pos_rpy_to_mat4f(0, 0, 0, 0, -M_PI/2, 0); + + std::vector<float> depthImage; + std::vector<Eigen::Vector3f> pointCloud; + VirtualRobot::CoinVisualizationFactory::renderOffscreenRgbDepthPointcloud( + camRenderer, pose, sceneSep, width, height, + true, camRGBBuffer, + false, depthImage, + false, pointCloud, + zNear, zFar, fov + ); + + QImage img(camRGBBuffer.data(), width, height, QImage::Format_RGB888); + UI.labelImg->setPixmap(QPixmap::fromImage(img.mirrored(false, true))); +} diff --git a/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.h b/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.h new file mode 100644 index 0000000000000000000000000000000000000000..0a9eb58ea7312eabaeb13e470abed055f7179f49 --- /dev/null +++ b/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.h @@ -0,0 +1,31 @@ +#pragma once + +#include <vector> + +#include <QtCore/QtGlobal> +#include <QtGui/QtGui> + +#include <Inventor/nodes/SoSeparator.h> +#include <Inventor/SoOffscreenRenderer.h> + +#include "ui_RGBOffscreenRendering.h" + +class RGBOffscreenRenderingExample : public QMainWindow +{ + Q_OBJECT +public: + RGBOffscreenRenderingExample(); + ~RGBOffscreenRenderingExample() override; + int main(); + +public slots: + void quit(); + void closeEvent(QCloseEvent* event) override; + void camYawUpdated(double y); +protected: + Ui::MainWindowCamera UI; + SoSeparator* sceneSep; + SoOffscreenRenderer* camRenderer; + std::vector<unsigned char> camRGBBuffer; +}; + diff --git a/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.ui b/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.ui new file mode 100644 index 0000000000000000000000000000000000000000..79b7571106dacc2e493b4e66e1f8c536750b5f9f --- /dev/null +++ b/VirtualRobot/examples/RGBOffscreenRendering/RGBOffscreenRendering.ui @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindowCamera</class> + <widget class="QMainWindow" name="MainWindowCamera"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>667</width> + <height>503</height> + </rect> + </property> + <property name="windowTitle"> + <string>Simox - VirtualRobot - Show Robot</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxCamYaw"> + <property name="minimum"> + <double>-3.150000000000000</double> + </property> + <property name="maximum"> + <double>3.150000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + <property name="value"> + <double>-1.750000000000000</double> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Camera yaw</string> + </property> + </widget> + </item> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="labelImg"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/VirtualRobot/examples/RGBOffscreenRendering/main.cpp b/VirtualRobot/examples/RGBOffscreenRendering/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85e4b4884a7e074aae9ca8764d17466870173694 --- /dev/null +++ b/VirtualRobot/examples/RGBOffscreenRendering/main.cpp @@ -0,0 +1,11 @@ +#include <VirtualRobot/RuntimeEnvironment.h> + +#include "RGBOffscreenRendering.h" + +int main(int argc, char* argv[]) +{ + VirtualRobot::init(argc, argv, "RGBOffscreenRendering"); + RGBOffscreenRenderingExample w; + w.main(); + return 0; +}