From 2a67c0f3f1dcf79b1ae235fd93062d6c12f3015b Mon Sep 17 00:00:00 2001 From: Zhivko Bogdanov Date: Wed, 27 Oct 2021 09:10:31 +0200 Subject: [PATCH 1/4] Provide customization points to the k-d tree in the locator. If we want to customize any of the k-d tree template values, we have to change the instance within the locator. To support multiple locators with different configurations, it's best to have the template arguments available in the locator declaration as well. --- CDT/include/LocatorKDTree.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CDT/include/LocatorKDTree.h b/CDT/include/LocatorKDTree.h index ddddbc87..2f3a0eaa 100644 --- a/CDT/include/LocatorKDTree.h +++ b/CDT/include/LocatorKDTree.h @@ -17,7 +17,11 @@ namespace CDT { /// KD-tree holding points -template +template < + typename TCoordType, + size_t NumVerticesInLeaf = 32, + size_t InitialStackDepth = 32, + size_t StackDepthIncrement = 32> class LocatorKDTree { public: @@ -34,7 +38,7 @@ class LocatorKDTree } private: - KDTree::KDTree m_kdTree; + KDTree::KDTree m_kdTree; }; } // namespace CDT From 936b333bd54fb0134915174d535ba7cd7d249075 Mon Sep 17 00:00:00 2001 From: Zhivko Bogdanov Date: Wed, 27 Oct 2021 09:22:27 +0200 Subject: [PATCH 2/4] Added missing additional template argument to the triangulation. After the refactor there is an additional template argument that was missing from the output parameter in `initializeWithRegularGrid` and `initializeWithIrregularGrid`. --- CDT/extras/InitializeWithGrid.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CDT/extras/InitializeWithGrid.h b/CDT/extras/InitializeWithGrid.h index ec536cec..d844b5f0 100644 --- a/CDT/extras/InitializeWithGrid.h +++ b/CDT/extras/InitializeWithGrid.h @@ -150,7 +150,7 @@ void generateGridTriangles( * @param yres grid Y-resolution * @param out triangulation to initialize with grid super-geometry */ -template +template void initializeWithRegularGrid( const T xmin, const T xmax, @@ -158,7 +158,7 @@ void initializeWithRegularGrid( const T ymax, const std::size_t xres, const std::size_t yres, - Triangulation& out) + Triangulation& out) { std::vector xcoords; std::vector ycoords; @@ -190,13 +190,13 @@ void initializeWithRegularGrid( * @param ylast end of Y-ticks range * @param out triangulation to initialize with grid super-geometry */ -template +template void initializeWithIrregularGrid( const TXCoordIter xfirst, const TXCoordIter xlast, const TYCoordIter yfirst, const TYCoordIter ylast, - Triangulation& out) + Triangulation& out) { const std::size_t xres = std::distance(xfirst, xlast) - 1; const std::size_t yres = std::distance(yfirst, ylast) - 1; From 9c51af7af79996c5ef83d0af43cbe5825a6be26c Mon Sep 17 00:00:00 2001 From: Zhivko Bogdanov Date: Wed, 27 Oct 2021 09:29:18 +0200 Subject: [PATCH 3/4] Renamed coordinate type template argument failing compilation. --- CDT/include/LocatorKDTree.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CDT/include/LocatorKDTree.h b/CDT/include/LocatorKDTree.h index 2f3a0eaa..7f6140d8 100644 --- a/CDT/include/LocatorKDTree.h +++ b/CDT/include/LocatorKDTree.h @@ -26,19 +26,19 @@ class LocatorKDTree { public: /// Add point to R-tree - void addPoint(const VertInd i, const std::vector >& points) + void addPoint(const VertInd i, const std::vector >& points) { m_kdTree.insert(i, points); } /// Find nearest point using R-tree VertInd - nearPoint(const V2d& pos, const std::vector >& points) const + nearPoint(const V2d& pos, const std::vector >& points) const { return m_kdTree.nearest(pos, points).second; } private: - KDTree::KDTree m_kdTree; + KDTree::KDTree m_kdTree; }; } // namespace CDT From d8442200f9da0f7acf57d4a374fff78d91af048a Mon Sep 17 00:00:00 2001 From: Zhivko Bogdanov Date: Wed, 27 Oct 2021 12:42:21 +0200 Subject: [PATCH 4/4] Format changes using the provided .clang-format style. --- CDT/extras/InitializeWithGrid.h | 6 +++++- CDT/include/LocatorKDTree.h | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CDT/extras/InitializeWithGrid.h b/CDT/extras/InitializeWithGrid.h index d844b5f0..71d81161 100644 --- a/CDT/extras/InitializeWithGrid.h +++ b/CDT/extras/InitializeWithGrid.h @@ -190,7 +190,11 @@ void initializeWithRegularGrid( * @param ylast end of Y-ticks range * @param out triangulation to initialize with grid super-geometry */ -template +template < + typename T, + typename TNearPointLocator, + typename TXCoordIter, + typename TYCoordIter> void initializeWithIrregularGrid( const TXCoordIter xfirst, const TXCoordIter xlast, diff --git a/CDT/include/LocatorKDTree.h b/CDT/include/LocatorKDTree.h index 7f6140d8..f128b54e 100644 --- a/CDT/include/LocatorKDTree.h +++ b/CDT/include/LocatorKDTree.h @@ -31,14 +31,20 @@ class LocatorKDTree m_kdTree.insert(i, points); } /// Find nearest point using R-tree - VertInd - nearPoint(const V2d& pos, const std::vector >& points) const + VertInd nearPoint( + const V2d& pos, + const std::vector >& points) const { return m_kdTree.nearest(pos, points).second; } private: - KDTree::KDTree m_kdTree; + KDTree::KDTree< + TCoordType, + NumVerticesInLeaf, + InitialStackDepth, + StackDepthIncrement> + m_kdTree; }; } // namespace CDT