Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
corefine-3d-face-face.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 COREFINE_3D_FACE_FACE_HH
25 #define COREFINE_3D_FACE_FACE_HH
26 
27 #include "corefine.hh"
28 #include "g-map-vertex.hh"
29 #include "corefine-3d-tools.hh"
31 #include "grid-3d.hh"
32 #include "time.hh"
33 
34 namespace GMap3d {
35 
38  typedef std::set<TInterPt*, TInterPtCmp> TInterPtSet;
39 // typedef std::list<CDart*> TFaceSet;
40  typedef std::multiset<CDart*, CAngularFaceComparator> TFaceSet;
41 
42  struct SCorefFace
43  {
45  SCorefFace(CDart * AFace, const CPlane & APlane, const CBoundingBox & ABox)
46  : face(AFace), plane(APlane), box(ABox) {}
47  CDart *face;
48  CPlane plane;
49  CBoundingBox box;
50  };
51 
52  typedef std::list<SCorefFace> TCorefFaceList;
53 
54  typedef CGrid3d< std::pair< std::list<CDart*>,
55  std::list<CDart*> > > TCorefFaceGrid;
56  typedef CGrid3dIterator< std::pair< std::list<CDart*>,
57  std::list<CDart*> > > TCorefFaceGridIter;
58 
59  class CCorefine3dFF : public CCorefine
60  {
61  public:
62  CCorefine3dFF(CGMapVertex * AMap, bool ACalculateOrientation = true,
63  TCoordinate AEpsilon = 1E-4, int AVertexDI = -1);
64  virtual ~CCorefine3dFF();
65 
66  void calculateOrientation(bool AState) { FCalculateOrientation = AState; }
67  void optimizeSearch(bool AState) { FOptimizeSearch = AState; }
69  void setDisplayMessagesLevel(int ALevel) { FDisplayMessages = ALevel; }
70 
71  const CTime & getInitialisationTime() const { return FInitialisationTime; }
72  const CTime & getFaceListCreationTime() const { return FFaceListCreationTime; }
73  const CTime & getFaceListReductionTime() const { return FFaceListReductionTime; }
74  const CTime & getSplitTime() const { return FSplitTime; }
75  const CTime & getMergeTime() const { return FMergeTime; }
76 
77  virtual int corefine(CDart *& AMesh1, CDart *& AMesh2,
78  std::bitset<NB_MARKS> ACopyMarks = 0);
79  virtual int corefine(int AMark1, int AMark2,
80  std::bitset<NB_MARKS> ACopyMarks = 0);
81 
82  virtual void splitMeshes(CDart * AMesh1, CDart * AMesh2,
83  std::bitset<NB_MARKS> ACopyMarks = 0);
84  virtual void splitMeshes(int AMark1, int AMark2,
85  std::bitset<NB_MARKS> ACopyMarks = 0);
86  virtual void mergeMeshes();
87  virtual void removeDoubleFaces(CDart **ADarts = NULL, int ANbDarts = 0);
88  virtual void linkCompounds(CDart * AMesh1, CDart * AMesh2,
89  std::bitset<NB_MARKS> ACopyMarks = 0);
90 
91  virtual void markIntersectionEdges(int AMark, int AObjectsToMark = 3);
92  virtual void markDoubleFaces(int AMark);
93  virtual void spreadMarksWithoutMerging(std::bitset<NB_MARKS> AMarks);
94 
95  virtual void clear();
96 
97  const std::list<CDart*> & getInterEdgesList() const {return FInterEdges; }
98  const std::list<CDart*> & getDoubleFacesList() const {return FDoubleFaces;}
99 
100  protected:
101 
102  virtual void splitMeshes(std::bitset<NB_MARKS> ACopyMarks = 0);
103 
104  bool checkEdges();
105 
106  void pointDirectInfoToData(int ADirectInfo, CDart * ADart,
107  TOrbit AOrbit, void * AData);
108 
109  virtual CBoundingBox initMesh(CDart * AMesh);
110  virtual void cleanMesh(CDart * AMesh);
111  virtual CBoundingBox initFaces(int AMark);
112 
113  SCorefFace computeFaceInfos(CDart * AFace, int AMark);
114  TCorefFaceList * buildFaceList(CDart * AMesh);
115  TCorefFaceList * buildFaceList(int AMark);
116  void reduceFaceLists(TCorefFaceList * AList1, TCorefFaceList * AList2,
117  const CBoundingBox & ABox);
118  void updateFaceInList(TCorefFaceList * AList, TCorefFaceList::iterator AElt,
119  std::list<CDart*> * AFaces);
120 
121  bool isVertexLinkedWithFace(CDart * AVertex, int AFaceMark);
122  void markFaceVertex(CDart * AVertex, int AFaceMark, int AMark);
123  CDart * getTwinDartOnFace(CDart * ADart, int AFaceMark);
124  CDart * findFaceSector(CDart * AFaceVertex, const CPlane & AFacePlane,
125  int AFaceMark, const CVertex & AVector);
126  CDart * findNearestFaceVertex(CDart * AFace,
127  const CPlane & ARefPlane,
128  const CPlane & AClipPlane1,
129  const CPlane & AClipPlane2);
130  CVertex edgeInsideVector(CDart * AEdge, const CPlane & AFacePlane);
131  CVertex vertexInsideVector(CDart * AVertex, const CPlane & AFacePlane);
132 
133  void classifyFaceVertices(CDart * AFace, const CPlane & APlane,
134  int APositiveMark, int ANegativeMark,
135  int AFacesMark, bool AUseVerticesLinks = true,
136  int * ANbVertices = NULL,
137  int * ANbPositiveVertices = NULL,
138  int * ANbNegativeVertices = NULL);
139  void getFaceFictiveElements(CDart * AFace, int AFaceMark,
140  std::list<CDart*> * AFictVertices,
141  std::list<CDart*> * AFictEdges);
142 
143 // TInterPt * testVertexIntersection(CDart * AVertex, const CPlane & APlane,
144 // int APositiveMark, int ANegativeMark,
145 // int AFacesMark);
146  void testPointInside(CDart * AVertex, TInterPt * APoint, int AFaceMark,
147  const CVertex & AInterLine, const CPlane & AFacePlane);
148  void testPointBorder(CDart * AVertex,
149  TInterPt * ANewPoint, TInterPt * AOldPoint,
150  const TInterPtCmp & AComparator);
151  TInterPtSet * findIntersectionPoints(CDart * AFace,
152  const CPlane & AFacePlane,
153  const CPlane & AInterPlane,
154  const CVertex & AInterLine,
155  int APositiveMark, int ANegativeMark,
156  int AFacesMark,
157  const TInterPtCmp & AComparator);
158 // TInterPtSet * findIntersectionPoints(CDart * AFace,
159 // const CPlane & AFacePlane,
160 // const CPlane & AInterPlane,
161 // const CVertex & AInterLine,
162 // int AFacesMark,
163 // const TInterPtCmp & AComparator,
164 // std::list<CDart*> * AFictVertices,
165 // std::list<CDart*> * AFictEdges);
166 
167  virtual CDart * createEdge();
168  virtual CDart * insertVertexInFace(CDart * AFace, const CVertex & APoint);
169  virtual CDart * insertEdgeInFace(CDart * AVertex1,
170  const CVertex & AVertex2);
171  virtual CDart * splitEdge(CDart * AEdge, const CVertex & APoint,
172  std::list<CDart*> * AFictiveEdges = NULL);
173  virtual CDart * splitFace(CDart * AVertex1, CDart * AVertex2);
174 
175  bool isUselessFictiveVertex(CDart * AVertex);
176  bool isUselessFictiveEdge(CDart * AEdge);
177  bool isWholeFaceMarked(CDart * AFace, int AMark);
178  virtual CDart * copyDoubleFaceData(CDart * AFace);
179  virtual CDart * removeFictiveVertex(CDart * AVertex, int ADeleteMark = -1);
180  virtual CDart * removeFictiveEdge(CDart * AEdge, int ADeleteMark = -1);
181  virtual CDart * removeDoubleFace(CDart * AFace);
182 
183  void linkVertices(CDart * AVertex1, CDart * AVertex2);
184  void addIntersectionPoint(CDart *AVertices[2], int AFaceNumber,
185  int AFacesMark, int AInterMark,
186  std::list<CDart*> * AInterList);
187 
188  virtual bool intersectFaces(CDart * AFace1, CDart * AFace2,
189  const CPlane & APlane1,
190  const CPlane & APlane2,
191  std::list<CDart*> * AFaceList1,
192  std::list<CDart*> * AFaceList2);
193 
194  virtual void intersectSecantFaces(CDart * AFace1, CDart * AFace2,
195  const CPlane & APlane1,
196  const CPlane & APlane2,
197  int APositiveMark, int ANegativeMark,
198  int AFacesMark,
199  std::list<CDart*> * AFictiveVertices,
200  std::list<CDart*> * AFictiveEdges);
201 
202  virtual void intersectCoplanarFaces(CDart * AFace1, CDart * AFace2,
203  const CPlane & APlane1,
204  const CPlane & APlane2,
205  int APositiveMark, int ANegativeMark,
206  int AFacesMark,
207  std::list<CDart*> * AFictiveVertices,
208  std::list<CDart*> * AFictiveEdges);
209 
210 // virtual bool intersectSecantFaces(CDart * AFace1, CDart * AFace2,
211 // const CPlane & APlane1,
212 // const CPlane & APlane2,
213 // std::list<CDart*> * AFaceList1,
214 // std::list<CDart*> * AFaceList2);
215 
216  void assignFacesPlaneInfo(int ADirectInfo, int ANegativeMark,
217  TCorefFaceList * AList);
218  void removeFacesPlaneInfo(int ADirectInfo, int ANegativeMark,
219  TCorefFaceList * AList);
220  void sortFacesAroundEdges(int AFacePlaneDI, int ANegativeMark);
221  TFaceSet * sortFacesAroundEdges(CDart * AEdge1, CDart * AEdge2,
222  int AFacePlaneDI, int ANegativeMark);
223  void linkSortedFaces(TFaceSet * AFaceSet);
224  void spreadMarksAroundEdges(TFaceSet * AFaceSet,
225  std::bitset<NB_MARKS> AMarks);
226 
227  bool isPointInFace(const CVertex & APoint, CDart * AFace,
228  const CPlane & APlane);
229 
230  protected:
237 
241  CTime FSplitTime;
242  CTime FMergeTime;
243 
247 
253 
255  std::list<CDart*> FInterEdges;
256  std::list<CDart*> FDoubleFaces;
257  };
258 
259 }
260 
261 #endif // COREFINE_3D_FACE_FACE_HH