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::surfaceIntersection 00026 00027 Description 00028 Basic surface-surface intersection description. Constructed from two 00029 surfaces it creates a description of the intersection. 00030 00031 The intersection information consists of the intersection line(s) 00032 with new points, new edges between points (note that these edges and 00033 points are on both surfaces) and various addressing from original 00034 surface faces/edges to intersection and vice versa. 00035 00036 Gets either precalculated intersection information or calculates it 00037 itself. 00038 Algorithm works by intersecting all edges of one surface with the other 00039 surface and storing a reference from both faces (one on surface1, one on 00040 surface 2) to the vertex. If the reference re-occurs we have the second 00041 hit of both faces and an edge is created between the retrieved vertex and 00042 the new one. 00043 00044 Note: when doing intersecting itself uses intersection::planarTol() as a 00045 fraction of 00046 current edge length to determine if intersection is a point-touching one 00047 instead of an edge-piercing action. 00048 00049 SourceFiles 00050 surfaceIntersection.C 00051 surfaceIntersectionFuncs.C 00052 surfaceIntersectionTemplates.C 00053 00054 \*---------------------------------------------------------------------------*/ 00055 00056 #ifndef surfaceIntersection_H 00057 #define surfaceIntersection_H 00058 00059 #include <OpenFOAM/DynamicList.H> 00060 #include <OpenFOAM/point.H> 00061 #include <OpenFOAM/edge.H> 00062 #include <triSurface/labelPairLookup.H> 00063 #include <OpenFOAM/typeInfo.H> 00064 #include <OpenFOAM/edgeList.H> 00065 #include <meshTools/pointIndexHit.H> 00066 00067 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00068 00069 namespace Foam 00070 { 00071 00072 // Forward declaration of classes 00073 class triSurfaceSearch; 00074 class triSurface; 00075 class edgeIntersections; 00076 00077 /*---------------------------------------------------------------------------*\ 00078 Class surfaceIntersection Declaration 00079 \*---------------------------------------------------------------------------*/ 00080 00081 class surfaceIntersection 00082 { 00083 // Private data 00084 00085 //- Newly introduced points. 00086 pointField cutPoints_; 00087 00088 //- Newly introduced edges (are on both surfaces). Reference into 00089 // cutPoints. 00090 edgeList cutEdges_; 00091 00092 //- From face on surf1 and face on surf2 to intersection point 00093 // (label in cutPoints) 00094 labelPairLookup facePairToVertex_; 00095 00096 //- From face on surf1 and face on surf2 to intersection edge 00097 // (label in cutEdges) 00098 labelPairLookup facePairToEdge_; 00099 00100 //- Edges on surf1 that are cut. From edge on surf1 to label in cutPoint 00101 // If multiple cuts:sorted from edge.start to edge.end 00102 labelListList surf1EdgeCuts_; 00103 00104 //- Edges on surf2 that are cut. From edge on surf2 to label in cutPoint 00105 // If multiple cuts:sorted from edge.start to edge.end 00106 labelListList surf2EdgeCuts_; 00107 00108 00109 // Private Member Functions 00110 00111 //- Write point in obj format. 00112 static void writeOBJ(const point& pt, Ostream& os); 00113 00114 //- Write points and edges in obj format 00115 static void writeOBJ 00116 ( 00117 const List<point>&, 00118 const List<edge>&, 00119 Ostream& 00120 ); 00121 00122 //- Transfer contents of List<DynamicList<..> > to List<List<..>> 00123 template<class T> 00124 static void transfer(List<DynamicList<T> >&, List<List<T> >&); 00125 00126 //- Get minimum length of all edges connected to point 00127 static scalar minEdgeLen(const triSurface& surf, const label pointI); 00128 00129 //- Get edge label of edge between face vertices fp and fp+1 00130 static label getEdge 00131 ( 00132 const triSurface& surf, 00133 const label faceI, 00134 const label fp 00135 ); 00136 00137 //- Remove duplicates from ordered dynamic list. Returns map from old 00138 // to new (-1 if element removed) 00139 static void removeDuplicates(const labelList& map, labelList& labels); 00140 00141 //- Apply map to elements of a labelList 00142 static void inlineRemap(const labelList& map, labelList& elems); 00143 00144 // Remove all duplicate and degenerate elements. Return unique elements 00145 // and map from old to new. 00146 static edgeList filterEdges(const edgeList&, labelList& map); 00147 00148 //- Remove all duplicate elements. 00149 static labelList filterLabels(const labelList& elems, labelList& map); 00150 00151 //- Do some checks if edge and face (resulting from hit) 00152 // should not be considered. Returns true if can be discarded. 00153 static bool excludeEdgeHit 00154 ( 00155 const triSurface& surf, 00156 const label edgeI, 00157 const label faceI, 00158 const scalar tol 00159 ); 00160 00164 //static pointIndexHit faceEdgeIntersection 00165 //( 00166 // const triSurface&, 00167 // const label hitFaceI, 00168 // 00169 // const vector& n, 00170 // const point& eStart, 00171 // const point& eEnd 00172 //); 00173 00174 00175 //- Debugging: Dump intersected edges to stream 00176 void writeIntersectedEdges 00177 ( 00178 const triSurface& surf, 00179 const labelListList& edgeCutVerts, 00180 Ostream& os 00181 ) const; 00182 00183 //- Detect if point close to edge of end. Returns -1: not close. 00184 // 0:close (within startTol) to start, 1:close (within endTol) to end 00185 static label classify 00186 ( 00187 const scalar startTol, 00188 const scalar endTol, 00189 const point& p, 00190 const edge& e, 00191 const pointField& points 00192 ); 00193 00194 //- Update reference between faceA and faceB. Updates facePairToVertex_ 00195 // (first occurrence of face pair) and facePairToEdge_ (second occ.) 00196 void storeIntersection 00197 ( 00198 const bool isFirstSurf, 00199 const labelList& facesA, 00200 const label faceB, 00201 DynamicList<edge>&, 00202 DynamicList<point>& 00203 ); 00204 00205 //- Investigate pHit to whether is case of point hits point, 00206 // point hits edge, point hits face or edge hits face. 00207 void classifyHit 00208 ( 00209 const triSurface& surf1, 00210 const scalarField& surf1PointTol, 00211 const triSurface& surf2, 00212 const bool isFirstSurf, 00213 const label edgeI, 00214 const scalar tolDim, 00215 const pointIndexHit& pHit, 00216 00217 DynamicList<edge>& allCutEdges, 00218 DynamicList<point>& allCutPoints, 00219 List<DynamicList<label> >& surfEdgeCuts 00220 ); 00221 00222 //- Cut edges of surf1 with surface 2. 00223 void doCutEdges 00224 ( 00225 const triSurface& surf1, 00226 const triSurfaceSearch& querySurf2, 00227 const bool isFirstSurf, 00228 const bool isSelfIntersection, 00229 00230 DynamicList<edge>& allCutEdges, 00231 DynamicList<point>& allCutPoints, 00232 List<DynamicList<label> >& surfEdgeCuts 00233 ); 00234 00235 public: 00236 00237 ClassName("surfaceIntersection"); 00238 00239 00240 // Constructors 00241 00242 //- Construct null 00243 surfaceIntersection(); 00244 00245 //- Construct from precalculated intersection information. 00246 // Advantage: intersection information is guaranteed to have no 00247 // degenerate cuts. 00248 surfaceIntersection 00249 ( 00250 const triSurface& surf1, 00251 const edgeIntersections& intersections1, 00252 const triSurface& surf2, 00253 const edgeIntersections& intersections2 00254 ); 00255 00256 //- Construct from two surfaces. Does all its own cutting. 00257 // Has problems with degenerate cuts 00258 surfaceIntersection 00259 ( 00260 const triSurfaceSearch& querySurf1, 00261 const triSurfaceSearch& querySurf2 00262 ); 00263 00264 //- Special: intersect surface with itself. Used to check for 00265 // self-intersection. 00266 surfaceIntersection(const triSurfaceSearch& querySurf1); 00267 00268 00269 // Member Functions 00270 00271 const pointField& cutPoints() const; 00272 00273 const edgeList& cutEdges() const; 00274 00275 //const labelPairLookup& facePairToVertex() const; 00276 00277 const labelPairLookup& facePairToEdge() const; 00278 00279 //- Access either surf1EdgeCuts (isFirstSurface = true) or 00280 // surf2EdgeCuts 00281 const labelListList& edgeCuts(const bool) const; 00282 00283 const labelListList& surf1EdgeCuts() const; 00284 00285 const labelListList& surf2EdgeCuts() const; 00286 00287 }; 00288 00289 00290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00291 00292 } // End namespace Foam 00293 00294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00295 00296 #ifdef NoRepository 00297 # include <meshTools/surfaceIntersectionTemplates.C> 00298 #endif 00299 00300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00301 00302 #endif 00303 00304 // ************************ vim: set sw=4 sts=4 et: ************************ //