FreeFOAM The Cross-Platform CFD Toolkit
treeDataCell.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::treeDataCell
26 
27 Description
28  Encapsulation of data needed to search in/for cells. Used to find the
29  cell containing a point (e.g. cell-cell mapping).
30 
31 SourceFiles
32  treeDataCell.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef treeDataCell_H
37 #define treeDataCell_H
38 
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of classes
47 class primitiveMesh;
48 template<class Type> class indexedOctree;
49 
50 /*---------------------------------------------------------------------------*\
51  Class treeDataCell Declaration
52 \*---------------------------------------------------------------------------*/
53 
55 {
56  // Private data
57 
58  const primitiveMesh& mesh_;
59 
60  //- Subset of cells to work on
61  const labelList cellLabels_;
62 
63  //- Whether to precalculate and store cell bounding box
64  const bool cacheBb_;
65 
66  //- cell bounding boxes (valid only if cacheBb_)
67  treeBoundBoxList bbs_;
68 
69 
70  // Private Member Functions
71 
72  //- Calculate cell bounding box
73  treeBoundBox calcCellBb(const label cellI) const;
74 
75 public:
76 
77  // Declare name of the class and its debug switch
78  ClassName("treeDataCell");
79 
80 
81  // Constructors
82 
83  //- Construct from mesh and subset of cells.
85  (
86  const bool cacheBb,
87  const primitiveMesh&,
88  const labelList&
89  );
90 
91  //- Construct from mesh. Uses all cells in mesh.
92  treeDataCell(const bool cacheBb, const primitiveMesh&);
93 
94 
95  // Member Functions
96 
97  // Access
98 
99  const labelList& cellLabels() const
100  {
101  return cellLabels_;
102  }
103 
104  const primitiveMesh& mesh() const
105  {
106  return mesh_;
107  }
108 
109 
110  label size() const
111  {
112  return cellLabels_.size();
113  }
114 
115  //- Get representative point cloud for all shapes inside
116  // (one point per shape)
117  pointField points() const;
118 
119 
120  // Search
121 
122  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
123  // Only makes sense for closed surfaces.
124  label getVolumeType
125  (
127  const point&
128  ) const
129  {
131  (
132  "treeDataCell::getVolumeType"
133  "(const indexedOctree<treeDataCell>&, const point&)"
134  );
135  return -1;
136  }
137 
138  //- Does (bb of) shape at index overlap bb
139  bool overlaps
140  (
141  const label index,
142  const treeBoundBox& sampleBb
143  ) const;
144 
145  //- Calculates nearest (to sample) point in shape.
146  // Returns actual point and distance (squared)
147  void findNearest
148  (
149  const labelList& indices,
150  const point& sample,
151 
152  scalar& nearestDistSqr,
153  label& nearestIndex,
154  point& nearestPoint
155  ) const;
156 
157  //- Calculates nearest (to line) point in shape.
158  // Returns point and distance (squared)
159  void findNearest
160  (
161  const labelList& indices,
162  const linePointRef& ln,
163 
164  treeBoundBox& tightest,
165  label& minIndex,
166  point& linePoint,
167  point& nearestPoint
168  ) const
169  {
171  (
172  "treeDataCell::findNearest"
173  "(const labelList&, const linePointRef&, ..)"
174  );
175  }
176 
177  //- Calculate intersection of shape with ray. Sets result
178  // accordingly
179  bool intersects
180  (
181  const label index,
182  const point& start,
183  const point& end,
184  point& result
185  ) const;
186 
187 };
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 
197 #endif
198 
199 // ************************ vim: set sw=4 sts=4 et: ************************ //