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"
30 #include "helperFunctions.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 bool meshOctree::isPointInside(const point& p) const
45 Info << "Checking inside/outside for vertex " << p << endl;
47 const label cLabel = findLeafContainingVertex(p);
51 if( returnLeaf(cLabel).cubeType() & meshOctreeCubeBasic::INSIDE )
60 void meshOctree::findEdgesInBox(const boundBox& bb, DynList<label>& edges) const
62 DynList<const meshOctreeCube*, 256> neighbours;
63 findLeavesContainedInBox(bb, neighbours);
65 const pointField& points = surface_.points();
66 const edgeLongList& sEdges = surface_.edges();
67 const point c = (bb.min() + bb.max()) / 2.0;
68 const scalar dSq = Foam::sqr(0.5 * (bb.max().x() - bb.min().x()));
71 forAll(neighbours, neiI)
73 const meshOctreeCube& oc = *neighbours[neiI];
75 if( !oc.hasContainedEdges() || !oc.isLeaf() )
78 const label ceI = oc.containedEdges();
79 const VRWGraph& ce = oc.slotPtr()->containedEdges_;
82 const edge& e = sEdges[ce(ceI, i)];
84 help::nearestPointOnTheEdgeExact
91 if( magSqr(p - c) < dSq )
92 edges.append(ce(ceI, i));
97 void meshOctree::findTrianglesInBox
100 DynList<label>& triaLabels
103 DynList<const meshOctreeCube*, 256> neighbours;
104 findLeavesContainedInBox(bb, neighbours);
106 const point c = (bb.min() + bb.max()) / 2.0;
107 const scalar dSq = Foam::sqr(0.5 * (bb.max().x() - bb.min().x()));
110 forAll(neighbours, neiI)
112 const meshOctreeCube& oc = *neighbours[neiI];
114 if( !oc.hasContainedElements() || !oc.isLeaf() )
117 const label elI = oc.containedElements();
118 const VRWGraph& ct = oc.slotPtr()->containedTriangles_;
119 forAllRow(ct, elI, i)
121 const label tI = ct(elI, i);
123 const point p = help::nearestPointOnTheTriangle(tI, surface_, c);
124 if( Foam::magSqr(p - c) < dSq )
125 triaLabels.append(tI);
130 void meshOctree::findLeavesContainedInBox
133 DynList<const meshOctreeCube*, 256>& containedCubes
136 containedCubes.clear();
138 initialCubePtr_->leavesInBox(rootBox_, bb, containedCubes);
141 void meshOctree::findLeavesContainedInBox
144 labelList& containedCubes
147 DynList<const meshOctreeCube*, 256> cb;
148 findLeavesContainedInBox(bb, cb);
150 containedCubes.setSize(cb.size());
154 if( cb[cI]->isLeaf() )
156 containedCubes[i] = cb[cI]->cubeLabel();
161 containedCubes.setSize(i);
164 void meshOctree::findLeavesContainedInBox
167 DynList<label>& containedCubes
170 DynList<const meshOctreeCube*, 256> cb;
171 findLeavesContainedInBox(bb, cb);
173 containedCubes.clear();
177 if( cb[cI]->isLeaf() )
178 containedCubes.append(cb[cI]->cubeLabel());
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // ************************************************************************* //