ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_MCNode.cpp
Revision: 176
Committed: Tue May 19 20:56:11 2009 UTC (15 years, 11 months ago) by foucault
Original Path: magic/lib/CAD4FE/CAD4FE/src/CAD4FE_MCNode.cpp
File size: 18057 byte(s)
Log Message:
Mise à jour :
* CAD4FE
* outil : HypergraphLib qui est maintenant compilable sous Linux (essais mois aout 2008)
* outil : ot_mathematique.cpp suppression d'une méthode de classe inutile nécessaire pour compiler avec CodeGear Builder 2006 OT_VECTEUR_3D::OT_VECTEUR_3D(OT_VECTEUR_3D& mdd)

File Contents

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