diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt new file mode 100644 index 0000000..20aea75 --- /dev/null +++ b/code/CMakeLists.txt @@ -0,0 +1,90 @@ +# Usage: +# Create build folder, like RC-build next to RobotControl and WifiScan folder +# CD into build folder and execute 'cmake -DCMAKE_BUILD_TYPE=Debug ../RobotControl' +# make + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +# select build type +SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" ) + +PROJECT(Raytrace) + +IF(NOT CMAKE_BUILD_TYPE) + MESSAGE(STATUS "No build type selected. Default to Debug") + SET(CMAKE_BUILD_TYPE "Debug") +ENDIF() + + + +INCLUDE_DIRECTORIES( + ../ + /mnt/data/workspaces/ +) + + +FILE(GLOB HEADERS + ./*.h + ./*/*.h + ./*/*/*.h + ./*/*/*/*.h + ./*/*/*/*/*.h + ./*/*/*/*/*/*.h + ./tests/data/* + ./tests/data/*/* + ./tests/data/*/*/* +) + + +FILE(GLOB SOURCES + ./*.cpp + ./*/*.cpp + ./*/*/*.cpp + ./*/*/*/*.cpp + /mnt/data/workspaces/Indoor/lib/tinyxml/tinyxml2.cpp +) + + +# use openMP +find_package(OpenMP REQUIRED) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") + +# system specific compiler flags +ADD_DEFINITIONS( + + -std=gnu++11 + + -Wall + -Werror=return-type + -Wextra + -Wpedantic + + -fstack-protector-all + + -g3 + -O2 + -march=native + + -DWITH_TESTS + -DWITH_ASSERTIONS + -DWITH_DEBUG_LOG + + +) + + +# build a binary file +ADD_EXECUTABLE( + ${PROJECT_NAME} + ${HEADERS} + ${SOURCES} +) + +# needed external libraries +TARGET_LINK_LIBRARIES( + ${PROJECT_NAME} + gtest + pthread +) + diff --git a/code/main.cpp b/code/main.cpp new file mode 100644 index 0000000..4d8f552 --- /dev/null +++ b/code/main.cpp @@ -0,0 +1,9 @@ +#include "ray2.h" +#include "ray3.h" + +int main(void) { + + //ray3(); + ray2(); + +} diff --git a/code/misc.h b/code/misc.h new file mode 100644 index 0000000..ebedfd6 --- /dev/null +++ b/code/misc.h @@ -0,0 +1,18 @@ +#ifndef MISC_H +#define MISC_H + +#include +#include +#include +#include + +void writeMap3(const Floorplan::IndoorMap* map, const std::string& file) { + + ModelFactory fac(map); + std::ofstream outOBJ(file); + outOBJ << fac.toOBJ(); + outOBJ.close(); + +} + +#endif // MISC_H diff --git a/code/ray2.h b/code/ray2.h new file mode 100644 index 0000000..529abac --- /dev/null +++ b/code/ray2.h @@ -0,0 +1,101 @@ +#ifndef RAY2_H +#define RAY2_H + +#include "misc.h" + +#include +#include +#include + +void dumpRay2(const WiFiRaytrace2D& rt, const DataMapSignal& dms); + +void ray2() { + + //std::string file = "/mnt/data/workspaces/raytest2.xml"; + //Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file); + //Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[0]; + + //std::string file = "/apps/SHL39.xml"; + std::string file = "/mnt/data/workspaces/IndoorMap/maps/SHL39.xml"; + Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file); + Floorplan::Floor* floor = map->floors[0]; + Floorplan::AccessPoint* ap = floor->accesspoints[4]; + + + const int gs_cm = 50; + + WiFiRaytrace2D rt(floor, gs_cm, ap->pos.xy()); + + std::chrono::time_point start = std::chrono::high_resolution_clock::now(); + const DataMapSignal& dms = rt.estimate(); + std::chrono::time_point end = std::chrono::high_resolution_clock::now(); + auto result = std::chrono::duration_cast(end-start).count(); + std::cout << "it took: " << result << " msec" << std::endl; + + if (1 == 1) {dumpRay2(rt, dms);} + +} + +void dumpRay2(const WiFiRaytrace2D& rt, const DataMapSignal& dms) { + + const char sep = ' '; + int lines = 0; + + std::stringstream tmp; + + auto lambda = [&] (const float x, const float y, const DataMapSignalEntry& e) { + + const float min = -120; + const float max = -40; + float rssi = e.getMaxRSSI(); + if (rssi > max) {rssi = max;} + + if (rssi > -100) { + ++lines; + const int v = ((rssi - min) / (max-min)) * 255; // color + tmp + << x << sep << y << sep + << v << sep << v << sep << v + << "\n"; + } + }; + + dms.forEach(lambda); + + /* + std::ofstream out("/tmp/vm/grid.ply"); + out << "ply\n"; + out << "format ascii 1.0\n"; + out << "comment VCGLIB generated\n"; + out << "element vertex " << lines << "\n"; + out << "property float x\n"; + out << "property float y\n"; + out << "property float z\n"; + out << "property uchar red\n"; + out << "property uchar green\n"; + out << "property uchar blue\n"; + out << "element face 0\n"; + out << "property list uchar int vertex_indices\n"; + out << "end_header\n"; + out << tmp.str(); + out.close(); + */ + + std::cout << "lines: " << lines << std::endl; + +/* + std::ofstream outHits("/tmp/vm/hits.xyz.txt"); + for (const Point3 hit : rt.getHitEnter()) { + outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 255 << sep << 0 << "\n"; + } + for (const Point3 hit : rt.getHitLeave()) { + outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 0 << sep << 255 << "\n"; + } + for (const Point3 hit : rt.getHitStop()) { + outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 0 << sep << 0 << "\n"; + } + outHits.close(); +*/ +} + +#endif // RAY2_H diff --git a/code/ray3.h b/code/ray3.h new file mode 100644 index 0000000..3932644 --- /dev/null +++ b/code/ray3.h @@ -0,0 +1,104 @@ +#ifndef RAY3_H +#define RAY3_H + + +#include +#include +#include + +#include "misc.h" + +void dumpRay3(const WiFiRaytrace3D& rt, const DataMap3Signal& dms); + +void ray3() { + + + //std::string file = "/mnt/data/workspaces/raytest2.xml"; + //Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file); + //Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[0]; + + //std::string file = "/apps/SHL39.xml"; + std::string file = "/mnt/data/workspaces/IndoorMap/maps/SHL39.xml"; + Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file); + Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[4]; + + writeMap3(map, "/tmp/vm/map.obj"); + + const int gs_cm = 50; + + WiFiRaytrace3D rt(map, gs_cm, ap->pos); + + std::chrono::time_point start = std::chrono::high_resolution_clock::now(); + const DataMap3Signal& dms = rt.estimate(); + std::chrono::time_point end = std::chrono::high_resolution_clock::now(); + auto result = std::chrono::duration_cast(end-start).count(); + std::cout << "it took: " << result << " msec" << std::endl; + + if (1 == 1) {dumpRay3(rt, dms);} + +} + +void dumpRay3(const WiFiRaytrace3D& rt, const DataMap3Signal& dms) { + + const char sep = ' '; + int lines = 0; + + std::stringstream tmp; + + auto lambda = [&] (const float x, const float y, const float z, const DataMap3SignalEntry& e) { + + const float min = -120; + const float max = -40; + float rssi = e.getMaxRSSI(); + if (rssi > max) {rssi = max;} + + if (z < 1.0 || z > 1.0) {return;} + + if (rssi > -100) { + ++lines; + const int v = ((rssi - min) / (max-min)) * 255; // color + tmp + << x << sep << y << sep << z << sep + << v << sep << v << sep << v + << "\n"; + } + }; + + dms.forEach(lambda); + + std::ofstream out("/tmp/vm/grid.ply"); + out << "ply\n"; + out << "format ascii 1.0\n"; + out << "comment VCGLIB generated\n"; + out << "element vertex " << lines << "\n"; + out << "property float x\n"; + out << "property float y\n"; + out << "property float z\n"; + out << "property uchar red\n"; + out << "property uchar green\n"; + out << "property uchar blue\n"; + out << "element face 0\n"; + out << "property list uchar int vertex_indices\n"; + out << "end_header\n"; + out << tmp.str(); + out.close(); + + std::cout << "lines: " << lines << std::endl; + + + std::ofstream outHits("/tmp/vm/hits.xyz.txt"); + for (const Point3 hit : rt.getHitEnter()) { + outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 255 << sep << 0 << "\n"; + } + for (const Point3 hit : rt.getHitLeave()) { + outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 0 << sep << 255 << "\n"; + } + for (const Point3 hit : rt.getHitStop()) { + outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 0 << sep << 0 << "\n"; + } + outHits.close(); + +} + + +#endif // RAY3_H