Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kdtree locator customization points #51

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CDT/extras/InitializeWithGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ void generateGridTriangles(
* @param yres grid Y-resolution
* @param out triangulation to initialize with grid super-geometry
*/
template <typename T>
template <typename T, typename TNearPointLocator>
void initializeWithRegularGrid(
const T xmin,
const T xmax,
const T ymin,
const T ymax,
const std::size_t xres,
const std::size_t yres,
Triangulation<T>& out)
Triangulation<T, TNearPointLocator>& out)
{
std::vector<T> xcoords;
std::vector<T> ycoords;
Expand Down Expand Up @@ -190,13 +190,17 @@ void initializeWithRegularGrid(
* @param ylast end of Y-ticks range
* @param out triangulation to initialize with grid super-geometry
*/
template <typename T, typename TXCoordIter, typename TYCoordIter>
template <
typename T,
typename TNearPointLocator,
typename TXCoordIter,
typename TYCoordIter>
void initializeWithIrregularGrid(
const TXCoordIter xfirst,
const TXCoordIter xlast,
const TYCoordIter yfirst,
const TYCoordIter ylast,
Triangulation<T>& out)
Triangulation<T, TNearPointLocator>& out)
{
const std::size_t xres = std::distance(xfirst, xlast) - 1;
const std::size_t yres = std::distance(yfirst, ylast) - 1;
Expand Down
20 changes: 15 additions & 5 deletions CDT/include/LocatorKDTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,34 @@ namespace CDT
{

/// KD-tree holding points
template <typename T>
template <
typename TCoordType,
size_t NumVerticesInLeaf = 32,
size_t InitialStackDepth = 32,
size_t StackDepthIncrement = 32>
class LocatorKDTree
{
public:
/// Add point to R-tree
void addPoint(const VertInd i, const std::vector<V2d<T> >& points)
void addPoint(const VertInd i, const std::vector<V2d<TCoordType> >& points)
{
m_kdTree.insert(i, points);
}
/// Find nearest point using R-tree
VertInd
nearPoint(const V2d<T>& pos, const std::vector<V2d<T> >& points) const
VertInd nearPoint(
const V2d<TCoordType>& pos,
const std::vector<V2d<TCoordType> >& points) const
{
return m_kdTree.nearest(pos, points).second;
}

private:
KDTree::KDTree<T> m_kdTree;
KDTree::KDTree<
TCoordType,
NumVerticesInLeaf,
InitialStackDepth,
StackDepthIncrement>
m_kdTree;
};

} // namespace CDT
Expand Down