A deal2lkit wrapper for the nanoflann library, used to compute the distance from a collection of points. More...
#include <parsed_kdtree_distance.h>
Classes | |
struct | PointCloudAdaptor |
Adaptor class used internally by nanoflann. More... | |
Public Types | |
typedef nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, PointCloudAdaptor >, PointCloudAdaptor, dim, unsigned int > | KDTree |
A typedef for the actual KDTree object. More... | |
Public Member Functions | |
ParsedKDTreeDistance (const std::string &name="", const unsigned int &max_leaf_size=10, const std::vector< Point< dim > > &pts=std::vector< Point< dim > >()) | |
Constructor: takes an optional name for the section. More... | |
virtual void | declare_parameters (ParameterHandler &prm) |
Calls the underlying function of ParsedFunction. More... | |
virtual double | value (const Point< dim > &p, const unsigned int component=0) const |
Compute the distance between the given point and the cloud of points in the currently stored adaptor. More... | |
void | set_points (const std::vector< Point< dim > > &pts) |
Store a reference to the passed points. More... | |
const Point< dim > & | operator[] (unsigned int i) const |
A const accessor to the underlying points. More... | |
unsigned int | size () const |
The size of the vector stored by this class. More... | |
unsigned int | get_points_within_ball (const Point< dim > &target, const double &radius, std::vector< std::pair< unsigned int, double > > &matches, bool sorted=false) const |
Fill a vector with the indices and the distance of the points that are at distance less than or equal to the given radius from the target point. More... | |
void | get_closest_points (const Point< dim > &target, std::vector< unsigned int > &indices, std::vector< double > &distances) const |
Fill two vectors with the indices and distances of the closest points to the given target point. More... | |
Public Member Functions inherited from ParameterAcceptor | |
ParameterAcceptor (const std::string section_name="") | |
The constructor adds derived classes to the list of acceptors. More... | |
virtual | ~ParameterAcceptor () |
The destructor sets to zero the pointer relative to this index, so that it is safe to destroy the mother class. More... | |
virtual void | parse_parameters (ParameterHandler &prm) |
Parse the parameter file. More... | |
virtual void | parse_parameters_call_back () |
Parse parameter call back. More... | |
std::string | get_section_name () const |
Return the section name of this class. More... | |
std::vector< std::string > | get_section_path () const |
Travers all registered classes, and figure out what subsections we need to enter. More... | |
template<class T > | |
void | add_parameter (ParameterHandler &prm, T *parameter, const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string()) |
Add a parameter the given parameter list. More... | |
template<class T > | |
void | add_parameter (T ¶meter, const std::string &entry, const std::string &documentation=std::string(), ParameterHandler &prm=ParameterAcceptor::prm) |
Add a parameter to the global parameter handler ParameterAcceptor::prm. More... | |
void | enter_my_subsection (ParameterHandler &prm) |
Make sure we enter the right subsection of the global parameter file. More... | |
void | leave_my_subsection (ParameterHandler &prm) |
This function undoes what the enter_my_subsection() function did. More... | |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const double &) |
double More... | |
template<> | |
std::string | to_string (const double &entry) |
template<> | |
double | to_type (const std::string ¶meter) |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const int &) |
int More... | |
template<> | |
std::string | to_string (const int &entry) |
template<> | |
int | to_type (const std::string ¶meter) |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const unsigned int &) |
unsigned int More... | |
template<> | |
std::string | to_string (const unsigned int &entry) |
template<> | |
unsigned int | to_type (const std::string ¶meter) |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const bool &) |
bool More... | |
template<> | |
std::string | to_string (const bool &entry) |
template<> | |
bool | to_type (const std::string ¶meter) |
Public Member Functions inherited from Subscriptor | |
Subscriptor () | |
Subscriptor (const Subscriptor &) | |
Subscriptor (Subscriptor &&) | |
virtual | ~Subscriptor () |
Subscriptor & | operator= (const Subscriptor &) |
Subscriptor & | operator= (Subscriptor &&) |
void | subscribe (const char *identifier=0) const |
void | unsubscribe (const char *identifier=0) const |
unsigned int | n_subscriptions () const |
void | list_subscribers () const |
void | serialize (Archive &ar, const unsigned int version) |
Public Member Functions inherited from Function< dim > | |
Function (const unsigned int n_components=1, const doubleinitial_time=0.0) | |
virtual | ~Function ()=0 |
Function & | operator= (const Function &f) |
virtual void | vector_value (const Point< dim > &p, Vector< double > &values) const |
virtual void | value_list (const std::vector< Point< dim > > &points, std::vector< double > &values, const unsigned int component=0) const |
virtual void | vector_value_list (const std::vector< Point< dim > > &points, std::vector< Vector< double > > &values) const |
virtual void | vector_values (const std::vector< Point< dim > > &points, std::vector< std::vector< double > > &values) const |
virtual Tensor< 1, dim, double > | gradient (const Point< dim > &p, const unsigned int component=0) const |
virtual void | vector_gradient (const Point< dim > &p, std::vector< Tensor< 1, dim, double > > &gradients) const |
virtual void | gradient_list (const std::vector< Point< dim > > &points, std::vector< Tensor< 1, dim, double > > &gradients, const unsigned int component=0) const |
virtual void | vector_gradients (const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, double > > > &gradients) const |
virtual void | vector_gradient_list (const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, double > > > &gradients) const |
virtual double | laplacian (const Point< dim > &p, const unsigned int component=0) const |
virtual void | vector_laplacian (const Point< dim > &p, Vector< double > &values) const |
virtual void | laplacian_list (const std::vector< Point< dim > > &points, std::vector< double > &values, const unsigned int component=0) const |
virtual void | vector_laplacian_list (const std::vector< Point< dim > > &points, std::vector< Vector< double > > &values) const |
virtual SymmetricTensor< 2, dim, double > | hessian (const Point< dim > &p, const unsigned int component=0) const |
virtual void | vector_hessian (const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, double > > &values) const |
virtual void | hessian_list (const std::vector< Point< dim > > &points, std::vector< SymmetricTensor< 2, dim, double > > &values, const unsigned int component=0) const |
virtual void | vector_hessian_list (const std::vector< Point< dim > > &points, std::vector< std::vector< SymmetricTensor< 2, dim, double > > > &values) const |
std::size_t | memory_consumption () const |
Public Member Functions inherited from FunctionTime< class > | |
FunctionTime (const Number initial_time=Number(0.0)) | |
virtual | ~FunctionTime () |
Number | get_time () const |
virtual void | set_time (const Number new_time) |
virtual void | advance_time (const Number delta_t) |
Private Attributes | |
unsigned int | max_leaf_size |
Max number of points per leaf. More... | |
shared_ptr< PointCloudAdaptor > | adaptor |
A point cloud adaptor, to be filled when set points is called. More... | |
shared_ptr< KDTree > | kdtree |
The actual kdtree. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from ParameterAcceptor | |
static void | initialize (const std::string filename="", const std::string outfilename="") |
Call declare_all_parameters(), read filename (if it is present as input parameter) and parse_all_parameters() on the static member prm. More... | |
static void | clear () |
Clear class list and global parameter file. More... | |
static void | parse_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm) |
Parse the given ParameterHandler. More... | |
static void | log_info () |
Print information about all stored classes. More... | |
static void | declare_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm) |
Initialize the ParameterHandler with all derived classes parameters.This function enters the subsection returned by get_section_name() for each derived class, and declares all parameters that were added using add_parameter(). More... | |
template<class T > | |
static std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const T &) |
Given a class T, construct its default pattern to be used when declaring parameters. More... | |
template<class T > | |
static T | to_type (const std::string &) |
Given a string, fill the value of the given parameter. More... | |
template<class T > | |
static std::string | to_string (const T &) |
Given a parameter, return a string containing the given parameter. More... | |
Static Public Member Functions inherited from Subscriptor | |
static::ExceptionBase & | ExcInUse (int arg1, char *arg2, std::string &arg3) |
static::ExceptionBase & | ExcNoSubscriber (char *arg1, char *arg2) |
Public Attributes inherited from Function< dim > | |
const unsigned int | n_components |
Static Public Attributes inherited from ParameterAcceptor | |
static ParameterHandler | prm |
Static parameter. More... | |
Static Public Attributes inherited from Function< dim > | |
static const unsigned int | dimension |
Protected Attributes inherited from ParameterAcceptor | |
const std::string | section_name |
The subsection name for this class. More... | |
A deal2lkit wrapper for the nanoflann library, used to compute the distance from a collection of points.
This function uses nanoflann to efficiently partition the space in a tree. The cost of each query is then roughly of order log(n), where n is the number of points stored in this class.
Additional methods are provided that give access to other functionalities of the nanoflann library, like searching the n nearest neighbors, or searching the points that fall within a raidius of a target point.
Definition at line 45 of file parsed_kdtree_distance.h.
typedef nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<double, PointCloudAdaptor> , PointCloudAdaptor, dim, unsigned int> ParsedKDTreeDistance< dim >::KDTree |
A typedef for the actual KDTree object.
Definition at line 155 of file parsed_kdtree_distance.h.
ParsedKDTreeDistance< dim >::ParsedKDTreeDistance | ( | const std::string & | name = "" , |
const unsigned int & | max_leaf_size = 10 , |
||
const std::vector< Point< dim > > & | pts = std::vector<Point<dim> >() |
||
) |
Constructor: takes an optional name for the section.
If the optional expression string is given, than it is used to set the expression as soon as the parameters are declared.
The max leaf parameter is used to decide how many points per leaf are used in the kdtree algorithm.
If the points are not passed to this constructor, then you have to pass them later to this object by calling the set_points() method.
Access to any of the methods without first passing a reference to a vector of points will result in an exception. Only a reference to the points is stored, so you should make sure that the life of the the vector you pass is longer than the life of this class, or you'll get undefinite behaviour.
If you update the vector of points in someway, remember to call again the set_points() method. The tree and the index are constructed only once, when you pass the points (either at construction time, or when you call set_points()). If you update your points, and do not call again set_points(), your results will likely be wrong.
Definition at line 9 of file parsed_kdtree_distance.cc.
|
virtual |
Calls the underlying function of ParsedFunction.
Reimplemented from ParameterAcceptor.
Definition at line 22 of file parsed_kdtree_distance.cc.
void ParsedKDTreeDistance< dim >::get_closest_points | ( | const Point< dim > & | target, |
std::vector< unsigned int > & | indices, | ||
std::vector< double > & | distances | ||
) | const |
Fill two vectors with the indices and distances of the closest points to the given target point.
The vectors are filled with indices and distances until there is space in them. You should resize them to the number of closest points you wish to get. An assertion is thrown if the vectors do not have the same size.
[in] | target | the target point |
[out] | indices | indices of the matching points |
[out] | distances | distances of the matching points |
Definition at line 79 of file parsed_kdtree_distance.cc.
unsigned int ParsedKDTreeDistance< dim >::get_points_within_ball | ( | const Point< dim > & | target, |
const double & | radius, | ||
std::vector< std::pair< unsigned int, double > > & | matches, | ||
bool | sorted = false |
||
) | const |
Fill a vector with the indices and the distance of the points that are at distance less than or equal to the given radius from the target point.
Consider preallocating the size of the return vector if you have a wild guess of how many should be there.
[in] | point | the target point |
[in] | radius | the radius of the ball |
[out] | mathes | indices and distances of the matching points |
[in] | sorted | sort the output results in ascending order with respect to distances |
Definition at line 63 of file parsed_kdtree_distance.cc.
|
inline |
A const accessor to the underlying points.
Definition at line 207 of file parsed_kdtree_distance.h.
void ParsedKDTreeDistance< dim >::set_points | ( | const std::vector< Point< dim > > & | pts | ) |
Store a reference to the passed points.
After you called this method, you can call the value() method to compute the minimum distance between an evaluation point and the collection of points you passed to this method, or the get_points_within_ball() and the get_closest_points() methods.
Notice that the constructor calls this method internally if you pass it a non empty vector of points.
Whenever your points change, you should call this method again, since this is the method responsible for building the index and storing the actual tree internally. If you change your points and don't call again this method, any function you call later will happily return wrong values without you noticing.
pts | a collection of points |
Definition at line 91 of file parsed_kdtree_distance.cc.
|
inline |
The size of the vector stored by this class.
Definition at line 217 of file parsed_kdtree_distance.h.
|
virtual |
Compute the distance between the given point and the cloud of points in the currently stored adaptor.
If the adaptor is empty, throw an exception. You should call the function set_points() to initialize a new adaptor, or call the constructor with a valid set of points. If your points change, call again the set_points() method.
p | the point where we want to evaluate the distance |
component | function component (throws an exception if it is different from zero. This is required by the dealii interface) |
Reimplemented from Function< dim >.
Definition at line 37 of file parsed_kdtree_distance.cc.
|
private |
A point cloud adaptor, to be filled when set points is called.
Definition at line 268 of file parsed_kdtree_distance.h.
|
private |
The actual kdtree.
Definition at line 274 of file parsed_kdtree_distance.h.
|
private |
Max number of points per leaf.
Definition at line 262 of file parsed_kdtree_distance.h.