Skip to content

Commit 5014e84

Browse files
committed
only write OBB and inner/outer to cache if required (previously written as empty polygons as placeholders)
1 parent efa36dc commit 5014e84

File tree

5 files changed

+175
-127
lines changed

5 files changed

+175
-127
lines changed

src/spatialjoin/GeometryCache.cpp

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright 2023, University of Freiburg
22
// Authors: Patrick Brosi <[email protected]>
33

4+
#include "GeometryCache.h"
5+
46
#include <fstream>
57
#include <iostream>
68
#include <mutex>
79
#include <vector>
810

9-
#include "GeometryCache.h"
1011
#include "util/geo/Geo.h"
1112

1213
const static size_t MAX_MEM_CACHE_SIZE = 1 * 1024 * 1024 * 20l;
@@ -200,8 +201,10 @@ std::pair<size_t, sj::Line> sj::GeometryCache<sj::Line>::getFrom(
200201
estSize += sizeof(sj::boxids::BoxId) * numBoxIds;
201202
}
202203

203-
// OBB
204-
estSize += readPoly(str, ret.obb);
204+
if (_opts.storeOBB) {
205+
// OBB
206+
estSize += readPoly(str, ret.obb);
207+
}
205208

206209
return {estSize, ret};
207210
}
@@ -254,25 +257,31 @@ std::pair<size_t, sj::Area> sj::GeometryCache<sj::Area>::getFrom(
254257
estSize += sizeof(sj::boxids::BoxId) * numBoxIds;
255258
}
256259

257-
// OBB
258-
estSize += readPoly(str, ret.obb);
260+
if (_opts.storeOBB) {
261+
// OBB
262+
estSize += readPoly(str, ret.obb);
263+
}
259264

