1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
28 Octree for mesh generation
33 \*---------------------------------------------------------------------------*/
39 #include "meshOctreeSlot.H"
40 #include "meshOctreeCube.H"
41 #include "patchRefinementList.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Forward declarations
52 /*---------------------------------------------------------------------------*\
53 Class meshOctree Declaration
54 \*---------------------------------------------------------------------------*/
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
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_;
75 bool isRootInitialised_;
77 //- octree search range
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
105 const meshOctreeCubeCoordinates&
108 //- find leaves contained in the box
109 void findLeavesContainedInBox
112 DynList<const meshOctreeCube*, 256>&
115 // Private copy constructor
116 //- Disallow default bitwise copy construct
117 meshOctree(const meshOctree&);
119 //- Disallow default bitwise assignment
120 void operator=(const meshOctree&);
124 friend class meshOctreeModifier;
128 //- Construct from surface
129 meshOctree(const triSurf&, const bool isQuadtree = false);
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
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
174 label& nearestTriangle,
179 //- find nearest surface point for vertex in a given region
180 void findNearestSurfacePointInRegion
184 label& nearestTriangle,
189 //- find nearest feature-edges vertex to a given vertex
190 bool findNearestEdgePoint
196 const DynList<label>& regions
199 bool findNearestPointToEdge
204 const FixedList<point, 2>& edgePoints,
205 const FixedList<label, 2>& edgePointRegions
208 //- find nearest corner point
209 bool findNearestCorner
215 const DynList<label>& patches
218 //- find the nearest vertex to the given patches
219 bool findNearestPointToPatches
224 const DynList<label>& patches,
225 const scalar tol = 1e-4
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
234 const meshOctreeCubeCoordinates&,
238 //- find neighbours over a cube's edge
239 void findNeighboursOverEdge
241 const meshOctreeCubeCoordinates&,
243 DynList<label>& neighbourLeaves
246 //- find neighbours over a leaf cube face in the given direction
247 void findNeighboursInDirection
249 const meshOctreeCubeCoordinates&,
251 DynList<label>& neighbourLeaves
254 //- find neighbour leaf cubes over all faces
255 void findNeighboursForLeaf
257 const meshOctreeCubeCoordinates&,
258 DynList<label>& neighbourLeaves
261 //- find neighbour leaves over nodes, edges and faces
262 void findAllLeafNeighbours
264 const meshOctreeCubeCoordinates&,
265 DynList<label>& neighbourLeaves
268 //- find neighbours over a cube's node
269 inline label findNeighbourOverNode
275 //- find neighbours over a cube's edge
276 inline void findNeighboursOverEdge
280 DynList<label>& neighbourLeaves
283 //- find neighbouring leaves of a leaf cube
284 inline void findNeighboursInDirection
291 //- find neighbours over faces
292 inline void findNeighboursForLeaf
298 //- find neighbours over nodes, edges and faces
299 inline void findAllLeafNeighbours
305 //- return leaf cube for the given position
306 label findLeafLabelForPosition
308 const meshOctreeCubeCoordinates&
311 //- find neighbouring leaves of a vertex
312 void findLeavesForCubeVertex
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;
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
341 const LongList<meshOctreeCubeCoordinates>& dataToSend,
342 LongList<meshOctreeCubeCoordinates>& dataToReceive
345 //- exchange requests with other processors generating the octree
346 void exchangeRequestsWithNeighbourProcessors
348 const LongList<meshOctreeCubeCoordinates>& dataToSend,
349 const LongList<scalar>& rangesToSend,
350 LongList<meshOctreeCubeCoordinates>& dataToReceive,
351 LongList<scalar>& receivedRanges
354 //- neighbour processors of the current one
355 inline const labelList& neiProcs() const;
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 } // End namespace Foam
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 #include "meshOctreeI.H"
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 // ************************************************************************* //