Forward compatibility: flex
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / triSurfaceTools / triSurfaceDetectFeatureEdges / triSurfaceDetectFeatureEdgesFunctions.C
blob635a20db0af7396923f900bc0ee8b825a31dc7e2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9     This file is part of cfMesh.
11     cfMesh 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     cfMesh 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.
21     You should have received a copy of the GNU General Public License
22     along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "triSurfaceDetectFeatureEdges.H"
29 #include "helperFunctions.H"
30 #include "demandDrivenData.H"
31 #include "labelPair.H"
33 # ifdef USE_OMP
34 #include <omp.h>
35 # endif
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 namespace Foam
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 void triSurfaceDetectFeatureEdges::detectFeatureEdgesAngleCriterion()
46     const scalar tol = Foam::cos(angleTolerance_*M_PI/180.0);
48     const vectorField& normals = surf_.facetNormals();
50     const VRWGraph& edgeFaces = surf_.edgeFacets();
52     # ifdef USE_OMP
53     # pragma omp parallel for schedule(dynamic, 40)
54     # endif
55     forAll(edgeFaces, edgeI)
56     {
57         const constRow eFaces = edgeFaces[edgeI];
59         if( edgeFaces.sizeOfRow(edgeI) != 2 )
60         {
61             featureEdges_[edgeI] |= 8;
62             continue;
63         }
65         scalar cosAngle =
66             (normals[eFaces[0]] & normals[eFaces[1]]) /
67             (mag(normals[eFaces[0]]) * mag(normals[eFaces[1]]) + VSMALL);
69         //- check the orientation of triangles at this edge
70         //- check the sign of the angle if the orientation  is not consistent
71         const labelledTri& tri0 = surf_[edgeFaces(edgeI, 0)];
72         const labelledTri& tri1 = surf_[edgeFaces(edgeI, 1)];
73         DynList<labelPair> sharedIndices;
74         forAll(tri0, i)
75         {
76             forAll(tri1, j)
77             {
78                 if( tri0[i] == tri1[j] )
79                     sharedIndices.append(labelPair(i, j));
80             }
81         }
83         if( sharedIndices.size() == 2 )
84         {
85             const labelPair& pair0 = sharedIndices[0];
86             const labelPair& pair1 = sharedIndices[1];
87             if( ((pair0.first() + 1) % 3) == pair1.first() )
88             {
89                 if( (pair0.second() + 1) % 3 == pair1.second() )
90                     cosAngle *= -1.0;
91             }
92             else
93             {
94                 if( (pair1.second() + 1) % 3 == pair0.second() )
95                     cosAngle *= -1.0;
96             }
97         }
99         if( cosAngle < tol )
100             featureEdges_[edgeI] |= 1;
101     }
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 } // End namespace Foam
108 // ************************************************************************* //