FreeFOAM The Cross-Platform CFD Toolkit
treeDataTriSurface.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::treeDataTriSurface
26 
27 Description
28  Encapsulates data for (indexedOc)tree searches on triSurface.
29 
30 SourceFiles
31  treeDataTriSurface.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef treeDataTriSurface_H
36 #define treeDataTriSurface_H
37 
38 #include <triSurface/triSurface.H>
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class treeBoundBox;
47 class treeDataTriSurface;
48 template<class Type> class indexedOctree;
49 
50 /*---------------------------------------------------------------------------*\
51  Class treeDataTriSurface Declaration
52 \*---------------------------------------------------------------------------*/
53 
55 {
56  // Private data
57 
58  const triSurface& surface_;
59 
60 
61  // Private Member Functions
62 
63  //- fast triangle nearest point calculation. Returns point in E0, E1
64  // coordinate system: base + s*E0 + t*E1
65  static scalar nearestCoords
66  (
67  const point& base,
68  const point& E0,
69  const point& E1,
70  const scalar a,
71  const scalar b,
72  const scalar c,
73  const point& P,
74  scalar& s,
75  scalar& t
76  );
77 
78 public:
79 
80  // Declare name of the class and its debug switch
81  ClassName("treeDataTriSurface");
82 
83 
84  // Constructors
85 
86  //- Construct from triSurface. Holds reference.
88 
89 
90  // Member Functions
91 
92  // Access
93 
94  const triSurface& surface() const
95  {
96  return surface_;
97  }
98 
99  label size() const
100  {
101  return surface_.size();
102  }
103 
104  //- Get representative point cloud for all shapes inside
105  // (one point per shape)
106  pointField points() const;
107 
108 
109  // Search
110 
111  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
112  // Only makes sense for closed surfaces.
113  label getVolumeType
114  (
116  const point&
117  ) const;
118 
119  //- Does (bb of) shape at index overlap bb
120  bool overlaps
121  (
122  const label index,
123  const treeBoundBox& sampleBb
124  ) const;
125 
126  //- Calculates nearest (to sample) point in shape.
127  // Returns actual point and distance (squared)
128  void findNearest
129  (
130  const labelList& indices,
131  const point& sample,
132 
133  scalar& nearestDistSqr,
134  label& nearestIndex,
135  point& nearestPoint
136  ) const;
137 
138  //- Calculates nearest (to line) point in shape.
139  // Returns point and distance (squared)
140  void findNearest
141  (
142  const labelList& indices,
143  const linePointRef& ln,
144 
145  treeBoundBox& tightest,
146  label& minIndex,
147  point& linePoint,
148  point& nearestPoint
149  ) const;
150 
151  //- Calculate intersection of triangle with ray. Sets result
152  // accordingly
153  bool intersects
154  (
155  const label index,
156  const point& start,
157  const point& end,
158  point& result
159  ) const;
160 
161 };
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 } // End namespace Foam
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 
171 #endif
172 
173 // ************************ vim: set sw=4 sts=4 et: ************************ //