initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / triSurface / surfaceFeatures / surfaceFeatures.H
blobf35acbeea1cfe4b8bd2dd40e398a45dbae3aa36e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::surfaceFeatures
28 Description
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
43 SourceFiles
44     surfaceFeatures.C
46 \*---------------------------------------------------------------------------*/
48 #ifndef surfaceFeatures_H
49 #define surfaceFeatures_H
51 #include "pointField.H"
52 #include "Map.H"
53 #include "HashSet.H"
54 #include "pointIndexHit.H"
55 #include "edgeList.H"
56 #include "typeInfo.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 namespace Foam
63 // Forward declaration of classes
64 class triSurface;
66 /*---------------------------------------------------------------------------*\
67                            Class surfaceFeatures Declaration
68 \*---------------------------------------------------------------------------*/
70 class surfaceFeatures
72 public:
74         enum edgeStatus
75         {
76             NONE,
77             REGION,
78             EXTERNAL,
79             INTERNAL
80         };
83 private:
85     //- label and scalar; used in path walking
86     class labelScalar
87     {
88     public:
89         label n_;
90         scalar len_;
92         labelScalar(const label n, const scalar len)
93         :
94             n_(n),
95             len_(len)
96         {}
97     };
100     // Private data
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
124         (
125             const point& start,
126             const point& end,
127             const point& sample
128         );
131         //- Construct feature points where more than 2 feature edges meet
132         void calcFeatPoints(const List<edgeStatus>&);
134         //- Choose next unset feature edge.
135         label nextFeatEdge
136         (
137             const List<edgeStatus>& edgeStat,
138             const labelList& featVisited,
139             const label unsetVal,
140             const label prevEdgeI,
141             const label vertI
142         ) const;
144         //- Walk connected feature edges. Marks edges in featVisited.
145         labelScalar walkSegment
146         (
147             const bool mark,
148             const List<edgeStatus>& edgeStat,
149             const label startEdgeI,
150             const label startPointI,
151             const label currentFeatI,
152             labelList& featVisited
153         );
155 public:
157     ClassName("surfaceFeatures");
159     // Constructors
161         //- Construct from surface
162         surfaceFeatures(const triSurface&);
164         //- Construct from components
165         surfaceFeatures
166         (
167             const triSurface&,
168             const labelList& featurePoints,
169             const labelList& featureEdges,
170             const label externalStart,
171             const label internalStart
172         );
174         //- Construct from surface, angle and min cumulative length and/or
175         //  number of elements
176         surfaceFeatures
177         (
178             const triSurface&,
179             const scalar includedAngle,
180             const scalar minLen = 0,
181             const label minElems = 0
182         );
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&);
194     // Member Functions
196         // Access
198             inline const triSurface& surface() const
199             {
200                 return surf_;
201             }
203             //- Return feature point list
204             inline const labelList& featurePoints() const
205             {
206                 return featurePoints_;
207             }
209             //- Return feature edge list
210             inline const labelList& featureEdges() const
211             {
212                 return featureEdges_;
213             }
215             //- start of external edges
216             inline label externalStart() const
217             {
218                 return externalStart_;
219             }
221             //- start of internal edges
222             inline label internalStart() const
223             {
224                 return internalStart_;
225             }
227             //- Return number of region edges
228             inline label nRegionEdges() const
229             {
230                 return externalStart_;
231             }
233             //- Return number of external edges
234             inline label nExternalEdges() const
235             {
236                 return internalStart_ - externalStart_;
237             }
239             //- Return number of internal edges
240             inline label nInternalEdges() const
241             {
242                 return featureEdges_.size() - internalStart_;
243             }
245             //- Helper function: select a subset of featureEdges_
246             labelList selectFeatureEdges
247             (
248                 const bool regionEdges,
249                 const bool externalEdges,
250                 const bool internalEdges
251             ) const;
254         // Edit
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>&);
270         // Find
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
277             (
278                 const labelList& selectedPoints,
279                 const pointField& samples,
280                 const scalarField& maxDist
281             ) const;
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
289             (
290                 const labelList& selectedEdges,
291                 const pointField& samples,
292                 const scalarField& sampleDist,
293                 const scalarField& maxDist,
294                 const scalar minSampleDist = 0.1
295             ) const;
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
301             (
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
309             ) const;
312             //- Find nearest surface edge (out of selectedEdges) for
313             //  each sample point.
314             //  Sets:
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
319             void nearestSurfEdge
320             (
321                 const labelList& selectedEdges,
322                 const pointField& samples,
323                 const vector& searchSpan,   // search span
324                 labelList& edgeLabel,
325                 labelList& edgeEndPoint,
326                 pointField& edgePoint
327             ) const;
330             //- Find nearest surface edge (out of selectedEdges) for each
331             // sample edge.
332             //  Sets:
333             //  - edgeLabel         : label of surface edge.
334             //  - pointOnEdge       : exact position of nearest point on edge.
335             //  - pointOnFeature    : exact position on sample edge.
336             void nearestSurfEdge
337             (
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
347             ) const;
350         // Write
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;
364     // Member Operators
366         void operator=(const surfaceFeatures&);
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 } // End namespace Foam
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 #endif
380 // ************************************************************************* //