00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __TRANSFORMED_TRIANGLE_HXX__
00021 #define __TRANSFORMED_TRIANGLE_HXX__
00022
00023 #include "INTERPKERNELDefines.hxx"
00024
00025 #include <vector>
00026
00027
00028
00029
00030
00031
00032
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
00110
00111
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
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
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
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
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
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
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
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
00294
00297 bool _validTP[4];
00298
00300 double _volume;
00301
00307 void preCalculateTriangleSurroundsEdge();
00308
00311 bool _triangleSurroundsEdgeCache[NO_TET_EDGE];
00312
00313
00314
00315
00316
00317
00318
00319
00320 static const int DP_OFFSET_1[8];
00321 static const int DP_OFFSET_2[8];
00322
00323
00324
00325
00326 static const int COORDINATE_FOR_DETERMINANT_EXPANSION[12];
00327
00328
00329
00330
00331 static const DoubleProduct DP_FOR_DETERMINANT_EXPANSION[12];
00332
00333
00334
00335 static const long double MACH_EPS;
00336 static const long double MULT_PREC_F;
00337 static const long double THRESHOLD_F;
00338
00339 static const double TRIPLE_PRODUCT_ANGLE_THRESHOLD;
00340
00341
00342
00343 static const DoubleProduct DP_FOR_SEG_FACET_INTERSECTION[12];
00344
00345
00346 static const double SIGN_FOR_SEG_FACET_INTERSECTION[12];
00347
00348
00349 static const double COORDS_TET_CORNER[12];
00350
00351
00352
00353
00354 static const int DP_INDEX[12];
00355
00356
00357 static const TetraCorner CORNERS_FOR_EDGE[12];
00358
00359
00360
00361 static const TetraFacet FACET_FOR_EDGE[12];
00362
00363
00364 static const TetraEdge EDGES_FOR_CORNER[12];
00365
00366
00367 static const DoubleProduct DP_FOR_HALFSTRIP_INTERSECTION[12];
00368
00369
00370 static const DoubleProduct DP_SEGMENT_RAY_INTERSECTION[21];
00371
00372 };
00373
00374
00375
00376 #include "TransformedTriangleInline.hxx"
00377 }
00378
00379
00380 #endif