OpenFOAM logo
Open Source CFD Toolkit

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