FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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