MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
CAD4FE_ShortestPath.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 //####// CAD4FE_ShortestPath.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:58:56 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 
23 
24 #pragma hdrstop
25 
26 #include "gestionversion.h"
27 
28 #include <fstream>
29 #include "CAD4FE_ShortestPath.h"
30 #include "mg_geometrie.h"
32 #include "CAD4FE_MCNode.h"
33 #include "CAD4FE_MCFace.h"
34 #include "CAD4FE_PolySurface.h"
36 #include "CAD4FE_Geometric_Tools.h"
39 
40 using namespace CAD4FE;
41 
42 
43 #pragma package(smart_init)
44 
46 {
48  {
49  delete _intrAdjacencyGraph;
50  _intrAdjacencyGraph = NULL;
51  }
52 }
53 
55 {
56  return _mcNode[0];
57 }
58 
60 {
61  return _mcNode[1];
62 }
63 
65 {
66  int nodeId = 1;
68  {
69  delete _intrAdjacencyGraph;
71  }
73 
74  std::map < MCNode * , int > mapGraphNodeByP;
75 
76  for (std::set<MCNode*>::iterator itP = _facePoints.begin();
77  itP != _facePoints.end();
78  itP++)
79  {
80  MCNode * mcNode = *itP;
81  Graph::Node * n = _intrAdjacencyGraph->AddNode(nodeId++);
82  n->SetUserData(mcNode);
83  n->SetUserData(2,this);
84  mapGraphNodeByP[mcNode]=n->Id();
85  }
86 
87  std::map<MG_FACE*, std::set<MCNode*> > map_listP_by_F;
88  std::map<MG_ARETE*, std::set<MCNode*> > map_listP_by_E;
89  std::map<MG_SOMMET*, std::set<MCNode*> > map_listP_by_V;
90 
91  for (std::set<MCNode*>::iterator itP = _facePoints.begin();
92  itP != _facePoints.end();
93  itP++)
94  {
95  MCNode * P = *itP;
96  for (MCNode::FMapIterator itF = P->GetRefFaceMapping().begin();
97  itF != P->GetRefFaceMapping().end();
98  itF ++ )
99  {
100  MG_FACE * F = itF->first;
101  if ( _polySurface->Contains(F) )
102  if ( P->GetRefVertexMapping().size() <=1 || P->RefTopoIsInFace(F) )
103  {
104  if (map_listP_by_F.find(F) == map_listP_by_F.end())
105  {
106  Graph::Arc * arc = _intrAdjacencyGraph->AddArc(F->get_id(), 1, mapGraphNodeByP[P]);
107  arc->SetUserData(F);
108  std::set<MCNode*> listP;
109  listP.insert( P );
110  map_listP_by_F.insert(std::make_pair(F,listP));
111  }
112  else
113  {
115  Graph::Node * n = _intrAdjacencyGraph->GetNode(mapGraphNodeByP[P]);
116  arc->Add( n );
117  n->Add(arc);
118  map_listP_by_F[F].insert(P);
119  }
120  }
121  }
122  for (MCNode::EMapIterator itE = P->GetRefEdgeMapping().begin();
123  itE != P->GetRefEdgeMapping().end();
124  itE ++ )
125  {
126  MG_ARETE * E = itE->first;
127  if ( _polySurface->Contains(E) )
128  if ( P->GetRefVertexMapping().size() <=1 || P->RefTopoIsInEdge(E) )
129  {
130  if (map_listP_by_E.find(E) == map_listP_by_E.end())
131  {
132  Graph::Arc * arc = _intrAdjacencyGraph->AddArc(E->get_id(), 1, mapGraphNodeByP[P]);
133  arc->SetUserData(E);
134  std::set<MCNode*> listP;
135  listP.insert( P );
136  map_listP_by_E.insert(std::make_pair(E,listP));
137  }
138  else
139  {
141  Graph::Node * n = _intrAdjacencyGraph->GetNode(mapGraphNodeByP[P]);
142  arc->Add( n );
143  n->Add(arc);
144  map_listP_by_E[E].insert(P);
145  }
146  }
147  }
148  for (MCNode::VMapIterator itV = P->GetRefVertexMapping().begin();
149  itV != P->GetRefVertexMapping().end();
150  itV ++ )
151  {
152  MG_SOMMET * V = *itV;
153  {
154  if (map_listP_by_V.find(V) == map_listP_by_V.end())
155  {
156  Graph::Arc * arc = _intrAdjacencyGraph->AddArc(V->get_id(), 1, mapGraphNodeByP[P]);
157  arc->SetUserData(V);
158  std::set<MCNode*> listP;
159  listP.insert( P );
160  map_listP_by_V.insert(std::make_pair(V,listP));
161  }
162  else
163  {
164  Graph::Arc * arc = _intrAdjacencyGraph->GetArc(V->get_id());
165  Graph::Node * n = _intrAdjacencyGraph->GetNode(mapGraphNodeByP[P]);
166  arc->Add( n );
167  n->Add(arc);
168  map_listP_by_V[V].insert(P);
169  }
170  }
171  }
172  }
173 }
174 
175 double ShortestPath::Find(std::vector <MCNode *> * __shortestPathNodes, std::vector <MG_ELEMENT_TOPOLOGIQUE *> * __shortestPathTopo)
176 {
177  std::vector <Graph::Node *> path;
178  std::vector <Graph::Arc *> pathArcs;
179  Graph::Node * nStart, * nEnd;
180  for (Graph::Graph::MapNodesById::const_iterator itNode = _intrAdjacencyGraph->GetNodes().begin();
181  itNode != _intrAdjacencyGraph->GetNodes().end();
182  itNode++)
183  {
184  Graph::Node * n = itNode->second;
185  if ((MCNode *)n->GetUserData() == _mcNode[0])
186  nStart = n;
187  else
188  if ((MCNode *)n->GetUserData() == _mcNode[1])
189  nEnd = n;
190  }
191  double distance = Graph::Dijkstra(_intrAdjacencyGraph,nStart,nEnd,Distance,path,pathArcs);
192 
193  for (unsigned i=0; i<path.size();i++)
194  _shortestPath.push_back((MCNode *)path[i]->GetUserData());
195 
196  if (__shortestPathNodes)
197  {
198  for (unsigned i=0; i<path.size();i++)
199  {
200  MCNode * mcNode = (MCNode *)path[i]->GetUserData();
201  __shortestPathNodes->push_back(mcNode);
202  }
203  }
204 
205  if (__shortestPathTopo)
206  {
207  for (unsigned i=0; i<pathArcs.size();i++)
208  {
209  MG_ELEMENT_TOPOLOGIQUE * topo = (MG_ELEMENT_TOPOLOGIQUE *)pathArcs[i]->GetUserData();
210  __shortestPathTopo->push_back(topo);
211  }
212  }
213 
214 
215  return distance;
216 }
217 
CAD4FE::ShortestPath::_mcNode
MCNode * _mcNode[2]
Definition: CAD4FE_ShortestPath.h:58
mg_geometrie.h
CAD4FE::ShortestPath::Find
double Find(std::vector< MCNode * > *__shortestPathNodes=0, std::vector< MG_ELEMENT_TOPOLOGIQUE * > *__shortestPathTopo=0)
Definition: CAD4FE_ShortestPath.cpp:175
CAD4FE_ShortestPath.h
HypergraphLib::GraphObject::GetUserData
void * GetUserData() const
Definition: hypergraphlib_graphobject.cpp:57
gestionversion.h
HypergraphLib::Arc::Add
void Add(Node *)
Definition: hypergraphlib_arc.cpp:59
CAD4FE::PolySurface::Contains
bool Contains(MG_FACE *__refFace)
Definition: CAD4FE_PolySurface.cpp:167
HypergraphLib::Graph::GetNodes
const MapNodesById & GetNodes() const
Definition: hypergraphlib_graph.h:178
MG_IDENTIFICATEUR::get_id
unsigned long get_id()
Definition: mg_identificateur.cpp:53
CAD4FE_Intersection_Plane_MG_ARETE.h
HypergraphLib::Dijkstra
double HYPERGRAPHLIB_ITEM Dijkstra(Graph *__G, Node *source, Node *destination, double(*distanceFunc)(HypergraphLib::Node *, HypergraphLib::Node *, HypergraphLib::Arc *), std::vector< Node * > &pathNodes, std::vector< Arc * > &pathArcs)
Definition: hypergraphlib_dijkstra.cpp:41
CAD4FE::ShortestPath::~ShortestPath
~ShortestPath()
Definition: CAD4FE_ShortestPath.cpp:45
HypergraphLib::Graph::GetArc
Arc * GetArc(int) const
Definition: hypergraphlib_graph.cpp:188
HypergraphLib::Arc
Definition: hypergraphlib_arc.h:37
CAD4FE::ShortestPath::_intrAdjacencyGraph
Graph::Graph * _intrAdjacencyGraph
Definition: CAD4FE_ShortestPath.h:60
CAD4FE::ShortestPath::_polySurface
PolySurface * _polySurface
Definition: CAD4FE_ShortestPath.h:57
MG_ELEMENT_TOPOLOGIQUE
Definition: mg_element_topologique.h:51
CAD4FE_ClosestPoint_Segment_MG_ARETE.h
CAD4FE::ShortestPath::InitializeAdjacencyGraph
void InitializeAdjacencyGraph()
Definition: CAD4FE_ShortestPath.cpp:64
CAD4FE::ShortestPath::_facePoints
std::set< MCNode * > _facePoints
Definition: CAD4FE_ShortestPath.h:59
CAD4FE::MCNode::VMapIterator
VMap::iterator VMapIterator
Definition: CAD4FE_MCNode.h:56
HypergraphLib::Graph::AddArc
Arc * AddArc(const std::vector< int > &, int __id)
Definition: hypergraphlib_graph.cpp:378
HypergraphLib::Node::Add
void Add(Arc *)
Definition: hypergraphlib_node.cpp:45
V
void V(MCAA *mcaa)
Definition: CAD4FE_MCAA.cpp:1794
CAD4FE::ShortestPath::GetStartNode
MCNode * GetStartNode()
Definition: CAD4FE_ShortestPath.cpp:54
CAD4FE_PolySurface.h
CAD4FE::MCNode::FMapIterator
FMap::iterator FMapIterator
Definition: CAD4FE_MCNode.h:51
CAD4FE_FaceBoundaryPoint.h
CAD4FE::ShortestPath::Distance
double(* Distance)(Graph::Node *__a, Graph::Node *__b, Graph::Arc *__arc)
Definition: CAD4FE_ShortestPath.h:55
HypergraphLib::GraphObject::Id
int Id() const
Definition: hypergraphlib_graphobject.cpp:47
HypergraphLib::Graph
Definition: hypergraphlib_graph.h:58
HypergraphLib::Graph::AddNode
Node * AddNode(int __id=0)
Definition: hypergraphlib_graph.cpp:278
CAD4FE_MCNode.h
HypergraphLib::Node
Definition: hypergraphlib_node.h:35
CAD4FE_Geometric_Tools.h
HypergraphLib::Graph::GetNode
Node * GetNode(int) const
Definition: hypergraphlib_graph.cpp:175
CAD4FE::ShortestPath::_shortestPath
std::vector< MCNode * > _shortestPath
Definition: CAD4FE_ShortestPath.h:61
ot_algorithme_geometrique.h
CAD4FE
Definition: CAD4FE_ClosestPoint_Segment_MG_ARETE.h:34
CAD4FE::MCNode
Definition: CAD4FE_MCNode.h:47
MG_ARETE
Definition: mg_arete.h:36
MG_FACE
Definition: mg_face.h:34
CAD4FE_MCFace.h
MG_SOMMET
Definition: mg_sommet.h:35
CAD4FE::ShortestPath::GetEndNode
MCNode * GetEndNode()
Definition: CAD4FE_ShortestPath.cpp:59
P
#define P(i, j)
HypergraphLib::GraphObject::SetUserData
void SetUserData(void *)
Definition: hypergraphlib_graphobject.cpp:66
CAD4FE::MCNode::EMapIterator
EMap::iterator EMapIterator
Definition: CAD4FE_MCNode.h:53