Skip to content

Commit

Permalink
OBB
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed May 6, 2024
1 parent 22b36f7 commit 618adf3
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 29 deletions.
33 changes: 20 additions & 13 deletions src/spatialjoin/GeometryCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ sj::Line sj::GeometryCache<sj::Line>::getFromDisk(size_t off,
}

// OBB
ret.obb.getOuter().resize(5);
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);
readPoly(_geomsFReads[tid], ret.obb);

return ret;
}
Expand Down Expand Up @@ -172,7 +170,8 @@ sj::Area sj::GeometryCache<sj::Area>::getFromDisk(size_t off,
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.area), sizeof(double));

// outer area
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.outerArea), sizeof(double));
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.outerArea),
sizeof(double));

// simplified inner
// readPoly(_geomsFReads[tid], ret.inner);
Expand Down Expand Up @@ -201,9 +200,7 @@ sj::Area sj::GeometryCache<sj::Area>::getFromDisk(size_t off,
// }

// OBB
ret.obb.getOuter().resize(5);
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);
readPoly(_geomsFReads[tid], ret.obb);

return ret;
}
Expand Down Expand Up @@ -291,9 +288,14 @@ size_t sj::GeometryCache<sj::Line>::add(const sj::Line& val) {
_geomsOffset += sizeof(uint32_t) + sizeof(sj::boxids::BoxId) * size;

// OBB
_geomsF.write(reinterpret_cast<const char*>(&val.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);
_geomsOffset += sizeof(util::geo::I32Point) * 5;
// uint8_t obbSize = val.obb.getOuter().size();
// _geomsF.write(reinterpret_cast<const char*>(&obbSize), sizeof(uint8_t));
// if (obbSize > 0) {
// _geomsF.write(reinterpret_cast<const char*>(&val.obb.getOuter()[0]),
// sizeof(util::geo::I32Point) * obbSize);
// }
// _geomsOffset += sizeof(uint8_t) + sizeof(util::geo::I32Point) * obbSize;
writePoly(val.obb);

return ret;
}
Expand Down Expand Up @@ -361,9 +363,14 @@ size_t sj::GeometryCache<sj::Area>::add(const sj::Area& val) {
// }

// OBB
_geomsF.write(reinterpret_cast<const char*>(&val.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);
_geomsOffset += sizeof(util::geo::I32Point) * 5;
// uint8_t obbSize = val.obb.getOuter().size();
// _geomsF.write(reinterpret_cast<const char*>(&obbSize), sizeof(uint8_t));
// if (obbSize > 0) {
// _geomsF.write(reinterpret_cast<const char*>(&val.obb.getOuter()[0]),
// sizeof(util::geo::I32Point) * obbSize);
// }
// _geomsOffset += sizeof(uint8_t) + sizeof(util::geo::I32Point) * obbSize;
writePoly(val.obb);

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/spatialjoin/GeometryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct Area {
// std::unordered_map<int32_t, util::geo::I32XSortedMultiPolygon> cutouts;

// OBB
util::geo::I32Polygon obb;
util::geo::I32XSortedPolygon obb;
};

struct SimpleLine {
Expand Down Expand Up @@ -88,7 +88,7 @@ struct Line {
std::vector<sj::boxids::BoxId> boxIds;

// OBB
util::geo::I32Polygon obb;
util::geo::I32XSortedPolygon obb;
};

struct Point {
Expand Down
3 changes: 1 addition & 2 deletions src/spatialjoin/SpatialJoinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ static const char* AUTHORS = "Patrick Brosi <[email protected]>";
// _____________________________________________________________________________
void printHelp(int argc, char** argv) {
UNUSED(argc);
<<<<<<< HEAD
std::cout
<< "\n"
<< "(C) 2023-" << YEAR << " " << COPY << "\n"
Expand Down Expand Up @@ -209,7 +208,7 @@ int main(int argc, char** argv) {
size_t NUM_THREADS = std::thread::hardware_concurrency();

Sweeper sweeper({NUM_THREADS, prefix, intersects, contains, covers, touches,
equals, overlaps, crosses, suffix, useBoxIds, useArea, useObb},
equals, overlaps, crosses, suffix, useBoxIds, useArea, useOBB},
useCache, cache, output);

if (!useCache) {
Expand Down
1 change: 1 addition & 0 deletions src/spatialjoin/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ inline std::string Stats::toString() {

t = double(timeBoxIdIsectLinePoint) / 1000000000.0;
ss << "time for box ID intersections LINE/POINT: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeOBBIsectAreaArea) / 1000000000.0;
ss << "time for obb intersections AREA/AREA: " << t << " s ("
Expand Down
61 changes: 51 additions & 10 deletions src/spatialjoin/Sweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@ void Sweeper::add(const I32Polygon& poly, const std::string& gid,
boxIds = packBoxIds(getBoxIds(spoly, poly, box, areaSize));

util::geo::I32Polygon obb;
if (_cfg.useOBB) obb = util::geo::convexHull(util::geo::getOrientedEnvelope(poly));
if (_cfg.useOBB)
obb = util::geo::convexHull(util::geo::getOrientedEnvelope(poly));

if (subid > 0)
multiAdd(gid, box.getLowerLeft().getX(), box.getUpperRight().getX());

if (!_cfg.useArea) areaSize = 0;

size_t id =
_areaCache.add({spoly, box, gid, subid, areaSize, outerAreaSize, boxIds, obb});
size_t id = _areaCache.add(
{spoly, box, gid, subid, areaSize, outerAreaSize, boxIds, obb});

diskAdd({id, box.getLowerLeft().getY(), box.getUpperRight().getY(),
box.getLowerLeft().getX(), false, POLYGON, areaSize});
Expand All @@ -168,7 +169,8 @@ void Sweeper::add(const I32Line& line, const std::string& gid, size_t subid) {
if (_cfg.useBoxIds) boxIds = packBoxIds(getBoxIds(line, box));
double len = util::geo::len(line);
util::geo::I32Polygon obb;
if (_cfg.useOBB) obb = util::geo::convexHull(util::geo::getOrientedEnvelope(line));
if (_cfg.useOBB)
obb = util::geo::convexHull(util::geo::getOrientedEnvelope(line));

if (subid > 0)
multiAdd(gid, box.getLowerLeft().getX(), box.getUpperRight().getX());
Expand Down Expand Up @@ -551,9 +553,9 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Area* a,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = util::geo::intersects(a->obb, b->obb);
auto r = util::geo::intersectsContainsCovers(a->obb, b->obb);
_stats[t].timeOBBIsectAreaArea += TOOK(ts);
if (!r) {
if (!std::get<0>(r)) {
return {0, 0, 0, 0, 0};
}
}
Expand Down Expand Up @@ -596,9 +598,9 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = util::geo::intersects(a->obb, b->obb);
auto r = util::geo::intersectsContainsCovers(a->obb, b->obb);
_stats[t].timeOBBIsectAreaLine += TOOK(ts);
if (!r) {
if (!std::get<0>(r)) {
return {0, 0, 0, 0, 0};
}
}
Expand Down Expand Up @@ -637,9 +639,9 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = util::geo::intersects(a->obb, b->obb);
auto r = util::geo::intersectsContainsCovers(a->obb, b->obb);
_stats[t].timeOBBIsectLineLine += TOOK(ts);
if (!r) {
if (!std::get<0>(r)) {
return {0, 0, 0, 0, 0};
}
}
Expand All @@ -665,6 +667,16 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const SimpleLine* a,
const Area* b,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = intersectsContainsCovers(
I32XSortedLine(LineSegment<int32_t>(a->a, a->b)), b->obb);
_stats[t].timeOBBIsectAreaLine += TOOK(ts);
if (!std::get<0>(r)) {
return {0, 0, 0, 0, 0};
}
}

if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect({{1, 0}, {getBoxId(a->a), 0}}, b->boxIds);
Expand Down Expand Up @@ -721,6 +733,16 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const SimpleLine* a,
std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const SimpleLine* a,
const Line* b,
size_t t) const {
// if (_cfg.useOBB) {
// auto ts = TIME();
// auto r = intersectsContainsCovers(
// I32XSortedLine(LineSegment<int32_t>(a->a, a->b)), b->obb);
// _stats[t].timeOBBIsectLineLine += TOOK(ts);
// if (!std::get<0>(r)) {
// return {0, 0, 0, 0, 0};
// }
// }

if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect({{1, 0}, {getBoxId(a->a), 0}}, b->boxIds);
Expand All @@ -743,6 +765,16 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const SimpleLine* a,
std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
const SimpleLine* b,
size_t t) const {
// if (_cfg.useOBB) {
// auto ts = TIME();
// auto r = intersectsContainsCovers(
// I32XSortedLine(LineSegment<int32_t>(b->a, b->b)), a->obb);
// _stats[t].timeOBBIsectLineLine += TOOK(ts);
// if (!std::get<0>(r)) {
// return {0, 0, 0, 0, 0};
// }
// }

if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect(a->boxIds, {{1, 0}, {getBoxId(b->a), 0}});
Expand All @@ -764,6 +796,15 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
// _____________________________________________________________________________
std::pair<bool, bool> Sweeper::check(const I32Point& a, const Area* b,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = containsCovers(a, b->obb);
_stats[t].timeOBBIsectAreaPoint += TOOK(ts);
if (!std::get<1>(r)) {
return {0, 0};
}
}

if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect({{1, 0}, {getBoxId(a), 0}}, b->boxIds);
Expand Down
2 changes: 1 addition & 1 deletion src/spatialjoin/tests/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using sj::Sweeper;
// _____________________________________________________________________________
std::string fullRun(const std::string& file) {
Sweeper sweeper({1, "$", " intersects ", " contains ", " covers ",
" touches ", " equals ", " overlaps ", " crosses ", "$\n", true, true},
" touches ", " equals ", " overlaps ", " crosses ", "$\n", true, true, true},
false, ".", ".resTmp");

size_t gid = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/util
Submodule util updated 2 files
+105 −36 geo/Geo.h
+12 −0 tests/TestMain.cpp

0 comments on commit 618adf3

Please sign in to comment.