ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/CAD4FE_PolySurface.cpp
Revision: 481
Committed: Tue Jan 28 16:10:58 2014 UTC (11 years, 3 months ago) by francois
Original Path: magic/lib/geometrie/src/cad4fe_polysurface.cpp
File size: 8581 byte(s)
Log Message:
unification de la facon d'ecrire les fichiers tous en minuscules

File Contents

# User Rev Content
1 francois 283 //---------------------------------------------------------------------------
2    
3     //---------------------------------------------------------------------------
4     // include MAGIC Headers
5     #include "gestionversion.h"
6     #include "mg_geometrie.h"
7     #include "mg_arete.h"
8     #include "tpl_fonction.h"
9    
10     //---------------------------------------------------------------------------
11     // include STL headers
12     //---------------------------------------------------------------------------
13     #include <map>
14     #include <ostream>
15     #include <string>
16     #include <vector>
17     //---------------------------------------------------------------------------
18    
19    
20     #pragma hdrstop
21    
22 francois 481 #include "cad4fe_polysurface.h"
23     #include "cad4fe_mcvertex.h"
24 francois 283 #include "ot_mathematique.h"
25     #include "math.h"
26    
27     //---------------------------------------------------------------------------
28    
29     #pragma package(smart_init)
30    
31     #ifdef __BORLANDC__
32     #pragma warn -8012
33     #endif
34    
35     using namespace CAD4FE;
36    
37     //---------------------------------------------------------------------------
38     PolySurface::PolySurface(MG_FACE * __refFace)
39     {
40     // Add the reference face in the list of faces
41     _lst_ref_faces.insert(__refFace);
42     }
43     //---------------------------------------------------------------------------
44    
45     void PolySurface::InsertSurface(MG_FACE *__refFace)
46     {
47     // Add the reference face in the list of faces
48     _lst_ref_faces.insert(__refFace);
49     }
50     //---------------------------------------------------------------------------
51    
52     void PolySurface::Merge( PolySurface & __polySurface )
53     {
54     // Add the reference faces in the list of faces
55     std::set<MG_FACE*> & r = __polySurface._lst_ref_faces;
56    
57     for (std::set<MG_FACE*>::iterator itRefFace = r.begin();
58     itRefFace != r.end();
59     itRefFace++)
60     _lst_ref_faces.insert(*itRefFace);
61     }
62    
63     //---------------------------------------------------------------------------
64    
65     void PolySurface::evaluer(double *uv,double *xyz)
66     {
67    
68     }
69    
70     //---------------------------------------------------------------------------
71    
72     void PolySurface::deriver(double *uv,double *xyzdu, double *xyzdv)
73     {
74    
75     }
76    
77    
78     //---------------------------------------------------------------------------
79     void PolySurface::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz, double *xyzdu, double *xyzdv)
80     {
81    
82     }
83    
84    
85     //---------------------------------------------------------------------------
86     void PolySurface::inverser(double *uv,double *xyz,double precision)
87     {
88    
89     }
90    
91     //---------------------------------------------------------------------------
92    
93     int PolySurface::est_periodique_u(void)
94     {
95    
96     return 0;
97     }
98    
99    
100     //---------------------------------------------------------------------------
101     int PolySurface::est_periodique_v(void)
102     {
103    
104     return 0;
105     }
106    
107    
108     //---------------------------------------------------------------------------
109     double PolySurface::get_periode_u(void)
110     {
111    
112     return 0;
113     }
114    
115     //---------------------------------------------------------------------------
116    
117     double PolySurface::get_periode_v(void)
118     {
119     return 0;
120    
121     }
122    
123    
124     //---------------------------------------------------------------------------
125    
126     void PolySurface::enregistrer(std::ostream& o)
127     {
128     // %ID=CAD4FE_POLYSURFACE(MG_FACE_1,MG_FACE_2,...,MG_FACE_N)
129     unsigned int i;
130    
131     o << "%" << get_id()
132     << "=CAD4FE_POLYSURFACE(" << GetRefFaceCount() << ",(";
133    
134     for (i=0; i < GetRefFaceCount(); i++)
135     {
136     if ( i ) o <<",";
137     o << "$" << GetRefFace(i)->get_id();
138     }
139    
140     o << "));" << std::endl;;
141     }
142    
143    
144     //---------------------------------------------------------------------------
145     int PolySurface::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
146     {
147     return 0;
148     }
149     //---------------------------------------------------------------------------
150    
151     bool PolySurface::Contains(MG_ARETE * __refEdge)
152     {
153     int nb_coedge = __refEdge->get_nb_mg_coarete();
154     for (int i=0; i<nb_coedge; i++)
155     {
156     MG_FACE * f = __refEdge->get_mg_coarete(i)->get_boucle()->get_mg_face();
157     if (Contains(f))
158     return true;
159     }
160     return false;
161     }
162     //---------------------------------------------------------------------------
163    
164     bool PolySurface::Contains(MG_FACE * __refFace)
165     {
166     return ( _lst_ref_faces.find(__refFace) != _lst_ref_faces.end());
167     }
168     //---------------------------------------------------------------------------
169    
170     MG_FACE * PolySurface::GetRefFace(unsigned int __index)
171     {
172     std::set<MG_FACE*>::iterator itFace = _lst_ref_faces.begin();
173     std::advance (itFace, __index);
174     return *itFace;
175     }
176     //---------------------------------------------------------------------------
177    
178     std::set<MG_FACE*> & PolySurface::GetRefFaces()
179     {
180     return _lst_ref_faces;
181     }
182     //---------------------------------------------------------------------------
183    
184     unsigned int PolySurface::GetRefFaceCount()
185     {
186     return _lst_ref_faces.size();
187     }
188     //---------------------------------------------------------------------------
189     void PolySurface::calcul_normale_unitaire(MG_SOMMET *v, double __normal[3], int * __nbRefFace)
190     {
191     double angleTot=0;
192     OT_VECTEUR_3D normalTriangle(0,0,0);
193    
194     MG_NOEUD * refNode = 0;
195     TPL_SET < MG_ELEMENT_MAILLAGE * > * refNodeMesh = v->get_lien_maillage();
196     TPL_SET < MG_ELEMENT_MAILLAGE * >::ITERATEUR it;
197     refNode = (MG_NOEUD *)refNodeMesh->get_premier(it);
198     TPL_LISTE_ENTITE<MG_TRIANGLE*>* adjacentTriangles = refNode->get_lien_triangle();
199     unsigned itTriang;
200     for (itTriang=0;itTriang <adjacentTriangles->get_nb(); itTriang++)
201     {
202     MG_TRIANGLE* t = adjacentTriangles->get(itTriang);
203     MG_FACE * refFace = (MG_FACE*) t->get_lien_topologie();
204     if ( Contains(refFace) == false)
205     continue;
206     int id=-1;
207     MG_NOEUD * nos[3]={t->get_noeud1(),t->get_noeud2(),t->get_noeud3()};
208     for (int j=0;j<3;j++)
209     if (nos[j] == refNode)
210     {
211     id = j;
212     break;
213     }
214     OT_VECTEUR_3D x[3];
215     for (int j=0;j<3;j++)
216     x[j]=OT_VECTEUR_3D(nos[j]->get_coord());
217     OT_VECTEUR_3D x1x2 = x[id]-x[(id+2)%3];
218     x1x2.norme();
219     OT_VECTEUR_3D x2x3 = x[(id+1)%3]-x[id];
220     x2x3.norme();
221     OT_VECTEUR_3D normal = x1x2&x2x3;
222     double angle = acos(-(x1x2*x2x3));
223     normal *= angle;
224     angleTot += angle;
225     normalTriangle += normal;
226     }
227     if (angleTot != 0)
228     {
229     normalTriangle /= angleTot;
230     for (int j=0;j<3;j++)
231     __normal[j]=normalTriangle[j];
232     }
233     else
234     {
235     for (int j=0;j<3;j++)
236     __normal[j]=0;
237     }
238     *__nbRefFace = ceil(angleTot);
239     }
240     //---------------------------------------------------------------------------
241    
242     void PolySurface::calcul_normale_unitaire(MCVertex * __mcVertex, double __n[3], int *__nbRefFace)
243     {
244     // normal = 1/n * sum_i=1,n ( normal(ref face) )
245     // where n is the number of reference faces adjacent to reference vertex and contained in the MC Face
246    
247     OT_VECTEUR_3D tmpNormal(0,0,0);
248     MG_SOMMET * v = __mcVertex->GetRefVertex();
249     int nbRefFace=0;
250     calcul_normale_unitaire(v, __n, &nbRefFace);
251     std::map <unsigned long, MG_SOMMET *> & mergedVertices = __mcVertex->GetMergedRefVertices();
252     for (std::map <unsigned long, MG_SOMMET *>::iterator itRefVertex=mergedVertices.begin();
253     itRefVertex != mergedVertices.end();
254     itRefVertex++)
255     {
256     v = itRefVertex->second;
257     int tmpnbRefFace;
258     calcul_normale_unitaire(v, tmpNormal, &tmpnbRefFace);
259     for (int i=0;i<3;i++) __n[i]+=tmpNormal[i];
260     nbRefFace += tmpnbRefFace;
261     }
262     *__nbRefFace = nbRefFace;
263     }
264     //---------------------------------------------------------------------------
265    
266     void PolySurface::calcul_normale_unitaire(const std::map<MG_FACE *, OT_VECTEUR_3D > & __tabRefFaceUV, double __n[3], int *__nbRefFace)
267     {
268     (*__nbRefFace) = 0;
269     OT_VECTEUR_3D n(0,0,0);
270    
271     for (std::map<MG_FACE *, OT_VECTEUR_3D >::const_iterator itF = __tabRefFaceUV.begin();
272     itF != __tabRefFaceUV.end(); itF++)
273     {
274     MG_FACE * refFace = itF->first;
275    
276     if ( _lst_ref_faces.find(refFace) == _lst_ref_faces.end() )
277     continue;
278    
279     OT_VECTEUR_3D refFaceNormal;
280     OT_VECTEUR_3D refFaceUV=itF->second;
281     refFace->calcul_normale_unitaire(refFaceUV,refFaceNormal);
282    
283     n += refFaceNormal;
284    
285     (*__nbRefFace)++;
286     }
287    
288     if ((*__nbRefFace)==0)
289     return;
290    
291     n /= (*__nbRefFace);
292    
293     double inv_n_norm = 1/n.get_longueur();
294     for (int i=0; i<3; i++)
295     __n[i]=n[i]*inv_n_norm;
296     }
297    
298     void PolySurface::get_param_NURBS(int& indx_premier_ptctr, TPL_LISTE_ENTITE<double> &param)
299     {
300     return;
301     }
302