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