Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/csg/solid.hpp
3206 views
1
#ifndef FILE_SOLID
2
#define FILE_SOLID
3
4
/**************************************************************************/
5
/* File: solid.hh */
6
/* Author: Joachim Schoeberl */
7
/* Date: 1. Dez. 95 */
8
/**************************************************************************/
9
10
/*
11
12
Constructive Solid Model (csg)
13
14
*/
15
16
17
18
19
class Solid;
20
21
class SolidIterator
22
{
23
public:
24
SolidIterator () { ; }
25
virtual ~SolidIterator () { ; }
26
virtual void Do (Solid * sol) = 0;
27
};
28
29
30
31
class Solid
32
{
33
public:
34
35
typedef enum optyp1 { TERM, TERM_REF, SECTION, UNION, SUB, ROOT, DUMMY } optyp;
36
37
private:
38
char * name;
39
Primitive * prim;
40
Solid * s1, * s2;
41
42
optyp op;
43
bool visited;
44
double maxh;
45
46
// static int cntnames;
47
48
public:
49
Solid (Primitive * aprim);
50
Solid (optyp aop, Solid * as1, Solid * as2 = NULL);
51
~Solid ();
52
53
const char * Name () const { return name; }
54
void SetName (const char * aname);
55
56
Solid * Copy (class CSGeometry & geom) const;
57
void Transform (Transformation<3> & trans);
58
59
60
void IterateSolid (SolidIterator & it, bool only_once = 0);
61
62
63
void Boundaries (const Point<3> & p, ARRAY<int> & bounds) const;
64
int NumPrimitives () const;
65
void GetSurfaceIndices (ARRAY<int> & surfind) const;
66
void GetSurfaceIndices (IndexSet & iset) const;
67
68
void GetTangentialSurfaceIndices (const Point<3> & p, ARRAY<int> & surfids, double eps) const;
69
void GetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, ARRAY<int> & surfids, double eps) const;
70
void GetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, ARRAY<int> & surfids, double eps) const;
71
72
73
Primitive * GetPrimitive ()
74
{ return (op == TERM || op == TERM_REF) ? prim : NULL; }
75
const Primitive * GetPrimitive () const
76
{ return (op == TERM || op == TERM_REF) ? prim : NULL; }
77
78
Solid * S1() { return s1; }
79
Solid * S2() { return s2; }
80
81
// geometric tests
82
83
bool IsIn (const Point<3> & p, double eps = 1e-6) const;
84
bool IsStrictIn (const Point<3> & p, double eps = 1e-6) const;
85
bool VectorIn (const Point<3> & p, const Vec<3> & v, double eps = 1e-6) const;
86
bool VectorStrictIn (const Point<3> & p, const Vec<3> & v, double eps = 1e-6) const;
87
88
bool VectorIn2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
89
double eps) const;
90
bool VectorIn2Rec (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
91
double eps) const;
92
93
94
/// compute localization in point p
95
void TangentialSolid (const Point<3> & p, Solid *& tansol, ARRAY<int> & surfids, double eps) const;
96
97
/// compute localization in point p tangential to vector t
98
void TangentialSolid2 (const Point<3> & p, const Vec<3> & t,
99
Solid *& tansol, ARRAY<int> & surfids, double eps) const;
100
101
/** compute localization in point p, with second order approximation to edge
102
p + s t + s*s/2 t2 **/
103
void TangentialSolid3 (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
104
Solid *& tansol, ARRAY<int> & surfids, double eps) const;
105
106
107
108
/** tangential solid, which follows the edge
109
p + s t + s*s/2 t2
110
with second order, and the neighbouring face
111
p + s t + s*s/2 t2 + r m
112
with first order
113
**/
114
void TangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
115
const Vec<3> & m,
116
Solid *& tansol, ARRAY<int> & surfids, double eps) const;
117
118
119
void CalcOnePrimitiveSpecialPoints (const Box<3> & box, ARRAY<Point<3> > & pts) const;
120
121
///
122
int Edge (const Point<3> & p, const Vec<3> & v, double eps) const;
123
///
124
int OnFace (const Point<3> & p, const Vec<3> & v, double eps) const;
125
///
126
void Print (ostream & str) const;
127
///
128
void CalcSurfaceInverse ();
129
///
130
Solid * GetReducedSolid (const BoxSphere<3> & box) const;
131
132
133
void SetMaxH (double amaxh)
134
{ maxh = amaxh; }
135
double GetMaxH () const
136
{ return maxh; }
137
138
void GetSolidData (ostream & ost, int first = 1) const;
139
static Solid * CreateSolid (istream & ist, const SYMBOLTABLE<Solid*> & solids);
140
141
142
static BlockAllocator ball;
143
void * operator new(size_t /* s */)
144
{
145
return ball.Alloc();
146
}
147
148
void operator delete (void * p)
149
{
150
ball.Free (p);
151
}
152
153
154
protected:
155
///
156
157
void RecBoundaries (const Point<3> & p, ARRAY<int> & bounds,
158
int & in, int & strin) const;
159
///
160
void RecTangentialSolid (const Point<3> & p, Solid *& tansol, ARRAY<int> & surfids,
161
int & in, int & strin, double eps) const;
162
163
void RecTangentialSolid2 (const Point<3> & p, const Vec<3> & vec,
164
Solid *& tansol, ARRAY<int> & surfids,
165
int & in, int & strin, double eps) const;
166
///
167
void RecTangentialSolid3 (const Point<3> & p, const Vec<3> & vec,const Vec<3> & vec2,
168
Solid *& tansol, ARRAY<int> & surfids,
169
int & in, int & strin, double eps) const;
170
///
171
void RecTangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
172
const Vec<3> & m,
173
Solid *& tansol, ARRAY<int> & surfids,
174
int & in, int & strin, double eps) const;
175
176
///
177
void RecEdge (const Point<3> & p, const Vec<3> & v,
178
int & in, int & strin, int & faces, double eps) const;
179
///
180
void CalcSurfaceInverseRec (int inv);
181
///
182
Solid * RecGetReducedSolid (const BoxSphere<3> & box, INSOLID_TYPE & in) const;
183
///
184
void RecGetSurfaceIndices (ARRAY<int> & surfind) const;
185
void RecGetTangentialSurfaceIndices (const Point<3> & p, ARRAY<int> & surfids, double eps) const;
186
void RecGetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, ARRAY<int> & surfids, double eps) const;
187
void RecGetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2,
188
ARRAY<int> & surfids, double eps) const;
189
void RecGetTangentialEdgeSurfaceIndices (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, const Vec<3> & m,
190
ARRAY<int> & surfids, double eps) const;
191
void RecGetSurfaceIndices (IndexSet & iset) const;
192
193
void RecCalcOnePrimitiveSpecialPoints (ARRAY<Point<3> > & pts) const;
194
195
friend class SolidIterator;
196
friend class ClearVisitedIt;
197
friend class RemoveDummyIterator;
198
friend class CSGeometry;
199
};
200
201
202
inline ostream & operator<< (ostream & ost, const Solid & sol)
203
{
204
sol.Print (ost);
205
return ost;
206
}
207
208
209
210
211
212
213
class ReducePrimitiveIterator : public SolidIterator
214
{
215
const BoxSphere<3> & box;
216
public:
217
ReducePrimitiveIterator (const BoxSphere<3> & abox)
218
: SolidIterator(), box(abox) { ; }
219
virtual ~ReducePrimitiveIterator () { ; }
220
virtual void Do (Solid * sol)
221
{
222
if (sol -> GetPrimitive())
223
sol -> GetPrimitive() -> Reduce (box);
224
}
225
};
226
227
228
class UnReducePrimitiveIterator : public SolidIterator
229
{
230
public:
231
UnReducePrimitiveIterator () { ; }
232
virtual ~UnReducePrimitiveIterator () { ; }
233
virtual void Do (Solid * sol)
234
{
235
if (sol -> GetPrimitive())
236
sol -> GetPrimitive() -> UnReduce ();
237
}
238
};
239
240
241
#endif
242
243