initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / triSurface / booleanOps / booleanSurface / booleanSurface.H
blobf1ce39aa6e0475322fc16f1747b1ca27aeb593cc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::booleanSurface
28 Description
29     Surface-surface intersection. Given two surfaces construct combined surface.
31     Called 'boolean' since the volume of resulting surface will encompass
32     the volumes of the original surface according to some boolean operation:
33     - all which is in surface1 AND in surface2 (intersection)
34     - all which is in surface1 AND NOT in surface2 ('chop' out surface2)
35     - all which is in surface1 OR in surface2 (union)
37     Algorithm:
38     -# find edge-surface intersection. Class 'surfaceIntersection'.
39     -# combine intersection with both surfaces. Class 'intersectedSurface'.
40     -# subset surfaces upto intersection. The 'side' of the surface to
41        include is based on the faces that can be reached from a
42        user-supplied face index.
43     -# merge surfaces. Only the points on the intersection are shared.
45 SourceFiles
46     booleanSurface.C
48 \*---------------------------------------------------------------------------*/
50 #ifndef booleanSurface_H
51 #define booleanSurface_H
53 #include "triSurface.H"
54 #include "surfaceIntersection.H"
55 #include "typeInfo.H"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 namespace Foam
62 // Forward declaration of classes
63 class triSurfaceSearch;
64 class intersectedSurface;
66 /*---------------------------------------------------------------------------*\
67                            Class booleanSurface Declaration
68 \*---------------------------------------------------------------------------*/
70 class booleanSurface
72     public triSurface
74     // Data types
76         //- Enumeration listing the status of a face (visible/invisible from
77         //  outside)
78         enum sideStat
79         {
80             UNVISITED,
81             OUTSIDE,
82             INSIDE
83         };
85     // Private data
87         //- From new to old face + surface:
88         //     >0 : to face on surface1
89         //     <0 : to face on surface2. Negate and offset by one to get
90         //          face2 (e.g. face2I = -faceMap[]-1)
91         labelList faceMap_;
93     // Private Member Functions
95         //- Check whether subset of faces (from markZones) reaches up to
96         //  the intersection.
97         static void checkIncluded
98         (
99             const intersectedSurface& surf,
100             const labelList& faceZone,
101             const label includedFace
102         );
104         //- Get label in elems of elem.
105         static label index(const labelList& elems, const label elem);
107         //- Find index of edge e in subset edgeLabels.
108         static label findEdge
109         (
110             const edgeList& edges,
111             const labelList& edgeLabels,
112             const edge& e
113         );
115         //- Get index of face in zoneI whose faceCentre is nearest farAwayPoint
116         static label findNearest
117         (
118             const triSurface& surf,
119             const labelList& faceZone,
120             const label zoneI
121         );
123         //- Generate combined patchList (returned). Sets patchMap to map from
124         // surf region numbers into combined patchList
125         static geometricSurfacePatchList mergePatches
126         (
127             const triSurface& surf1,
128             const triSurface& surf2,
129             labelList& patchMap2
130         );
132         //- On edgeI, coming from face prevFace, determines visibility/side of
133         // all the other faces using the edge.
134         static void propagateEdgeSide
135         (
136             const triSurface& surf,
137             const label prevVert0,
138             const label prevFaceI,
139             const label prevState,
140             const label edgeI,
141             labelList& side
142         );
144         //- Given in/outside status of face determines status for all
145         //  neighbouring faces.
146         static void propagateSide
147         (
148             const triSurface& surf,
149             const label prevState,
150             const label faceI,
151             labelList& side
152         );
154 public:
156     ClassName("booleanSurface");
159     // Data types
161         //- Enumeration listing the possible volume operator types
162         enum booleanOpType
163         {
164             OR,     // Union of volumes
165             AND,    // Intersection of volumes
166             XOR,    // Difference of volumes
167             ALL     // Special: does not subset combined surface. (Produces
168                     // multiply connected surface)
169         };
172     // Constructors
174         //- Construct null
175         booleanSurface();
177         //- Construct from surfaces and face labels to keep.
178         //  Walks from provided seed faces without crossing intersection line 
179         //  to determine faces to keep.
180         booleanSurface
181         (
182             const triSurface& surf1,
183             const triSurface& surf2,
184             const surfaceIntersection& inter,
185             const label includeFace1,
186             const label includeFace2
187         );
189         //- Construct from surfaces and operation. Surfaces need to be closed
190         //  for this to make any sense since uses inside/outside to determine
191         //  which part of combined surface to include.
192         booleanSurface
193         (
194             const triSurface& surf1,
195             const triSurface& surf2,
196             const surfaceIntersection& inter,
197             const label booleanOp
198         );
201     // Member Functions
203         //- new to old face map. >0: surface 1 face label. <0: surface 2. Negate
204         //  and subtract 1 to get face label on surface 2.
205         const labelList& faceMap() const
206         {
207             return faceMap_;
208         }
210         bool from1(const label faceI) const
211         {
212             return faceMap_[faceI] >= 0;
213         }
215         bool surf1Face(const label faceI) const
216         {
217             if (!from1(faceI))
218             {
219                 FatalErrorIn("booleanSurface::surf1Face(const label)")
220                     << "face " << faceI << " not from surface 1"
221                     << abort(FatalError);
222             }
223             return faceMap_[faceI];
224         }
226         bool surf2Face(const label faceI) const
227         {
228             if (from1(faceI))
229             {
230                 FatalErrorIn("booleanSurface::surf2Face(const label)")
231                     << "face " << faceI << " not from surface 2"
232                     << abort(FatalError);
233             }
234             return -faceMap_[faceI]-1;
235         }
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 } // End namespace Foam
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 #endif
249 // ************************************************************************* //