1 |
|
5 |
//---------------------------------------------------------------------------
|
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 |
|
|
#include "CAD4FE_PolySurface.h"
|
23 |
foucault |
27 |
#include "CAD4FE_MCVertex.h"
|
24 |
|
|
#include "ot_mathematique.h"
|
25 |
|
|
#include "math.h"
|
26 |
|
5 |
|
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> ¶m)
|
146 |
|
|
{
|
147 |
|
|
return 0;
|
148 |
|
|
}
|
149 |
foucault |
27 |
//---------------------------------------------------------------------------
|
150 |
|
5 |
|
151 |
foucault |
27 |
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 |
|
5 |
|
164 |
|
|
bool PolySurface::Contains(MG_FACE * __refFace)
|
165 |
|
|
{
|
166 |
|
|
return ( _lst_ref_faces.find(__refFace) != _lst_ref_faces.end());
|
167 |
|
|
}
|
168 |
foucault |
27 |
//---------------------------------------------------------------------------
|
169 |
|
5 |
|
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 |
foucault |
27 |
//---------------------------------------------------------------------------
|
177 |
|
5 |
|
178 |
|
|
std::set<MG_FACE*> & PolySurface::GetRefFaces()
|
179 |
|
|
{
|
180 |
|
|
return _lst_ref_faces;
|
181 |
|
|
}
|
182 |
foucault |
27 |
//---------------------------------------------------------------------------
|
183 |
|
5 |
|
184 |
|
|
unsigned int PolySurface::GetRefFaceCount()
|
185 |
|
|
{
|
186 |
|
|
return _lst_ref_faces.size();
|
187 |
|
|
}
|
188 |
foucault |
27 |
//---------------------------------------------------------------------------
|
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 |
|
|
{ id = j; break; }
|
211 |
|
|
OT_VECTEUR_3D x[3];
|
212 |
|
|
for (int j=0;j<3;j++)
|
213 |
|
|
x[j]=OT_VECTEUR_3D(nos[j]->get_coord());
|
214 |
|
|
OT_VECTEUR_3D x1x2 = x[id]-x[(id+2)%3];
|
215 |
|
|
x1x2.norme();
|
216 |
|
|
OT_VECTEUR_3D x2x3 = x[(id+1)%3]-x[id];
|
217 |
|
|
x2x3.norme();
|
218 |
|
|
OT_VECTEUR_3D normal = x1x2&x2x3;
|
219 |
|
|
double angle = acos(-(x1x2*x2x3));
|
220 |
|
|
normal *= angle;
|
221 |
|
|
angleTot += angle;
|
222 |
|
|
normalTriangle += normal;
|
223 |
|
|
}
|
224 |
|
|
if (angleTot != 0)
|
225 |
|
|
{
|
226 |
|
|
normalTriangle /= angleTot;
|
227 |
|
|
for (int j=0;j<3;j++)
|
228 |
|
|
__normal[j]=normalTriangle[j];
|
229 |
|
|
}
|
230 |
|
|
else
|
231 |
|
|
{
|
232 |
|
|
for (int j=0;j<3;j++)
|
233 |
|
|
__normal[j]=0;
|
234 |
|
|
}
|
235 |
|
|
*__nbRefFace = ceil(angleTot);
|
236 |
|
|
}
|
237 |
|
|
//---------------------------------------------------------------------------
|
238 |
|
5 |
|
239 |
foucault |
27 |
void PolySurface::calcul_normale_unitaire(MCVertex * __mcVertex, double __n[3], int *__nbRefFace)
|
240 |
|
5 |
{
|
241 |
foucault |
27 |
// normal = 1/n * sum_i=1,n ( normal(ref face) )
|
242 |
|
|
// where n is the number of reference faces adjacent to reference vertex and contained in the MC Face
|
243 |
|
|
|
244 |
|
|
OT_VECTEUR_3D tmpNormal(0,0,0);
|
245 |
|
|
MG_SOMMET * v = __mcVertex->GetRefVertex();
|
246 |
|
|
int nbRefFace=0;
|
247 |
|
|
calcul_normale_unitaire(v, __n, &nbRefFace);
|
248 |
|
|
std::map <unsigned long, MG_SOMMET *> & mergedVertices = __mcVertex->GetMergedRefVertices();
|
249 |
|
|
for (std::map <unsigned long, MG_SOMMET *>::iterator itRefVertex=mergedVertices.begin();
|
250 |
|
|
itRefVertex != mergedVertices.end();
|
251 |
|
|
itRefVertex++)
|
252 |
|
|
{
|
253 |
|
|
v = itRefVertex->second;
|
254 |
|
|
int tmpnbRefFace;
|
255 |
|
|
calcul_normale_unitaire(v, tmpNormal, &tmpnbRefFace);
|
256 |
|
|
for (int i=0;i<3;i++) __n[i]+=tmpNormal[i];
|
257 |
|
|
nbRefFace += tmpnbRefFace;
|
258 |
|
|
}
|
259 |
|
|
*__nbRefFace = nbRefFace;
|
260 |
|
5 |
}
|
261 |
foucault |
27 |
//---------------------------------------------------------------------------
|
262 |
|
5 |
|
263 |
foucault |
27 |
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 |
|
5 |
|
268 |
foucault |
27 |
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 |
|
5 |
|
273 |
foucault |
27 |
if ( _lst_ref_faces.find(refFace) == _lst_ref_faces.end() )
|
274 |
|
|
continue;
|
275 |
|
5 |
|
276 |
foucault |
27 |
OT_VECTEUR_3D refFaceNormal;
|
277 |
|
|
OT_VECTEUR_3D refFaceUV=itF->second;
|
278 |
|
|
refFace->calcul_normale_unitaire(refFaceUV,refFaceNormal);
|
279 |
|
5 |
|
280 |
foucault |
27 |
n += refFaceNormal;
|
281 |
|
5 |
|
282 |
foucault |
27 |
(*__nbRefFace)++;
|
283 |
|
|
}
|
284 |
|
|
|
285 |
|
|
if ((*__nbRefFace)==0)
|
286 |
|
|
return;
|
287 |
|
5 |
|
288 |
foucault |
27 |
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 |
|
5 |
|
295 |
foucault |
27 |
void PolySurface::get_param_NURBS(int& indx_premier_ptctr, TPL_LISTE_ENTITE<double> ¶m)
|
296 |
|
|
{
|
297 |
|
|
return;
|
298 |
|
|
}
|
299 |
|
|
|