Fixed URL for libccmio-2.6.1 (bug report #5 by Thomas Oliveira)
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / octrees / meshOctree / meshOctree.H
blob0d88443cce6857a0a74557eb0cf2cc026e66a1c9
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 Class
25     meshOctree
27 Description
28     Octree for mesh generation
30 SourceFiles
31     meshOctree.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef meshOctree_H
36 #define meshOctree_H
38 #include "DynList.H"
39 #include "meshOctreeSlot.H"
40 #include "meshOctreeCube.H"
41 #include "patchRefinementList.H"
42 #include "Pair.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declarations
50 class triSurf;
52 /*---------------------------------------------------------------------------*\
53                            Class meshOctree Declaration
54 \*---------------------------------------------------------------------------*/
56 class meshOctree
58     // Private data
59         //- Reference to surface to work on
60         const triSurf& surface_;
62         //- neighbouring processors which can exchange data with the current one
63         //- this is only used in case of parallel calculations
64         labelList neiProcs_;
66         //- this list contains the first the last octree box coordinates on
67         //- a neighbour processor. They are used for parallel runs when the
68         //- leaves are sorted in Morton's Z-order
69         List<Pair<meshOctreeCubeCoordinates> > neiRange_;
71         //- Root cube of the octree structure
72         meshOctreeCube* initialCubePtr_;
73         label initialCubeRotation_;
74         boundBox rootBox_;
75         bool isRootInitialised_;
77         //- octree search range
78         scalar searchRange_;
80         //- vectors pointing into each octant
81         //- they are useful during creation of vertex labels
82         FixedList<Vector<label>, 8> octantVectors_;
83         FixedList<FixedList<meshOctreeCubeCoordinates, 8>, 8> vrtLeavesPos_;
84         FixedList<meshOctreeCubeCoordinates, 26> regularityPositions_;
86         //- List of slots containing data generated by each processor
87         List<meshOctreeSlot> dataSlots_;
89         //- list of cubes which are leaves of the octree
90         LongList<meshOctreeCube*> leaves_;
92         //- a flag whether is true if is it a quadtree
93         const bool isQuadtree_;
95     // Private member functions
96         //- set data needed for finding neighbours
97         void setOctantVectorsAndPositions();
99         //- create initial octree box
100         void createInitialOctreeBox();
102         //- return leaf cube for the given position
103         meshOctreeCube* findCubeForPosition
104         (
105             const meshOctreeCubeCoordinates&
106         ) const;
108         //- find leaves contained in the box
109         void findLeavesContainedInBox
110         (
111             const boundBox&,
112             DynList<const meshOctreeCube*, 256>&
113         ) const;
115     // Private copy constructor
116         //- Disallow default bitwise copy construct
117         meshOctree(const meshOctree&);
119         //- Disallow default bitwise assignment
120         void operator=(const meshOctree&);
122 public:
124     friend class meshOctreeModifier;
126     // Constructors
128         //- Construct from surface
129         meshOctree(const triSurf&, const bool isQuadtree = false);
131     // Destructor
133         ~meshOctree();
136     // Member Functions
138         //- find a cube containing the vertex
139         label findLeafContainingVertex(const point&) const;
141         //- find leaves within the given range from the given point
142         void findLeavesInSphere
143         (
144             const point&,
145             const scalar,
146             DynList<label>&
147         ) const;
149         //- is octree a quadtree or an octree
150         inline bool isQuadtree() const;
152         //- return octant vectors
153         inline const FixedList<Vector<label>, 8>& octantVectors() const;
155         //- return leaves of the octree
156         inline label numberOfLeaves() const;
157         inline const meshOctreeCubeBasic& returnLeaf(const label) const;
158         inline short leafAtProc(const label) const;
159         void findBoundaryPatchesForLeaf(const label, DynList<label>&) const;
160         inline bool hasContainedTriangles(const label) const;
161         inline void containedTriangles(const label, DynList<label>&) const;
162         inline bool hasContainedEdges(const label) const;
163         inline void containedEdges(const label, DynList<label>&) const;
166         //- checks if the point is inside or outside the surface
167         bool isPointInside(const point&) const;
169         //- find nearest surface point for vertex and its region
170         void findNearestSurfacePoint
171         (
172             point& nearest,
173             scalar& distSq,
174             label& nearestTriangle,
175             label& region,
176             const point& p
177         ) const;
179         //- find nearest surface point for vertex in a given region
180         void findNearestSurfacePointInRegion
181         (
182             point& nearest,
183             scalar& distSq,
184             label& nearestTriangle,
185             const label region,
186             const point& p
187         ) const;
189         //- find nearest feature-edges vertex to a given vertex
190         bool findNearestEdgePoint
191         (
192             point& edgePoint,
193             scalar& distSq,
194             label& nearestEdge,
195             const point& p,
196             const DynList<label>& regions
197         ) const;
199         bool findNearestPointToEdge
200         (
201             point& nearest,
202             scalar& distSq,
203             label& nearestEdge,
204             const FixedList<point, 2>& edgePoints,
205             const FixedList<label, 2>& edgePointRegions
206         ) const;
208         //- find nearest corner point
209         bool findNearestCorner
210         (
211             point& nearest,
212             scalar& distSq,
213             label& nearestPoint,
214             const point& p,
215             const DynList<label>& patches
216         ) const;
218         //- find the nearest vertex to the given patches
219         bool findNearestPointToPatches
220         (
221             point& nearest,
222             scalar& distSq,
223             const point& p,
224             const DynList<label>& patches,
225             const scalar tol = 1e-4
226         ) const;
228         //- return a reference to the surface
229         inline const triSurf& surface() const;
231         //- find a neighbour over a cube's node
232         label findNeighbourOverNode
233         (
234             const meshOctreeCubeCoordinates&,
235             const label nodeI
236         ) const;
238         //- find neighbours over a cube's edge
239         void findNeighboursOverEdge
240         (
241             const meshOctreeCubeCoordinates&,
242             const label eI,
243             DynList<label>& neighbourLeaves
244         ) const;
246         //- find neighbours over a leaf cube face in the given direction
247         void findNeighboursInDirection
248         (
249             const meshOctreeCubeCoordinates&,
250             const label dir,
251             DynList<label>& neighbourLeaves
252         ) const;
254         //- find neighbour leaf cubes over all faces
255         void findNeighboursForLeaf
256         (
257             const meshOctreeCubeCoordinates&,
258             DynList<label>& neighbourLeaves
259         ) const;
261         //- find neighbour leaves over nodes, edges and faces
262         void findAllLeafNeighbours
263         (
264             const meshOctreeCubeCoordinates&,
265             DynList<label>& neighbourLeaves
266         ) const;
268         //- find neighbours over a cube's node
269         inline label findNeighbourOverNode
270         (
271             const label leafI,
272             const label nodeI
273         ) const;
275         //- find neighbours over a cube's edge
276         inline void findNeighboursOverEdge
277         (
278             const label leafI,
279             const label eI,
280             DynList<label>& neighbourLeaves
281         ) const;
283         //- find neighbouring leaves of a leaf cube
284         inline void findNeighboursInDirection
285         (
286             const label leafI,
287             const label dir,
288             DynList<label>&
289         ) const;
291         //- find neighbours over faces
292         inline void findNeighboursForLeaf
293         (
294             const label,
295             DynList<label>&
296         ) const;
298         //- find neighbours over nodes, edges and faces
299         inline void findAllLeafNeighbours
300         (
301             const label,
302             DynList<label>&
303         ) const;
305         //- return leaf cube for the given position
306         label findLeafLabelForPosition
307         (
308             const meshOctreeCubeCoordinates&
309         ) const;
311         //- find neighbouring leaves of a vertex
312         void findLeavesForCubeVertex
313         (
314             const label,
315             const direction,
316             FixedList<label, 8>&
317         ) const;
319         //- find all leaves contained within the given boundBox
320         void findLeavesContainedInBox(const boundBox&, labelList&) const;
321         void findLeavesContainedInBox(const boundBox&, DynList<label>&) const;
323         void findEdgesInBox(const boundBox&, DynList<label>&) const;
324         void findTrianglesInBox(const boundBox&, DynList<label>&) const;
326         //- return rootBox
327         inline const boundBox& rootBox() const;
329         //- return positions which need to be searched
330         //- to achieve 1-irregular octree
331         inline const FixedList<meshOctreeCubeCoordinates, 26>&
332         regularityPositions() const;
334         //- return positions to find the leaves at each cube node
335         inline const FixedList<FixedList<meshOctreeCubeCoordinates, 8>, 8>&
336         positionsOfLeavesAtNodes() const;
338         //- exchange requests with other processors generating the octree
339         void exchangeRequestsWithNeighbourProcessors
340         (
341             const LongList<meshOctreeCubeCoordinates>& dataToSend,
342             LongList<meshOctreeCubeCoordinates>& dataToReceive
343         ) const;
345         //- exchange requests with other processors generating the octree
346         void exchangeRequestsWithNeighbourProcessors
347         (
348             const LongList<meshOctreeCubeCoordinates>& dataToSend,
349             const LongList<scalar>& rangesToSend,
350             LongList<meshOctreeCubeCoordinates>& dataToReceive,
351             LongList<scalar>& receivedRanges
352         ) const;
354         //- neighbour processors of the current one
355         inline const labelList& neiProcs() const;
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 } // End namespace Foam
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 #include "meshOctreeI.H"
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 #endif
371 // ************************************************************************* //