ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/CAD4FE_PolySurface.cpp
Revision: 906
Committed: Mon Nov 13 22:30:18 2017 UTC (7 years, 6 months ago) by couturad
File size: 8952 byte(s)
Log Message:
Nouveau opencascade commit 1

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 foucault 569 #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 couturad 906 bool PolySurface::est_sur_surface(double* xyz, double precision)
92     {
93     std::cout <<" *** PolySurface::est_sur_surface : FONCTION NON IMPLEMENTE ***" << std::endl;
94     }
95    
96 francois 283 //---------------------------------------------------------------------------
97    
98     int PolySurface::est_periodique_u(void)
99     {
100    
101     return 0;
102     }
103    
104    
105     //---------------------------------------------------------------------------
106     int PolySurface::est_periodique_v(void)
107     {
108    
109     return 0;
110     }
111    
112    
113     //---------------------------------------------------------------------------
114     double PolySurface::get_periode_u(void)
115     {
116    
117     return 0;
118     }
119    
120     //---------------------------------------------------------------------------
121    
122     double PolySurface::get_periode_v(void)
123     {
124     return 0;
125    
126     }
127    
128    
129     //---------------------------------------------------------------------------
130    
131 francois 763 void PolySurface::enregistrer(std::ostream& o,double version)
132 francois 283 {
133     // %ID=CAD4FE_POLYSURFACE(MG_FACE_1,MG_FACE_2,...,MG_FACE_N)
134     unsigned int i;
135    
136     o << "%" << get_id()
137     << "=CAD4FE_POLYSURFACE(" << GetRefFaceCount() << ",(";
138    
139     for (i=0; i < GetRefFaceCount(); i++)
140     {
141     if ( i ) o <<",";
142     o << "$" << GetRefFace(i)->get_id();
143     }
144    
145     o << "));" << std::endl;;
146     }
147    
148    
149     //---------------------------------------------------------------------------
150     int PolySurface::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
151     {
152     return 0;
153     }
154     //---------------------------------------------------------------------------
155    
156     bool PolySurface::Contains(MG_ARETE * __refEdge)
157     {
158     int nb_coedge = __refEdge->get_nb_mg_coarete();
159     for (int i=0; i<nb_coedge; i++)
160     {
161     MG_FACE * f = __refEdge->get_mg_coarete(i)->get_boucle()->get_mg_face();
162     if (Contains(f))
163     return true;
164     }
165     return false;
166     }
167     //---------------------------------------------------------------------------
168    
169     bool PolySurface::Contains(MG_FACE * __refFace)
170     {
171     return ( _lst_ref_faces.find(__refFace) != _lst_ref_faces.end());
172     }
173     //---------------------------------------------------------------------------
174    
175     MG_FACE * PolySurface::GetRefFace(unsigned int __index)
176     {
177     std::set<MG_FACE*>::iterator itFace = _lst_ref_faces.begin();
178     std::advance (itFace, __index);
179     return *itFace;
180     }
181     //---------------------------------------------------------------------------
182    
183     std::set<MG_FACE*> & PolySurface::GetRefFaces()
184     {
185     return _lst_ref_faces;
186     }
187     //---------------------------------------------------------------------------
188    
189     unsigned int PolySurface::GetRefFaceCount()
190     {
191     return _lst_ref_faces.size();
192     }
193     //---------------------------------------------------------------------------
194     void PolySurface::calcul_normale_unitaire(MG_SOMMET *v, double __normal[3], int * __nbRefFace)
195     {
196     double angleTot=0;
197     OT_VECTEUR_3D normalTriangle(0,0,0);
198    
199     MG_NOEUD * refNode = 0;
200     TPL_SET < MG_ELEMENT_MAILLAGE * > * refNodeMesh = v->get_lien_maillage();
201     TPL_SET < MG_ELEMENT_MAILLAGE * >::ITERATEUR it;
202     refNode = (MG_NOEUD *)refNodeMesh->get_premier(it);
203     TPL_LISTE_ENTITE<MG_TRIANGLE*>* adjacentTriangles = refNode->get_lien_triangle();
204     unsigned itTriang;
205     for (itTriang=0;itTriang <adjacentTriangles->get_nb(); itTriang++)
206     {
207     MG_TRIANGLE* t = adjacentTriangles->get(itTriang);
208     MG_FACE * refFace = (MG_FACE*) t->get_lien_topologie();
209     if ( Contains(refFace) == false)
210     continue;
211     int id=-1;
212     MG_NOEUD * nos[3]={t->get_noeud1(),t->get_noeud2(),t->get_noeud3()};
213     for (int j=0;j<3;j++)
214     if (nos[j] == refNode)
215     {
216     id = j;
217     break;
218     }
219     OT_VECTEUR_3D x[3];
220     for (int j=0;j<3;j++)
221     x[j]=OT_VECTEUR_3D(nos[j]->get_coord());
222     OT_VECTEUR_3D x1x2 = x[id]-x[(id+2)%3];
223     x1x2.norme();
224     OT_VECTEUR_3D x2x3 = x[(id+1)%3]-x[id];
225     x2x3.norme();
226     OT_VECTEUR_3D normal = x1x2&x2x3;
227     double angle = acos(-(x1x2*x2x3));
228     normal *= angle;
229     angleTot += angle;
230     normalTriangle += normal;
231     }
232     if (angleTot != 0)
233     {
234     normalTriangle /= angleTot;
235     for (int j=0;j<3;j++)
236     __normal[j]=normalTriangle[j];
237     }
238     else
239     {
240     for (int j=0;j<3;j++)
241     __normal[j]=0;
242     }
243     *__nbRefFace = ceil(angleTot);
244     }
245     //---------------------------------------------------------------------------
246    
247     void PolySurface::calcul_normale_unitaire(MCVertex * __mcVertex, double __n[3], int *__nbRefFace)
248     {
249     // normal = 1/n * sum_i=1,n ( normal(ref face) )
250     // where n is the number of reference faces adjacent to reference vertex and contained in the MC Face
251    
252     OT_VECTEUR_3D tmpNormal(0,0,0);
253     MG_SOMMET * v = __mcVertex->GetRefVertex();
254     int nbRefFace=0;
255     calcul_normale_unitaire(v, __n, &nbRefFace);
256     std::map <unsigned long, MG_SOMMET *> & mergedVertices = __mcVertex->GetMergedRefVertices();
257     for (std::map <unsigned long, MG_SOMMET *>::iterator itRefVertex=mergedVertices.begin();
258     itRefVertex != mergedVertices.end();
259     itRefVertex++)
260     {
261     v = itRefVertex->second;
262     int tmpnbRefFace;
263     calcul_normale_unitaire(v, tmpNormal, &tmpnbRefFace);
264     for (int i=0;i<3;i++) __n[i]+=tmpNormal[i];
265     nbRefFace += tmpnbRefFace;
266     }
267     *__nbRefFace = nbRefFace;
268     }
269     //---------------------------------------------------------------------------
270    
271     void PolySurface::calcul_normale_unitaire(const std::map<MG_FACE *, OT_VECTEUR_3D > & __tabRefFaceUV, double __n[3], int *__nbRefFace)
272     {
273     (*__nbRefFace) = 0;
274     OT_VECTEUR_3D n(0,0,0);
275    
276     for (std::map<MG_FACE *, OT_VECTEUR_3D >::const_iterator itF = __tabRefFaceUV.begin();
277     itF != __tabRefFaceUV.end(); itF++)
278     {
279     MG_FACE * refFace = itF->first;
280    
281     if ( _lst_ref_faces.find(refFace) == _lst_ref_faces.end() )
282     continue;
283    
284     OT_VECTEUR_3D refFaceNormal;
285     OT_VECTEUR_3D refFaceUV=itF->second;
286     refFace->calcul_normale_unitaire(refFaceUV,refFaceNormal);
287    
288     n += refFaceNormal;
289    
290     (*__nbRefFace)++;
291     }
292    
293     if ((*__nbRefFace)==0)
294     return;
295    
296     n /= (*__nbRefFace);
297    
298     double inv_n_norm = 1/n.get_longueur();
299     for (int i=0; i<3; i++)
300     __n[i]=n[i]*inv_n_norm;
301     }
302    
303     void PolySurface::get_param_NURBS(int& indx_premier_ptctr, TPL_LISTE_ENTITE<double> &param)
304     {
305     return;
306     }
307    
308 francois 820 void PolySurface::get_liste_pole(std::vector<double> *liste_pole,double eps)
309 couturad 814 {
310 francois 820 printf("void PolySurface::get_liste_pole(std::vector<double> *liste_pole) : Fonction non implementee !\n");
311 couturad 814 }
312    
313    
314