diff --git a/third_party/libspatialindex/larch64/include/spatialindex/Ball.h b/third_party/libspatialindex/larch64/include/spatialindex/Ball.h new file mode 100644 index 000000000..50299a9a6 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/Ball.h @@ -0,0 +1,98 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Peter Labadorf - plaba3.1415@gmail.com + ****************************************************************************** + * Copyright (c) 2023, Peter Labadorf + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +namespace SpatialIndex +{ + + class SIDX_DLL Ball: public Tools::IObject, public virtual IShape + { + public: + Ball(); + Ball(double radius, const Point& center); + Ball(double radius, const double *pCoords, uint32_t dimension); + Ball(const Ball& b); + ~Ball() override; + + virtual Ball& operator=(const Ball& b); + virtual bool operator==(const Ball& b) const; + + // + // IObject interface + // + + Ball* clone() override; + + // + // ISerializable interface + // + + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t *data) override; + void storeToByteArray(uint8_t **data, uint32_t &length) override; + + // + // IShape interface + // + + bool intersectsShape(const IShape &in) const override; + bool containsShape(const IShape &in) const override; + bool touchesShape(const IShape &in) const override; + void getCenter(SpatialIndex::Point &out) const override; + uint32_t getDimension() const override; + void getMBR(SpatialIndex::Region &out) const override; + double getArea() const override; + double getMinimumDistance(const IShape &in) const override; + + virtual bool containsLineSegment(const SpatialIndex::LineSegment *line) const; + virtual bool containsRegion(const SpatialIndex::Region *region) const; + + inline bool containsPoint(const Point *point) const + { + return getMinimumDistance(*point) <= m_centerPoint.m_dimension; + } + + inline bool containsBall(const Ball *ball) const + { + return getMinimumDistance(ball->m_centerPoint) + ball->m_radius <= m_radius; + } + + public: + double m_radius{0.0}; + Point m_centerPoint; + + }; // Ball + + SIDX_DLL std::ostream& operator<<(std::ostream& os, const Ball& ball); + +} + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/LineSegment.h b/third_party/libspatialindex/larch64/include/spatialindex/LineSegment.h new file mode 100644 index 000000000..5cd399cee --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/LineSegment.h @@ -0,0 +1,103 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + class SIDX_DLL LineSegment : public Tools::IObject, public virtual IShape + { + public: + LineSegment(); + LineSegment(const double* startPoint, const double* endPoint, uint32_t dimension); + LineSegment(const Point& startPoint, const Point& endPoint); + LineSegment(const LineSegment& l); + ~LineSegment() override; + + virtual LineSegment& operator=(const LineSegment& p); + virtual bool operator==(const LineSegment& p) const; + + // + // IObject interface + // + LineSegment* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& length) override; + + // + // IShape interface + // + bool intersectsShape(const IShape& in) const override; + bool containsShape(const IShape& in) const override; + bool touchesShape(const IShape& in) const override; + void getCenter(Point& out) const override; + uint32_t getDimension() const override; + void getMBR(Region& out) const override; + double getArea() const override; + double getMinimumDistance(const IShape& in) const override; + + virtual bool intersectsLineSegment(const LineSegment& l) const; + virtual bool intersectsRegion(const Region& p) const; + virtual double getMinimumDistance(const Point& p) const; + //virtual double getMinimumDistance(const Region& r) const; + virtual double getRelativeMinimumDistance(const Point& p) const; + virtual double getRelativeMaximumDistance(const Region& r) const; + virtual double getAngleOfPerpendicularRay(); + + virtual void makeInfinite(uint32_t dimension); + virtual void makeDimension(uint32_t dimension); + + public: + uint32_t m_dimension{0}; + double* m_pStartPoint{nullptr}; + double* m_pEndPoint{nullptr}; + + friend class Region; + friend class Point; + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const LineSegment& pt); + + protected: + + //some helpers for intersects methods + static double doubleAreaTriangle(const Point& a, const Point& b, const Point& c); + static bool leftOf(const Point& a, const Point& b, const Point& c); + static bool collinear(const Point& a, const Point& b, const Point& c); + static bool between(const Point& a, const Point& b, const Point& c); + static bool between(double a, double b, double c); + static bool intersectsProper(const Point& a, const Point& b, const Point& c, const Point& d); + static bool intersects(const Point& a, const Point& b, const Point& c, const Point& d); + + }; // LineSegment + + SIDX_DLL std::ostream& operator<<(std::ostream& os, const LineSegment& pt); +} + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/MVRTree.h b/third_party/libspatialindex/larch64/include/spatialindex/MVRTree.h new file mode 100644 index 000000000..492e7428c --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/MVRTree.h @@ -0,0 +1,88 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + namespace MVRTree + { + enum MVRTreeVariant + { + RV_LINEAR = 0x0, + RV_QUADRATIC, + RV_RSTAR + }; + + enum PersistenObjectIdentifier + { + PersistentIndex = 0x1, + PersistentLeaf = 0x2 + }; + + enum RangeQueryType + { + ContainmentQuery = 0x1, + IntersectionQuery = 0x2 + }; + + class SIDX_DLL Data : public IData, public Tools::ISerializable + { + public: + Data(uint32_t len, uint8_t* pData, TimeRegion& r, id_type id); + ~Data() override; + + Data* clone() override; + id_type getIdentifier() const override; + void getShape(IShape** out) const override; + void getData(uint32_t& len, uint8_t** data) const override; + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + id_type m_id; + TimeRegion m_region; + uint8_t* m_pData; + uint32_t m_dataLength; + }; // Data + + SIDX_DLL ISpatialIndex* returnMVRTree(IStorageManager& ind, Tools::PropertySet& in); + SIDX_DLL ISpatialIndex* createNewMVRTree( + IStorageManager& in, + double fillFactor, + uint32_t indexCapacity, + uint32_t leafCapacity, + uint32_t dimension, + MVRTreeVariant rv, + id_type& out_indexIdentifier + ); + SIDX_DLL ISpatialIndex* loadMVRTree( + IStorageManager& in, + id_type indexIdentifier + ); + } +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/MovingPoint.h b/third_party/libspatialindex/larch64/include/spatialindex/MovingPoint.h new file mode 100644 index 000000000..ea9c35fbc --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/MovingPoint.h @@ -0,0 +1,85 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2003, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + class SIDX_DLL MovingPoint : public TimePoint, public IEvolvingShape + { + public: + MovingPoint(); + MovingPoint(const double* pCoords, const double* pVCoords, const Tools::IInterval& ti, uint32_t dimension); + MovingPoint(const double* pCoords, const double* pVCoords, double tStart, double tEnd, uint32_t dimension); + MovingPoint(const Point& p, const Point& vp, const Tools::IInterval& ti); + MovingPoint(const Point& p, const Point& vp, double tStart, double tEnd); + MovingPoint(const MovingPoint& p); + ~MovingPoint() override; + + virtual MovingPoint& operator=(const MovingPoint& p); + virtual bool operator==(const MovingPoint& p) const; + + virtual double getCoord(uint32_t index, double t) const; + virtual double getProjectedCoord(uint32_t index, double t) const; + virtual double getVCoord(uint32_t index) const; + virtual void getPointAtTime(double t, Point& out) const; + + // + // IObject interface + // + MovingPoint* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + // + // IEvolvingShape interface + // + void getVMBR(Region& out) const override; + void getMBRAtTime(double t, Region& out) const override; + + void makeInfinite(uint32_t dimension) override; + void makeDimension(uint32_t dimension) override; + + private: + void initialize( + const double* pCoords, const double* pVCoords, + double tStart, double tEnd, uint32_t dimension); + + public: + double* m_pVCoords; + + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const MovingPoint& pt); + }; // MovingPoint + + SIDX_DLL std::ostream& operator<<(std::ostream& os, const MovingPoint& pt); +} + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/MovingRegion.h b/third_party/libspatialindex/larch64/include/spatialindex/MovingRegion.h new file mode 100644 index 000000000..8f3f0a9d9 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/MovingRegion.h @@ -0,0 +1,166 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2003, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + class SIDX_DLL MovingRegion : public TimeRegion, public IEvolvingShape + { + using Region::getLow; + using Region::getHigh; + using TimeRegion::intersectsRegionInTime; + using TimeRegion::containsRegionInTime; + using TimeRegion::combineRegionInTime; + using TimeRegion::getCombinedRegionInTime; + using TimeRegion::containsPointInTime; + + public: + MovingRegion(); + MovingRegion( + const double* pLow, const double* pHigh, + const double* pVLow, const double* pVHigh, + const Tools::IInterval& ti, uint32_t dimension); + MovingRegion( + const double* pLow, const double* pHigh, + const double* pVLow, const double* pVHigh, + double tStart, double tEnd, uint32_t dimension); + MovingRegion( + const Point& low, const Point& high, + const Point& vlow, const Point& vhigh, + const Tools::IInterval& ti); + MovingRegion( + const Point& low, const Point& high, + const Point& vlow, const Point& vhigh, + double tStart, double tEnd); + MovingRegion(const Region& mbr, const Region& vbr, const Tools::IInterval& ivI); + MovingRegion(const Region& mbr, const Region& vbr, double tStart, double tEnd); + MovingRegion(const MovingPoint& low, const MovingPoint& high); + MovingRegion(const MovingRegion& in); + ~MovingRegion() override; + + virtual MovingRegion& operator=(const MovingRegion& r); + virtual bool operator==(const MovingRegion&) const; + + bool isShrinking() const; + + virtual double getLow(uint32_t index, double t) const; + virtual double getHigh(uint32_t index, double t) const; + virtual double getExtrapolatedLow(uint32_t index, double t) const; + virtual double getExtrapolatedHigh(uint32_t index, double t) const; + virtual double getVLow(uint32_t index) const; + virtual double getVHigh(uint32_t index) const; + + virtual bool intersectsRegionInTime(const MovingRegion& r) const; + virtual bool intersectsRegionInTime(const MovingRegion& r, Tools::IInterval& out) const; + virtual bool intersectsRegionInTime(const Tools::IInterval& ivI, const MovingRegion& r, Tools::IInterval& ret) const; + virtual bool containsRegionInTime(const MovingRegion& r) const; + virtual bool containsRegionInTime(const Tools::IInterval& ivI, const MovingRegion& r) const; + virtual bool containsRegionAfterTime(double t, const MovingRegion& r) const; + + virtual double getProjectedSurfaceAreaInTime() const; + virtual double getProjectedSurfaceAreaInTime(const Tools::IInterval& ivI) const; + + virtual double getCenterDistanceInTime(const MovingRegion& r) const; + virtual double getCenterDistanceInTime(const Tools::IInterval& ivI, const MovingRegion& r) const; + + virtual bool intersectsRegionAtTime(double t, const MovingRegion& r) const; + virtual bool containsRegionAtTime(double t, const MovingRegion& r) const; + + virtual bool intersectsPointInTime(const MovingPoint& p) const; + virtual bool intersectsPointInTime(const MovingPoint& p, Tools::IInterval& out) const; + virtual bool intersectsPointInTime(const Tools::IInterval& ivI, const MovingPoint& p, Tools::IInterval& out) const; + virtual bool containsPointInTime(const MovingPoint& p) const; + virtual bool containsPointInTime(const Tools::IInterval& ivI, const MovingPoint& p) const; + + //virtual bool intersectsPointAtTime(double t, const MovingRegion& in) const; + //virtual bool containsPointAtTime(double t, const MovingRegion& in) const; + + virtual void combineRegionInTime(const MovingRegion& r); + virtual void combineRegionAfterTime(double t, const MovingRegion& r); + virtual void getCombinedRegionInTime(MovingRegion& out, const MovingRegion& in) const; + virtual void getCombinedRegionAfterTime(double t, MovingRegion& out, const MovingRegion& in) const; + + virtual double getIntersectingAreaInTime(const MovingRegion& r) const; + virtual double getIntersectingAreaInTime(const Tools::IInterval& ivI, const MovingRegion& r) const; + + // + // IObject interface + // + MovingRegion* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + // + // IEvolvingShape interface + // + void getVMBR(Region& out) const override; + void getMBRAtTime(double t, Region& out) const override; + + // + // ITimeShape interface + // + double getAreaInTime() const override; + double getAreaInTime(const Tools::IInterval& ivI) const override; + double getIntersectingAreaInTime(const ITimeShape& r) const override; + double getIntersectingAreaInTime(const Tools::IInterval& ivI, const ITimeShape& r) const override; + + void makeInfinite(uint32_t dimension) override; + void makeDimension(uint32_t dimension) override; + + private: + void initialize( + const double* pLow, const double* pHigh, + const double* pVLow, const double* pVHigh, + double tStart, double tEnd, uint32_t dimension); + + public: + class CrossPoint + { + public: + double m_t; + uint32_t m_dimension; + uint32_t m_boundary; + const MovingRegion* m_to; + + }; // CrossPoint + + public: + double* m_pVLow{nullptr}; + double* m_pVHigh{nullptr}; + + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const MovingRegion& r); + }; // MovingRegion + + typedef Tools::PoolPointer MovingRegionPtr; + SIDX_DLL std::ostream& operator<<(std::ostream& os, const MovingRegion& r); +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/Point.h b/third_party/libspatialindex/larch64/include/spatialindex/Point.h new file mode 100644 index 000000000..ff7daccfd --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/Point.h @@ -0,0 +1,87 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "tools/Tools.h" + +namespace SpatialIndex +{ + class SIDX_DLL Point : public Tools::IObject, public virtual IShape + { + public: + Point(); + Point(const double* pCoords, uint32_t dimension); + Point(const Point& p); + ~Point() override; + + virtual Point& operator=(const Point& p); + virtual bool operator==(const Point& p) const; + + // + // IObject interface + // + Point* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& length) override; + + // + // IShape interface + // + bool intersectsShape(const IShape& in) const override; + bool containsShape(const IShape& in) const override; + bool touchesShape(const IShape& in) const override; + void getCenter(Point& out) const override; + uint32_t getDimension() const override; + void getMBR(Region& out) const override; + double getArea() const override; + double getMinimumDistance(const IShape& in) const override; + + virtual double getMinimumDistance(const Point& p) const; + + virtual double getCoordinate(uint32_t index) const; + + virtual void makeInfinite(uint32_t dimension); + virtual void makeDimension(uint32_t dimension); + + public: + uint32_t m_dimension{0}; + double* m_pCoords{nullptr}; + + friend class Region; + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const Point& pt); + }; // Point + + typedef Tools::PoolPointer PointPtr; + + SIDX_DLL std::ostream& operator<<(std::ostream& os, const Point& pt); +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/RTree.h b/third_party/libspatialindex/larch64/include/spatialindex/RTree.h new file mode 100644 index 000000000..03a08ab91 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/RTree.h @@ -0,0 +1,108 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + namespace RTree + { + enum RTreeVariant + { + RV_LINEAR = 0x0, + RV_QUADRATIC, + RV_RSTAR + }; + + enum BulkLoadMethod + { + BLM_STR = 0x0 + }; + + enum PersistenObjectIdentifier + { + PersistentIndex = 0x1, + PersistentLeaf = 0x2 + }; + + enum RangeQueryType + { + ContainmentQuery = 0x1, + IntersectionQuery = 0x2 + }; + + class SIDX_DLL Data : public IData, public Tools::ISerializable + { + public: + Data(uint32_t len, uint8_t* pData, Region& r, id_type id); + ~Data() override; + + Data* clone() override; + id_type getIdentifier() const override; + void getShape(IShape** out) const override; + void getData(uint32_t& len, uint8_t** data) const override; + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + id_type m_id; + Region m_region; + uint8_t* m_pData; + uint32_t m_dataLength; + }; // Data + + SIDX_DLL ISpatialIndex* returnRTree(IStorageManager& ind, Tools::PropertySet& in); + SIDX_DLL ISpatialIndex* createNewRTree( + IStorageManager& sm, + double fillFactor, + uint32_t indexCapacity, + uint32_t leafCapacity, + uint32_t dimension, + RTreeVariant rv, + id_type& indexIdentifier + ); + SIDX_DLL ISpatialIndex* createAndBulkLoadNewRTree( + BulkLoadMethod m, + IDataStream& stream, + IStorageManager& sm, + double fillFactor, + uint32_t indexCapacity, + uint32_t leafCapacity, + uint32_t dimension, + RTreeVariant rv, + id_type& indexIdentifier + ); + SIDX_DLL ISpatialIndex* createAndBulkLoadNewRTree( + BulkLoadMethod m, + IDataStream& stream, + IStorageManager& sm, + Tools::PropertySet& ps, + id_type& indexIdentifier + ); + SIDX_DLL ISpatialIndex* loadRTree(IStorageManager& in, id_type indexIdentifier); + } +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/Region.h b/third_party/libspatialindex/larch64/include/spatialindex/Region.h new file mode 100644 index 000000000..e0e3df000 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/Region.h @@ -0,0 +1,106 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + class SIDX_DLL Region : public Tools::IObject, public virtual IShape + { + public: + Region(); + Region(const double* pLow, const double* pHigh, uint32_t dimension); + Region(const Point& low, const Point& high); + Region(const Region& in); + ~Region() override; + + virtual Region& operator=(const Region& r); + virtual bool operator==(const Region&) const; + + // + // IObject interface + // + Region* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& length) override; + + // + // IShape interface + // + bool intersectsShape(const IShape& in) const override; + bool containsShape(const IShape& in) const override; + bool touchesShape(const IShape& in) const override; + void getCenter(Point& out) const override; + uint32_t getDimension() const override; + void getMBR(Region& out) const override; + double getArea() const override; + double getMinimumDistance(const IShape& in) const override; + + virtual bool intersectsRegion(const Region& in) const; + virtual bool containsRegion(const Region& in) const; + virtual bool touchesRegion(const Region& in) const; + virtual double getMinimumDistance(const Region& in) const; + + virtual bool intersectsLineSegment(const LineSegment& in) const; + + virtual bool containsPoint(const Point& in) const; + virtual bool touchesPoint(const Point& in) const; + virtual double getMinimumDistance(const Point& in) const; + + virtual Region getIntersectingRegion(const Region& r) const; + virtual double getIntersectingArea(const Region& in) const; + virtual double getMargin() const; + + virtual void combineRegion(const Region& in); + virtual void combinePoint(const Point& in); + virtual void getCombinedRegion(Region& out, const Region& in) const; + + virtual double getLow(uint32_t index) const; + virtual double getHigh(uint32_t index) const; + + virtual void makeInfinite(uint32_t dimension); + virtual void makeDimension(uint32_t dimension); + + private: + void initialize(const double* pLow, const double* pHigh, uint32_t dimension); + + public: + uint32_t m_dimension{0}; + double* m_pLow{nullptr}; + double* m_pHigh{nullptr}; + + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const Region& r); + }; // Region + + typedef Tools::PoolPointer RegionPtr; + SIDX_DLL std::ostream& operator<<(std::ostream& os, const Region& r); +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/SpatialIndex.h b/third_party/libspatialindex/larch64/include/spatialindex/SpatialIndex.h new file mode 100644 index 000000000..48dcc615a --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/SpatialIndex.h @@ -0,0 +1,265 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2003, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "tools/Tools.h" + +#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661922 +#endif + +namespace SpatialIndex +{ + class Point; + class Ball; + class LineSegment; + class Region; + + + typedef int64_t id_type; + + enum CommandType + { + CT_NODEREAD = 0x0, + CT_NODEDELETE, + CT_NODEWRITE + }; + + class SIDX_DLL InvalidPageException : public Tools::Exception + { + public: + InvalidPageException(id_type id); + ~InvalidPageException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // InvalidPageException + + // + // Interfaces + // + + class SIDX_DLL IShape : public Tools::ISerializable + { + public: + virtual bool intersectsShape(const IShape& in) const = 0; + virtual bool containsShape(const IShape& in) const = 0; + virtual bool touchesShape(const IShape& in) const = 0; + virtual void getCenter(Point& out) const = 0; + virtual uint32_t getDimension() const = 0; + virtual void getMBR(Region& out) const = 0; + virtual double getArea() const = 0; + virtual double getMinimumDistance(const IShape& in) const = 0; + ~IShape() override = default; + }; // IShape + + class SIDX_DLL ITimeShape : public Tools::IInterval + { + public: + virtual bool intersectsShapeInTime(const ITimeShape& in) const = 0; + virtual bool intersectsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0; + virtual bool containsShapeInTime(const ITimeShape& in) const = 0; + virtual bool containsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0; + virtual bool touchesShapeInTime(const ITimeShape& in) const = 0; + virtual bool touchesShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0; + virtual double getAreaInTime() const = 0; + virtual double getAreaInTime(const Tools::IInterval& ivI) const = 0; + virtual double getIntersectingAreaInTime(const ITimeShape& r) const = 0; + virtual double getIntersectingAreaInTime(const Tools::IInterval& ivI, const ITimeShape& r) const = 0; + ~ITimeShape() override = default; + }; // ITimeShape + + class SIDX_DLL IEvolvingShape + { + public: + virtual void getVMBR(Region& out) const = 0; + virtual void getMBRAtTime(double t, Region& out) const = 0; + virtual ~IEvolvingShape() = default; + }; // IEvolvingShape + + class SIDX_DLL IEntry : public Tools::IObject + { + public: + virtual id_type getIdentifier() const = 0; + virtual void getShape(IShape** out) const = 0; + ~IEntry() override = default; + }; // IEntry + + class SIDX_DLL INode : public IEntry, public Tools::ISerializable + { + public: + virtual uint32_t getChildrenCount() const = 0; + virtual id_type getChildIdentifier(uint32_t index) const = 0; + virtual void getChildData(uint32_t index, uint32_t& len, uint8_t** data) const = 0; + virtual void getChildShape(uint32_t index, IShape** out) const = 0; + virtual uint32_t getLevel() const = 0; + virtual bool isIndex() const = 0; + virtual bool isLeaf() const = 0; + ~INode() override = default; + }; // INode + + class SIDX_DLL IData : public IEntry + { + public: + virtual void getData(uint32_t& len, uint8_t** data) const = 0; + ~IData() override = default; + }; // IData + + class SIDX_DLL IDataStream : public Tools::IObjectStream + { + public: + IData* getNext() override = 0; + ~IDataStream() override = default; + }; // IDataStream + + class SIDX_DLL ICommand + { + public: + virtual void execute(const INode& in) = 0; + virtual ~ICommand() = default; + }; // ICommand + + class SIDX_DLL INearestNeighborComparator + { + public: + virtual double getMinimumDistance(const IShape& query, const IShape& entry) = 0; + virtual double getMinimumDistance(const IShape& query, const IData& data) = 0; + virtual ~INearestNeighborComparator() = default; + }; // INearestNeighborComparator + + class SIDX_DLL IStorageManager + { + public: + virtual void loadByteArray(const id_type id, uint32_t& len, uint8_t** data) = 0; + virtual void storeByteArray(id_type& id, const uint32_t len, const uint8_t* const data) = 0; + virtual void deleteByteArray(const id_type id) = 0; + virtual void flush() = 0; + virtual ~IStorageManager() = default; + }; // IStorageManager + + class SIDX_DLL IVisitor + { + public: + virtual void visitNode(const INode& in) = 0; + virtual void visitData(const IData& in) = 0; + virtual void visitData(std::vector& v) = 0; + virtual ~IVisitor() = default; + }; // IVisitor + + class SIDX_DLL IQueryStrategy + { + public: + virtual void getNextEntry(const IEntry& previouslyFetched, id_type& nextEntryToFetch, bool& bFetchNextEntry) = 0; + virtual ~IQueryStrategy() = default; + }; // IQueryStrategy + + class SIDX_DLL IStatistics + { + public: + virtual uint64_t getReads() const = 0; + virtual uint64_t getWrites() const = 0; + virtual uint32_t getNumberOfNodes() const = 0; + virtual uint64_t getNumberOfData() const = 0; + virtual ~IStatistics() = default; + }; // IStatistics + + class SIDX_DLL ISpatialIndex + { + public: + virtual void insertData(uint32_t len, const uint8_t* pData, const IShape& shape, id_type shapeIdentifier) = 0; + virtual bool deleteData(const IShape& shape, id_type shapeIdentifier) = 0; + virtual void internalNodesQuery(const IShape& query, IVisitor& v) = 0; + virtual void containsWhatQuery(const IShape& query, IVisitor& v) = 0; + virtual void intersectsWithQuery(const IShape& query, IVisitor& v) = 0; + virtual void pointLocationQuery(const Point& query, IVisitor& v) = 0; + virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v, INearestNeighborComparator& nnc) = 0; + virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v) = 0; + virtual void selfJoinQuery(const IShape& s, IVisitor& v) = 0; + virtual void queryStrategy(IQueryStrategy& qs) = 0; + virtual void getIndexProperties(Tools::PropertySet& out) const = 0; + virtual void addCommand(ICommand* in, CommandType ct) = 0; + virtual bool isIndexValid() = 0; + virtual void getStatistics(IStatistics** out) const = 0; + virtual void flush() = 0; + virtual ~ISpatialIndex() = default; + + }; // ISpatialIndex + + namespace StorageManager + { + enum StorageManagerConstants + { + EmptyPage = -0x1, + NewPage = -0x1 + }; + + class SIDX_DLL IBuffer : public IStorageManager + { + public: + virtual uint64_t getHits() = 0; + virtual void clear() = 0; + ~IBuffer() override = default; + }; // IBuffer + + SIDX_DLL IStorageManager* returnMemoryStorageManager(Tools::PropertySet& in); + SIDX_DLL IStorageManager* createNewMemoryStorageManager(); + + SIDX_DLL IStorageManager* returnDiskStorageManager(Tools::PropertySet& in); + SIDX_DLL IStorageManager* createNewDiskStorageManager(std::string& baseName, uint32_t pageSize); + SIDX_DLL IStorageManager* loadDiskStorageManager(std::string& baseName); + + SIDX_DLL IBuffer* returnRandomEvictionsBuffer(IStorageManager& ind, Tools::PropertySet& in); + SIDX_DLL IBuffer* createNewRandomEvictionsBuffer(IStorageManager& in, uint32_t capacity, bool bWriteThrough); + } + + // + // Global functions + // + SIDX_DLL std::ostream& operator<<(std::ostream&, const ISpatialIndex&); + SIDX_DLL std::ostream& operator<<(std::ostream&, const IStatistics&); +} + +#include "Point.h" +#include "Region.h" +#include "Ball.h" +#include "LineSegment.h" +#include "TimePoint.h" +#include "TimeRegion.h" +#include "MovingPoint.h" +#include "MovingRegion.h" +#include "RTree.h" +#include "MVRTree.h" +#include "TPRTree.h" +#include "Version.h" + + +// typedef SpatialIndex::Tools::PoolPointer RegionPtr; +// typedef SpatialIndex::Tools::PoolPointer PointPtr; +// typedef SpatialIndex::Tools::PoolPointer TimeRegionPtr; +// typedef SpatialIndex::Tools::PoolPointer MovingRegionPtr; diff --git a/third_party/libspatialindex/larch64/include/spatialindex/TPRTree.h b/third_party/libspatialindex/larch64/include/spatialindex/TPRTree.h new file mode 100644 index 000000000..7b743f94f --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/TPRTree.h @@ -0,0 +1,85 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2003, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#pragma once + +namespace SpatialIndex +{ + namespace TPRTree + { + enum TPRTreeVariant + { + TPRV_RSTAR = 0x2 + }; + + enum PersistenObjectIdentifier + { + PersistentIndex = 0x1, + PersistentLeaf = 0x2 + }; + + enum RangeQueryType + { + ContainmentQuery = 0x1, + IntersectionQuery = 0x2 + }; + + class SIDX_DLL Data : public IData, public Tools::ISerializable + { + public: + Data(uint32_t len, uint8_t* pData, MovingRegion& r, id_type id); + ~Data() override; + + Data* clone() override; + id_type getIdentifier() const override; + void getShape(IShape** out) const override; + void getData(uint32_t& len, uint8_t** data) const override; + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + id_type m_id; + MovingRegion m_region; + uint8_t* m_pData; + uint32_t m_dataLength; + }; // Data + + SIDX_DLL ISpatialIndex* returnTPRTree(IStorageManager& ind, Tools::PropertySet& in); + SIDX_DLL ISpatialIndex* createNewTPRTree( + IStorageManager& sm, + double fillFactor, + uint32_t indexCapacity, + uint32_t leafCapacity, + uint32_t dimension, + TPRTreeVariant rv, + double horizon, + id_type& indexIdentifier + ); + SIDX_DLL ISpatialIndex* loadTPRTree(IStorageManager& in, id_type indexIdentifier); + } +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/TimePoint.h b/third_party/libspatialindex/larch64/include/spatialindex/TimePoint.h new file mode 100644 index 000000000..5db346c13 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/TimePoint.h @@ -0,0 +1,95 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + class SIDX_DLL TimePoint : public Point, public ITimeShape + { + public: + TimePoint(); + TimePoint(const double* pCoords, const Tools::IInterval& ti, uint32_t dimension); + TimePoint(const double* pCoords, double tStart, double tEnd, uint32_t dimension); + TimePoint(const Point& p, const Tools::IInterval& ti); + TimePoint(const Point& p, double tStart, double tEnd); + TimePoint(const TimePoint& p); + ~TimePoint() override; + + virtual TimePoint& operator=(const TimePoint& p); + virtual bool operator==(const TimePoint& p) const; + + // + // IObject interface + // + TimePoint* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + // + // ITimeShape interface + // + bool intersectsShapeInTime(const ITimeShape& in) const override; + bool intersectsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const override; + bool containsShapeInTime(const ITimeShape& in) const override; + bool containsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const override; + bool touchesShapeInTime(const ITimeShape& in) const override; + bool touchesShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const override; + double getAreaInTime() const override; + double getAreaInTime(const Tools::IInterval& ivI) const override; + double getIntersectingAreaInTime(const ITimeShape& r) const override; + double getIntersectingAreaInTime(const Tools::IInterval& ivI, const ITimeShape& r) const override; + + // + // IInterval interface + // + virtual Tools::IInterval& operator=(const Tools::IInterval&); + double getLowerBound() const override; + double getUpperBound() const override; + void setBounds(double, double) override; + bool intersectsInterval(const Tools::IInterval& ti) const override; + bool intersectsInterval(Tools::IntervalType t, const double start, const double end) const override; + bool containsInterval(const Tools::IInterval& ti) const override; + Tools::IntervalType getIntervalType() const override; + + void makeInfinite(uint32_t dimension) override; + void makeDimension(uint32_t dimension) override; + + public: + double m_startTime; + double m_endTime; + + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const TimePoint& pt); + }; // TimePoint + + SIDX_DLL std::ostream& operator<<(std::ostream& os, const TimePoint& pt); +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/TimeRegion.h b/third_party/libspatialindex/larch64/include/spatialindex/TimeRegion.h new file mode 100644 index 000000000..1da0ad9ca --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/TimeRegion.h @@ -0,0 +1,109 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2003, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +namespace SpatialIndex +{ + class SIDX_DLL TimeRegion : public Region, public ITimeShape + { + public: + TimeRegion(); + TimeRegion(const double* pLow, const double* pHigh, const Tools::IInterval& ti, uint32_t dimension); + TimeRegion(const double* pLow, const double* pHigh, double tStart, double tEnd, uint32_t dimension); + TimeRegion(const Point& low, const Point& high, const Tools::IInterval& ti); + TimeRegion(const Point& low, const Point& high, double tStart, double tEnd); + TimeRegion(const Region& in, const Tools::IInterval& ti); + TimeRegion(const Region& in, double tStart, double tEnd); + TimeRegion(const TimePoint& low, const TimePoint& high); + TimeRegion(const TimeRegion& in); + ~TimeRegion() override; + + virtual TimeRegion& operator=(const TimeRegion& r); + virtual bool operator==(const TimeRegion&) const; + + virtual bool intersectsRegionInTime(const TimeRegion& in) const; + virtual bool containsRegionInTime(const TimeRegion& in) const; + virtual bool touchesRegionInTime(const TimeRegion& in) const; + + virtual bool containsPointInTime(const TimePoint& in) const; + virtual bool touchesPointInTime(const TimePoint& in) const; + + virtual void combineRegionInTime(const TimeRegion& in); + virtual void getCombinedRegionInTime(TimeRegion& out, const TimeRegion& in) const; + + // + // IObject interface + // + TimeRegion* clone() override; + + // + // ISerializable interface + // + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& len) override; + + // + // ITimeShape interface + // + bool intersectsShapeInTime(const ITimeShape& in) const override; + bool intersectsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const override; + bool containsShapeInTime(const ITimeShape& in) const override; + bool containsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const override; + bool touchesShapeInTime(const ITimeShape& in) const override; + bool touchesShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const override; + double getAreaInTime() const override; + double getAreaInTime(const Tools::IInterval& ivI) const override; + double getIntersectingAreaInTime(const ITimeShape& r) const override; + double getIntersectingAreaInTime(const Tools::IInterval& ivI, const ITimeShape& r) const override; + + // + // IInterval interface + // + virtual Tools::IInterval& operator=(const Tools::IInterval&); + double getLowerBound() const override; + double getUpperBound() const override; + void setBounds(double, double) override; + bool intersectsInterval(const Tools::IInterval& ti) const override; + bool intersectsInterval(Tools::IntervalType t, const double start, const double end) const override; + bool containsInterval(const Tools::IInterval& ti) const override; + Tools::IntervalType getIntervalType() const override; + + void makeInfinite(uint32_t dimension) override; + void makeDimension(uint32_t dimension) override; + + public: + double m_startTime; + double m_endTime; + + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const TimeRegion& r); + }; // TimeRegion + + typedef Tools::PoolPointer TimeRegionPtr; + SIDX_DLL std::ostream& operator<<(std::ostream& os, const TimeRegion& r); +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/Version.h b/third_party/libspatialindex/larch64/include/spatialindex/Version.h new file mode 100644 index 000000000..b90268f83 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/Version.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2003, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#ifndef SIDX_VERSION_MAJOR +#define SIDX_VERSION_MAJOR 2 +#define SIDX_VERSION_MINOR 0 +#define SIDX_VERSION_REV 0 +#define SIDX_VERSION_BUILD 0 +#endif + +#ifndef SIDX_VERSION_NUM +#define SIDX_VERSION_NUM (SIDX_VERSION_MAJOR*1000+SIDX_VERSION_MINOR*100+SIDX_VERSION_REV*10+SIDX_VERSION_BUILD) +#endif + +#ifndef SIDX_RELEASE_DATE +#define SIDX_RELEASE_DATE 20240517 +#endif + +#ifndef SIDX_RELEASE_NAME +#define SIDX_RELEASE_NAME "2.0.0" +#endif + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/BoundsQuery.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/BoundsQuery.h new file mode 100644 index 000000000..79fdcb82d --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/BoundsQuery.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement the bounds query. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class SIDX_DLL BoundsQuery : public SpatialIndex::IQueryStrategy +{ +private: + SpatialIndex::Region* m_bounds; + +public: + + BoundsQuery(); + ~BoundsQuery() { if (m_bounds != 0) delete m_bounds; } + void getNextEntry( const SpatialIndex::IEntry& entry, + SpatialIndex::id_type& nextEntry, + bool& hasNext); + + SpatialIndex::Region* GetBounds() const { return m_bounds; } +}; + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/CountVisitor.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/CountVisitor.h new file mode 100644 index 000000000..eaaee8dd2 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/CountVisitor.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ objects to implement the count visitor. + * Author: Leonard Norrgård, leonard.norrgard@refactor.fi + ****************************************************************************** + * Copyright (c) 2010, Leonard Norrgård + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class SIDX_DLL CountVisitor : public SpatialIndex::IVisitor +{ +private: + uint64_t nResults; + +public: + + CountVisitor(); + ~CountVisitor(); + + uint64_t GetResultCount() const { return nResults; } + + void visitNode(const SpatialIndex::INode& n); + void visitData(const SpatialIndex::IData& d); + void visitData(std::vector& v); +}; diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/CustomStorage.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/CustomStorage.h new file mode 100644 index 000000000..fa670206b --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/CustomStorage.h @@ -0,0 +1,84 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement the custom storage manager. + * Author: Matthias (nitro), nitro@dr-code.org + ****************************************************************************** + * Copyright (c) 2010, Matthias (nitro) + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +namespace SpatialIndex +{ + namespace StorageManager + { + struct SIDX_DLL CustomStorageManagerCallbacks + { + CustomStorageManagerCallbacks() + : context(0) + , createCallback(0) + , destroyCallback(0) + , loadByteArrayCallback(0) + , storeByteArrayCallback(0) + , deleteByteArrayCallback(0) + {} + + void* context; + void (*createCallback)( const void* context, int* errorCode ); + void (*destroyCallback)( const void* context, int* errorCode ); + void (*flushCallback)( const void* context, int* errorCode ); + void (*loadByteArrayCallback)( const void* context, const id_type page, uint32_t* len, uint8_t** data, int* errorCode ); + void (*storeByteArrayCallback)( const void* context, id_type* page, const uint32_t len, const uint8_t* const data, int* errorCode ); + void (*deleteByteArrayCallback)( const void* context, const id_type page, int* errorCode ); + }; + + class SIDX_DLL CustomStorageManager : public SpatialIndex::IStorageManager + { + public: + // I'd like this to be an enum, but casting between enums and ints is not nice + static const int NoError = 0; + static const int InvalidPageError = 1; + static const int IllegalStateError = 2; + + CustomStorageManager(Tools::PropertySet&); + + virtual ~CustomStorageManager(); + + virtual void flush(); + virtual void loadByteArray(const id_type page, uint32_t& len, uint8_t** data); + virtual void storeByteArray(id_type& page, const uint32_t len, const uint8_t* const data); + virtual void deleteByteArray(const id_type page); + + private: + CustomStorageManagerCallbacks callbacks; + + inline void processErrorCode(int errorCode, const id_type page); + }; // CustomStorageManager + + // factory function + IStorageManager* returnCustomStorageManager(Tools::PropertySet& in); + } +} + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/DataStream.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/DataStream.h new file mode 100644 index 000000000..3334faff6 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/DataStream.h @@ -0,0 +1,56 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: Declarations to support stream loading via C API + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class SIDX_DLL DataStream : public SpatialIndex::IDataStream +{ +public: + DataStream(int (*readNext)(SpatialIndex::id_type* id, double **pMin, double **pMax, uint32_t *nDimension, const uint8_t **pData, size_t *nDataLength)); + ~DataStream(); + + SpatialIndex::IData* getNext(); + bool hasNext(); + + uint32_t size(); + void rewind(); + +protected: + SpatialIndex::RTree::Data* m_pNext; + SpatialIndex::id_type m_id; + +private: + int (*iterfunct)(SpatialIndex::id_type *id, double **pMin, double **pMax, uint32_t *nDimension, const uint8_t **pData, size_t *nDataLength); + + bool readData(); + bool m_bDoneReading; + +}; + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/Error.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/Error.h new file mode 100644 index 000000000..e8cc647d6 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/Error.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement the error object. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class SIDX_DLL Error +{ +public: + + Error(int code, std::string const& message, std::string const& method); + + /// Copy constructor. + Error(Error const& other); + + /// Assignment operator. + Error& operator=(Error const& rhs); + + int GetCode() const { return m_code; } + const char* GetMessage() const { return m_message.c_str(); } + const char* GetMethod() const { return m_method.c_str(); } + +private: + + int m_code; + std::string m_message; + std::string m_method; +}; diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/IdVisitor.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/IdVisitor.h new file mode 100644 index 000000000..959680529 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/IdVisitor.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement a query ids only. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class SIDX_DLL IdVisitor : public SpatialIndex::IVisitor +{ +private: + std::vector m_vector; + uint64_t nResults; + +public: + + IdVisitor(); + ~IdVisitor(); + + uint64_t GetResultCount() const { return nResults; } + std::vector& GetResults() { return m_vector; } + + void visitNode(const SpatialIndex::INode& n); + void visitData(const SpatialIndex::IData& d); + void visitData(std::vector& v); +}; diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/Index.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/Index.h new file mode 100644 index 000000000..1820850ac --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/Index.h @@ -0,0 +1,82 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement the wrapper. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + + +#include "sidx_export.h" + +class SIDX_DLL Index +{ + +public: + Index(const Tools::PropertySet& poProperties); + Index(const Tools::PropertySet& poProperties, int (*readNext)(SpatialIndex::id_type *id, double **pMin, double **pMax, uint32_t *nDimension, const uint8_t **pData, size_t* nDataLength)); + ~Index(); + + const Tools::PropertySet GetProperties() { index().getIndexProperties(m_properties); return m_properties;} + + bool insertFeature(uint64_t id, double *min, double *max); + + RTIndexType GetIndexType(); + void SetIndexType(RTIndexType v); + + RTStorageType GetIndexStorage(); + void SetIndexStorage(RTStorageType v); + + RTIndexVariant GetIndexVariant(); + void SetIndexVariant(RTIndexVariant v); + + int64_t GetResultSetOffset(); + void SetResultSetOffset(int64_t v); + + int64_t GetResultSetLimit(); + void SetResultSetLimit(int64_t v); + + void flush(); + + SpatialIndex::ISpatialIndex& index() {return *m_rtree;} + SpatialIndex::StorageManager::IBuffer& buffer() {return *m_buffer;} + +private: + + Index& operator=(const Index&); + Index(); + + void Initialize(); + SpatialIndex::IStorageManager* m_storage; + SpatialIndex::StorageManager::IBuffer* m_buffer; + SpatialIndex::ISpatialIndex* m_rtree; + + Tools::PropertySet m_properties; + + void Setup(); + SpatialIndex::IStorageManager* CreateStorage(); + SpatialIndex::StorageManager::IBuffer* CreateIndexBuffer(SpatialIndex::IStorageManager& storage); + SpatialIndex::ISpatialIndex* CreateIndex(); +}; diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/LeafQuery.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/LeafQuery.h new file mode 100644 index 000000000..9f30a0f3e --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/LeafQuery.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement a query of the index's leaves. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class LeafQueryResult; + +class SIDX_DLL LeafQuery : public SpatialIndex::IQueryStrategy +{ +private: + std::queue m_ids; + std::vector m_results; +public: + + LeafQuery(); + ~LeafQuery() { } + void getNextEntry( const SpatialIndex::IEntry& entry, + SpatialIndex::id_type& nextEntry, + bool& hasNext); + std::vector const& GetResults() const {return m_results;} +}; + +class SIDX_DLL LeafQueryResult +{ +private: + std::vector ids; + SpatialIndex::Region* bounds; + SpatialIndex::id_type m_id; + LeafQueryResult(); +public: + LeafQueryResult(SpatialIndex::id_type id) : bounds(0), m_id(id){} + ~LeafQueryResult() {if (bounds!=0) delete bounds;} + + /// Copy constructor. + LeafQueryResult(LeafQueryResult const& other); + + /// Assignment operator. + LeafQueryResult& operator=(LeafQueryResult const& rhs); + + std::vector const& GetIDs() const; + void SetIDs(std::vector& v); + const SpatialIndex::Region* GetBounds() const; + void SetBounds(const SpatialIndex::Region* b); + SpatialIndex::id_type getIdentifier() const {return m_id;} + void setIdentifier(uint32_t v) {m_id = v;} +}; diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/ObjVisitor.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/ObjVisitor.h new file mode 100644 index 000000000..2c27d5a2c --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/ObjVisitor.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement the object visitor. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "sidx_export.h" + +class SIDX_DLL ObjVisitor : public SpatialIndex::IVisitor +{ +private: + std::vector m_vector; + uint64_t nResults; + +public: + + ObjVisitor(); + ~ObjVisitor(); + + uint64_t GetResultCount() const { return nResults; } + std::vector& GetResults() { return m_vector; } + + void visitNode(const SpatialIndex::INode& n); + void visitData(const SpatialIndex::IData& d); + void visitData(std::vector& v); +}; + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/Utility.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/Utility.h new file mode 100644 index 000000000..9962ceb4f --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/Utility.h @@ -0,0 +1,38 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement utilities. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#include "ObjVisitor.h" +#include "IdVisitor.h" +#include "sidx_export.h" + +#pragma once + +SIDX_DLL Tools::PropertySet* GetDefaults(); + +SIDX_DLL void Page_ResultSet_Ids(IdVisitor& visitor, int64_t** ids, int64_t nStart, int64_t nResultLimit, uint64_t* nResults); +SIDX_DLL void Page_ResultSet_Obj(ObjVisitor& visitor, IndexItemH** items, int64_t nStart, int64_t nResultLimit, uint64_t* nResults); diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_api.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_api.h new file mode 100644 index 000000000..15e3696c4 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_api.h @@ -0,0 +1,395 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C API. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#ifndef SIDX_API_H_INCLUDED +#define SIDX_API_H_INCLUDED + +#define SIDX_C_API 1 + +#include "sidx_config.h" + +#include + +IDX_C_START + +SIDX_DLL IndexH Index_Create(IndexPropertyH properties); + +SIDX_DLL IndexH Index_CreateWithStream( IndexPropertyH properties, + int (*readNext)(int64_t *id, double **pMin, double **pMax, uint32_t *nDimension, const uint8_t **pData, size_t *nDataLength) + ); + +SIDX_DLL void Index_Destroy(IndexH index); +SIDX_DLL IndexPropertyH Index_GetProperties(IndexH index); + +SIDX_DLL RTError Index_DeleteData( IndexH index, + int64_t id, + double* pdMin, + double* pdMax, + uint32_t nDimension); + +SIDX_C_DLL RTError Index_DeleteTPData( IndexH index, + int64_t id, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension + ); + +SIDX_C_DLL RTError Index_DeleteMVRData( IndexH index, + int64_t id, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension + ); + +SIDX_DLL RTError Index_InsertData( IndexH index, + int64_t id, + double* pdMin, + double* pdMax, + uint32_t nDimension, + const uint8_t* pData, + size_t nDataLength); + +SIDX_C_DLL RTError Index_InsertTPData( IndexH index, + int64_t id, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension, + const uint8_t* pData, + size_t nDataLength); + +SIDX_C_DLL RTError Index_InsertMVRData( IndexH index, + int64_t id, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension, + const uint8_t* pData, + size_t nDataLength); + +SIDX_DLL uint32_t Index_IsValid(IndexH index); + +SIDX_C_DLL RTError Index_TPIntersects_obj( IndexH index, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_MVRIntersects_obj( IndexH index, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_DLL RTError Index_Intersects_obj( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_Contains_obj( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_TPIntersects_id( IndexH index, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension, + int64_t** ids, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_MVRIntersects_id( IndexH index, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension, + int64_t** ids, + uint64_t* nResults); + +SIDX_DLL RTError Index_Intersects_id( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + int64_t** items, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_Contains_id(IndexH index, + double *pdMin, + double *pdMax, + uint32_t nDimension, + int64_t **ids, + uint64_t *nResults); + +SIDX_C_DLL RTError Index_TPIntersects_count( IndexH index, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_MVRIntersects_count( IndexH index, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension, + uint64_t* nResults); + +SIDX_DLL RTError Index_Intersects_count( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_Contains_count( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_TPNearestNeighbors_obj(IndexH index, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_MVRNearestNeighbors_obj(IndexH index, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_DLL RTError Index_NearestNeighbors_obj(IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_TPNearestNeighbors_id(IndexH index, + double* pdMin, + double* pdMax, + double* pdVMin, + double* pdVMax, + double tStart, + double tEnd, + uint32_t nDimension, + int64_t** ids, + uint64_t* nResults); + +SIDX_C_DLL RTError Index_MVRNearestNeighbors_id(IndexH index, + double* pdMin, + double* pdMax, + double tStart, + double tEnd, + uint32_t nDimension, + int64_t** ids, + uint64_t* nResults); + +SIDX_DLL RTError Index_NearestNeighbors_id( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + int64_t** items, + uint64_t* nResults); + +SIDX_DLL RTError Index_Intersects_internal( IndexH index, + double* pdMin, + double* pdMax, + uint32_t nDimension, + IndexItemH** items, + uint64_t* nResults); + +SIDX_DLL RTError Index_GetBounds( IndexH index, + double** ppdMin, + double** ppdMax, + uint32_t* nDimension); + + +SIDX_C_DLL RTError Index_GetLeaves( IndexH index, + uint32_t* nLeafNodes, + uint32_t** nLeafSizes, + int64_t** nLeafIDs, + int64_t*** nLeafChildIDs, + double*** pppdMin, + double*** pppdMax, + uint32_t* nDimension); + +SIDX_DLL RTError Index_SetResultSetOffset(IndexH index, int64_t value); +SIDX_DLL int64_t Index_GetResultSetOffset(IndexH index); + +SIDX_DLL RTError Index_SetResultSetLimit(IndexH index, int64_t value); +SIDX_DLL int64_t Index_GetResultSetLimit(IndexH index); + +SIDX_DLL void Index_DestroyObjResults(IndexItemH* results, uint32_t nResults); +SIDX_DLL void Index_ClearBuffer(IndexH index); +SIDX_DLL void Index_Free(void* object); +SIDX_DLL void Index_Flush(IndexH index); + +SIDX_DLL void IndexItem_Destroy(IndexItemH item); +SIDX_DLL int64_t IndexItem_GetID(IndexItemH item); + +SIDX_DLL RTError IndexItem_GetData(IndexItemH item, uint8_t** data, uint64_t* length); + +SIDX_DLL RTError IndexItem_GetBounds( IndexItemH item, + double** ppdMin, + double** ppdMax, + uint32_t* nDimension); + +SIDX_DLL IndexPropertyH IndexProperty_Create(void); +SIDX_DLL void IndexProperty_Destroy(IndexPropertyH hProp); + +SIDX_DLL RTError IndexProperty_SetIndexType(IndexPropertyH iprop, RTIndexType value); +SIDX_DLL RTIndexType IndexProperty_GetIndexType(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetDimension(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetDimension(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetIndexVariant(IndexPropertyH iprop, RTIndexVariant value); +SIDX_DLL RTIndexVariant IndexProperty_GetIndexVariant(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetIndexStorage(IndexPropertyH iprop, RTStorageType value); +SIDX_DLL RTStorageType IndexProperty_GetIndexStorage(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetPagesize(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetPagesize(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetIndexCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetIndexCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetLeafCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetLeafCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetLeafPoolCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetLeafPoolCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetIndexPoolCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetIndexPoolCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetRegionPoolCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetRegionPoolCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetPointPoolCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetPointPoolCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetBufferingCapacity(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetBufferingCapacity(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetEnsureTightMBRs(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetEnsureTightMBRs(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetOverwrite(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetOverwrite(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetNearMinimumOverlapFactor(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetNearMinimumOverlapFactor(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetWriteThrough(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetWriteThrough(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetFillFactor(IndexPropertyH iprop, double value); +SIDX_DLL double IndexProperty_GetFillFactor(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetSplitDistributionFactor(IndexPropertyH iprop, double value); +SIDX_DLL double IndexProperty_GetSplitDistributionFactor(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetTPRHorizon(IndexPropertyH iprop, double value); +SIDX_DLL double IndexProperty_GetTPRHorizon(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetReinsertFactor(IndexPropertyH iprop, double value); +SIDX_DLL double IndexProperty_GetReinsertFactor(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetFileName(IndexPropertyH iprop, const char* value); +SIDX_DLL char* IndexProperty_GetFileName(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetFileNameExtensionDat(IndexPropertyH iprop, const char* value); +SIDX_DLL char* IndexProperty_GetFileNameExtensionDat(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetFileNameExtensionIdx(IndexPropertyH iprop, const char* value); +SIDX_DLL char* IndexProperty_GetFileNameExtensionIdx(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetCustomStorageCallbacksSize(IndexPropertyH iprop, uint32_t value); +SIDX_DLL uint32_t IndexProperty_GetCustomStorageCallbacksSize(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetCustomStorageCallbacks(IndexPropertyH iprop, const void* value); +SIDX_DLL void* IndexProperty_GetCustomStorageCallbacks(IndexPropertyH iprop); + +SIDX_DLL RTError IndexProperty_SetIndexID(IndexPropertyH iprop, int64_t value); +SIDX_DLL int64_t IndexProperty_GetIndexID(IndexPropertyH iprop); + +SIDX_C_DLL void* SIDX_NewBuffer(size_t bytes); +SIDX_C_DLL void SIDX_DeleteBuffer(void* buffer); + +SIDX_DLL RTError IndexProperty_SetResultSetLimit(IndexPropertyH iprop, uint64_t value); +SIDX_DLL uint64_t IndexProperty_GetResultSetLimit(IndexPropertyH iprop); + +SIDX_C_DLL char* SIDX_Version(void); + +SIDX_C_DLL char* Error_GetLastErrorMsg(void); + +IDX_C_END + +#endif diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_config.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_config.h new file mode 100644 index 000000000..153e2ea5f --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_config.h @@ -0,0 +1,112 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C API configuration + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#ifndef SIDX_CONFIG_H_INCLUDED +#define SIDX_CONFIG_H_INCLUDED + + + +#ifdef _MSC_VER + +#if _MSC_VER <= 1500 + typedef __int8 int8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef __int64 int64_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int64 uint64_t; +#else + #include +#endif + + #include + #define STRDUP _strdup + #include + +#else + + #include + #define SIDX_THREAD __thread + #define STRDUP strdup +#endif + +#include + +#include "sidx_export.h" + +typedef enum +{ + RT_None = 0, + RT_Debug = 1, + RT_Warning = 2, + RT_Failure = 3, + RT_Fatal = 4 +} RTError; + +typedef enum +{ + RT_RTree = 0, + RT_MVRTree = 1, + RT_TPRTree = 2, + RT_InvalidIndexType = -99 +} RTIndexType; + +typedef enum +{ + RT_Memory = 0, + RT_Disk = 1, + RT_Custom = 2, + RT_InvalidStorageType = -99 +} RTStorageType; + +typedef enum +{ + RT_Linear = 0, + RT_Quadratic = 1, + RT_Star = 2, + RT_InvalidIndexVariant = -99 +} RTIndexVariant; + + +#ifdef __cplusplus +# define IDX_C_START extern "C" { +# define IDX_C_END } +#else +# define IDX_C_START +# define IDX_C_END +#endif + +typedef struct IndexS *IndexH; +typedef struct SpatialIndex_IData *IndexItemH; +typedef struct Tools_PropertySet *IndexPropertyH; + + + +#endif diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_export.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_export.h new file mode 100644 index 000000000..7b0a39364 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_export.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement utilities. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2014, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#ifndef SIDX_C_DLL +#if defined(_MSC_VER) && defined(SIDX_DLL_EXPORT) +# define SIDX_C_DLL __declspec(dllexport) +# define SIDX_DLL __declspec(dllexport) +#else +# if defined(USE_GCC_VISIBILITY_FLAG) +# define SIDX_C_DLL __attribute__ ((visibility("default"))) +# define SIDX_DLL __attribute__ ((visibility("default"))) +# else +# define SIDX_C_DLL +# define SIDX_DLL +# endif +#endif +#endif diff --git a/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_impl.h b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_impl.h new file mode 100644 index 000000000..df665b9fb --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/capi/sidx_impl.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * Project: libsidx - A C API wrapper around libspatialindex + * Purpose: C++ object declarations to implement utilities. + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2009, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "../SpatialIndex.h" +#include "sidx_config.h" +#include "Utility.h" +#include "ObjVisitor.h" +#include "IdVisitor.h" +#include "CountVisitor.h" +#include "BoundsQuery.h" +#include "LeafQuery.h" +#include "Error.h" +#include "DataStream.h" +#include "Index.h" +#include "CustomStorage.h" diff --git a/third_party/libspatialindex/larch64/include/spatialindex/tools/PointerPool.h b/third_party/libspatialindex/larch64/include/spatialindex/tools/PointerPool.h new file mode 100644 index 000000000..4611122d3 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/tools/PointerPool.h @@ -0,0 +1,95 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "PoolPointer.h" + +namespace Tools +{ + template class PointerPool + { + public: + explicit PointerPool(uint32_t capacity) : m_capacity(capacity) + { + } + + ~PointerPool() + { + assert(m_pool.size() <= m_capacity); + + while (! m_pool.empty()) + { + X* x = m_pool.top(); m_pool.pop(); + delete x; + } + } + + PoolPointer acquire() + { + X* p = nullptr; + + if (! m_pool.empty()) + { + p = m_pool.top(); m_pool.pop(); + } + else + { + p = new X(); + } + + return PoolPointer(p, this); + } + + void release(X* p) + { + if (m_pool.size() < m_capacity) + { + m_pool.push(p); + } + else + { + delete p; + } + + assert(m_pool.size() <= m_capacity); + } + + uint32_t getCapacity() const { return m_capacity; } + void setCapacity(uint32_t c) + { + assert (c >= 0); + m_capacity = c; + } + + private: + uint32_t m_capacity; + std::stack m_pool; + + }; +} + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/tools/PoolPointer.h b/third_party/libspatialindex/larch64/include/spatialindex/tools/PoolPointer.h new file mode 100644 index 000000000..759701759 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/tools/PoolPointer.h @@ -0,0 +1,102 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + +#include "PointerPool.h" + +namespace Tools +{ + template class PointerPool; + + template class PoolPointer + { + public: + explicit PoolPointer(X* p = nullptr) : m_pointer(p), m_pPool(nullptr) { m_prev = m_next = this; } + explicit PoolPointer(X* p, PointerPool* pPool) noexcept : m_pointer(p), m_pPool(pPool) { m_prev = m_next = this; } + ~PoolPointer() { release(); } + PoolPointer(const PoolPointer& p) noexcept { acquire(p); } + PoolPointer& operator=(const PoolPointer& p) + { + if (this != &p) + { + release(); + acquire(p); + } + return *this; + } + + X& operator*() const noexcept { return *m_pointer; } + X* operator->() const noexcept { return m_pointer; } + X* get() const noexcept { return m_pointer; } + bool unique() const noexcept { return m_prev ? m_prev == this : true; } + void relinquish() noexcept + { + m_pPool = nullptr; + m_pointer = nullptr; + release(); + } + + private: + X* m_pointer; + mutable const PoolPointer* m_prev; + mutable const PoolPointer* m_next; + PointerPool* m_pPool; + + void acquire(const PoolPointer& p) noexcept + { + m_pPool = p.m_pPool; + m_pointer = p.m_pointer; + m_next = p.m_next; + m_next->m_prev = this; + m_prev = &p; + #ifndef mutable + p.m_next = this; + #else + (const_cast*>(&p))->m_next = this; + #endif + } + + void release() + { + if (unique()) + { + if (m_pPool != nullptr) m_pPool->release(m_pointer); + else delete m_pointer; + } + else + { + m_prev->m_next = m_next; + m_next->m_prev = m_prev; + m_prev = m_next = nullptr; + } + m_pointer = nullptr; + m_pPool = nullptr; + } + }; +} + diff --git a/third_party/libspatialindex/larch64/include/spatialindex/tools/Tools.h b/third_party/libspatialindex/larch64/include/spatialindex/tools/Tools.h new file mode 100644 index 000000000..07c1926e8 --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/tools/Tools.h @@ -0,0 +1,501 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Marios Hadjieleftheriou, mhadji@gmail.com + ****************************************************************************** + * Copyright (c) 2004, Marios Hadjieleftheriou + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + +#pragma once + + +#if (defined _WIN32 || defined _WIN64 || defined WIN32 || defined WIN64) && (defined _MSC_VER) && (_MSC_VER < 1900) && !defined __GNUC__ + typedef __int8 int8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef __int64 int64_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int64 uint64_t; + +#else + #include +#endif + +#if (defined _WIN32 || defined _WIN64 || defined WIN32 || defined WIN64) && !defined __GNUC__ + #ifdef SIDX_DLL_EXPORT + #define SIDX_DLL __declspec(dllexport) + #else + #define SIDX_DLL + #endif + + // Nuke this annoying warning. See http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html +#pragma warning( disable: 4251 ) + +#else + #define SIDX_DLL +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PointerPool.h" +#include "PoolPointer.h" + +namespace Tools +{ + enum IntervalType + { + IT_RIGHTOPEN = 0x0, + IT_LEFTOPEN, + IT_OPEN, + IT_CLOSED + }; + + enum VariantType + { + VT_LONG = 0x0, + VT_BYTE, + VT_SHORT, + VT_FLOAT, + VT_DOUBLE, + VT_CHAR, + VT_USHORT, + VT_ULONG, + VT_INT, + VT_UINT, + VT_BOOL, + VT_PCHAR, + VT_PVOID, + VT_EMPTY, + VT_LONGLONG, + VT_ULONGLONG, + VT_PWCHAR + }; + + enum FileMode + { + APPEND = 0x0, + CREATE + }; + + // + // Exceptions + // + class SIDX_DLL Exception + { + public: + virtual std::string what() = 0; + virtual ~Exception() = default; + }; + + class SIDX_DLL IndexOutOfBoundsException : public Exception + { + public: + IndexOutOfBoundsException(size_t i); + ~IndexOutOfBoundsException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // IndexOutOfBoundsException + + class SIDX_DLL IllegalArgumentException : public Exception + { + public: + IllegalArgumentException(std::string s); + ~IllegalArgumentException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // IllegalArgumentException + + class SIDX_DLL IllegalStateException : public Exception + { + public: + IllegalStateException(std::string s); + ~IllegalStateException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // IllegalStateException + + class SIDX_DLL EndOfStreamException : public Exception + { + public: + EndOfStreamException(std::string s); + ~EndOfStreamException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // EndOfStreamException + + class SIDX_DLL ResourceLockedException : public Exception + { + public: + ResourceLockedException(std::string s); + ~ResourceLockedException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // ResourceLockedException + + class SIDX_DLL NotSupportedException : public Exception + { + public: + NotSupportedException(std::string s); + ~NotSupportedException() override = default; + std::string what() override; + + private: + std::string m_error; + }; // NotSupportedException + + // + // Interfaces + // + class SIDX_DLL IInterval + { + public: + virtual ~IInterval() = default; + + virtual double getLowerBound() const = 0; + virtual double getUpperBound() const = 0; + virtual void setBounds(double, double) = 0; + virtual bool intersectsInterval(const IInterval&) const = 0; + virtual bool intersectsInterval(IntervalType type, const double start, const double end) const = 0; + virtual bool containsInterval(const IInterval&) const = 0; + virtual IntervalType getIntervalType() const = 0; + }; // IInterval + + class SIDX_DLL IObject + { + public: + virtual ~IObject() = default; + + virtual IObject* clone() = 0; + // return a new object that is an exact copy of this one. + // IMPORTANT: do not return the this pointer! + }; // IObject + + class SIDX_DLL ISerializable + { + public: + virtual ~ISerializable() = default; + + virtual uint32_t getByteArraySize() = 0; + // returns the size of the required uint8_t array. + virtual void loadFromByteArray(const uint8_t* data) = 0; + // load this object using the uint8_t array. + virtual void storeToByteArray(uint8_t** data, uint32_t& length) = 0; + // store this object in the uint8_t array. + }; + + class SIDX_DLL IComparable + { + public: + virtual ~IComparable() = default; + + virtual bool operator<(const IComparable& o) const = 0; + virtual bool operator>(const IComparable& o) const = 0; + virtual bool operator==(const IComparable& o) const = 0; + }; //IComparable + + class SIDX_DLL IObjectComparator + { + public: + virtual ~IObjectComparator() = default; + + virtual int compare(IObject* o1, IObject* o2) = 0; + }; // IObjectComparator + + class SIDX_DLL IObjectStream + { + public: + virtual ~IObjectStream() = default; + + virtual IObject* getNext() = 0; + // returns a pointer to the next entry in the + // stream or 0 at the end of the stream. + + virtual bool hasNext() = 0; + // returns true if there are more items in the stream. + + virtual uint32_t size() = 0; + // returns the total number of entries available in the stream. + + virtual void rewind() = 0; + // sets the stream pointer to the first entry, if possible. + }; // IObjectStream + + // + // Classes & Functions + // + + class SIDX_DLL Variant + { + public: + Variant(); + + VariantType m_varType{VT_EMPTY}; + + union + { + int16_t iVal; // VT_SHORT + int32_t lVal; // VT_LONG + int64_t llVal; // VT_LONGLONG + uint8_t bVal; // VT_BYTE + float fltVal; // VT_FLOAT + double dblVal; // VT_DOUBLE + char cVal; // VT_CHAR + uint16_t uiVal; // VT_USHORT + uint32_t ulVal; // VT_ULONG + uint64_t ullVal; // VT_ULONGLONG + bool blVal; // VT_BOOL + char* pcVal; // VT_PCHAR + void* pvVal; // VT_PVOID + wchar_t* pwcVal; + } m_val; + }; // Variant + + class SIDX_DLL PropertySet; + SIDX_DLL std::ostream& operator<<(std::ostream& os, const Tools::PropertySet& p); + + class SIDX_DLL PropertySet : public ISerializable + { + public: + PropertySet(); + PropertySet(const uint8_t* data); + ~PropertySet() override; + + Variant getProperty(std::string property) const; + void setProperty(std::string property, Variant const& v); + void removeProperty(std::string property); + + uint32_t getByteArraySize() override; + void loadFromByteArray(const uint8_t* data) override; + void storeToByteArray(uint8_t** data, uint32_t& length) override; + + private: + std::map m_propertySet; +// #ifdef HAVE_PTHREAD_H +// pthread_rwlock_t m_rwLock; +// #else +// bool m_rwLock; +// #endif + friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const Tools::PropertySet& p); + }; // PropertySet + + // does not support degenerate intervals. + class SIDX_DLL Interval : public IInterval + { + public: + Interval(); + Interval(IntervalType, double, double); + Interval(double, double); + Interval(const Interval&); + ~Interval() override = default; + virtual IInterval& operator=(const IInterval&); + + virtual bool operator==(const Interval&) const; + virtual bool operator!=(const Interval&) const; + double getLowerBound() const override; + double getUpperBound() const override; + void setBounds(double, double) override; + bool intersectsInterval(const IInterval&) const override; + bool intersectsInterval(IntervalType type, const double start, const double end) const override; + bool containsInterval(const IInterval&) const override; + IntervalType getIntervalType() const override; + + IntervalType m_type{IT_RIGHTOPEN}; + double m_low{0.0}; + double m_high{0.0}; + }; // Interval + + SIDX_DLL std::ostream& operator<<(std::ostream& os, const Tools::Interval& iv); + + class SIDX_DLL Random + { + public: + Random(); + Random(uint32_t seed, uint16_t xsubi0); + virtual ~Random(); + + int32_t nextUniformLong(); + // returns a uniformly distributed long. + uint32_t nextUniformUnsignedLong(); + // returns a uniformly distributed unsigned long. + int32_t nextUniformLong(int32_t low, int32_t high); + // returns a uniformly distributed long in the range [low, high). + uint32_t nextUniformUnsignedLong(uint32_t low, uint32_t high); + // returns a uniformly distributed unsigned long in the range [low, high). + int64_t nextUniformLongLong(); + // returns a uniformly distributed long long. + uint64_t nextUniformUnsignedLongLong(); + // returns a uniformly distributed unsigned long long. + int64_t nextUniformLongLong(int64_t low, int64_t high); + // returns a uniformly distributed unsigned long long in the range [low, high). + uint64_t nextUniformUnsignedLongLong(uint64_t low, uint64_t high); + // returns a uniformly distributed unsigned long long in the range [low, high). + int16_t nextUniformShort(); + // returns a uniformly distributed short. + uint16_t nextUniformUnsignedShort(); + // returns a uniformly distributed unsigned short. + double nextUniformDouble(); + // returns a uniformly distributed double in the range [0, 1). + double nextUniformDouble(double low, double high); + // returns a uniformly distributed double in the range [low, high). + + bool flipCoin(); + + private: + void initDrand(uint32_t seed, uint16_t xsubi0); + + uint16_t* m_pBuffer; + }; // Random + + #if HAVE_PTHREAD_H + class SIDX_DLL LockGuard + { + public: + LockGuard(pthread_mutex_t* pLock); + ~LockGuard(); + + private: + pthread_mutex_t* m_pLock; + }; // LockGuard + #endif + + class SIDX_DLL BufferedFile + { + public: + BufferedFile(uint32_t u32BufferSize = 16384); + virtual ~BufferedFile(); + + virtual void close(); + virtual bool eof(); + virtual void rewind() = 0; + virtual void seek(std::fstream::off_type offset) = 0; + + protected: + std::fstream m_file; + char* m_buffer; + uint32_t m_u32BufferSize; + bool m_bEOF{true}; + }; + + class SIDX_DLL BufferedFileReader : public BufferedFile + { + public: + BufferedFileReader(); + BufferedFileReader(const std::string& sFileName, uint32_t u32BufferSize = 32768); + ~BufferedFileReader() override; + + virtual void open(const std::string& sFileName); + void rewind() override; + void seek(std::fstream::off_type offset) override; + + virtual uint8_t readUInt8(); + virtual uint16_t readUInt16(); + virtual uint32_t readUInt32(); + virtual uint64_t readUInt64(); + virtual float readFloat(); + virtual double readDouble(); + virtual bool readBoolean(); + virtual std::string readString(); + virtual void readBytes(uint32_t u32Len, uint8_t** pData); + }; + + class SIDX_DLL BufferedFileWriter : public BufferedFile + { + public: + BufferedFileWriter(); + BufferedFileWriter(const std::string& sFileName, FileMode mode = CREATE, uint32_t u32BufferSize = 32768); + ~BufferedFileWriter() override; + + virtual void open(const std::string& sFileName, FileMode mode = CREATE); + void rewind() override; + void seek(std::fstream::off_type offset) override; + + virtual void write(uint8_t i); + virtual void write(uint16_t i); + virtual void write(uint32_t i); + virtual void write(uint64_t i); + virtual void write(float i); + virtual void write(double i); + virtual void write(bool b); + virtual void write(const std::string& s); + virtual void write(uint32_t u32Len, uint8_t* pData); + }; + + class SIDX_DLL TemporaryFile + { + public: + TemporaryFile(); + virtual ~TemporaryFile(); + + void rewindForReading(); + void rewindForWriting(); + bool eof(); + std::string getFileName() const; + + uint8_t readUInt8(); + uint16_t readUInt16(); + uint32_t readUInt32(); + uint64_t readUInt64(); + float readFloat(); + double readDouble(); + std::string readString(); + void readBytes(uint32_t u32Len, uint8_t** pData); + + void write(uint8_t i); + void write(uint16_t i); + void write(uint32_t i); + void write(uint64_t i); + void write(float i); + void write(double i); + void write(const std::string& s); + void write(uint32_t u32Len, uint8_t* pData); + + private: + std::string m_sFile; + BufferedFile* m_pFile; + }; +} diff --git a/third_party/libspatialindex/larch64/include/spatialindex/tools/rand48.h b/third_party/libspatialindex/larch64/include/spatialindex/tools/rand48.h new file mode 100644 index 000000000..46ff3226a --- /dev/null +++ b/third_party/libspatialindex/larch64/include/spatialindex/tools/rand48.h @@ -0,0 +1,89 @@ +/****************************************************************************** + * Project: libspatialindex - A C++ library for spatial indexing + * Author: Howard Butler, hobu.inc@gmail.com + ****************************************************************************** + * Copyright (c) 2011, Howard Butler + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#pragma once + +/* Only define this stuff if we're not ANDROID */ +#ifndef ANDROID + +#ifndef HAVE_SRAND48 + +#if HAVE_FEATURES_H +#include +#ifndef __THROW +/* copy-pasted from sys/cdefs.h */ +/* GCC can always grok prototypes. For C++ programs we add throw() +to help it optimize the function calls. But this works only with +gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions +as non-throwing using a function attribute since programs can use +the -fexceptions options for C code as well. */ +# if !defined __cplusplus && __GNUC_PREREQ (3, 3) +# define __THROW __attribute__ ((__nothrow__)) +# define __NTH(fct) __attribute__ ((__nothrow__)) fct +# else +# if defined __cplusplus && __GNUC_PREREQ (2,8) +# define __THROW throw () +# define __NTH(fct) fct throw () +# else +# define __THROW +# define __NTH(fct) fct +# endif +# endif +#endif +#endif + +#ifndef __THROW +# define __THROW +#endif + +#ifndef __NTH +# define __NTH(fct) fct +#endif + +extern void srand48(long int seed) __THROW; + +extern unsigned short *seed48(unsigned short xseed[3]) __THROW; + +extern long nrand48(unsigned short xseed[3]) __THROW; + +extern long mrand48(void) __THROW; + +extern long lrand48(void) __THROW; + +extern void lcong48(unsigned short p[7]) __THROW; + +extern long jrand48(unsigned short xseed[3]) __THROW; + +extern double erand48(unsigned short xseed[3]) __THROW; + +extern double drand48(void) __THROW; + +#endif + +/* Only define this stuff if we're not ANDROID */ +#endif diff --git a/third_party/libspatialindex/larch64/lib/libspatialindex.so b/third_party/libspatialindex/larch64/lib/libspatialindex.so new file mode 120000 index 000000000..58916f7ba --- /dev/null +++ b/third_party/libspatialindex/larch64/lib/libspatialindex.so @@ -0,0 +1 @@ +libspatialindex.so.7 \ No newline at end of file diff --git a/third_party/libspatialindex/larch64/lib/libspatialindex.so.7 b/third_party/libspatialindex/larch64/lib/libspatialindex.so.7 new file mode 120000 index 000000000..4bde966fb --- /dev/null +++ b/third_party/libspatialindex/larch64/lib/libspatialindex.so.7 @@ -0,0 +1 @@ +libspatialindex.so.7.0.0 \ No newline at end of file diff --git a/third_party/libspatialindex/larch64/lib/libspatialindex.so.7.0.0 b/third_party/libspatialindex/larch64/lib/libspatialindex.so.7.0.0 new file mode 100644 index 000000000..0a777458f Binary files /dev/null and b/third_party/libspatialindex/larch64/lib/libspatialindex.so.7.0.0 differ diff --git a/third_party/libspatialindex/larch64/lib/libspatialindex_c.so b/third_party/libspatialindex/larch64/lib/libspatialindex_c.so new file mode 120000 index 000000000..fe5192b58 --- /dev/null +++ b/third_party/libspatialindex/larch64/lib/libspatialindex_c.so @@ -0,0 +1 @@ +libspatialindex_c.so.7 \ No newline at end of file diff --git a/third_party/libspatialindex/larch64/lib/libspatialindex_c.so.7 b/third_party/libspatialindex/larch64/lib/libspatialindex_c.so.7 new file mode 120000 index 000000000..c5fccf46a --- /dev/null +++ b/third_party/libspatialindex/larch64/lib/libspatialindex_c.so.7 @@ -0,0 +1 @@ +libspatialindex_c.so.7.0.0 \ No newline at end of file diff --git a/third_party/libspatialindex/larch64/lib/libspatialindex_c.so.7.0.0 b/third_party/libspatialindex/larch64/lib/libspatialindex_c.so.7.0.0 new file mode 100644 index 000000000..1e793dcda Binary files /dev/null and b/third_party/libspatialindex/larch64/lib/libspatialindex_c.so.7.0.0 differ