ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_MCNode.cpp
Revision: 763
Committed: Wed Dec 2 19:55:53 2015 UTC (9 years, 5 months ago) by francois
File size: 18373 byte(s)
Log Message:
Le fichier MAGiC est maintenant versionné. LA version actuelle est 2.0. L'ancienne version est 1.0.
Tout est transparent pour l'utilisateur. Les vieilles versions sont lisibles mais les nouveaux enregistrements sont dans la version la plus récente.
Changement des conditions aux limites : ajout d'un parametre pour dire si la condition numerique est une valeur ou une formule ou un lien vers une autre entité magic.
Les parametres pour saisir sont maintenant -ccf -ccfi -ccff -ccft -ccfit -ccfft

File Contents

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