spatial hash using pareto for vertex positions
This commit is contained in:
parent
d9a3abfba7
commit
f5ef0f90f4
|
|
@ -13,3 +13,6 @@
|
||||||
[submodule "3rdparty/Catch2"]
|
[submodule "3rdparty/Catch2"]
|
||||||
path = 3rdparty/Catch2
|
path = 3rdparty/Catch2
|
||||||
url = https://github.com/catchorg/Catch2
|
url = https://github.com/catchorg/Catch2
|
||||||
|
[submodule "3rdparty/pareto"]
|
||||||
|
path = 3rdparty/pareto
|
||||||
|
url = https://github.com/alandefreitas/pareto.git
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ add_subdirectory(fmt EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(Catch2 EXCLUDE_FROM_ALL)
|
add_subdirectory(Catch2 EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(json EXCLUDE_FROM_ALL)
|
add_subdirectory(json EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(nanobench EXCLUDE_FROM_ALL)
|
add_subdirectory(nanobench EXCLUDE_FROM_ALL)
|
||||||
|
add_subdirectory(pareto EXCLUDE_FROM_ALL)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 47f491eeaead1b5a95e27ee3d6bc4c591b0e4462
|
||||||
|
|
@ -136,12 +136,6 @@ struct maptexdata_t
|
||||||
|
|
||||||
extern std::shared_mutex map_planes_lock;
|
extern std::shared_mutex map_planes_lock;
|
||||||
|
|
||||||
struct hashvert_t
|
|
||||||
{
|
|
||||||
qvec3d point;
|
|
||||||
size_t num;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct mapplane_t : qbsp_plane_t
|
struct mapplane_t : qbsp_plane_t
|
||||||
{
|
{
|
||||||
std::optional<size_t> outputnum;
|
std::optional<size_t> outputnum;
|
||||||
|
|
@ -173,6 +167,8 @@ struct qbsp_plane_eq
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <pareto/spatial_map.h>
|
||||||
|
|
||||||
struct mapdata_t
|
struct mapdata_t
|
||||||
{
|
{
|
||||||
/* Arrays of actual items */
|
/* Arrays of actual items */
|
||||||
|
|
@ -256,7 +252,7 @@ struct mapdata_t
|
||||||
std::unordered_map<int, std::vector<int>> planehash;
|
std::unordered_map<int, std::vector<int>> planehash;
|
||||||
|
|
||||||
// hashed vertices; generated by EmitVertices
|
// hashed vertices; generated by EmitVertices
|
||||||
std::map<qvec3i, std::list<hashvert_t>> hashverts;
|
pareto::spatial_map<vec_t, 3, size_t> hashverts {};
|
||||||
|
|
||||||
// find vector of points in hash closest to vec
|
// find vector of points in hash closest to vec
|
||||||
inline auto find_hash_vector(const qvec3d &vec)
|
inline auto find_hash_vector(const qvec3d &vec)
|
||||||
|
|
@ -267,12 +263,11 @@ struct mapdata_t
|
||||||
// find output index for specified already-output vector.
|
// find output index for specified already-output vector.
|
||||||
inline std::optional<size_t> find_emitted_hash_vector(const qvec3d &vert)
|
inline std::optional<size_t> find_emitted_hash_vector(const qvec3d &vert)
|
||||||
{
|
{
|
||||||
if (auto it = find_hash_vector(vert); it != hashverts.end()) {
|
static const vec_t point_epsilon_with_border = std::nextafter(POINT_EQUAL_EPSILON, 1.0);
|
||||||
for (hashvert_t &hv : it->second) {
|
|
||||||
if (qv::epsilonEqual(hv.point, vert, POINT_EQUAL_EPSILON)) {
|
if (auto it = hashverts.find_intersection({{ vert[0] - (POINT_EQUAL_EPSILON * 0.5), vert[1] - (POINT_EQUAL_EPSILON * 0.5), vert[2] - (POINT_EQUAL_EPSILON * 0.5) }},
|
||||||
return hv.num;
|
{{ vert[0] + (POINT_EQUAL_EPSILON * 0.5) }, { vert[1] + (POINT_EQUAL_EPSILON * 0.5) }, { vert[2] + (POINT_EQUAL_EPSILON * 0.5) }}); it != hashverts.end()) {
|
||||||
}
|
return it->second;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
@ -281,17 +276,7 @@ struct mapdata_t
|
||||||
// add vector to hash
|
// add vector to hash
|
||||||
inline void add_hash_vector(const qvec3d &point, const size_t &num)
|
inline void add_hash_vector(const qvec3d &point, const size_t &num)
|
||||||
{
|
{
|
||||||
// insert each vert at floor(pos[axis]) and floor(pos[axis]) + 1 (for each axis)
|
hashverts.emplace(pareto::point<vec_t, 3>({ point[0], point[1], point[2] }), num);
|
||||||
// so e.g. a vert at (0.99, 0.99, 0.99) shows up if we search at (1.01, 1.01, 1.01)
|
|
||||||
// this is a bit wasteful..
|
|
||||||
for (int32_t x = -1; x <= 1; x++) {
|
|
||||||
for (int32_t y = -1; y <= 1; y++) {
|
|
||||||
for (int32_t z = -1; z <= 1; z++) {
|
|
||||||
const qvec3i h{floor(point[0]) + x, floor(point[1]) + y, floor(point[2]) + z};
|
|
||||||
hashverts[h].push_front({point, num});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashed edges; generated by EmitEdges
|
// hashed edges; generated by EmitEdges
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ set(QBSP_SOURCES
|
||||||
${QBSP_INCLUDES})
|
${QBSP_INCLUDES})
|
||||||
|
|
||||||
add_library(libqbsp STATIC ${QBSP_SOURCES})
|
add_library(libqbsp STATIC ${QBSP_SOURCES})
|
||||||
target_link_libraries(libqbsp common ${CMAKE_THREAD_LIBS_INIT} TBB::tbb fmt::fmt nlohmann_json::nlohmann_json)
|
target_link_libraries(libqbsp common ${CMAKE_THREAD_LIBS_INIT} TBB::tbb fmt::fmt nlohmann_json::nlohmann_json pareto)
|
||||||
|
|
||||||
add_executable(qbsp main.cc)
|
add_executable(qbsp main.cc)
|
||||||
target_link_libraries(qbsp libqbsp)
|
target_link_libraries(qbsp libqbsp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue