diff --git a/Makefile b/Makefile index 0d470a3c4be8f778497d3c8bc5df601878da4a3f..9812e55d31120b029b7732eae01652b217513d7b 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,9 @@ -include src/common.mk -include dep.mk - -OBJSALL=$(shell find src -name '*.o') - -LIBNAME=libsandbox -LIB_MINOR_VERS=0.0 -LIB_MAJOR_VERS=1 -LIB_VERS=$(LIB_MAJOR_VERS).$(LIB_MINOR_VERS) -LIB_FULL_NAME=$(LIBNAME).so.$(LIB_VERS) - all: $(MAKE) -C src - $(MAKE) pack -C . - $(MAKE) link -C . + $(MAKE) -C build $(MAKE) -C app -pack: - gcc -shared -Wl,-soname,$(LIB_FULL_NAME) -o $(LIB_FULL_NAME) $(OBJSALL) - -link: - -ln -s $(LIB_FULL_NAME) $(LIBNAME).so.$(LIB_MAJOR_VERS) - -ln -s $(LIB_FULL_NAME) $(LIBNAME).so - clean: - -rm -f *.o *.so* - -rm $(SETUPAPP) $(MAKE) clean -C src $(MAKE) clean -C app + $(MAKE) clean -C build diff --git a/README.md b/README.md index 4b57a9e2e1526b195c6fcb371505a45567bc86d9..6dad81cfff13a363142cba72173ce21f75d970d5 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,6 @@ - LD_LIBRARY_PATH must contain dir's path to libsandbox.so - Enter this command in the terminal where you are using your application ``` -REALTIVE_PATH_TO_SO=../ar_sandbox_lib && \ +REALTIVE_PATH_TO_SO=../ar_sandbox_lib/build && \ export LD_LIBRARY_PATH=$(pwd)/$REALTIVE_PATH_TO_SO ``` diff --git a/app/Makefile b/app/Makefile index 435e3ed1a95a9bec48267c52c3d6fe44ad56b7e6..1d33540ac9872d118faa66ff5b379dbcbea1d143 100644 --- a/app/Makefile +++ b/app/Makefile @@ -1,16 +1,7 @@ -include ../src/common.mk -include ../dep.mk -SETUPAPP=SandboxSetupApp -LIB_PATH=.. - - -app: $(SETUPAPP).o - g++ $< -o $(SETUPAPP) -L$(LIB_PATH) -lsandbox $(DEP_SANDBOX) - -$(SETUPAPP).o: $(SETUPAPP).cpp - $(CCP) $(CFLAGS) -I$(LIB_PATH)/inc -c $< -o $@ +all: + $(shell cd SandboxSetup && qmake *.pro) + $(MAKE) -C SandboxSetup clean: - -rm -f *.o - -rm $(SETUPAPP) + $(MAKE) distclean -C SandboxSetup diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro new file mode 100644 index 0000000000000000000000000000000000000000..e9dad85fab974ea71c9e7b46ba5ec4f2ec5b4a5b --- /dev/null +++ b/app/SandboxSetup/SandboxSetup.pro @@ -0,0 +1,41 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2020-05-13T17:30:24 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = SandboxSetup +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui + + + +INCLUDEPATH += ../../inc + +LIBS += -L"../../build" -lsandbox -lrealsense2 -lyaml-cpp +LIBS += $(shell pkg-config --libs --cflags opencv) diff --git a/app/SandboxSetupApp.cpp b/app/SandboxSetup/main.cpp similarity index 53% rename from app/SandboxSetupApp.cpp rename to app/SandboxSetup/main.cpp index d8ed820e94e1d334f1d465bbc8b05a876c947823..945ee5e3b1b9eafde7e7bf1062509b163ace5c4b 100644 --- a/app/SandboxSetupApp.cpp +++ b/app/SandboxSetup/main.cpp @@ -1,19 +1,28 @@ -#include "../inc/sandboxSetup.h" +#include "mainwindow.h" +#include <QApplication> +#include <sandboxSetup.h> + +int main(int argc, char *argv[]) +{ -int main(){ SandboxSetup setup; - - if(setup.setupBeamerResolution()){ - std::cout << "Invalide resolution" << std::endl; + QApplication a(argc, argv); + MainWindow w; + w.show(); + a.exec(); + + setup.setBeamerResolution(cv::Size(w.getWidth(), w.getHeight())); + if(w.getWidth()==0 || w.getHeight()==0){ + std::cout << "Cancel Resolution" << std::endl; return 1; } - + if(setup.setupProjection()){ std::cout << "Cancel calibration" << std::endl; return 1; } - + if(setup.setupBeamerLocation()){ std::cout << "Cancel calibration" << std::endl; return 1; @@ -23,6 +32,7 @@ int main(){ std::cout << "Failed to save configuration" << std::endl; return 1; } - + + return 0; } diff --git a/app/SandboxSetup/mainwindow.cpp b/app/SandboxSetup/mainwindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4522900f8642360a9502e424d833c23ee4ba2ed0 --- /dev/null +++ b/app/SandboxSetup/mainwindow.cpp @@ -0,0 +1,106 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + std::string path = ".monitors.tmp"; + monitors = std::map<std::string, std::vector<std::string>>(); + + + // Save in file the monitors and their resolutions + system( ("xrandr -d :0 | sed -n '1!p' > " + path).c_str() ); + + loadResolutionsFromFile(path); + + + QList<QScreen*> screens = QApplication::screens(); + + for(int i=0; i<screens.size(); i++){ + QScreen* sc = screens[i]; + ui->cbxOutputs->addItem( sc->name() ); + } + + if(screens.size() > 0){ + loadResolutionsOf(screens[0]); + } + + std::remove(path.c_str()); + +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_cbxOutputs_currentIndexChanged(int index){ + QList<QScreen*> screens = QApplication::screens(); + loadResolutionsOf(screens[index]); +} + + + +// load resolutions into GUI +void MainWindow::loadResolutionsOf(QScreen* sc){ + ui->cbxResolutions->clear(); + const char *key = sc->name().toStdString().c_str(); + std::vector<std::string> resolutions = monitors[key]; + + for(int i=0; i<resolutions.size(); i++){ + std::vector<std::string> res = splitResolution(resolutions[i]); + ui->cbxResolutions->addItem( QString::fromStdString(res[0] + "x" + res[1]) ); + } +} + +// Get height and width from the string "_width_x_height_" +// http://www.martinbroadhurst.com/how-to-split-a-string-in-c.html +std::vector<std::string> MainWindow::splitResolution(std::string s){ + char delim = 'x'; + std::vector<std::string> res; + std::stringstream ss(s); + std::string token; + while (std::getline(ss, token, delim)) { + res.push_back(token); + } + + return res; +} + +bool MainWindow::isResolution(std::string s){ + return splitResolution(s).size() == 2; +} + +void MainWindow::loadResolutionsFromFile(std::string path){ + // Get monitors and their resolutions into a Map + std::ifstream infile(path); + std::string line; + std::string key; + + while (std::getline(infile, line)){ + + std::istringstream iss(line); + std::string l; + iss >> l; + + if(!isResolution(l)){ + key = l; + monitors[key] = std::vector<std::string>(); + }else{ + monitors[key].push_back(l); + } + } +} + + +void MainWindow::on_btnOutputs_clicked() +{ + QString selectedRes = ui->cbxResolutions->currentText(); + std::vector<std::string> res = splitResolution(selectedRes.toStdString()); + width = std::stoi(res[0]); + height = std::stoi(res[1]); + this->close(); +} diff --git a/app/SandboxSetup/mainwindow.h b/app/SandboxSetup/mainwindow.h new file mode 100644 index 0000000000000000000000000000000000000000..67067d3ead090e348e5b68c5a387a6ca1d91b341 --- /dev/null +++ b/app/SandboxSetup/mainwindow.h @@ -0,0 +1,44 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QtWidgets> +#include <string> +#include <sstream> +#include <vector> +#include <fstream> +#include <map> +#include <iostream> + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + int getHeight(){ return height; } + int getWidth(){ return width; } + +private slots: + void on_cbxOutputs_currentIndexChanged(int index); + + void on_btnOutputs_clicked(); + +private: + Ui::MainWindow *ui; + int height = 0; + int width = 0; + std::map<std::string, std::vector<std::string>> monitors; + void loadResolutionsOf(QScreen* screen); + std::vector<std::string> splitResolution(std::string s); + bool isResolution(std::string s); + void loadResolutionsFromFile(std::string path); + +}; + +#endif // MAINWINDOW_H diff --git a/app/SandboxSetup/mainwindow.ui b/app/SandboxSetup/mainwindow.ui new file mode 100644 index 0000000000000000000000000000000000000000..fe361ad7db031a3af6caa2d4d3e2a1d962ba4b0c --- /dev/null +++ b/app/SandboxSetup/mainwindow.ui @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <widget class="QComboBox" name="cbxOutputs"> + <property name="geometry"> + <rect> + <x>50</x> + <y>40</y> + <width>141</width> + <height>25</height> + </rect> + </property> + </widget> + <widget class="QComboBox" name="cbxResolutions"> + <property name="geometry"> + <rect> + <x>50</x> + <y>130</y> + <width>181</width> + <height>25</height> + </rect> + </property> + </widget> + <widget class="QPushButton" name="btnOutputs"> + <property name="geometry"> + <rect> + <x>270</x> + <y>180</y> + <width>89</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Valide</string> + </property> + </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>101</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Choose output</string> + </property> + </widget> + <widget class="QLabel" name="label_2"> + <property name="geometry"> + <rect> + <x>10</x> + <y>100</y> + <width>131</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Choose resolution</string> + </property> + </widget> + </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QToolBar" name="mainToolBar"> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> diff --git a/build/Makefile b/build/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..b896e89b434fe4d0475d1e8047484c18b5e7d10e --- /dev/null +++ b/build/Makefile @@ -0,0 +1,21 @@ +OBJSALL=$(shell find ../src -name '*.o') + +LIBNAME=libsandbox +LIB_MINOR_VERS=0.0 +LIB_MAJOR_VERS=1 +LIB_VERS=$(LIB_MAJOR_VERS).$(LIB_MINOR_VERS) +LIB_FULL_NAME=$(LIBNAME).so.$(LIB_VERS) + +all: + $(MAKE) pack + $(MAKE) link + +pack: + gcc -shared -Wl,-soname,$(LIB_FULL_NAME) -o $(LIB_FULL_NAME) $(OBJSALL) + +link: + -ln -s $(LIB_FULL_NAME) $(LIBNAME).so.$(LIB_MAJOR_VERS) + -ln -s $(LIB_FULL_NAME) $(LIBNAME).so + +clean: + -rm -f *.so* diff --git a/inc/sandbox.h b/inc/sandbox.h index d77df2c3e13d3dde8dfd8c14e5b012df490e6042..81e4f6f58c40d0e5588fde69b4a8640fcaa6ed12 100644 --- a/inc/sandbox.h +++ b/inc/sandbox.h @@ -5,7 +5,6 @@ #include "camera.h" #include "beamerProjection.h" #include "beamer.h" -#include "borderedit.h" #include "sandboxConfig.h" class Sandbox{ diff --git a/inc/sandboxSetup.h b/inc/sandboxSetup.h index 5e4dd59899a4d60f43a3b9035d4d9003ad51dc12..2353457d9bf781066e385a3269904ad22503d038 100644 --- a/inc/sandboxSetup.h +++ b/inc/sandboxSetup.h @@ -2,7 +2,6 @@ #define SANDBOXSETUP_H #include <opencv2/opencv.hpp> -#include <cstdlib> #include "beamer.h" #include "beamerProjection.h" #include "camera.h" @@ -22,11 +21,20 @@ class SandboxSetup{ public: SandboxSetup(); + // save config in file => persistant int saveConfigFrom(char *path); int saveConfig(); + + // edit variables of config => not persistant int setupProjection(); int setupBeamerResolution(); int setupBeamerLocation(); + + void setBeamerResolution(cv::Size resolution); + void setBeamerPosition(cv::Point3f pos); + void setCroppingMask(cv::Rect mask); + void setAdjustingMatrix(cv::Mat matrix); + }; #endif diff --git a/sandbox.h b/sandbox.h deleted file mode 100644 index d77df2c3e13d3dde8dfd8c14e5b012df490e6042..0000000000000000000000000000000000000000 --- a/sandbox.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef SANDBOX_H -#define SANDBOX_H - -#include <opencv2/opencv.hpp> -#include "camera.h" -#include "beamerProjection.h" -#include "beamer.h" -#include "borderedit.h" -#include "sandboxConfig.h" - -class Sandbox{ - private: - char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml"; - char *defaultWindowsName = (char*) "ShowApp"; - BeamerProjection projection; - Camera camera; - Beamer beamer; - - void initWindowsFullScreen(char *windowName); - void showImage(cv::Mat* image, char *windowName); - - public: - Sandbox(); - - cv::Mat getRGBFrame(); - cv::Mat getDepthFrame(); - cv::Mat* adjustProjection(cv::Mat* frame); - void showImage(cv::Mat* image); - int loadConfig(); - int loadConfigFrom(char *path); - void initWindowsFullScreen(); - -}; - -#endif diff --git a/src/lib/sandboxSetup.cpp b/src/lib/sandboxSetup.cpp index d77d1493c772930e31b04db556658aad8478530a..6279bec7cc3031d022c4531e3ef3540d62833231 100644 --- a/src/lib/sandboxSetup.cpp +++ b/src/lib/sandboxSetup.cpp @@ -5,6 +5,23 @@ SandboxSetup::SandboxSetup(){ } +void SandboxSetup::setBeamerResolution(cv::Size resolution){ + beamer.setHeight(resolution.height); + beamer.setWidth(resolution.width); +} + +void SandboxSetup::setBeamerPosition(cv::Point3f pos){ + beamer.setPosition(pos); +} + +void SandboxSetup::setCroppingMask(cv::Rect mask){ + camera.setCroppingMask(mask); +} + +void SandboxSetup::setAdjustingMatrix(cv::Mat matrix){ + projection.setAdjustingMatrix(matrix); +} + // return 1 when config can't be saved in file int SandboxSetup::saveConfigFrom(char *path){