41 #ifndef DTK_STATICSEARCHTREE_IMPL_HPP 42 #define DTK_STATICSEARCHTREE_IMPL_HPP 48 #include <Teuchos_as.hpp> 58 PointCloud<1>::kdtree_distance(
const double *p1,
const std::size_t idx_p2,
59 std::size_t DTK_REMEMBER( size ) )
const 61 DTK_REQUIRE( 1 == size );
62 DTK_REQUIRE( idx_p2 < Teuchos::as<std::size_t>( d_points.size() ) );
63 const double d0 = p1[0] - d_points[idx_p2];
73 PointCloud<2>::kdtree_distance(
const double *p1,
const std::size_t idx_p2,
74 std::size_t DTK_REMEMBER( size ) )
const 76 DTK_REQUIRE( 2 == size );
77 DTK_REQUIRE( 2 * idx_p2 + 1 < Teuchos::as<std::size_t>( d_points.size() ) );
78 const double d0 = p1[0] - d_points[2 * idx_p2];
79 const double d1 = p1[1] - d_points[2 * idx_p2 + 1];
80 return d0 * d0 + d1 * d1;
89 PointCloud<3>::kdtree_distance(
const double *p1,
const std::size_t idx_p2,
90 std::size_t DTK_REMEMBER( size ) )
const 92 DTK_REQUIRE( 3 == size );
93 DTK_REQUIRE( 3 * idx_p2 + 2 < Teuchos::as<std::size_t>( d_points.size() ) );
94 const double d0 = p1[0] - d_points[3 * idx_p2];
95 const double d1 = p1[1] - d_points[3 * idx_p2 + 1];
96 const double d2 = p1[2] - d_points[3 * idx_p2 + 2];
97 return d0 * d0 + d1 * d1 + d2 * d2;
105 inline double PointCloud<1>::kdtree_get_pt(
const std::size_t idx,
106 int DTK_REMEMBER( dim ) )
const 108 DTK_REQUIRE( dim < 1 );
109 DTK_REQUIRE( idx < Teuchos::as<std::size_t>( d_points.size() ) );
110 return d_points[idx];
118 inline double PointCloud<2>::kdtree_get_pt(
const std::size_t idx,
121 DTK_REQUIRE( dim < 2 );
122 DTK_REQUIRE( 2 * idx + dim < Teuchos::as<std::size_t>( d_points.size() ) );
123 return d_points[2 * idx + dim];
131 inline double PointCloud<3>::kdtree_get_pt(
const std::size_t idx,
134 DTK_REQUIRE( dim < 3 );
135 DTK_REQUIRE( 3 * idx + dim < Teuchos::as<std::size_t>( d_points.size() ) );
136 return d_points[3 * idx + dim];
147 const Teuchos::ArrayView<const double> &points,
148 const unsigned max_leaf_size )
150 DTK_CHECK( 0 == points.size() % DIM );
152 d_cloud = PointCloud<DIM>( points );
153 d_tree = Teuchos::rcp(
new TreeType(
156 d_tree->buildIndex();
164 Teuchos::Array<unsigned>
166 const unsigned num_neighbors )
const 168 DTK_REQUIRE( DIM == point.size() );
169 Teuchos::Array<unsigned> neighbors( num_neighbors );
170 Teuchos::Array<double> neighbor_dists( num_neighbors );
171 d_tree->knnSearch( point.getRawPtr(), num_neighbors, neighbors.getRawPtr(),
172 neighbor_dists.getRawPtr() );
181 Teuchos::Array<unsigned>
183 const double radius )
const 185 DTK_REQUIRE( DIM == point.size() );
186 Teuchos::Array<std::pair<unsigned, double>> neighbor_pairs;
188 double l2_radius = radius * radius;
189 d_tree->radiusSearch( point.getRawPtr(), l2_radius, neighbor_pairs,
192 Teuchos::Array<std::pair<unsigned, double>>::const_iterator pair_it;
193 Teuchos::Array<unsigned> neighbors( neighbor_pairs.size() );
194 Teuchos::Array<unsigned>::iterator id_it;
195 for ( id_it = neighbors.begin(), pair_it = neighbor_pairs.begin();
196 id_it != neighbors.end(); ++id_it, ++pair_it )
198 *id_it = pair_it->first;
210 #endif // end DTK_STATICSEARCHTREE_IMPL_HPP Teuchos::Array< unsigned > nnSearch(const Teuchos::ArrayView< const double > &point, const unsigned num_neighbors) const
Perform an n-nearest neighbor search.
Teuchos::Array< unsigned > radiusSearch(const Teuchos::ArrayView< const double > &point, const double radius) const
Perform a nearest neighbor search within a specified radius.
Assertions and Design-by-Contract for error handling.
NanoflannTree(const Teuchos::ArrayView< const double > &points, const unsigned max_leaf_size)
Constructor.