-
Notifications
You must be signed in to change notification settings - Fork 5
/
contour.h
139 lines (133 loc) · 4.53 KB
/
contour.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/******************************************************/
/* */
/* contour.h - generates contours */
/* */
/******************************************************/
/* Copyright 2020,2021 Pierre Abbat.
* This file is part of PerfectTIN.
*
* PerfectTIN is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* PerfectTIN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and Lesser General Public License along with PerfectTIN. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef CONTOUR_H
#define CONTOUR_H
#include <vector>
#include "polyline.h"
#include "ps.h"
#define CCHALONG 0.30754991027012474516361707317
// This is sqrt(4/27) of the way from 0.5 to 0. See clampcubic in Bezitopo.
#define M_SQRT_10 3.16227766016837933199889354
class pointlist;
class ContourInterval
{
/* interval is in meters. When interval is in the display unit, they may be:
* int fine coarse
* 1 5 4
* 2 5 5
* 5 4 5
* 1 1 5
* 2 1 5
* 5 1 4
* with int multiplied by any power of 10. The coarse interval tells which
* contours are labeled with elevations, the medium interval tells which
* contours are completely drawn, and the fine interval, if different from
* the medium, tells which contours are drawn only on nearly flat ground.
*/
public:
ContourInterval();
ContourInterval(double unit,int icode,bool fine);
double fineInterval() const
{
return interval;
};
double mediumInterval() const
{
return interval*fineRatio;
};
double coarseInterval() const
{
return interval*fineRatio*coarseRatio;
};
double tolerance() const
{
return interval*fineRatio*relativeTolerance;
};
double getRelativeTolerance() const
{
return relativeTolerance;
};
void setRelativeTolerance(double tol)
{
relativeTolerance=tol;
}
void setInterval(double unit,int icode,bool fine);
void setIntervalRatios(double i,int f,int c);
std::string valueString(double unit,bool precise=false);
std::string valueToleranceString() const;
int contourType(double elev);
friend bool operator<(const ContourInterval &l,const ContourInterval &r);
friend bool operator==(const ContourInterval &l,const ContourInterval &r);
friend bool operator!=(const ContourInterval &l,const ContourInterval &r);
void writeXml(std::ostream &ofile);
private:
double interval,relativeTolerance;
int fineRatio,coarseRatio;
};
struct ContourLayer
/* These correspond to layers when exporting as DXF. Each ContourInterval
* has a set of 4 or 5 or 2 layers. E.g. if they are 1 m 1/2 contours, either
* 1 m 1/2 200: 0,5,10,15...
* 1 m 1/2 104: 1,6,11,16...
* 1 m 1/2 108: 2,7,12,17...
* 1 m 1/2 10c: 3,8,13,18...
* 1 m 1/2 110: 4,9,14,19...
* or
* 1 m 1/2 200: 0,5,10,15...
* 1 m 1/2 100: 1,2,3,4,6...
*/
{
ContourInterval ci;
int tp;
friend bool operator<(const ContourLayer &l,const ContourLayer &r);
friend bool operator==(const ContourLayer &l,const ContourLayer &r);
friend bool operator!=(const ContourLayer &l,const ContourLayer &r);
};
class DirtyTracker
{
public:
void init(int n);
bool isDirty(int n);
void markDirty(int n,int spread);
void markClean(int n);
void erase(int n);
void insert(int n);
private:
std::vector<char> dirt;
};
float splitpoint(double leftclamp,double rightclamp,double tolerance);
std::vector<edge *> contstarts(pointlist &pts,double elev);
polyline trace(edge *edgep,double elev);
polyline intrace(triangle *tri,double elev);
double bendiness(xy a,xy b,xy c,double tolerance);
void rough1contour(pointlist &pl,double elev,int thread);
void roughcontours(pointlist &pl,double conterval);
void checkContour(pointlist &pl,polyspiral &contour,double tolerance);
void prune1contour(pointlist &pl,double tolerance,int i,int thread);
void prunecontours(pointlist &pl,double tolerance);
void smooth1contour(pointlist &pl,double tolerance,int i,int thread);
void smoothcontours(pointlist &pl,double tolerance);
int makeContourIndex();
spiralarc nthPiece(int n);
#endif