isoSurfaceCell.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::isoSurfaceCell
29 
30 Description
31  A surface formed by the iso value.
32  After "Polygonising A Scalar Field Using Tetrahedrons", Paul Bourke
33  (http://paulbourke.net/geometry/polygonise) and
34  "Regularised Marching Tetrahedra: improved iso-surface extraction",
35  G.M. Treece, R.W. Prager and A.H. Gee.
36 
37  See isoSurface. This is a variant which does tetrahedrisation from
38  triangulation of face to cell centre instead of edge of face to two
39  neighbouring cell centres. This gives much lower quality triangles
40  but they are local to a cell.
41 
42 SourceFiles
43  isoSurfaceCell.C
44  isoSurfaceCellTemplates.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef isoSurfaceCell_H
49 #define isoSurfaceCell_H
50 
51 #include "labelPair.H"
52 #include "pointIndexHit.H"
53 #include "bitSet.H"
54 #include "isoSurfaceBase.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declarations
62 
63 class polyMesh;
64 class triSurface;
65 
66 /*---------------------------------------------------------------------------*\
67  Class isoSurfaceCell Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class isoSurfaceCell
71 :
72  public isoSurfaceBase
73 {
74  // Private data
75 
76  enum segmentCutType
77  {
78  NEARFIRST,
79  NEARSECOND,
80  NOTNEAR
81  };
82 
83  enum cellCutType
84  {
85  NOTCUT,
86  SPHERE,
87  CUT
88  };
89 
90 
91  //- Reference to mesh
92  const polyMesh& mesh_;
93 
94  const scalarField& cVals_;
95 
96  const scalarField& pVals_;
97 
98  //- Optional cells to ignore
99  const bitSet& ignoreCells_;
100 
101  //- When to merge points
102  const scalar mergeDistance_;
103 
104  //- Whether cell might be cut
105  List<cellCutType> cellCutType_;
106 
107  //- Estimated number of cut cells
108  label nCutCells_;
109 
110  //- For every unmerged triangle point the point in the triSurface
111  labelList triPointMergeMap_;
112 
113  //- triSurface points that have weighted interpolation
114  DynamicList<label> interpolatedPoints_;
115 
116  //- corresponding original, unmerged points
117  DynamicList<FixedList<label, 3>> interpolatedOldPoints_;
118 
119  //- corresponding weights
120  DynamicList<FixedList<scalar, 3>> interpolationWeights_;
121 
122 
123  // Private Member Functions
124 
125  //- Get location of iso value as fraction inbetween s0,s1
126  scalar isoFraction
127  (
128  const scalar s0,
129  const scalar s1
130  ) const;
131 
132 
133  //- Determine whether cell is cut
134  cellCutType calcCutType
135  (
136  const bitSet&,
137  const scalarField& cellValues,
138  const scalarField& pointValues,
139  const label
140  ) const;
141 
142  void calcCutTypes
143  (
144  const bitSet&,
145  const scalarField& cellValues,
146  const scalarField& pointValues
147  );
148 
149  //- Return the two common points between two triangles
150  static labelPair findCommonPoints
151  (
152  const labelledTri&,
153  const labelledTri&
154  );
155 
156  //- Calculate centre of surface.
157  static point calcCentre(const triSurface&);
158 
159  //- Replace surface (localPoints, localTris) with single point.
160  // Returns point. Destroys arguments.
161  pointIndexHit collapseSurface
162  (
163  const label celli,
164  pointField& localPoints,
166  ) const;
167 
168  //- Determine per cc whether all near cuts can be snapped to single
169  // point.
170  void calcSnappedCc
171  (
172  const bitSet& isTet,
173  const scalarField& cVals,
174  const scalarField& pVals,
176  labelList& snappedCc
177  ) const;
178 
179  //- Generate triangles for face connected to pointi
180  void genPointTris
181  (
182  const scalarField& cellValues,
183  const scalarField& pointValues,
184  const label pointi,
185  const label facei,
186  const label celli,
187  DynamicList<point, 64>& localTriPoints
188  ) const;
189 
190  //- Generate triangles for tet connected to pointi
191  void genPointTris
192  (
193  const scalarField& pointValues,
194  const label pointi,
195  const label facei,
196  const label celli,
197  DynamicList<point, 64>& localTriPoints
198  ) const;
199 
200  //- Determine per point whether all near cuts can be snapped to single
201  // point.
202  void calcSnappedPoint
203  (
204  const bitSet& isTet,
205  const scalarField& cVals,
206  const scalarField& pVals,
208  labelList& snappedPoint
209  ) const;
210 
211  //- Generate single point by interpolation or snapping
212  template<class Type>
213  Type generatePoint
214  (
215  const DynamicList<Type>& snappedPoints,
216  const scalar s0,
217  const Type& p0,
218  const label p0Index,
219  const scalar s1,
220  const Type& p1,
221  const label p1Index
222  ) const;
223 
224  template<class Type>
225  void generateTriPoints
226  (
227  const DynamicList<Type>& snapped,
228  const scalar s0,
229  const Type& p0,
230  const label p0Index,
231  const scalar s1,
232  const Type& p1,
233  const label p1Index,
234  const scalar s2,
235  const Type& p2,
236  const label p2Index,
237  const scalar s3,
238  const Type& p3,
239  const label p3Index,
241  ) const;
242 
243  template<class Type>
244  void generateTriPoints
245  (
246  const scalarField& cVals,
247  const scalarField& pVals,
248 
249  const Field<Type>& cCoords,
250  const Field<Type>& pCoords,
251 
252  const DynamicList<Type>& snappedPoints,
253  const labelList& snappedCc,
254  const labelList& snappedPoint,
255 
257  DynamicList<label>& triMeshCells
258  ) const;
259 
260  triSurface stitchTriPoints
261  (
262  const bool checkDuplicates,
263  const List<point>& triPoints,
264  labelList& triPointReverseMap, // unmerged to merged point
265  labelList& triMap // merged to unmerged triangle
266  ) const;
267 
268  //- Determine edge-face addressing
269  void calcAddressing
270  (
271  const triSurface& surf,
272  List<FixedList<label, 3>>& faceEdges,
273  labelList& edgeFace0,
274  labelList& edgeFace1,
275  Map<labelList>& edgeFacesRest
276  ) const;
277 
278  //- Is triangle (given by 3 edges) not fully connected?
279  static bool danglingTriangle
280  (
281  const FixedList<label, 3>& fEdges,
282  const labelList& edgeFace1
283  );
284 
285  //- Mark all non-fully connected triangles
286  static label markDanglingTriangles
287  (
288  const List<FixedList<label, 3>>& faceEdges,
289  const labelList& edgeFace0,
290  const labelList& edgeFace1,
291  const Map<labelList>& edgeFacesRest,
292  boolList& keepTriangles
293  );
294 
295  static triSurface subsetMesh
296  (
297  const triSurface&,
298  const labelList& newToOldFaces,
299  labelList& oldToNewPoints,
300  labelList& newToOldPoints
301  );
302 
303 
304 public:
305 
306  //- Filtering type
308 
309 
310  //- Runtime type information
311  TypeName("isoSurfaceCell");
312 
313 
314  // Constructors
315 
316  //- Construct from cell and point values
317  //
318  // \param bounds optional bounding box for trimming
319  // \param mergeTol fraction of mesh bounding box for merging points
320  // \param ignoreCells cells to ignore in the cellValues
322  (
323  const polyMesh& mesh,
324  const scalarField& cellValues,
325  const scalarField& pointValues,
326  const scalar iso,
327  const isoSurfaceBase::filterType filter,
328  const boundBox& bounds = boundBox::invertedBox,
329  const scalar mergeTol = 1e-6,
330  const bitSet& ignoreCells = bitSet()
331  );
332 
333  //- Construct from cell and point values
334  //
335  // \param bounds optional bounding box for trimming
336  // \param mergeTol fraction of mesh bounding box for merging points
337  // \param ignoreCells cells to ignore in the cellValues
339  (
340  const polyMesh& mesh,
341  const scalarField& cellValues,
342  const scalarField& pointValues,
343  const scalar iso,
344  const bool regularise,
345  const boundBox& bounds = boundBox::invertedBox,
346  const scalar mergeTol = 1e-6,
347  const bitSet& ignoreCells = bitSet()
348  );
349 
350 
351  // Member Functions
352 
353  //- Interpolates cCoords, pCoords.
354  template<class Type>
356  (
357  const Field<Type>& cCoords,
358  const Field<Type>& pCoords
359  ) const;
360 };
361 
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 } // End namespace Foam
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 #ifdef NoRepository
370  #include "isoSurfaceCellTemplates.C"
371 #endif
372 
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 
375 #endif
376 
377 // ************************************************************************* //
pointIndexHit.H
Foam::isoSurfaceBase
Low-level components common to various iso-surface algorithms.
Definition: isoSurfaceBase.H:54
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
isoSurfaceCellTemplates.C
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::DynamicList< label >
Foam::boundBox::invertedBox
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
Definition: boundBox.H:86
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: HashTableFwd.H:46
bitSet.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
isoSurfaceBase.H
Foam::isoSurfaceCell
A surface formed by the iso value. After "Polygonising A Scalar Field Using Tetrahedrons",...
Definition: isoSurfaceCell.H:69
Foam::isoSurfaceCell::TypeName
TypeName("isoSurfaceCell")
Runtime type information.
Foam::triPoints
Triangle storage. Null constructable (unfortunately triangle<point, point> is not)
Definition: triPoints.H:52
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:55
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< scalar >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:70
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::isoSurfaceCell::isoSurfaceCell
isoSurfaceCell(const polyMesh &mesh, const scalarField &cellValues, const scalarField &pointValues, const scalar iso, const isoSurfaceBase::filterType filter, const boundBox &bounds=boundBox::invertedBox, const scalar mergeTol=1e-6, const bitSet &ignoreCells=bitSet())
Construct from cell and point values.
Definition: isoSurfaceCell.C:1294
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::Vector< scalar >
Foam::List< cellCutType >
Foam::isoSurfaceCell::interpolate
tmp< Field< Type > > interpolate(const Field< Type > &cCoords, const Field< Type > &pCoords) const
Interpolates cCoords, pCoords.
Foam::FixedList< label, 3 >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:58
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
p0
const volScalarField & p0
Definition: EEqn.H:36
Foam::isoSurfaceBase::filterType
filterType
The filtering (regularization) to apply.
Definition: isoSurfaceBase.H:87
labelPair.H