ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_MCNode.cpp
Revision: 1158
Committed: Thu Jun 13 22:18:49 2024 UTC (11 months ago) by francois
File size: 17066 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

# User Rev Content
1 francois 1158 //####//------------------------------------------------------------
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_MCNode.cpp
15     //####//
16     //####//------------------------------------------------------------
17     //####//------------------------------------------------------------
18     //####// COPYRIGHT 2000-2024
19     //####// jeu 13 jun 2024 11:58:56 EDT
20     //####//------------------------------------------------------------
21     //####//------------------------------------------------------------
22 foucault 27
23    
24     #pragma hdrstop
25    
26 francois 763
27     #include "gestionversion.h"
28 foucault 27 #include "CAD4FE_MCNode.h"
29 foucault 176 #include "mg_maillage.h"
30     #include "mg_geometrie.h"
31 foucault 27 #include "CAD4FE_FaceBoundaryPoint.h"
32     #include "CAD4FE_MCVertex.h"
33     #include "CAD4FE_MCEdge.h"
34     #include "CAD4FE_MCFace.h"
35 foucault 569 #include "CAD4FE_Geometric_Tools.h"
36 foucault 27 #include <math.h>
37    
38    
39     #pragma package(smart_init)
40    
41     using namespace CAD4FE;
42    
43     MCNode::MCNode()
44     : MG_NOEUD (0, 0, 0, 0, 0), _saveFormat(0)
45     {
46 foucault 569 Creator = unknown;
47 foucault 27 }
48     MCNode::MCNode(unsigned long num,MG_ELEMENT_TOPOLOGIQUE* mcTopo,MG_ELEMENT_TOPOLOGIQUE* __refTopo,double xx,double yy,double zz)
49 francois 791 : MG_NOEUD (num, mcTopo, xx,yy,zz,MAGIC::ORIGINE::MAILLEUR_AUTO),_refTopo(__refTopo), _saveFormat(0)
50 foucault 569 {
51     Creator = unknown;
52 foucault 27 ConstructMapping();
53     }
54     MCNode::MCNode(MG_ELEMENT_TOPOLOGIQUE* mcTopo,MG_ELEMENT_TOPOLOGIQUE* __refTopo,double xx,double yy,double zz)
55 francois 791 : MG_NOEUD(mcTopo,xx,yy,zz,MAGIC::ORIGINE::MAILLEUR_AUTO),_refTopo(__refTopo), _saveFormat(0)
56 foucault 569 {
57     Creator = unknown;
58 foucault 27 ConstructMapping();
59     }
60     MCNode::MCNode(MG_ELEMENT_TOPOLOGIQUE* mcTopo,MG_FACE* __refFace, double __uv[2], double __xyz[3])
61 francois 791 : MG_NOEUD(mcTopo,__xyz[0],__xyz[1],__xyz[2],MAGIC::ORIGINE::MAILLEUR_AUTO),_refTopo(__refFace), _saveFormat(0)
62 foucault 569 {
63     Creator = unknown;
64 foucault 27 OT_VECTEUR_3D uv(__uv[0], __uv[1], 0);
65     _F.insert(std::make_pair(__refFace, uv));
66     }
67     MCNode::MCNode(MG_ELEMENT_TOPOLOGIQUE* mcTopo,MG_ARETE* __refEdge, double __t, double __xyz[3])
68 francois 791 : MG_NOEUD(mcTopo,__xyz[0],__xyz[1],__xyz[2],MAGIC::ORIGINE::MAILLEUR_AUTO),_refTopo(__refEdge), _saveFormat(0)
69 foucault 569 {
70     Creator = unknown;
71 foucault 27 _E.insert(std::make_pair(__refEdge, __t));
72     ConstructMapping();
73     }
74     MCNode::~MCNode()
75     {
76     }
77     MCNode::MCNode(const MCNode& __src)
78     : MG_NOEUD ((MG_NOEUD & )__src)
79     {
80     /* for (FMapCIterator itF = __src._F.begin();
81     itF != __src._F.end();
82     itF++)
83     _F.insert(std::make_pair(itF->first,itF->second));
84     for (EMapCIterator itE = __src._E.begin();
85     itE != __src._E.end();
86     itE++)
87     _E.insert(std::make_pair(itE->first,itE->second));
88     for (VMapCIterator itV = __src._V.begin();
89     itV != __src._V.end();
90     itV++)
91 foucault 569 _V.insert(*itV); */
92     Creator = __src.Creator;
93 foucault 27 _F=__src._F;
94     _E=__src._E;
95     _V=__src._V;
96     _refTopo = __src._refTopo;
97     }
98     void MCNode::CopyGeometry(const MCNode& __src)
99     {
100     /*_F.clear();
101     for (FMapCIterator itF = __src._F.begin();
102     itF != __src._F.end();
103     itF++)
104     _F.insert(std::make_pair(itF->first,itF->second));
105     _E.clear();
106     for (EMapCIterator itE = __src._E.begin();
107     itE != __src._E.end();
108     itE++)
109     _E.insert(std::make_pair(itE->first,itE->second));
110     _V.clear();
111     for (VMapCIterator itV = __src._V.begin();
112     itV != __src._V.end();
113     itV++)
114     _V.insert(*itV); */
115     _F.clear();_E.clear();_V.clear();
116     _F=__src._F;
117     _E=__src._E;
118     _V=__src._V;
119     _refTopo = __src._refTopo;
120     for (int i=0;i<3;i++)xyz[i]=__src.xyz[i];
121     }
122     int MCNode::get_type_entite ()
123     {
124     return IDMCNODE;
125     }
126     MG_ELEMENT_TOPOLOGIQUE * MCNode::get_lien_topologie_reference()
127     {
128     return _refTopo;
129     }
130     void MCNode::change_lien_topologie_reference(MG_ELEMENT_TOPOLOGIQUE *__refTopo)
131     {
132     _refTopo = __refTopo;
133     }
134     MCNode::FMap & MCNode::GetRefFaceMapping() {return _F;}
135     MCNode::EMap & MCNode::GetRefEdgeMapping() {return _E;}
136     MCNode::VMap & MCNode::GetRefVertexMapping() {return _V;}
137     void MCNode::SetRefFaceMapping(MG_FACE * __face, double * __uv) {OT_VECTEUR_3D vec(__uv[0],__uv[1],0);_F[__face] = vec;}
138     void MCNode::SetRefEdgeMapping(MG_ARETE * __edge, double __t) {_E[__edge] = __t;}
139     void MCNode::SetRefVertexMapping(MG_SOMMET * __vertex) { _V.insert(__vertex); }
140     void MCNode::ConstructMapping()
141     {
142     MG_ELEMENT_TOPOLOGIQUE * topo = _refTopo;
143 foucault 569 _F.clear(); _E.clear(); _V.clear();
144 foucault 27
145     if (topo == NULL) // should happen rarely
146     return;
147    
148     switch (topo->get_dimension())
149     {
150     case 0:
151     {
152     // Look for an existing MC Node on this vertex
153     MG_SOMMET* vertex=(MG_SOMMET*)topo;
154     MCNode * mcNode = 0;
155    
156 francois 763 TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = vertex->get_lien_maillage();
157     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
158     MG_ELEMENT_MAILLAGE* element;
159     int nb = lien_maillage->get_nb();
160     int i=0;
161     for (element = lien_maillage->get_premier(it); i++ < nb && element ; element = lien_maillage->get_suivant(it) )
162     {
163     int elementType = element->get_type_entite();
164     if ( elementType == IDMCNODE && element != this )
165     {
166     MCNode * tmpmcNode = (MCNode*) element;
167     if (tmpmcNode->_V.size() && tmpmcNode->_E.size() && tmpmcNode->_F.size())
168     {
169     mcNode = tmpmcNode;
170     break;
171     }
172     }
173 foucault 27 }
174     // Make a copy of the mapping to the existing MC node
175     if (mcNode)
176     {
177     _V = mcNode->_V;
178     _E = mcNode->_E;
179     _F = mcNode->_F;
180     }
181     // Compute the topology mapping
182     else
183     {
184     _V.insert((MG_SOMMET*)topo);
185     if (get_lien_topologie())
186     {
187     if (get_lien_topologie()->get_dimension() == 0)
188     {
189     MCVertex * mcVertex = (MCVertex*)get_lien_topologie();
190     for (std::map<unsigned long, MG_SOMMET*>::iterator itMergedVertex = mcVertex->GetMergedRefVertices().begin();
191     itMergedVertex != mcVertex->GetMergedRefVertices().end();
192     itMergedVertex++)
193     _V.insert(itMergedVertex->second);
194     }
195     if (get_lien_topologie()->get_dimension() == 1)
196     {
197     MCEdge * mcEdge = (MCEdge*)get_lien_topologie();
198     MCVertex * mcVertex[2];
199     mcVertex[0] = (MCVertex*)mcEdge->get_cosommet1()->get_sommet();
200     mcVertex[1] = (MCVertex*)mcEdge->get_cosommet2()->get_sommet();
201     for (int j = 0; j<2; j++)
202     {
203     std::map<unsigned long, MG_SOMMET*>::iterator itMergedVertex = mcVertex[j]->GetMergedRefVertices().find(_refTopo->get_id());
204     if (itMergedVertex != mcVertex[j]->GetMergedRefVertices().end())
205     {
206     for (itMergedVertex = mcVertex[j]->GetMergedRefVertices().begin();
207     itMergedVertex != mcVertex[j]->GetMergedRefVertices().end();
208     itMergedVertex++)
209     _V.insert(itMergedVertex->second);
210     }
211     }
212     }
213     }
214     else
215     {
216     printf("Warning: MC topology of MC Node = NULL!\n");
217     }
218     for (std::set<MG_SOMMET*>::iterator itV = _V.begin();
219     itV != _V.end();
220     itV++)
221     {
222     MG_SOMMET * v = *itV;
223     // Init Edge Mapping
224     for (int itE = 0; itE < v->get_nb_mg_cosommet(); itE++)
225     {
226     MG_ARETE * edge = v->get_mg_cosommet(itE)->get_arete();
227    
228     // edge parameter is the reference vertex parameter
229     MG_SOMMET * refVertex = (MG_SOMMET *) _refTopo;
230     if ( v == refVertex || (edge->get_cosommet1()->get_sommet() != refVertex) && (edge->get_cosommet1()->get_sommet() != refVertex) )
231     {
232     double tEdge = v->get_mg_cosommet(itE)->get_t();
233     double edgePeriod = edge->get_courbe()->get_periode();
234     if ( tEdge < edge->get_tmin() && edgePeriod != 0.0 )
235     {
236     tEdge += edgePeriod;
237     }
238     _E.insert(std::make_pair(edge, tEdge));
239     }
240    
241     // Init Face mapping
242     for (int itF = 0; itF < edge->get_nb_mg_coarete(); itF++)
243     {
244     MG_FACE * face = edge->get_mg_coarete(itF)->get_boucle()->get_mg_face();
245    
246     if (v != refVertex && GeometricTools::MG_FACE_Contains_MG_SOMMET(face,refVertex) )
247     continue;
248    
249     if ( _F.find(face) == _F.end() )
250     {
251     // project vertex in face parametrization
252     OT_VECTEUR_3D uv(0,0,0);
253     face->inverser(uv,xyz,1E-6);
254     // correct uv coordinates of 3D points which are not
255     // exactly on "exact surfaces" (torus, sphere, cylinder, cone, etc)
256     GeometricTools::FacePointCorrection(face,xyz,uv);
257     _F.insert(std::make_pair(face, uv));
258     }
259     }
260     }
261     }
262     }
263     break;
264     }
265     case 1:
266     {
267     MG_ARETE * edge = (MG_ARETE*) topo;
268    
269     // Init Edge Mapping
270     // Not implemented : parameter of edge mapping
271     if (_E.find(edge) == _E.end())
272     {
273     double tEdge;
274     double edgePeriod = edge->get_courbe()->get_periode();
275     edge->inverser(tEdge,xyz);
276     if ( tEdge < edge->get_tmin() && edgePeriod != 0.0 )
277     {
278     tEdge += edgePeriod;
279     }
280     _E.insert(std::make_pair(edge, tEdge));
281     }
282    
283     // Init Face mapping
284     for (int itF = 0; itF < edge->get_nb_mg_coarete(); itF++)
285     {
286     MG_FACE * face = edge->get_mg_coarete(itF)->get_boucle()->get_mg_face();
287     OT_VECTEUR_3D uv(0,0,0);
288     face->inverser(uv,xyz,1E-6);
289     // correct uv coordinates of 3D points which are not
290     // exactly on "exact surfaces" (torus, sphere, cylinder, cone, etc)
291     GeometricTools::FacePointCorrection(face,xyz,uv);
292     _F.insert(std::make_pair(face, uv));
293     }
294     break;
295     }
296     case 2:
297     {
298     // Init Face Mapping
299     MG_FACE * face = (MG_FACE*) topo;
300     OT_VECTEUR_3D uv(0,0,0);
301     face->inverser(uv,xyz,1E-6);
302     // correct uv coordinates of 3D points which are not
303     // exactly on "exact surfaces" (torus, sphere, cylinder, cone, etc)
304     GeometricTools::FacePointCorrection(face,xyz,uv);
305     _F.insert(std::make_pair(face, uv));
306     break;
307     }
308    
309     }
310     }
311     void MCNode::SharedFaces(MCNode * __other, std::set <MG_FACE*> & __setF)
312     {
313     for (MCNode::FMapIterator itF1 = _F.begin();
314     itF1 != _F.end();
315     itF1 ++ )
316     if (__other->_F.find(itF1->first) != __other->_F.end())
317     __setF.insert (itF1->first);
318     }
319     void MCNode::SharedEdges(MCNode * __other, std::set <MG_ARETE*> & __setE)
320     {
321     for (MCNode::EMapIterator itE1 = _E.begin();
322     itE1 != _E.end();
323     itE1 ++ )
324     if (__other->_E.find(itE1->first) != __other->_E.end())
325     __setE.insert (itE1->first);
326     }
327     void MCNode::SharedVertices(MCNode * __other, std::set <MG_SOMMET*> & __setV)
328     {
329     for (MCNode::VMapIterator itV1 = _V.begin();
330     itV1 != _V.end();
331     itV1 ++ )
332     if (__other->_V.find(*itV1) != __other->_V.end())
333     __setV.insert (*itV1);
334     }
335     bool MCNode::IsInFace (MG_FACE * __e)
336     {
337     FMapIterator itF = _F.find(__e);
338     return (itF != _F.end());
339     }
340     void MCNode::NormalMCFace(MCFace* __mcFace, double * __normal)
341 francois 763 {
342     int nbRefFaces=0;
343     int dimension=_refTopo->get_dimension();
344     switch (dimension)
345     {
346     case 1:
347     {
348     __mcFace->calcul_normale_unitaire(GetRefFaceMapping(), __normal, &nbRefFaces);
349     return;
350     }
351     case 2:
352     {
353     __mcFace->calcul_normale_unitaire(GetRefFaceMapping(), __normal, &nbRefFaces);
354     return;
355     }
356     case 0:
357     {
358     __mcFace->calcul_normale_unitaire((MG_SOMMET*) _refTopo, __normal, &nbRefFaces);
359     }
360     }
361 foucault 27 }
362    
363     bool MCNode::RefTopoIsInFace (MG_FACE * __e)
364     {
365     FMapIterator itF = _F.find(__e);
366     if (itF == _F.end()) return false;
367     switch (_refTopo->get_dimension())
368     {
369     case 0:
370     if (_V.size() <= 1) // if it's not in a merged vertex, then no further test is required
371     return true;
372     else
373     return (GeometricTools::MG_FACE_Contains_MG_SOMMET(__e, (MG_SOMMET*) _refTopo));
374     default:
375     return true;
376     }
377     }
378     bool MCNode::RefTopoIsInEdge (MG_ARETE * __e)
379     {
380     EMapIterator itE = _E.find(__e);
381     if (itE == _E.end()) return false;
382     switch (_refTopo->get_dimension())
383     {
384     case 0:
385     if (_V.size() <= 1) // if it's not in a merged vertex, then no further test is required
386     return true;
387     else
388     return (GeometricTools::MG_ARETE_Contains_MG_SOMMET(__e, (MG_SOMMET*) _refTopo));
389     default:
390     return true;
391     }
392     }
393     bool MCNode::IsInEdge (MG_ARETE * __e)
394     {
395     return (_E.find(__e) != _E.end());
396     }
397     bool MCNode::IsInVertex (MG_SOMMET * __e)
398     {
399     return (_V.find(__e) != _V.end());
400     }
401     bool MCNode::RefTopoIsInVertex (MG_SOMMET * __e)
402     {
403     return (_refTopo != __e);
404     }
405     MG_SOMMET * MCNode::GetMergedVertex(MG_FACE * __face)
406     {
407     if (_V.size() > 1)
408     {
409     MG_SOMMET * refVertex = (MG_SOMMET*) _refTopo;
410     for (VMapIterator itV = _V.begin();
411     itV != _V.end();
412     itV++)
413     {
414     MG_SOMMET * mergedVertex = *itV;
415     if (mergedVertex == refVertex)
416     continue;
417     if (GeometricTools::MG_FACE_Contains_MG_SOMMET(__face, mergedVertex))
418     return mergedVertex;
419     }
420     }
421     return NULL;
422     }
423     OT_VECTEUR_3D & MCNode::GetFaceParams (MG_FACE * __e)
424     {
425     static OT_VECTEUR_3D badParam (-1E308,-1E308,-1E308);
426     FMapIterator itF = _F.find(__e);
427     if (itF != _F.end())
428     return itF->second;
429     else
430     return badParam;
431     }
432     OT_VECTEUR_3D & MCNode::UV (MG_FACE * __e)
433     {
434     return GetFaceParams (__e);
435     }
436     double MCNode::GetEdgeParams (MG_ARETE * __e)
437     {
438 foucault 176 static double badParam = -1E308;
439 foucault 27 EMapCIterator itE = _E.find(__e);
440     if (itE != _E.end())
441     return itE->second;
442     else
443     return badParam;
444     }
445     double MCNode::T (MG_ARETE * __e)
446     {
447     return GetEdgeParams(__e);
448     }
449    
450     void MCNode::SetSaveFormat(char __format)
451     {
452     _saveFormat=__format;
453     if (__format == 2)
454     {
455     change_lien_topologie(_refTopo);
456     }
457     }
458    
459 francois 763 void MCNode::enregistrer(std::ostream& o,double version)
460 foucault 27 {
461     if (_saveFormat==0)
462     {
463     o << "%" << get_id() << "=CAD4FE_MCNODE($"<< _refTopo->get_id() <<",$" << get_lien_topologie()->get_id() << "," << xyz[0] << "," << xyz[1] << "," << xyz[2] << ");" << std::endl;
464     }
465     else if (_saveFormat==1)
466     {
467 francois 763 MG_NOEUD::enregistrer (o,version);
468 foucault 27 }
469     else if (_saveFormat==2)
470     {
471 francois 763 MG_NOEUD::enregistrer (o,version);
472 foucault 27 }
473     }
474    
475     void MCNode::Print()
476     {
477     printf("%f %f %f ", get_x(), get_y(), get_z());
478     }
479