MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
sld_import_tessellation.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// sld_import_tessellation.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:58:53 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 
23 #pragma hdrstop
24 
25 #include "gestionversion.h"
26 #ifdef BREP_SLD
27 
28 #include "mg_maillage_outils.h"
29 #include "sld_import.h"
30 #include "mg_geometrie.h"
31 #include "mg_gestionnaire.h"
32 #include "sld_surface.h"
33 #include "sld_point.h"
34 #include "sld_courbe.h"
35 #include "lc_point.h"
36 #include "sld_fonction.h"
37 #include "tpl_grille.h"
39 #include "ot_root_find.h"
41 
42 
43 #include <atl\atlmod.h>
44 #include "smartvars.h"
45 #include <string.h>
46 #include <stdio.h>
47 #include <math.h>
48 
50 #pragma package(smart_init)
51 
53 {
54  tess = NULL;
55 }
56 
58 {
59  for (std::map<MG_FACE *, double *>::const_iterator it_face_tessPts = lst_face_tessPts.begin();
60  it_face_tessPts != lst_face_tessPts.end();
61  it_face_tessPts ++)
62  {
63  double * tessPts = it_face_tessPts->second;
64  delete [] tessPts;
65  }
66 }
67 
68 void SLD_IMPORT_TESSELLATION::GetFaceMeshNormal(MG_FACE * __face, MG_NOEUD * __node, double __normal[3])
69 {
70  double angleTot=0;
71  OT_VECTEUR_3D normalTriangle(0,0,0);
72 
73  TPL_LISTE_ENTITE<MG_TRIANGLE*>* adjacentTriangles = __node->get_lien_triangle();
74  int itTriang;
75  for (itTriang=0;itTriang <adjacentTriangles->get_nb(); itTriang++)
76  {
77  MG_TRIANGLE* t = adjacentTriangles->get(itTriang);
78  MG_FACE * refFace = (MG_FACE*) t->get_lien_topologie();
79  if ( __face != refFace )
80  continue;
81  int id=-1;
82  MG_NOEUD * nos[3]={t->get_noeud1(),t->get_noeud2(),t->get_noeud3()};
83  for (int j=0;j<3;j++)
84  if (nos[j] == __node)
85  {
86  id = j;
87  break;
88  }
89  OT_VECTEUR_3D x[3];
90  for (int j=0;j<3;j++)
91  x[j]=OT_VECTEUR_3D(nos[j]->get_coord());
92  OT_VECTEUR_3D x1x2 = x[id]-x[(id+2)%3];
93  x1x2.norme();
94  OT_VECTEUR_3D x2x3 = x[(id+1)%3]-x[id];
95  x2x3.norme();
96  OT_VECTEUR_3D normal = x1x2&x2x3;
97  double angle = acos(-(x1x2*x2x3));
98  normal *= angle;
99  angleTot += angle;
100  normalTriangle += normal;
101  }
102  if (angleTot != 0)
103  {
104  normalTriangle /= angleTot;
105  for (int j=0;j<3;j++)
106  __normal[j]=normalTriangle[j];
107  }
108  else
109  {
110  for (int j=0;j<3;j++)
111  __normal[j]=0;
112  }
113 }
114 
115 /*
116 int SLD_IMPORT_TESSELLATION::VerifyFaceOrientation(MG_FACE * __face)
117 {
118  std::set <MG_NOEUD*> testedNodes;
119  int nbNodeInSameSense = 0;
120  int nbNodeInOppositeSense = 0;
121  for (int itLoop=0; itLoop!=__face->get_nb_mg_boucle(); itLoop++)
122  for (int itCoEdge=0; itCoEdge!=__face->get_mg_boucle(itLoop)->get_nb_mg_coarete(); itCoEdge++)
123  {
124  MG_ARETE * edge = __face->get_mg_boucle(itLoop)->get_mg_coarete(itCoEdge)->get_arete();
125  TPL_SET< MG_ELEMENT_MAILLAGE * > * tess=edge->get_lien_maillage();
126  TPL_SET< MG_ELEMENT_MAILLAGE * >::ITERATEUR itSeg;
127  for (MG_SEGMENT * seg = (MG_SEGMENT *)tess->get_premier(itSeg); seg; seg = (MG_SEGMENT *)tess->get_suivant(itSeg) )
128  {
129  testedNodes.insert(seg->get_noeud1());
130  testedNodes.insert(seg->get_noeud2());
131  }
132  }
133  for (std::set<MG_NOEUD*>::iterator itNode=testedNodes.begin();itNode!=testedNodes.end();itNode++)
134  {
135  MG_NOEUD * node=*itNode;
136  double uv[2];
137  double xyzFaceNormal[3];
138  __face->inverser(uv,node->get_coord());
139  double dist;
140  __face->calcul_normale_unitaire(uv,xyzFaceNormal);
141  double xyzTessNormal[3];
142  GetFaceMeshNormal(__face,node,xyzTessNormal);
143  double sense = OT_ALGORITHME_GEOMETRIQUE::VEC3_DOT_VEC3(xyzTessNormal,xyzFaceNormal);
144  if (sense > 0)
145  nbNodeInSameSense++;
146  if (sense < 0)
147  nbNodeInOppositeSense++;
148  }
149  if (nbNodeInSameSense > 0 && nbNodeInOppositeSense == 0)
150  return 1;
151  if (nbNodeInSameSense == 0 && nbNodeInOppositeSense > 0)
152  return -1;
153  VerifyFaceOrientation(__face);
154  return 0;
155 }
156 
157 int
158 SLD_IMPORT_TESSELLATION::ProjectPointToEdge(MG_ARETE * __edge, double __maxDist, double __x[3], double __newX[3])
159 {
160  double t;
161  __edge->inverser(t,__x);
162  double brackT[2]={t,t};
163 
164  CAD4FE::MG_ARETE_ClosestPointOn tool(__x, __edge);
165  OT_ROOT_FIND_1D::ZeroBracOut(
166  CAD4FE::MG_ARETE_ClosestPointOn::_Function_Plane_Edge_SquaredDist,
167  __edge->get_tmin(), __edge->get_tmax(),
168  brackT[0],
169  brackT[1],
170  &tool);
171 
172  double newT = OT_ROOT_FIND_1D::RootSafe(
173  CAD4FE::MG_ARETE_ClosestPointOn::_Function_Plane_Edge_SquaredDist,
174  CAD4FE::MG_ARETE_ClosestPointOn::_Derivative_Plane_Edge_SquaredDist,
175  brackT[0], brackT[1], 1E-6*( __edge->get_tmax() - __edge->get_tmin() ),
176  &tool);
177 
178  if (newT > 1E100)
179  {
180  for (int i=0;i<3;i++) __newX[i]=__x[i];
181  printf("Error while projecting point to edge %d\n", __edge->get_id());
182  return 0;
183  }
184 
185  __edge->evaluer(newT, __newX);
186  double dist = OT_ALGORITHME_GEOMETRIQUE::VEC3_DISTANCE_VEC3(__newX,__x);
187 
188  if (dist > __maxDist)
189  {
190  for (int i=0;i<3;i++) __newX[i]=__x[i];
191  printf("Error while projecting point to edge %d\n", __edge->get_id());
192  return 0;
193  }
194 
195  return 1;
196 } */
197 
198 template <class A>
199 void
200 cstr_grid(double __bbox[6], int __nb_steps[3], TPL_GRILLE<A> & __grid)
201 {
202  double center[3];
203  for (int i=0; i<3; i++)
204  center[i] = .5*(__bbox[i] + __bbox[3+i]);
205 
206  double step[3];
207  for (int i=0; i<3; i++)
208  step[i] = (__bbox[3+i] - __bbox[i])/__nb_steps[i];
209 
210 
211  double bbox[6];
212  for (int i=0; i<6; i++) bbox[i] = __bbox[i];
213 
214  for (int i=0; i<3; i++)
215  bbox[i+3] += .1*step[i];
216  for (int i=0; i<3; i++)
217  bbox[i] -= .1*step[i];
218 
219  __grid.initialiser(bbox[0], bbox[1], bbox[2], bbox[3], bbox[4], bbox[5], __nb_steps[0], __nb_steps[1], __nb_steps[2]);
220 }
221 
223 SLD_IMPORT_TESSELLATION::importer(class MG_GESTIONNAIRE& gest,char *path, double tessellationTolerance)
224 {
225  MG_GEOMETRIE * geom = SLD_IMPORT::importer(gest,path);
226  return importer_tessellation(gest,geom, gest.get_sld_fonction(),tessellationTolerance);
227 }
228 
231 {
232  if (tessellationTolerance != 0)
233  {
234  fonction.Modeler_SetToleranceValue(4,tessellationTolerance);
235  fonction.Modeler_SetToleranceValue(6,tessellationTolerance);
236  }
237 
238  // Get the tessellation of each face
240  unsigned nb_shells = body->get_nb_mg_coquille ();
241  for (unsigned it_shells = 0; it_shells < nb_shells; it_shells++)
242  {
243  MG_COQUILLE * shell = body->get_mg_coquille(it_shells);
244  unsigned nb_coface = shell->get_nb_mg_coface();
245  for (unsigned it_coface = 0; it_coface < nb_coface; it_coface++)
246  {
247  MG_FACE * face = shell->get_mg_coface(it_coface)->get_face();
248  double * tessPts;
249  long nbTessTriang;
250 
251  CComPtr<IFace2> sld_face;
252  fonction.GetParID((char*)face->get_idoriginal().c_str(), sld_face);
253  fonction.get_face_tessellation(sld_face, &(nbTessTriang), &(tessPts));
254  lst_face_tessPts[face] = tessPts;
255  lst_face_nbTessTriangles[face] = nbTessTriang;
256  printf("Face \"%s\" has %d triangles\n", face->get_idoriginal().c_str(), nbTessTriang);
257  }
258  }
259 
260  // Compute the boundary box of the tessellation
261  // bbox [6] = {x_min, y_min, z_min, x_max, y_max, z_max}
262  double bbox[6] = {1E308, 1E308, 1E308, -1E308, -1E308, -1E308};
263  for (std::map<MG_FACE *, double *>::const_iterator it_face_tessPts = lst_face_tessPts.begin();
264  it_face_tessPts != lst_face_tessPts.end();
265  it_face_tessPts ++)
266  {
267  MG_FACE * face = it_face_tessPts->first;
268  double * tessPts = it_face_tessPts->second;
269  long nbTessTriang = lst_face_nbTessTriangles[face];
270 
271  // scan each point of the tessellation
272  for (long itPt = 0; itPt < 9*nbTessTriang; itPt += 3)
273  {
274  double vertex [3];
275  for (int i=0; i<3; i++)
276  {
277  vertex[i] = tessPts[ itPt + i ];
278  if (vertex[i] < bbox[i])
279  bbox[i+0] = vertex[i];
280  if (vertex[i] > bbox[i+3])
281  bbox[i+3] = vertex[i];
282  }
283  }
284  }
285 
286 
287  // Construct the tessellation of the bodies
288  tess = new MG_MAILLAGE (geom);
291  int nb_step_grid [3] = {34,34,34};
292  cstr_grid<MG_NOEUD*>(bbox, nb_step_grid, grid);
293  double epsilon = 1E-8*sqrt(pow(bbox[3]-bbox[0],2)+pow(bbox[4]-bbox[1],2)+pow(bbox[5]-bbox[2],2));
294  epsilon = std::max(1E-14,epsilon);
295  for (std::map<MG_FACE *, double *>::const_iterator it_face_tessPts = lst_face_tessPts.begin();
296  it_face_tessPts != lst_face_tessPts.end();
297  it_face_tessPts ++)
298  {
299  MG_FACE * face = it_face_tessPts->first;
300  double * tessPts = it_face_tessPts->second;
301  long nbTessTriang = lst_face_nbTessTriangles[face];
302 
303  // Create triangles on the faces of the body
304  for (long iTriang = 0; iTriang < nbTessTriang; iTriang ++)
305  {
306  MG_NOEUD * triangNodes[3];
307  MG_TRIANGLE * triang;
308 
309  for (int iVert = 0; iVert < 3; iVert ++)
310  {
311  double vertex[3];
312  for (int j = 0; j < 3; j++)
313  vertex [j] = tessPts[ 9*iTriang + 3*iVert + j ];
314 
315  // Check if vertex exist in the grid
316  TPL_MAP_ENTITE<MG_NOEUD*> neighbouring_nodes;
317  grid.rechercher(vertex[0], vertex[1], vertex[2], epsilon, neighbouring_nodes);
318 
319  int nb_neighbours = neighbouring_nodes.get_nb();
320  double distance_closest_node = 1E308;
321  MG_NOEUD * closest_node = NULL;
322  for (int itNode=0; itNode<nb_neighbours; itNode++)
323  {
324  MG_NOEUD * n = neighbouring_nodes.get(itNode);
325  double node_vertex_distance = pow(n->get_x()-vertex[0],2) + pow(n->get_y()-vertex[1],2) + pow(n->get_z()-vertex[2],2);
326  if ( node_vertex_distance < distance_closest_node )
327  {
328  distance_closest_node = node_vertex_distance;
329  closest_node = n;
330  }
331  }
332  if ( distance_closest_node > epsilon*epsilon )
333  {
334  // if no nodes exist in the neighbouring of the vertex, then add a new node
335  triangNodes[iVert] = tess->ajouter_mg_noeud (face, vertex[0], vertex[1], vertex[2],TRIANGULATION);
336  // Add the new node to the grid
337  grid.inserer( triangNodes[iVert] );
338  }
339  else
340  {
341  triangNodes[iVert] = closest_node;
342  }
343  }
344  tess->ajouter_mg_triangle(face, triangNodes[0], triangNodes[1], triangNodes[2],TRIANGULATION);
345  }
346  std::vector<MG_SEGMENT*> tmp;
347  lst_face_contourSegments[face] = tmp;
348  }
349 
350 
352 
353 
354  // vector containing missing vertex nodes
355  // (node that have to be inserted in the tessellation
356  // to represent a vertex missing in the tessellation)
357  std::vector<MG_NOEUD*> missing_vertex_node;
358  double epsilon_vertex = 1E-6*sqrt(pow(bbox[3]-bbox[0],2)+pow(bbox[4]-bbox[1],2)+pow(bbox[5]-bbox[2],2));
359  // Construct the tessellation of the vertices of the body
360  long nb_vertices = geom->get_nb_mg_sommet();
361  for (long iVert = 0; iVert < nb_vertices; iVert++)
362  {
363  MG_SOMMET * vertex = geom->get_mg_sommet(iVert);
364  double vertex_pos [3];
365  vertex->get_point()->evaluer(vertex_pos);
366 
367  // Check if vertex exist in the grid
368  TPL_MAP_ENTITE<MG_NOEUD*> neighbouring_nodes;
369  grid.rechercher(vertex_pos[0], vertex_pos[1], vertex_pos[2], epsilon_vertex, neighbouring_nodes);
370 
371  int nb_neighbours = neighbouring_nodes.get_nb();
372  double distance_closest_node = 1E308;
373  MG_NOEUD * closest_node = NULL;
374  for (int itNode=0; itNode<nb_neighbours; itNode++)
375  {
376  MG_NOEUD * n = neighbouring_nodes.get(itNode);
377  double node_vertex_distance = pow(n->get_x()-vertex_pos[0],2)+pow(n->get_y()-vertex_pos[1],2)+pow(n->get_z()-vertex_pos[2],2);
378  if ( node_vertex_distance < distance_closest_node && node_vertex_distance < epsilon_vertex*epsilon_vertex )
379  {
380  distance_closest_node = node_vertex_distance;
381  closest_node = n;
382  }
383  }
384  if (closest_node)
385  {
386  closest_node->change_lien_topologie(vertex);
387  closest_node->change_coord(vertex_pos);
388  }
389  else
390  {
391  // if no nodes exist in the neighbouring of the vertex_pos, then
392  // it is an error in the tessellation of the body
393  printf("Warning : while importing SW tessellation, the distance between the vertex and the tessellation node is\n");
394  printf("%e while the tolerance is %e\n", sqrt(distance_closest_node), epsilon_vertex);
395  printf("Warning : while importing the tessellation from SW no tessellation node was found for vertex id %d\n", vertex->get_id());
396  printf("A new node located of the missing vertex \n is gonna be inserted on the closest contour segment\n");
397  MG_NOEUD * n = new MG_NOEUD(vertex, vertex_pos[0], vertex_pos[1], vertex_pos[2],TRIANGULATION);
399  missing_vertex_node.push_back(n);
400  }
401  }
402 
403  // Construct the tessellation of the edges of the body
404  LISTE_MG_SEGMENT::iterator itSeg;
405  for (MG_SEGMENT * seg=tess->get_premier_segment(itSeg);
406  seg; seg=tess->get_suivant_segment(itSeg))
407  {
408  TPL_LISTE_ENTITE<MG_TRIANGLE*> * lst_triangle = seg->get_lien_triangle();
409 
410  unsigned nb_adj_triang = lst_triangle->get_nb();
411  if (nb_adj_triang == 0)
412  continue;
413  if (nb_adj_triang == 1)
414  {
415  continue;
416  }
417 
418  std::set <MG_FACE * > adjacent_faces;
419 
420  for (unsigned it_triang = 0; it_triang < nb_adj_triang; it_triang++)
421  {
422  MG_ELEMENT_TOPOLOGIQUE * topo = lst_triangle->get(it_triang)->get_lien_topologie();
423  MG_FACE * face = (MG_FACE*) topo;
424 
425  adjacent_faces.insert(face);
426  }
427  if (adjacent_faces.size() > 1)
428  {
429  for (std::set <MG_FACE*>::const_iterator it_adjacent_face = adjacent_faces.begin();
430  it_adjacent_face != adjacent_faces.end();
431  it_adjacent_face++)
432  {
433  MG_FACE * adj_face = *it_adjacent_face;
434  lst_face_contourSegments[adj_face].push_back(seg);
435  }
436  }
437  }
438 
439  std::set <MG_ARETE *> lst_missing_vertex_edge;
440  for (unsigned it_node = 0; it_node < missing_vertex_node.size(); it_node++)
441  {
442  MG_NOEUD * n = missing_vertex_node[it_node];
443  MG_SOMMET * vertex = (MG_SOMMET*) n->get_lien_topologie();
444 
445  // Get the edges adjacent to this vertex
446  std::set <MG_FACE*> lst_adjacent_faces;
447  int it_cov;
448  for (it_cov = 0; it_cov < vertex->get_nb_mg_cosommet(); it_cov++)
449  {
450  MG_ARETE * edge = vertex->get_mg_cosommet(it_cov)->get_arete();
451  int nb_adjacent_faces = edge->get_nb_mg_coarete();
452 
453  lst_missing_vertex_edge.insert(edge);
454 
455  for (int j=0; j < nb_adjacent_faces; j++)
456  lst_adjacent_faces.insert ( edge->get_mg_coarete(j)->get_boucle()->get_mg_face() );
457  }
458 
459  // Get the tessellation of the contours of the faces
460  // that are shared by several faces
461  // These segments are the tessellation of edges
462  // which join adjacent faces
463  std::set<MG_SEGMENT*> visited_segs;
464  std::set<MG_SEGMENT*> shared_segs;
465  for (std::set<MG_FACE *>::iterator
466  it_face = lst_adjacent_faces.begin();
467  it_face != lst_adjacent_faces.end();
468  it_face ++)
469  {
470  MG_FACE * face = *it_face;
471 
472  const std::vector < MG_SEGMENT *> & segs = lst_face_contourSegments[face];
473 
474  for (std::vector<MG_SEGMENT *>::const_iterator
475  itSegs = segs.begin();
476  itSegs != segs.end();
477  itSegs ++ )
478  {
479  bool segment_shared_by_several_faces = (visited_segs.find(*itSegs) != visited_segs.end() );
480  if (segment_shared_by_several_faces)
481  shared_segs.insert(*itSegs);
482  else
483  visited_segs.insert(*itSegs);
484  }
485  }
486 
487  double n_xyz[3];
488  n_xyz[0] = n->get_x();
489  n_xyz[1] = n->get_y();
490  n_xyz[2] = n->get_z();
491 
492  // Find the closest segment to this node
493  double minDist = 1E99;
494  MG_SEGMENT * closestSeg = NULL;
495  for (std::set<MG_SEGMENT *>::iterator it_seg = shared_segs.begin();
496  it_seg != shared_segs.end(); it_seg++)
497  {
498  MG_SEGMENT * seg = *it_seg;
499  double seg_xyz[2][3];
500  MG_NOEUD *seg_nodes [2];
501  seg_nodes[0] = seg->get_noeud1();
502  seg_nodes[1] = seg->get_noeud2();
503  seg_xyz[0][0] = seg_nodes[0]->get_x();
504  seg_xyz[0][1] = seg_nodes[0]->get_y();
505  seg_xyz[0][2] = seg_nodes[0]->get_z();
506  seg_xyz[1][0] = seg_nodes[1]->get_x();
507  seg_xyz[1][1] = seg_nodes[1]->get_y();
508  seg_xyz[1][2] = seg_nodes[1]->get_z();
509  double distance = OT_ALGORITHME_GEOMETRIQUE::Dist3D_Point_Segment(seg_xyz[0],seg_xyz[1],n_xyz);
510  if (distance < minDist)
511  {
512  minDist = distance;
513  closestSeg = seg;
514  }
515  }
516 
517  MG_SEGMENT * splitSegs[2];
518  MG_MAILLAGE_OUTILS::inserer_noeud_segment(tess, n, closestSeg, splitSegs);
519 
520 
521  for (std::set<MG_FACE *>::iterator
522  it_face = lst_adjacent_faces.begin();
523  it_face != lst_adjacent_faces.end();
524  it_face ++)
525  {
526  MG_FACE * face = *it_face;
527 
528  std::vector < MG_SEGMENT *> & segs = lst_face_contourSegments[face];
529 
530  std::vector<MG_SEGMENT*>::iterator itSeg = std::find(segs.begin(), segs.end(), closestSeg);
531  if (itSeg != segs.end())
532  {
533  segs.erase(itSeg);
534  segs.push_back(splitSegs[0]);
535  segs.push_back(splitSegs[1]);
536  }
537  }
538  }
539 
540 
541 
542  long nb_edges = geom->get_nb_mg_arete();
543  std::set<MG_ARETE *> lst_recognized_edge;
544  for (long it_edge = 0; it_edge < nb_edges; it_edge++)
545  {
546  MG_ARETE * edge = geom->get_mg_arete(it_edge);
547 
548  // Get the faces adjacent to edge
549  int nb_adjacent_faces = edge->get_nb_mg_coarete();
550  std::set<MG_FACE *> lst_adjacent_faces;
551  for (int j=0; j < nb_adjacent_faces; j++)
552  lst_adjacent_faces.insert ( edge->get_mg_coarete(j)->get_boucle()->get_mg_face() );
553 
554 
555  // Get the tessellation of the contours of the faces
556  // that are shared by several faces
557  // These segments are the tessellation of edges
558  // which join adjacent faces
559  std::set<MG_SEGMENT*> visited_segs;
560  std::set<MG_SEGMENT*> shared_segs;
561  for (std::set<MG_FACE *>::iterator
562  it_face = lst_adjacent_faces.begin();
563  it_face != lst_adjacent_faces.end();
564  it_face ++)
565  {
566  MG_FACE * face = *it_face;
567 
568  const std::vector < MG_SEGMENT *> & segs = lst_face_contourSegments[face];
569 
570  for (std::vector<MG_SEGMENT *>::const_iterator
571  itSegs = segs.begin();
572  itSegs != segs.end();
573  itSegs ++ )
574  {
575  bool segment_shared_by_several_faces = (visited_segs.find(*itSegs) != visited_segs.end() );
576  if (segment_shared_by_several_faces)
577  shared_segs.insert(*itSegs);
578  else
579  visited_segs.insert(*itSegs);
580  }
581  }
582 
583  std::set<MG_ARETE*> lst_candidate_edge;
584  MG_MAILLAGE_OUTILS::FindCommonEdgesOfFaces(lst_adjacent_faces, lst_candidate_edge);
585 
586  std::set < MG_SEGMENT * > segs = shared_segs;
587  // Tant que (segs) n'est pas vide :
588  while (segs.size())
589  {
590  //((segs^E), N^i') = Parcourir ( (segs), (Nv), (visited_seg), (visited_N)) :
591  std::vector <MG_SEGMENT *> visitedSegs;
592  std::vector <MG_NOEUD * > visitedNodes;
593 
594  if (lst_missing_vertex_edge.find(edge) != lst_missing_vertex_edge.end())
595  printf("Trying to recognize segments of an edge which had a missing vertex !\n");
596 
597  MG_MAILLAGE_OUTILS::classe_elements_dimension1(segs, visitedSegs, visitedNodes);
598  std::set < MG_SOMMET * > edgeExtremities;
599  MG_SOMMET * vertex1=(MG_SOMMET*) visitedNodes[ 0 ]->get_lien_topologie();
600  MG_SOMMET * vertex2=((MG_SOMMET*) visitedNodes[ visitedNodes.size()-1 ]->get_lien_topologie());
601  edgeExtremities.insert ( vertex1 );
602  edgeExtremities.insert ( vertex2 );
603 
604  MG_ARETE * coincident_edge=0;
605 
606  if (visitedSegs.size() == 0)
607  printf("No segments were found for edge %d", edge->get_id());
608 
609  // if there is no more segments for other edges, then
610  // use edge in priority !
611 
612  if (lst_candidate_edge.size() == 1)
613  {
614  coincident_edge = *(lst_candidate_edge.begin());
615  }
616  else
617  {
618  MG_MAILLAGE_OUTILS::IdentifyEdge3 ( edgeExtremities, lst_candidate_edge, visitedNodes, &coincident_edge );
619 
620  std::set<MG_ARETE*>::iterator it_candidate_edge = lst_candidate_edge.find(coincident_edge);
621  if (it_candidate_edge != lst_candidate_edge.end())
622  lst_candidate_edge.erase(it_candidate_edge);
623  }
624 
625  lst_recognized_edge.insert(coincident_edge);
626 
627  if (coincident_edge != edge)
628  continue;
629 
630  for (std::vector<MG_SEGMENT*>::iterator it_visitedSegs = visitedSegs.begin();
631  it_visitedSegs != visitedSegs.end();
632  it_visitedSegs++)
633  {
634  MG_SEGMENT * segment = (*it_visitedSegs);
635  segment->change_lien_topologie(coincident_edge);
636  MG_NOEUD * nos[2];
637  nos[0]=segment->get_noeud1();
638  nos[1]=segment->get_noeud2();
639  for (int j=0;j<2;j++)
640  {
641  if (nos[j]->get_lien_topologie()->get_dimension() >= 1)
642  {
643  nos[j]->change_lien_topologie(coincident_edge);
644  //ProjectPointToEdge(coincident_edge, 1E-4, nos[j]->get_coord(), nos[j]->get_coord());
645  }
646  }
647  }
648  }
649 
650  if (lst_recognized_edge.find(edge) == lst_recognized_edge.end())
651  {
652  printf("Problem while classifying the segments of this edge no segment was found for edge %d\n", edge->get_id());
653  it_edge--;
654  }
655  }
656 
657 
658  /* for (std::map<MG_FACE *, double *>::const_iterator it_face_tessPts = lst_face_tessPts.begin();
659  it_face_tessPts != lst_face_tessPts.end();
660  it_face_tessPts ++)
661  {
662  MG_FACE * face = it_face_tessPts->first;
663  int sense = VerifyFaceOrientation(face);
664  if (sense != 1)
665  printf("Warning: SLD_IMPORT::importer() method returned a face with bad orientation!\n");
666  }*/
667 
668  return geom;
669 }
670 
671 
672 #endif
MG_SOMMET::get_mg_cosommet
virtual MG_COSOMMET * get_mg_cosommet(int num)
Definition: mg_sommet.cpp:88
sld_surface.h
MG_SEGMENT
Definition: mg_segment.h:38
mg_geometrie.h
MG_VOLUME::get_nb_mg_coquille
virtual int get_nb_mg_coquille(void)
Definition: mg_volume.cpp:65
gestionversion.h
TPL_MAP_ENTITE< MG_NOEUD * >
SLD_IMPORT::importer
class MG_GEOMETRIE * importer(class MG_GESTIONNAIRE &gest, char *path)
Definition: sld_import.cpp:145
mg_gestionnaire.h
MG_SEGMENT::get_noeud2
virtual MG_NOEUD * get_noeud2(void)
Definition: mg_segment.cpp:113
sld_point.h
SLD_IMPORT_TESSELLATION::importer
MG_GEOMETRIE * importer(class MG_GESTIONNAIRE &gest, char *path, double tessellationTolerance=0)
Definition: sld_import_tessellation.cpp:223
MG_NOEUD::get_z
virtual double get_z(void)
Definition: mg_noeud.cpp:87
MG_NOEUD::get_lien_triangle
TPL_LISTE_ENTITE< class MG_TRIANGLE * > * get_lien_triangle(void)
Definition: mg_noeud.cpp:153
MG_IDENTIFICATEUR::get_id
unsigned long get_id()
Definition: mg_identificateur.cpp:53
SLD_FONCTION
Definition: sld_fonction.h:37
TPL_GRILLE::inserer
virtual void inserer(A a)
Definition: tpl_grille.h:274
MG_GEOMETRIE::get_nb_mg_arete
unsigned int get_nb_mg_arete(void)
Definition: mg_geometrie.cpp:813
robustPredicates::epsilon
static REAL epsilon
Definition: robustpredicates.cc:371
SLD_IMPORT_TESSELLATION::importer_tessellation
MG_GEOMETRIE * importer_tessellation(class MG_GESTIONNAIRE &gest, MG_GEOMETRIE *geom, SLD_FONCTION &fonction, double tessellationTolerance)
Definition: sld_import_tessellation.cpp:230
MG_COFACE::get_face
virtual MG_FACE * get_face(void)
Definition: mg_coface.cpp:58
TPL_GRILLE
Definition: tpl_grille.h:121
OT_ALGORITHME_GEOMETRIQUE::Dist3D_Point_Segment
static double Dist3D_Point_Segment(double a[3], double b[3], double c[3])
Definition: ot_algorithme_geometrique.cpp:299
MG_COARETE::get_boucle
virtual MG_BOUCLE * get_boucle(void)
Definition: mg_coarete.cpp:53
MG_GEOMETRIE::get_mg_sommet
MG_SOMMET * get_mg_sommet(unsigned int num)
Definition: mg_geometrie.cpp:539
MG_ELEMENT_MAILLAGE::change_lien_topologie
void change_lien_topologie(MG_ELEMENT_TOPOLOGIQUE *topo)
Definition: mg_element_maillage.cpp:56
MG_TRIANGLE
Definition: mg_triangle.h:38
SLD_IMPORT_TESSELLATION::lst_face_nbTessTriangles
std::map< MG_FACE *, long > lst_face_nbTessTriangles
Definition: sld_import_tessellation.h:54
MG_MAILLAGE_OUTILS::classe_elements_dimension1
static void classe_elements_dimension1(std::set< MG_SEGMENT * > &__unvisitedSegs, std::vector< MG_SEGMENT * > &__visitedSegs, std::vector< MG_NOEUD * > &__visitedNodes)
Definition: mg_maillage_outils.cpp:427
SLD_IMPORT_TESSELLATION::tess
MG_MAILLAGE * tess
Definition: sld_import_tessellation.h:56
sld_import.h
MG_VOLUME
Definition: mg_volume.h:33
MG_COQUILLE
Definition: mg_coquille.h:34
MG_GESTIONNAIRE
Definition: mg_gestionnaire.h:57
MG_MAILLAGE::get_premier_segment
MG_SEGMENT * get_premier_segment(LISTE_MG_SEGMENT::iterator &)
Definition: mg_maillage.cpp:630
sld_fonction.h
MG_SOMMET::get_nb_mg_cosommet
virtual int get_nb_mg_cosommet(void)
Definition: mg_sommet.cpp:64
MG_VOLUME::get_mg_coquille
virtual MG_COQUILLE * get_mg_coquille(int num)
Definition: mg_volume.cpp:70
ot_root_find.h
MG_ELEMENT_TOPOLOGIQUE
Definition: mg_element_topologique.h:51
MG_GESTIONNAIRE::ajouter_mg_maillage
int ajouter_mg_maillage(MG_MAILLAGE *mgmai)
Definition: mg_gestionnaire.cpp:521
MG_ARETE::get_nb_mg_coarete
virtual int get_nb_mg_coarete(void)
Definition: mg_arete.cpp:106
mg_maillage_outils.h
MG_MAILLAGE_OUTILS::FindCommonEdgesOfFaces
static void FindCommonEdgesOfFaces(std::set< MG_FACE * > &__faces, std::set< MG_ARETE * > &__commonEdges)
Definition: mg_maillage_outils.cpp:871
lc_point.h
MG_MAILLAGE::ajouter_mg_triangle
MG_TRIANGLE * ajouter_mg_triangle(MG_ELEMENT_TOPOLOGIQUE *topo, class MG_NOEUD *mgnoeud1, class MG_NOEUD *mgnoeud2, class MG_NOEUD *mgnoeud3, int origine, unsigned long num=0)
Definition: mg_maillage.cpp:731
MG_SEGMENT::get_noeud1
virtual MG_NOEUD * get_noeud1(void)
Definition: mg_segment.cpp:108
SLD_IMPORT_TESSELLATION::lst_face_tessPts
std::map< MG_FACE *, double * > lst_face_tessPts
Definition: sld_import_tessellation.h:53
TPL_MAP_ENTITE::get_nb
virtual int get_nb(void)
Definition: tpl_map_entite.h:83
SLD_IMPORT_TESSELLATION::SLD_IMPORT_TESSELLATION
SLD_IMPORT_TESSELLATION()
Definition: sld_import_tessellation.cpp:52
MG_NOEUD
Definition: mg_noeud.h:41
TPL_GRILLE::rechercher
virtual void rechercher(BOITE_3D bt, TPL_MAP_ENTITE< A > &liste_entite_trouve)
Definition: tpl_grille.h:202
MG_GEOMETRIE::get_mg_arete
MG_ARETE * get_mg_arete(unsigned int num)
Definition: mg_geometrie.cpp:800
SLD_FONCTION::get_face_tessellation
void get_face_tessellation(CComPtr< IFace2 > __swFace, long *__triangleCount, double **__tessPts)
Definition: sld_fonction.cpp:78
SLD_IMPORT_TESSELLATION::~SLD_IMPORT_TESSELLATION
virtual ~SLD_IMPORT_TESSELLATION()
Definition: sld_import_tessellation.cpp:57
MG_COSOMMET::get_arete
virtual MG_ARETE * get_arete(void)
Definition: mg_cosommet.cpp:88
SLD_FONCTION::Modeler_SetToleranceValue
void Modeler_SetToleranceValue(long iTol, double __tolerance)
Definition: sld_fonction.cpp:106
MG_MAILLAGE::get_suivant_segment
MG_SEGMENT * get_suivant_segment(LISTE_MG_SEGMENT::iterator &)
Definition: mg_maillage.cpp:638
tpl_grille.h
MG_BOUCLE::get_mg_face
virtual MG_FACE * get_mg_face(void)
Definition: mg_boucle.cpp:102
TPL_LISTE_ENTITE::get_nb
virtual int get_nb(void)
Definition: tpl_liste_entite.h:67
MG_SOMMET::get_point
virtual MG_POINT * get_point(void)
Definition: mg_sommet.cpp:52
cstr_grid
void cstr_grid(double __bbox[6], int __nb_steps[3], TPL_GRILLE< A > &__grid)
Definition: sld_import_tessellation.cpp:200
OT_VECTEUR_3D::norme
virtual void norme(void)
Definition: ot_mathematique.cpp:494
MG_IDENTIFICATEUR::id
unsigned long id
Definition: mg_identificateur.h:49
MG_TRIANGLE::get_noeud2
virtual MG_NOEUD * get_noeud2(void)
Definition: mg_triangle.cpp:131
TPL_LISTE_ENTITE::get
virtual X get(int num)
Definition: tpl_liste_entite.h:72
CAD4FE_MG_ARETE_ClosestPointOn.h
MG_NOEUD::get_x
virtual double get_x(void)
Definition: mg_noeud.cpp:77
acos
double2 acos(double2 &val)
Definition: ot_doubleprecision.cpp:224
MG_MAILLAGE_OUTILS::inserer_noeud_segment
static void inserer_noeud_segment(class MG_MAILLAGE *__mesh, class MG_NOEUD *__node, class MG_SEGMENT *__splitSeg, MG_SEGMENT *__segs[2], bool __deleteOriginalSeg=true)
Definition: mg_maillage_outils.cpp:174
OT_VECTEUR_3D
Definition: ot_mathematique.h:94
MG_TRIANGLE::get_noeud1
virtual MG_NOEUD * get_noeud1(void)
Definition: mg_triangle.cpp:126
sqrt
double2 sqrt(double2 &val)
Definition: ot_doubleprecision.cpp:345
MG_MAILLAGE_OUTILS::IdentifyEdge3
static void IdentifyEdge3(std::set< MG_SOMMET * > __vertices, std::set< MG_ARETE * > &__lst_edge, std::vector< MG_NOEUD * > &__nodes, MG_ARETE **__edge)
Definition: mg_maillage_outils.cpp:548
MG_ELEMENT_MAILLAGE::get_lien_topologie
MG_ELEMENT_TOPOLOGIQUE * get_lien_topologie(void)
Definition: mg_element_maillage.cpp:51
ot_algorithme_geometrique.h
TPL_MAP_ENTITE::get
virtual X get(int num)
Definition: tpl_map_entite.h:89
SLD_IMPORT_TESSELLATION::GetFaceMeshNormal
void GetFaceMeshNormal(MG_FACE *__face, MG_NOEUD *__node, double __normal[3])
Definition: sld_import_tessellation.cpp:68
MG_TRIANGLE::get_noeud3
virtual MG_NOEUD * get_noeud3(void)
Definition: mg_triangle.cpp:137
MG_GEOMETRIE
Definition: mg_geometrie.h:84
MG_NOEUD::change_coord
virtual void change_coord(double *coo)
Definition: mg_noeud.cpp:133
MG_MAILLAGE
Definition: mg_maillage.h:62
TPL_LISTE_ENTITE< MG_TRIANGLE * >
MG_COQUILLE::get_nb_mg_coface
virtual int get_nb_mg_coface(void)
Definition: mg_coquille.cpp:76
MG_COQUILLE::get_mg_coface
virtual MG_COFACE * get_mg_coface(int num)
Definition: mg_coquille.cpp:90
MG_ARETE
Definition: mg_arete.h:36
MG_FACE
Definition: mg_face.h:34
SLD_FONCTION::GetParID
BOOL GetParID(char *ID, CComPtr< IFace2 > &)
Definition: sld_fonction.cpp:381
MG_ELEMENT_TOPOLOGIQUE::get_idoriginal
virtual std::string get_idoriginal(void)
Definition: mg_element_topologique.cpp:299
MG_SOMMET
Definition: mg_sommet.h:35
MG_GEOMETRIE::gest
MG_GESTIONNAIRE * gest
Definition: mg_geometrie.h:349
SLD_IMPORT_TESSELLATION::lst_face_contourSegments
std::map< MG_FACE *, std::vector< MG_SEGMENT * > > lst_face_contourSegments
Definition: sld_import_tessellation.h:55
TPL_GRILLE::initialiser
virtual void initialiser(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, int nb_pasx, int nb_pasy, int nb_pasz)
Definition: tpl_grille.h:142
MG_GESTIONNAIRE::get_mg_geometrie
MG_GEOMETRIE * get_mg_geometrie(unsigned int num)
Definition: mg_gestionnaire.cpp:331
sld_courbe.h
sld_import_tessellation.h
MG_GEOMETRIE::get_mg_volume
MG_VOLUME * get_mg_volume(unsigned int num)
Definition: mg_geometrie.cpp:1683
MG_POINT::evaluer
virtual void evaluer(double *xyz)=0
MG_GEOMETRIE::get_nb_mg_sommet
unsigned int get_nb_mg_sommet(void)
Definition: mg_geometrie.cpp:552
MG_ARETE::get_mg_coarete
virtual MG_COARETE * get_mg_coarete(int num)
Definition: mg_arete.cpp:228
MG_NOEUD::get_y
virtual double get_y(void)
Definition: mg_noeud.cpp:82
MG_MAILLAGE::ajouter_mg_noeud
MG_NOEUD * ajouter_mg_noeud(MG_ELEMENT_TOPOLOGIQUE *topo, double xx, double yy, double zz, int origine, unsigned long num=0)
Definition: mg_maillage.cpp:421