https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Typedefs | Functions
PointReduction Namespace Reference

Typedefs

typedef std::pair< libMesh::Real, libMesh::RealFunctionNode
 
typedef std::vector< FunctionNodeFunctionNodeList
 

Functions

libMesh::Real perpendicularDistance (const FunctionNode &point, const FunctionNode &begin, const FunctionNode &end)
 compute the perpendicular distance of a point P from a line defined by begin and end points.
 
FunctionNodeList douglasPeucker (const FunctionNodeList &, libMesh::Real epsilon)
 Generate a pruned function node list using the Ramer-Douglas-Peucker algorithm.
 
Real sqr (Real a)
 
Real square (Real a)
 
void douglasPeuckerRecurse (const FunctionNodeList &list, const Real epsilon, std::vector< bool > &keep, std::size_t begin, std::size_t end)
 
FunctionNodeList douglasPeucker (const FunctionNodeList &list, const Real epsilon)
 

Typedef Documentation

◆ FunctionNode

Definition at line 18 of file PointReduction.h.

◆ FunctionNodeList

Definition at line 19 of file PointReduction.h.

Function Documentation

◆ douglasPeucker() [1/2]

FunctionNodeList PointReduction::douglasPeucker ( const FunctionNodeList ,
libMesh::Real  epsilon 
)

Generate a pruned function node list using the Ramer-Douglas-Peucker algorithm.

Parameters
listAn ordered (by x) list of (x,y) points defining a pointwise defined function.
epsilonThe Ramer-Douglas-Peucker tolerance parameter for coarsening.

Referenced by CoarsenedPiecewiseLinear::buildCoarsenedGrid().

◆ douglasPeucker() [2/2]

FunctionNodeList PointReduction::douglasPeucker ( const FunctionNodeList list,
const Real  epsilon 
)

filter result

Definition at line 90 of file PointReduction.C.

91{
92 // set up keep list for function nodes
93 std::vector<bool> keep(list.size(), true);
94 douglasPeuckerRecurse(list, epsilon, keep, 0, list.size() - 1);
95
96 FunctionNodeList result;
97 result.reserve(std::count_if(keep.begin(), keep.end(), [](bool k) { return k; }));
98
100 for (std::size_t i = 0; i < list.size(); ++i)
101 if (keep[i])
102 result.push_back(list[i]);
103
104 return result;
105}
std::vector< FunctionNode > FunctionNodeList
void douglasPeuckerRecurse(const FunctionNodeList &list, const Real epsilon, std::vector< bool > &keep, std::size_t begin, std::size_t end)

◆ douglasPeuckerRecurse()

void PointReduction::douglasPeuckerRecurse ( const FunctionNodeList list,
const Real  epsilon,
std::vector< bool > &  keep,
std::size_t  begin,
std::size_t  end 
)

Definition at line 53 of file PointReduction.C.

58{
59 // Find the point with the maximum distance from the line defined by begin and end
60 Real dmax = 0.0;
61 std::size_t index = 0;
62
63 for (std::size_t i = begin; i <= end; ++i)
64 if (keep[i])
65 {
66 const Real d = perpendicularDistance(list[i], list[begin], list[end]);
67 if (d > dmax)
68 {
69 index = i;
70 dmax = d;
71 }
72 }
73
74 // If max distance is greater than epsilon, recursively simplify
75 if (dmax > epsilon)
76 {
77 // Recursive call
78 douglasPeuckerRecurse(list, epsilon, keep, begin, index);
79 douglasPeuckerRecurse(list, epsilon, keep, index, end);
80 }
81 else
82 {
83 // remove all points between begin and end
84 for (std::size_t i = begin + 1; i < end; ++i)
85 keep[i] = false;
86 }
87}
libMesh::Real perpendicularDistance(const FunctionNode &point, const FunctionNode &begin, const FunctionNode &end)
compute the perpendicular distance of a point P from a line defined by begin and end points.

Referenced by douglasPeucker(), and douglasPeuckerRecurse().

◆ perpendicularDistance()

Real PointReduction::perpendicularDistance ( const FunctionNode point,
const FunctionNode begin,
const FunctionNode end 
)

compute the perpendicular distance of a point P from a line defined by begin and end points.

Parameters
pointThe (x,y) point P
beginThe first (x,y) point defining the line to compute the distance to
endThe second (x,y) point defining the line to compute the distance to

Definition at line 34 of file PointReduction.C.

37{
38 const Real x0 = node.first;
39 const Real y0 = node.second;
40 const Real x1 = begin.first;
41 const Real y1 = begin.second;
42 const Real x2 = end.first;
43 const Real y2 = end.second;
44
45 const Real denom = std::sqrt(square(y2 - y1) + square(x2 - x1));
46 mooseAssert(MooseUtils::absoluteFuzzyGreaterThan(denom, 0.0),
47 "Line begin and end points must not be the same");
48
49 return std::abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) / denom;
50}
Real square(Real a)

Referenced by douglasPeuckerRecurse().

◆ sqr()

Real PointReduction::sqr ( Real  a)

Definition at line 21 of file PointReduction.C.

22{
23 mooseDeprecated("use PointReduction::square() instead");
24 return a * a;
25}
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:363

◆ square()

Real PointReduction::square ( Real  a)

Definition at line 28 of file PointReduction.C.

29{
30 return a * a;
31}

Referenced by perpendicularDistance().