From a6d39dbca12bb11022546e67fc549e86efbf2703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csik=C3=B3s=20Attila?= Date: Wed, 6 Mar 2024 22:54:40 +0100 Subject: [PATCH] Issue: #22 glm adaptor --- adaptor.glm.h | 222 ++++++++++++++++++++++ adaptortests/adaptortests.vcxproj | 5 + adaptortests/adaptortests.vcxproj.filters | 21 ++ adaptortests/test.cpp | 43 +++++ adaptortests/vcpkg.json | 3 +- unittests/unittests.vcxproj | 1 + unittests/unittests.vcxproj.filters | 3 + 7 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 adaptor.glm.h create mode 100644 adaptortests/adaptortests.vcxproj.filters diff --git a/adaptor.glm.h b/adaptor.glm.h new file mode 100644 index 0000000..a52c975 --- /dev/null +++ b/adaptor.glm.h @@ -0,0 +1,222 @@ +#pragma once +/* +MIT License + +Copyright (c) 2021 Attila Csikós + +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 "octree.h" +// #include +namespace glm +{ + // Define related elements + + template + struct boxNd_t + { + vec min; + vec max; + }; + + template + struct rayNd_t + { + vec origin; + vec direction; + }; + + template + struct planeNd_t + { + TGeometry origo_distance; // origo_distance = dot_product(normal, any_point) + vec normal; // should be normalized + }; + + using box2 = boxNd_t<2, float>; + using ray2 = rayNd_t<2, float>; + using plane2 = planeNd_t<2, float>; + + using box3 = boxNd_t<3, float>; + using ray3 = rayNd_t<3, float>; + using plane3 = planeNd_t<3, float>; + + using box4 = boxNd_t<4, float>; + using ray4 = rayNd_t<4, float>; + using plane4 = planeNd_t<4, float>; +} // namespace glm + + +namespace OrthoTree +{ + namespace GlmAdaptor + { + + template + struct AdaptorGeneralBasics + { + using TVector = glm::vec; + using TBox = glm::boxNd_t; + using TRay = glm::rayNd_t; + using TPlane = glm::planeNd_t; + + + static constexpr TGeometry GetPointC(TVector const& point, dim_t dimensionID) noexcept { return point[dimensionID]; } + static constexpr void SetPointC(TVector& point, dim_t dimensionID, TGeometry value) noexcept { point[dimensionID] = value; } + + static constexpr TGeometry GetBoxMinC(TBox const& box, dim_t dimensionID) noexcept { return GetPointC(box.min, dimensionID); } + static constexpr TGeometry GetBoxMaxC(TBox const& box, dim_t dimensionID) noexcept { return GetPointC(box.max, dimensionID); } + static constexpr void SetBoxMinC(TBox& box, dim_t dimensionID, TGeometry value) noexcept { SetPointC(box.min, dimensionID, value); } + static constexpr void SetBoxMaxC(TBox& box, dim_t dimensionID, TGeometry value) noexcept { SetPointC(box.max, dimensionID, value); } + + static constexpr TVector const& GetRayDirection(TRay const& ray) noexcept { return ray.direction; } + static constexpr TVector const& GetRayOrigin(TRay const& ray) noexcept { return ray.origin; } + + static constexpr TVector const& GetPlaneNormal(TPlane const& plane) noexcept { return plane.normal; } + static constexpr TGeometry GetPlaneOrigoDistance(TPlane const& plane) noexcept { return plane.origo_distance; } + }; + + template + using GlmAdaptorGeneral = AdaptorGeneralBase< + DIMENSION_NO, + glm::vec, + glm::boxNd_t, + glm::rayNd_t, + glm::planeNd_t, + TGeometry, + AdaptorGeneralBasics>; + + template + using GlmOrthoTreePoint = OrthoTreePoint< + DIMENSION_NO, + glm::vec, + glm::boxNd_t, + glm::rayNd_t, + glm::planeNd_t, + TGeometry, + GlmAdaptorGeneral>; + + template + using GlmOrthoTreeBoundingBox = OrthoTreeBoundingBox< + DIMENSION_NO, + glm::vec, + glm::boxNd_t, + glm::rayNd_t, + glm::planeNd_t, + TGeometry, + SPLIT_DEPTH_INCREASEMENT, + GlmAdaptorGeneral>; + } // namespace GlmAdapter +} // namespace OrthoTree + +namespace glm +{ + using namespace OrthoTree::GlmAdaptor; + + // Core types + + template + using orthotree_point_t = GlmOrthoTreePoint; + + using quadtree_point_d = GlmOrthoTreePoint<2, double>; + using quadtree_point_f = GlmOrthoTreePoint<2, float>; + using quadtree_point_i = GlmOrthoTreePoint<2, int>; + using quadtree_point = quadtree_point_f; + + using octree_point_d = GlmOrthoTreePoint<3, double>; + using octree_point_f = GlmOrthoTreePoint<3, float>; + using octree_point_i = GlmOrthoTreePoint<3, int>; + using octree_point = octree_point_f; + + using hextree_point_d = GlmOrthoTreePoint<4, double>; + using hextree_point_f = GlmOrthoTreePoint<4, float>; + using hextree_point_i = GlmOrthoTreePoint<4, int>; + using hextree_point = hextree_point_f; + + template + using orthotree_box_t = GlmOrthoTreeBoundingBox; + + template + using quadtree_box_ds = GlmOrthoTreeBoundingBox<2, SPLIT_DEPTH_INCREASEMENT, double>; + using quadtree_box_d = GlmOrthoTreeBoundingBox<2, 2, double>; + using quadtree_box_f = GlmOrthoTreeBoundingBox<2, 2, float>; + using quadtree_box_i = GlmOrthoTreeBoundingBox<2, 2, int>; + using quadtree_box = quadtree_box_f; + + template + using octree_box_ds = GlmOrthoTreeBoundingBox<3, SPLIT_DEPTH_INCREASEMENT, double>; + using octree_box_d = GlmOrthoTreeBoundingBox<3, 2, double>; + using octree_box_f = GlmOrthoTreeBoundingBox<3, 2, float>; + using octree_box_i = GlmOrthoTreeBoundingBox<3, 2, int>; + using octree_box = octree_box_f; + + template + using hextree_box_ds = GlmOrthoTreeBoundingBox<4, SPLIT_DEPTH_INCREASEMENT, double>; + using hextree_box_d = GlmOrthoTreeBoundingBox<4, 2, double>; + using hextree_box_f = GlmOrthoTreeBoundingBox<4, 2, float>; + using hextree_box_i = GlmOrthoTreeBoundingBox<4, 2, int>; + using hextree_box = hextree_box_f; + + // Container types + + template + using orthotree_point_c_t = OrthoTree::OrthoTreeContainerPoint, vec>; + + using quadtree_point_c_d = orthotree_point_c_t<2, double>; + using quadtree_point_c_f = orthotree_point_c_t<2, float>; + using quadtree_point_c_i = orthotree_point_c_t<2, int>; + using quadtree_point_c = quadtree_point_c_d; + + using octree_point_c_d = orthotree_point_c_t<3, double>; + using octree_point_c_f = orthotree_point_c_t<3, float>; + using octree_point_c_i = orthotree_point_c_t<3, int>; + using octree_point_c = octree_point_c_f; + + using hextree_point_c_d = orthotree_point_c_t<4, double>; + using hextree_point_c_f = orthotree_point_c_t<4, float>; + using hextree_point_c_i = orthotree_point_c_t<4, int>; + using hextree_point_c = hextree_point_c_f; + + + template + using orthotree_box_c_t = + OrthoTree::OrthoTreeContainerBox, boxNd_t>; + + template + using quadtree_box_c_ds = orthotree_box_c_t<2, SPLIT_DEPTH_INCREASEMENT, double>; + using quadtree_box_c_d = orthotree_box_c_t<2, 2, double>; + using quadtree_box_c_f = orthotree_box_c_t<2, 2, float>; + using quadtree_box_c_i = orthotree_box_c_t<2, 2, int>; + using quadtree_box_c = quadtree_box_c_f; + + template + using octree_box_c_ds = orthotree_box_c_t<3, SPLIT_DEPTH_INCREASEMENT, double>; + using octree_box_c_d = orthotree_box_c_t<3, 2, double>; + using octree_box_c_f = orthotree_box_c_t<3, 2, float>; + using octree_box_c_i = orthotree_box_c_t<3, 2, int>; + using octree_box_c = octree_box_c_f; + + template + using hextree_box_c_ds = orthotree_box_c_t<4, SPLIT_DEPTH_INCREASEMENT, double>; + using hextree_box_c_d = orthotree_box_c_t<4, 2, double>; + using hextree_box_c_f = orthotree_box_c_t<4, 2, float>; + using hextree_box_c_i = orthotree_box_c_t<4, 2, int>; + using hextree_box_c = hextree_box_c_f; +} // namespace boost::geometry \ No newline at end of file diff --git a/adaptortests/adaptortests.vcxproj b/adaptortests/adaptortests.vcxproj index e0ac156..9728eb9 100644 --- a/adaptortests/adaptortests.vcxproj +++ b/adaptortests/adaptortests.vcxproj @@ -46,6 +46,7 @@ MultiThreadedDebugDLL Level3 stdcpp20 + /bigobj %(AdditionalOptions) true @@ -62,6 +63,7 @@ MultiThreadedDebugDLL Level3 stdcpp20 + /bigobj %(AdditionalOptions) true @@ -77,6 +79,7 @@ Level3 ProgramDatabase stdcpp20 + /bigobj %(AdditionalOptions) true @@ -94,6 +97,7 @@ Level3 ProgramDatabase stdcpp20 + /bigobj %(AdditionalOptions) true @@ -103,6 +107,7 @@ + diff --git a/adaptortests/adaptortests.vcxproj.filters b/adaptortests/adaptortests.vcxproj.filters new file mode 100644 index 0000000..b9f2e33 --- /dev/null +++ b/adaptortests/adaptortests.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + + + + + + Adapters + + + + + + + + {bb49d17a-b3d1-4108-b8e9-a0c4e9d02a22} + + + \ No newline at end of file diff --git a/adaptortests/test.cpp b/adaptortests/test.cpp index a0d7aaf..e1de97e 100644 --- a/adaptortests/test.cpp +++ b/adaptortests/test.cpp @@ -13,6 +13,10 @@ #include #include "../adaptor.eigen.h" +// glm +#include +#include "../adaptor.glm.h" + // XYZ #include "../adaptor.xyz.h" @@ -62,6 +66,7 @@ namespace } } + // Boost template void rayConv(TRay const& rayO, typename boost::geometry::model::rayNd_t& rayA) @@ -78,6 +83,8 @@ namespace } + // Eigen + template void rayConv(TRay const& rayO, Eigen::ParametrizedLine& rayA) { @@ -94,12 +101,32 @@ namespace } + // glm + + template + void rayConv(TRay const& rayO, typename glm::rayNd_t& rayA) + { + vectorConv(rayO.Origin, rayA.origin); + vectorConv(rayO.Direction, rayA.direction); + } + + template + void planeConv(TPlane const& planeO, typename glm::planeNd_t& planeA) + { + vectorConv(planeO.Normal, planeA.normal); + planeA.origo_distance = typename TOrthoTreeA::TGeometry(planeO.OrigoDistance); + } + + + // Unreal + template void rayConv(TRay const& rayO, FQuadtreePoint::TRay& rayA) { vectorConv(rayO.Origin, rayA.Origin); vectorConv(rayO.Direction, rayA.Direction); } + template void planeConv(TPlane const& planeO, FQuadtreePoint::TPlane& planeA) { @@ -123,6 +150,8 @@ namespace } + // XYZ + template void rayConv(TRay const& rayO, BasicTypesXYZ::Ray2D& rayA) { @@ -486,6 +515,20 @@ namespace EigenAdapter } } // namespace EigenAdapter + +namespace glmAdapter +{ + TEST(glm_CoreTest, Point3D) + { + corePointTest3D(); + } + + TEST(glm_ContainerTest, Box2D) + { + containerBoxTest2D(); + } +} // namespace glmAdapter + namespace UnrealAdapter { TEST(Unreal_CoreTest, Point3D) diff --git a/adaptortests/vcpkg.json b/adaptortests/vcpkg.json index 2ec8efb..ec6d79e 100644 --- a/adaptortests/vcpkg.json +++ b/adaptortests/vcpkg.json @@ -1,7 +1,8 @@ { "dependencies": [ "boost", + "eigen3", "gtest", - "eigen3" + "glm" ] } diff --git a/unittests/unittests.vcxproj b/unittests/unittests.vcxproj index c183749..099bb63 100644 --- a/unittests/unittests.vcxproj +++ b/unittests/unittests.vcxproj @@ -193,6 +193,7 @@ + diff --git a/unittests/unittests.vcxproj.filters b/unittests/unittests.vcxproj.filters index 0f28523..e50d6e2 100644 --- a/unittests/unittests.vcxproj.filters +++ b/unittests/unittests.vcxproj.filters @@ -59,6 +59,9 @@ Header Files + + Header Files +