many changes :P
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static inline std::string getDataFile(const std::string& name) {
|
||||
return "/mnt/firma/kunden/indoor/tests/data/" + name;
|
||||
return "/apps/workspaces/Indoor/tests/data/" + name;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
269
tests/data/fp1.svg
Normal file
269
tests/data/fp1.svg
Normal file
@@ -0,0 +1,269 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="256"
|
||||
height="256"
|
||||
viewBox="0 0 256 256"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="fp1.svg">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="5.6"
|
||||
inkscape:cx="73.937318"
|
||||
inkscape:cy="144.77356"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer3"
|
||||
showgrid="true"
|
||||
units="px"
|
||||
inkscape:object-nodes="true"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1021"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid3336"
|
||||
empspacing="8" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-796.36219)"
|
||||
style="display:none"
|
||||
sodipodi:insensitive="true">
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 8,1044.3622 0,-240.00001 240,0 0,168 -128,0 0,72.00001 -112,0"
|
||||
id="path3340"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccccc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 8,956.36219 24,0"
|
||||
id="path3342"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 248,852.36219 -48,0"
|
||||
id="path3346"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 184,852.36219 -56,0"
|
||||
id="path3348"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 112,852.36219 -72,0"
|
||||
id="path3350"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 24,852.36219 -16,0"
|
||||
id="path3352"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 80,852.36219 0,-48"
|
||||
id="path3354"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 160,852.36219 0,-48"
|
||||
id="path3356"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 248,924.36219 -64,0"
|
||||
id="path3358"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 168,924.36219 -64,0"
|
||||
id="path3360"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 136,924.36219 0,48"
|
||||
id="path3362"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 88,924.36219 -32,0 0,48 64,0"
|
||||
id="path3364"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94280899px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 56,972.36219 0,48.00001"
|
||||
id="path3366"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 56,1036.3622 0,8"
|
||||
id="path3368"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 168,900.36219 -40,0 0,-24 40,0"
|
||||
id="path3389"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccc" />
|
||||
</g>
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer3"
|
||||
inkscape:label="1_2"
|
||||
style="display:none">
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 169,104 0,-24 -64,0"
|
||||
id="path3441"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccc" />
|
||||
</g>
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer2"
|
||||
inkscape:label="2"
|
||||
style="display:inline"
|
||||
sodipodi:insensitive="true">
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 112,104 40,0 0,-24 -40,0"
|
||||
id="path3394"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 216,56 -72,0"
|
||||
id="path3396"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 128,56 64,56"
|
||||
id="path3398"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 48,56 8,56"
|
||||
id="path3400"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 8,200 64,0"
|
||||
id="path3402"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 88,200 56,0"
|
||||
id="path3404"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 160,200 40,0"
|
||||
id="path3406"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 96,200 0,48"
|
||||
id="path3408"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 168,200 0,48"
|
||||
id="path3410"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 72,168 -24,0"
|
||||
id="path3416"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 32,168 8,168"
|
||||
id="path3418"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 216,8 0,128"
|
||||
id="path3422"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 8,8 216,8"
|
||||
id="path3426"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 8,8 8,248"
|
||||
id="path3428"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 216,248 8,248"
|
||||
id="path3430"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 216,248 0,-80"
|
||||
id="path3432"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 72,168 144,0"
|
||||
id="path3434"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 72,168 0,-32"
|
||||
id="path3436"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 72,136 144,0"
|
||||
id="path3438"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 11 KiB |
@@ -6,15 +6,55 @@
|
||||
|
||||
TEST(Angle, calc) {
|
||||
|
||||
ASSERT_EQ(0, Angle::getDEG(0,0, +1,0)); // to the right
|
||||
ASSERT_EQ(90, Angle::getDEG(0,0, 0,+1)); // upwards
|
||||
ASSERT_EQ(180, Angle::getDEG(0,0, -1,0)); // to the left
|
||||
ASSERT_EQ(270, Angle::getDEG(0,0, 0,-1)); // downwards
|
||||
ASSERT_EQ(0, Angle::getDEG_360(0,0, +1,0)); // to the right
|
||||
ASSERT_EQ(90, Angle::getDEG_360(0,0, 0,+1)); // upwards
|
||||
ASSERT_EQ(180, Angle::getDEG_360(0,0, -1,0)); // to the left
|
||||
ASSERT_EQ(270, Angle::getDEG_360(0,0, 0,-1)); // downwards
|
||||
|
||||
ASSERT_EQ(45, Angle::getDEG(0,0, +1,+1)); // to the upper right
|
||||
ASSERT_EQ(135, Angle::getDEG(0,0, -1,+1)); // to the upper left
|
||||
ASSERT_EQ(225, Angle::getDEG(0,0, -1,-1)); // to the lower left
|
||||
ASSERT_EQ(315, Angle::getDEG(0,0, +1,-1)); // to the lower right
|
||||
ASSERT_EQ(45, Angle::getDEG_360(0,0, +1,+1)); // to the upper right
|
||||
ASSERT_EQ(135, Angle::getDEG_360(0,0, -1,+1)); // to the upper left
|
||||
ASSERT_EQ(225, Angle::getDEG_360(0,0, -1,-1)); // to the lower left
|
||||
ASSERT_EQ(315, Angle::getDEG_360(0,0, +1,-1)); // to the lower right
|
||||
|
||||
}
|
||||
|
||||
TEST(Angle, diff) {
|
||||
|
||||
const float r = Angle::getRAD_2PI(0,0, +1,0); // to the right
|
||||
const float u = Angle::getRAD_2PI(0,0, 0,+1); // upwards
|
||||
const float l = Angle::getRAD_2PI(0,0, -1,0); // to the left
|
||||
const float d = Angle::getRAD_2PI(0,0, 0,-1); // downwards
|
||||
|
||||
const float ur = Angle::getRAD_2PI(0,0, +1,+1); // to the upper right
|
||||
const float ul = Angle::getRAD_2PI(0,0, -1,+1); // to the upper left
|
||||
const float dl = Angle::getRAD_2PI(0,0, -1,-1); // to the lower left
|
||||
const float dr = Angle::getRAD_2PI(0,0, +1,-1); // to the lower right
|
||||
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(r, u), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(u, r), 0.0001);
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(u, l), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(l, u), 0.0001);
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(l, d), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(d, l), 0.0001);
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(d, r), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(r, d), 0.0001);
|
||||
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(ur, ul), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(ul, ur), 0.0001);
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(ul, dl), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(dl, ul), 0.0001);
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(dl, dr), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(dr, dl), 0.0001);
|
||||
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(dr, ur), 0.0001);
|
||||
ASSERT_NEAR(M_PI_2, Angle::getDiffRAD_2PI_PI(ur, dr), 0.0001);
|
||||
|
||||
}
|
||||
|
||||
|
||||
29
tests/grid/GridImportance.cpp
Normal file
29
tests/grid/GridImportance.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../Tests.h"
|
||||
#include "../../grid/factory/GridImportance.h"
|
||||
#include "../../grid/factory/GridFactory.h"
|
||||
#include "../../floorplan/FloorplanFactorySVG.h"
|
||||
|
||||
#include "Plot.h"
|
||||
|
||||
TEST(GridImportance, a) {
|
||||
|
||||
|
||||
|
||||
Grid<20, GP> g;
|
||||
GridFactory<20, GP> gf(g);
|
||||
FloorplanFactorySVG fpf(getDataFile("fp1.svg"), 6);
|
||||
|
||||
Floor f1 = fpf.getFloor("1");
|
||||
gf.addFloor(f1, 20);
|
||||
gf.removeIsolated();
|
||||
|
||||
GridImportance gi;
|
||||
gi.addImportance(g, 20);
|
||||
|
||||
plot(g);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
66
tests/grid/Plot.h
Normal file
66
tests/grid/Plot.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef PLOT_H
|
||||
#define PLOT_H
|
||||
|
||||
|
||||
#include <KLib/misc/gnuplot/Gnuplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplotElementPoints.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplotElementColorPoints.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplotElementLines.h>
|
||||
|
||||
|
||||
class GP : public GridNode, public GridPoint {
|
||||
public:
|
||||
float imp = 1.0f;
|
||||
public:
|
||||
GP() : GridNode(), GridPoint() {;}
|
||||
GP(int x, int y, int z) : GridNode(), GridPoint(x,y,z) {;}
|
||||
|
||||
};
|
||||
|
||||
template <int gridSize_cm, typename T> void plot(Grid<gridSize_cm, T>& g) {
|
||||
|
||||
K::Gnuplot gp;
|
||||
K::GnuplotSplot splot;
|
||||
K::GnuplotSplotElementColorPoints points;
|
||||
K::GnuplotSplotElementLines lines;
|
||||
|
||||
gp << "set ticslevel 0\n";
|
||||
gp << "set view equal xyz\n";
|
||||
gp << "set cbrange[0.5:1.0]\n";
|
||||
gp << "set palette gray negative\n";
|
||||
|
||||
std::set<uint64_t> done;
|
||||
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < g.getNumNodes(); ++i) {
|
||||
const GP& n1 = g[i];
|
||||
points.add(K::GnuplotPoint3(n1.x_cm, n1.y_cm, n1.z_cm), n1.imp);
|
||||
|
||||
for (int n = 0; n < n1.getNumNeighbors(); ++n) {
|
||||
const GP& n2 = n1.getNeighbor(n, g);
|
||||
if (done.find(g.getUID(n2)) == done.end()) {
|
||||
K::GnuplotPoint3 p1(n1.x_cm, n1.y_cm, n1.z_cm);
|
||||
K::GnuplotPoint3 p2(n2.x_cm, n2.y_cm, n2.z_cm);
|
||||
lines.addSegment(p1, p2);
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
done.insert(g.getUID(n1));
|
||||
|
||||
}
|
||||
|
||||
points.setPointSize(1);
|
||||
//splot.add(&lines);
|
||||
splot.add(&points);
|
||||
|
||||
gp.draw(splot);
|
||||
gp.flush();
|
||||
|
||||
sleep(100);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // PLOT_H
|
||||
@@ -27,20 +27,20 @@ TEST(BBox, intersect) {
|
||||
GridNodeBBox bb1(GridPoint(20,20,20), 20);
|
||||
|
||||
// left
|
||||
ASSERT_FALSE(bb1.intersects( Line2D(9, -999, 9, +999) ));
|
||||
ASSERT_TRUE (bb1.intersects( Line2D(11, -999, 11, +999) ));
|
||||
ASSERT_FALSE(bb1.intersects( Line2(9, -999, 9, +999) ));
|
||||
ASSERT_TRUE (bb1.intersects( Line2(11, -999, 11, +999) ));
|
||||
|
||||
// right
|
||||
ASSERT_TRUE (bb1.intersects( Line2D(29, -999, 29, +999) ));
|
||||
ASSERT_FALSE(bb1.intersects( Line2D(31, -999, 31, +999) ));
|
||||
ASSERT_TRUE (bb1.intersects( Line2(29, -999, 29, +999) ));
|
||||
ASSERT_FALSE(bb1.intersects( Line2(31, -999, 31, +999) ));
|
||||
|
||||
// top
|
||||
ASSERT_FALSE(bb1.intersects( Line2D(-999, 9, +999, 9) ));
|
||||
ASSERT_TRUE (bb1.intersects( Line2D(-999, 11, +999, 11) ));
|
||||
ASSERT_FALSE(bb1.intersects( Line2(-999, 9, +999, 9) ));
|
||||
ASSERT_TRUE (bb1.intersects( Line2(-999, 11, +999, 11) ));
|
||||
|
||||
// bottom
|
||||
ASSERT_TRUE (bb1.intersects( Line2D(-999, 29, +999, 29) ));
|
||||
ASSERT_FALSE(bb1.intersects( Line2D(-999, 31, +999, 31) ));
|
||||
ASSERT_TRUE (bb1.intersects( Line2(-999, 29, +999, 29) ));
|
||||
ASSERT_FALSE(bb1.intersects( Line2(-999, 31, +999, 31) ));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,15 @@ TEST(Grid, BBox) {
|
||||
|
||||
Grid<20, GP> grid;
|
||||
int idx = grid.add(GP(40,40,40));
|
||||
ASSERT_EQ(30, grid.getBBox(idx).x1_cm);
|
||||
ASSERT_EQ(50, grid.getBBox(idx).x2_cm);
|
||||
ASSERT_EQ(30, grid.getBBox(idx).y1_cm);
|
||||
ASSERT_EQ(50, grid.getBBox(idx).y2_cm);
|
||||
ASSERT_EQ(30, grid.getBBox(idx).getMin().x);
|
||||
ASSERT_EQ(50, grid.getBBox(idx).getMax().x);
|
||||
ASSERT_EQ(30, grid.getBBox(idx).getMin().y);
|
||||
ASSERT_EQ(50, grid.getBBox(idx).getMax().y);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(Grid, neighbors) {
|
||||
TEST(Grid, connectBiDir) {
|
||||
|
||||
Grid<1, GP> grid;
|
||||
|
||||
@@ -54,10 +54,10 @@ TEST(Grid, neighbors) {
|
||||
int idx4 = grid.add(GP( 1, 0, 0));
|
||||
int idx5 = grid.add(GP(-1, 0, 0));
|
||||
|
||||
grid.connect(idx1, idx2);
|
||||
grid.connect(idx1, idx3);
|
||||
grid.connect(idx1, idx4);
|
||||
grid.connect(idx1, idx5);
|
||||
grid.connectBiDir(idx1, idx2);
|
||||
grid.connectBiDir(idx1, idx3);
|
||||
grid.connectBiDir(idx1, idx4);
|
||||
grid.connectBiDir(idx1, idx5);
|
||||
|
||||
ASSERT_EQ(4, grid.getNumNeighbors(idx1));
|
||||
ASSERT_EQ(1, grid.getNumNeighbors(idx2));
|
||||
@@ -65,6 +65,54 @@ TEST(Grid, neighbors) {
|
||||
ASSERT_EQ(1, grid.getNumNeighbors(idx4));
|
||||
ASSERT_EQ(1, grid.getNumNeighbors(idx5));
|
||||
|
||||
ASSERT_EQ(grid[idx2], grid.getNeighbor(idx1, 0));
|
||||
ASSERT_EQ(grid[idx3], grid.getNeighbor(idx1, 1));
|
||||
ASSERT_EQ(grid[idx4], grid.getNeighbor(idx1, 2));
|
||||
ASSERT_EQ(grid[idx5], grid.getNeighbor(idx1, 3));
|
||||
|
||||
}
|
||||
|
||||
TEST(Grid, disconnectBiDir) {
|
||||
|
||||
Grid<1, GP> grid;
|
||||
|
||||
int idx1 = grid.add(GP( 0, 0, 0));
|
||||
int idx2 = grid.add(GP( 0, 1, 0));
|
||||
int idx3 = grid.add(GP( 0,-1, 0));
|
||||
int idx4 = grid.add(GP( 1, 0, 0));
|
||||
int idx5 = grid.add(GP(-1, 0, 0));
|
||||
|
||||
grid.connectBiDir(idx1, idx2);
|
||||
grid.connectBiDir(idx1, idx3);
|
||||
grid.connectBiDir(idx1, idx4);
|
||||
grid.connectBiDir(idx1, idx5);
|
||||
|
||||
// remove 1 <-> 4
|
||||
grid.disconnectBiDir(idx1, idx4);
|
||||
ASSERT_EQ(3, grid.getNumNeighbors(idx1));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(idx4));
|
||||
ASSERT_EQ(grid[idx2], grid.getNeighbor(idx1, 0));
|
||||
ASSERT_EQ(grid[idx3], grid.getNeighbor(idx1, 1));
|
||||
ASSERT_EQ(grid[idx5], grid.getNeighbor(idx1, 2));
|
||||
|
||||
// remove 1 <-> 5
|
||||
grid.disconnectBiDir(idx1, idx5);
|
||||
ASSERT_EQ(2, grid.getNumNeighbors(idx1));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(idx5));
|
||||
ASSERT_EQ(grid[idx2], grid.getNeighbor(idx1, 0));
|
||||
ASSERT_EQ(grid[idx3], grid.getNeighbor(idx1, 1));
|
||||
|
||||
// remove 1 <-> 2
|
||||
grid.disconnectBiDir(idx1, idx2);
|
||||
ASSERT_EQ(1, grid.getNumNeighbors(idx1));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(idx2));
|
||||
ASSERT_EQ(grid[idx3], grid.getNeighbor(idx1, 0));
|
||||
|
||||
// remove 1 <-> 2
|
||||
grid.disconnectBiDir(idx1, idx3);
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(idx1));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(idx3));
|
||||
|
||||
}
|
||||
|
||||
TEST(Grid, uid) {
|
||||
@@ -81,6 +129,87 @@ TEST(Grid, uid) {
|
||||
|
||||
}
|
||||
|
||||
TEST(Grid, remove) {
|
||||
|
||||
Grid<1, GP> grid;
|
||||
|
||||
GP gp1( 0, 0, 0);
|
||||
GP gp2( 0, 1, 0);
|
||||
GP gp3( 0,-1, 0);
|
||||
GP gp4( 1, 0, 0);
|
||||
GP gp5(-1, 0, 0);
|
||||
|
||||
int idx1 = grid.add(gp1);
|
||||
int idx2 = grid.add(gp2);
|
||||
int idx3 = grid.add(gp3);
|
||||
int idx4 = grid.add(gp4);
|
||||
int idx5 = grid.add(gp5);
|
||||
|
||||
grid.connectBiDir(idx1, idx2);
|
||||
grid.connectBiDir(idx1, idx3);
|
||||
grid.connectBiDir(idx1, idx4);
|
||||
grid.connectBiDir(idx1, idx5);
|
||||
|
||||
grid.remove(idx1);
|
||||
grid.cleanup();
|
||||
|
||||
ASSERT_EQ(4, grid.getNumNodes());
|
||||
ASSERT_EQ(gp2, grid[0]);
|
||||
ASSERT_EQ(gp3, grid[1]);
|
||||
ASSERT_EQ(gp4, grid[2]);
|
||||
ASSERT_EQ(gp5, grid[3]);
|
||||
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(grid[0]));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(grid[1]));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(grid[2]));
|
||||
ASSERT_EQ(0, grid.getNumNeighbors(grid[3]));
|
||||
|
||||
}
|
||||
|
||||
TEST(Grid, neighborIter) {
|
||||
|
||||
Grid<1, GP> grid;
|
||||
|
||||
int idx1 = grid.add(GP( 0, 0, 0));
|
||||
int idx2 = grid.add(GP( 0, 1, 0));
|
||||
int idx3 = grid.add(GP( 0,-1, 0));
|
||||
int idx4 = grid.add(GP( 1, 0, 0));
|
||||
int idx5 = grid.add(GP(-1, 0, 0));
|
||||
|
||||
grid.connectBiDir(idx1, idx2);
|
||||
grid.connectBiDir(idx1, idx3);
|
||||
grid.connectBiDir(idx1, idx4);
|
||||
grid.connectBiDir(idx1, idx5);
|
||||
|
||||
int i = 0;
|
||||
for (GP& node : grid.neighbors(idx1)) {++i;}
|
||||
ASSERT_EQ(4, i);
|
||||
|
||||
}
|
||||
|
||||
TEST(Grid, bbox) {
|
||||
|
||||
Grid<1, GP> grid;
|
||||
|
||||
int idx1 = grid.add(GP( 0, 0, 0));
|
||||
int idx2 = grid.add(GP( 0, 1, 0));
|
||||
int idx3 = grid.add(GP( 0,-1, 0));
|
||||
int idx4 = grid.add(GP( 1, 0, 0));
|
||||
int idx5 = grid.add(GP(-1, 0, 0));
|
||||
|
||||
BBox3 bb = grid.getBBox();
|
||||
|
||||
ASSERT_EQ(bb.getMin().x, -1);
|
||||
ASSERT_EQ(bb.getMin().y, -1);
|
||||
ASSERT_EQ(bb.getMin().z, 0);
|
||||
|
||||
ASSERT_EQ(bb.getMax().x, +1);
|
||||
ASSERT_EQ(bb.getMax().y, +1);
|
||||
ASSERT_EQ(bb.getMax().z, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(Grid, nearest) {
|
||||
|
||||
Grid<20, GP> grid;
|
||||
|
||||
@@ -4,42 +4,35 @@
|
||||
#include "../../grid/factory/GridFactory.h"
|
||||
#include "../../floorplan/FloorplanFactorySVG.h"
|
||||
|
||||
#include <KLib/misc/gnuplot/Gnuplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplotElementPoints.h>
|
||||
|
||||
class GP : public GridNode, public GridPoint {
|
||||
public:
|
||||
GP() : GridNode(), GridPoint() {;}
|
||||
GP(int x, int y, int z) : GridNode(), GridPoint(x,y,z) {;}
|
||||
|
||||
};
|
||||
#include "Plot.h"
|
||||
|
||||
TEST(GridFactory, create) {
|
||||
|
||||
Grid<20, GP> g;
|
||||
Grid<20, GP> gInv;
|
||||
|
||||
GridFactory<20, GP> gf(g);
|
||||
FloorplanFactorySVG fpf(getDataFile("test.svg"), 2);
|
||||
FloorplanFactorySVG fpf(getDataFile("fp1.svg"), 4);
|
||||
Floor f1 = fpf.getFloor("1");
|
||||
Floor f2 = fpf.getFloor("2");
|
||||
Stairs s1_2 = fpf.getStairs("1_2");
|
||||
|
||||
gf.addFloor(f1, 0);
|
||||
gf.addFloor(f1, 20);
|
||||
gf.addFloor(f2, 340);
|
||||
gf.addStairs(s1_2, 20, 340);
|
||||
gf.removeIsolated();
|
||||
|
||||
K::Gnuplot gp;
|
||||
K::GnuplotSplot splot;
|
||||
K::GnuplotSplotElementPoints points;
|
||||
GridFactory<20, GP> gfInv(gInv);
|
||||
gfInv.addInverted(g, 20);
|
||||
gfInv.addInverted(g, 340);
|
||||
|
||||
for (int i = 0; i < g.getNumNodes(); ++i) {
|
||||
const GP& node = g[i];
|
||||
points.add(K::GnuplotPoint3(node.x_cm, node.y_cm, node.z_cm));
|
||||
}
|
||||
|
||||
splot.add(&points);
|
||||
gp.draw(splot);
|
||||
gp.flush();
|
||||
|
||||
sleep(10);
|
||||
// plot(gInv);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user