Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
corefine-3d.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_HH
25 #define COREFINE_3D_HH
26 
27 #include "inline-macro.hh"
28 #include "corefine.hh"
29 #include "attribute-bounding-box.hh"
30 #include "corefine-3d-tools.hh"
31 #include "edge-intersection.hh"
32 #include "grid-3d.hh"
33 #include "grid-tree-3d.hh"
34 #include "time.hh"
35 
36 namespace GMap3d {
37 
38  typedef CGridTree3d<std::list<CDart*>*> TFaceGrid;
39  typedef CGridTree3dIterator<std::list<CDart*>*> TFaceGridIter;
40 
41  class CCorefine3d : public CCorefine
42  {
43  public:
44 
45  CCorefine3d(CGMapVertex * AMap, bool ACalculateOrientation = true,
46  TCoordinate AEpsilon = 1E-4, int AVertexDI = -1);
47  ~CCorefine3d();
48 
49  void computeOnlyFirstIntersection(bool ABoolean);
50  void setGridResolution(int ARes);
51 
52  virtual int corefine(CDart *& AMesh1, CDart *& AMesh2,
53  std::bitset<NB_MARKS> ACopyMarks = 0);
54 
55  const CTime & getInitialisationTime() const { return FInitialisationTime; }
56  const CTime & getGridCreationTime() const { return FGridCreationTime; }
57  const CTime & getResearchTime() const { return FResearchTime; }
58  const CTime & getLineCreationTime() const { return FLineCreationTime; }
59  const CTime & getUpdateTime() const { return FUpdateTime; }
60 
61  protected:
62 
63  virtual unsigned long initMesh(CDart * AMesh);
64  virtual void cleanMesh(CDart * AMesh);
65 
66  void createGrid(CDart * AMesh, unsigned long ANbFaces);
67  void destroyGrid();
68 
69  unsigned int getMaxVerticesDegree(std::list<CDart*> * AList);
70  CVertex normalizeGridSize(const CVertex & AGridSize);
71  void getGridResolution(const CVertex & AGridSize,
72  unsigned int AMinRes,
73  unsigned int AMaxRes,
74  unsigned int * AResX,
75  unsigned int * AResY,
76  unsigned int * AResZ);
77  void computeGridResolution(const CVertex & AGridSize,
78  unsigned long ANbFaces,
79  TCoordinate ANbFacesPerCell,
80  unsigned int * AResX,
81  unsigned int * AResY,
82  unsigned int * AResZ,
83  unsigned int AMinRes = 1,
84  unsigned int AMaxRes = 512);
85  unsigned int refineGrid(unsigned int AMaxSubDiv,
86  unsigned int AMaxNumberOfFaces);
87 
88  void addFaceToGrid(TFaceGrid * AGrid, CDart * AFace);
89  void removeFaceFromGrid(TFaceGrid * AGrid, CDart * AFace);
90 
91  void updateVertexLinks(CDart * ADart, CAttributeVertex * AVertex);
92  void updateVertexLinks(CDart * ADart);
93  CVertex * getVertex(CDart * ADart);
94 
95  void updateFaceLinks(CDart * AFace);
96  CDart * getFace(CDart * ADart);
97 
98  CDart * createEdge();
99 
100  virtual CDart * insertVertexInFace(CDart * AFace, const CVertex & APoint);
101  virtual CDart * insertEdgeInFace(CDart * AVertex1, const CVertex & AVertex2);
102  virtual CDart * splitFace(CDart * AVertex1, CDart * AVertex2);
103  virtual CDart * splitEdge(CDart * AVertex, const CVertex & APoint);
104  virtual CDart * removeEdge(CDart * AEdge, int ADeleteMark = -1);
105  CVertex getProjectionOnPlane(CDart * AVertex, const CPlane & APlane);
106 
107  bool isSameEdge_Naive(CDart * AEdge1, CDart * AEdge2);
108  bool isSameEdge_Optimized(CDart * AEdge1, CDart * AEdge2);
109  bool areFacesLinked(CDart * AFace1, CDart * AFace2);
110 
111  CEdgeIntersection findNearestIntersectionInGrid(const CVertex & AVertex1,
112  const CVertex & AVertex2);
113 
114  CDart * findFirstIntersectionInGrid(const CVertex & AVertex, int * ADim);
115 
116  void followIntersection(CDart * AVertex1, CDart * AVertex2, int AMark);
117 
118  bool manageFacesIntersection(CDart * AFace1, const CPlane & APlane1,
119  CDart * AFace2, const CPlane & APlane2,
120  int AMark, std::list<CDart*> * AList);
121 
122  void createIntersectionEdge(CDart * AFace1, CDart * AFace2,
123  const CPlane & APlane1,
124  const CPlane & APlane2,
125  const CEdgeIntersection & AInter1,
126  const CEdgeIntersection & AInter2,
127  int AMark, std::list<CDart*> * AList);
128 
129  void applyModifications(CDart * AMesh);
130 
131  void extractIntersectionLines(CDart * AMesh);
132 
133  private:
134 
135  int FVertexDI;
136  int FFaceDI;
137 
138  int FAlpha2DI;
139 
140  int FOrientMark;
141  int FFictiveMark;
142  int FIntersectionMark;
143 
144  int FNumberOfIntersectionLines;
145  int FNumberOfIntersectionEdges;
146 
147  bool FLocalVertexDirectInfo;
148  bool FCalculateOrientation;
149  bool FComputeOnlyFirstIntersection;
150  int FGridResolution;
151 
152  CTime FInitialisationTime;
153  CTime FGridCreationTime;
154  CTime FResearchTime;
155  CTime FLineCreationTime;
156  CTime FUpdateTime;
157 
158  CCorefine3dTools FTools;
159 
160  TFaceGrid * FGrid;
161  };
162 
163 } // namespace GMap3d
164 
165 #include INCLUDE_INLINE("corefine-3d.icc")
166 
167 #endif