00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FACE_INTERSECTION_TOOLS_HH
00025 #define FACE_INTERSECTION_TOOLS_HH
00026
00027 #include "message-macros.hh"
00028
00029 #include "g-map-vertex.hh"
00030 #include "general-tools.hh"
00031 #include "plane.hh"
00032
00033 namespace GMap3d {
00034
00035 enum TPositionInFace {FP_Outside, FP_Inside,
00036 FP_OnBorder, FP_OnReversedBorder};
00037
00038 std::ostream & operator << (std::ostream & AStream, TPositionInFace APos);
00039
00040 class CIntersectionPoint
00041 {
00042 public:
00043 CIntersectionPoint(const CVertex & APoint = ORIGIN, int ADim = 0,
00044 TPositionInFace APos = FP_Outside)
00045 : FPoint(APoint), FEnteringSector(NULL), FLeavingSector(NULL),
00046 FCellDim(ADim), FPos(APos) {}
00047
00048 const CVertex & getPoint () const { return FPoint; }
00049 CDart * getEnteringSector() const { return FEnteringSector; }
00050 CDart * getLeavingSector () const { return FLeavingSector; }
00051 int getCellDim () const { return FCellDim; }
00052 TPositionInFace getPosition () const { return FPos; }
00053
00054 void setPoint (const CVertex & APoint){ FPoint = APoint; }
00055 void setEnteringSector(CDart * ASector) { FEnteringSector = ASector; }
00056 void setLeavingSector (CDart * ASector) { FLeavingSector = ASector; }
00057 void setCellDim (int ADim) { FCellDim = ADim; }
00058 void setPosition (TPositionInFace APos) { FPos = APos; }
00059
00060 private:
00061 CVertex FPoint;
00062 CDart *FEnteringSector;
00063 CDart *FLeavingSector;
00064 int FCellDim;
00065 TPositionInFace FPos;
00066 };
00067
00068 class CIntersectionPointComparator
00069 {
00070 public:
00071 CIntersectionPointComparator(CGeneralTools * ATools,
00072 const CVertex & AIntersectionLine = ORIGIN)
00073 : FTools(ATools), FInterLine(AIntersectionLine) {}
00074
00075 const CVertex & getIntersectionLine() const { return FInterLine; }
00076 void setIntersectionLine(const CVertex & ALine) { FInterLine = ALine; }
00077
00078 bool operator () (const CIntersectionPoint * APoint1,
00079 const CIntersectionPoint * APoint2) const
00080 {
00081 assert(APoint1->getPoint().getX() != APoint2->getPoint().getX() ||
00082 APoint1->getPoint().getY() != APoint2->getPoint().getY() ||
00083 APoint1->getPoint().getZ() != APoint2->getPoint().getZ());
00084
00085
00086
00087
00088
00089 return (APoint2->getPoint() -
00090 APoint1->getPoint()).dot(FInterLine) > 0.0;
00091 }
00092
00093 private:
00094 CGeneralTools *FTools;
00095 CVertex FInterLine;
00096 };
00097
00098 class CAngularFaceComparator
00099 {
00100 public:
00101 CAngularFaceComparator(CGMapVertex * AMap, CGeneralTools * ATools,
00102 const CVertex & AAxis, const CVertex & ARef,
00103 int AVertexDI, int AFacePlaneDI, int ANegativeMark)
00104 : FMap(AMap), FTools(ATools), FAxis(AAxis), FRefX(ARef),
00105 FVertexDI(AVertexDI), FFacePlaneDI(AFacePlaneDI),
00106 FNegativeMark(ANegativeMark)
00107 {
00108 FRefY = FAxis * FRefX;
00109 }
00110
00111 int getArea(const CVertex & AVector)
00112 {
00113 if (AVector.dot(FRefX) > 0.0) {
00114 if (AVector.dot(FRefY) > 0.0) return 0;
00115 else return 3;
00116 }
00117 else {
00118 if (AVector.dot(FRefY) > 0.0) return 1;
00119 else return 2;
00120 }
00121 }
00122
00123 bool operator () (CDart * AFace1, CDart * AFace2)
00124 {
00125 CVertex n1, n2;
00126 CPlane *plane;
00127
00128 plane = (CPlane*)FMap->getDirectInfo(AFace1, FFacePlaneDI);
00129 if (plane)
00130 n1 = (FMap->isMarked(AFace1, FNegativeMark) ?
00131 -plane->getNormal() : plane->getNormal());
00132 else {
00133 FUNC_WARN("Calcul de la normale à une face non sélectionnée !");
00134 n1 = FTools->faceNormalVector(AFace1, FVertexDI);
00135 }
00136
00137 plane = (CPlane*)FMap->getDirectInfo(AFace2, FFacePlaneDI);
00138 if (plane)
00139 n2 = (FMap->isMarked(AFace2, FNegativeMark) ?
00140 -plane->getNormal() : plane->getNormal());
00141 else {
00142 FUNC_WARN("Calcul de la normale à une face non sélectionnée !");
00143 n2 = FTools->faceNormalVector(AFace2, FVertexDI);
00144 }
00145
00146 int area1 = getArea(n1);
00147 int area2 = getArea(n2);
00148
00149 if (area1 == area2)
00150 return (n1 * n2).dot(FAxis) > 0.0;
00151 else
00152 return
00153 area1 < area2;
00154 }
00155
00156 private:
00157 CGMapVertex *FMap;
00158 CGeneralTools *FTools;
00159 CVertex FAxis, FRefX, FRefY;
00160 int FVertexDI;
00161 int FFacePlaneDI;
00162 int FNegativeMark;
00163 };
00164
00165 }
00166
00167 #endif // FACE_INTERSECTION_TOOLS_HH