Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/stlgeom/stltool.hpp
3206 views
1
#ifndef FILE_STLTOOL
2
#define FILE_STLTOOL
3
4
5
//#include "gprim/gprim.hh"
6
7
/**************************************************************************/
8
/* File: stlgeom.hh */
9
/* Author: Joachim Schoeberl */
10
/* Author2: Johannes Gerstmayr */
11
/* Date: 20. Nov. 99 */
12
/**************************************************************************/
13
14
15
16
// use one normal vector for whole chart
17
extern int usechartnormal;
18
extern int chartdebug;
19
20
extern int geomsearchtreeon;
21
extern int AddPointIfNotExists(ARRAY<Point3d>& ap, const Point3d& p, double eps = 1e-8);
22
//get distance from line lp1-lp2 to point p
23
extern double GetDistFromLine(const Point<3>& lp1, const Point<3>& lp2, Point<3>& p);
24
extern double GetDistFromInfiniteLine(const Point<3>& lp1, const Point<3>& lp2, const Point<3>& p);
25
26
27
extern void FIOReadInt(istream& ios, int& i);
28
extern void FIOWriteInt(ostream& ios, const int& i);
29
extern void FIOReadDouble(istream& ios, double& i);
30
extern void FIOWriteDouble(ostream& ios, const double& i);
31
extern void FIOReadFloat(istream& ios, float& i);
32
extern void FIOWriteFloat(ostream& ios, const float& i);
33
extern void FIOReadString(istream& ios, char* str, int len);
34
extern void FIOReadStringE(istream& ios, char* str, int len);
35
extern void FIOWriteString(ostream& ios, char* str, int len);
36
37
38
typedef ARRAY <int> * ARRAYINTPTR;
39
40
class STLGeometry;
41
42
class STLChart
43
{
44
private:
45
STLGeometry * geometry;
46
ARRAY<int>* charttrigs; // trigs which only belong to this chart
47
ARRAY<int>* outertrigs; // trigs which belong to other charts
48
Box3dTree * searchtree; // ADT containing outer trigs
49
50
ARRAY<twoint>* olimit; //outer limit of outer chart
51
ARRAY<twoint>* ilimit; //outer limit of inner chart
52
53
54
public:
55
56
STLChart(STLGeometry * ageometry);
57
void AddChartTrig(int i);
58
void AddOuterTrig(int i);
59
60
int IsInWholeChart(int nr) const;
61
62
int GetChartTrig(int i) const {return charttrigs->Get(i);}
63
int GetOuterTrig(int i) const {return outertrigs->Get(i);}
64
//get all trigs:
65
int GetTrig(int i) const
66
{
67
if (i <= charttrigs->Size()) {return charttrigs->Get(i);}
68
else {return outertrigs->Get(i-charttrigs->Size());}
69
}
70
71
int GetNChartT() const {return charttrigs->Size();}
72
int GetNOuterT() const {return outertrigs->Size();}
73
int GetNT() const {return charttrigs->Size()+outertrigs->Size(); }
74
75
void GetTrianglesInBox (const Point3d & pmin,
76
const Point3d & pmax,
77
ARRAY<int> & trias) const;
78
void AddOLimit(twoint l) {olimit->Append(l);}
79
void AddILimit(twoint l) {ilimit->Append(l);}
80
81
void ClearOLimit() {olimit->SetSize(0);}
82
void ClearILimit() {ilimit->SetSize(0);}
83
84
int GetNOLimit() const {return olimit->Size();}
85
int GetNILimit() const {return ilimit->Size();}
86
87
twoint GetOLimit(int i) const {return olimit->Get(i);}
88
twoint GetILimit(int i) const {return ilimit->Get(i);}
89
90
//move triangles trigs (local chart-trig numbers) to outer chart
91
void MoveToOuterChart(const ARRAY<int>& trigs);
92
void DelChartTrigs(const ARRAY<int>& trigs);
93
94
95
// define local coordinate system, JS:
96
private:
97
Vec<3> normal;
98
Point<3> pref;
99
Vec<3> t1, t2;
100
public:
101
void SetNormal (const Point<3> & apref, const Vec<3> & anormal);
102
const Vec<3> & GetNormal () const { return normal; }
103
Point<2> Project2d (const Point<3> & p3d) const;
104
};
105
106
class STLBoundarySeg
107
{
108
Point<3> p1, p2, center;
109
Point<2> p2d1, p2d2;
110
Box<2> boundingbox;
111
// Point<2> p2dmin, p2dmax;
112
113
double rad;
114
int i1, i2;
115
int smoothedge;
116
public:
117
STLBoundarySeg () { ; }
118
STLBoundarySeg (int ai1, int ai2, const ARRAY<Point<3> > & points,
119
const STLChart * achart);
120
121
int operator== (const STLBoundarySeg & s2) const
122
{ return i1 == s2.i1 && i2 == s2.i2; }
123
void Swap ();
124
int I1() const { return i1; }
125
int I2() const { return i2; }
126
const Point<3> & P1() const { return p1; }
127
const Point<3> & P2() const { return p2; }
128
const Point<2> & P2D1() const { return p2d1; }
129
const Point<2> & P2D2() const { return p2d2; }
130
const Point<2> & P2DMin() const { return boundingbox.PMin(); }
131
const Point<2> & P2DMax() const { return boundingbox.PMax(); }
132
const Point<3> & Center() const { return center; }
133
const Box<2> & BoundingBox() const { return boundingbox; }
134
double Radius () const { return rad; }
135
136
void SetSmoothEdge (int se) { smoothedge = se; }
137
int IsSmoothEdge () const { return smoothedge; }
138
friend class STLBoundary;
139
};
140
141
class STLBoundary
142
{
143
private:
144
STLGeometry * geometry;
145
const STLChart * chart;
146
ARRAY<STLBoundarySeg> boundary;
147
public:
148
STLBoundary(STLGeometry * ageometry);
149
// : boundary() {};
150
151
void Clear() {boundary.SetSize(0);};
152
void SetChart (const STLChart * achart) { chart = achart; }
153
//don't check, if already exists!
154
void AddNewSegment(const STLBoundarySeg & seg) {boundary.Append(seg);};
155
//check if segment exists
156
void AddOrDelSegment(const STLBoundarySeg & seg);
157
//addordelsegment for all 3 triangle segments!
158
void AddTriangle(const STLTriangle & t);
159
int NOSegments() {return boundary.Size();};
160
const STLBoundarySeg & GetSegment(int i) {return boundary.Get(i);}
161
162
int TestSeg(const Point<3> & p1, const Point<3> & p2, const Vec<3> & sn,
163
double sinchartangle, int divisions, ARRAY<Point<3> >& points,
164
double eps);
165
166
int TestSegChartNV(const Point3d& p1, const Point3d& p2, const Vec3d& sn);
167
};
168
169
170
class STLDoctorParams
171
{
172
public:
173
int drawmeshededges;
174
double geom_tol_fact;
175
176
double longlinefact;
177
int showexcluded;
178
179
int selectmode; //0==trig, 1==edge, 2==point, 3==multiedge, 4==line cluster
180
int edgeselectmode;
181
182
int useexternaledges;
183
int showfaces;
184
int showedgecornerpoints;
185
int showtouchedtrigchart;
186
int conecheck;
187
int spiralcheck;
188
int selecttrig;
189
int nodeofseltrig;
190
int selectwithmouse;
191
int showmarkedtrigs;
192
double dirtytrigfact;
193
double smoothangle;
194
195
double smoothnormalsweight;
196
197
int showvicinity;
198
int vicinity;
199
///
200
STLDoctorParams();
201
///
202
void Print (ostream & ost) const;
203
};
204
205
extern STLDoctorParams stldoctor;
206
207
208
209
class STLParameters
210
{
211
public:
212
/// angle for edge detection
213
double yangle;
214
double contyangle; //edges continued with contyangle
215
/// angle of geometry edge at which the mesher should set a point
216
double edgecornerangle;
217
/// angle inside on chart
218
double chartangle;
219
/// angle for overlapping parts of char
220
double outerchartangle;
221
/// 0 .. no, 1 .. local, (2 .. global)
222
int usesearchtree;
223
///
224
double resthatlasfac;
225
int resthatlasenable;
226
double atlasminh;
227
228
double resthsurfcurvfac;
229
int resthsurfcurvenable;
230
231
double resthchartdistfac;
232
int resthchartdistenable;
233
234
double resthcloseedgefac;
235
int resthcloseedgeenable;
236
237
double resthedgeanglefac;
238
int resthedgeangleenable;
239
240
double resthsurfmeshcurvfac;
241
int resthsurfmeshcurvenable;
242
243
double resthlinelengthfac;
244
int resthlinelengthenable;
245
246
///
247
int recalc_h_opt;
248
///
249
STLParameters();
250
///
251
void Print (ostream & ost) const;
252
};
253
254
extern STLParameters stlparam;
255
256
257
void STLMeshing (STLGeometry & geom,
258
class Mesh & mesh);
259
260
261
int STLSurfaceMeshing (STLGeometry & geom,
262
class Mesh & mesh);
263
264
void STLSurfaceOptimization (STLGeometry & geom,
265
class Mesh & mesh,
266
class MeshingParameters & mparam);
267
268
269
270
271
#endif
272
273