deal2lkit: A ToolKit library for Deal.II
ParsedKDTreeDistance< dim > Class Template Reference

A deal2lkit wrapper for the nanoflann library, used to compute the distance from a collection of points. More...

#include <parsed_kdtree_distance.h>

Inheritance diagram for ParsedKDTreeDistance< dim >:
ParameterAcceptor Function< dim > Subscriptor FunctionTime< class > Subscriptor

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 &parameter, 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::PatternBaseto_pattern (const double &)
 double More...
 
template<>
std::string to_string (const double &entry)
 
template<>
double to_type (const std::string &parameter)
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const int &)
 int More...
 
template<>
std::string to_string (const int &entry)
 
template<>
int to_type (const std::string &parameter)
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const unsigned int &)
 unsigned int More...
 
template<>
std::string to_string (const unsigned int &entry)
 
template<>
unsigned int to_type (const std::string &parameter)
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const bool &)
 bool More...
 
template<>
std::string to_string (const bool &entry)
 
template<>
bool to_type (const std::string &parameter)
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&)
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (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
 
Functionoperator= (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< PointCloudAdaptoradaptor
 A point cloud adaptor, to be filled when set points is called. More...
 
shared_ptr< KDTreekdtree
 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::PatternBaseto_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...
 

Detailed Description

template<int dim>
class ParsedKDTreeDistance< dim >

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.

Member Typedef Documentation

§ KDTree

template<int dim>
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.

Constructor & Destructor Documentation

§ ParsedKDTreeDistance()

template<int dim>
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.

Member Function Documentation

§ declare_parameters()

template<int dim>
void ParsedKDTreeDistance< dim >::declare_parameters ( ParameterHandler prm)
virtual

Calls the underlying function of ParsedFunction.

Reimplemented from ParameterAcceptor.

Definition at line 22 of file parsed_kdtree_distance.cc.

§ get_closest_points()

template<int dim>
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.

Parameters
[in]targetthe target point
[out]indicesindices of the matching points
[out]distancesdistances of the matching points

Definition at line 79 of file parsed_kdtree_distance.cc.

§ get_points_within_ball()

template<int dim>
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.

Parameters
[in]pointthe target point
[in]radiusthe radius of the ball
[out]mathesindices and distances of the matching points
[in]sortedsort the output results in ascending order with respect to distances
Returns
number of points that are within the ball

Definition at line 63 of file parsed_kdtree_distance.cc.

§ operator[]()

template<int dim>
const Point<dim>& ParsedKDTreeDistance< dim >::operator[] ( unsigned int  i) const
inline

A const accessor to the underlying points.

Definition at line 207 of file parsed_kdtree_distance.h.

§ set_points()

template<int dim>
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.

Parameters
ptsa collection of points

Definition at line 91 of file parsed_kdtree_distance.cc.

§ size()

template<int dim>
unsigned int ParsedKDTreeDistance< dim >::size ( ) const
inline

The size of the vector stored by this class.

Definition at line 217 of file parsed_kdtree_distance.h.

§ value()

template<int dim>
double ParsedKDTreeDistance< dim >::value ( const Point< dim > &  p,
const unsigned int  component = 0 
) const
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.

Parameters
pthe point where we want to evaluate the distance
componentfunction component (throws an exception if it is different from zero. This is required by the dealii interface)
Returns
the minimum distance from the collection of points set with the constructor or with the method set_points()

Reimplemented from Function< dim >.

Definition at line 37 of file parsed_kdtree_distance.cc.

Member Data Documentation

§ adaptor

template<int dim>
shared_ptr<PointCloudAdaptor> ParsedKDTreeDistance< dim >::adaptor
private

A point cloud adaptor, to be filled when set points is called.

Definition at line 268 of file parsed_kdtree_distance.h.

§ kdtree

template<int dim>
shared_ptr<KDTree> ParsedKDTreeDistance< dim >::kdtree
private

The actual kdtree.

Definition at line 274 of file parsed_kdtree_distance.h.

§ max_leaf_size

template<int dim>
unsigned int ParsedKDTreeDistance< dim >::max_leaf_size
private

Max number of points per leaf.

Definition at line 262 of file parsed_kdtree_distance.h.


The documentation for this class was generated from the following files: