1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A surface formed by the iso value.
29 After "Polygonising A Scalar Field Using Tetrahedrons", Paul Bourke
31 "Regularised Marching Tetrahedra: improved iso-surface extraction",
32 G.M. Treece, R.W. Prager and A.H. Gee.
34 See isoSurface. This is a variant which does tetrahedrisation from
35 triangulation of face to cell centre instead of edge of face to two
36 neighbouring cell centres. This gives much lower quality triangles
37 but they are local to a cell.
42 \*---------------------------------------------------------------------------*/
44 #ifndef isoSurfaceCell_H
45 #define isoSurfaceCell_H
47 #include "triSurface.H"
48 #include "labelPair.H"
49 #include "pointIndexHit.H"
50 #include "PackedBoolList.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 /*---------------------------------------------------------------------------*\
60 Class isoSurfaceCell Declaration
61 \*---------------------------------------------------------------------------*/
71 NEARFIRST, // intersection close to e.first()
72 NEARSECOND, // ,, e.second()
73 NOTNEAR // no intersection
79 SPHERE, // all edges to cell centre cut
85 const polyMesh& mesh_;
87 const scalarField& cVals_;
89 const scalarField& pVals_;
91 //- isoSurfaceCell value
94 //- When to merge points
95 const scalar mergeDistance_;
97 //- Whether cell might be cut
98 List<cellCutType> cellCutType_;
100 //- Estimated number of cut cells
103 //- For every triangle the original cell in mesh
104 labelList meshCells_;
106 //- For every unmerged triangle point the point in the triSurface
107 labelList triPointMergeMap_;
110 // Private Member Functions
112 //- Get location of iso value as fraction inbetween s0,s1
119 //List<triFace> triangulate(const face& f) const;
121 //- Determine whether cell is cut
122 cellCutType calcCutType
124 const PackedBoolList&,
125 const scalarField& cellValues,
126 const scalarField& pointValues,
132 const PackedBoolList&,
133 const scalarField& cellValues,
134 const scalarField& pointValues
137 static labelPair findCommonPoints
143 static point calcCentre(const triSurface&);
145 static pointIndexHit collapseSurface
147 pointField& localPoints,
148 DynamicList<labelledTri, 64>& localTris
151 //- Determine per cc whether all near cuts can be snapped to single
155 const PackedBoolList& isTet,
156 const scalarField& cVals,
157 const scalarField& pVals,
158 DynamicList<point>& triPoints,
162 //- Generate triangles for face connected to pointI
165 const scalarField& cellValues,
166 const scalarField& pointValues,
170 DynamicList<point, 64>& localTriPoints
173 //- Generate triangles for tet connected to pointI
176 const scalarField& pointValues,
179 DynamicList<point, 64>& localTriPoints
182 //- Determine per point whether all near cuts can be snapped to single
184 void calcSnappedPoint
186 const PackedBoolList& isBoundaryPoint,
187 const PackedBoolList& isTet,
188 const scalarField& cVals,
189 const scalarField& pVals,
190 DynamicList<point>& triPoints,
191 labelList& snappedPoint
194 //- Generate single point by interpolation or snapping
198 const DynamicList<Type>& snappedPoints,
208 void generateTriPoints
210 const DynamicList<Type>& snapped,
223 DynamicList<Type>& points
227 void generateTriPoints
229 const scalarField& cVals,
230 const scalarField& pVals,
232 const Field<Type>& cCoords,
233 const Field<Type>& pCoords,
235 const DynamicList<Type>& snappedPoints,
236 const labelList& snappedCc,
237 const labelList& snappedPoint,
239 DynamicList<Type>& triPoints,
240 DynamicList<label>& triMeshCells
243 triSurface stitchTriPoints
245 const bool checkDuplicates,
246 const List<point>& triPoints,
247 labelList& triPointReverseMap, // unmerged to merged point
248 labelList& triMap // merged to unmerged triangle
251 //- Check single triangle for (topological) validity
252 static bool validTri(const triSurface&, const label);
254 //- Determine edge-face addressing
257 const triSurface& surf,
258 List<FixedList<label, 3> >& faceEdges,
259 labelList& edgeFace0,
260 labelList& edgeFace1,
261 Map<labelList>& edgeFacesRest
264 //- Determine orientation
265 static void walkOrientation
267 const triSurface& surf,
268 const List<FixedList<label, 3> >& faceEdges,
269 const labelList& edgeFace0,
270 const labelList& edgeFace1,
271 const label seedTriI,
276 static void orientSurface
279 const List<FixedList<label, 3> >& faceEdges,
280 const labelList& edgeFace0,
281 const labelList& edgeFace1,
282 const Map<labelList>& edgeFacesRest
285 //- Is triangle (given by 3 edges) not fully connected?
286 static bool danglingTriangle
288 const FixedList<label, 3>& fEdges,
289 const labelList& edgeFace1
292 //- Mark all non-fully connected triangles
293 static label markDanglingTriangles
295 const List<FixedList<label, 3> >& faceEdges,
296 const labelList& edgeFace0,
297 const labelList& edgeFace1,
298 const Map<labelList>& edgeFacesRest,
299 boolList& keepTriangles
302 static triSurface subsetMesh
305 const labelList& newToOldFaces,
306 labelList& oldToNewPoints,
307 labelList& newToOldPoints
310 //- Combine all triangles inside a cell into a minimal triangulation
311 void combineCellTriangles();
315 //- Runtime type information
316 TypeName("isoSurfaceCell");
321 //- Construct from dictionary
324 const polyMesh& mesh,
325 const scalarField& cellValues,
326 const scalarField& pointValues,
328 const bool regularise,
329 const scalar mergeTol = 1E-6 // fraction of bounding box
335 //- For every face original cell in mesh
336 const labelList& meshCells() const
341 //- For every unmerged triangle point the point in the triSurface
342 const labelList triPointMergeMap() const
344 return triPointMergeMap_;
348 //- Interpolates cCoords,pCoords. Takes the original fields
349 // used to create the iso surface.
350 template <class Type>
351 tmp<Field<Type> > interpolate
353 const scalarField& cVals,
354 const scalarField& pVals,
355 const Field<Type>& cCoords,
356 const Field<Type>& pCoords
359 //- Interpolates cCoords,pCoords.
360 template <class Type>
361 tmp<Field<Type> > interpolate
363 const Field<Type>& cCoords,
364 const Field<Type>& pCoords
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 } // End namespace Foam
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 # include "isoSurfaceCellTemplates.C"
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 // ************************************************************************* //