Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement obb checks for Line and Area #4

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/spatialjoin/GeometryCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ 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);
ret.obb.getOuter().resize(5);
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);

return ret;
}
Expand Down Expand Up @@ -195,9 +195,9 @@ 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);
ret.obb.getOuter().resize(5);
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);

return ret;
}
Expand Down Expand Up @@ -281,9 +281,9 @@ 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;
_geomsF.write(reinterpret_cast<const char*>(&val.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);
_geomsOffset += sizeof(util::geo::I32Point) * 5;

return ret;
}
Expand Down Expand Up @@ -347,9 +347,9 @@ 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;
_geomsF.write(reinterpret_cast<const char*>(&val.obb.getOuter()[0]),
sizeof(util::geo::I32Point) * 5);
_geomsOffset += sizeof(util::geo::I32Point) * 5;

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 @@ -53,7 +53,7 @@ struct Area {
// std::unordered_map<int32_t, util::geo::I32XSortedMultiPolygon> cutouts;

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

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

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

struct Point {
Expand Down
11 changes: 9 additions & 2 deletions src/spatialjoin/SpatialJoinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void printHelp(int argc, char** argv) {
<< "disable box id criteria for contains/intersect computation\n"
<< std::setw(41) << " --no-surface-area"
<< "disable surface area criteria for polygon contains\n"
<< std::setw(41) << " --no-oriented-envelope"
<< "disable oriented envelope cirteria for contains/intersect"
<< " computation\n"
<< std::endl;
}

Expand Down Expand Up @@ -219,6 +222,7 @@ int main(int argc, char** argv) {

bool useBoxIds = true;
bool useArea = true;
bool useOBB = true;

for (int i = 1; i < argc; i++) {
std::string cur = argv[i];
Expand Down Expand Up @@ -255,6 +259,9 @@ int main(int argc, char** argv) {
if (cur == "--no-surface-area") {
useArea = false;
}
if (cur == "--no-oriented-envelope") {
useOBB = false;
}
break;
case 1:
prefix = cur;
Expand Down Expand Up @@ -291,8 +298,8 @@ int main(int argc, char** argv) {

size_t NUM_THREADS = std::thread::hardware_concurrency();

Sweeper sweeper({NUM_THREADS, prefix, intersects, contains, suffix, useBoxIds, useArea}, useCache,
cache, output);
Sweeper sweeper({NUM_THREADS, prefix, intersects, contains, suffix, useBoxIds,
useArea, useOBB}, useCache, cache, output);

size_t gid = 0;

Expand Down
27 changes: 27 additions & 0 deletions src/spatialjoin/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ struct Stats {
uint64_t timeBoxIdIsectAreaPoint = 0;
uint64_t timeBoxIdIsectLineLine = 0;

uint64_t timeOBBIsectAreaArea = 0;
uint64_t timeOBBIsectAreaLine = 0;
uint64_t timeOBBIsectAreaPoint = 0;
uint64_t timeOBBIsectLineLine = 0;

uint64_t timeFullGeoCheckAreaArea = 0;
uint64_t timeFullGeoCheckAreaLine = 0;
uint64_t timeFullGeoCheckAreaPoint = 0;
Expand All @@ -34,6 +39,8 @@ inline std::string Stats::toString() {
double(timeGeoCacheRetrievalArea + timeGeoCacheRetrievalLine + timeWrite +
timeBoxIdIsectAreaArea + timeBoxIdIsectAreaLine +
timeBoxIdIsectAreaPoint + timeBoxIdIsectLineLine +
timeOBBIsectAreaArea + timeOBBIsectAreaLine +
timeOBBIsectAreaPoint + timeOBBIsectLineLine +
timeFullGeoCheckAreaArea + timeFullGeoCheckAreaLine +
timeFullGeoCheckAreaPoint + timeFullGeoCheckLineLine) /
1000000000.0;
Expand Down Expand Up @@ -64,6 +71,22 @@ inline std::string Stats::toString() {
ss << "time for box ID intersections LINE/LINE: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeOBBIsectAreaArea) / 1000000000.0;
ss << "time for obb intersections AREA/AREA: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeOBBIsectAreaLine) / 1000000000.0;
ss << "time for obb intersections AREA/LINE: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeOBBIsectAreaPoint) / 1000000000.0;
ss << "time for obb intersections AREA/POINT: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeOBBIsectLineLine) / 1000000000.0;
ss << "time for obb intersections LINE/LINE: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeFullGeoCheckAreaArea) / 1000000000.0;
ss << "time for " << fullGeoChecksAreaArea
<< " full geom checks AREA/AREA: " << t << " s (" << ((t / sum) * 100.0)
Expand Down Expand Up @@ -100,6 +123,10 @@ inline Stats operator+(const Stats& a, const Stats& b) {
a.timeBoxIdIsectAreaLine + b.timeBoxIdIsectAreaLine,
a.timeBoxIdIsectAreaPoint + b.timeBoxIdIsectAreaPoint,
a.timeBoxIdIsectLineLine + b.timeBoxIdIsectLineLine,
a.timeOBBIsectAreaArea + b.timeOBBIsectAreaArea,
a.timeOBBIsectAreaLine + b.timeOBBIsectAreaLine,
a.timeOBBIsectAreaPoint + b.timeOBBIsectAreaPoint,
a.timeOBBIsectLineLine + b.timeOBBIsectLineLine,
a.timeFullGeoCheckAreaArea + b.timeFullGeoCheckAreaArea,
a.timeFullGeoCheckAreaLine + b.timeFullGeoCheckAreaLine,
a.timeFullGeoCheckAreaPoint + b.timeFullGeoCheckAreaPoint,
Expand Down
31 changes: 30 additions & 1 deletion src/spatialjoin/Sweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ void Sweeper::add(const util::geo::I32Polygon& poly, const std::string& gid,
double areaSize = util::geo::area(poly);
BoxIdList boxIds;
if (_cfg.useBoxIds) boxIds = packBoxIds(getBoxIds(spoly, poly, box, areaSize));
util::geo::I32Polygon obb;
if (_cfg.useOBB) obb = util::geo::convexHull(util::geo::getOrientedEnvelope(poly));

if (!_cfg.useArea) areaSize = 0;

Expand All @@ -106,6 +108,7 @@ void Sweeper::add(const util::geo::I32Polygon& poly, const std::string& gid,
subid,
areaSize,
boxIds,
obb
});

diskAdd({id, box.getLowerLeft().getY(), box.getUpperRight().getY(),
Expand All @@ -128,6 +131,8 @@ void Sweeper::add(const util::geo::I32Line& line, const std::string& gid,
const auto& box = util::geo::getBoundingBox(line);
BoxIdList boxIds;
if (_cfg.useBoxIds) boxIds = packBoxIds(getBoxIds(line, box));
util::geo::I32Polygon obb;
if (_cfg.useOBB) obb = util::geo::convexHull(util::geo::getOrientedEnvelope(line));

if (line.size() == 2 && (!_cfg.useBoxIds || boxIds.front().first == 1) && subid == 0) {
// simple line
Expand All @@ -142,7 +147,7 @@ void Sweeper::add(const util::geo::I32Line& line, const std::string& gid,
const util::geo::I32XSortedLine sline(line);

size_t id = _lineCache.add(Line{
sline, box, gid, subid, boxIds, //{} // dummy
sline, box, gid, subid, boxIds, obb//{} // dummy
});

diskAdd({id, box.getLowerLeft().getY(), box.getUpperRight().getY(),
Expand Down Expand Up @@ -322,6 +327,14 @@ void Sweeper::sweep() {
// _____________________________________________________________________________
std::pair<bool, bool> Sweeper::check(const Area* a, const Area* b,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = util::geo::intersects(a->obb, b->obb);
_stats[t].timeOBBIsectAreaArea += TOOK(ts);
if (!r) {
return {0, 0};
}
}
if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect(a->boxIds, b->boxIds);
Expand Down Expand Up @@ -353,6 +366,14 @@ std::pair<bool, bool> Sweeper::check(const Area* a, const Area* b,
// _____________________________________________________________________________
std::pair<bool, bool> Sweeper::check(const Line* a, const Area* b,
size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = util::geo::intersects(a->obb, b->obb);
_stats[t].timeOBBIsectAreaLine += TOOK(ts);
if (!r) {
return {0, 0};
}
}
if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect(a->boxIds, b->boxIds);
Expand Down Expand Up @@ -383,6 +404,14 @@ std::pair<bool, bool> Sweeper::check(const Line* a, const Area* b,

// _____________________________________________________________________________
bool Sweeper::check(const Line* a, const Line* b, size_t t) const {
if (_cfg.useOBB) {
auto ts = TIME();
auto r = util::geo::intersects(a->obb, b->obb);
_stats[t].timeOBBIsectLineLine += TOOK(ts);
if (!r) {
return false;
}
}
if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect(a->boxIds, b->boxIds);
Expand Down
1 change: 1 addition & 0 deletions src/spatialjoin/Sweeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct SweeperCfg {
std::string& pairEnd;
bool useBoxIds;
bool useArea;
bool useOBB;
};

// buffer sizes _must_ be multiples of sizeof(BoxVal)
Expand Down
Loading