260-
// simplified inner
261-
estSize += readPoly(str, ret.inner);
265+
if (_opts.storeInnerOuter) {
266+
// simplified inner
267+
estSize += readPoly(str, ret.inner);
262268

263-
if (!ret.inner.empty()) {
264-
str.read(reinterpret_cast<char*>(&ret.innerBox), sizeof(util::geo::I32Box));
265-
str.read(reinterpret_cast<char*>(&ret.innerOuterArea), sizeof(double));
266-
estSize += sizeof(double) + sizeof(util::geo::I32Box);
267-
}
269+
if (!ret.inner.empty()) {
270+
str.read(reinterpret_cast<char*>(&ret.innerBox),
271+
sizeof(util::geo::I32Box));
272+
str.read(reinterpret_cast<char*>(&ret.innerOuterArea), sizeof(double));
273+
estSize += sizeof(double) + sizeof(util::geo::I32Box);
274+
}
268275

269-
// simplified outer
270-
estSize += readPoly(str, ret.outer);
276+
// simplified outer
277+
estSize += readPoly(str, ret.outer);
271278

272-
if (!ret.outer.empty()) {
273-
str.read(reinterpret_cast<char*>(&ret.outerBox), sizeof(util::geo::I32Box));
274-
str.read(reinterpret_cast<char*>(&ret.outerOuterArea), sizeof(double));
275-
estSize += sizeof(double) + sizeof(util::geo::I32Box);
279+
if (!ret.outer.empty()) {
280+
str.read(reinterpret_cast<char*>(&ret.outerBox),
281+
sizeof(util::geo::I32Box));
282+
str.read(reinterpret_cast<char*>(&ret.outerOuterArea), sizeof(double));
283+
estSize += sizeof(double) + sizeof(util::geo::I32Box);
284+
}
276285
}
277286

278287
return {estSize, ret};
@@ -281,7 +290,7 @@ std::pair<size_t, sj::Area> sj::GeometryCache<sj::Area>::getFrom(
281290
// ____________________________________________________________________________
282291
template <>
283292
size_t sj::GeometryCache<sj::Point>::writeTo(const sj::Point& val,
284-
std::ostream& str) {
293+
std::ostream& str) const {
285294
size_t ret = 0;
286295

287296
// id
@@ -333,7 +342,7 @@ size_t sj::GeometryCache<W>::add(const std::string& raw) {
333342
// ____________________________________________________________________________
334343
template <>
335344
size_t sj::GeometryCache<sj::SimpleArea>::writeTo(const sj::SimpleArea& val,
336-
std::ostream& str) {
345+
std::ostream& str) const {
337346
size_t ret = 0;
338347

339348
// geom
@@ -362,7 +371,7 @@ size_t sj::GeometryCache<sj::SimpleArea>::writeTo(const sj::SimpleArea& val,
362371

363372
template <>
364373
size_t sj::GeometryCache<sj::SimpleLine>::writeTo(const sj::SimpleLine& val,
365-
std::ostream& str) {
374+
std::ostream& str) const {
366375
size_t ret = 0;
367376

368377
// geoms
@@ -384,7 +393,7 @@ size_t sj::GeometryCache<sj::SimpleLine>::writeTo(const sj::SimpleLine& val,
384393
// ____________________________________________________________________________
385394
template <>
386395
size_t sj::GeometryCache<sj::Line>::writeTo(const sj::Line& val,
387-
std::ostream& str) {
396+
std::ostream& str) const {
388397
size_t ret = 0;
389398

390399
// geoms
@@ -420,16 +429,18 @@ size_t sj::GeometryCache<sj::Line>::writeTo(const sj::Line& val,
420429

421430
ret += sizeof(uint32_t) + sizeof(sj::boxids::BoxId) * size;
422431

423-
// OBB
424-
ret += writePoly(val.obb, str);
432+
if (_opts.storeOBB) {
433+
// OBB
434+
ret += writePoly(val.obb, str);
435+
}
425436

426437
return ret;
427438
}
428439

429440
// ____________________________________________________________________________
430441
template <>
431442
size_t sj::GeometryCache<sj::Area>::writeTo(const sj::Area& val,
432-
std::ostream& str) {
443+
std::ostream& str) const {
433444
size_t ret = 0;
434445

435446
// geoms
@@ -469,35 +480,39 @@ size_t sj::GeometryCache<sj::Area>::writeTo(const sj::Area& val,
469480

470481
ret += sizeof(uint32_t) + sizeof(sj::boxids::BoxId) * size;
471482

472-
// OBB
473-
ret += writePoly(val.obb, str);
483+
if (_opts.storeOBB) {
484+
// OBB
485+
ret += writePoly(val.obb, str);
486+
}
474487

475-
// innerGeom
476-
ret += writePoly(val.inner, str);
488+
if (_opts.storeInnerOuter) {
489+
// innerGeom
490+
ret += writePoly(val.inner, str);
477491

478-
if (!val.inner.empty()) {
479-
str.write(reinterpret_cast<const char*>(&val.innerBox),
480-
sizeof(util::geo::I32Box));
481-
ret += sizeof(util::geo::I32Box);
492+
if (!val.inner.empty()) {
493+
str.write(reinterpret_cast<const char*>(&val.innerBox),
494+
sizeof(util::geo::I32Box));
495+
ret += sizeof(util::geo::I32Box);
482496

483-
// inner area
484-
str.write(reinterpret_cast<const char*>(&val.innerOuterArea),
485-
sizeof(double));
486-
ret += sizeof(double);
487-
}
497+
// inner area
498+
str.write(reinterpret_cast<const char*>(&val.innerOuterArea),
499+
sizeof(double));
500+
ret += sizeof(double);
501+
}
488502

489-
// outerGeom
490-
ret += writePoly(val.outer, str);
503+
// outerGeom
504+
ret += writePoly(val.outer, str);
491505

492-
if (!val.outer.empty()) {
493-
str.write(reinterpret_cast<const char*>(&val.outerBox),
494-
sizeof(util::geo::I32Box));
495-
ret += sizeof(util::geo::I32Box);
506+
if (!val.outer.empty()) {
507+
str.write(reinterpret_cast<const char*>(&val.outerBox),
508+
sizeof(util::geo::I32Box));
509+
ret += sizeof(util::geo::I32Box);
496510

497-
// outer area
498-
str.write(reinterpret_cast<const char*>(&val.outerOuterArea),
499-
sizeof(double));
500-
ret += sizeof(double);
511+
// outer area
512+
str.write(reinterpret_cast<const char*>(&val.outerOuterArea),
513+
sizeof(double));
514+
ret += sizeof(double);
515+
}
501516
}
502517

503518
return ret;

src/spatialjoin/GeometryCache.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ struct ValEntry {
117117

118118
const static size_t WRITE_BUFF_SIZE = 1024 * 1024 * 4l;
119119

120+
struct StorageOptions {
121+
bool storeOBB;
122+
bool storeInnerOuter;
123+
};
124+
120125
template <typename W>
121126
class GeometryCache {
122127
public:
123-
GeometryCache(size_t maxSize, size_t maxNumElements, size_t numthreads,
128+
GeometryCache(const StorageOptions& opts, size_t maxSize, size_t maxNumElements, size_t numthreads,
124129
const std::string& dir)
125-
: GeometryCache(maxSize, maxNumElements, numthreads, dir,
130+
: GeometryCache(opts, maxSize, maxNumElements, numthreads, dir,
126131
".spatialjoin"){};
127-
GeometryCache(size_t maxSize, size_t maxNumElements, size_t numthreads,
132+
GeometryCache(const StorageOptions& opts, size_t maxSize, size_t maxNumElements, size_t numthreads,
128133
const std::string& dir, const std::string& tmpPrefix)
129-
: _maxSize(maxSize),
134+
: _opts(opts),
135+
_maxSize(maxSize),
130136
_maxNumElements(maxNumElements),
131137
_numThreads(numthreads),
132138
_dir(dir),
@@ -160,7 +166,7 @@ class GeometryCache {
160166
}
161167

162168
size_t add(const std::string& raw);
163-
static size_t writeTo(const W& val, std::ostream& str);
169+
size_t writeTo(const W& val, std::ostream& str) const;
164170

165171
std::shared_ptr<W> get(size_t off, ssize_t tid) const;
166172
std::pair<size_t, W> getFrom(size_t off, std::istream& str) const;
@@ -210,6 +216,7 @@ class GeometryCache {
210216
_idMap;
211217
mutable std::vector<size_t> _valSizes;
212218

219+
StorageOptions _opts;
213220
size_t _maxSize, _maxNumElements, _numThreads;
214221
std::string _dir, _tmpPrefix;
215222
std::string _fName;

0 commit comments

Comments
 (0)