OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceFeatures.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::surfaceFeatures
00027 
00028 Description
00029     Holds feature edges/points of surface.
00030 
00031     Feature edges are stored in one list and sorted:
00032         0 .. externalStart_-1               : region edges
00033         externalStart_ .. internalStart_-1  : external edges
00034         internalStart_ .. size-1            : internal edges
00035 
00036 
00037     NOTE: angle is included angle, not feature angle and is in degrees.
00038     The included angle is the smallest angle between two planes. For coplanar
00039     faces it is 180, for straight angles it is 90. To pick up straight edges
00040     only use included angle of 91 degrees
00041 
00042 
00043 SourceFiles
00044     surfaceFeatures.C
00045 
00046 \*---------------------------------------------------------------------------*/
00047 
00048 #ifndef surfaceFeatures_H
00049 #define surfaceFeatures_H
00050 
00051 #include "pointField.H"
00052 #include "Map.H"
00053 #include "HashSet.H"
00054 #include "pointIndexHit.H"
00055 #include "edgeList.H"
00056 #include "typeInfo.H"
00057 
00058 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00059 
00060 namespace Foam
00061 {
00062 
00063 // Forward declaration of classes
00064 class triSurface;
00065 
00066 /*---------------------------------------------------------------------------*\
00067                            Class surfaceFeatures Declaration
00068 \*---------------------------------------------------------------------------*/
00069 
00070 class surfaceFeatures
00071 {
00072 public:
00073 
00074         enum edgeStatus
00075         {
00076             NONE,
00077             REGION,
00078             EXTERNAL,
00079             INTERNAL
00080         };
00081 
00082 
00083 private:
00084 
00085     //- label and scalar; used in path walking
00086     class labelScalar
00087     {
00088     public:
00089         label n_;
00090         scalar len_;
00091 
00092         labelScalar(const label n, const scalar len)
00093         :
00094             n_(n),
00095             len_(len)
00096         {}
00097     };
00098 
00099 
00100     // Private data
00101 
00102         //- Reference to surface
00103         const triSurface& surf_;
00104 
00105         //- Labels of points that are features
00106         labelList featurePoints_;
00107 
00108         //- Labels of edges that are features
00109         labelList featureEdges_;
00110 
00111         //- Start of external edges in featureEdges_
00112         label externalStart_;
00113 
00114         //- Start of internal edges in featureEdges_
00115         label internalStart_;
00116 
00117 
00118     // Private Member Functions
00119 
00120         //- Return nearest point on edge (start..end). Also classify nearest:
00121         //  index=-1: nearest on mid of edge. index=0:nearest on edge.start()
00122         //  index=1: nearest on edge.end().
00123         static pointIndexHit edgeNearest
00124         (
00125             const point& start,
00126             const point& end,
00127             const point& sample
00128         );
00129 
00130 
00131         //- Construct feature points where more than 2 feature edges meet
00132         void calcFeatPoints(const List<edgeStatus>&);
00133 
00134         //- Choose next unset feature edge.
00135         label nextFeatEdge
00136         (
00137             const List<edgeStatus>& edgeStat,
00138             const labelList& featVisited,
00139             const label unsetVal,
00140             const label prevEdgeI,
00141             const label vertI
00142         ) const;
00143 
00144         //- Walk connected feature edges. Marks edges in featVisited.
00145         labelScalar walkSegment
00146         (
00147             const bool mark,
00148             const List<edgeStatus>& edgeStat,
00149             const label startEdgeI,
00150             const label startPointI,
00151             const label currentFeatI,
00152             labelList& featVisited
00153         );
00154 
00155 public:
00156 
00157     ClassName("surfaceFeatures");
00158 
00159     // Constructors
00160 
00161         //- Construct from surface
00162         surfaceFeatures(const triSurface&);
00163 
00164         //- Construct from components
00165         surfaceFeatures
00166         (
00167             const triSurface&,
00168             const labelList& featurePoints,
00169             const labelList& featureEdges,
00170             const label externalStart,
00171             const label internalStart
00172         );
00173 
00174         //- Construct from surface, angle and min cumulative length and/or
00175         //  number of elements
00176         surfaceFeatures
00177         (
00178             const triSurface&,
00179             const scalar includedAngle,
00180             const scalar minLen = 0,
00181             const label minElems = 0
00182         );
00183 
00184         //- Construct from dictionary
00185         surfaceFeatures(const triSurface&, const dictionary& dict);
00186 
00187         //- Construct from file
00188         surfaceFeatures(const triSurface&, const fileName& fName);
00189 
00190         //- Construct as copy
00191         surfaceFeatures(const surfaceFeatures&);
00192 
00193 
00194     // Member Functions
00195 
00196         // Access
00197 
00198             inline const triSurface& surface() const
00199             {
00200                 return surf_;
00201             }
00202 
00203             //- Return feature point list
00204             inline const labelList& featurePoints() const
00205             {
00206                 return featurePoints_;
00207             }
00208 
00209             //- Return feature edge list
00210             inline const labelList& featureEdges() const
00211             {
00212                 return featureEdges_;
00213             }
00214 
00215             //- start of external edges
00216             inline label externalStart() const
00217             {
00218                 return externalStart_;
00219             }
00220 
00221             //- start of internal edges
00222             inline label internalStart() const
00223             {
00224                 return internalStart_;
00225             }
00226 
00227             //- Return number of region edges
00228             inline label nRegionEdges() const
00229             {
00230                 return externalStart_;
00231             }
00232 
00233             //- Return number of external edges
00234             inline label nExternalEdges() const
00235             {
00236                 return internalStart_ - externalStart_;
00237             }
00238 
00239             //- Return number of internal edges
00240             inline label nInternalEdges() const
00241             {
00242                 return featureEdges_.size() - internalStart_;
00243             }
00244 
00245             //- Helper function: select a subset of featureEdges_
00246             labelList selectFeatureEdges
00247             (
00248                 const bool regionEdges,
00249                 const bool externalEdges,
00250                 const bool internalEdges
00251             ) const;
00252 
00253 
00254         // Edit
00255 
00256             //- Find feature edges using provided included angle
00257             void findFeatures(const scalar includedAngle);
00258 
00259             //- Delete small sets of edges. Edges are stringed up and any
00260             //  string of length < minLen (or nElems < minElems) is deleted.
00261             void trimFeatures(const scalar minLen, const label minElems);
00262 
00263             //- From member feature edges to status per edge.
00264             List<edgeStatus> toStatus() const;
00265 
00266             //- Set from status per edge
00267             void setFromStatus(const List<edgeStatus>&);
00268 
00269 
00270         // Find
00271 
00272             //- Find nearest sample for selected surface points (usually the
00273             //  set of featurePoints). Return map from index in
00274             //  samples to surface point. Do not include points that are further
00275             //  than maxDist away (separate maxDist for every sample)
00276             Map<label> nearestSamples
00277             (
00278                 const labelList& selectedPoints,
00279                 const pointField& samples,
00280                 const scalarField& maxDist
00281             ) const;
00282 
00283             //- Find nearest sample for regularly sampled points along the
00284             //  selected (surface) edges. Return map from sample to edge.
00285             //  maxDist is distance below which gets snapped.
00286             //  Edge gets sampled at points sampleDist[sampleI] apart.
00287             //  (with a maximum of 10 samples per edge)
00288             Map<label> nearestSamples
00289             (
00290                 const labelList& selectedEdges,
00291                 const pointField& samples,
00292                 const scalarField& sampleDist,
00293                 const scalarField& maxDist,
00294                 const scalar minSampleDist = 0.1
00295             ) const;
00296 
00297             //- Like nearestSamples but now gets nearest point on
00298             //  sample-edge instead of nearest sample-point itself.
00299             //  Return map from sample edge to feature edge.
00300             Map<pointIndexHit> nearestEdges
00301             (
00302                 const labelList& selectedEdges,
00303                 const edgeList& sampleEdges,
00304                 const labelList& selectedSampleEdges,
00305                 const pointField& samplePoints,
00306                 const scalarField& sampleDist,
00307                 const scalarField& maxDist,
00308                 const scalar minSampleDist = 0.1
00309             ) const;
00310 
00311 
00312             //- Find nearest surface edge (out of selectedEdges) for
00313             //  each sample point.
00314             //  Sets:
00315             //  - edgeLabel : label of surface edge.
00316             //  - edgePoint : exact position of nearest point on edge.
00317             //  - edgeEndPoint : -1, 0, 1 depending on whether edgePoint is
00318             //                  on inside/start/end of edge
00319             void nearestSurfEdge
00320             (
00321                 const labelList& selectedEdges,
00322                 const pointField& samples,
00323                 const vector& searchSpan,   // search span
00324                 labelList& edgeLabel,
00325                 labelList& edgeEndPoint,
00326                 pointField& edgePoint
00327             ) const;
00328 
00329 
00330             //- Find nearest surface edge (out of selectedEdges) for each
00331             // sample edge.
00332             //  Sets:
00333             //  - edgeLabel         : label of surface edge.
00334             //  - pointOnEdge       : exact position of nearest point on edge.
00335             //  - pointOnFeature    : exact position on sample edge.
00336             void nearestSurfEdge
00337             (
00338                 const labelList& selectedEdges,
00339                 const edgeList& sampleEdges,
00340                 const labelList& selectedSampleEdges,
00341                 const pointField& samplePoints,
00342                 const vector& searchSpan,   // search span
00343 
00344                 labelList& edgeLabel,       // label of surface edge or -1
00345                 pointField& pointOnEdge,    // point on above edge
00346                 pointField& pointOnFeature  // point on sample edge
00347             ) const;
00348 
00349 
00350         // Write
00351 
00352             //- Write as dictionary
00353             void writeDict(Ostream&) const;
00354 
00355             //- Write as dictionary to file
00356             void write(const fileName& fName) const;
00357 
00358             //- Write to separate OBJ files (region, external, internal edges,
00359             //  feature points) for visualization
00360             void writeObj(const fileName& prefix) const;
00361 
00362 
00363 
00364     // Member Operators
00365 
00366         void operator=(const surfaceFeatures&);
00367 
00368 
00369 };
00370 
00371 
00372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00373 
00374 } // End namespace Foam
00375 
00376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00377 
00378 #endif
00379 
00380 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd