meshOctreeInsideCalculations.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "meshOctree.H"
29 #include "triSurf.H"
30 #include "helperFunctions.H"
31 #include "boundBox.H"
32 
33 //#define DEBUGSearch
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 bool meshOctree::isPointInside(const point& p) const
43 {
44  # ifdef DEBUGSearch
45  Info << "Checking inside/outside for vertex " << p << endl;
46  # endif
47  const label cLabel = findLeafContainingVertex(p);
48 
49  if( cLabel >= 0 )
50  {
51  if( returnLeaf(cLabel).cubeType() & meshOctreeCubeBasic::INSIDE )
52  {
53  return true;
54  }
55  }
56 
57  return false;
58 }
59 
60 void meshOctree::findEdgesInBox(const boundBox& bb, DynList<label>& edges) const
61 {
63  findLeavesContainedInBox(bb, neighbours);
64 
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()));
69 
70  edges.clear();
71  forAll(neighbours, neiI)
72  {
73  const meshOctreeCube& oc = *neighbours[neiI];
74 
75  if( !oc.hasContainedEdges() || !oc.isLeaf() )
76  continue;
77 
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 =
85  (
86  points[e[0]],
87  points[e[1]],
88  c
89  );
90 
91  if( magSqr(p - c) < dSq )
92  edges.append(ce(ceI, i));
93  }
94  }
95 }
96 
98 (
99  const boundBox& bb,
100  DynList<label>& triaLabels
101 ) const
102 {
104  findLeavesContainedInBox(bb, neighbours);
105 
106  const point c = (bb.min() + bb.max()) / 2.0;
107  const scalar dSq = Foam::sqr(0.5 * (bb.max().x() - bb.min().x()));
108 
109  triaLabels.clear();
110  forAll(neighbours, neiI)
111  {
112  const meshOctreeCube& oc = *neighbours[neiI];
113 
114  if( !oc.hasContainedElements() || !oc.isLeaf() )
115  continue;
116 
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);
122 
123  const point p = help::nearestPointOnTheTriangle(tI, surface_, c);
124  if( Foam::magSqr(p - c) < dSq )
125  triaLabels.append(tI);
126  }
127  }
128 }
129 
131 (
132  const boundBox& bb,
134 ) const
135 {
136  containedCubes.clear();
137 
138  initialCubePtr_->leavesInBox(rootBox_, bb, containedCubes);
139 }
140 
142 (
143  const boundBox& bb,
144  labelList& containedCubes
145 ) const
146 {
148  findLeavesContainedInBox(bb, cb);
149 
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  }
160 
161  containedCubes.setSize(i);
162 }
163 
165 (
166  const boundBox& bb,
167  DynList<label>& containedCubes
168 ) const
169 {
171  findLeavesContainedInBox(bb, cb);
172 
173  containedCubes.clear();
174 
175  forAll(cb, cI)
176  {
177  if( cb[cI]->isLeaf() )
178  containedCubes.append(cb[cI]->cubeLabel());
179  }
180 }
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 } // End namespace Foam
185 
186 // ************************************************************************* //
triSurf.H
p
p
Definition: pEqn.H:62
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshOctreeCube::containedEdges
label containedEdges() const
Definition: meshOctreeCubeI.H:102
Foam::triSurfPoints::points
const pointField & points() const
access to points
Definition: triSurfPointsI.H:44
Foam::meshOctreeCube::hasContainedElements
bool hasContainedElements() const
return true if the box contains some triangles
Definition: meshOctreeCubeI.H:81
Foam::help::nearestPointOnTheTriangle
point nearestPointOnTheTriangle(const triangle< point, point > &tri, const point &)
find the nearest point on the triangle to the given point
Definition: helperFunctionsGeometryQueriesI.H:475
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::meshOctree::findEdgesInBox
void findEdgesInBox(const boundBox &, DynList< label > &) const
Definition: meshOctreeInsideCalculations.C:60
Foam::meshOctree::findLeavesContainedInBox
void findLeavesContainedInBox(const boundBox &, DynList< const meshOctreeCube *, 256 > &) const
find leaves contained in the box
Definition: meshOctreeInsideCalculations.C:131
meshOctree.H
Foam::meshOctreeCube::hasContainedEdges
bool hasContainedEdges() const
returns true if the box contains some edges
Definition: meshOctreeCubeI.H:94
Foam::LongList< edge >
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::meshOctreeCube::isLeaf
bool isLeaf() const
check if the cube is a leaf
Definition: meshOctreeCubeI.H:63
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
Foam::help::nearestPointOnTheEdgeExact
point nearestPointOnTheEdgeExact(const point &edgePoint0, const point &edgePoint1, const point &p)
find the vertex on the edge nearest to the point p
Definition: helperFunctionsGeometryQueriesI.H:1633
Foam::meshOctreeCube::slotPtr
const meshOctreeSlot * slotPtr() const
return the pointer to the slot containing the cube
Definition: meshOctreeCubeI.H:58
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshOctree::isPointInside
bool isPointInside(const point &) const
checks if the point is inside or outside the surface
Definition: meshOctreeInsideCalculations.C:42
Foam::meshOctree::findTrianglesInBox
void findTrianglesInBox(const boundBox &, DynList< label > &) const
Definition: meshOctreeInsideCalculations.C:98
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList< label >
Foam::meshOctreeCubeBasic::INSIDE
@ INSIDE
Definition: meshOctreeCubeBasic.H:91
boundBox.H
Foam::meshOctreeSlot::containedEdges_
VRWGraph containedEdges_
feature edges contained in an octree cube
Definition: meshOctreeSlot.H:65
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::meshOctreeSlot::containedTriangles_
VRWGraph containedTriangles_
surface triangles contained in an octree cube
Definition: meshOctreeSlot.H:62
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::meshOctree::findLeafContainingVertex
label findLeafContainingVertex(const point &) const
find a cube containing the vertex
Definition: meshOctreeNeighbourSearches.C:42
helperFunctions.H
Foam::meshOctree::surface_
const triSurf & surface_
Reference to surface to work on.
Definition: meshOctree.H:59
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::meshOctreeCube
Definition: meshOctreeCube.H:56
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::triSurfAddressing::edges
const LongList< edge > & edges() const
return edges
Definition: triSurfAddressingI.H:61
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::meshOctreeCube::containedElements
label containedElements() const
Definition: meshOctreeCubeI.H:89
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::meshOctree::returnLeaf
const meshOctreeCubeBasic & returnLeaf(const label) const
Definition: meshOctreeI.H:60
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::DynList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: DynListI.H:279
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304