Version: 6.3.1

src/INTERP_KERNEL/TransformedTriangle.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __TRANSFORMED_TRIANGLE_HXX__
00021 #define __TRANSFORMED_TRIANGLE_HXX__
00022 
00023 #include "INTERPKERNELDefines.hxx"
00024 
00025 #include <vector>
00026 
00027 // Levels : 
00028 // 1 - overview of algorithm + volume result
00029 // 2 - algorithm detail
00030 // 3 - intersection polygon results detail
00031 // 4 - intersection polygon search detail
00032 // higher -> misc. gory details of calculation
00033 
00034 #include "Log.hxx"
00035 
00036 #ifdef WNT
00037 #pragma warning(disable:4251)
00038 #endif
00039 
00040 namespace INTERP_TEST
00041 {
00042   class TransformedTriangleTest;
00043   class TransformedTriangleIntersectTest;
00044 }
00045 
00046 
00047 namespace INTERP_KERNEL
00048 {
00049 
00100   class INTERPKERNEL_EXPORT TransformedTriangle
00101   {
00102  
00103 
00104   public:
00105 
00106     friend class INTERP_TEST::TransformedTriangleTest;
00107     friend class INTERP_TEST::TransformedTriangleIntersectTest;
00108     /*
00109      * Enumerations representing the different geometric elements of the unit tetrahedron
00110      * and the triangle. The end element, NO_* gives the number of elements in the enumeration
00111      * and can be used as end element in loops.
00112      */
00113 
00115     enum TetraCorner { O = 0, X, Y, Z, NO_TET_CORNER };
00116 
00118     enum TetraEdge { OX = 0, OY, OZ, XY, YZ, ZX, H01, H10, NO_TET_EDGE };
00119 
00121     enum TetraFacet { OYZ = 0, OZX, OXY, XYZ, NO_TET_FACET };
00122 
00124     enum TriCorner { P = 0, Q, R, NO_TRI_CORNER };
00125     
00127     enum TriSegment { PQ = 0, QR, RP, NO_TRI_SEGMENT };
00128     
00130     enum IntersectionPolygon{ A = 0, B, NO_INTERSECTION_POLYGONS };
00131 
00134     enum DoubleProduct { C_YZ = 0, C_ZX, C_XY, C_ZH, C_XH, C_YH, C_01, C_10, NO_DP };
00135 
00136     TransformedTriangle(double* p, double* q, double* r); 
00137     ~TransformedTriangle();
00138 
00139     double calculateIntersectionVolume(); 
00140 
00141     void dumpCoords() const;
00142 
00143     // Queries of member values used by UnitTetraIntersectionBary
00144 
00145     const double* getCorner(TriCorner corner) const { return _coords + 5*corner; }
00146 
00147     const std::vector<double*>& getPolygonA() const { return _polygonA; }
00148 
00149     double getVolume() const { return _volume; }
00150 
00151   protected:
00152 
00153     TransformedTriangle() { }
00154 
00155     // ----------------------------------------------------------------------------------
00156     //  High-level methods called directly by calculateIntersectionVolume()     
00157     // ----------------------------------------------------------------------------------
00158     void calculateIntersectionPolygons(); 
00159 
00160     void calculatePolygonBarycenter(const IntersectionPolygon poly, double* barycenter); 
00161 
00162     void sortIntersectionPolygon(const IntersectionPolygon poly, const double* barycenter); 
00163 
00164     double calculateVolumeUnderPolygon(IntersectionPolygon poly, const double* barycenter); 
00165 
00166     // ----------------------------------------------------------------------------------
00167     //  Detection of degenerate triangles  
00168     // ----------------------------------------------------------------------------------
00169 
00170     bool isTriangleInPlaneOfFacet(const TetraFacet facet) const;
00171     
00172     bool isTriangleParallelToFacet(const TetraFacet facet) const;
00173 
00174     int isTriangleInclinedToFacet(const TetraFacet facet) const;
00175 
00176     bool isTriangleBelowTetraeder() const;
00177 
00178     // ----------------------------------------------------------------------------------
00179     //  Intersection test methods and intersection point calculations           
00180     // ----------------------------------------------------------------------------------
00181  
00182     inline bool testSurfaceEdgeIntersection(const TetraEdge edge) const; 
00183 
00184     void calcIntersectionPtSurfaceEdge(const TetraEdge edge, double* pt) const;  
00185 
00186     inline bool testSegmentFacetIntersection(const TriSegment seg, const TetraFacet facet) const; 
00187 
00188     void calcIntersectionPtSegmentFacet(const TriSegment seg, const TetraFacet facet, double* pt) const;  
00189 
00190     bool testSegmentEdgeIntersection(const TriSegment seg, const TetraEdge edge) const; 
00191  
00192     void calcIntersectionPtSegmentEdge(const TriSegment seg, const TetraEdge edge, double* pt) const ; 
00193 
00194     bool testSegmentCornerIntersection(const TriSegment seg, const TetraCorner corner) const ;
00195 
00196     inline bool testSurfaceRayIntersection(const TetraCorner corner) const;
00197 
00198     bool testSegmentHalfstripIntersection(const TriSegment seg, const TetraEdge edg);
00199 
00200     void calcIntersectionPtSegmentHalfstrip(const TriSegment seg, const TetraEdge edge, double* pt) const;
00201     
00202     bool testSegmentRayIntersection(const TriSegment seg, const TetraCorner corner) const;
00203 
00204     inline bool testCornerInTetrahedron(const TriCorner corner) const;
00205 
00206     inline bool testCornerOnXYZFacet(const TriCorner corner) const;
00207 
00208     inline bool testCornerAboveXYZFacet(const TriCorner corner) const;
00209 
00210     // ----------------------------------------------------------------------------------
00211     //  Utility methods used in intersection tests                       
00212     // ----------------------------------------------------------------------------------
00213     
00214     bool testTriangleSurroundsEdge(const TetraEdge edge) const;
00215 
00216     inline bool testEdgeIntersectsTriangle(const TetraEdge edge) const;
00217 
00218     inline bool testFacetSurroundsSegment(const TriSegment seg, const TetraFacet facet) const;
00219 
00220     inline bool testSegmentIntersectsFacet(const TriSegment seg, const TetraFacet facet) const;
00221 
00222     bool testSegmentIntersectsHPlane(const TriSegment seg) const;
00223 
00224     bool testSurfaceAboveCorner(const TetraCorner corner) const;
00225     
00226     bool testTriangleSurroundsRay(const TetraCorner corner) const;
00227 
00228     // ----------------------------------------------------------------------------------
00229     //  Double and triple product calculations                           
00230     // ----------------------------------------------------------------------------------
00231     
00232     void resetNearZeroCoordinates();
00233 
00234     bool areDoubleProductsConsistent(const TriSegment seg) const;
00235 
00236     void preCalculateDoubleProducts(void);
00237 
00238     inline void resetDoubleProducts(const TriSegment seg, const TetraCorner corner);
00239 
00240     double calculateDistanceCornerSegment(const TetraCorner corner, const TriSegment seg) const;
00241     
00242     void preCalculateTripleProducts(void);
00243 
00244     double calculateAngleEdgeTriangle(const TetraEdge edge) const;
00245 
00246     inline double calcStableC(const TriSegment seg, const DoubleProduct dp) const;
00247 
00248     inline double calcStableT(const TetraCorner corner) const;
00249 
00250     inline double calcUnstableC(const TriSegment seg, const DoubleProduct dp) const;
00251 
00252     double calcTByDevelopingRow(const TetraCorner corner, const int row = 1, const bool project = false) const;
00253 
00254     // ----------------------------------------------------------------------------------
00255     //  Member variables                                                 
00256     // ----------------------------------------------------------------------------------
00257   protected:
00258 
00262     double _coords[15];
00263     
00265     bool _is_double_products_calculated;
00266 
00268     bool _is_triple_products_calculated; 
00269 
00273     double _doubleProducts[24];
00274 
00277     double _tripleProducts[4];
00278 
00281     std::vector<double*> _polygonA;
00282     
00285     std::vector<double*> _polygonB;
00286     
00289     double _barycenterA[3];
00290 
00293     //double _barycenterB[3];
00294 
00297     bool _validTP[4];
00298 
00300     double _volume;
00301     
00307     void preCalculateTriangleSurroundsEdge();
00308 
00311     bool _triangleSurroundsEdgeCache[NO_TET_EDGE];
00312 
00313     // ----------------------------------------------------------------------------------
00314     //  Constants                                                    
00315     // ----------------------------------------------------------------------------------
00316 
00317     // offsets : 0 -> x, 1 -> y, 2 -> z, 3 -> h, 4 -> H
00318     // corresponds to order of double products in DoubleProduct
00319     // so that offset[C_*] gives the right coordinate
00320     static const int DP_OFFSET_1[8];
00321     static const int DP_OFFSET_2[8];
00322 
00323     // the coordinates used in the expansion of triple products by a given row
00324     // in constellation (corner, row-1)
00325     // (0,1,2,3) <=> (x,y,z,h)
00326     static const int COORDINATE_FOR_DETERMINANT_EXPANSION[12];
00327 
00328     // contains the edge of the double product used when 
00329     // expanding the triple product determinant associated with each corner
00330     // by a given row
00331     static const DoubleProduct DP_FOR_DETERMINANT_EXPANSION[12];
00332     
00333     // values used to decide how imprecise the double products 
00334     // should be to set them to 0.0
00335     static const long double MACH_EPS;    // machine epsilon
00336     static const long double MULT_PREC_F; // precision of multiplications (Grandy : f)
00337     static const long double THRESHOLD_F; // threshold for zeroing (Grandy : F/f)
00338 
00339     static const double TRIPLE_PRODUCT_ANGLE_THRESHOLD;
00340 
00341     // correspondance facet - double product
00342     // Grandy, table IV
00343     static const DoubleProduct DP_FOR_SEG_FACET_INTERSECTION[12];
00344 
00345     // signs associated with entries in DP_FOR_SEGMENT_FACET_INTERSECTION
00346     static const double SIGN_FOR_SEG_FACET_INTERSECTION[12];
00347     
00348     // coordinates of corners of tetrahedron
00349     static const double COORDS_TET_CORNER[12];
00350     
00351     // indices to use in tables DP_FOR_SEG_FACET_INTERSECTION and SIGN_FOR_SEG_FACET_INTERSECTION
00352     // for the calculation of the coordinates (x,y,z) of the intersection points
00353     // for Segment-Facet and Segment-Edge intersections
00354     static const int DP_INDEX[12];
00355 
00356     // correspondance edge - corners
00357     static const TetraCorner CORNERS_FOR_EDGE[12];
00358 
00359     // correspondance edge - facets
00360     // facets shared by each edge
00361     static const TetraFacet FACET_FOR_EDGE[12];
00362 
00363     // correspondance edge - corners
00364     static const TetraEdge EDGES_FOR_CORNER[12];
00365    
00366     // double products used in segment-halfstrip test
00367     static const DoubleProduct DP_FOR_HALFSTRIP_INTERSECTION[12];
00368 
00369     // double products used in segment - ray test
00370     static const DoubleProduct DP_SEGMENT_RAY_INTERSECTION[21];
00371 
00372   };
00373 
00374   // include definitions of inline methods
00375 
00376 #include "TransformedTriangleInline.hxx"
00377 }
00378 
00379 
00380 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS