OpenFOAM logo
Open Source CFD Toolkit

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-2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00024 
00025 Class
00026     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 "labelHashSet.H"
00054 #include "pointIndexHit.H"
00055 #include "edgeList.H"
00056 #include "typeInfo.H"
00057 
00058 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00059 
00060 namespace Foam
00061 {
00062 
00063 // Class forward declarations
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 
00246         // Edit
00247 
00248             //- Find feature edges using provided included angle
00249             void findFeatures(const scalar includedAngle);
00250 
00251             //- Delete small sets of edges. Edges are stringed up and any
00252             //  string of length < minLen (or nElems < minElems) is deleted.
00253             void trimFeatures(const scalar minLen, const label minElems);
00254 
00255             //- From member feature edges to status per edge.
00256             List<edgeStatus> toStatus() const;
00257 
00258             //- Set from status per edge
00259             void setFromStatus(const List<edgeStatus>&);
00260 
00261         // Find
00262 
00263             //- Find nearest sample for every point (usually the set of
00264             //  featurePoints). Return map from index in
00265             //  samples to surface point. Do not include points that are further
00266             //  than maxDist away (separate maxDist for every sample)
00267             Map<label> nearestSamples
00268             (
00269                 const labelList& pointLabels,
00270                 const pointField& samples,
00271                 const scalarField& maxDist
00272             ) const;
00273 
00274             //- Find nearest sample for regularly sampled points along the
00275             //  feature edges. Return map from sample to feature edge.
00276             //  maxDist is distance below which gets snapped.
00277             //  Edge gets sampled at points sampleDist[sampleI] apart.
00278             //  (with a maximum of 10 samples per edge)
00279             Map<label> nearestSamplesToFeatEdges
00280             (
00281                 const pointField& samples,
00282                 const scalarField& sampleDist,
00283                 const scalarField& maxDist,
00284                 const scalar minSampleDist = 0.1
00285             ) const;
00286 
00287             //- Like nearestSamplesToFeatEdges but now gets nearest point on
00288             //  sample-edge instead of nearest sample-point itself.
00289             //  Return map from sample edge to feature edge.
00290             Map<pointIndexHit> nearestEdgesToFeatEdges
00291             (
00292                 const edgeList& sampleEdges,
00293                 const labelList& selectedSampleEdges,
00294                 const pointField& samplePoints,
00295                 const scalarField& sampleDist,
00296                 const scalarField& maxDist,
00297                 const scalar minSampleDist = 0.1
00298             ) const;
00299 
00300 
00301             //- Find nearest surface feature edge for each sample point.
00302             //  Sets:
00303             //  - edgeLabel : label of surface edge.
00304             //  - edgePoint : exact position of nearest point on edge.
00305             //  - edgeEndPoint : -1, 0, 1 depending on whether edgePoint is
00306             //                  on inside/start/end of edge
00307             void nearestSurfFeatures
00308             (
00309                 const pointField& samples,
00310                 const scalarField& maxDist,
00311                 labelList& edgeLabel,
00312                 labelList& edgeEndPoint,
00313                 pointField& edgePoint
00314             ) const;
00315 
00316 
00317             //- Find nearest surface feature edge for each sample edge.
00318             //  Sets:
00319             //  - edgeLabel         : label of surface edge.
00320             //  - pointOnEdge       : exact position of nearest point on edge.
00321             //  - pointOnFeature    : exact position on sample edge.
00322             void nearestSurfFeatures
00323             (
00324                 const edgeList& sampleEdges,
00325                 const labelList& selectedSampleEdges,
00326                 const pointField& samplePoints,
00327 
00328                 const vector& searchSpan,   // search span 
00329                 labelList& edgeLabel,       // label of surface edge or -1
00330                 pointField& pointOnEdge,    // point on above edge
00331                 pointField& pointOnFeature  // point on sample edge
00332             ) const;
00333 
00334 
00335         // Write
00336 
00337             //- Write as dictionary
00338             void writeDict(Ostream&) const;
00339 
00340             //- Write as dictionary to file
00341             void write(const fileName& fName) const;
00342 
00343             //- Write to separate OBJ files (region, external, internal edges,
00344             //  feature points) for visualization
00345             void writeObj(const fileName& prefix) const;
00346 
00347 
00348 
00349     // Member Operators
00350 
00351         void operator=(const surfaceFeatures&);
00352 
00353 
00354 };
00355 
00356 
00357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00358 
00359 } // End namespace Foam
00360 
00361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00362 
00363 #endif
00364 
00365 // ************************************************************************* //
For further information go to www.openfoam.org