Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
face-intersection-tools.hh
Go to the documentation of this file.
1 /*
2  * lib-corefinement : Opérations de corafinement.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-corefinement
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef FACE_INTERSECTION_TOOLS_HH
25 #define FACE_INTERSECTION_TOOLS_HH
26 
27 #include "message-macros.hh"
28 
29 #include "g-map-vertex.hh"
30 #include "general-tools.hh"
31 #include "plane.hh"
32 
33 namespace GMap3d {
34 
37 
38  std::ostream & operator << (std::ostream & AStream, TPositionInFace APos);
39 
41  {
42  public:
43  CIntersectionPoint(const CVertex & APoint = ORIGIN, int ADim = 0,
45  : FPoint(APoint), FEnteringSector(NULL), FLeavingSector(NULL),
46  FCellDim(ADim), FPos(APos) {}
47 
48  const CVertex & getPoint () const { return FPoint; }
49  CDart * getEnteringSector() const { return FEnteringSector; }
50  CDart * getLeavingSector () const { return FLeavingSector; }
51  int getCellDim () const { return FCellDim; }
52  TPositionInFace getPosition () const { return FPos; }
53 
54  void setPoint (const CVertex & APoint){ FPoint = APoint; }
55  void setEnteringSector(CDart * ASector) { FEnteringSector = ASector; }
56  void setLeavingSector (CDart * ASector) { FLeavingSector = ASector; }
57  void setCellDim (int ADim) { FCellDim = ADim; }
58  void setPosition (TPositionInFace APos) { FPos = APos; }
59 
60  private:
61  CVertex FPoint;
62  CDart *FEnteringSector;
63  CDart *FLeavingSector;
64  int FCellDim;
65  TPositionInFace FPos;
66  };
67 
69  {
70  public:
71  CIntersectionPointComparator(CGeneralTools * ATools,
72  const CVertex & AIntersectionLine = ORIGIN)
73  : FTools(ATools), FInterLine(AIntersectionLine) {}
74 
75  const CVertex & getIntersectionLine() const { return FInterLine; }
76  void setIntersectionLine(const CVertex & ALine) { FInterLine = ALine; }
77 
78  bool operator () (const CIntersectionPoint * APoint1,
79  const CIntersectionPoint * APoint2) const
80  {
81  assert(APoint1->getPoint().getX() != APoint2->getPoint().getX() ||
82  APoint1->getPoint().getY() != APoint2->getPoint().getY() ||
83  APoint1->getPoint().getZ() != APoint2->getPoint().getZ());
84 // if (FTools->arePointsEqual(APoint1->getPoint(), APoint2->getPoint())) {
85 // std::cerr << "CIntersectionPointComparator: " << APoint1->getPoint()
86 // << " = " << APoint2->getPoint() << std::endl;
87 // exit(0);
88 // }
89  return (APoint2->getPoint() -
90  APoint1->getPoint()).dot(FInterLine) > 0.0;
91  }
92 
93  private:
94  CGeneralTools *FTools;
95  CVertex FInterLine;
96  };
97 
99  {
100  public:
101  CAngularFaceComparator(CGMapVertex * AMap, CGeneralTools * ATools,
102  const CVertex & AAxis, const CVertex & ARef,
103  int AVertexDI, int AFacePlaneDI, int ANegativeMark)
104  : FMap(AMap), FTools(ATools), FAxis(AAxis), FRefX(ARef),
105  FVertexDI(AVertexDI), FFacePlaneDI(AFacePlaneDI),
106  FNegativeMark(ANegativeMark)
107  {
108  FRefY = FAxis * FRefX;
109  }
110 
111  int getArea(const CVertex & AVector)
112  {
113  if (AVector.dot(FRefX) > 0.0) {
114  if (AVector.dot(FRefY) > 0.0) return 0;
115  else return 3;
116  }
117  else {
118  if (AVector.dot(FRefY) > 0.0) return 1;
119  else return 2;
120  }
121  }
122 
123  bool operator () (CDart * AFace1, CDart * AFace2)
124  {
125  CVertex n1, n2;
126  CPlane *plane;
127 
128  plane = (CPlane*)FMap->getDirectInfo(AFace1, FFacePlaneDI);
129  if (plane)
130  n1 = (FMap->isMarked(AFace1, FNegativeMark) ?
131  -plane->getNormal() : plane->getNormal());
132  else {
133  FUNC_WARN("Calcul de la normale à une face non sélectionnée !");
134  n1 = FTools->faceNormalVector(AFace1, FVertexDI);
135  }
136 
137  plane = (CPlane*)FMap->getDirectInfo(AFace2, FFacePlaneDI);
138  if (plane)
139  n2 = (FMap->isMarked(AFace2, FNegativeMark) ?
140  -plane->getNormal() : plane->getNormal());
141  else {
142  FUNC_WARN("Calcul de la normale à une face non sélectionnée !");
143  n2 = FTools->faceNormalVector(AFace2, FVertexDI);
144  }
145 
146  int area1 = getArea(n1);
147  int area2 = getArea(n2);
148 
149  if (area1 == area2)
150  return (n1 * n2).dot(FAxis) > 0.0;
151  else
152  return
153  area1 < area2;
154  }
155 
156  private:
157  CGMapVertex *FMap;
158  CGeneralTools *FTools;
159  CVertex FAxis, FRefX, FRefY;
160  int FVertexDI;
161  int FFacePlaneDI;
162  int FNegativeMark;
163  };
164 
165 }
166 
167 #endif // FACE_INTERSECTION_TOOLS_HH