Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operations-corefinement.cc
Go to the documentation of this file.
1 /*
2  * lib-controler-gmap : Le contrôleur de 3-G-cartes, surcouche de lib-controler.
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-controler-gmap
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 #ifdef MODULE_COREFINEMENT
26 //******************************************************************************
27 #include "g-map-vertex.hh"
28 #include "controler-gmap.hh"
29 #include <cassert>
30 
31 #include "corefinement-api.hh"
32 #include "geometry.hh"
33 
34 using namespace GMap3d;
35 
36 //******************************************************************************
37 bool CControlerGMap::check2dCorefinability(CDart ** d1, CDart ** d2,
38  CVertex * normal) // :)
39 {
40  assert(d1 != NULL);
41  assert(d2 != NULL);
42  assert(normal != NULL);
43 
44  if (FMap->getMarkedCells(ORBIT_CC, getSelectionMark(), NULL, d1) != 1)
45  {
46  setMessage("Selection 1 not correct");
47  return false;
48  }
49 
50  if (!FMap->isIFreeOrbit(*d1, 3, ORBIT_CC))
51  {
52  setMessage("Mesh 1 invalid: all the darts must be 3-free");
53  return false;
54  }
55 
56  if (FMap->getMarkedCells(ORBIT_CC, getNextSelectionMark(1), NULL, d2) != 1)
57  {
58  setMessage("Selection 2 not correct");
59  return false;
60  }
61 
62  if (!FMap->isIFreeOrbit(*d2, 3, ORBIT_CC))
63  {
64  setMessage("Mesh 2 invalid: all the darts must be 3-free");
65  return false;
66  }
67 
68  CVertex n1 = FMap->cellDimensionNormalVector(*d1, 3);
69  CVertex n2 = FMap->cellDimensionNormalVector(*d2, 3);
70 
71  TCoordinate angle = CGeometry::getAngle(n1,n2);
72 
73  if (angle>90)
74  angle = 180 - angle;
75 
76  if (fabs(angle) > 0.5)
77  {
78  setMessage("The two meshes are not parallel");
79  return false;
80  }
81 
82  CVertex bary1 = FMap->barycenter(*d1, ORBIT_CC);
83  CVertex bary2 = FMap->barycenter(*d2, ORBIT_CC);
84 
85  if (!(bary1 - CGeometry::orthoProjectVertexOnPlane(bary1, bary2,n2)).isNull())
86  {
87  setMessage("The two meshes are not coplanar");
88  return false;
89  }
90 
91  if (angle > 90)
92  n2 = - n2;
93 
94  * normal = n1 + n2;
95 
96  if (normal->isNull())
97  * normal = OZ;
98  else
99  * normal /= normal->norm();
100 
101  return true;
102 }
103 //******************************************************************************
105 {
108  {
109  CDart * d1, * d2;
110  CVertex normal;
111 
112  // À modifier:
113  if (!check2dCorefinability(& d1, & d2, & normal))
114  return false;
115 
116  undoRedoPreSave();
117  CCorefinementAPI(FMap).corefine2dMeshesSweeping(d1,d2, normal);
119 
120  setModelChanged();
121  setMessage("Co-refinement by sweeping line done");
122  return true;
123  }
124 
125  return false;
126 }
127 //******************************************************************************
129 {
132  {
133  CCorefinementAPI corefinator(FMap);
134  CDart * d1, * d2;
135  CVertex normal;
136 
137  if (!check2dCorefinability(& d1, & d2, & normal))
138  return false;
139 
140  undoRedoPreSave();
141  corefinator.corefine2dMeshesPropagation(d1, d2, normal);
143 
144  setModelChanged();
145  setMessage("Co-refinement 2D by propagation done");
146  return true;
147  }
148 
149  return false;
150 }
151 //******************************************************************************
153 {
156  CCorefinementAPI coref(FMap);
157  CDart *d1, *d2;
158  CVertex normal;
159 
160  if (FMap->getMarkedCells(ORBIT_CC, getSelectionMark(), NULL, &d1) != 1) {
161  setMessage("Selection 1 not correct");
162  return false;
163  }
164 
165  if (FMap->getMarkedCells(ORBIT_CC, getNextSelectionMark(1),
166  NULL, &d2) != 1) {
167  setMessage("Selection 2 not correct");
168  return false;
169  }
170 
171  if (!check2dCorefinability(& d1, & d2, & normal))
172  return false;
173 
174  undoRedoPreSave();
175  coref.booleanOperations2d(d1, d2, normal,
180 
181  setModelChanged();
182  setMessage("2D boolean operations done");
183  return true;
184  }
185 
186  return false;
187 }
188 //******************************************************************************
190 {
193  {
194  CCorefinementAPI corefinator(FMap);
195  CDart * d1, * d2;
196 
197  if (FMap->getMarkedCells(ORBIT_CC, getSelectionMark(), NULL, &d1) != 1)
198  {
199  setMessage("Selection 1 not correct");
200  return false;
201  }
202 
203  if (FMap->getMarkedCells(ORBIT_CC, getNextSelectionMark(1),
204  NULL, &d2) != 1)
205  {
206  setMessage("Selection 2 not correct");
207  return false;
208  }
209 
210  undoRedoPreSave();
211  corefinator.corefine3dMeshes(d1, d2);
213 
214  setModelChanged();
215  setMessage("Co-refinement 3D done");
216  return true;
217  }
218 
219  return false;
220 }
221 //******************************************************************************
223 {
226  {
227  CCorefinementAPI corefinator(FMap);
228  CDart *d;
229 
230  if (FMap->getMarkedCells(ORBIT_CC, getNextSelectionMark(1),
231  NULL, &d) != 1)
232  {
233  setMessage("Selection 1 not correct");
234  return false;
235  }
236 
237  undoRedoPreSave();
238  corefinator.corefineMarked3dMeshesWith(getSelectionMark(), d);
240 
241  setModelChanged();
242  setMessage("Co-refinement 3D done");
243  return true;
244  }
245 
246  return false;
247 }
248 //******************************************************************************
250 {
253  CCorefinementAPI coref(FMap);
254  CDart *d1, *d2;
255 
256  if (FMap->getMarkedCells(ORBIT_CC, getSelectionMark(), NULL, &d1) != 1) {
257  setMessage("Selection 1 not correct");
258  return false;
259  }
260 
261  if (FMap->getMarkedCells(ORBIT_CC, getNextSelectionMark(1),
262  NULL, &d2) != 1) {
263  setMessage("Selection 2 not correct");
264  return false;
265  }
266 
267  undoRedoPreSave();
268  coref.booleanOperations3d(d1, d2,
273 
274  setModelChanged();
275  setMessage("3D boolean operations done");
276  return true;
277  }
278 
279  return false;
280 }
281 //******************************************************************************
283 {
286  {
287  CCorefinementAPI corefinator(FMap);
288  CDart * d1, * d2;
289 
290  if (FMap->getMarkedCells(ORBIT_CC, getSelectionMark(), NULL, &d1) != 1)
291  {
292  setMessage("Selection 1 not correct");
293  return false;
294  }
295 
296  if (FMap->getMarkedCells(ORBIT_CC, getNextSelectionMark(1),
297  NULL, &d2) != 1)
298  {
299  setMessage("Selection 2 not correct");
300  return false;
301  }
302 
303  undoRedoPreSave();
304  corefinator.corefine3dMeshes(d1, d2);
306 
307  setModelChanged();
308  setMessage("Co-refinement 3D done");
309  return true;
310  }
311 
312  return false;
313 }
314 //******************************************************************************
316 {
319  {
320  CCorefinementAPI corefinator(FMap);
321 
322  undoRedoPreSave();
323  corefinator.corefineMarked3dFaces(getSelectionMark(),
326 
327  setModelChanged();
328  setMessage("Co-refinement 3D done");
329  return true;
330  }
331 
332  return false;
333 }
334 //******************************************************************************
335 #endif // COREFINEMENT
336 //******************************************************************************