CDT  1.4.2
C++ library for constrained Delaunay triangulation
 
Loading...
Searching...
No Matches
LocatorKDTree.h
Go to the documentation of this file.
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
9
10#ifndef CDT_POINTKDTREE_H
11#define CDT_POINTKDTREE_H
12
13#include "CDTUtils.h"
14#include "KDTree.h"
15
16namespace CDT
17{
18
20template <
21 typename TCoordType,
22 size_t NumVerticesInLeaf = 32,
23 size_t InitialStackDepth = 32,
24 size_t StackDepthIncrement = 32>
26{
27public:
29 void initialize(const std::vector<V2d<TCoordType> >& points)
30 {
31 typedef V2d<TCoordType> V2d_t;
32 V2d_t min = points.front();
33 V2d_t max = min;
34 typedef typename std::vector<V2d_t>::const_iterator Cit;
35 for(Cit it = points.begin(); it != points.end(); ++it)
36 {
37 min = V2d_t(std::min(min.x, it->x), std::min(min.y, it->y));
38 max = V2d_t(std::max(max.x, it->x), std::max(max.y, it->y));
39 }
40 m_kdTree = KDTree_t(min, max);
41 for(VertInd i(0); i < points.size(); ++i)
42 {
43 m_kdTree.insert(i, points);
44 }
45 }
46
47 void addPoint(const VertInd i, const std::vector<V2d<TCoordType> >& points)
48 {
49 m_kdTree.insert(i, points);
50 }
51
53 const V2d<TCoordType>& pos,
54 const std::vector<V2d<TCoordType> >& points) const
55 {
56 return m_kdTree.nearest(pos, points).second;
57 }
58
59 CDT::VertInd size() const
60 {
61 return m_kdTree.size();
62 }
63
64 bool empty() const
65 {
66 return !size();
67 }
68
69private:
70 typedef KDTree::KDTree<
71 TCoordType,
72 NumVerticesInLeaf,
73 InitialStackDepth,
74 StackDepthIncrement>
75 KDTree_t;
76 KDTree_t m_kdTree;
77};
78
79} // namespace CDT
80
81#endif
Utilities and helpers.
KD-tree holding points.
void initialize(const std::vector< V2d< TCoordType > > &points)
Initialize KD-tree with points.
void addPoint(const VertInd i, const std::vector< V2d< TCoordType > > &points)
Add point to KD-tree.
VertInd nearPoint(const V2d< TCoordType > &pos, const std::vector< V2d< TCoordType > > &points) const
Find nearest point using R-tree.
Namespace containing triangulation functionality.
IndexSizeType VertInd
Vertex index.
Definition CDTUtils.h:191
2D vector
Definition CDTUtils.h:136