1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 //- isoSurfaceCell value
90 //- When to merge points
91 const scalar mergeDistance_;
93 //- Whether cell might be cut
94 List<cellCutType> cellCutType_;
96 //- Estimated number of cut cells
99 //- For every triangle the original cell in mesh
100 labelList meshCells_;
102 //- For every unmerged triangle point the point in the triSurface
103 labelList triPointMergeMap_;
106 // Private Member Functions
108 //- Get location of iso value as fraction inbetween s0,s1
115 //List<triFace> triangulate(const face& f) const;
117 //- Determine whether cell is cut
118 cellCutType calcCutType
120 const PackedBoolList&,
121 const scalarField& cellValues,
122 const scalarField& pointValues,
128 const PackedBoolList&,
129 const scalarField& cellValues,
130 const scalarField& pointValues
133 static labelPair findCommonPoints
139 static point calcCentre(const triSurface&);
141 static pointIndexHit collapseSurface
143 pointField& localPoints,
144 DynamicList<labelledTri, 64>& localTris
147 //- Determine per cc whether all near cuts can be snapped to single
151 const PackedBoolList& isTet,
152 const scalarField& cVals,
153 const scalarField& pVals,
154 DynamicList<point>& triPoints,
158 //- Generate triangles for face connected to pointI
161 const scalarField& cellValues,
162 const scalarField& pointValues,
166 DynamicList<point, 64>& localTriPoints
169 //- Generate triangles for tet connected to pointI
172 const scalarField& pointValues,
175 DynamicList<point, 64>& localTriPoints
178 //- Determine per point whether all near cuts can be snapped to single
180 void calcSnappedPoint
182 const PackedBoolList& isBoundaryPoint,
183 const PackedBoolList& isTet,
184 const scalarField& cVals,
185 const scalarField& pVals,
186 DynamicList<point>& triPoints,
187 labelList& snappedPoint
190 //- Generate single point by interpolation or snapping
194 const DynamicList<Type>& snappedPoints,
204 void generateTriPoints
206 const DynamicList<Type>& snapped,
219 DynamicList<Type>& points
223 void generateTriPoints
225 const scalarField& cVals,
226 const scalarField& pVals,
228 const Field<Type>& cCoords,
229 const Field<Type>& pCoords,
231 const DynamicList<Type>& snappedPoints,
232 const labelList& snappedCc,
233 const labelList& snappedPoint,
235 DynamicList<Type>& triPoints,
236 dynamicLabelList& triMeshCells
239 triSurface stitchTriPoints
241 const bool checkDuplicates,
242 const List<point>& triPoints,
243 labelList& triPointReverseMap, // unmerged to merged point
244 labelList& triMap // merged to unmerged triangle
247 //- Check single triangle for (topological) validity
248 static bool validTri(const triSurface&, const label);
250 //- Determine edge-face addressing
253 const triSurface& surf,
254 List<FixedList<label, 3> >& faceEdges,
255 labelList& edgeFace0,
256 labelList& edgeFace1,
257 Map<labelList>& edgeFacesRest
260 //- Determine orientation
261 static void walkOrientation
263 const triSurface& surf,
264 const List<FixedList<label, 3> >& faceEdges,
265 const labelList& edgeFace0,
266 const labelList& edgeFace1,
267 const label seedTriI,
272 static void orientSurface
275 const List<FixedList<label, 3> >& faceEdges,
276 const labelList& edgeFace0,
277 const labelList& edgeFace1,
278 const Map<labelList>& edgeFacesRest
281 //- Is triangle (given by 3 edges) not fully connected?
282 static bool danglingTriangle
284 const FixedList<label, 3>& fEdges,
285 const labelList& edgeFace1
288 //- Mark all non-fully connected triangles
289 static label markDanglingTriangles
291 const List<FixedList<label, 3> >& faceEdges,
292 const labelList& edgeFace0,
293 const labelList& edgeFace1,
294 const Map<labelList>& edgeFacesRest,
295 boolList& keepTriangles
298 static triSurface subsetMesh
301 const labelList& newToOldFaces,
302 labelList& oldToNewPoints,
303 labelList& newToOldPoints
306 //- Combine all triangles inside a cell into a minimal triangulation
307 void combineCellTriangles();
311 //- Runtime type information
312 TypeName("isoSurfaceCell");
317 //- Construct from dictionary
320 const polyMesh& mesh,
321 const scalarField& cellValues,
322 const scalarField& pointValues,
324 const bool regularise,
325 const scalar mergeTol = 1E-6 // fraction of bounding box
331 //- For every face original cell in mesh
332 const labelList& meshCells() const
337 //- For every unmerged triangle point the point in the triSurface
338 const labelList triPointMergeMap() const
340 return triPointMergeMap_;
344 //- Interpolates cCoords,pCoords. Takes the original fields
345 // used to create the iso surface.
346 template <class Type>
347 tmp<Field<Type> > interpolate
349 const scalarField& cVals,
350 const scalarField& pVals,
351 const Field<Type>& cCoords,
352 const Field<Type>& pCoords
357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 } // End namespace Foam
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 # include "isoSurfaceCellTemplates.C"
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 // ************************************************************************* //