Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit 0fa897f

Browse files
authored
Merge pull request #55 from MetacityTools/dev
Implementing QuadTree alternative to Grid layout
2 parents 68ee959 + cf27625 commit 0fa897f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1047
-343
lines changed

CMakeLists.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ pybind11_add_module(geometry src/metacity/geometry/geometry.cpp
2929
src/metacity/geometry/types.hpp
3030
src/metacity/geometry/convert.hpp
3131
src/metacity/geometry/progress.hpp
32-
src/metacity/geometry/mesh_pipeline/bbox.hpp
33-
src/metacity/geometry/mesh_pipeline/bbox.cpp
34-
src/metacity/geometry/mesh_pipeline/modifiers.hpp
35-
src/metacity/geometry/mesh_pipeline/modifiers.cpp
36-
src/metacity/geometry/mesh_pipeline/graham.hpp
37-
src/metacity/geometry/mesh_pipeline/graham.cpp
38-
src/metacity/geometry/mesh_pipeline/bvh.hpp
39-
src/metacity/geometry/mesh_pipeline/bvh.cpp
40-
src/metacity/geometry/mesh_pipeline/model.hpp
41-
src/metacity/geometry/mesh_pipeline/model.cpp
42-
src/metacity/geometry/mesh_pipeline/layer.hpp
43-
src/metacity/geometry/mesh_pipeline/layer.cpp
44-
src/metacity/geometry/mesh_pipeline/attribute.hpp
45-
src/metacity/geometry/mesh_pipeline/attribute.cpp
46-
src/metacity/geometry/mesh_pipeline/grid.hpp
47-
src/metacity/geometry/mesh_pipeline/grid.cpp
48-
src/metacity/geometry/mesh_pipeline/triangulation.hpp
49-
src/metacity/geometry/mesh_pipeline/triangulation.cpp
50-
src/metacity/geometry/vector_pipeline/graph.hpp
51-
src/metacity/geometry/vector_pipeline/graph.cpp)
32+
src/metacity/geometry/mesh/bbox.hpp
33+
src/metacity/geometry/mesh/bbox.cpp
34+
src/metacity/geometry/mesh/modifiers.hpp
35+
src/metacity/geometry/mesh/modifiers.cpp
36+
src/metacity/geometry/mesh/graham.hpp
37+
src/metacity/geometry/mesh/graham.cpp
38+
src/metacity/geometry/mesh/bvh.hpp
39+
src/metacity/geometry/mesh/bvh.cpp
40+
src/metacity/geometry/mesh/model.hpp
41+
src/metacity/geometry/mesh/model.cpp
42+
src/metacity/geometry/mesh/layer.hpp
43+
src/metacity/geometry/mesh/layer.cpp
44+
src/metacity/geometry/mesh/attribute.hpp
45+
src/metacity/geometry/mesh/attribute.cpp
46+
src/metacity/geometry/mesh/grid.hpp
47+
src/metacity/geometry/mesh/grid.cpp
48+
src/metacity/geometry/mesh/quadtree.hpp
49+
src/metacity/geometry/mesh/quadtree.cpp
50+
src/metacity/geometry/mesh/triangulation.hpp
51+
src/metacity/geometry/mesh/triangulation.cpp)
5252

5353
install(TARGETS geometry DESTINATION .)

LICENCE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2022 Vojtěch Tomas - Metacity Tools
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

setup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121

