1 |
#include <vector>
|
2 |
#include <string>
|
3 |
#include <sstream>
|
4 |
#include <fstream>
|
5 |
#include <algorithm>
|
6 |
#include <math.h>
|
7 |
#pragma hdrstop
|
8 |
|
9 |
// Headers of Magic
|
10 |
|
11 |
#include "gestionversion.h"
|
12 |
#include "lc_point.h"
|
13 |
#include "step_point.h"
|
14 |
|
15 |
#include "CAD4FE_MCFace.h"
|
16 |
#include "CAD4FE_MCEdge.h"
|
17 |
#include "CAD4FE_PolyCurve.h"
|
18 |
#include "CAD4FE_PolySurface.h"
|
19 |
#include "CAD4FE_MCVertex.h"
|
20 |
#include "mg_maillage.h"
|
21 |
#include "CAD4FE_mg_utils.h"
|
22 |
#include "mg_gestionnaire.h"
|
23 |
#include "ot_mathematique.h"
|
24 |
|
25 |
// Headers of CAD4FE
|
26 |
#include "CAD4FE_Geometric_Tools.h"
|
27 |
#include "CAD4FE_MakeLoops.h"
|
28 |
#include "CAD4FE_MCBody.h"
|
29 |
#include "CAD4FE_ColorMap.h"
|
30 |
#include "CAD4FE_Criteria.h"
|
31 |
#include "hypergraphlib_components.h"
|
32 |
#include "hypergraphlib_neato.h"
|
33 |
#include "hypergraphlib_findcycles.h"
|
34 |
|
35 |
using namespace CAD4FE;
|
36 |
|
37 |
|
38 |
void MCTChanges::Merge(MCTChanges& __mctChanges)
|
39 |
{
|
40 |
/*int i;
|
41 |
|
42 |
std::multimap<MCEdge*,MCEdge*>::iterator itEdge1, itEdge2;
|
43 |
for ( itEdge1 = E.begin();
|
44 |
itEdge1 != E.end();
|
45 |
itEdge1++)
|
46 |
{
|
47 |
i=0;
|
48 |
for ( itEdge2 = __mctChanges.E.find(itEdge1->second);
|
49 |
itEdge2->first == itEdge1->second && itEdge2 != __mctChanges.E.end();
|
50 |
itEdge2++)
|
51 |
{
|
52 |
if (itEdge2->second == itEdge2->first)
|
53 |
continue;
|
54 |
E.insert(std::make_pair(itEdge1->first, itEdge2->second));
|
55 |
i++;
|
56 |
}
|
57 |
if (i>0){
|
58 |
itEdge2 = itEdge1;
|
59 |
itEdge2 --;
|
60 |
E.erase(itEdge1);
|
61 |
itEdge1 = itEdge2;
|
62 |
}
|
63 |
}
|
64 |
|
65 |
for ( itEdge2 = __mctChanges.E.begin();
|
66 |
itEdge2 != __mctChanges.E.end();
|
67 |
itEdge2++)
|
68 |
{
|
69 |
itEdge1 = E.find(itEdge2->first);
|
70 |
if (itEdge1 == E.end())
|
71 |
{
|
72 |
E.insert(std::make_pair(itEdge1->first,itEdge1->second));
|
73 |
}
|
74 |
}*/
|
75 |
}
|
76 |
|
77 |
//---------------------------------------------------------------------------
|
78 |
MCBody::MCBody(MG_GEOMETRIE* __refGeom, MG_VOLUME * __refBody)
|
79 |
{
|
80 |
time = 0;
|
81 |
_refBody = __refBody;
|
82 |
_refGeom = __refGeom;
|
83 |
InitHyperGraphs();
|
84 |
}
|
85 |
|
86 |
//---------------------------------------------------------------------------
|
87 |
MCBody::~MCBody()
|
88 |
{
|
89 |
delete _G10;
|
90 |
delete _G20;
|
91 |
delete _G21;
|
92 |
}
|
93 |
|
94 |
//---------------------------------------------------------------------------
|
95 |
void MCBody::Graph_SetUserData(MG_ELEMENT_TOPOLOGIQUE * __topo)
|
96 |
{
|
97 |
Graph_SetUserData(_G10, __topo);
|
98 |
Graph_SetUserData(_G20, __topo);
|
99 |
Graph_SetUserData(_G21, __topo);
|
100 |
}
|
101 |
|
102 |
//---------------------------------------------------------------------------
|
103 |
void MCBody::Graph_SetUserData(Graph::Graph * __G, MG_ELEMENT_TOPOLOGIQUE * __topo)
|
104 |
{
|
105 |
int id = __topo->get_id();
|
106 |
|
107 |
switch (__topo->get_dimension())
|
108 |
{
|
109 |
case 0:// MCVertex
|
110 |
{
|
111 |
// reference vertex in arc of g10 and g20
|
112 |
if (__G == _G10 || __G == _G20 )
|
113 |
__G->GetArc(id)->SetUserData(__topo);
|
114 |
|
115 |
break;
|
116 |
}
|
117 |
case 1:// MCEdge
|
118 |
{
|
119 |
// reference edge in node of g10 and arc of g21
|
120 |
if (__G == _G10 )
|
121 |
__G->GetNode(id)->SetUserData(__topo);
|
122 |
else if (__G == _G21 )
|
123 |
__G->GetArc(id)->SetUserData(__topo);
|
124 |
|
125 |
break;
|
126 |
}
|
127 |
case 2:// MCFace
|
128 |
{
|
129 |
// reference face in node of g20 and g21
|
130 |
if (__G == _G20 || __G == _G21 )
|
131 |
__G->GetNode(id)->SetUserData(__topo);
|
132 |
|
133 |
break;
|
134 |
}
|
135 |
}
|
136 |
}
|
137 |
|
138 |
//---------------------------------------------------------------------------
|
139 |
MCFace * MCBody::AddMCFace(MG_FACE * __refFace)
|
140 |
{
|
141 |
MCFace *newMCFace = new MCFace(__refFace);
|
142 |
// Set the face ID
|
143 |
_refGeom->ajouter_mg_surface(newMCFace->GetPolySurface());
|
144 |
_refGeom->ajouter_mg_face(newMCFace);
|
145 |
|
146 |
return newMCFace;
|
147 |
}
|
148 |
|
149 |
//---------------------------------------------------------------------------
|
150 |
MCFace * MCBody::AddMCFace( MCFace *__a, MCFace *__b)
|
151 |
{
|
152 |
std::ostringstream idOriginal;
|
153 |
MCFace & mcFace1 = *__a;
|
154 |
MCFace & mcFace2 = *__b;
|
155 |
MCFace *newMCFace = new MCFace(mcFace1, mcFace2);
|
156 |
_refGeom->ajouter_mg_surface(newMCFace->GetPolySurface());
|
157 |
_refGeom->ajouter_mg_face(newMCFace);
|
158 |
return newMCFace;
|
159 |
}
|
160 |
|
161 |
//---------------------------------------------------------------------------
|
162 |
MCFace* MCBody::GetMCFace(const int __id) const
|
163 |
{
|
164 |
Graph::Node * node = _G21->GetNode(__id);
|
165 |
if (node)
|
166 |
return GetMCFace(node);
|
167 |
else
|
168 |
printf("Error in GetMCFace ID = %d\n", __id);
|
169 |
|
170 |
return NULL;
|
171 |
}
|
172 |
|
173 |
//---------------------------------------------------------------------------
|
174 |
bool MCBody::Contains(MCFace * __mcFace) const
|
175 |
{
|
176 |
return (GetMCFace(__mcFace->get_id()) != NULL);
|
177 |
}
|
178 |
|
179 |
//---------------------------------------------------------------------------
|
180 |
MCFace* MCBody::GetMCFace(Graph::GraphObject * __graphObject)
|
181 |
{
|
182 |
return (MCFace*) __graphObject->GetUserData();
|
183 |
}
|
184 |
//---------------------------------------------------------------------------
|
185 |
//
|
186 |
void MCBody::AddMCEdgeCovertices(MCEdge * __mcEdge, std::vector<MCVertex *> __mcVertex)
|
187 |
{
|
188 |
int i;
|
189 |
|
190 |
// Set the covertex ID and add it in the geometry manager
|
191 |
MG_COSOMMET * covertex[2];
|
192 |
for (i=0;i<2;i++)
|
193 |
covertex[i] = _refGeom->ajouter_mg_cosommet(__mcEdge, __mcVertex[i]);
|
194 |
|
195 |
if ( covertex[0]->get_t() > covertex[1]->get_t() && ! __mcEdge->GetPolyCurve()->est_periodique() )
|
196 |
std::swap (covertex[0], covertex[1]);
|
197 |
|
198 |
|
199 |
__mcEdge->changer_cosommet1(covertex[0]);
|
200 |
__mcEdge->changer_cosommet2(covertex[1]);
|
201 |
}
|
202 |
//---------------------------------------------------------------------------
|
203 |
void MCBody::DeleteMCEdgeCovertices(MCEdge * __mcEdge)
|
204 |
{
|
205 |
_refGeom->supprimer_mg_cosommet(__mcEdge->get_cosommet1());
|
206 |
_refGeom->supprimer_mg_cosommet(__mcEdge->get_cosommet2());
|
207 |
}
|
208 |
//---------------------------------------------------------------------------
|
209 |
void MCBody::DeleteMCEdge(MCEdge * __mcEdge)
|
210 |
{
|
211 |
printf("Deleting MC Edge\t : ID \"%lu\" at adress %p\n",__mcEdge->get_id(), __mcEdge);
|
212 |
_refGeom->supprimer_mg_courbeid(__mcEdge->GetPolyCurve()->get_id());
|
213 |
_refGeom->supprimer_mg_areteid(__mcEdge->get_id());
|
214 |
}
|
215 |
//---------------------------------------------------------------------------
|
216 |
void MCBody::DeleteMCFace(MCFace * __mcFace)
|
217 |
{
|
218 |
printf("Deleting MC Face\t : ID \"%lu\" at adress %p\n",__mcFace->get_id(), __mcFace);
|
219 |
_refGeom->supprimer_mg_surfaceid(__mcFace->GetPolySurface()->get_id());
|
220 |
_refGeom->supprimer_mg_faceid(__mcFace->get_id());
|
221 |
}
|
222 |
//---------------------------------------------------------------------------
|
223 |
void MCBody::DeleteMCVertex(MCVertex * __mcVertex)
|
224 |
{
|
225 |
// printf("Deleting MC Vertex\t : ID \"%lu\" at adress %p\n",__mcVertex->get_id(), __mcVertex);
|
226 |
|
227 |
_refGeom->supprimer_mg_sommetid(__mcVertex->get_id());
|
228 |
}
|
229 |
//---------------------------------------------------------------------------
|
230 |
MCEdge * MCBody::AddMCEdge(MG_ARETE * __refEdge)
|
231 |
{
|
232 |
// Construct a mc edge
|
233 |
MCEdge * newMCEdge = new MCEdge(__refEdge);
|
234 |
|
235 |
// Set the newEdge ID
|
236 |
_refGeom->ajouter_mg_courbe(newMCEdge->GetPolyCurve());
|
237 |
|
238 |
if (_refGeom->get_mg_courbeid( newMCEdge->GetPolyCurve()->get_id()) == NULL)
|
239 |
printf("PB!\n");
|
240 |
|
241 |
_refGeom->ajouter_mg_arete(newMCEdge);
|
242 |
if (_refGeom->get_mg_areteid( newMCEdge->get_id()) == NULL)
|
243 |
printf("PB!\n");
|
244 |
|
245 |
return newMCEdge;
|
246 |
}
|
247 |
//---------------------------------------------------------------------------
|
248 |
MCEdge * MCBody::AddMCEdge(MCEdge *__A, MCEdge *__B)
|
249 |
{
|
250 |
std::ostringstream idOriginal;
|
251 |
idOriginal<< __A->get_idoriginal();
|
252 |
idOriginal<<"+";
|
253 |
idOriginal<< __B->get_idoriginal();
|
254 |
|
255 |
// Create a polycurve
|
256 |
MCEdge * newMCEdge = new MCEdge( idOriginal.str(), *__A, *__B);
|
257 |
|
258 |
// Set the newEdge ID
|
259 |
_refGeom->ajouter_mg_courbe(newMCEdge->GetPolyCurve());
|
260 |
|
261 |
if (_refGeom->get_mg_courbeid( newMCEdge->GetPolyCurve()->get_id()) == NULL)
|
262 |
printf("PB!\n");
|
263 |
|
264 |
_refGeom->ajouter_mg_arete(newMCEdge);
|
265 |
if (_refGeom->get_mg_areteid( newMCEdge->get_id()) == NULL)
|
266 |
printf("PB!\n");
|
267 |
|
268 |
return newMCEdge;
|
269 |
}
|
270 |
//---------------------------------------------------------------------------
|
271 |
MCEdge * MCBody::AddMCEdge(PolyCurve *__curve)
|
272 |
{
|
273 |
std::ostringstream idOriginal;
|
274 |
idOriginal<< "MCEdge" ;
|
275 |
for (unsigned i=0; i<__curve->GetRefEdgeCount(); i++)
|
276 |
idOriginal<<"-"<<__curve->GetRefEdge(i)->get_id();
|
277 |
MCEdge * newMCEdge = new MCEdge(idOriginal.str(), __curve);
|
278 |
|
279 |
// Set the newEdge ID
|
280 |
_refGeom->ajouter_mg_courbe(newMCEdge->GetPolyCurve());
|
281 |
|
282 |
if (_refGeom->get_mg_courbeid( newMCEdge->GetPolyCurve()->get_id()) == NULL)
|
283 |
printf("PB!\n");
|
284 |
|
285 |
_refGeom->ajouter_mg_arete(newMCEdge);
|
286 |
if (_refGeom->get_mg_areteid( newMCEdge->get_id()) == NULL)
|
287 |
printf("PB!\n");
|
288 |
|
289 |
return newMCEdge;
|
290 |
}
|
291 |
|
292 |
//---------------------------------------------------------------------------
|
293 |
Graph::Graph * MCBody::G10() const
|
294 |
{
|
295 |
return _G10;
|
296 |
}
|
297 |
|
298 |
//---------------------------------------------------------------------------
|
299 |
Graph::Graph * MCBody::G21() const
|
300 |
{
|
301 |
return _G21;
|
302 |
}
|
303 |
|
304 |
//---------------------------------------------------------------------------
|
305 |
Graph::Graph * MCBody::G20() const
|
306 |
{
|
307 |
return _G20;
|
308 |
}
|
309 |
|
310 |
//---------------------------------------------------------------------------
|
311 |
MCEdge* MCBody::GetMCEdge(int __id) const
|
312 |
{
|
313 |
Graph::Node * node = _G10->GetNode(__id);
|
314 |
|
315 |
if (node)
|
316 |
return GetMCEdge(node);
|
317 |
else
|
318 |
cout << "GetMCEdge : Error: Did not find the MCEdge corresponding to the ID \""<<__id<<"\"\n";
|
319 |
|
320 |
return NULL;
|
321 |
}
|
322 |
|
323 |
//---------------------------------------------------------------------------
|
324 |
MCEdge* MCBody::GetMCEdge(Graph::GraphObject * __graphObject)
|
325 |
{
|
326 |
return (MCEdge *) __graphObject->GetUserData();
|
327 |
}
|
328 |
|
329 |
//---------------------------------------------------------------------------
|
330 |
bool MCBody::Contains(MCEdge * __mcEdge) const
|
331 |
{
|
332 |
Graph::Node * n = _G10->GetNode(__mcEdge->get_id());
|
333 |
|
334 |
if (!n)
|
335 |
return false;
|
336 |
|
337 |
return ( n->GetUserData() == __mcEdge );
|
338 |
}
|
339 |
|
340 |
//---------------------------------------------------------------------------
|
341 |
MCVertex * MCBody::AddMCVertex(MG_SOMMET * __refVertex)
|
342 |
{
|
343 |
double pos[3]; __refVertex->get_point()->evaluer(pos);
|
344 |
MCVertex *mcVertex = new MCVertex(__refVertex);
|
345 |
|
346 |
// Add the vertex to the geometry manager in order to
|
347 |
// set its ID
|
348 |
_refGeom->ajouter_mg_sommet(mcVertex);
|
349 |
|
350 |
return mcVertex;
|
351 |
}
|
352 |
|
353 |
//---------------------------------------------------------------------------
|
354 |
MCVertex* MCBody::GetMCVertex(int __id)const
|
355 |
{
|
356 |
Graph::Arc * arc;
|
357 |
arc = _G10->GetArc(__id);
|
358 |
if (arc)
|
359 |
return GetMCVertex(arc);
|
360 |
else
|
361 |
{
|
362 |
printf("Error in GetMCVertex (int id) method : can't find the arc ID %d in G10 Graph !\n", __id);
|
363 |
}
|
364 |
return NULL;
|
365 |
}
|
366 |
|
367 |
//---------------------------------------------------------------------------
|
368 |
bool MCBody::Contains(MCVertex * __mcVertex) const
|
369 |
{
|
370 |
Graph::Arc * a = _G10->GetArc(__mcVertex->get_id());
|
371 |
|
372 |
if (!a)
|
373 |
return false;
|
374 |
|
375 |
return (a->GetUserData() == __mcVertex );
|
376 |
}
|
377 |
|
378 |
//---------------------------------------------------------------------------
|
379 |
MCVertex * MCBody::GetMCVertex(Graph::GraphObject * __graphObject)
|
380 |
{
|
381 |
return (MCVertex*) __graphObject->GetUserData();
|
382 |
}
|
383 |
|
384 |
//---------------------------------------------------------------------------
|
385 |
void MCBody::InitHyperGraphs()
|
386 |
{
|
387 |
int j, k;
|
388 |
_G21 = new Graph::Graph;
|
389 |
_G10 = new Graph::Graph;
|
390 |
_G20 = new Graph::Graph;
|
391 |
|
392 |
std::set < MG_FACE * > lst_ref_faces;
|
393 |
std::set < MG_ARETE * > lst_ref_edges;
|
394 |
std::set < MG_SOMMET * > lst_ref_vertices;
|
395 |
|
396 |
// initialize face, edge, and vertices lists
|
397 |
unsigned nb_shells = _refBody->get_nb_mg_coquille ();
|
398 |
for (unsigned it_shells = 0; it_shells < nb_shells; it_shells++)
|
399 |
{
|
400 |
MG_COQUILLE * shell = _refBody->get_mg_coquille(it_shells);
|
401 |
unsigned nb_coface = shell->get_nb_mg_coface();
|
402 |
for (unsigned it_coface = 0; it_coface < nb_coface; it_coface++)
|
403 |
{
|
404 |
MG_FACE * face = shell->get_mg_coface(it_coface)->get_face();
|
405 |
lst_ref_faces.insert(face);
|
406 |
|
407 |
unsigned nb_loop = face->get_nb_mg_boucle();
|
408 |
for (unsigned it_loop = 0; it_loop < nb_loop; it_loop++)
|
409 |
{
|
410 |
MG_BOUCLE * loop = face->get_mg_boucle(it_loop);
|
411 |
unsigned nb_edge = loop->get_nb_mg_coarete();
|
412 |
|
413 |
for (unsigned it_edge = 0; it_edge < nb_edge; it_edge++)
|
414 |
{
|
415 |
MG_ARETE * edge = loop->get_mg_coarete(it_edge)->get_arete();
|
416 |
lst_ref_edges.insert(edge);
|
417 |
|
418 |
lst_ref_vertices.insert (edge->get_cosommet1()->get_sommet());
|
419 |
lst_ref_vertices.insert (edge->get_cosommet2()->get_sommet());
|
420 |
}
|
421 |
}
|
422 |
}
|
423 |
}
|
424 |
|
425 |
|
426 |
// Correspondance map between Reference Entities and MC entities
|
427 |
std::map <MG_FACE *, MCFace *> mapRefToMCFace;
|
428 |
std::map <MG_ARETE *, MCEdge *> mapRefToMCEdge;
|
429 |
std::map <MG_SOMMET *, MCVertex *> mapRefToMCVertex;
|
430 |
|
431 |
// Create the MC Vertices
|
432 |
for (std::set<MG_SOMMET*>::iterator it_vert = lst_ref_vertices.begin();
|
433 |
it_vert != lst_ref_vertices.end(); it_vert++)
|
434 |
{
|
435 |
MG_SOMMET * refVertex = *it_vert;
|
436 |
// Create the MC Vertex
|
437 |
// and initialize the Indentifier using the Geometry manager
|
438 |
MCVertex * mcVertex = AddMCVertex(refVertex);
|
439 |
// Map the MC Vertex to its reference vertex in the correspondance map
|
440 |
mapRefToMCVertex [ refVertex ] = mcVertex;
|
441 |
}
|
442 |
|
443 |
// Create the MC Edges
|
444 |
for (std::set <MG_ARETE *>::iterator it_edge = lst_ref_edges.begin();
|
445 |
it_edge != lst_ref_edges.end();
|
446 |
it_edge ++)
|
447 |
{
|
448 |
MG_ARETE * refEdge = *it_edge;
|
449 |
// Create the MC Edge
|
450 |
// and initialize the Indentifier using the Geometry manager
|
451 |
MCEdge * mcEdge = AddMCEdge(refEdge);
|
452 |
// Map the MC Edge to its reference edge in the correspondance map
|
453 |
mapRefToMCEdge [ refEdge ] = mcEdge;
|
454 |
}
|
455 |
|
456 |
// Create the MC Faces
|
457 |
for (std::set<MG_FACE*>::iterator it_face = lst_ref_faces.begin();
|
458 |
it_face != lst_ref_faces.end();
|
459 |
it_face++)
|
460 |
{
|
461 |
MG_FACE * refFace = *it_face;
|
462 |
// Create the MC Face
|
463 |
// and initialize the Indentifier using the Geometry manager
|
464 |
MCFace * mcFace = AddMCFace(refFace);
|
465 |
// Map the MC Face to its reference Face in the correspondance map
|
466 |
mapRefToMCFace [ refFace ] = mcFace;
|
467 |
}
|
468 |
|
469 |
// for each face of the reference topology
|
470 |
for (std::set<MG_FACE*>::iterator it_face = lst_ref_faces.begin();
|
471 |
it_face != lst_ref_faces.end();
|
472 |
it_face++)
|
473 |
{
|
474 |
MG_FACE * refFace = *it_face;
|
475 |
|
476 |
// Get the MCFace corresponding to the reference face
|
477 |
MCFace * mcFace = mapRefToMCFace [ refFace ];
|
478 |
|
479 |
printf("Initializing\tMC Face\tID \"%lu\" \t(Ref Face ID \"%lu\")\n",mcFace->get_id(), refFace->get_id());
|
480 |
|
481 |
// Add a node in _G21 and _G20
|
482 |
_G21->AddNode (mcFace->get_id());
|
483 |
_G20->AddNode (mcFace->get_id());
|
484 |
|
485 |
// initialize graph G21 and G20 nodes to face
|
486 |
Graph_SetUserData(mcFace);
|
487 |
}
|
488 |
|
489 |
// For each edge of refBody :
|
490 |
// create an arc in G21 and connect-it to each nodes of adjacent faces
|
491 |
// create a node in G1
|
492 |
for (std::set <MG_ARETE *>::iterator it_edge = lst_ref_edges.begin();
|
493 |
it_edge != lst_ref_edges.end();
|
494 |
it_edge ++)
|
495 |
{
|
496 |
MG_ARETE * refEdge = *it_edge;
|
497 |
|
498 |
// Get the MCEdge corresponding to the reference Edge
|
499 |
MCEdge * mcEdge = mapRefToMCEdge [ refEdge ];
|
500 |
|
501 |
// printing the step number
|
502 |
printf("Initializing\t MC Edge\t%d of %d : ID = \"%lu\" \t(Reference Edge ID \"%lu\")\n", std::distance(lst_ref_edges.begin(), it_edge)+1, lst_ref_edges.size(), mcEdge->get_id(), refEdge->get_id());
|
503 |
|
504 |
// create a node in G1
|
505 |
|
506 |
// add a node in _G10
|
507 |
_G10->AddNode (mcEdge->get_id());
|
508 |
|
509 |
// create an arc in G21 and connect-it to each nodes of adjacent faces
|
510 |
std::vector <int> nodes;
|
511 |
for (int j=0; j < refEdge->get_nb_mg_coarete(); j++)
|
512 |
{
|
513 |
MG_FACE * refFace = refEdge->get_mg_coarete(j)->get_boucle()->get_mg_face();
|
514 |
// mcFace = adjacent face
|
515 |
MCFace * mcFace = mapRefToMCFace [ refFace ];
|
516 |
|
517 |
// connect arc to adjacent faces
|
518 |
nodes.push_back(mcFace->get_id());
|
519 |
}
|
520 |
_G21->AddArc(nodes, mcEdge->get_id());
|
521 |
|
522 |
// initialize graph G21 arcs and G10 nodes to MC Edge
|
523 |
Graph_SetUserData(mcEdge);
|
524 |
}
|
525 |
|
526 |
|
527 |
// For each ref vertex of reference Body :
|
528 |
for (std::set<MG_SOMMET*>::iterator it_vertex = lst_ref_vertices.begin();
|
529 |
it_vertex != lst_ref_vertices.end();
|
530 |
it_vertex++)
|
531 |
{
|
532 |
MG_SOMMET * refVertex = *it_vertex;
|
533 |
|
534 |
// Get the MCVertex corresponding to the reference Vertex
|
535 |
MCVertex * mcVertex = mapRefToMCVertex [ refVertex ];
|
536 |
|
537 |
// -------------- G20 Arc --------------------------------------------
|
538 |
// create an arc in G20 and connect-it to each nodes of adjacent faces
|
539 |
{
|
540 |
std::vector <int> nodes;
|
541 |
for (unsigned j = 0; j < refVertex->get_nb_mg_cosommet(); j++)
|
542 |
{
|
543 |
MG_ARETE * refEdge = refVertex->get_mg_cosommet(j)->get_arete();
|
544 |
|
545 |
for (int k=0; k < refEdge->get_nb_mg_coarete(); k++)
|
546 |
{
|
547 |
MG_FACE * refFace = refEdge->get_mg_coarete(k)->get_boucle()->get_mg_face();
|
548 |
MCFace * mcFace = mapRefToMCFace [ refFace ];
|
549 |
|
550 |
if (std::find (nodes.begin(), nodes.end(), mcFace->get_id()) == nodes.end())
|
551 |
nodes.push_back(mcFace->get_id());
|
552 |
}
|
553 |
}
|
554 |
// create a graph-arc in G20
|
555 |
_G20->AddArc(nodes, mcVertex->get_id());
|
556 |
}
|
557 |
|
558 |
|
559 |
// -------------- G10 Arc --------------------------------------------
|
560 |
// create an arc in G10 and connect-it to each nodes of adjacent edges
|
561 |
{
|
562 |
std::vector <int> nodes;
|
563 |
for (unsigned j = 0; j < refVertex->get_nb_mg_cosommet(); j++)
|
564 |
{
|
565 |
MG_ARETE * refEdge = refVertex->get_mg_cosommet(j)->get_arete();
|
566 |
MCEdge * mcEdge = mapRefToMCEdge [ refEdge ];
|
567 |
|
568 |
nodes.push_back(mcEdge->get_id());
|
569 |
}
|
570 |
// create a graph-arc in G10
|
571 |
_G10->AddArc(nodes, mcVertex->get_id());
|
572 |
}
|
573 |
|
574 |
// initialize graph G10 arc and G20 arc to MC Vertex
|
575 |
Graph_SetUserData(mcVertex);
|
576 |
}
|
577 |
|
578 |
// Add covertices for each edge
|
579 |
{
|
580 |
MCBODY_FOR_EACH_MCEDGE(this, mcEdge)
|
581 |
{
|
582 |
std::vector <MCVertex*> extremities;
|
583 |
Edge_GetVertices(mcEdge, extremities);
|
584 |
AddMCEdgeCovertices(mcEdge, extremities);
|
585 |
}
|
586 |
}
|
587 |
}
|
588 |
|
589 |
//---------------------------------------------------------------------------
|
590 |
int
|
591 |
MCBody::G2ToNeatoFile (Graph::Graph * __G2,
|
592 |
char * __filename,
|
593 |
char *__graphname)
|
594 |
{
|
595 |
using std::cout;
|
596 |
std::string graphNeato;
|
597 |
std::ofstream neatoFile;
|
598 |
neatoFile.open( __filename );
|
599 |
graphNeato = NeatoGraph(*__G2);
|
600 |
std::cout << graphNeato;
|
601 |
neatoFile << graphNeato;
|
602 |
neatoFile.flush();
|
603 |
neatoFile.close(); //explicit
|
604 |
|
605 |
return 0;
|
606 |
}
|
607 |
//---------------------------------------------------------------------------
|
608 |
// Create a MCVertex with a defined label
|
609 |
MCVertex * MCBody::CreateMCVertex (MG_SOMMET * __refVertex)
|
610 |
{
|
611 |
// Create the MC Vertex in G20 and G10
|
612 |
|
613 |
MCVertex * mcVertex = new MCVertex (__refVertex);
|
614 |
|
615 |
_refGeom->ajouter_mg_sommet(mcVertex);
|
616 |
|
617 |
int id = mcVertex->get_id();
|
618 |
Graph::Arc * G20Arc = _G20->AddArc(id, 0 /*rank=0*/);
|
619 |
Graph::Arc * G10Arc = _G10->AddArc(id, 0 /*rank=0*/);
|
620 |
|
621 |
Graph_SetUserData(mcVertex);
|
622 |
|
623 |
return mcVertex;
|
624 |
}
|
625 |
|
626 |
//---------------------------------------------------------------------------
|
627 |
// Split an MC edge by inserting one MC vertex in its domain
|
628 |
void MCBody::SplitEdge(MCEdge * __mcEdge, double __xyz[3], MCTChanges * __mctChanges, RTChanges * __rtChanges)
|
629 |
{
|
630 |
MG_ARETE *__origRefEdge;
|
631 |
MG_SOMMET * __splitRefVertex;
|
632 |
MG_ARETE *__splitRefEdges[2];
|
633 |
MCVertex * __mcVertex;
|
634 |
MCEdge *__result[2];
|
635 |
int i;
|
636 |
|
637 |
// store the extremities of the original edge in a vector
|
638 |
std::vector <MCVertex * > origEdgeExtremities;
|
639 |
Edge_GetVertices ( __mcEdge, origEdgeExtremities );
|
640 |
|
641 |
// split curves
|
642 |
PolyCurve * edgePolyCurve = __mcEdge->GetPolyCurve();
|
643 |
PolyCurve * curves[2];
|
644 |
SplitPolyCurve(edgePolyCurve, __xyz, _refBody, _refGeom, curves, &__origRefEdge, &__splitRefVertex, __splitRefEdges);
|
645 |
if ( __splitRefVertex == NULL )
|
646 |
{
|
647 |
printf("Can't split MC Edge in MC body\n");
|
648 |
return;
|
649 |
}
|
650 |
_refGeom->ajouter_mg_sommet(__splitRefVertex);
|
651 |
|
652 |
__mcVertex = CreateMCVertex(__splitRefVertex);
|
653 |
|
654 |
printf("Inserting MC Vertex\t : ID \"%lu\" \n", __mcVertex->get_id());
|
655 |
|
656 |
// Create the two MC Edges
|
657 |
for ( i=0; i<2; i++)
|
658 |
{
|
659 |
__result[i] = AddMCEdge(curves[i]);
|
660 |
__result[i]->copie_ccf(*__mcEdge);
|
661 |
}
|
662 |
|
663 |
// duplicate G21A to get 2 parallel arcs
|
664 |
Graph::Arc * G21A[3];
|
665 |
G21A[2] = _G21->GetArc(__mcEdge->get_id());
|
666 |
int faceId[2];
|
667 |
|
668 |
// save the G21 nodes adjacent to the mc Edges's arc
|
669 |
Graph::Node * G21N[2];
|
670 |
i=0;
|
671 |
for (Graph::Arc::MultimapNodesById::iterator itG21Node = G21A[2]->Nodes().begin();
|
672 |
itG21Node != G21A[2]->Nodes().end();
|
673 |
itG21Node++ )
|
674 |
{
|
675 |
faceId[i] = itG21Node->first;
|
676 |
G21N[i++] = itG21Node->second;
|
677 |
}
|
678 |
|
679 |
|
680 |
// Set edges id
|
681 |
int edgeId[3];
|
682 |
edgeId[2] = __mcEdge->get_id();
|
683 |
for (i = 0; i < 2; i++)
|
684 |
edgeId[i] = __result[i]->get_id();
|
685 |
|
686 |
// Duplicate the G21 arc of the split edge
|
687 |
for (i = 0; i < 2; i++)
|
688 |
G21A[i] = _G21->DuplicateArc(G21A[2], edgeId[i]);
|
689 |
// Remove the G21 Arc of the split edge
|
690 |
_G21->RemoveArc(G21A[2]);
|
691 |
|
692 |
// split the G10 node of the split edge
|
693 |
Graph::Arc * G10A[3];
|
694 |
Graph::Node * G10N[3];
|
695 |
G10A[2] = _G10->GetArc( __mcVertex->get_id() ); // the arc representing the split vertex
|
696 |
G10N[2] = _G10->GetNode( __mcEdge->get_id() );
|
697 |
// delete the G10 node of the old edge
|
698 |
_G10->RemoveNode(G10N[2]);
|
699 |
// Add two new nodes
|
700 |
for ( i=0; i<2; i++)
|
701 |
G10N[i] = _G10->AddNode(edgeId[i]);
|
702 |
// Add an arc linking the 2 nodes. This arc represents the split vertex
|
703 |
// Link the G10 arc of the MC vertex to the 2 nodes representing the edges
|
704 |
for (i=0; i<2; i++)
|
705 |
{
|
706 |
G10A[2]->Add(G10N[i]);
|
707 |
G10N[i]->Add(G10A[2]);
|
708 |
}
|
709 |
|
710 |
for (i=0; i<2; i++)
|
711 |
{
|
712 |
MG_SOMMET * refVertex = NULL;
|
713 |
if (curves[i]->get_sommet1()->get_id() != __mcVertex->GetRefVertex()->get_id())
|
714 |
refVertex = curves[i]->get_sommet1();
|
715 |
else
|
716 |
refVertex = curves[i]->get_sommet2();
|
717 |
MCVertex * V;
|
718 |
|
719 |
for (int j=0; j<2; j++)
|
720 |
if (origEdgeExtremities[j]->Contains( refVertex ))
|
721 |
V = origEdgeExtremities[j];
|
722 |
|
723 |
G10A[i] = _G10->GetArc(V->get_id());
|
724 |
}
|
725 |
|
726 |
|
727 |
// add new node[i] in arc[i]
|
728 |
for ( i=0; i<2; i++)
|
729 |
{
|
730 |
G10A[i]->Add(G10N[i]);
|
731 |
G10N[i]->Add(G10A[i]);
|
732 |
}
|
733 |
|
734 |
// Add an arc in G20
|
735 |
Graph::Arc * G20Arc = _G20->GetArc(__mcVertex->get_id());
|
736 |
Graph::Node * G20Node[2];
|
737 |
for ( i=0; i<2; i++)
|
738 |
{
|
739 |
G20Node[i] = _G20->GetNode(faceId[i]);
|
740 |
G20Arc->Add(G20Node[i]);
|
741 |
G20Node[i]->Add(G20Arc);
|
742 |
}
|
743 |
|
744 |
printf("G10A[2]->Rank = %d\n", G10A[2]->Rank());
|
745 |
printf("G20A[2]->Rank = %d\n", _G20->GetArc(__mcVertex->get_id())->Rank());
|
746 |
|
747 |
/// Operations using the resulting Graph of this MC Edge
|
748 |
/// split :
|
749 |
/// Get the vertex extremities of both new MC Edge
|
750 |
/// and Add 2 Covertices
|
751 |
for (i=0; i<2; i++)
|
752 |
{
|
753 |
MCEdge * newMCEdge = __result[i];
|
754 |
|
755 |
std::vector<MCVertex*> mcVertexExtremities;
|
756 |
Edge_GetVertices(newMCEdge, mcVertexExtremities);
|
757 |
AddMCEdgeCovertices(newMCEdge, mcVertexExtremities);
|
758 |
|
759 |
/// Set graph user Data of new MCEdge G21 Arc and G10 Node
|
760 |
Graph_SetUserData(newMCEdge);
|
761 |
}
|
762 |
|
763 |
|
764 |
// Deleted and Created MC Topology
|
765 |
if (__mctChanges)
|
766 |
{
|
767 |
// a new vertex has been created
|
768 |
__mctChanges->V.insert( std::make_pair ((MCVertex*)NULL, __mcVertex));
|
769 |
// __mcEdge has been replaces by 2 new edges
|
770 |
__mctChanges->E.insert( std::make_pair (__mcEdge, (MCEdge*) NULL) );
|
771 |
__mctChanges->E.insert( std::make_pair ((MCEdge*) NULL, __result[0]) );
|
772 |
__mctChanges->E.insert( std::make_pair ((MCEdge*) NULL, __result[1]) );
|
773 |
}
|
774 |
|
775 |
// Deleted and created Reference Topology
|
776 |
if (__rtChanges)
|
777 |
{
|
778 |
// a new vertex __splitRefVertex has been created
|
779 |
__rtChanges->V.insert( std::make_pair ((MCVertex*)NULL , __splitRefVertex) );
|
780 |
// __origRefEdge has been replaces by 2 new edges __splitRefEdges
|
781 |
__rtChanges->E.insert( std::make_pair (__origRefEdge , __splitRefEdges[0]) );
|
782 |
__rtChanges->E.insert( std::make_pair (__origRefEdge , __splitRefEdges[1]) );
|
783 |
}
|
784 |
|
785 |
}
|
786 |
|
787 |
//---------------------------------------------------------------------------
|
788 |
int
|
789 |
MCBody::G1ToNeatoFile (Graph::Graph * __G1,
|
790 |
char * __filename,
|
791 |
char *__graphname)
|
792 |
{
|
793 |
using std::cout;
|
794 |
std::ofstream neatoFile;
|
795 |
neatoFile.open( __filename );
|
796 |
neatoFile << "graph \""<< __graphname <<"\" {" << std::endl;
|
797 |
neatoFile << "node [ shape=box , color = blue ]\n";
|
798 |
|
799 |
//////// G1 graph
|
800 |
GRAPH_FOR_EACH_ARC_CONST(__G1,itarcs)
|
801 |
{
|
802 |
neatoFile << "\""<<itarcs->first<<"\" [ shape=point, style=filled, fillcolor=red ]\n";
|
803 |
|
804 |
ARC_FOR_EACH_NODE_CONST( itarcs->second, itnodes)
|
805 |
{
|
806 |
neatoFile << "\""<< itnodes->first << "\"";
|
807 |
neatoFile << " -- ";
|
808 |
neatoFile << "\""<< itarcs->first << "\"";
|
809 |
neatoFile << " [ len=1 ] ";
|
810 |
neatoFile << std::endl;
|
811 |
}
|
812 |
}
|
813 |
neatoFile << "}" << std::endl;
|
814 |
neatoFile << std::endl;
|
815 |
|
816 |
neatoFile.close(); //explicit
|
817 |
|
818 |
return 0;
|
819 |
}
|
820 |
|
821 |
bool V2(MCBody * _mcBody, MG_ELEMENT_TOPOLOGIQUE * topo)
|
822 |
{
|
823 |
if (topo)
|
824 |
{
|
825 |
switch (topo->get_dimension())
|
826 |
{
|
827 |
case 0:
|
828 |
{
|
829 |
MCVertex * mctopo = _mcBody->GetMCVertex(topo->get_id());
|
830 |
|
831 |
|
832 |
if (mctopo != topo)
|
833 |
{
|
834 |
printf("MC Vertex %ld does not exist !\n", topo->get_id());
|
835 |
return false;
|
836 |
}
|
837 |
else
|
838 |
return true;
|
839 |
|
840 |
|
841 |
|
842 |
}
|
843 |
case 1:
|
844 |
{
|
845 |
MCEdge * mctopo = _mcBody->GetMCEdge(topo->get_id());
|
846 |
MCEdge * topo2 = (MCEdge*) _mcBody->GetGeometry()->get_mg_areteid(topo->get_id());
|
847 |
|
848 |
if (mctopo != topo || topo2 != topo)
|
849 |
{
|
850 |
printf("MC Edge %ld does not exist !\n", topo->get_id());
|
851 |
return false;
|
852 |
}
|
853 |
else
|
854 |
return true;
|
855 |
}
|
856 |
case 2:
|
857 |
{
|
858 |
MCFace * mctopo = _mcBody->GetMCFace(topo->get_id());
|
859 |
|
860 |
if (mctopo != topo)
|
861 |
{
|
862 |
printf("MC Face %ld does not exist !\n", topo->get_id());
|
863 |
return false;
|
864 |
}
|
865 |
else
|
866 |
return true;
|
867 |
}
|
868 |
default:
|
869 |
printf("The topological link claims a dimension \"%d\" > 2 or < 0 !\n", topo->get_dimension());
|
870 |
}
|
871 |
}
|
872 |
else
|
873 |
{
|
874 |
printf("Topo = NULL\n");
|
875 |
return false;
|
876 |
}
|
877 |
return false;
|
878 |
}
|
879 |
|
880 |
void V(MCBody * _mcBody)
|
881 |
{
|
882 |
int i=0;
|
883 |
{MCBODY_FOR_EACH_MCEDGE(_mcBody, edge22){
|
884 |
if (_mcBody->G21()->GetArcs().size() <= 1)
|
885 |
break;
|
886 |
if (V2(_mcBody, edge22) == false)
|
887 |
printf("MC Edge ID=%lu not OK\n", edge22->get_id());
|
888 |
i++;
|
889 |
}
|
890 |
}
|
891 |
|
892 |
}
|
893 |
//---------------------------------------------------------------------------
|
894 |
void
|
895 |
MCBody::SuppressMCEdge(MCEdge * __mcEdge, MCFace * __F[3])
|
896 |
{
|
897 |
int i;
|
898 |
int __id = __mcEdge->get_id();
|
899 |
|
900 |
// Find the arc __id in G2V (G2 Virtual)
|
901 |
Graph::Arc * arcG21 = _G21->GetArc(__id);
|
902 |
// V(this);
|
903 |
|
904 |
///// Process G2 Graph
|
905 |
printf("Deleting MC Edge\t : ID \"%d\" at adress %p \n", __id, __mcEdge);
|
906 |
|
907 |
if ( ! arcG21->IsLoop() ) // The arc represents an boundary edge
|
908 |
{
|
909 |
// Get the two mc faces adjacent to the suppressed mc edge
|
910 |
MCFace * face[3];
|
911 |
int faceId[3];
|
912 |
Graph::Node * faceNode[3];
|
913 |
|
914 |
i = 0;
|
915 |
Graph::Arc::MultimapNodesById::iterator itNode = arcG21->Nodes().begin();
|
916 |
for (i=0; i<2; i++)
|
917 |
{
|
918 |
faceId[i] = itNode->first;
|
919 |
faceNode[i] = itNode->second;
|
920 |
face[i] = GetMCFace(faceId[i]);
|
921 |
|
922 |
itNode++;
|
923 |
}
|
924 |
|
925 |
//V(this);
|
926 |
_G21->RemoveArc(__id);
|
927 |
//V(this);
|
928 |
|
929 |
// Merge the nodes of these 2 mc face in G21
|
930 |
// (contract the arc in G21)
|
931 |
MCFace* newMCFace = AddMCFace(face[0], face[1]);
|
932 |
faceId[2] = newMCFace->get_id();
|
933 |
faceNode[2] = _G21->MergeNodes(faceNode[0], faceNode[1], faceId[2]);
|
934 |
|
935 |
// Merge the nodes of these 2 mc faces in G20
|
936 |
Graph::Node * mergedG20Node = _G20->MergeNodes( faceId[0], faceId[1], faceId[2]);
|
937 |
//V(this);
|
938 |
|
939 |
// Remove the node in G10
|
940 |
_G10->RemoveNode(__mcEdge->get_id());
|
941 |
//V(this);
|
942 |
|
943 |
// Attach the MC Face to Graph nodes of G21 and G10
|
944 |
Graph_SetUserData(newMCFace);
|
945 |
//V(this);
|
946 |
|
947 |
printf ("Adding new merged face %d = { %d + %d }\n", faceId[2], faceId[0], faceId[1]);
|
948 |
|
949 |
__F[0] = face[0];
|
950 |
__F[1] = face[1];
|
951 |
__F[2] = newMCFace;
|
952 |
}
|
953 |
else // The arc represents an interior edge
|
954 |
{
|
955 |
Graph::Node *n = _G21->GetArc(__id)->First();
|
956 |
|
957 |
// if the arc is a loop then delete it
|
958 |
// in G2V : delete the g2v arc from the node and from the graph
|
959 |
_G21->RemoveArc(__id);
|
960 |
//V(this);
|
961 |
// in G1V : delete the g1v node from the graph
|
962 |
_G10->RemoveNode(__id);
|
963 |
//V(this);
|
964 |
|
965 |
__F[0] = 0;
|
966 |
__F[1] = 0;
|
967 |
__F[2] = GetMCFace(n);
|
968 |
//V(this);
|
969 |
}
|
970 |
}
|
971 |
|
972 |
//---------------------------------------------------------------------------
|
973 |
void
|
974 |
MCBody::SuppressMCVertex(MCVertex * __mcVertex, MCTChanges * __mctChanges)
|
975 |
{
|
976 |
printf("Deleting MC Vertex\t : ID \"%lu\" at adress %p\n",__mcVertex->get_id(), __mcVertex);
|
977 |
|
978 |
// Find the arc __name in G1V (G1 Virtual)
|
979 |
Graph::Arc *g1vArc = _G10->GetArc( __mcVertex->get_id() );
|
980 |
MCVertex * mcVertex = __mcVertex;
|
981 |
|
982 |
// Case of a B-Rep vertex separating only 2 edges
|
983 |
if ( g1vArc->Rank() == 2 )
|
984 |
{
|
985 |
// Get the 2 MC Edges separated by the MC Vertex
|
986 |
std::vector <MCEdge *> edge;
|
987 |
Vertex_GetAdjacentEdges( mcVertex, edge );
|
988 |
|
989 |
// Get the MC Faces Separated by the 2 MC Edges
|
990 |
std::set <MCFace *> listMCFaces = Edge_GetAdjacentFaces(edge[0]);
|
991 |
MCFace * mcFace[2];
|
992 |
std::set<MCFace*>::iterator itr=listMCFaces.begin();
|
993 |
for (unsigned i=0;i<2;i++)
|
994 |
{
|
995 |
mcFace[i] = *itr;
|
996 |
itr++;
|
997 |
}
|
998 |
|
999 |
// Unify parallel G21 arcs
|
1000 |
|
1001 |
// Create a unique arc in G2 Which connect n1 and n2
|
1002 |
Graph::Arc::MultimapNodesById newG21ArcNodes = _G21->GetArc( edge[0]->get_id() )->Nodes();
|
1003 |
_G21->RemoveArc( edge[0]->get_id() );
|
1004 |
_G21->RemoveArc( edge[1]->get_id() );
|
1005 |
|
1006 |
printf("the deleted vertex was adjacent to %d / %d faces\n", _G20->GetArc( __mcVertex->get_id() )->Rank(), listMCFaces.size());
|
1007 |
printf("the deleted vertex was adjacent to %d edges\n", _G10->GetArc( __mcVertex->get_id() )->Rank());
|
1008 |
// attach to the new node a edge attribute
|
1009 |
// constructed by the merge of the 2 edge attributes
|
1010 |
MCEdge * newMCEdge = AddMCEdge(edge[0], edge[1]);
|
1011 |
|
1012 |
_G21->AddArc(newMCEdge->get_id(), newG21ArcNodes);
|
1013 |
|
1014 |
// Merge nodes G10
|
1015 |
Graph::Node* n = _G10->MergeNodes(_G10->GetNode(edge[0]->get_id()), _G10->GetNode(edge[1]->get_id()), newMCEdge->get_id());
|
1016 |
// Remove G10 loop-arc to newNode
|
1017 |
_G10->RemoveArc( _G10->GetArc(__mcVertex->get_id()) );
|
1018 |
// Remove G20 arc
|
1019 |
_G20->RemoveArc( _G20->GetArc(__mcVertex->get_id()));
|
1020 |
|
1021 |
/// Operations using the resulting Graph of this MC Vertex
|
1022 |
/// Suppression :
|
1023 |
/// Get the vertex extremities of this new MC Edge
|
1024 |
/// and Add 2 Covertices
|
1025 |
std::vector<MCVertex*> mcVertexExtremities;
|
1026 |
Edge_GetVertices(newMCEdge, mcVertexExtremities);
|
1027 |
PolyCurve * newPolyCurve = newMCEdge->GetPolyCurve();
|
1028 |
|
1029 |
if (newPolyCurve->est_periodique())
|
1030 |
if (newPolyCurve->get_sommet1() != mcVertexExtremities[0]->GetRefVertex())
|
1031 |
newPolyCurve->SetPeriodicPoleRefVertex(mcVertexExtremities[0]->GetRefVertex());
|
1032 |
|
1033 |
AddMCEdgeCovertices(newMCEdge, mcVertexExtremities);
|
1034 |
/// Set graph user Data of new MCEdge G21 Arc and G10 Node
|
1035 |
Graph_SetUserData(newMCEdge);
|
1036 |
|
1037 |
if (__mctChanges)
|
1038 |
{
|
1039 |
// The mc vertex has been deleted
|
1040 |
__mctChanges->V.insert( std::make_pair (__mcVertex, (MCVertex*) NULL) );
|
1041 |
// The 2 adjacent edges have been merged together
|
1042 |
__mctChanges->E.insert( std::make_pair (edge[0], newMCEdge) );
|
1043 |
__mctChanges->E.insert( std::make_pair (edge[1], newMCEdge) );
|
1044 |
}
|
1045 |
}
|
1046 |
else if (g1vArc->Rank() == 0)
|
1047 |
{ // case of a vertex isolated in the domain of a face
|
1048 |
_G10->RemoveArc(_G10->GetArc(__mcVertex->get_id()));
|
1049 |
_G20->RemoveArc(_G20->GetArc(__mcVertex->get_id()));
|
1050 |
|
1051 |
if (__mctChanges)
|
1052 |
{
|
1053 |
// The mc vertex has been deleted
|
1054 |
__mctChanges->V.insert( std::make_pair (__mcVertex, (MCVertex*) NULL) );
|
1055 |
}
|
1056 |
}
|
1057 |
else
|
1058 |
{
|
1059 |
printf("Warning : MCBody can't delete vertex %d because its rank equals %d\n", g1vArc->Id(), g1vArc->Rank());
|
1060 |
}
|
1061 |
}
|
1062 |
|
1063 |
//---------------------------------------------------------------------------
|
1064 |
void MCBody::MergeVertices(MCVertex * __deleteVertex, MCVertex * __targetVertex, std::set<MCEdge*> & edges)
|
1065 |
{
|
1066 |
int V1_id, V2_id;
|
1067 |
MCVertex * V1, * V2;
|
1068 |
Graph::Arc * V1_G10Arc, *V2_G10Arc, *V1_G20Arc, *V2_G20Arc;
|
1069 |
V1=__deleteVertex; V1_id=V1->get_id();
|
1070 |
V2=__targetVertex; V2_id=V2->get_id();
|
1071 |
V1_G10Arc=_G10->GetArc(V1_id);
|
1072 |
V1_G20Arc=_G20->GetArc(V1_id);
|
1073 |
V2_G10Arc=_G10->GetArc(V2_id);
|
1074 |
V2_G20Arc=_G20->GetArc(V2_id);
|
1075 |
Graph::Arc::MultimapNodesById V1_G10Arc_MapNodes = V1_G10Arc->Nodes();
|
1076 |
Graph::Arc::MultimapNodesById V1_G20Arc_MapNodes = V1_G20Arc->Nodes();
|
1077 |
Graph::Arc::MultimapNodesById::iterator itNode;
|
1078 |
|
1079 |
// Initialize edge list
|
1080 |
for (itNode = V1_G10Arc_MapNodes.begin(); itNode != V1_G10Arc_MapNodes.end(); itNode++)
|
1081 |
{
|
1082 |
Graph::Node * n = itNode->second;
|
1083 |
MCEdge * e = GetMCEdge(n);
|
1084 |
edges.insert(e);
|
1085 |
}
|
1086 |
// Replace V1 by V2 in G20 and G10
|
1087 |
for (itNode = V1_G10Arc_MapNodes.begin(); itNode != V1_G10Arc_MapNodes.end(); itNode++)
|
1088 |
{
|
1089 |
Graph::Node * n = itNode->second;
|
1090 |
V2_G10Arc->Add(n);
|
1091 |
n->Add(V2_G10Arc);
|
1092 |
}
|
1093 |
_G10->RemoveArc(V1_G10Arc);
|
1094 |
for (itNode = V1_G20Arc_MapNodes.begin(); itNode != V1_G20Arc_MapNodes.end(); itNode++)
|
1095 |
{
|
1096 |
Graph::Node * n = itNode->second;
|
1097 |
V2_G20Arc->Add(n);
|
1098 |
n->Add(V2_G20Arc);
|
1099 |
}
|
1100 |
_G20->RemoveArc(V1_G20Arc);
|
1101 |
|
1102 |
// replace each covertices to V1 by covertex to V2
|
1103 |
int i,N;
|
1104 |
N=V1->get_nb_mg_cosommet();
|
1105 |
for (i=0; i<N; i++)
|
1106 |
{
|
1107 |
MG_COSOMMET * cov = V1->get_mg_cosommet(i);
|
1108 |
MCEdge * e = (MCEdge*) cov->get_arete();
|
1109 |
|
1110 |
cov = _refGeom->ajouter_mg_cosommet(e,V2);
|
1111 |
|
1112 |
if (e->get_cosommet1()->get_sommet()==V1)
|
1113 |
e->changer_cosommet1(cov);
|
1114 |
else if (e->get_cosommet2()->get_sommet()==V1)
|
1115 |
e->changer_cosommet2(cov);
|
1116 |
}
|
1117 |
|
1118 |
V2->Merge(V1);
|
1119 |
}
|
1120 |
//---------------------------------------------------------------------------
|
1121 |
/**
|
1122 |
* Edge collapse operator
|
1123 |
* arguments : name of the edge to be contracted, name of the vertex to contract the edge on
|
1124 |
*
|
1125 |
*/
|
1126 |
void MCBody::ContractEdgeToVertex(MCEdge * __mcEdge, MCVertex * __targetVertex, std::set <MCEdge*> & newEdges, std::set<MCEdge*> & oldEdges)
|
1127 |
{
|
1128 |
// E3 = mcedge V3 = target vertex V4 = delete vertex
|
1129 |
printf("Contracting\tMC Edge \"%lu\" to MC Vertex \"%lu\"\n", __mcEdge->get_id(), __targetVertex->get_id());
|
1130 |
|
1131 |
MCVertex * V3 = __targetVertex, * V4;
|
1132 |
MCEdge * E3 = __mcEdge;
|
1133 |
int V4_id, V3_id, E3_id;
|
1134 |
Graph::Arc * V4_G10Arc, *V3_G10Arc, * V4_G20Arc, *V3_G20Arc, * E3_G21Arc;
|
1135 |
Graph::Node * E3_G10Node;
|
1136 |
|
1137 |
V3_id = V3->get_id();
|
1138 |
V3_G10Arc = _G10->GetArc(V3_id);
|
1139 |
V3_G20Arc = _G20->GetArc(V3_id);
|
1140 |
|
1141 |
E3_id = E3->get_id();
|
1142 |
E3_G10Node = _G10->GetNode(E3_id);
|
1143 |
E3_G21Arc = _G21->GetArc(E3_id);
|
1144 |
|
1145 |
// Get G1 arc V4 the second incident arc to E3 different to V3
|
1146 |
for (Graph::Node::MultimapArcsById::const_iterator incidentArcIter = E3_G10Node->IncidentArcs().begin();
|
1147 |
incidentArcIter != E3_G10Node->IncidentArcs().end();
|
1148 |
incidentArcIter++)
|
1149 |
if (incidentArcIter->first != V3_id)
|
1150 |
V4_G10Arc = incidentArcIter->second;
|
1151 |
V4 = GetMCVertex(V4_G10Arc);
|
1152 |
V4_id = V4->get_id();
|
1153 |
V4_G20Arc = _G20->GetArc(V4_id);
|
1154 |
|
1155 |
// Merge E3 with edges that are adjacent to V4
|
1156 |
// get the nodes of the arc
|
1157 |
Graph::Arc::MultimapNodesById initialV4Nodes = V4_G10Arc->Nodes();
|
1158 |
for (Graph::Arc::MultimapNodesById::const_iterator itNode = initialV4Nodes.begin();
|
1159 |
itNode != initialV4Nodes.end();
|
1160 |
itNode++)
|
1161 |
{
|
1162 |
int id = itNode->first;
|
1163 |
|
1164 |
if (V4_G10Arc->IsLoopOfNode(id) || V3_G10Arc->IsLoopOfNode(E3_id)|| V4_G10Arc->IsLoopOfNode(E3_id) )
|
1165 |
{
|
1166 |
printf("Warning while Contracting\tMC Edge \"%d\" to MC Vertex \"%d\" \nArc %d is a loop of node %d\n",
|
1167 |
V4_id, E3_id, V3_id, id);
|
1168 |
|
1169 |
return;
|
1170 |
}
|
1171 |
}
|
1172 |
|
1173 |
|
1174 |
for (Graph::Arc::MultimapNodesById::const_iterator itNode = initialV4Nodes.begin();
|
1175 |
itNode != initialV4Nodes.end();
|
1176 |
itNode++)
|
1177 |
{
|
1178 |
oldEdges.insert(GetMCEdge(itNode->second));
|
1179 |
}
|
1180 |
|
1181 |
for (Graph::Arc::MultimapNodesById::const_iterator itNode = initialV4Nodes.begin();
|
1182 |
itNode != initialV4Nodes.end();
|
1183 |
itNode++)
|
1184 |
{
|
1185 |
int id = itNode->first;
|
1186 |
Graph::Node * node = itNode->second;
|
1187 |
|
1188 |
if (id != E3_id)
|
1189 |
{
|
1190 |
|
1191 |
// attach to the new node a MC edge attribute
|
1192 |
// constructed by the merge of the 2 edge attributes
|
1193 |
MCEdge * newEdge = AddMCEdge(GetMCEdge(id), E3);
|
1194 |
int newId = newEdge->get_id();
|
1195 |
|
1196 |
Graph::Node * newG10Node = _G10->MergeNodes(node, E3_G10Node, newId, true);
|
1197 |
printf("Edge Contraction : merging edges %d and %d in new edge %d\n", node->Id(), E3_id, newId);
|
1198 |
|
1199 |
// Create an edge in G2 named newVEdgeName and
|
1200 |
// conecting nodes n1_g2nodes
|
1201 |
Graph::Arc* newG21Arc = _G21->AddArc(newId, _G21->GetArc(id)->Nodes());
|
1202 |
|
1203 |
newEdges.insert(newEdge);
|
1204 |
}
|
1205 |
}
|
1206 |
for (Graph::Arc::MultimapNodesById::const_iterator itNode = V4_G20Arc->Nodes().begin();
|
1207 |
itNode != V4_G20Arc->Nodes().end();
|
1208 |
itNode++)
|
1209 |
{
|
1210 |
Graph::Node * n = itNode->second;
|
1211 |
int idN = itNode->first;
|
1212 |
if (E3_G21Arc->Nodes().find(idN) == E3_G21Arc->Nodes().end())
|
1213 |
{
|
1214 |
V3_G20Arc->Add(n);
|
1215 |
n->Add(V3_G20Arc);
|
1216 |
}
|
1217 |
}
|
1218 |
for (Graph::Arc::MultimapNodesById::const_iterator itNode = initialV4Nodes.begin();
|
1219 |
itNode != initialV4Nodes.end();
|
1220 |
itNode++)
|
1221 |
{
|
1222 |
// in G1 : remove the old edges adjacent to v4
|
1223 |
_G10->RemoveNode(itNode->first);
|
1224 |
|
1225 |
// In G2 :
|
1226 |
// remove the old edges adjacent to v4
|
1227 |
_G21->RemoveArc(itNode->first);
|
1228 |
}
|
1229 |
|
1230 |
_G20->RemoveArc(V4_id);
|
1231 |
_G10->RemoveArc(V4_id);
|
1232 |
|
1233 |
for (std::set<MCEdge*>::iterator itEdge=newEdges.begin();itEdge!=newEdges.end();itEdge++)
|
1234 |
{
|
1235 |
MCEdge * newEdge = *itEdge;
|
1236 |
Graph_SetUserData(newEdge);
|
1237 |
std::vector<MCVertex*> mcVertexExtremities;
|
1238 |
Edge_GetVertices(newEdge, mcVertexExtremities);
|
1239 |
AddMCEdgeCovertices(newEdge, mcVertexExtremities);
|
1240 |
}
|
1241 |
|
1242 |
V3->Merge(V4);
|
1243 |
}
|
1244 |
|
1245 |
//---------------------------------------------------------------------------
|
1246 |
void MCBody::Edge_GetVertices (MCEdge * __mcEdge, std::vector<MCVertex*> & __mcVertices)
|
1247 |
{
|
1248 |
// Get the incident G10 arcs to G10 node
|
1249 |
// they compose the loops of the MC face
|
1250 |
|
1251 |
Graph::Node::MultimapArcsById & arcsOfG10Node = _G10->GetNode( __mcEdge->get_id() )->IncidentArcs();
|
1252 |
|
1253 |
// Get each MC edge from incident arcs
|
1254 |
for ( Graph::Node::MultimapArcsById::const_iterator it = arcsOfG10Node.begin();
|
1255 |
it != arcsOfG10Node.end(); it++)
|
1256 |
{
|
1257 |
__mcVertices.push_back(GetMCVertex (it->second));
|
1258 |
}
|
1259 |
}
|
1260 |
|
1261 |
//---------------------------------------------------------------------------
|
1262 |
std::set < MCFace * >
|
1263 |
MCBody::Edge_GetAdjacentFaces(MCEdge * __mcEdge)
|
1264 |
{
|
1265 |
std::set < MCFace * > result;
|
1266 |
|
1267 |
// Get the G21 nodes to G21 arc
|
1268 |
// they compose the MC faces adjacent to the MC edge
|
1269 |
Graph::Arc *G21Arc = _G21->GetArc(__mcEdge->get_id());
|
1270 |
|
1271 |
Graph::Arc::MultimapNodesById & nodesOfG21Arc = G21Arc->Nodes();
|
1272 |
|
1273 |
|
1274 |
for (Graph::Arc::MultimapNodesById::const_iterator it = nodesOfG21Arc.begin();
|
1275 |
it != nodesOfG21Arc.end();
|
1276 |
it++)
|
1277 |
{
|
1278 |
|
1279 |
MCFace *mcFace = GetMCFace(it->second);
|
1280 |
result.insert( mcFace );
|
1281 |
|
1282 |
}
|
1283 |
|
1284 |
return result;
|
1285 |
}
|
1286 |
|
1287 |
|
1288 |
//---------------------------------------------------------------------------
|
1289 |
std::set < MCEdge * >
|
1290 |
MCBody::Face_GetAdjacentEdges(MCFace * __mcFace)
|
1291 |
{
|
1292 |
std::set < MCEdge * > result;
|
1293 |
|
1294 |
// Get the G21 arcs to G21 node
|
1295 |
// they compose the MC edges adjacent to the MC face
|
1296 |
Graph::Node *G21Node = _G21->GetNode(__mcFace->get_id());
|
1297 |
|
1298 |
Graph::Node::MultimapArcsById & arcsOfG21Node = G21Node->IncidentArcs();
|
1299 |
|
1300 |
|
1301 |
for (Graph::Node::MultimapArcsById::const_iterator it = arcsOfG21Node.begin();
|
1302 |
it != arcsOfG21Node.end();
|
1303 |
it++)
|
1304 |
{
|
1305 |
|
1306 |
result.insert( GetMCEdge(it->second) );
|
1307 |
|
1308 |
}
|
1309 |
|
1310 |
return result;
|
1311 |
}
|
1312 |
|
1313 |
std::vector < std::vector < MCEdge * > >
|
1314 |
MCBody::Face_GetUnsortedLoops(MCFace * __mcFace)
|
1315 |
{
|
1316 |
std::set < std::set < Graph::Node * > > loops;
|
1317 |
std::vector < std::vector < MCEdge * > > result;
|
1318 |
|
1319 |
// Extract G 10 subgraph of this face
|
1320 |
Graph::Graph * G10 = Face_G10SubGraph(__mcFace);
|
1321 |
|
1322 |
// Extract Strongly Connected Components
|
1323 |
// The SCC represent the BRep loop edges !
|
1324 |
std::set < std::set < Graph::Node * > > scc;
|
1325 |
Graph::FindSCC(G10,scc);
|
1326 |
|
1327 |
for (std::set < std::set < Graph::Node * > >::iterator it1 = scc.begin();
|
1328 |
it1 != scc.end();
|
1329 |
it1++
|
1330 |
)
|
1331 |
{
|
1332 |
std::vector <MCEdge * > loop;
|
1333 |
const std::set < Graph::Node * > & loopNodes = *it1;
|
1334 |
for ( std::set < Graph::Node * >::const_iterator it2 = loopNodes.begin();
|
1335 |
it2 != loopNodes.end();
|
1336 |
it2++)
|
1337 |
{
|
1338 |
Graph::Node * node = *it2;
|
1339 |
MCEdge * mcEdge = GetMCEdge( node );
|
1340 |
loop.push_back(mcEdge);
|
1341 |
}
|
1342 |
result.push_back(loop);
|
1343 |
}
|
1344 |
|
1345 |
delete G10;
|
1346 |
return result;
|
1347 |
}
|
1348 |
|
1349 |
std::vector < std::vector < MCEdge * > >
|
1350 |
MCBody::Face_GetCycles(MCFace * __mcFace)
|
1351 |
{
|
1352 |
std::set < std::set < Graph::Node * > > loops;
|
1353 |
std::vector < std::vector < MCEdge * > > result;
|
1354 |
|
1355 |
// Extract G 10 subgraph of this face
|
1356 |
Graph::Graph * G10 = Face_G10SubGraph(__mcFace);
|
1357 |
|
1358 |
// Extract Graph cycles
|
1359 |
// The graph cycles represent loops which toopology is a circle !
|
1360 |
std::vector < std::vector < Graph::Node * > > cycles;
|
1361 |
Graph::FindCycles(G10,cycles);
|
1362 |
|
1363 |
for (std::vector < std::vector < Graph::Node * > >::iterator it1 = cycles.begin();
|
1364 |
it1 != cycles.end();
|
1365 |
it1++
|
1366 |
)
|
1367 |
{
|
1368 |
std::vector <MCEdge * > mcEdgeLoop;
|
1369 |
std::vector < Graph::Node * > & cycleNodes = *it1;
|
1370 |
for ( std::vector < Graph::Node * >::iterator it2 = cycleNodes.begin();
|
1371 |
it2 != cycleNodes.end();
|
1372 |
it2++)
|
1373 |
{
|
1374 |
Graph::Node * node = *it2;
|
1375 |
MCEdge * mcEdge = GetMCEdge( node );
|
1376 |
mcEdgeLoop.push_back(mcEdge);
|
1377 |
}
|
1378 |
result.push_back(mcEdgeLoop);
|
1379 |
}
|
1380 |
|
1381 |
for (Graph::Graph::MapNodesById::const_iterator itNode = G10->GetNodes().begin();
|
1382 |
itNode != G10->GetNodes().end();
|
1383 |
itNode++)
|
1384 |
{
|
1385 |
Graph::Node * node = itNode->second;
|
1386 |
for (Graph::Node::MultimapArcsById::const_iterator itArc = node->IncidentArcs().begin();
|
1387 |
itArc != node->IncidentArcs().end();
|
1388 |
itArc ++)
|
1389 |
{
|
1390 |
Graph::Arc * arc = itArc->second;
|
1391 |
if ( arc->IsLoopOfNode(node->Id()) )
|
1392 |
{
|
1393 |
std::vector < MCEdge * > loop;
|
1394 |
MCEdge * mcEdge = GetMCEdge(node);
|
1395 |
loop.push_back(mcEdge);
|
1396 |
result.push_back(loop);
|
1397 |
}
|
1398 |
}
|
1399 |
}
|
1400 |
|
1401 |
delete G10;
|
1402 |
return result;
|
1403 |
}
|
1404 |
//---------------------------------------------------------------------------
|
1405 |
void MCBody::Face_GetMCVertices (MCFace * __mcFace, std::vector<MCVertex*> & __mcVertices)
|
1406 |
{
|
1407 |
// Get the incident G20 arcs to G20 node
|
1408 |
const Graph::Node::MultimapArcsById & arcsOfG20Node = _G20->GetNode(__mcFace->get_id())->IncidentArcs();
|
1409 |
|
1410 |
// Get each MC edge from incident arcs
|
1411 |
for ( Graph::Node::MultimapArcsById::const_iterator it = arcsOfG20Node.begin();
|
1412 |
it != arcsOfG20Node.end(); it++)
|
1413 |
{
|
1414 |
__mcVertices.push_back(GetMCVertex (it->second));
|
1415 |
}
|
1416 |
}
|
1417 |
|
1418 |
//---------------------------------------------------------------------------
|
1419 |
void MCBody::Vertex_GetAdjacentEdges(MCVertex * __mcVertex, std::vector<MCEdge *> & __list)
|
1420 |
{
|
1421 |
__list.clear();
|
1422 |
|
1423 |
Graph::Arc * a = _G10->GetArc(__mcVertex->get_id());
|
1424 |
for (Graph::Arc::MultimapNodesById::const_iterator it = a->Nodes().begin();
|
1425 |
it != a->Nodes().end();
|
1426 |
it++)
|
1427 |
{
|
1428 |
MCEdge * mcEdge = GetMCEdge(it->second);
|
1429 |
__list.push_back(mcEdge);
|
1430 |
}
|
1431 |
}
|
1432 |
|
1433 |
//---------------------------------------------------------------------------
|
1434 |
void MCBody::Vertex_GetAdjacentEdges(MCVertex * __mcVertex, std::set<MCEdge *> & __list)
|
1435 |
{
|
1436 |
__list.clear();
|
1437 |
|
1438 |
Graph::Arc * a = _G10->GetArc( __mcVertex->get_id() );
|
1439 |
for (Graph::Arc::MultimapNodesById::const_iterator it = a->Nodes().begin();
|
1440 |
it != a->Nodes().end();
|
1441 |
it++)
|
1442 |
{
|
1443 |
MCEdge * mcEdge = GetMCEdge(it->second);
|
1444 |
__list.insert(mcEdge);
|
1445 |
}
|
1446 |
}
|
1447 |
|
1448 |
|
1449 |
//---------------------------------------------------------------------------
|
1450 |
void MCBody::Vertex_GetAdjacentFaces(MCVertex * __mcVertex, std::set<MCFace *> & __list)
|
1451 |
{
|
1452 |
__list.clear();
|
1453 |
|
1454 |
Graph::Arc * a = _G20->GetArc(__mcVertex->get_id());
|
1455 |
for (Graph::Arc::MultimapNodesById::const_iterator it = a->Nodes().begin();
|
1456 |
it != a->Nodes().end();
|
1457 |
it++)
|
1458 |
{
|
1459 |
MCFace * mcFace = GetMCFace(it->second);
|
1460 |
__list.insert(mcFace);
|
1461 |
}
|
1462 |
}
|
1463 |
//---------------------------------------------------------------------------
|
1464 |
Graph::Graph * MCBody::Face_G10SubGraph(MCFace * __mcFace)
|
1465 |
{
|
1466 |
std::set < Graph::Node * > nodes;
|
1467 |
Graph::Graph * result;
|
1468 |
|
1469 |
// Get the G21 arcs to G21 node
|
1470 |
// they compose the MC edges adjacent to the MC face
|
1471 |
Graph::Node *G21Node = _G21->GetNode( __mcFace->get_id() );
|
1472 |
|
1473 |
Graph::Node::MultimapArcsById & arcsOfG21Node = G21Node->IncidentArcs();
|
1474 |
|
1475 |
|
1476 |
for (Graph::Node::MultimapArcsById::const_iterator it = arcsOfG21Node.begin();
|
1477 |
it != arcsOfG21Node.end();
|
1478 |
it++)
|
1479 |
{
|
1480 |
MCEdge * edge = GetMCEdge(it->second);
|
1481 |
Graph::Node * g10Node = _G10->GetNode(edge->get_id());
|
1482 |
nodes.insert(g10Node);
|
1483 |
}
|
1484 |
|
1485 |
result = new Graph::Graph(*_G10,nodes);
|
1486 |
|
1487 |
return result;
|
1488 |
}
|
1489 |
|
1490 |
//---------------------------------------------------------------------------
|
1491 |
MG_COARETE * MCBody::CreateCoEdge(MCFace * mcFace, MG_BOUCLE * mcLoop, MCEdge * mcEdge, int sense)
|
1492 |
{
|
1493 |
MG_COARETE * mcCoEdge = _refGeom->ajouter_mg_coarete (mcEdge, mcLoop, sense);
|
1494 |
mcLoop->ajouter_mg_coarete(mcCoEdge);
|
1495 |
return mcCoEdge;
|
1496 |
}
|
1497 |
//---------------------------------------------------------------------------
|
1498 |
int MCBody::ExportBRep_MCEdgeSense(MCFace * mcFace, MCEdge * mcEdge)
|
1499 |
{
|
1500 |
|
1501 |
// for each shell of the ref body
|
1502 |
unsigned nb_shells = _refBody->get_nb_mg_coquille ();
|
1503 |
for (unsigned it_shells = 0; it_shells < nb_shells; it_shells++)
|
1504 |
{
|
1505 |
MG_COQUILLE * shell = _refBody->get_mg_coquille(it_shells);
|
1506 |
// for each coface->face F of the shell
|
1507 |
unsigned nb_coface = shell->get_nb_mg_coface();
|
1508 |
for (unsigned it_coface = 0; it_coface < nb_coface; it_coface++)
|
1509 |
{
|
1510 |
MG_FACE * face = shell->get_mg_coface(it_coface)->get_face();
|
1511 |
|
1512 |
if ( ! mcFace->GetPolySurface()->Contains(face) )
|
1513 |
continue;
|
1514 |
|
1515 |
// for each loop L of this face
|
1516 |
unsigned nb_loop = face->get_nb_mg_boucle();
|
1517 |
for (unsigned it_loop = 0; it_loop < nb_loop; it_loop++)
|
1518 |
{
|
1519 |
MG_BOUCLE * loop = face->get_mg_boucle(it_loop);
|
1520 |
// for each coedge coe of L
|
1521 |
unsigned nb_edge = loop->get_nb_mg_coarete();
|
1522 |
for (unsigned it_edge = 0; it_edge < nb_edge; it_edge++)
|
1523 |
{
|
1524 |
MG_COARETE * coedge = loop->get_mg_coarete(it_edge);
|
1525 |
MG_ARETE * edge = coedge->get_arete();
|
1526 |
|
1527 |
int iRefEdge = -1;
|
1528 |
for (int itRefEdge = 0; itRefEdge != mcEdge->GetPolyCurve()->GetRefEdgeCount(); itRefEdge++)
|
1529 |
{
|
1530 |
|
1531 |
if (mcEdge->GetPolyCurve()->GetRefEdge(itRefEdge) == edge)
|
1532 |
{
|
1533 |
// Do not take reference edge if it is interior to the MC Face
|
1534 |
// (e.g. boundary edge contracted along an interior edge)
|
1535 |
int nbInteriorFaces = 0;
|
1536 |
for (int it_face2 = 0; it_face2 < edge->get_nb_mg_coarete(); it_face2++)
|
1537 |
{
|
1538 |
MG_FACE * face2 = edge->get_mg_coarete(it_face2)->get_boucle()->get_mg_face();
|
1539 |
if (mcFace->GetPolySurface()->Contains(face2))
|
1540 |
nbInteriorFaces ++;
|
1541 |
}
|
1542 |
if (nbInteriorFaces == 1)
|
1543 |
iRefEdge = itRefEdge;
|
1544 |
}
|
1545 |
}
|
1546 |
|
1547 |
if ( iRefEdge != -1 )
|
1548 |
{
|
1549 |
MG_SOMMET * polycurveStartRefVertex = mcEdge->GetPolyCurve()->GetRefVertex(iRefEdge);
|
1550 |
MG_ARETE * polycurveStartRefEdge = mcEdge->GetPolyCurve()->GetRefEdge(iRefEdge);
|
1551 |
|
1552 |
// Get the start vertex of this coedge
|
1553 |
// coedgeStartVertex = start ref vertex of coe1
|
1554 |
MG_SOMMET * coedgeStartVertex;
|
1555 |
if ( coedge->get_orientation() == 1)
|
1556 |
coedgeStartVertex = edge->get_cosommet1()->get_sommet();
|
1557 |
else
|
1558 |
coedgeStartVertex = edge->get_cosommet2()->get_sommet();
|
1559 |
|
1560 |
//
|
1561 |
// sense = ( coedgeStartVertex != v1 ) ? -1 : 1 ;
|
1562 |
int sense;
|
1563 |
if ( polycurveStartRefVertex != edge->get_cosommet1()->get_sommet() )
|
1564 |
sense = -coedge->get_orientation();
|
1565 |
else
|
1566 |
sense = coedge->get_orientation();
|
1567 |
|
1568 |
/*OT_VECTEUR_3D tangentPc, tangentRefEdge;
|
1569 |
PolyCurve * pc = mcEdge->GetPolyCurve();
|
1570 |
MG_SOMMET * polycurveStartRefVertex = pc->GetRefVertex(iRefEdge);
|
1571 |
MG_SOMMET * polycurveEndRefVertex = pc->GetRefVertex(iRefEdge+1);
|
1572 |
double sMid = .5*(pc->RefVertex_GetS(polycurveStartRefVertex)+pc->RefVertex_GetS(polycurveEndRefVertex));
|
1573 |
pc->deriver(sMid, tangentPc);
|
1574 |
double tMidRefEdge, dtMidRefEdge; MG_ARETE * tmpRefEdge;
|
1575 |
pc->Parameter_SToRefEdgeT(sMid, &tmpRefEdge, &tMidRefEdge, &dtMidRefEdge, false);
|
1576 |
tmpRefEdge->deriver(tMidRefEdge, tangentRefEdge);
|
1577 |
|
1578 |
double fSense = tangentRefEdge * tangentPc;
|
1579 |
int sense;
|
1580 |
if ( fSense < 0 )
|
1581 |
sense = -coedge->get_orientation();
|
1582 |
else
|
1583 |
sense = coedge->get_orientation(); */
|
1584 |
|
1585 |
return sense;
|
1586 |
}
|
1587 |
} // end for coedge
|
1588 |
} // end for face->loop
|
1589 |
} // end for coface
|
1590 |
} // end shell
|
1591 |
|
1592 |
return -10000;
|
1593 |
}
|
1594 |
MG_VOLUME * MCBody::ExportBRep()
|
1595 |
{
|
1596 |
int i,j,k;
|
1597 |
|
1598 |
std::ostringstream idBRepVolume;
|
1599 |
idBRepVolume << "MCBody of reference BRep "<< _refBody->get_idoriginal();
|
1600 |
_brep = new MG_VOLUME (idBRepVolume.str());
|
1601 |
_refGeom->ajouter_mg_volume(_brep);
|
1602 |
|
1603 |
MG_COQUILLE * mcShell = new MG_COQUILLE(_brep);
|
1604 |
_refGeom->ajouter_mg_coquille(mcShell, _brep);
|
1605 |
|
1606 |
{MCBODY_FOR_EACH_MCFACE(this, mcFace)
|
1607 |
{
|
1608 |
_refGeom->ajouter_mg_face(mcFace);
|
1609 |
|
1610 |
MG_COFACE * mcCoFace = _refGeom->ajouter_mg_coface(mcFace, mcShell, 1);
|
1611 |
mcShell->ajouter_mg_coface(mcCoFace);
|
1612 |
MG_SURFACE * surface = mcFace->get_surface();
|
1613 |
_refGeom->ajouter_mg_surface(surface);
|
1614 |
|
1615 |
std::set <MCEdge*> mcEdgeArray = Face_GetAdjacentEdges(mcFace);
|
1616 |
std::vector <MG_FACE*> faces;std::vector <MG_ARETE*> edges;std::vector <int> edgesense;
|
1617 |
for (std::set <MCEdge*>::iterator itEdge = mcEdgeArray.begin();
|
1618 |
itEdge != mcEdgeArray.end(); itEdge++)
|
1619 |
{
|
1620 |
MCEdge * mcEdge = *itEdge;
|
1621 |
|
1622 |
bool boundaryEdge = (!_G21->GetArc(mcEdge->get_id())->IsLoop());
|
1623 |
|
1624 |
// If the MC Edge is a boundary, then create an oriented coedge
|
1625 |
if (boundaryEdge)
|
1626 |
{
|
1627 |
faces.push_back(mcFace);
|
1628 |
edges.push_back(mcEdge);
|
1629 |
int sense = ExportBRep_MCEdgeSense(mcFace,mcEdge);
|
1630 |
edgesense.push_back(sense);
|
1631 |
}
|
1632 |
// If the MC Edge is interior, then create two coedges
|
1633 |
// with same sense and inverse sense
|
1634 |
else
|
1635 |
{
|
1636 |
faces.push_back(mcFace); faces.push_back(mcFace);
|
1637 |
edges.push_back(mcEdge);edges.push_back(mcEdge);
|
1638 |
edgesense.push_back(+1);edgesense.push_back(-1);
|
1639 |
}
|
1640 |
}
|
1641 |
std::vector < std::vector<CAD4FE::MakeLoops::CoEdge*> > loops;
|
1642 |
CAD4FE::MakeLoops makeLoops(faces,edges,edgesense);
|
1643 |
makeLoops.GetFaceLoops(mcFace,loops);
|
1644 |
for (unsigned k=0;k<loops.size();k++)
|
1645 |
{
|
1646 |
MG_BOUCLE * mcLoop = new MG_BOUCLE(mcFace);
|
1647 |
_refGeom->ajouter_mg_boucle(mcLoop, mcFace);
|
1648 |
for (unsigned l=0;l<loops[k].size();l++)
|
1649 |
{
|
1650 |
CAD4FE::MakeLoops::CoEdge* c = loops[k][l];
|
1651 |
CreateCoEdge(mcFace,mcLoop,(MCEdge*)c->Edge(),c->Sense());
|
1652 |
}
|
1653 |
}
|
1654 |
}}
|
1655 |
|
1656 |
{MCBODY_FOR_EACH_MCVERTEX(this, mcVertex)
|
1657 |
{
|
1658 |
MCFace * mcFace = 0;
|
1659 |
int test = TestInteriorVertexIsolatedInFace(mcVertex, &mcFace);
|
1660 |
if (test)
|
1661 |
{
|
1662 |
ExportBRep_CreateInteriorVertexIsolatedInFace(mcVertex, mcFace);
|
1663 |
}
|
1664 |
}}
|
1665 |
|
1666 |
return _brep;
|
1667 |
}
|
1668 |
|
1669 |
int MCBody::TestInteriorVertexIsolatedInFace(MCVertex * __mcVertex, MCFace ** __mcFace)
|
1670 |
{
|
1671 |
std::set<MCFace*> adjacentFaces;
|
1672 |
Vertex_GetAdjacentFaces(__mcVertex, adjacentFaces);
|
1673 |
std::set<MCEdge*> adjacentEdges;
|
1674 |
Vertex_GetAdjacentEdges(__mcVertex, adjacentEdges);
|
1675 |
|
1676 |
if ( adjacentFaces.size() == 1 && adjacentEdges.size() == 0)
|
1677 |
{
|
1678 |
*__mcFace = *(adjacentFaces.begin());
|
1679 |
return 1;
|
1680 |
}
|
1681 |
else
|
1682 |
{
|
1683 |
*__mcFace = 0;
|
1684 |
return 0;
|
1685 |
}
|
1686 |
}
|
1687 |
|
1688 |
int MCBody::ExportBRep_CreateInteriorVertexIsolatedInFace(MCVertex * __mcVertex, MCFace * __mcFace)
|
1689 |
{
|
1690 |
/*
|
1691 |
\item soit $RV$ le sommet r�f�rence du {\mcvertex} $V$,
|
1692 |
\item g�n�rer une {\mcedge}, not�e $E$, n'ayant aucune ar�te r�f�rence,
|
1693 |
mais contenant sommet r�f�rence $RV$,
|
1694 |
\item g�n�rer une coar�te $CE$ liant $E$ � $F$,
|
1695 |
\item ajouter � $F$ une boucle $B$ contenant $CE$
|
1696 |
*/
|
1697 |
PolyCurve * edgeCurve = new PolyCurve(__mcVertex->GetRefVertex());
|
1698 |
MCEdge * edge = AddMCEdge(edgeCurve);
|
1699 |
std::vector<MCVertex*> edgeVertices;
|
1700 |
for (int i=0;i<2;i++) edgeVertices.push_back(__mcVertex);
|
1701 |
AddMCEdgeCovertices(edge,edgeVertices);
|
1702 |
MG_BOUCLE * mcLoop = new MG_BOUCLE(__mcFace);
|
1703 |
_refGeom->ajouter_mg_boucle(mcLoop, __mcFace);
|
1704 |
CreateCoEdge(__mcFace, mcLoop, edge, +1);
|
1705 |
return 1;
|
1706 |
}
|
1707 |
|
1708 |
void MCBody::GetFEVCount(int * __faceCount,int * __edgeCount,int * __vertexCount)
|
1709 |
{
|
1710 |
* __faceCount = _G21->GetNodes().size();
|
1711 |
* __edgeCount = _G21->GetArcs().size();
|
1712 |
* __vertexCount = _G10->GetArcs().size();
|
1713 |
}
|
1714 |
|
1715 |
void MCBody::GetRefBodyFEVCount(int * __faceCount,int * __edgeCount,int * __vertexCount)
|
1716 |
{
|
1717 |
MG_UTILS::GetFEVCount(_refBody,__faceCount,__edgeCount,__vertexCount);
|
1718 |
}
|
1719 |
|
1720 |
int MCBody::DeleteBRep(MG_GESTIONNAIRE * gest, MG_GEOMETRIE * mggeo)
|
1721 |
{
|
1722 |
/// Lists of MCT entities
|
1723 |
std::set < CAD4FE::MCFace * > lst_mc_faces;
|
1724 |
std::set < CAD4FE::MCEdge * > lst_mc_edges;
|
1725 |
std::set < CAD4FE::MCVertex * > lst_mc_vertices;
|
1726 |
std::set < MG_COQUILLE * > lst_mc_shell;
|
1727 |
std::set < MG_BOUCLE * > lst_mc_loop;
|
1728 |
|
1729 |
// initialize MC face, MC edge, MC loop, MC shell, and MC vertices lists
|
1730 |
unsigned nb_shells = _brep->get_nb_mg_coquille ();
|
1731 |
for (unsigned it_shells = 0; it_shells < nb_shells; it_shells++)
|
1732 |
{
|
1733 |
MG_COQUILLE * shell = _brep->get_mg_coquille(it_shells);
|
1734 |
lst_mc_shell.insert(shell);
|
1735 |
unsigned nb_coface = shell->get_nb_mg_coface();
|
1736 |
for (unsigned it_coface = 0; it_coface < nb_coface; it_coface++)
|
1737 |
{
|
1738 |
CAD4FE::MCFace * face = (CAD4FE::MCFace *)shell->get_mg_coface(it_coface)->get_face();
|
1739 |
lst_mc_faces.insert(face);
|
1740 |
|
1741 |
unsigned nb_loop = face->get_nb_mg_boucle();
|
1742 |
for (unsigned it_loop = 0; it_loop < nb_loop; it_loop++)
|
1743 |
{
|
1744 |
MG_BOUCLE * loop = face->get_mg_boucle(it_loop);
|
1745 |
lst_mc_loop.insert(loop);
|
1746 |
unsigned nb_edge = loop->get_nb_mg_coarete();
|
1747 |
|
1748 |
for (unsigned it_edge = 0; it_edge < nb_edge; it_edge++)
|
1749 |
{
|
1750 |
CAD4FE::MCEdge * edge = (CAD4FE::MCEdge*)loop->get_mg_coarete(it_edge)->get_arete();
|
1751 |
lst_mc_edges.insert(edge);
|
1752 |
|
1753 |
lst_mc_vertices.insert ((CAD4FE::MCVertex*)edge->get_cosommet1()->get_sommet());
|
1754 |
lst_mc_vertices.insert ((CAD4FE::MCVertex*)edge->get_cosommet2()->get_sommet());
|
1755 |
}
|
1756 |
}
|
1757 |
}
|
1758 |
}
|
1759 |
|
1760 |
for (unsigned i=0;i<gest->get_nb_mg_maillage();)
|
1761 |
{
|
1762 |
MG_MAILLAGE * tmpMesh = gest->get_mg_maillage(i);
|
1763 |
LISTE_MG_TRIANGLE::iterator itTri;
|
1764 |
for (MG_TRIANGLE * tri = tmpMesh->get_premier_triangle(itTri);
|
1765 |
tri; tri = tmpMesh->get_suivant_triangle(itTri))
|
1766 |
if (lst_mc_faces.end() != lst_mc_faces.find((CAD4FE::MCFace*)tri->get_lien_topologie()))
|
1767 |
tmpMesh->supprimer_mg_triangleid(tri->get_id());
|
1768 |
LISTE_MG_SEGMENT::iterator itSeg;
|
1769 |
for (MG_SEGMENT * seg = tmpMesh->get_premier_segment(itSeg);
|
1770 |
seg; seg=tmpMesh->get_suivant_segment(itSeg) )
|
1771 |
if (lst_mc_edges.end() != lst_mc_edges.find((CAD4FE::MCEdge*)seg->get_lien_topologie())
|
1772 |
|| lst_mc_faces.end() != lst_mc_faces.find((CAD4FE::MCFace*)seg->get_lien_topologie())
|
1773 |
)
|
1774 |
tmpMesh->supprimer_mg_segmentid(seg->get_id());
|
1775 |
LISTE_MG_NOEUD::iterator itNo;
|
1776 |
for (MG_NOEUD * no = tmpMesh->get_premier_noeud(itNo);
|
1777 |
no; no=tmpMesh->get_suivant_noeud(itNo))
|
1778 |
if (
|
1779 |
lst_mc_vertices.end() != lst_mc_vertices.find((CAD4FE::MCVertex*)no->get_lien_topologie())
|
1780 |
|| lst_mc_edges.end() != lst_mc_edges.find((CAD4FE::MCEdge*)no->get_lien_topologie())
|
1781 |
|| lst_mc_faces.end() != lst_mc_faces.find((CAD4FE::MCFace*)no->get_lien_topologie())
|
1782 |
)
|
1783 |
tmpMesh->supprimer_mg_noeudid(no->get_id());
|
1784 |
|
1785 |
if (tmpMesh->get_nb_mg_noeud() == 0)
|
1786 |
gest->supprimer_mg_maillage(i);
|
1787 |
else
|
1788 |
i++;
|
1789 |
}
|
1790 |
for (std::set < MG_COQUILLE * >::iterator itShell = lst_mc_shell.begin();
|
1791 |
itShell != lst_mc_shell.end();
|
1792 |
itShell++)
|
1793 |
mggeo->supprimer_mg_coquilleid((*itShell)->get_id());
|
1794 |
for (std::set<CAD4FE::MCFace *>::iterator itFace = lst_mc_faces.begin(); itFace != lst_mc_faces.end(); itFace++)
|
1795 |
{
|
1796 |
CAD4FE::MCFace* mcFace=*itFace;
|
1797 |
CAD4FE::PolySurface * ps = mcFace->GetPolySurface();
|
1798 |
mggeo->supprimer_mg_faceid(mcFace->get_id());
|
1799 |
mggeo->supprimer_mg_surfaceid(ps->get_id());
|
1800 |
}
|
1801 |
for (std::set < MG_BOUCLE * >::iterator itLoop = lst_mc_loop.begin();
|
1802 |
itLoop != lst_mc_loop.end();
|
1803 |
itLoop++)
|
1804 |
mggeo->supprimer_mg_boucleid((*itLoop)->get_id());
|
1805 |
|
1806 |
for (std::set<CAD4FE::MCEdge *>::iterator itEdge = lst_mc_edges.begin(); itEdge != lst_mc_edges.end(); itEdge++)
|
1807 |
{
|
1808 |
CAD4FE::MCEdge* mcEdge=*itEdge;
|
1809 |
CAD4FE::PolyCurve * pc=mcEdge->GetPolyCurve();
|
1810 |
mggeo->supprimer_mg_areteid(mcEdge->get_id());
|
1811 |
mggeo->supprimer_mg_courbeid(pc->get_id());
|
1812 |
}
|
1813 |
for (std::set<CAD4FE::MCVertex *>::iterator itVertex = lst_mc_vertices.begin(); itVertex != lst_mc_vertices.end(); itVertex++)
|
1814 |
{
|
1815 |
CAD4FE::MCVertex * mcVertex = *itVertex; |
1816 |
mggeo->supprimer_mg_sommetid(mcVertex->get_id()); |
1817 |
} |
1818 |
mggeo->supprimer_mg_volumeid(_brep->get_id()); |
1819 |
return 1; |
1820 |
}
|