GeometricAlgorithms.hpp
1 #pragma once
2 
3 #include "DM/config.hpp"
4 #include "DM/AutoLink.hpp" //enable autolink
5 #include "DM/IPoint.hpp"
6 #include "DM/IPolyline.hpp"
7 
8 DM_NAMESPACE_BEGIN
9 
10 
11 /// \brief interface for analysing distances between polyline objects (see GeometricAlgorithms::analyseDistance)
12 class DM_API IAnalyseDistance
13 {
14 protected:
15  virtual ~IAnalyseDistance() {}
16 
17 public:
18  /// \brief this function is called if non max. distance threshold is set or the distance is below the given threshold.
19  /**
20  Note: if lineIdx1 == lineIdx2 then the closest point is a vertex and not a point on a segment
21 
22  \param[in] distance shortest 3d/2d distance between basePt (=base[idx]) and polyline 'other'
23  \param[in] idx index of the current vertex (of the base polyline)
24  \param[in] basePt current vertex (of the base polyline)
25  \param[in] lineIdx1 source point index of closest segment of polyline 'other'
26  \param[in] lineIdx2 target point index of closest segment of polyline 'other'
27  \param[in] minDistPt point on polyline 'other' with the shortest distance to basePt
28  */
29  virtual void closest(double distance, unsigned idx, const IPoint &basePt, unsigned lineIdx1, unsigned lineIdx2, const IPoint &minDistPt) = 0;
30 
31  /// \brief this function is called if the distance between the current base vertex and the 'other' polyline exceeds the given distance threshold
32  /// \param[in] idx index of the current vertex (of the base polyline)
33  virtual void exceeds(unsigned idx) = 0;
34 };
35 
36 
37 
38 
39 /// \brief provides a set of geometric algorithms (Douglas-Peucker algorithm, densification of lines)
40 namespace GeometricAlgorithms
41 {
42  /// \brief Use the Douglas-Peucker algorithm to create a polyline with a subset of vertices of the provided line object.
43  /** Each polyline part is treated as a separate object
44 
45  \param[in] line polyline that should be thinned out
46  \param[in] maxOrthoDist Discarded vertices feature an orthogonal distance to the returned polyline <= d_maxOrthoDist
47  \return resulting object
48  */
49  DM_API DM::PolylineHandle thinOut(const DM::PolylineHandle &line, double maxOrthoDist);
50 
51 
52  /// \brief densify a polyline by inserting new points along the line segments\n
53  /** insert as few points as possible to reach the criterion:\n
54  (distances between neighbours) <= d_maxSpacing\n
55  distribute the new points equally along each line segment\n
56  preserve original points together with their additional infos\n
57 
58  \param[in] line polyline that should be densified
59  \param[in] maxSpacing maximum spacing between neighboring vertices
60  \return resulting object
61  */
62  DM_API DM::PolylineHandle densify(const DM::PolylineHandle &line, double maxSpacing );
63 
64 
65  /// test if a polyline is self intersecting
66  DM_API bool isSelfIntersecting(const DM::PolylineHandle &line);
67 
68  /// \brief For analysing 2d/3d distances between vertices of the base polyline to the other provided polyline (optional a max distance threshold is considered)
69  /** The function computes the shortest 2d/3d distances of all vertices of the base polyline to the 'other' polyline. With the results of each
70  base vertex distance computation the corresponding function of the provided callback object is called. If an maximum distance threshold is provided (maxDist>0),
71  the algorithms only considers distances up to the given threshold (see IAnalyseDistance). The implemented algorithm uses the maxDist threshold during spatial
72  search and therfore, is more efficient than only handling the distance threshold within the callback oject.
73 
74  \param[in] base the vertex of the base polyline is used for distance analysis
75  \param[in] other polyline to which the distances are computed
76  \param[in] callback callback object for analysing the computed distance results
77  \param[in] maxDist optional maximum distance threshold (-1: no distance threshold is applied)
78  \param[in] d3 flag if 3d or 2d computation (true: 3d / false: 2d)
79  */
80  DM_API void analyseDistance(const PolylineHandle &base, const PolylineHandle &other, IAnalyseDistance &callback, double maxDist = -1, bool d3 = true);
81 }
82 
83 DM_NAMESPACE_END
interface for analysing distances between polyline objects (see GeometricAlgorithms::analyseDistance)
Definition: GeometricAlgorithms.hpp:12
DM_API bool isSelfIntersecting(const DM::PolylineHandle &line)
test if a polyline is self intersecting
DM_API DM::PolylineHandle densify(const DM::PolylineHandle &line, double maxSpacing)
densify a polyline by inserting new points along the line segments
DM_API void analyseDistance(const PolylineHandle &base, const PolylineHandle &other, IAnalyseDistance &callback, double maxDist=-1, bool d3=true)
For analysing 2d/3d distances between vertices of the base polyline to the other provided polyline (o...
Smart pointer class using reference counting with support for DM objects (see ObjectBase)
Definition: Handle.hpp:75
3d point object
Definition: IPoint.hpp:14
DM_API DM::PolylineHandle thinOut(const DM::PolylineHandle &line, double maxOrthoDist)
Use the Douglas-Peucker algorithm to create a polyline with a subset of vertices of the provided line...