Moving cfMesh into place. Updated contibutors list
[foam-extend-3.2.git] / src / mesh / cfMesh / meshLibrary / utilities / octrees / meshOctree / meshOctreeInsideCalculations.C
blob89d5f105439df75495d31b2898588d326994037c
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 Description
26 \*---------------------------------------------------------------------------*/
28 #include "meshOctree.H"
29 #include "triSurf.H"
30 #include "helperFunctions.H"
31 #include "boundBox.H"
33 //#define DEBUGSearch
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 bool meshOctree::isPointInside(const point& p) const
44     # ifdef DEBUGSearch
45     Info << "Checking inside/outside for vertex " << p << endl;
46     # endif
47     const label cLabel = findLeafContainingVertex(p);
49     if( cLabel >= 0 )
50     {
51         if( returnLeaf(cLabel).cubeType() & meshOctreeCubeBasic::INSIDE )
52         {
53             return true;
54         }
55     }
57     return false;
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()));
70     edges.clear();
71     forAll(neighbours, neiI)
72     {
73         const meshOctreeCube& oc = *neighbours[neiI];
75         if( !oc.hasContainedEdges() || !oc.isLeaf() )
76             continue;
78         const label ceI = oc.containedEdges();
79         const VRWGraph& ce = oc.slotPtr()->containedEdges_;
80         forAllRow(ce, ceI, i)
81         {
82             const edge& e = sEdges[ce(ceI, i)];
83             const point p =
84                 help::nearestPointOnTheEdgeExact
85                 (
86                     points[e[0]],
87                     points[e[1]],
88                     c
89                 );
91             if( magSqr(p - c) < dSq )
92                 edges.append(ce(ceI, i));
93         }
94     }
97 void meshOctree::findTrianglesInBox
99     const boundBox& bb,
100     DynList<label>& triaLabels
101 ) const
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()));
109     triaLabels.clear();
110     forAll(neighbours, neiI)
111     {
112         const meshOctreeCube& oc = *neighbours[neiI];
114         if( !oc.hasContainedElements() || !oc.isLeaf() )
115             continue;
117         const label elI = oc.containedElements();
118         const VRWGraph& ct = oc.slotPtr()->containedTriangles_;
119         forAllRow(ct, elI, i)
120         {
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);
126         }
127     }
130 void meshOctree::findLeavesContainedInBox
132     const boundBox& bb,
133     DynList<const meshOctreeCube*, 256>& containedCubes
134 ) const
136     containedCubes.clear();
138     initialCubePtr_->leavesInBox(rootBox_, bb, containedCubes);
141 void meshOctree::findLeavesContainedInBox
143     const boundBox& bb,
144     labelList& containedCubes
145 ) const
147     DynList<const meshOctreeCube*, 256> cb;
148     findLeavesContainedInBox(bb, cb);
150     containedCubes.setSize(cb.size());
151     label i(0);
152     forAll(cb, cI)
153     {
154         if( cb[cI]->isLeaf() )
155         {
156             containedCubes[i] = cb[cI]->cubeLabel();
157             ++i;
158         }
159     }
161     containedCubes.setSize(i);
164 void meshOctree::findLeavesContainedInBox
166     const boundBox& bb,
167     DynList<label>& containedCubes
168 ) const
170     DynList<const meshOctreeCube*, 256> cb;
171     findLeavesContainedInBox(bb, cb);
173     containedCubes.clear();
175     forAll(cb, cI)
176     {
177         if( cb[cI]->isLeaf() )
178             containedCubes.append(cb[cI]->cubeLabel());
179     }
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // ************************************************************************* //