Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
triSurface
triSurface
triSurface.H
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
========= |
3
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4
\\ / O peration |
5
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6
\\/ M anipulation |
7
-------------------------------------------------------------------------------
8
License
9
This file is part of OpenFOAM.
10
11
OpenFOAM is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15
16
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19
for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23
24
Class
25
Foam::triSurface
26
27
Description
28
Triangulated surface description with patch information.
29
30
SourceFiles
31
triSurface.C
32
33
\*---------------------------------------------------------------------------*/
34
35
#ifndef triSurface_H
36
#define triSurface_H
37
38
#include <
OpenFOAM/PrimitivePatch_.H
>
39
#include <
OpenFOAM/pointField.H
>
40
#include <
triSurface/labelledTri.H
>
41
#include <
OpenFOAM/boolList.H
>
42
#include <
triSurface/geometricSurfacePatchList.H
>
43
#include <
triSurface/surfacePatchList.H
>
44
#include <
OpenFOAM/triFaceList.H
>
45
46
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48
namespace
Foam
49
{
50
51
class
Time;
52
class
IFstream;
53
54
/*---------------------------------------------------------------------------*\
55
Class triSurface Declaration
56
\*---------------------------------------------------------------------------*/
57
58
class
triSurface
59
:
60
public
PrimitivePatch
<labelledTri, ::Foam::List, pointField, point>
61
{
62
// Private typedefs
63
64
//- Typedefs for convenience
65
typedef
labelledTri
Face
;
66
typedef
PrimitivePatch
67
<
68
labelledTri
,
69
::Foam::List
,
70
pointField
,
71
point
72
>
73
ParentType
;
74
75
76
// Private data
77
78
//- The number of bytes in the STL header
79
static
const
int
STLheaderSize = 80;
80
81
//- Patch information (face ordering nFaces/startFace only used
82
// during reading and writing)
83
geometricSurfacePatchList
patches_;
84
85
86
// Demand driven private data.
87
88
//- Edge-face addressing (sorted)
89
mutable
labelListList
* sortedEdgeFacesPtr_;
90
91
//- Label of face that 'owns' edge (i.e. e.vec() is righthanded walk
92
// along face)
93
mutable
labelList
* edgeOwnerPtr_;
94
95
96
// Private member functions
97
98
//- Calculate sorted edgeFaces
99
void
calcSortedEdgeFaces()
const
;
100
101
//- Calculate owner
102
void
calcEdgeOwner()
const
;
103
104
//- Sort faces according to region. Returns patch list
105
// and sets faceMap to index of labelledTri inside *this.
106
surfacePatchList
calcPatches(
labelList
& faceMap)
const
;
107
108
//- Sets default values for patches
109
void
setDefaultPatches();
110
111
//- Function to stitch the triangles by removing duplicate points.
112
// Returns true if any points merged
113
bool
stitchTriangles
114
(
115
const
pointField
& rawPoints,
116
const
scalar tol = SMALL,
117
const
bool
verbose =
false
118
);
119
120
//- Read in Foam format
121
bool
read(
Istream
&);
122
123
//- Generic read routine. Chooses reader based on extension.
124
bool
read(
const
fileName
&,
const
word
& ext,
const
bool
check =
true
);
125
126
bool
readSTL(
const
fileName
&);
127
bool
readSTLASCII(
const
fileName
&);
128
bool
readSTLBINARY(
const
fileName
&);
129
bool
readGTS(
const
fileName
&);
130
bool
readOBJ(
const
fileName
&);
131
bool
readOFF(
const
fileName
&);
132
bool
readTRI(
const
fileName
&);
133
bool
readAC(
const
fileName
&);
134
bool
readNAS(
const
fileName
&);
135
136
//- Generic write routine. Chooses writer based on extension.
137
void
write(
const
fileName
&,
const
word
& ext,
const
bool
sort
)
const
;
138
139
//- Write to Ostream in ASCII STL format.
140
// Each region becomes 'solid' 'endsolid' block.
141
void
writeSTLASCII(
Ostream
&)
const
;
142
143
//- Write to std::ostream in BINARY STL format
144
void
writeSTLBINARY(std::ostream&)
const
;
145
146
//- Write to Ostream in GTS (Gnu Tri Surface library)
147
// format.
148
void
writeGTS(
const
bool
writeSorted,
Ostream
&)
const
;
149
150
//- Write to Ostream in OBJ (Lightwave) format.
151
// writeSorted=true: sort faces acc. to region and write as single
152
// group. =false: write in normal order.
153
void
writeOBJ(
const
bool
writeSorted,
Ostream
&)
const
;
154
155
//- Write to Ostream in OFF (Geomview) format.
156
// writeSorted=true: sort faces acc. to region and write as single
157
// group. =false: write in normal order.
158
void
writeOFF(
const
bool
writeSorted,
Ostream
&)
const
;
159
160
//- Write to VTK legacy format.
161
void
writeVTK(
const
bool
writeSorted,
Ostream
&)
const
;
162
163
//- Write to Ostream in TRI (AC3D) format
164
// Ac3d .tri format (unmerged triangle format)
165
void
writeTRI(
const
bool
writeSorted,
Ostream
&)
const
;
166
167
//- Write to Ostream in SMESH (tetgen) format
168
void
writeSMESH(
const
bool
writeSorted,
Ostream
&)
const
;
169
170
//- Write to Ostream in AC3D format. Always sorted by patch.
171
void
writeAC(
Ostream
&)
const
;
172
173
//- For DX writing.
174
void
writeDX(
const
bool
,
Ostream
&)
const
;
175
void
writeDXGeometry(
const
bool
,
Ostream
&)
const
;
176
void
writeDXTrailer(
Ostream
&)
const
;
177
178
// Static private functions
179
180
//- Convert faces to labelledTri. All get same region.
181
static
List<labelledTri>
convertToTri
182
(
183
const
faceList
&,
184
const
label defaultRegion = 0
185
);
186
187
//- Convert triFaces to labelledTri. All get same region.
188
static
List<labelledTri>
convertToTri
189
(
190
const
triFaceList
&,
191
const
label defaultRegion = 0
192
);
193
194
//- helper function to print triangle info
195
static
void
printTriangle
196
(
197
Ostream
&,
198
const
Foam::string
& pre,
199
const
labelledTri
&,
200
const
pointField
&
201
);
202
203
//- read non-comment line
204
static
string
getLineNoComment(
IFstream
&);
205
206
protected
:
207
208
// Protected Member Functions
209
210
//- Non-const access to global points
211
pointField
&
storedPoints
()
212
{
213
return
const_cast<
pointField
&
>
(
ParentType::points
());
214
}
215
216
//- Non-const access to the faces
217
List<Face>
&
storedFaces
()
218
{
219
return
static_cast<
List<Face>
&
>
(*this);
220
}
221
222
public
:
223
224
// Public typedefs
225
226
//- Placeholder only, but do not remove - it is needed for GeoMesh
227
typedef
bool
BoundaryMesh
;
228
229
230
//- Runtime type information
231
ClassName
(
"triSurface"
);
232
233
234
// Static
235
236
//- Name of triSurface directory to use.
237
static
fileName
triSurfInstance
(
const
Time
&);
238
239
240
// Constructors
241
242
//- Construct null
243
triSurface
();
244
245
//- Construct from triangles, patches, points.
246
triSurface
247
(
248
const
List<labelledTri>
&,
249
const
geometricSurfacePatchList
&,
250
const
pointField
&
251
);
252
253
//- Construct from triangles, patches, points. Reuse storage.
254
triSurface
255
(
256
List<labelledTri>
&,
257
const
geometricSurfacePatchList
&,
258
pointField
&,
259
const
bool
reUse
260
);
261
262
//- Construct from triangles, points. Set patchnames to default.
263
triSurface
(
const
List<labelledTri>
&,
const
pointField
&);
264
265
//- Construct from triangles, points. Set region to 0 and default
266
// patchName.
267
triSurface
(
const
triFaceList
&,
const
pointField
&);
268
269
//- Construct from file name (uses extension to determine type)
270
triSurface
(
const
fileName
&);
271
272
//- Construct from Istream
273
triSurface
(
Istream
&);
274
275
//- Construct from objectRegistry
276
triSurface
(
const
Time
&
d
);
277
278
//- Construct as copy
279
triSurface
(
const
triSurface
&);
280
281
282
283
// Destructor
284
285
~triSurface
();
286
287
void
clearOut
();
288
289
void
clearTopology
();
290
291
void
clearPatchMeshAddr
();
292
293
294
// Member Functions
295
296
// Access
297
298
const
geometricSurfacePatchList
&
patches
()
const
299
{
300
return
patches_;
301
}
302
303
geometricSurfacePatchList
&
patches
()
304
{
305
return
patches_;
306
}
307
308
//- Return edge-face addressing sorted (for edges with more than
309
// 2 faces) according to the angle around the edge.
310
// Orientation is anticlockwise looking from
311
// edge.vec(localPoints())
312
const
labelListList
&
sortedEdgeFaces
()
const
;
313
314
//- If 2 face neighbours: label of face where ordering of edge
315
// is consistent with righthand walk.
316
// If 1 neighbour: label of only face.
317
// If >2 neighbours: undetermined.
318
const
labelList
&
edgeOwner
()
const
;
319
320
// Edit
321
322
//- Move points
323
virtual
void
movePoints
(
const
pointField
&);
324
325
//- Scale points. A non-positive factor is ignored
326
virtual
void
scalePoints
(
const
scalar&);
327
328
//- Check/remove duplicate/degenerate triangles
329
void
checkTriangles
(
const
bool
verbose);
330
331
//- Check triply (or more) connected edges.
332
void
checkEdges
(
const
bool
verbose);
333
334
//- Remove non-valid triangles
335
void
cleanup
(
const
bool
verbose);
336
337
//- Fill faceZone with currentZone for every face reachable
338
// from faceI without crossing edge marked in borderEdge.
339
// Note: faceZone has to be sized nFaces before calling this fun.
340
void
markZone
341
(
342
const
boolList
& borderEdge,
343
const
label faceI,
344
const
label currentZone,
345
labelList
&
faceZone
346
)
const
;
347
348
//- (size and) fills faceZone with zone of face. Zone is area
349
// reachable by edge crossing without crossing borderEdge
350
// (bool for every edge in surface). Returns number of zones.
351
label
markZones
352
(
353
const
boolList
& borderEdge,
354
labelList
&
faceZone
355
)
const
;
356
357
//- 'Create' sub mesh, including only faces for which
358
// boolList entry is true
359
// Sets: pointMap: from new to old localPoints
360
// faceMap: new to old faces
361
void
subsetMeshMap
362
(
363
const
boolList
& include,
364
labelList
& pointMap,
365
labelList
& faceMap
366
)
const
;
367
368
//- Return new surface. Returns pointMap, faceMap from
369
// subsetMeshMap
370
triSurface
subsetMesh
371
(
372
const
boolList
& include,
373
labelList
& pointMap,
374
labelList
& faceMap
375
)
const
;
376
377
// Write
378
379
//- Write to Ostream in simple FOAM format
380
void
write(
Ostream
&)
const
;
381
382
//- Generic write routine. Chooses writer based on extension.
383
void
write(
const
fileName
&,
const
bool
sortByRegion =
false
)
const
;
384
385
//- Write to database
386
void
write(
const
Time
&)
const
;
387
388
//- Write to Ostream in OpenDX format
389
void
writeDX(
const
scalarField
&,
Ostream
&)
const
;
390
void
writeDX(
const
vectorField
&,
Ostream
&)
const
;
391
392
//- Write some statistics
393
void
writeStats
(
Ostream
&)
const
;
394
395
396
// Member operators
397
398
void
operator=
(
const
triSurface
&);
399
400
401
// Ostream Operator
402
403
friend
Ostream
&
operator<<
(
Ostream
&,
const
triSurface
&);
404
};
405
406
407
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
408
409
}
// End namespace Foam
410
411
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412
413
#endif
414
415
// ************************ vim: set sw=4 sts=4 et: ************************ //