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