2222
setup(
2323
name="metacity",
24-
version="0.5.3",
25-
author="Metacity",
24+
version="0.6.0",
25+
author="Vojtěch Tomas",
26+
author_email="[email protected]",
2627
license="MIT",
2728
description="Python toolkit for Urban Data processing",
2829
long_description=README,
@@ -31,7 +32,10 @@
3132
package_dir={"": "src"},
3233
cmake_install_dir="src/metacity",
3334
install_requires = [
34-
"orjson>=3.6.4"
35+
"orjson>=3.6.4",
36+
"colored>=1.4.3",
37+
"six",
38+
"protobuf>=4.21.7"
3539
],
3640
url="https://github.com/MetacitySuite/Metacity",
3741
python_requires='>=3.8',

src/metacity/geometry.pyi

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/metacity/geometry/geometry.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include <pybind11/functional.h>
44
#include "deps/gltf/pybind11_json.hpp"
55
#include "progress.hpp"
6-
#include "mesh_pipeline/model.hpp"
7-
#include "mesh_pipeline/attribute.hpp"
8-
#include "mesh_pipeline/layer.hpp"
9-
#include "mesh_pipeline/grid.hpp"
10-
#include "vector_pipeline/graph.hpp"
6+
#include "mesh/model.hpp"
7+
#include "mesh/attribute.hpp"
8+
#include "mesh/layer.hpp"
9+
#include "mesh/grid.hpp"
10+
#include "mesh/quadtree.hpp"
1111

1212
#define TINYGLTF_IMPLEMENTATION
1313
#define STB_IMAGE_IMPLEMENTATION
@@ -62,16 +62,9 @@ PYBIND11_MODULE(geometry, m) {
6262
.def(py::init<string>())
6363
.def("update", &Progress::update);
6464

65-
py::class_<Edge, std::shared_ptr<Edge>>(m, "Edge")
66-
.def(py::init<size_t, size_t, size_t, std::shared_ptr<Attribute>, nlohmann::json>());
67-
68-
py::class_<Node, std::shared_ptr<Node>>(m, "Node")
69-
.def(py::init<size_t, tfloat, tfloat, nlohmann::json>());
70-
71-
py::class_<Graph, std::shared_ptr<Graph>>(m, "Graph")
72-
.def(py::init<>())
73-
.def("add_node", &Graph::add_node)
74-
.def("add_edge", &Graph::add_edge)
75-
.def_property_readonly("node_count", &Graph::get_node_count)
76-
.def_property_readonly("edge_count", &Graph::get_edge_count);
65+
py::class_<QuadTree, std::shared_ptr<QuadTree>>(m, "QuadTree")
66+
.def(py::init<const vector<shared_ptr<Model>> &, size_t>())
67+
.def(py::init<shared_ptr<Layer>, size_t>())
68+
.def("merge_at_level", &QuadTree::merge_at_level)
69+
.def("to_json", &QuadTree::to_json, py::arg("dirname"), py::arg("yield_models_at_level"), py::arg("store_metadata") = true);
7770
}

src/metacity/geometry/mesh_pipeline/attribute.cpp renamed to src/metacity/geometry/mesh/attribute.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "attribute.hpp"
22
#include "triangulation.hpp"
33

4+
45
Attribute::Attribute() : dtype(AttributeType::NONE) {}
56

67
void Attribute::allowedAttributeType(AttributeType type)
@@ -151,9 +152,9 @@ const tvec3 &Attribute::operator[](const size_t index) const
151152
throw runtime_error("Index out of range");
152153
}
153154

154-
pair<tvec3, tvec3> Attribute::bbox() const
155+
BBox Attribute::bbox() const
155156
{
156-
return make_pair(vmin(), vmax());
157+
return BBox{vmin(), vmax()};
157158
}
158159

159160
tvec3 Attribute::vmin() const

src/metacity/geometry/mesh_pipeline/attribute.hpp renamed to src/metacity/geometry/mesh/attribute.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <vector>
33
#include "../types.hpp"
44
#include "../deps/gltf/tiny_gltf.h"
5+
#include "bbox.hpp"
56

67
using namespace std;
78

@@ -44,7 +45,7 @@ class Attribute
4445
tvec3 &operator[](const size_t index);
4546
const tvec3 &operator[](const size_t index) const;
4647

47-
pair<tvec3, tvec3> bbox() const;
48+
BBox bbox() const;
4849
AttributeType geom_type() const;
4950

5051
protected:

src/metacity/geometry/mesh_pipeline/bbox.cpp renamed to src/metacity/geometry/mesh/bbox.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool overlaps(const BBox &b1, const BBox &b2)
4040

4141
bool inside(const BBox &b, const tvec3 &p)
4242
{
43-
return ((b.min.x <= p.x) && (p.x <= b.max.x)) && ((b.min.y <= p.y) && (p.y <= b.max.y));
43+
return ((b.min.x <= p.x) && (p.x < b.max.x)) && ((b.min.y <= p.y) && (p.y < b.max.y));
4444
}
4545

4646
void set_empty(BBox &box)
@@ -81,3 +81,16 @@ tfloat midpoint(const BBox &b1, uint8_t axis)
8181
{
8282
return (b1.min[axis] + b1.max[axis]) / 2;
8383
}
84+
85+
BBox toEqualXY(const BBox &b1) {
86+
BBox b2 = b1;
87+
tvec3 mid = b1.centroid();
88+
tfloat hx = (b1.max.x - b1.min.x) / 2;
89+
tfloat hy = (b1.max.y - b1.min.y) / 2;
90+
tfloat rad = max(hx, hy);
91+
b2.min.x = mid.x - rad;
92+
b2.min.y = mid.y - rad;
93+
b2.max.x = mid.x + rad;
94+
b2.max.y = mid.y + rad;
95+
return b2;
96+
}

src/metacity/geometry/mesh_pipeline/bbox.hpp renamed to src/metacity/geometry/mesh/bbox.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ void set_empty(BBox &box);
2121
BBox empty_bbox();
2222
void extend(BBox &b1, const BBox &b2);
2323
void extend(BBox &b1, const tvec3 &p);
24+
BBox toEqualXY(const BBox &b1);
2425
tfloat midpoint(const BBox &b1, uint8_t axis);

src/metacity/geometry/mesh_pipeline/bvh.cpp renamed to src/metacity/geometry/mesh/bvh.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ tfloat BVH::traceDownRegualarRay(const tfloat x, const tfloat y, const tfloat z)
198198
return ray.t;
199199

200200
recursiveTrace(ray, root);
201+
202+
if (ray.t == RTINFINITY)
203+
return RTINFINITY;
204+
201205
return 10000 - ray.t;
202206
}
203207

0 commit comments

Comments
 (0)