-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SpatialPartitioning] Add kd-tree sample index iterator and query
- Loading branch information
Amael Marquez
committed
Oct 31, 2023
1 parent
f8e54a5
commit 5e01cf4
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
Ponca/src/SpatialPartitioning/KdTree/Iterator/kdTreeSampleIndexIterator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace Ponca { | ||
|
||
template <typename Traits> | ||
class KdTreeSampleIndexQuery; | ||
|
||
template <typename Traits> | ||
class KdTreeSampleIndexIterator | ||
{ | ||
public: | ||
using IndexType = typename Traits::IndexType; | ||
|
||
void operator++() { ++m_index; } | ||
|
||
bool operator!=(const KdTreeSampleIndexIterator& other) const { | ||
return m_points != other.m_points || m_samples != other.m_samples || m_index != other.m_index; | ||
} | ||
|
||
IndexType operator*() const { return (*m_samples)[m_index]; } | ||
|
||
private: | ||
friend KdTreeSampleIndexQuery<Traits>; | ||
|
||
using PointContainer = typename Traits::PointContainer; | ||
using IndexContainer = typename Traits::IndexContainer; | ||
|
||
IndexType m_index; | ||
const PointContainer* m_points; | ||
const IndexContainer* m_samples; | ||
|
||
KdTreeSampleIndexIterator(IndexType index, const PointContainer& points, const IndexContainer& samples) | ||
: m_index(index), m_points(&points), m_samples(&samples) {} | ||
}; | ||
|
||
} // namespace Ponca |
44 changes: 44 additions & 0 deletions
44
Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeSampleIndexQuery.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "../Iterator/kdTreeSampleIndexIterator.h" | ||
|
||
namespace Ponca { | ||
|
||
template <typename Traits> | ||
class KdTreeBase; | ||
|
||
template <typename Traits> | ||
class KdTreeSampleIndexQuery | ||
{ | ||
public: | ||
using IndexType = typename Traits::IndexType; | ||
using Iterator = KdTreeSampleIndexIterator<Traits>; | ||
|
||
Iterator begin() { | ||
return Iterator(0, *m_points, *m_samples); | ||
} | ||
|
||
Iterator end() { | ||
return Iterator((IndexType)m_samples->size(), *m_points, *m_samples); | ||
} | ||
|
||
private: | ||
friend KdTreeBase<Traits>; | ||
|
||
using PointContainer = typename Traits::PointContainer; | ||
using IndexContainer = typename Traits::IndexContainer; | ||
|
||
const PointContainer* m_points; | ||
const IndexContainer* m_samples; | ||
|
||
KdTreeSampleIndexQuery(const PointContainer& points, const IndexContainer& samples) | ||
: m_points(&points), m_samples(&samples) {} | ||
}; | ||
|
||
} // namespace Ponca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters