1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A surface formed by the iso value.
30 After "Polygonising A Scalar Field Using Tetrahedrons", Paul Bourke
32 "Regularised Marching Tetrahedra: improved iso-surface extraction",
33 G.M. Treece, R.W. Prager and A.H. Gee.
35 See isoSurface. This is a variant which does tetrahedrisation from
36 triangulation of face to cell centre instead of edge of face to two
37 neighbouring cell centres. This gives much lower quality triangles
38 but they are local to a cell.
43 \*---------------------------------------------------------------------------*/
45 #ifndef isoSurfaceCell_H
46 #define isoSurfaceCell_H
48 #include "triSurface.H"
49 #include "labelPair.H"
50 #include "pointIndexHit.H"
51 #include "PackedBoolList.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 /*---------------------------------------------------------------------------*\
61 Class isoSurfaceCell Declaration
62 \*---------------------------------------------------------------------------*/
72 NEARFIRST, // intersection close to e.first()
73 NEARSECOND, // ,, e.second()
74 NOTNEAR // no intersection
80 SPHERE, // all edges to cell centre cut
86 const polyMesh& mesh_;
88 //- isoSurfaceCell value
91 //- When to merge points
92 const scalar mergeDistance_;
94 //- Whether cell might be cut
95 List<cellCutType> cellCutType_;
97 //- Estimated number of cut cells
100 //- For every triangle the original cell in mesh
101 labelList meshCells_;
103 //- For every unmerged triangle point the point in the triSurface
104 labelList triPointMergeMap_;
107 // Private Member Functions
109 //- Get location of iso value as fraction inbetween s0,s1
116 //List<triFace> triangulate(const face& f) const;
118 //- Determine whether cell is cut
119 cellCutType calcCutType
121 const PackedBoolList&,
122 const scalarField& cellValues,
123 const scalarField& pointValues,
129 const PackedBoolList&,
130 const scalarField& cellValues,
131 const scalarField& pointValues
134 static labelPair findCommonPoints
140 static point calcCentre(const triSurface&);
142 static pointIndexHit collapseSurface
144 pointField& localPoints,
145 DynamicList<labelledTri, 64>& localTris
148 //- Determine per cc whether all near cuts can be snapped to single
152 const PackedBoolList& isTet,
153 const scalarField& cVals,
154 const scalarField& pVals,
155 DynamicList<point>& triPoints,
159 //- Generate triangles for face connected to pointI
162 const scalarField& cellValues,
163 const scalarField& pointValues,
167 DynamicList<point, 64>& localTriPoints
170 //- Generate triangles for tet connected to pointI
173 const scalarField& pointValues,
176 DynamicList<point, 64>& localTriPoints
179 //- Determine per point whether all near cuts can be snapped to single
181 void calcSnappedPoint
183 const PackedBoolList& isBoundaryPoint,
184 const PackedBoolList& isTet,
185 const scalarField& cVals,
186 const scalarField& pVals,
187 DynamicList<point>& triPoints,
188 labelList& snappedPoint
191 //- Generate single point by interpolation or snapping
195 const DynamicList<Type>& snappedPoints,
205 void generateTriPoints
207 const DynamicList<Type>& snapped,
220 DynamicList<Type>& points
224 void generateTriPoints
226 const scalarField& cVals,
227 const scalarField& pVals,
229 const Field<Type>& cCoords,
230 const Field<Type>& pCoords,
232 const DynamicList<Type>& snappedPoints,
233 const labelList& snappedCc,
234 const labelList& snappedPoint,
236 DynamicList<Type>& triPoints,
237 DynamicList<label>& triMeshCells
240 triSurface stitchTriPoints
242 const bool checkDuplicates,
243 const List<point>& triPoints,
244 labelList& triPointReverseMap, // unmerged to merged point
245 labelList& triMap // merged to unmerged triangle
248 //- Check single triangle for (topological) validity
249 static bool validTri(const triSurface&, const label);
251 //- Determine edge-face addressing
254 const triSurface& surf,
255 List<FixedList<label, 3> >& faceEdges,
256 labelList& edgeFace0,
257 labelList& edgeFace1,
258 Map<labelList>& edgeFacesRest
261 //- Determine orientation
262 static void walkOrientation
264 const triSurface& surf,
265 const List<FixedList<label, 3> >& faceEdges,
266 const labelList& edgeFace0,
267 const labelList& edgeFace1,
268 const label seedTriI,
273 static void orientSurface
276 const List<FixedList<label, 3> >& faceEdges,
277 const labelList& edgeFace0,
278 const labelList& edgeFace1,
279 const Map<labelList>& edgeFacesRest
282 //- Is triangle (given by 3 edges) not fully connected?
283 static bool danglingTriangle
285 const FixedList<label, 3>& fEdges,
286 const labelList& edgeFace1
289 //- Mark all non-fully connected triangles
290 static label markDanglingTriangles
292 const List<FixedList<label, 3> >& faceEdges,
293 const labelList& edgeFace0,
294 const labelList& edgeFace1,
295 const Map<labelList>& edgeFacesRest,
296 boolList& keepTriangles
299 static triSurface subsetMesh
302 const labelList& newToOldFaces,
303 labelList& oldToNewPoints,
304 labelList& newToOldPoints
307 //- Combine all triangles inside a cell into a minimal triangulation
308 void combineCellTriangles();
312 //- Runtime type information
313 TypeName("isoSurfaceCell");
318 //- Construct from dictionary
321 const polyMesh& mesh,
322 const scalarField& cellValues,
323 const scalarField& pointValues,
325 const bool regularise,
326 const scalar mergeTol = 1E-6 // fraction of bounding box
332 //- For every face original cell in mesh
333 const labelList& meshCells() const
338 //- For every unmerged triangle point the point in the triSurface
339 const labelList triPointMergeMap() const
341 return triPointMergeMap_;
345 //- Interpolates cCoords,pCoords. Takes the original fields
346 // used to create the iso surface.
347 template <class Type>
348 tmp<Field<Type> > interpolate
350 const scalarField& cVals,
351 const scalarField& pVals,
352 const Field<Type>& cCoords,
353 const Field<Type>& pCoords
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 } // End namespace Foam
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 # include "isoSurfaceCellTemplates.C"
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 // ************************************************************************* //