Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/stlgeom/stlgeom.hpp
3206 views
1
#ifndef FILE_STLGEOM
2
#define FILE_STLGEOM
3
4
/**************************************************************************/
5
/* File: stlgeom.hpp */
6
/* Author: Joachim Schoeberl */
7
/* Author2: Johannes Gerstmayr */
8
/* Date: 26. Jul. 99 */
9
/**************************************************************************/
10
11
/**
12
STL Geometry
13
14
15
Terminology:
16
17
Point ... coordinates of STL triangles
18
Triangle (short Trig) STL triangle
19
TopEdge .... edge in topology, boundary of STL triangles (many)
20
Edge .... Edges which will occur in the mesh (confirmed edges, less)
21
*/
22
23
24
#include <gprim.hpp>
25
#include <meshing.hpp>
26
27
28
29
namespace netgen
30
{
31
extern int IsInArray(int n, const ARRAY<int>& ia);
32
extern int AddIfNotExists(ARRAY<int>& list, int x);
33
34
35
#include "stltopology.hpp"
36
#include "stltool.hpp"
37
#include "stlline.hpp"
38
39
40
41
42
43
44
45
class STLEdgeDataList
46
{
47
ARRAY<int> storedstatus;
48
STLTopology & geom;
49
public:
50
51
STLEdgeDataList(STLTopology & ageom);
52
~STLEdgeDataList();
53
54
void Store ();
55
void Restore ();
56
57
void SetSize(int /* size */) { };
58
void Clear() { };
59
int Size() const { return geom.GetNTE(); }
60
const STLTopEdge & Get(int i) const { return geom.GetTopEdge(i); }
61
STLTopEdge & Elem(int i) { return geom.GetTopEdge(i); }
62
63
int GetNEPP(int pn) const {return geom.NTopEdgesPerPoint(pn); }
64
int GetEdgePP(int pn, int vi) const {return geom.TopEdgePerPoint(pn, vi);};
65
66
//void AddEdgePP(int pn, int vn) { } ;
67
68
void ResetAll();
69
void ChangeStatus(int status1, int status2);
70
71
int GetEdgeNum(int np1, int np2) const
72
{ return geom.GetTopEdgeNum (np1, np2); }
73
74
int GetNConfEdges() const;
75
76
void Write(ofstream& of) const;
77
void Read(ifstream& ifs);
78
79
void BuildLineWithEdge(int ep1, int ep2, ARRAY<twoint>& line);
80
void BuildClusterWithEdge(int ep1, int ep2, ARRAY<twoint>& line);
81
82
int GetNEPPStat(int p, int status) const;
83
int GetNConfCandEPP(int p) const;
84
};
85
86
87
88
89
90
91
class STLGeometry : public STLTopology
92
{
93
// edges to be meshed:
94
ARRAY<STLEdge> edges;
95
//edges per point
96
TABLE<int> edgesperpoint;
97
98
// line: a connection of edges
99
ARRAY<STLLine*> lines;
100
ARRAY<int> lineendpoints; //per geometrypoint, 1 = is endpoint; 0 = no endpoint,
101
102
ARRAY<Vec3d> normals; //normals belong to points!
103
104
ARRAY<twoint> externaledges;
105
106
int undoexternaledges;
107
ARRAY<twoint> storedexternaledges;
108
109
STLEdgeDataList * edgedata;
110
// STLEdgeDataList edgedata_store;
111
int calcedgedataanglesnew;
112
113
int edgedatastored;
114
115
116
117
int facecnt;
118
//meshpoint is only set, if an edge is at this point!!!
119
120
ARRAY<int> vicinity; //is one, if a triangle belongs to vicinity (eg. of selecttrig)
121
ARRAY<int> markedtrigs; //is one, if a triangle belongs to marked triangles (calcdirtystrigs)
122
ARRAY<Point3d> markedsegs; //every pointpair is a segment!!!
123
ARRAY<twoint> selectedmultiedge;
124
125
126
//spiralpoints:
127
ARRAY<int> spiralpoints;
128
//
129
ARRAY<STLChart*> atlas;
130
//marks all already charted trigs with chartnumber
131
ARRAY<int> chartmark;
132
//outerchartspertrig, ascending sorted
133
TABLE<int> outerchartspertrig;
134
135
136
//for meshing and project:
137
ARRAY<int> meshcharttrigs; //per trig: 1=belong to chart, 0 not
138
int meshchart;
139
140
ARRAY<int> ha_points; // help array, np long, filled with 0
141
142
143
// sharp geometric edges not declared as edges
144
// (not considered for spiral check)
145
INDEX_2_HASHTABLE<int> * smoothedges;
146
147
148
//transformation:
149
Vec<3> meshtrignv;
150
Vec<3> ex, ey, ez;
151
Point<3> p1;
152
153
public:
154
int edgesfound;
155
int surfacemeshed;
156
int surfaceoptimized;
157
int volumemeshed;
158
159
int trigsconverted; //when STLTriangles exist -> 1
160
161
//for selecting nodes
162
//int selecttrig, nodeofseltrig;
163
164
//only for testing;
165
ARRAY<STLLine*> meshlines;
166
ARRAY<Point3d> meshpoints;
167
168
public:
169
STLGeometry();
170
virtual ~STLGeometry();
171
172
173
void Clear();
174
175
176
177
void STLInfo(double* data);
178
//stldoctor:
179
void SmoothNormals();
180
void MarkNonSmoothNormals();
181
182
void CalcEdgeData();
183
void CalcEdgeDataAngles();
184
185
const STLEdgeDataList& EdgeDataList() const {return *edgedata;}
186
187
void UndoEdgeChange();
188
void StoreEdgeData();
189
void RestoreEdgeData();
190
191
//void ClearSelectedMultiEdge() {selectedmultiedge.SetSize(0);}
192
//void AddSelectedMultiEdge(twoint ep) {selectedmultiedge.Append(ep);}
193
//int SelectedMultiEdgeSize() {return selectedmultiedge.Size();}
194
const ARRAY<twoint>& SelectedMultiEdge() {return selectedmultiedge;}
195
twoint GetNearestSelectedDefinedEdge();
196
void BuildSelectedMultiEdge(twoint ep);
197
void BuildSelectedEdge(twoint ep);
198
void BuildSelectedCluster(twoint ep);
199
200
void ImportEdges();
201
void AddEdges(const ARRAY<Point<3> >& eps);
202
void ExportEdges();
203
void LoadEdgeData(const char* file);
204
void SaveEdgeData(const char* file);
205
// void SetEdgeAtSelected(int mode);
206
207
208
void STLDoctorConfirmEdge();
209
void STLDoctorCandidateEdge();
210
void STLDoctorExcludeEdge();
211
void STLDoctorUndefinedEdge();
212
213
void STLDoctorSetAllUndefinedEdges();
214
void STLDoctorEraseCandidateEdges();
215
void STLDoctorConfirmCandidateEdges();
216
void STLDoctorConfirmedToCandidateEdges();
217
218
void STLDoctorDirtyEdgesToCandidates();
219
void STLDoctorLongLinesToCandidates();
220
221
void UndoExternalEdges();
222
void StoreExternalEdges();
223
void RestoreExternalEdges();
224
225
void ImportExternalEdges(const char * filename); // Flame edges, JS
226
// void LoadExternalEdges();
227
228
void BuildExternalEdgesFromEdges();
229
void SaveExternalEdges();
230
void AddExternalEdgeAtSelected();
231
void AddClosedLinesToExternalEdges();
232
void AddLongLinesToExternalEdges();
233
void AddAllNotSingleLinesToExternalEdges();
234
void STLDoctorBuildEdges();
235
void AddExternalEdgesFromGeomLine();
236
void DeleteDirtyExternalEdges();
237
void DeleteExternalEdgeAtSelected();
238
void DeleteExternalEdgeInVicinity();
239
void AddExternalEdge(int p1, int p2);
240
void DeleteExternalEdge(int p1, int p2);
241
int IsExternalEdge(int p1, int p2);
242
int NOExternalEdges() const {return externaledges.Size();}
243
twoint GetExternalEdge(int i) const {return externaledges.Get(i);}
244
245
void DestroyDirtyTrigs();
246
void CalcNormalsFromGeometry();
247
void MoveSelectedPointToMiddle();
248
void NeighbourAnglesOfSelectedTrig();
249
void PrintSelectInfo();
250
void ShowSelectedTrigChartnum();
251
void ShowSelectedTrigCoords();
252
void SmoothGeometry ();
253
254
255
void LoadMarkedTrigs();
256
void SaveMarkedTrigs();
257
void ClearMarkedSegs() {markedsegs.SetSize(0);}
258
void AddMarkedSeg(const Point<3> & ap1, const Point<3> & ap2)
259
{
260
markedsegs.Append(ap1);markedsegs.Append(ap2);
261
}
262
263
void GetMarkedSeg(int i, Point<3> & ap1, Point<3> & ap2)
264
{
265
ap1=markedsegs.Get(i*2-1);
266
ap2=markedsegs.Get(i*2);
267
}
268
int GetNMarkedSegs() {return markedsegs.Size()/2;}
269
void CalcVicinity(int starttrig);
270
void GetVicinity(int starttrig, int size, ARRAY<int>& vic);
271
272
int Vicinity(int trig) const;
273
274
void InitMarkedTrigs();
275
void MarkDirtyTrigs();
276
void SmoothDirtyTrigs();
277
void GeomSmoothRevertedTrigs();
278
void MarkRevertedTrigs();
279
double CalcTrigBadness(int i);
280
int IsMarkedTrig(int trig) const;
281
void SetMarkedTrig(int trig, int num);
282
void MarkTopErrorTrigs ();
283
284
//Selected triangle
285
void SetSelectTrig(int trig);
286
int GetSelectTrig() const;
287
void SetNodeOfSelTrig(int n);
288
int GetNodeOfSelTrig() const;
289
290
291
int AddNormal(const Vec3d& n) {return normals.Append(n);}
292
const Vec3d & GetNormal(int nr) const {return normals.Get(nr);}
293
void SetNormal(int nr, const Vec3d& n) {normals.Elem(nr) = n;}
294
295
int AddEdge(const STLEdge& v) {return edges.Append(v);}
296
int AddEdge(int p1, int p2);
297
298
STLEdge GetEdge(int nr) {return edges.Get(nr);}
299
int GetNE() {return edges.Size();}
300
301
double Area();
302
303
double GetAngle(int t1, int t2);
304
double GetGeomAngle(int t1, int t2);
305
//if triangles t1 and t2 touch, return 1 and in p1, p2 the touching points
306
//int TrigsTouch(int t1, int t2, int& p1, int& p2);
307
308
309
310
///
311
312
///ReadTriangle->STLTriangle, initialise some important variables, always after load!!!
313
virtual void InitSTLGeometry (const ARRAY<STLReadTriangle> & readtrigs);
314
virtual void TopologyChanged(); //do some things, if topology changed!
315
int CheckGeometryOverlapping();
316
317
//get NO edges per point
318
int GetEPPSize() const {return edgesperpoint.Size();};
319
int GetNEPP(int pn)
320
{
321
if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();}
322
return edgesperpoint.EntrySize(pn);
323
};
324
int GetEdgePP(int pn, int vi)
325
{
326
if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();}
327
return edgesperpoint.Get(pn,vi);
328
};
329
void AddEdgePP(int pn, int vn) {edgesperpoint.Add1(pn,vn);};
330
//von 2 punkten ermitteln, ob sie eine Kante sind
331
int IsEdge(int p1, int p2);
332
int IsEdgeNum(int p1, int p2);
333
334
///Build EdgeSegments
335
void ClearEdges();
336
void BuildEdges();
337
void BuildEdgesPerPoint();
338
void UseExternalEdges();
339
340
341
void FindEdgesFromAngles();
342
void CalcFaceNums();
343
int GetNOBodys();
344
int GetNOFaces() {return facecnt;}
345
void LinkEdges();
346
347
void AddConeAndSpiralEdges();
348
void AddFaceEdges(); //each face should have at least one starting edge (outherwise it won't be meshed)
349
350
void GetDirtyChartTrigs(int chartnum, STLChart& chart, const ARRAY<int>& outercharttrigs,
351
ARRAY<int>& chartpointchecked, ARRAY<int>& dirtytrigs);
352
353
void ClearSpiralPoints();
354
void SetSpiralPoint(int pn) {spiralpoints.Elem(pn) = 1;};
355
int GetSpiralPoint(int pn) const {return spiralpoints.Get(pn);};
356
357
void GetSortedTrianglesAroundPoint(int p, int starttrig, ARRAY<int>& trigs);
358
359
// smooth edges: sharp geometric edges not declared as edges
360
void BuildSmoothEdges ();
361
int IsSmoothEdge (int pi1, int pi2) const;
362
363
364
//make charts with regions of a max. angle
365
void MakeAtlas(class Mesh & mesh);
366
367
//outerchartspertrig, sorted!
368
int GetOCPTSize() const {return outerchartspertrig.Size();};
369
int GetNOCPT(int tn) const {return outerchartspertrig.EntrySize(tn);};
370
int GetOCPT(int tn, int vi) const {return outerchartspertrig.Get(tn,vi);};
371
void SetOCPT(int tn, int vi, int ocn) {outerchartspertrig.Set(tn,vi,ocn);};
372
void AddOCPT(int tn, int ocn) {outerchartspertrig.Add1(tn, ocn);};
373
int TrigIsInOC(int tn, int ocn) const;
374
375
//get chart number of a trig or 0 if unmarked
376
int GetChartNr(int i) const;
377
int GetMarker(int i) const
378
{ return chartmark.Get(i); }
379
void SetMarker(int nr, int m);
380
int GetNOCharts() const;
381
//get a chart from atlas
382
const STLChart& GetChart(int nr) const;
383
STLChart& GetChart(int nr) {return *(atlas.Get(nr));};
384
int AtlasMade() const;
385
386
void GetInnerChartLimes(ARRAY<twoint>& limes, int chartnum);
387
388
//FOR MESHING
389
int GetMeshChartNr () { return meshchart; }
390
void GetMeshChartBoundary (ARRAY<Point2d > & points,
391
ARRAY<Point3d > & points3d,
392
ARRAY<INDEX_2> & lines, double h);
393
394
395
Point<3> PointBetween(const Point<3> & p1, int t1, const Point<3> & p2, int t2);
396
397
//select triangles in meshcharttrigs of actual (defined by trig) whole chart
398
void PrepareSurfaceMeshing();
399
//
400
void DefineTangentialPlane(const Point<3> & ap1, const Point<3> & ap2, int trig);
401
//
402
void SelectChartOfTriangle (int trignum);
403
//
404
void SelectChartOfPoint (const Point<3> & p);
405
//
406
const Vec<3> & GetChartNormalVector () const { return meshtrignv; }
407
408
// list of trigs
409
void ToPlane (const Point<3> & locpoint, int * trigs, Point<2> & plainpoint,
410
double h, int& zone, int checkchart);
411
//return 0, wenn alles OK, 1 sonst
412
int FromPlane (const Point<2> & plainpoint, Point<3> & locpoint, double h);
413
414
//get nearest point in actual chart and return any triangle where it lies on
415
int ProjectNearest(Point<3> & p3d) const;
416
//project point with normal nv from last define tangential plane
417
418
int LastTrig() const;
419
int Project(Point<3> & p3d) const;
420
int ProjectOnWholeSurface (Point<3> & p3d) const;
421
422
int GetNLines() const {return lines.Size();}
423
int AddLine(STLLine* line) {return lines.Append(line);}
424
STLLine* GetLine(int nr) const {return lines.Get(nr);}
425
int GetLineP(int lnr, int pnr) const {return lines.Get(lnr)->PNum(pnr);}
426
int GetLineNP(int nr) const {return lines.Get(nr)->NP();}
427
428
void SetLineEndPoint(int pn);
429
int IsLineEndPoint(int pn);
430
int LineEndPointsSet() const {return lineendpoints.Size() == GetNP();}
431
void ClearLineEndPoints();
432
433
void RestrictLocalH(class Mesh & mesh, double gh);
434
void RestrictLocalHCurv(class Mesh & mesh, double gh);
435
void RestrictHChartDistOneChart(int chartnum, ARRAY<int>& acttrigs, class Mesh & mesh,
436
double gh, double fact, double minh);
437
438
friend class MeshingSTLSurface;
439
};
440
441
442
#include "meshstlsurface.hpp"
443
444
445
extern int STLMeshingDummy (STLGeometry* stlgeometry, Mesh*& mesh,
446
int perfstepsstart, int perfstepsend, char* optstring);
447
448
449
}
450
#endif
451
452