1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Holds feature edges/points of surface.
31 Feature edges are stored in one list and sorted:
32 0 .. externalStart_-1 : region edges
33 externalStart_ .. internalStart_-1 : external edges
34 internalStart_ .. size-1 : internal edges
37 NOTE: angle is included angle, not feature angle and is in degrees.
38 The included angle is the smallest angle between two planes. For coplanar
39 faces it is 180, for straight angles it is 90. To pick up straight edges
40 only use included angle of 91 degrees
46 \*---------------------------------------------------------------------------*/
48 #ifndef surfaceFeatures_H
49 #define surfaceFeatures_H
51 #include "pointField.H"
53 #include "labelHashSet.H"
54 #include "pointIndexHit.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 // Forward declaration of classes
66 /*---------------------------------------------------------------------------*\
67 Class surfaceFeatures Declaration
68 \*---------------------------------------------------------------------------*/
85 //- label and scalar; used in path walking
92 labelScalar(const label n, const scalar len)
102 //- Reference to surface
103 const triSurface& surf_;
105 //- Labels of points that are features
106 labelList featurePoints_;
108 //- Labels of edges that are features
109 labelList featureEdges_;
111 //- Start of external edges in featureEdges_
112 label externalStart_;
114 //- Start of internal edges in featureEdges_
115 label internalStart_;
118 // Private Member Functions
120 //- Return nearest point on edge (start..end). Also classify nearest:
121 // index=-1: nearest on mid of edge. index=0:nearest on edge.start()
122 // index=1: nearest on edge.end().
123 static pointIndexHit edgeNearest
131 //- Construct feature points where more than 2 feature edges meet
132 void calcFeatPoints(const List<edgeStatus>&);
134 //- Choose next unset feature edge.
137 const List<edgeStatus>& edgeStat,
138 const labelList& featVisited,
139 const label unsetVal,
140 const label prevEdgeI,
144 //- Walk connected feature edges. Marks edges in featVisited.
145 labelScalar walkSegment
148 const List<edgeStatus>& edgeStat,
149 const label startEdgeI,
150 const label startPointI,
151 const label currentFeatI,
152 labelList& featVisited
157 ClassName("surfaceFeatures");
161 //- Construct from surface
162 surfaceFeatures(const triSurface&);
164 //- Construct from components
168 const labelList& featurePoints,
169 const labelList& featureEdges,
170 const label externalStart,
171 const label internalStart
174 //- Construct from surface, angle and min cumulative length and/or
175 // number of elements
179 const scalar includedAngle,
180 const scalar minLen = 0,
181 const label minElems = 0
184 //- Construct from dictionary
185 surfaceFeatures(const triSurface&, const dictionary& dict);
187 //- Construct from file
188 surfaceFeatures(const triSurface&, const fileName& fName);
190 //- Construct as copy
191 surfaceFeatures(const surfaceFeatures&);
198 inline const triSurface& surface() const
203 //- Return feature point list
204 inline const labelList& featurePoints() const
206 return featurePoints_;
209 //- Return feature edge list
210 inline const labelList& featureEdges() const
212 return featureEdges_;
215 //- start of external edges
216 inline label externalStart() const
218 return externalStart_;
221 //- start of internal edges
222 inline label internalStart() const
224 return internalStart_;
227 //- Return number of region edges
228 inline label nRegionEdges() const
230 return externalStart_;
233 //- Return number of external edges
234 inline label nExternalEdges() const
236 return internalStart_ - externalStart_;
239 //- Return number of internal edges
240 inline label nInternalEdges() const
242 return featureEdges_.size() - internalStart_;
245 //- Helper function: select a subset of featureEdges_
246 labelList selectFeatureEdges
248 const bool regionEdges,
249 const bool externalEdges,
250 const bool internalEdges
256 //- Find feature edges using provided included angle
257 void findFeatures(const scalar includedAngle);
259 //- Delete small sets of edges. Edges are stringed up and any
260 // string of length < minLen (or nElems < minElems) is deleted.
261 void trimFeatures(const scalar minLen, const label minElems);
263 //- From member feature edges to status per edge.
264 List<edgeStatus> toStatus() const;
266 //- Set from status per edge
267 void setFromStatus(const List<edgeStatus>&);
272 //- Find nearest sample for selected surface points (usually the
273 // set of featurePoints). Return map from index in
274 // samples to surface point. Do not include points that are further
275 // than maxDist away (separate maxDist for every sample)
276 Map<label> nearestSamples
278 const labelList& selectedPoints,
279 const pointField& samples,
280 const scalarField& maxDist
283 //- Find nearest sample for regularly sampled points along the
284 // selected (surface) edges. Return map from sample to edge.
285 // maxDist is distance below which gets snapped.
286 // Edge gets sampled at points sampleDist[sampleI] apart.
287 // (with a maximum of 10 samples per edge)
288 Map<label> nearestSamples
290 const labelList& selectedEdges,
291 const pointField& samples,
292 const scalarField& sampleDist,
293 const scalarField& maxDist,
294 const scalar minSampleDist = 0.1
297 //- Like nearestSamples but now gets nearest point on
298 // sample-edge instead of nearest sample-point itself.
299 // Return map from sample edge to feature edge.
300 Map<pointIndexHit> nearestEdges
302 const labelList& selectedEdges,
303 const edgeList& sampleEdges,
304 const labelList& selectedSampleEdges,
305 const pointField& samplePoints,
306 const scalarField& sampleDist,
307 const scalarField& maxDist,
308 const scalar minSampleDist = 0.1
312 //- Find nearest surface edge (out of selectedEdges) for
313 // each sample point.
315 // - edgeLabel : label of surface edge.
316 // - edgePoint : exact position of nearest point on edge.
317 // - edgeEndPoint : -1, 0, 1 depending on whether edgePoint is
318 // on inside/start/end of edge
321 const labelList& selectedEdges,
322 const pointField& samples,
323 const vector& searchSpan, // search span
324 labelList& edgeLabel,
325 labelList& edgeEndPoint,
326 pointField& edgePoint
330 //- Find nearest surface edge (out of selectedEdges) for each
333 // - edgeLabel : label of surface edge.
334 // - pointOnEdge : exact position of nearest point on edge.
335 // - pointOnFeature : exact position on sample edge.
338 const labelList& selectedEdges,
339 const edgeList& sampleEdges,
340 const labelList& selectedSampleEdges,
341 const pointField& samplePoints,
342 const vector& searchSpan, // search span
344 labelList& edgeLabel, // label of surface edge or -1
345 pointField& pointOnEdge, // point on above edge
346 pointField& pointOnFeature // point on sample edge
352 //- Write as dictionary
353 void writeDict(Ostream&) const;
355 //- Write as dictionary to file
356 void write(const fileName& fName) const;
358 //- Write to separate OBJ files (region, external, internal edges,
359 // feature points) for visualization
360 void writeObj(const fileName& prefix) const;
366 void operator=(const surfaceFeatures&);
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 } // End namespace Foam
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 // ************************************************************************* //