FreeFOAM The Cross-Platform CFD Toolkit
surfaceFeatures.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::surfaceFeatures
26 
27 Description
28  Holds feature edges/points of surface.
29 
30  Feature edges are stored in one list and sorted:
31  0 .. externalStart_-1 : region edges
32  externalStart_ .. internalStart_-1 : external edges
33  internalStart_ .. size-1 : internal edges
34 
35 
36  NOTE: angle is included angle, not feature angle and is in degrees.
37  The included angle is the smallest angle between two planes. For coplanar
38  faces it is 180, for straight angles it is 90. To pick up straight edges
39  only use included angle of 91 degrees
40 
41 
42 SourceFiles
43  surfaceFeatures.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef surfaceFeatures_H
48 #define surfaceFeatures_H
49 
50 #include <OpenFOAM/pointField.H>
51 #include <OpenFOAM/Map.H>
52 #include <OpenFOAM/HashSet.H>
54 #include <OpenFOAM/edgeList.H>
55 #include <OpenFOAM/typeInfo.H>
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward declaration of classes
63 class triSurface;
64 
65 /*---------------------------------------------------------------------------*\
66  Class surfaceFeatures Declaration
67 \*---------------------------------------------------------------------------*/
68 
70 {
71 public:
72 
74  {
79  };
80 
81 
82 private:
83 
84  //- label and scalar; used in path walking
85  class labelScalar
86  {
87  public:
88  label n_;
89  scalar len_;
90 
91  labelScalar(const label n, const scalar len)
92  :
93  n_(n),
94  len_(len)
95  {}
96  };
97 
98 
99  // Private data
100 
101  //- Reference to surface
102  const triSurface& surf_;
103 
104  //- Labels of points that are features
105  labelList featurePoints_;
106 
107  //- Labels of edges that are features
108  labelList featureEdges_;
109 
110  //- Start of external edges in featureEdges_
111  label externalStart_;
112 
113  //- Start of internal edges in featureEdges_
114  label internalStart_;
115 
116 
117  // Private Member Functions
118 
119  //- Return nearest point on edge (start..end). Also classify nearest:
120  // index=-1: nearest on mid of edge. index=0:nearest on edge.start()
121  // index=1: nearest on edge.end().
122  static pointIndexHit edgeNearest
123  (
124  const point& start,
125  const point& end,
126  const point& sample
127  );
128 
129 
130  //- Construct feature points where more than 2 feature edges meet
131  void calcFeatPoints(const List<edgeStatus>&);
132 
133  //- Choose next unset feature edge.
134  label nextFeatEdge
135  (
136  const List<edgeStatus>& edgeStat,
137  const labelList& featVisited,
138  const label unsetVal,
139  const label prevEdgeI,
140  const label vertI
141  ) const;
142 
143  //- Walk connected feature edges. Marks edges in featVisited.
144  labelScalar walkSegment
145  (
146  const bool mark,
147  const List<edgeStatus>& edgeStat,
148  const label startEdgeI,
149  const label startPointI,
150  const label currentFeatI,
151  labelList& featVisited
152  );
153 
154 public:
155 
156  ClassName("surfaceFeatures");
157 
158  // Constructors
159 
160  //- Construct from surface
161  surfaceFeatures(const triSurface&);
162 
163  //- Construct from components
165  (
166  const triSurface&,
167  const labelList& featurePoints,
168  const labelList& featureEdges,
169  const label externalStart,
170  const label internalStart
171  );
172 
173  //- Construct from surface, angle and min cumulative length and/or
174  // number of elements
176  (
177  const triSurface&,
178  const scalar includedAngle,
179  const scalar minLen = 0,
180  const label minElems = 0
181  );
182 
183  //- Construct from dictionary
184  surfaceFeatures(const triSurface&, const dictionary& dict);
185 
186  //- Construct from file
187  surfaceFeatures(const triSurface&, const fileName& fName);
188 
189  //- Construct as copy
191 
192 
193  // Member Functions
194 
195  // Access
196 
197  inline const triSurface& surface() const
198  {
199  return surf_;
200  }
201 
202  //- Return feature point list
203  inline const labelList& featurePoints() const
204  {
205  return featurePoints_;
206  }
207 
208  //- Return feature edge list
209  inline const labelList& featureEdges() const
210  {
211  return featureEdges_;
212  }
213 
214  //- start of external edges
215  inline label externalStart() const
216  {
217  return externalStart_;
218  }
219 
220  //- start of internal edges
221  inline label internalStart() const
222  {
223  return internalStart_;
224  }
225 
226  //- Return number of region edges
227  inline label nRegionEdges() const
228  {
229  return externalStart_;
230  }
231 
232  //- Return number of external edges
233  inline label nExternalEdges() const
234  {
235  return internalStart_ - externalStart_;
236  }
237 
238  //- Return number of internal edges
239  inline label nInternalEdges() const
240  {
241  return featureEdges_.size() - internalStart_;
242  }
243 
244  //- Helper function: select a subset of featureEdges_
246  (
247  const bool regionEdges,
248  const bool externalEdges,
249  const bool internalEdges
250  ) const;
251 
252 
253  // Edit
254 
255  //- Find feature edges using provided included angle
256  void findFeatures(const scalar includedAngle);
257 
258  //- Delete small sets of edges. Edges are stringed up and any
259  // string of length < minLen (or nElems < minElems) is deleted.
260  void trimFeatures(const scalar minLen, const label minElems);
261 
262  //- From member feature edges to status per edge.
263  List<edgeStatus> toStatus() const;
264 
265  //- Set from status per edge
266  void setFromStatus(const List<edgeStatus>&);
267 
268 
269  // Find
270 
271  //- Find nearest sample for selected surface points (usually the
272  // set of featurePoints). Return map from index in
273  // samples to surface point. Do not include points that are further
274  // than maxDist away (separate maxDist for every sample)
276  (
277  const labelList& selectedPoints,
278  const pointField& samples,
279  const scalarField& maxDist
280  ) const;
281 
282  //- Find nearest sample for regularly sampled points along the
283  // selected (surface) edges. Return map from sample to edge.
284  // maxDist is distance below which gets snapped.
285  // Edge gets sampled at points sampleDist[sampleI] apart.
286  // (with a maximum of 10 samples per edge)
288  (
289  const labelList& selectedEdges,
290  const pointField& samples,
291  const scalarField& sampleDist,
292  const scalarField& maxDist,
293  const scalar minSampleDist = 0.1
294  ) const;
295 
296  //- Like nearestSamples but now gets nearest point on
297  // sample-edge instead of nearest sample-point itself.
298  // Return map from sample edge to feature edge.
300  (
301  const labelList& selectedEdges,
302  const edgeList& sampleEdges,
303  const labelList& selectedSampleEdges,
304  const pointField& samplePoints,
305  const scalarField& sampleDist,
306  const scalarField& maxDist,
307  const scalar minSampleDist = 0.1
308  ) const;
309 
310 
311  //- Find nearest surface edge (out of selectedEdges) for
312  // each sample point.
313  // Sets:
314  // - edgeLabel : label of surface edge.
315  // - edgePoint : exact position of nearest point on edge.
316  // - edgeEndPoint : -1, 0, 1 depending on whether edgePoint is
317  // on inside/start/end of edge
318  void nearestSurfEdge
319  (
320  const labelList& selectedEdges,
321  const pointField& samples,
322  const vector& searchSpan, // search span
323  labelList& edgeLabel,
324  labelList& edgeEndPoint,
325  pointField& edgePoint
326  ) const;
327 
328 
329  //- Find nearest surface edge (out of selectedEdges) for each
330  // sample edge.
331  // Sets:
332  // - edgeLabel : label of surface edge.
333  // - pointOnEdge : exact position of nearest point on edge.
334  // - pointOnFeature : exact position on sample edge.
335  void nearestSurfEdge
336  (
337  const labelList& selectedEdges,
338  const edgeList& sampleEdges,
339  const labelList& selectedSampleEdges,
340  const pointField& samplePoints,
341  const vector& searchSpan, // search span
342 
343  labelList& edgeLabel, // label of surface edge or -1
344  pointField& pointOnEdge, // point on above edge
345  pointField& pointOnFeature // point on sample edge
346  ) const;
347 
348 
349  // Write
350 
351  //- Write as dictionary
352  void writeDict(Ostream&) const;
353 
354  //- Write as dictionary to file
355  void write(const fileName& fName) const;
356 
357  //- Write to separate OBJ files (region, external, internal edges,
358  // feature points) for visualization
359  void writeObj(const fileName& prefix) const;
360 
361 
362 
363  // Member Operators
364 
365  void operator=(const surfaceFeatures&);
366 
367 
368 };
369 
370 
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 
373 } // End namespace Foam
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #endif
378 
379 // ************************ vim: set sw=4 sts=4 et: ************************ //