Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
corefinement-api.cc
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 //******************************************************************************
25 #include "corefinement-api.hh"
26 #include "g-map-vertex.hh"
27 #include "time.hh"
28 
29 // 2D Meshes:
30 #include "corefine-2d-sweeping.hh"
32 #include "boolean-operations-2d.hh"
33 // 3D:
34 #include "corefine-3d.hh"
35 #include "corefine-3d-face-face.hh"
36 #include "boolean-operations-3d.hh"
37 using namespace std;
38 using namespace GMap3d;
39 //******************************************************************************
41 {
42  assert(AMap != NULL);
43 
44  FMap = AMap;
45 }
46 //******************************************************************************
48 {
49 }
50 //******************************************************************************
51 void CCorefinementAPI::corefine2dMeshesSweeping(CDart * ADart1, CDart * ADart2,
52  const CVertex& ANormal)
53 {
54  assert(ADart1 != NULL);
55  assert(ADart2 != NULL);
56 
57  CCorefineSegmentsSweeping(FMap).corefine(ADart1, ADart2, ANormal);
58 }
59 //******************************************************************************
61  CDart * ADart2,
62  const CVertex & ANormal,
63  bool /*useBBox*/)
64 {
65  assert(ADart1 != NULL);
66  assert(ADart2 != NULL);
67 
68  CTime start, end;
69 
70  cout << endl << "Co-raffinement des maillages" << endl;
71  start.updateTime();
72 
73  CVertex * vertex = FMap->findVertex(ADart1);
74  CPlane plane(ANormal, *vertex);
75 
76  CCorefine2dPropagation(FMap, plane).corefine(ADart1, ADart2);
77 
78  end.updateTime();
79  cout << "Durée du co-raffinement : " << end - start << endl;
80 }
81 //******************************************************************************
82 void CCorefinementAPI::corefine3dMeshes(CDart * ADart1, CDart * ADart2)
83 {
84  assert(ADart1 != NULL);
85  assert(ADart2 != NULL);
86 
87  CTime start, end;
88 
89  start.updateTime();
90 
91  cout << endl << "Co-raffinement 3D des maillages" << endl;
92 // CCorefine3d(FMap, false).corefine(ADart1, ADart2);
93 
94  CCorefine3dFF coref(FMap, false);
95  coref.splitMeshes(ADart1, ADart2);
96 
97  end.updateTime();
98  cout << "Durée du co-raffinement : " << end - start << endl;
99 }
100 //******************************************************************************
101 void CCorefinementAPI::corefineMarked3dFaces(int AMark1, int AMark2)
102 {
103  CTime start, end;
104 
105  cout << endl << "Co-raffinement 3D des faces" << endl;
106  start.updateTime();
107 
108  CCorefine3dFF coref(FMap, false);
109  coref.corefine(AMark1, AMark2);
110 
111  end.updateTime();
112  cout << "Durée du co-raffinement : " << end - start << endl;
113 }
114 //******************************************************************************
115 void CCorefinementAPI::corefineMarked3dMeshesWith(int AMark, CDart * ADart)
116 {
117  assert(ADart != NULL);
118 
119  int vertex_di = FMap->getNewDirectInfo();
120  CCorefine3dFF coref(FMap, false, 1E-4, vertex_di);
121  CCorefine3dTools tools(FMap);
122  list<CDart*> objects;
123  CDart *d1, *d2;
124  CTime start, end;
125 
126  start.updateTime();
127 
128  FMap->pointDirectInfoToAttributeVertex(vertex_di);
129 
130  int tmp_mark = FMap->getNewMark();
131 
132  d2 = tools.findWellOrientedDart(ADart, vertex_di);
133  FMap->markOrbit(d2, ORBIT_CC, tmp_mark);
134 
135  for (CDynamicCoverageAll dca(FMap); dca.cont(); ++dca) {
136  if (FMap->isMarked(*dca, AMark) && !FMap->isMarked(*dca, tmp_mark)) {
137  d1 = tools.findWellOrientedDart(*dca, vertex_di);
138  FMap->markOrbit(d1, ORBIT_CC, tmp_mark);
139  objects.push_back(d1);
140  }
141  }
142 
143  FMap->unmarkAll(tmp_mark);
144  FMap->freeMark(tmp_mark);
145 
146  while (!objects.empty()) {
147  d1 = objects.front(), objects.pop_front();
148 
149  coref.corefine(d1, d2);
150  }
151 
152  FMap->freeDirectInfo(vertex_di);
153 
154  end.updateTime();
155  cout << "Durée total du calcul : " << end - start << endl;
156 }
157 //******************************************************************************
159  CDart * ADart2,
160  const CVertex & /*ANormal*/,
161  int ADifference1Mark,
162  int ADifference2Mark,
163  int AIntersectionMark,
164  int AUnionMark)
165 {
166  assert(ADart1 != NULL);
167  assert(ADart2 != NULL);
168 
169  CTime start, end;
170 
171  cout << endl << "Co-raffinement des maillages" << endl;
172  start.updateTime();
173 
174  CBooleanOperations2d ops(FMap, ADart1, ADart2, true);
175 
176  ops.computeResults();
177 
178  end.updateTime();
179  cout << "Durée du co-raffinement : " << end - start << endl;
180 
181  cout << "Extraction des opérations booléennes" << endl;
182  start.updateTime();
183 
184  if (ADifference1Mark >= 0) {
185  FMap->unmarkAll(ADifference1Mark);
186  ops.markResult(BO_Difference1, ADifference1Mark);
187  }
188 
189  if (ADifference2Mark >= 0) {
190  FMap->unmarkAll(ADifference2Mark);
191  ops.markResult(BO_Difference2, ADifference2Mark);
192  }
193 
194  if (AIntersectionMark >= 0) {
195  FMap->unmarkAll(AIntersectionMark);
196  ops.markResult(BO_Intersection, AIntersectionMark);
197  }
198 
199  if (AUnionMark >= 0) {
200  FMap->unmarkAll(AUnionMark);
201  ops.markResult(BO_Union, AUnionMark);
202  }
203 
204  end.updateTime();
205  cout << "Durée de l'extraction : " << end - start << endl;
206 }
207 //******************************************************************************
208 void CCorefinementAPI::booleanOperations3d(CDart * ADart1, CDart * ADart2,
209  int ADifference1Mark,
210  int ADifference2Mark,
211  int AIntersectionMark,
212  int AUnionMark)
213 {
214  assert(ADart1 != NULL);
215  assert(ADart2 != NULL);
216 
217  CTime start, end, total;
218 
219  cout << endl << "Co-raffinement des maillages" << endl;
220  start.updateTime();
221  total.updateTime();
222 
223  CBooleanOperations3d ops(FMap, ADart1, ADart2, false);
224 
225  ops.computeResults();
226 
227  end.updateTime();
228  cout << "Durée du co-raffinement : " << end - start << endl;
229 
230  cout << "Extraction des opérations booléennes" << endl;
231  start.updateTime();
232 
233  if (ADifference1Mark >= 0) {
234  FMap->unmarkAll(ADifference1Mark);
235  ops.markResult(BO_Difference1, ADifference1Mark);
236  }
237 
238  if (ADifference2Mark >= 0) {
239  FMap->unmarkAll(ADifference2Mark);
240  ops.markResult(BO_Difference2, ADifference2Mark);
241  }
242 
243  if (AIntersectionMark >= 0) {
244  FMap->unmarkAll(AIntersectionMark);
245  ops.markResult(BO_Intersection, AIntersectionMark);
246  }
247 
248  if (AUnionMark >= 0) {
249  FMap->unmarkAll(AUnionMark);
250  ops.markResult(BO_Union, AUnionMark);
251  }
252 
253  end.updateTime();
254  cout << "Durée de l'extraction : " << end - start << endl;
255  cout << "Durée totale : " << end - total << endl;
256 }
257 //******************************************************************************