FreeFOAM The Cross-Platform CFD Toolkit
octreeDataCell.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::octreeDataCell
26 
27 Description
28  Encapsulation of data needed to search in/for cells.
29 
30  Used to find the cell containing a point (e.g. cell-cell mapping).
31 
32 SourceFiles
33  octreeDataCell.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef octreeDataCell_H
38 #define octreeDataCell_H
39 
40 #include "treeBoundBoxList.H"
41 #include <OpenFOAM/labelList.H>
42 #include <OpenFOAM/linePointRef.H>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 class polyMesh;
51 template<class Type> class octree;
52 
53 /*---------------------------------------------------------------------------*\
54  Class octreeDataCell Declaration
55 \*---------------------------------------------------------------------------*/
56 
58 {
59  // Private data
60 
61  const polyMesh& mesh_;
62 
63  labelList cellLabels_;
64 
65  treeBoundBoxList bbs_;
66 
67 
68 public:
69 
70  // Constructors
71 
72  //- Construct from components.
74  (
75  const polyMesh&,
76  const labelList& cellLabels,
77  const treeBoundBoxList& bbs
78  );
79 
80  //- Construct from mesh. Uses all cells in mesh.
81  octreeDataCell(const polyMesh&);
82 
83 
84  // Member Functions
85 
86  // Access
87 
88  const labelList& cellLabels() const
89  {
90  return cellLabels_;
91  }
92 
93  const polyMesh& mesh() const
94  {
95  return mesh_;
96  }
97 
98  const treeBoundBoxList& allBb() const
99  {
100  return bbs_;
101  }
102 
103  label size() const
104  {
105  return bbs_.size();
106  }
107 
108  // Search
109 
110  //- Get type of sample
111  label getSampleType(octree<octreeDataCell>&, const point&) const;
112 
113  //- Does (bb of) shape at index overlap bb
114  bool overlaps
115  (
116  const label index,
117  const treeBoundBox& sampleBb
118  ) const;
119 
120  //- Does shape at index contain sample
121  bool contains
122  (
123  const label index,
124  const point& sample
125  ) const;
126 
127  //- Segment (from start to end) intersection with shape
128  // at index. If intersects returns true and sets intersectionPoint
129  // BUG: not yet done.
130  bool intersects
131  (
132  const label index,
133  const point& start,
134  const point& end,
135  point& intersectionPoint
136  ) const;
137 
138  //- Sets newTightest to bounding box (and returns true) if
139  // nearer to sample than tightest bounding box. Otherwise
140  // returns false
141  bool findTightest
142  (
143  const label index,
144  const point& sample,
145  treeBoundBox& tightest
146  ) const;
147 
148  //- Given index get unit normal and calculate (numerical) sign
149  // of sample.
150  // Used to determine accuracy of calcNearest or inside/outside.
151  // Note: always returns GREAT since no inside/outside.
152  scalar calcSign
153  (
154  const label index,
155  const point& sample,
156  vector& n
157  ) const;
158 
159  //- Calculates nearest (to sample) point in shape.
160  // Returns point and mag(nearest - sample)
161  scalar calcNearest
162  (
163  const Foam::label index,
164  const Foam::point& sample,
165  point& nearest
166  ) const;
167 
168  //- Calculates nearest (to line segment) point in shape.
169  // Returns distance and both point.
170  scalar calcNearest
171  (
172  const label index,
173  const linePointRef& ln,
174  point& linePt, // nearest point on line
175  point& shapePt // nearest point on shape
176  ) const;
177 
178 
179 
180  // Write
181 
182  // Write shape at index
183  void write(Ostream& os, const label index) const;
184 };
185 
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 } // End namespace Foam
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 
194 #endif
195 
196 // ************************ vim: set sw=4 sts=4 et: ************************ //