initial commit
setup for 2D and 3D raytracing
This commit is contained in:
90
code/CMakeLists.txt
Normal file
90
code/CMakeLists.txt
Normal file
@@ -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
|
||||||
|
)
|
||||||
|
|
||||||
9
code/main.cpp
Normal file
9
code/main.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "ray2.h"
|
||||||
|
#include "ray3.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
|
||||||
|
//ray3();
|
||||||
|
ray2();
|
||||||
|
|
||||||
|
}
|
||||||
18
code/misc.h
Normal file
18
code/misc.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef MISC_H
|
||||||
|
#define MISC_H
|
||||||
|
|
||||||
|
#include <Indoor/floorplan/v2/FloorplanReader.h>
|
||||||
|
#include <Indoor/wifi/estimate/ray3/ModelFactory.h>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
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
|
||||||
101
code/ray2.h
Normal file
101
code/ray2.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#ifndef RAY2_H
|
||||||
|
#define RAY2_H
|
||||||
|
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
#include <Indoor/wifi/estimate/ray2d/WiFiRayTrace2D.h>
|
||||||
|
#include <Indoor/floorplan/v2/FloorplanReader.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
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<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
|
||||||
|
const DataMapSignal& dms = rt.estimate();
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto result = std::chrono::duration_cast<std::chrono::milliseconds>(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
|
||||||
104
code/ray3.h
Normal file
104
code/ray3.h
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#ifndef RAY3_H
|
||||||
|
#define RAY3_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Indoor/wifi/estimate/ray3/WifiRayTrace3D.h>
|
||||||
|
#include <Indoor/floorplan/v2/FloorplanReader.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#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<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
|
||||||
|
const DataMap3Signal& dms = rt.estimate();
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto result = std::chrono::duration_cast<std::chrono::milliseconds>(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
|
||||||
Reference in New Issue
Block a user