#include <BasicRelax_fwd.hpp>
Redistributes nodes towards more uniform distribution by minimizing potential between nodes.
The engine first finds num_neighbours
closest neighbours. Then it translates each point according to the repelling "force" induced by its neighbours, where it also takes into account target potential. The force is determined by summing the gradients of potentials in surrounding nodes, where amplitude is determined based on distance to the closest neighbour and supplied target density function. The algorithm uses also a primitive Simulated Annealing, i.e. the relax movement magnitude is multiplied with an annealing factor that is linearly dropping from initial_heat to final_heat.
The Engine supports two call types: with supplied distribution function relax(func), where it tries to satisfy the user supplied nodal density function. This can be achieved only when there is the total number of domain nodes the same as integral of density function over the domain. If there is too much nodes a volatile relax might occur. If there is not enough nodes the relax might become lazy. The best use of this mode is in combination with fillDistribution Engines, check test for examples.
Without distribution, where nodes always move towards less populated area regardless anything. The relax magnitude is simply determined from annealing factor and distance to the closest node. A simple and stable approach, however, note that this relax always converges towards uniformly distributed nodes.
Usage example:
Definition at line 43 of file BasicRelax_fwd.hpp.
Public Member Functions | |
BasicRelax & | onlyNodes (Range< int > nodes) |
Move only given nodes. More... | |
BasicRelax & | initialHeat (double in) |
Sets initial heat. More... | |
BasicRelax & | finalHeat (double in) |
Sets final heat. More... | |
BasicRelax & | numNeighbours (int neighbours) |
Sets num neighbours. More... | |
BasicRelax & | potentialOrder (int order) |
Sets order of repulsing potential. More... | |
BasicRelax & | iterations (int iterations) |
Sets number of iterations. More... | |
BasicRelax & | rebuildTreeAfter (int iterations) |
Sets rebuild tree frequency. More... | |
BasicRelax & | projectionType (ProjectionType in) |
Determines how to handle nodes that escape during relaxation. More... | |
BasicRelax & | boundaryProjectionThreshold (double in) |
Sets threshold for adding nodes on boundary, i.e. if node \(d_1\) and \(d_2\) are distances to closest boundary nodes, do not add node on boundary if \(d_1/d_2 < boundary_projection_threshold \). More... | |
template<class domain_t > | |
void | operator() (domain_t &domain) const |
Runs the relax on the selected domain with constant distribution equals to domain characteristic distance. More... | |
template<class domain_t > | |
void | operator() (domain_t &domain, double r) const |
Runs the relax on the selected domain with constant density. More... | |
template<class domain_t , class radius_func_type > | |
void | operator() (domain_t &domain, const radius_func_type &r_func) const |
Runs the procedure of a given domain. More... | |
Public Types | |
enum | ProjectionType { DO_NOT_PROJECT, PROJECT_IN_DIRECTION, PROJECT_BETWEEN_CLOSEST } |
Indicating type of projection used when a relax node goes out of the domain. More... | |
Private Attributes | |
int | num_neighbours = 1 |
Number of nodes to consider when calculating the potential. More... | |
int | num_iterations = 50 |
Number of iterations performed. More... | |
double | initial_heat = 1 |
Initial heat, usually between 0 and 5. More... | |
double | final_heat = 0 |
Heat at the end of the relax, usually around 0. More... | |
int | potential_order = 2 |
Order of repulsing potential. More... | |
int | rebuild_tree_after = 1 |
How often engine rebuild search tree, 1 is perfect but slow. More... | |
Range< int > | nodes_ |
List of nodes to process. More... | |
ProjectionType | projection_type = DO_NOT_PROJECT |
On boundary projection method. More... | |
double | boundary_projection_threshold = 0.75 |
Threshold for projecting nodes on boundary. More... | |
Indicating type of projection used when a relax node goes out of the domain.
Definition at line 46 of file BasicRelax_fwd.hpp.
BasicRelax & mm::BasicRelax::boundaryProjectionThreshold | ( | double | in | ) |
Sets threshold for adding nodes on boundary, i.e. if node \(d_1\) and \(d_2\) are distances to closest boundary nodes, do not add node on boundary if \(d_1/d_2 < boundary_projection_threshold \).
If threshold is 0 all nodes are added, if it is greater than 1 no nodes are added.
Definition at line 26 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::finalHeat | ( | double | in | ) |
Sets final heat.
Definition at line 18 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::initialHeat | ( | double | in | ) |
Sets initial heat.
in | Initial heat, usually between 0 and 5, higher heat means more volatile movement. High initial heat may cause divergence and erratic behaviour. Setting too small initial heat might results in lazy relaxation. |
Definition at line 14 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::iterations | ( | int | iterations | ) |
Sets number of iterations.
Definition at line 37 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::numNeighbours | ( | int | neighbours | ) |
Sets num neighbours.
Definition at line 33 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::onlyNodes | ( | Range< int > | nodes | ) |
Move only given nodes.
Definition at line 10 of file BasicRelax.cpp.
|
inline |
Runs the relax on the selected domain with constant distribution equals to domain characteristic distance.
domain | domain to process |
Definition at line 127 of file BasicRelax_fwd.hpp.
void mm::BasicRelax::operator() | ( | domain_t & | domain, |
const radius_func_type & | r_func | ||
) | const |
Runs the procedure of a given domain.
Definition at line 19 of file BasicRelax.hpp.
|
inline |
Runs the relax on the selected domain with constant density.
domain | domain to process |
r | constant density |
Definition at line 138 of file BasicRelax_fwd.hpp.
BasicRelax & mm::BasicRelax::potentialOrder | ( | int | order | ) |
Sets order of repulsing potential.
Definition at line 41 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::projectionType | ( | ProjectionType | in | ) |
Determines how to handle nodes that escape during relaxation.
Definition at line 22 of file BasicRelax.cpp.
BasicRelax & mm::BasicRelax::rebuildTreeAfter | ( | int | iterations | ) |
Sets rebuild tree frequency.
Ir rebuild's tree every in
iterations. in = 1
is perfect but slow. Using higher values results in better performance at the cost of accuracy.
Definition at line 45 of file BasicRelax.cpp.
|
private |
Threshold for projecting nodes on boundary.
Definition at line 75 of file BasicRelax_fwd.hpp.
|
private |
Heat at the end of the relax, usually around 0.
Definition at line 70 of file BasicRelax_fwd.hpp.
|
private |
Initial heat, usually between 0 and 5.
Definition at line 69 of file BasicRelax_fwd.hpp.
|
private |
List of nodes to process.
Definition at line 73 of file BasicRelax_fwd.hpp.
|
private |
Number of iterations performed.
Definition at line 68 of file BasicRelax_fwd.hpp.
|
private |
Number of nodes to consider when calculating the potential.
Definition at line 67 of file BasicRelax_fwd.hpp.
|
private |
Order of repulsing potential.
Definition at line 71 of file BasicRelax_fwd.hpp.
|
private |
On boundary projection method.
Definition at line 74 of file BasicRelax_fwd.hpp.
|
private |
How often engine rebuild search tree, 1 is perfect but slow.
Definition at line 72 of file BasicRelax_fwd.hpp.