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

octreeDataTriSurface.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::octreeDataTriSurface
00026 
00027 Description
00028     Encapsulates data for octree searches on triSurface.
00029 
00030 SourceFiles
00031     octreeDataTriSurface.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef octreeDataTriSurface_H
00036 #define octreeDataTriSurface_H
00037 
00038 #include <meshTools/treeBoundBoxList.H>
00039 #include <OpenFOAM/labelList.H>
00040 #include <OpenFOAM/point.H>
00041 #include <triSurface/triSurface.H>
00042 #include <OpenFOAM/linePointRef.H>
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // Forward declaration of classes
00050 template<class Type> class octree;
00051 
00052 /*---------------------------------------------------------------------------*\
00053                            Class octreeDataTriSurface Declaration
00054 \*---------------------------------------------------------------------------*/
00055 
00056 class octreeDataTriSurface
00057 {
00058     // Static data
00059 
00060         //- tolerance on linear dimensions
00061         static scalar tol;
00062 
00063     // Private data
00064 
00065         const triSurface& surface_;
00066 
00067         const treeBoundBoxList allBb_;
00068 
00069         // Extra data to speed up distance searches.
00070         // Triangles expressed as base + spanning vectors
00071         pointField base_;
00072         pointField E0_;
00073         pointField E1_;
00074         scalarList a_;
00075         scalarList b_;
00076         scalarList c_;
00077 
00078 
00079     // Private Static Functions
00080 
00081         //- fast triangle nearest point calculation. Returns point in E0, E1
00082         //  coordinate system:  base + s*E0 + t*E1
00083         static void nearestCoords
00084         (
00085             const point& base,
00086             const point& E0,
00087             const point& E1,
00088             const scalar a,
00089             const scalar b,
00090             const scalar c,
00091             const point& P,
00092             scalar& s,
00093             scalar& t
00094         );
00095 
00096         //- Calculate bounding boxes for triangles
00097         static treeBoundBoxList calcBb(const triSurface&);
00098 
00099     // Private Member Functions
00100 
00101         //- nearest point in xyz coord system
00102         point nearestPoint(const label index, const point& P) const;
00103 
00104 public:
00105 
00106     // Declare name of the class and its debug switch
00107     ClassName("octreeDataTriSurface");
00108 
00109 
00110     // Constructors
00111 
00112         //- Construct from triSurface. Holds reference. Bounding box
00113         //  calculated from triangle points.
00114         octreeDataTriSurface(const triSurface&);
00115 
00116         //- Construct from triSurface and bounding box.
00117         //  Holds references.
00118         octreeDataTriSurface(const triSurface&, const treeBoundBoxList&);
00119 
00120 
00121     // Member Functions
00122 
00123         // Access
00124 
00125             const triSurface& surface() const
00126             {
00127                 return surface_;
00128             }
00129 
00130             const treeBoundBoxList& allBb() const
00131             {
00132                 return allBb_;
00133             }
00134 
00135             label size() const
00136             {
00137                 return allBb_.size();
00138             }
00139 
00140         // Search
00141 
00142             //- Get type of sample
00143             label getSampleType
00144             (
00145                 const octree<octreeDataTriSurface>&,
00146                 const point&
00147             ) const;
00148 
00149             //- Does (bb of) shape at index overlap bb
00150             bool overlaps
00151             (
00152                 const label index,
00153                 const treeBoundBox& sampleBb
00154             ) const;
00155 
00156             //- Does shape at index contain sample
00157             bool contains
00158             (
00159                 const label index,
00160                 const point& sample
00161             ) const;
00162 
00163             //- Segment (from start to end) intersection with shape
00164             //  at index. If intersects returns true and sets intersectionPoint
00165             bool intersects
00166             (
00167                 const label index,
00168                 const point& start,
00169                 const point& end,
00170                 point& intersectionPoint
00171             ) const;
00172 
00173             //- Sets newTightest to bounding box (and returns true) if
00174             //  nearer to sample than tightest bounding box. Otherwise
00175             //  returns false.
00176             bool findTightest
00177             (
00178                 const label index,
00179                 const point& sample,
00180                 treeBoundBox& tightest
00181             ) const;
00182 
00183             //- Given index get unit normal and calculate (numerical) sign 
00184             //  of sample.
00185             //  Used to determine accuracy of calcNearest or inside/outside.
00186             scalar calcSign
00187             (
00188                 const label index,
00189                 const point& sample,
00190                 vector& n
00191             ) const;
00192 
00193             //- Calculates nearest (to sample) point in shape.
00194             //  Returns point and mag(nearest - sample)
00195             scalar calcNearest
00196             (
00197                 const label index,
00198                 const point& sample,
00199                 point& nearest
00200             ) const;
00201 
00202             //- Calculates nearest (to line segment) point in shape.
00203             //  Returns distance and both point.
00204             scalar calcNearest
00205             (
00206                 const label index,
00207                 const linePointRef& ln,
00208                 point& linePt,          // nearest point on line
00209                 point& shapePt          // nearest point on shape
00210             ) const;
00211 
00212 
00213         // Write
00214 
00215             // Write shape at index
00216             void write(Ostream& os, const label index) const;
00217 
00218 
00219     // IOstream Operators
00220 
00221         friend Istream& operator>>(Istream&, octreeDataTriSurface&);
00222         friend Ostream& operator<<(Ostream&, const octreeDataTriSurface&);
00223 };
00224 
00225 
00226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00227 
00228 } // End namespace Foam
00229 
00230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00231 
00232 
00233 #endif
00234 
00235 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines