Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/csg/csgeom.hpp
3206 views
1
#ifndef FILE_CSGEOM
2
#define FILE_CSGEOM
3
4
/**************************************************************************/
5
/* File: csgeom.hh */
6
/* Author: Joachim Schoeberl */
7
/* Date: 27. Nov. 97 */
8
/**************************************************************************/
9
10
/**
11
Constructive Solid Geometry
12
*/
13
14
15
class TriangleApproximation;
16
class TATriangle;
17
18
19
/**
20
A top level object is an entity to be meshed.
21
I can be either a solid, or one surface patch of a solid.
22
*/
23
class TopLevelObject
24
{
25
Solid * solid;
26
Surface * surface;
27
28
double red, blue, green;
29
bool visible, transp;
30
double maxh;
31
string material;
32
int layer;
33
int bc; // for surface patches, only
34
string bcname;
35
36
public:
37
TopLevelObject (Solid * asolid,
38
Surface * asurface = NULL);
39
40
const Solid * GetSolid() const { return solid; }
41
Solid * GetSolid() { return solid; }
42
43
const Surface * GetSurface () const { return surface; }
44
Surface * GetSurface () { return surface; }
45
46
void GetData (ostream & ost);
47
void SetData (istream & ist);
48
49
void SetMaxH (double amaxh) { maxh = amaxh; }
50
double GetMaxH () const { return maxh; }
51
52
void SetRGB (double ared, double agreen, double ablue)
53
{
54
red = ared;
55
green = agreen;
56
blue = ablue;
57
}
58
59
double GetRed () const { return red; }
60
double GetGreen () const { return green; }
61
double GetBlue () const { return blue; }
62
63
void SetTransparent (bool atransp)
64
{ transp = atransp; }
65
bool GetTransparent () const { return transp; }
66
67
void SetVisible (bool avisible)
68
{ visible = avisible; }
69
bool GetVisible () const { return visible; }
70
71
const string GetMaterial () const { return material; }
72
void SetMaterial (const string & mat) { material = mat; }
73
74
int GetLayer () const { return layer; }
75
void SetLayer (int alayer) { layer = alayer; }
76
77
void SetBCProp (int abc) { bc = abc; }
78
int GetBCProp () const { return bc; }
79
80
void SetBCName (string abc) { bcname = abc; }
81
const string GetBCName () const { return bcname; }
82
};
83
84
85
/**
86
CSGeometry has the whole geometric information
87
*/
88
class CSGeometry
89
{
90
private:
91
/// all surfaces
92
SYMBOLTABLE<Surface*> surfaces;
93
94
public:
95
/// primitive of surface
96
ARRAY<const Primitive*> surf2prim;
97
98
private:
99
ARRAY<Surface*> delete_them;
100
101
/// all named solids
102
SYMBOLTABLE<Solid*> solids;
103
104
/// all 2d splinecurves
105
SYMBOLTABLE< SplineGeometry<2>* > splinecurves2d;
106
/// all 3d splinecurves
107
SYMBOLTABLE< SplineGeometry<3>* > splinecurves3d;
108
109
/// all top level objects: solids and surfaces
110
ARRAY<TopLevelObject*> toplevelobjects;
111
112
/// additional points specified by user
113
ARRAY<Point<3> > userpoints;
114
ARRAY<double> userpoints_ref_factor;
115
116
mutable ARRAY<Point<3> > identpoints;
117
118
/// triangular approximation of top level objects
119
ARRAY<TriangleApproximation*> triapprox;
120
121
/// increment, if geometry is changed
122
static int changeval;
123
124
/// bounding box of geometry
125
Box<3> boundingbox;
126
127
/// bounding box, if not set by input file
128
static Box<3> default_boundingbox;
129
130
/// identic surfaces are stored by pair of indizes, val = inverse
131
INDEX_2_HASHTABLE<int> identicsurfaces;
132
ARRAY<int> isidenticto;
133
/// identification of boundaries (periodic, thin domains, ...)
134
135
double ideps;
136
137
138
/// filename of inputfile
139
string filename;
140
141
142
public:
143
CSGeometry ();
144
CSGeometry (const string & afilename);
145
~CSGeometry ();
146
147
void Clean ();
148
149
void Save (ostream & ost);
150
void Load (istream & ist);
151
152
void SaveSurfaces (ostream & out);
153
void LoadSurfaces (istream & in);
154
155
int GetChangeVal() { return changeval; }
156
void Change() { changeval++; }
157
158
void AddSurface (Surface * surf);
159
void AddSurface (char * name, Surface * surf);
160
void AddSurfaces (Primitive * prim);
161
162
int GetNSurf () const { return surfaces.Size(); }
163
const Surface * GetSurface (const char * name) const;
164
const Surface * GetSurface (int i) const
165
{ return surfaces[i]; }
166
167
void SetSolid (const char * name, Solid * sol);
168
const Solid * GetSolid (const char * name) const;
169
const Solid * GetSolid (const string & name) const;
170
int GetNSolids () const { return solids.Size(); }
171
const Solid * GetSolid (int i) const { return solids[i]; }
172
const SYMBOLTABLE<Solid*> & GetSolids () const { return solids; }
173
174
175
void SetSplineCurve (const char * name, SplineGeometry<2> * spl);
176
void SetSplineCurve (const char * name, SplineGeometry<3> * spl);
177
const SplineGeometry<2> * GetSplineCurve2d (const string & name) const;
178
const SplineGeometry<3> * GetSplineCurve3d (const string & name) const;
179
180
181
void SetFlags (const char * solidname, const Flags & flags);
182
183
184
int GetNTopLevelObjects () const
185
{ return toplevelobjects.Size(); }
186
int SetTopLevelObject (Solid * sol, Surface * surf = NULL);
187
void GetTopLevelObject (int nr, Solid *& sol, Surface *& surf)
188
{
189
sol = toplevelobjects[nr]->GetSolid();
190
surf = toplevelobjects[nr]->GetSurface();
191
}
192
void GetTopLevelObject (int nr, const Solid *& sol, const Surface *& surf) const
193
{
194
sol = toplevelobjects[nr]->GetSolid();
195
surf = toplevelobjects[nr]->GetSurface();
196
}
197
198
TopLevelObject * GetTopLevelObject (const Solid * sol, const Surface * surf = NULL);
199
TopLevelObject * GetTopLevelObject (int nr)
200
{ return toplevelobjects[nr]; }
201
const TopLevelObject * GetTopLevelObject (int nr) const
202
{ return toplevelobjects[nr]; }
203
void RemoveTopLevelObject (Solid * sol, Surface * surf = NULL);
204
205
206
void AddUserPoint (const Point<3> & p, double ref_factor = 0)
207
{ userpoints.Append (p); userpoints_ref_factor.Append (ref_factor); }
208
int GetNUserPoints () const
209
{ return userpoints.Size(); }
210
const Point<3> & GetUserPoint (int nr) const
211
{ return userpoints[nr]; }
212
double GetUserPointRefFactor (int nr) const
213
{ return userpoints_ref_factor[nr]; }
214
215
void AddIdentPoint (const Point<3> & p) const
216
{ identpoints.Append(p);}
217
int GetNIdentPoints (void) const
218
{ return identpoints.Size();}
219
const Point<3> & GetIdentPoint(int nr) const
220
{ return identpoints[nr]; }
221
void DeleteIdentPoints(void) const
222
{ identpoints.DeleteAll();}
223
224
225
// quick implementations:
226
ARRAY<SingularFace*> singfaces;
227
ARRAY<SingularEdge*> singedges;
228
ARRAY<SingularPoint*> singpoints;
229
ARRAY<Identification*> identifications;
230
231
int GetNIdentifications (void) const { return identifications.Size(); }
232
void AddIdentification (Identification * ident);
233
234
235
///
236
void CalcTriangleApproximation(const Box<3> & boundingbox,
237
double detail, double facets);
238
239
///
240
void FindIdenticSurfaces (double eps);
241
///
242
void GetSurfaceIndices (const Solid * sol,
243
const BoxSphere<3> & box,
244
ARRAY<int> & locsurf) const;
245
///
246
void GetIndependentSurfaceIndices (const Solid * sol,
247
const BoxSphere<3> & box,
248
ARRAY<int> & locsurf) const;
249
///
250
void GetIndependentSurfaceIndices (const Solid * sol,
251
const Point<3> & p, Vec<3> & v,
252
ARRAY<int> & locsurf) const;
253
///
254
void GetIndependentSurfaceIndices (ARRAY<int> & locsurf) const;
255
256
///
257
int GetSurfaceClassRepresentant (int si) const
258
{ return isidenticto[si]; }
259
260
///
261
const TriangleApproximation * GetTriApprox (int msnr)
262
{
263
if (msnr < triapprox.Size())
264
return triapprox[msnr];
265
return 0;
266
}
267
268
269
void IterateAllSolids (SolidIterator & it, bool only_once = false);
270
271
void RefineTriangleApprox (Solid * locsol,
272
int surfind,
273
const BoxSphere<3> & box,
274
double detail,
275
const TATriangle & tria,
276
TriangleApproximation & tams,
277
IndexSet & iset);
278
279
const Box<3> & BoundingBox () const { return boundingbox; }
280
281
void SetBoundingBox (const Box<3> & abox)
282
{
283
boundingbox = abox;
284
}
285
286
287
static void SetDefaultBoundingBox (const Box<3> & abox)
288
{
289
default_boundingbox = abox;
290
}
291
292
double MaxSize () const;
293
294
void SetIdEps(double eps){ideps = eps;}
295
double GetIdEps(void) const {return ideps;}
296
297
class BCModification {
298
public:
299
int si;
300
int tlonr;
301
int bcnr;
302
string * bcname;
303
};
304
305
ARRAY<BCModification> bcmodifications;
306
307
};
308
#endif
309
310
311