00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 #ifndef triSurfaceTools_H
00036 #define triSurfaceTools_H
00037 
00038 #include <OpenFOAM/boolList.H>
00039 #include <OpenFOAM/pointField.H>
00040 #include <OpenFOAM/DynamicList.H>
00041 #include <OpenFOAM/HashSet.H>
00042 #include <OpenFOAM/FixedList.H>
00043 #include <OpenFOAM/vector2D.H>
00044 #include <OpenFOAM/triPointRef.H>
00045 #include <meshTools/surfaceLocation.H>
00046 
00047 
00048 
00049 namespace Foam
00050 {
00051 
00052 
00053 class triSurface;
00054 class edge;
00055 class labelledTri;
00056 class polyBoundaryMesh;
00057 class plane;
00058 
00059 
00060 
00061 
00062 
00063 class triSurfaceTools
00064 {
00065     
00066 
00067         
00068 
00069             enum refineType
00070             {
00071                 NONE,
00072                 RED,
00073                 GREEN
00074             };
00075             static void calcRefineStatus
00076             (
00077                 const triSurface& surf,
00078                 const label faceI,
00079                 List<refineType>& refine
00080             );
00081             static void greenRefine
00082             (
00083                 const triSurface& surf,
00084                 const label faceI,
00085                 const label edgeI,
00086                 const label newPointI,
00087                 DynamicList<labelledTri>& newFaces
00088             );
00089             static triSurface doRefine
00090             (
00091                 const triSurface& surf,
00092                 const List<refineType>& refineStatus
00093             );
00094 
00095 
00096         
00097 
00098             static scalar faceCosAngle
00099             (
00100                 const point& pStart,
00101                 const point& pEnd,
00102                 const point& pLeft,
00103                 const point& pRight
00104             );
00105 
00106             static void protectNeighbours
00107             (
00108                 const triSurface& surf,
00109                 const label vertI,
00110                 labelList& faceStatus
00111             );
00112 
00113             
00114             static labelHashSet getCollapsedFaces
00115             (
00116                 const triSurface& surf,
00117                 label edgeI
00118             );
00119 
00120             
00121             
00122             static label vertexUsesFace
00123             (
00124                 const triSurface& surf,
00125                 const labelHashSet& faceUsed,
00126                 const label vertI
00127             );
00128 
00129             
00130             
00131             
00132             
00133             
00134             
00135             
00136             
00137             static void getMergedEdges
00138             (
00139                 const triSurface& surf,
00140                 const label edgeI,
00141                 const labelHashSet& collapsedFaces,
00142                 HashTable<label, label, Hash<label> >& edgeToEdge,
00143                 HashTable<label, label, Hash<label> >& edgeToFace
00144             );
00145 
00146             
00147             
00148             
00149             static scalar edgeCosAngle
00150             (
00151                 const triSurface& surf,
00152                 const label v1,
00153                 const point& pt,
00154                 const labelHashSet& collapsedFaces,
00155                 const HashTable<label, label, Hash<label> >& edgeToEdge,
00156                 const HashTable<label, label, Hash<label> >& edgeToFace,
00157                 const label faceI,
00158                 const label edgeI
00159             );
00160 
00161             
00163             
00164             
00165             static scalar collapseMinCosAngle
00166             (
00167                 const triSurface& surf,
00168                 const label v1,
00169                 const point& pt,
00170                 const labelHashSet& collapsedFaces,
00171                 const HashTable<label, label, Hash<label> >& edgeToEdge,
00172                 const HashTable<label, label, Hash<label> >& edgeToFace
00173             );
00174 
00175             
00176             bool collapseCreatesFold
00177             (
00178                 const triSurface& surf,
00179                 const label v1,
00180                 const point& pt,
00181                 const labelHashSet& collapsedFaces,
00182                 const HashTable<label, label, Hash<label> >& edgeToEdge,
00183                 const HashTable<label, label, Hash<label> >& edgeToFace,
00184                 const scalar minCos
00185             );
00186 
00189             
00190             
00191             
00192             
00193             
00194             
00195 
00196         
00197 
00198             
00199             
00200             
00201             
00202             
00203             static surfaceLocation cutEdge
00204             (
00205                 const triSurface& s,
00206                 const label triI,
00207                 const label excludeEdgeI,
00208                 const label excludePointI,
00209                 const point& triPoint,
00210                 const plane& cutPlane,
00211                 const point& toPoint
00212             );
00213 
00214             
00215             
00216             static void snapToEnd
00217             (
00218                 const triSurface& s,
00219                 const surfaceLocation& endInfo,
00220                 surfaceLocation& current
00221             );
00222 
00223             
00224             
00225             
00226             
00227             
00228             
00229             
00230             
00231             static surfaceLocation visitFaces
00232             (
00233                 const triSurface& s,
00234                 const labelList& eFaces,
00235                 const surfaceLocation& start,
00236                 const label excludeEdgeI,
00237                 const label excludePointI,
00238                 const surfaceLocation& end,
00239                 const plane& cutPlane
00240             );
00241 
00242 
00243 public:
00244 
00245     
00246 
00247         
00248         static void writeOBJ
00249         (
00250             const fileName& fName,
00251             const pointField& pts
00252         );
00253 
00254         
00255         static void writeOBJ
00256         (
00257             const triSurface& surf,
00258             const fileName& fName,
00259             const boolList& markedVerts
00260         );
00261 
00262 
00263     
00264 
00265         
00266         static void getVertexTriangles
00267         (
00268             const triSurface& surf,
00269             const label edgeI,
00270             labelList& edgeTris
00271         );
00272 
00273         
00274         static labelList getVertexVertices
00275         (
00276             const triSurface& surf,
00277             const edge& e
00278         );
00279 
00281         
00282         
00283         
00284         
00285         
00286         
00287         
00288         
00289 
00290         
00291         static label otherFace
00292         (
00293             const triSurface& surf,
00294             const label faceI,
00295             const label edgeI
00296         );
00297 
00298         
00299         static void otherEdges
00300         (
00301             const triSurface& surf,
00302             const label faceI,
00303             const label edgeI,
00304             label& e1,
00305             label& e2
00306         );
00307 
00308         
00309         
00310         static void otherVertices
00311         (
00312             const triSurface& surf,
00313             const label faceI,
00314             const label vertI,
00315             label& vert1I,
00316             label& vert2I
00317         );
00318 
00319         
00320         static label oppositeEdge
00321         (
00322             const triSurface& surf,
00323             const label faceI,
00324             const label vertI
00325         );
00326 
00327         
00328         static label oppositeVertex
00329         (
00330             const triSurface& surf,
00331             const label faceI,
00332             const label edgeI
00333         );
00334 
00335         
00336         static label getEdge
00337         (
00338             const triSurface& surf,
00339             const label vert1I,
00340             const label vert2I
00341         );
00342 
00343         
00344         static label getTriangle
00345         (
00346             const triSurface& surf,
00347             const label e0I,
00348             const label e1I,
00349             const label e2I
00350         );
00351 
00352     
00353 
00354         
00355         static triSurface collapseEdges
00356         (
00357             const triSurface& surf,
00358             const labelList& collapsableEdges
00359         );
00360 
00361 
00362         
00363         
00364         
00365         
00366         
00367         static const label ANYEDGE;
00368         static const label NOEDGE;
00369         static const label COLLAPSED;
00370 
00371         
00372         
00373         
00374         
00375         
00376         static triSurface collapseEdges
00377         (
00378             const triSurface& surf,
00379             const labelList& collapsableEdges,
00380             const pointField& edgeMids,
00381             labelList& faceStatus
00382         );
00383 
00384 
00385     
00386 
00387         
00388         static triSurface greenRefine
00389         (
00390             const triSurface& surf,
00391             const labelList& refineEdges
00392         );
00393 
00394         
00395         
00396         static triSurface redGreenRefine
00397         (
00398             const triSurface& surf,
00399             const labelList& refineFaces
00400         );
00401 
00402 
00403     
00404 
00405         
00406         static label minEdge
00407         (
00408             const triSurface& surf,
00409             const labelList& edgeIndices
00410         );
00411 
00412         
00413         static label maxEdge
00414         (
00415             const triSurface& surf,
00416             const labelList& edgeIndices
00417         );
00418 
00419         
00420         static triSurface mergePoints
00421         (
00422             const triSurface& surf,
00423             const scalar mergeTol
00424         );
00425 
00426         
00427         
00428         
00429         static vector surfaceNormal
00430         (
00431             const triSurface& surf,
00432             const label nearestFaceI,
00433             const point& nearestPt
00434         );
00435 
00436         
00437         enum sideType
00438         {
00439             UNKNOWN,    
00440             INSIDE,     
00441             OUTSIDE     
00442         };
00443 
00444         
00445         
00446         static sideType edgeSide
00447         (
00448             const triSurface& surf,
00449             const point& sample,
00450             const point& nearestPoint,
00451             const label edgeI
00452         );
00453 
00454         
00455         
00456         
00457         static sideType surfaceSide
00458         (
00459             const triSurface& surf,
00460             const point& sample,
00461             const label nearestFaceI,   
00462             const point& nearestPt,     
00463             const scalar tol            
00464         );
00465 
00466     
00467 
00468         
00469         
00470         
00471         static triSurface triangulate
00472         (
00473             const polyBoundaryMesh& mBesh,
00474             const labelHashSet& includePatches,
00475             const bool verbose = false
00476         );
00477 
00478         
00479         
00480         
00481         
00482         triSurface triangulateFaceCentre
00483         (
00484             const polyBoundaryMesh& mBesh,
00485             const labelHashSet& includePatches,
00486             const bool verbose = false
00487         );
00488 
00489 
00490     
00491 
00492         
00493         
00494         static void calcInterpolationWeights
00495         (
00496             const triPointRef&,
00497             const point&,
00498             FixedList<scalar, 3>& weights
00499         );
00500 
00501         
00502         
00503         
00504         
00505         
00506         
00507         
00508         static void calcInterpolationWeights
00509         (
00510             const triSurface& s,
00511             const pointField& samplePts,
00512             List<FixedList<label, 3> >& verts,
00513             List<FixedList<scalar, 3> >& weights
00514         );
00515 
00516         
00517         
00518         static triSurface delaunay2D(const List<vector2D>&);
00519 
00520 
00521     
00522 
00523         
00524         
00525         static surfaceLocation classify
00526         (
00527             const triSurface&,
00528             const label triI,
00529             const point& trianglePoint
00530         );
00531 
00532         
00533         
00534         
00535         
00536         
00537         
00538         
00539         
00540         
00541         
00542         
00543         
00544         
00545         
00546         
00547         
00548         static surfaceLocation trackToEdge
00549         (
00550             const triSurface&,
00551             const surfaceLocation& start,
00552             const surfaceLocation& end,
00553             const plane& cutPlane
00554         );
00555 
00556         
00557         
00558         
00559         
00560         
00561         static void track
00562         (
00563             const triSurface&,
00564             const surfaceLocation& endInfo,
00565             const plane& cutPlane,
00566             surfaceLocation& hitInfo
00567         );
00568 };
00569 
00570 
00571 
00572 
00573 } 
00574 
00575 
00576 
00577 #endif
00578 
00579