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/>.
26 \*---------------------------------------------------------------------------*/
28 #include "meshOctree.H"
31 #include "demandDrivenData.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 // Construct from surface
47 meshOctree::meshOctree(const triSurf& ts, const bool isQuadtree)
52 initialCubePtr_(NULL),
53 initialCubeRotation_(0),
55 isRootInitialised_(false),
59 regularityPositions_(),
62 isQuadtree_(isQuadtree)
64 createInitialOctreeBox();
66 setOctantVectorsAndPositions();
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
71 meshOctree::~meshOctree()
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 void meshOctree::setOctantVectorsAndPositions()
78 octantVectors_[0] = Vector<label>(-1, -1, -1);
79 octantVectors_[1] = Vector<label>(1, -1, -1);
80 octantVectors_[2] = Vector<label>(-1, 1, -1);
81 octantVectors_[3] = Vector<label>(1, 1, -1);
82 octantVectors_[4] = Vector<label>(-1, -1, 1);
83 octantVectors_[5] = Vector<label>(1, -1, 1);
84 octantVectors_[6] = Vector<label>(-1, 1, 1);
85 octantVectors_[7] = Vector<label>(1, 1, 1);
88 Info << "Octant vectors " << octantVectors_ << endl;
91 //- set regularity positions
92 //- neighbours over faces
93 regularityPositions_[0] = meshOctreeCubeCoordinates(-1, 0, 0, 0);
94 regularityPositions_[1] = meshOctreeCubeCoordinates(1, 0, 0, 0);
95 regularityPositions_[2] = meshOctreeCubeCoordinates(0, -1, 0, 0);
96 regularityPositions_[3] = meshOctreeCubeCoordinates(0, 1, 0, 0);
97 regularityPositions_[4] = meshOctreeCubeCoordinates(0, 0, -1, 0);
98 regularityPositions_[5] = meshOctreeCubeCoordinates(0, 0, 1, 0);
100 //- neighbours over edges
101 //- edges in x-direction
102 regularityPositions_[6] = meshOctreeCubeCoordinates(0, -1, -1, 0);
103 regularityPositions_[7] = meshOctreeCubeCoordinates(0, 1, -1, 0);
104 regularityPositions_[8] = meshOctreeCubeCoordinates(0, -1, 1, 0);
105 regularityPositions_[9] = meshOctreeCubeCoordinates(0, 1, 1, 0);
107 //- edges in y-direction
108 regularityPositions_[10] = meshOctreeCubeCoordinates(-1, 0, -1, 0);
109 regularityPositions_[11] = meshOctreeCubeCoordinates(1, 0, -1, 0);
110 regularityPositions_[12] = meshOctreeCubeCoordinates(-1, 0, 1, 0);
111 regularityPositions_[13] = meshOctreeCubeCoordinates(1, 0, 1, 0);
113 //- edges in z-direction
114 regularityPositions_[14] = meshOctreeCubeCoordinates(-1, -1, 0, 0);
115 regularityPositions_[15] = meshOctreeCubeCoordinates(1, -1, 0, 0);
116 regularityPositions_[16] = meshOctreeCubeCoordinates(-1, 1, 0, 0);
117 regularityPositions_[17] = meshOctreeCubeCoordinates(1, 1, 0, 0);
119 //- neighbours over vertices
120 regularityPositions_[18] = meshOctreeCubeCoordinates(-1, -1, -1, 0);
121 regularityPositions_[19] = meshOctreeCubeCoordinates(1, -1, -1, 0);
122 regularityPositions_[20] = meshOctreeCubeCoordinates(-1, 1, -1, 0);
123 regularityPositions_[21] = meshOctreeCubeCoordinates(1, 1, -1, 0);
124 regularityPositions_[22] = meshOctreeCubeCoordinates(-1, -1, 1, 0);
125 regularityPositions_[23] = meshOctreeCubeCoordinates(1, -1, 1, 0);
126 regularityPositions_[24] = meshOctreeCubeCoordinates(-1, 1, 1, 0);
127 regularityPositions_[25] = meshOctreeCubeCoordinates(1, 1, 1, 0);
130 Info << "Regularity positions " << regularityPositions_ << endl;
133 //- set vrtLeavesPos_
134 for(label vrtI=0;vrtI<8;++vrtI)
136 FixedList<label, 3> vc(0);
146 Info << "Vert " << vrtI << " vc " << vc << endl;
149 for(label i=0;i<8;++i)
151 FixedList<label, 3> pos;
153 for(label j=0;j<3;++j)
155 if( vc[j] == 0 && octantVectors_[i][j] == 1 )
159 else if( vc[j] == 1 && octantVectors_[i][j] == 1 )
165 pos[j] = vc[j] + octantVectors_[i][j];
169 vrtLeavesPos_[vrtI][i] =
170 meshOctreeCubeCoordinates
181 Info << "vrtLeavesPos_ " << vrtLeavesPos_ << endl;
185 void meshOctree::createInitialOctreeBox()
187 //- create initial octree box
188 boundBox bb(surface_.points());
189 const point& min_ = bb.min();
190 const point& max_ = bb.max();
192 const point c = (max_ + min_) / 2.0;
193 scalar cs = 1.5 * (max_.x() - min_.x()) / 2.0;
194 if( cs < (1.5 * (max_.y() - min_.y()) / 2.0) )
196 cs = 1.5 * (max_.y() - min_.y()) / 2.0;
198 if( cs < (1.5 * (max_.z() - min_.z()) / 2.0) )
200 cs = 1.5 * (max_.z() - min_.z()) / 2.0;
203 //- create root box and initial cube
204 rootBox_ = boundBox(c - point(cs, cs, cs), c + point(cs, cs, cs));
206 if( Pstream::parRun() )
208 reduce(rootBox_.min(), minOp<point>());
209 reduce(rootBox_.max(), maxOp<point>());
212 //- allocate data slots
214 if( omp_get_num_procs() > 0 )
216 dataSlots_.setSize(omp_get_num_procs());
220 dataSlots_.setSize(1);
223 dataSlots_.setSize(1);
226 meshOctreeSlot* slotPtr = &dataSlots_[0];
230 slotPtr->cubes_.append
234 meshOctreeCubeCoordinates(0, 0, 0, 0),
242 slotPtr->cubes_.append
246 meshOctreeCubeCoordinates(0, 0, -10, 0),
253 initialCubePtr_ = &slotPtr->cubes_[0];
256 leaves_[0] = initialCubePtr_;
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace Foam
263 // ************************************************************************* //