1 |
francois |
283 |
//------------------------------------------------------------ |
2 |
|
|
//------------------------------------------------------------ |
3 |
|
|
// MAGiC |
4 |
|
|
// Jean Christophe Cuilli�re et Vincent FRANCOIS |
5 |
|
|
// D�partement de G�nie M�canique - UQTR |
6 |
|
|
//------------------------------------------------------------ |
7 |
|
|
// Le projet MAGIC est un projet de recherche du d�partement |
8 |
|
|
// de g�nie m�canique de l'Universit� du Qu�bec � |
9 |
|
|
// Trois Rivi�res |
10 |
|
|
// Les librairies ne peuvent �tre utilis�es sans l'accord |
11 |
|
|
// des auteurs (contact : francois@uqtr.ca) |
12 |
|
|
//------------------------------------------------------------ |
13 |
|
|
//------------------------------------------------------------ |
14 |
|
|
// |
15 |
|
|
// sld_surface.cpp |
16 |
|
|
// |
17 |
|
|
//------------------------------------------------------------ |
18 |
|
|
//------------------------------------------------------------ |
19 |
|
|
// COPYRIGHT 2000 |
20 |
|
|
// Version du 02/03/2006 � 11H22 |
21 |
|
|
//------------------------------------------------------------ |
22 |
|
|
//------------------------------------------------------------ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "gestionversion.h" |
26 |
|
|
|
27 |
|
|
#ifdef BREP_SLD |
28 |
|
|
|
29 |
|
|
#include "mg_surface.h" |
30 |
|
|
#include "sld_surface.h" |
31 |
|
|
#include <system.hpp> |
32 |
|
|
#include <atl\atlmod.h> |
33 |
|
|
#include "smartvars.h" |
34 |
|
|
//#include <clx.h> |
35 |
|
|
#include "sld_fonction.h" |
36 |
|
|
#include "stplane.h" |
37 |
|
|
#include "stcylindrical.h" |
38 |
|
|
#include "stconical.h" |
39 |
|
|
#include "stspherical.h" |
40 |
|
|
#include "sttoroidal.h" |
41 |
|
|
#include "stbsplines.h" |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
//TComModule& _Module=*static_cast<TComModule*>(NULL); |
45 |
|
|
|
46 |
|
|
SLD_SURFACE::SLD_SURFACE(unsigned long num,string idface,SLD_FONCTION& fonc):MG_SURFACE(num),fonction(fonc) |
47 |
|
|
{ |
48 |
|
|
initialisation(idface); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
SLD_SURFACE::SLD_SURFACE(string idface,SLD_FONCTION& fonc):MG_SURFACE(),fonction(fonc) |
53 |
|
|
{ |
54 |
|
|
initialisation(idface); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
SLD_SURFACE::SLD_SURFACE(string idface, SLD_FONCTION& fonc, CComPtr < IFace2 > & p_swFace) : MG_SURFACE(), swFace(p_swFace), fonction(fonc) |
58 |
|
|
{ |
59 |
|
|
swFace->IGetSurface(&swSurface); |
60 |
|
|
initialisation(); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
void SLD_SURFACE::initialisation(string idface) |
64 |
|
|
{ |
65 |
|
|
idoriginal=idface; |
66 |
|
|
fonction.GetParID((char*)idface.c_str(),swFace); |
67 |
|
|
swFace->IGetSurface(&swSurface); |
68 |
|
|
initialisation(); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
void SLD_SURFACE::initialisation() |
72 |
|
|
{ |
73 |
|
|
CComVariant vparam; |
74 |
|
|
swSurface->Parameterization( &vparam); |
75 |
|
|
SafeDoubleArray saparam(vparam); |
76 |
|
|
u_min=saparam[0]; |
77 |
|
|
u_max=saparam[1]; |
78 |
|
|
v_min=saparam[2]; |
79 |
|
|
v_max=saparam[3]; |
80 |
|
|
stsurface=NULL; |
81 |
|
|
VARIANT_BOOL retval; |
82 |
|
|
swSurface->IsPlane(&retval); |
83 |
|
|
if (retval==1) |
84 |
|
|
{ |
85 |
|
|
CComVariant vRetval; |
86 |
|
|
vRetval=swSurface->get_PlaneParams(); |
87 |
|
|
SafeDoubleArray sda(vRetval); |
88 |
|
|
double origine[3]; |
89 |
|
|
double dir[3]; |
90 |
|
|
origine[0]=sda[3]; |
91 |
|
|
origine[1]=sda[4]; |
92 |
|
|
origine[2]=sda[5]; |
93 |
|
|
dir[0]=sda[0]; |
94 |
|
|
dir[1]=sda[1]; |
95 |
|
|
dir[2]=sda[2]; |
96 |
|
|
stsurface=new ST_PLANE(origine,dir); |
97 |
|
|
return; |
98 |
|
|
} |
99 |
|
|
swSurface->IsCylinder(&retval); |
100 |
|
|
if (retval==1) |
101 |
|
|
{ |
102 |
|
|
CComVariant vRetval; |
103 |
|
|
vRetval=swSurface->get_CylinderParams(); |
104 |
|
|
SafeDoubleArray sda(vRetval); |
105 |
|
|
double origine[3]; |
106 |
|
|
double dir[3]; |
107 |
|
|
origine[0]=sda[0]; |
108 |
|
|
origine[1]=sda[1]; |
109 |
|
|
origine[2]=sda[2]; |
110 |
|
|
dir[0]=sda[3]; |
111 |
|
|
dir[1]=sda[4]; |
112 |
|
|
dir[2]=sda[5]; |
113 |
|
|
double rayon=sda[6]; |
114 |
|
|
stsurface=new ST_CYLINDRICAL(origine,dir,NULL,rayon); |
115 |
|
|
return; |
116 |
|
|
} |
117 |
|
|
swSurface->IsCone(&retval); |
118 |
|
|
if (retval==1) |
119 |
|
|
{ |
120 |
|
|
CComVariant vRetval; |
121 |
|
|
vRetval=swSurface->get_ConeParams(); |
122 |
|
|
SafeDoubleArray sda(vRetval); |
123 |
|
|
double origine[3]; |
124 |
|
|
double dir[3]; |
125 |
|
|
origine[0]=sda[0]; |
126 |
|
|
origine[1]=sda[1]; |
127 |
|
|
origine[2]=sda[2]; |
128 |
|
|
dir[0]=-sda[3]; |
129 |
|
|
dir[1]=-sda[4]; |
130 |
|
|
dir[2]=-sda[5]; |
131 |
|
|
double rayon=sda[6]; |
132 |
|
|
double angle=sda[7]; |
133 |
|
|
stsurface=new ST_CONICAL(origine,dir,NULL,rayon,angle); |
134 |
|
|
return; |
135 |
|
|
} |
136 |
|
|
swSurface->IsSphere(&retval); |
137 |
|
|
if (retval==1) |
138 |
|
|
{ |
139 |
|
|
CComVariant vRetval; |
140 |
|
|
vRetval=swSurface->get_SphereParams() ; |
141 |
|
|
SafeDoubleArray sda(vRetval); |
142 |
|
|
double origine[3]; |
143 |
|
|
origine[0]=sda[0]; |
144 |
|
|
origine[1]=sda[1]; |
145 |
|
|
origine[2]=sda[2]; |
146 |
|
|
double rayon=sda[3]; |
147 |
|
|
stsurface=new ST_SPHERICAL(origine,NULL,NULL,rayon); |
148 |
|
|
return; |
149 |
|
|
} |
150 |
|
|
swSurface->IsTorus(&retval) ; |
151 |
|
|
if (retval==1) |
152 |
|
|
{ |
153 |
|
|
CComVariant vRetval; |
154 |
|
|
vRetval=swSurface->get_TorusParams(); |
155 |
|
|
SafeDoubleArray sda(vRetval); |
156 |
|
|
double origine[3]; |
157 |
|
|
double dir[3]; |
158 |
|
|
origine[0]=sda[0]; |
159 |
|
|
origine[1]=sda[1]; |
160 |
|
|
origine[2]=sda[2]; |
161 |
|
|
dir[0]=sda[3]; |
162 |
|
|
dir[1]=sda[4]; |
163 |
|
|
dir[2]=sda[5]; |
164 |
|
|
double grayon=sda[6]; |
165 |
|
|
double prayon=sda[7]; |
166 |
|
|
stsurface=new ST_TOROIDAL(origine,dir,grayon,prayon); |
167 |
|
|
return; |
168 |
|
|
} |
169 |
|
|
VARIANT vRetval; |
170 |
|
|
VARIANT_BOOL sense; |
171 |
|
|
VARIANT vp0; |
172 |
|
|
vp0=swFace->GetUVBounds(); |
173 |
|
|
double tolerance = fonction.GetValeurTolerance() ; |
174 |
|
|
swSurface->GetBSurfParams2(false,false,vp0,tolerance,&sense,&vRetval); |
175 |
|
|
SafeDoubleArray sda(vRetval); |
176 |
|
|
int uordre,vordre; |
177 |
|
|
int numcpt,numlpt; |
178 |
|
|
int uperiodic,vperiodic; |
179 |
|
|
int dim,dummy; |
180 |
|
|
OPERATEUR::doubleto2int(sda[0],uordre,vordre); |
181 |
|
|
OPERATEUR::doubleto2int(sda[1],numcpt,numlpt); |
182 |
|
|
OPERATEUR::doubleto2int(sda[2],uperiodic,vperiodic); |
183 |
|
|
OPERATEUR::doubleto2int(sda[3],dim,dummy); |
184 |
|
|
vector<double> knots_u; |
185 |
|
|
vector<double> knots_v; |
186 |
|
|
vector<double> poids; |
187 |
|
|
vector<double> ptsctr; |
188 |
|
|
for (int i=0;i<uordre+numcpt;i++) |
189 |
|
|
knots_u.insert(knots_u.end(),sda[4+i]); |
190 |
|
|
for (int i=0;i<vordre+numlpt;i++) |
191 |
|
|
knots_v.insert(knots_v.end(),sda[4+uordre+numcpt+i]); |
192 |
|
|
for (int i=0;i<numcpt;i++) |
193 |
|
|
for (int j=0;j<numlpt;j++) |
194 |
|
|
{ |
195 |
|
|
int num=j*numcpt+i; |
196 |
|
|
ptsctr.insert(ptsctr.end(),sda[4+uordre+numcpt+vordre+numlpt+dim*num]); |
197 |
|
|
ptsctr.insert(ptsctr.end(),sda[4+uordre+numcpt+vordre+numlpt+dim*num+1]); |
198 |
|
|
ptsctr.insert(ptsctr.end(),sda[4+uordre+numcpt+vordre+numlpt+dim*num+2]); |
199 |
|
|
if (dim==4) poids.insert(poids.end(),sda[4+uordre+numcpt+vordre+numlpt+dim*num+3]); |
200 |
|
|
else poids.insert(poids.end(),1.); |
201 |
|
|
} |
202 |
|
|
int sens; |
203 |
|
|
sens=1; |
204 |
|
|
stsurface=new ST_B_SPLINE_SURF(uordre-1,vordre-1,knots_u,knots_v,ptsctr,poids,sens); |
205 |
|
|
// Gilles: J'ai rencontr� le cas d'une surface NURBS dont ST_BSPLINE_SURF |
206 |
|
|
// ne d�tecte pas la p�riodicit�: le crit�re de p�riodicit� de ST_BSPLINE_SURF est |
207 |
|
|
// l'�galit� des points de controle pour umin/umax ou vmin/vmax |
208 |
|
|
// r�sultat: imposibilit� de mailler |
209 |
|
|
// |
210 |
|
|
// j'ai pr�f�r� corriger en ajoutant la m�thode set_periodique_u() � ST_BSPLINE_SURF |
211 |
|
|
// afin d'utiliser les informations de p�riodicit� donn�es explicitement par |
212 |
|
|
// SolidWorks |
213 |
|
|
((ST_B_SPLINE_SURF*) stsurface)->set_periodique_u( uperiodic ); |
214 |
|
|
((ST_B_SPLINE_SURF*) stsurface)->set_periodique_v( vperiodic ); |
215 |
|
|
}; |
216 |
|
|
|
217 |
|
|
|
218 |
|
|
SLD_SURFACE::~SLD_SURFACE() |
219 |
|
|
{ |
220 |
|
|
if (swFace.p != NULL) swFace.p = NULL; |
221 |
|
|
if (swSurface.p != NULL) swSurface.p = NULL; |
222 |
|
|
if (stsurface!=NULL) delete stsurface; |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
void SLD_SURFACE::evaluer(double *uv,double *xyz) |
226 |
|
|
{ |
227 |
|
|
if (stsurface!=NULL) |
228 |
|
|
{ |
229 |
|
|
stsurface->evaluer(uv,xyz); |
230 |
|
|
return; |
231 |
|
|
} |
232 |
|
|
//entr�e |
233 |
|
|
double UParam=uv[0]; |
234 |
|
|
double VParam=uv[1]; |
235 |
|
|
long NumUDeriv=0; |
236 |
|
|
long NumVDeriv=0; |
237 |
|
|
//sortie |
238 |
|
|
CComVariant vretval; |
239 |
|
|
|
240 |
|
|
swSurface->Evaluate ( UParam, VParam, NumUDeriv, NumVDeriv, &vretval); |
241 |
|
|
SafeDoubleArray saretval(vretval); |
242 |
|
|
//notre r�sultat |
243 |
|
|
xyz[0]=saretval[0]; |
244 |
|
|
xyz[1]=saretval[1]; |
245 |
|
|
xyz[2]=saretval[2]; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
void SLD_SURFACE::deriver(double *uv,double *xyzdu, double *xyzdv) |
249 |
|
|
{ |
250 |
|
|
if (stsurface!=NULL) |
251 |
|
|
{ |
252 |
|
|
stsurface->deriver(uv,xyzdu,xyzdv); |
253 |
|
|
return; |
254 |
|
|
} |
255 |
|
|
//entr�e |
256 |
|
|
double UParam=uv[0]; |
257 |
|
|
double VParam=uv[1]; |
258 |
|
|
long NumUDeriv=1; |
259 |
|
|
long NumVDeriv=1; |
260 |
|
|
//sortie |
261 |
|
|
CComVariant vretval; |
262 |
|
|
|
263 |
|
|
swSurface->Evaluate ( UParam, VParam, NumUDeriv, NumVDeriv, &vretval); |
264 |
|
|
SafeDoubleArray saretval(vretval); |
265 |
|
|
xyzdu[0]=saretval[3]; |
266 |
|
|
xyzdu[1]=saretval[4]; |
267 |
|
|
xyzdu[2]=saretval[5]; |
268 |
|
|
xyzdv[0]=saretval[6]; |
269 |
|
|
xyzdv[1]=saretval[7]; |
270 |
|
|
xyzdv[2]=saretval[8]; |
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
void SLD_SURFACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz, double *xyzdu, double *xyzdv) |
274 |
|
|
{ |
275 |
|
|
if (stsurface!=NULL) |
276 |
|
|
{ |
277 |
|
|
stsurface->deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv); |
278 |
|
|
return; |
279 |
|
|
} |
280 |
|
|
//entr�e |
281 |
|
|
double UParam=uv[0]; |
282 |
|
|
double VParam=uv[1]; |
283 |
|
|
long NumUDeriv=2; |
284 |
|
|
long NumVDeriv=2; |
285 |
|
|
//sortie |
286 |
|
|
CComVariant vretval; |
287 |
|
|
|
288 |
|
|
swSurface->Evaluate ( UParam, VParam, NumUDeriv, NumVDeriv, &vretval); |
289 |
|
|
SafeDoubleArray saretval(vretval); |
290 |
|
|
// virtual void deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv, |
291 |
|
|
//double *xyz = NULL , double *xyzdu = NULL , double *xyzdv =NULL); |
292 |
|
|
if (xyz!=NULL) //or xyz~=NULL |
293 |
|
|
{ |
294 |
|
|
xyz[0]=saretval[0]; |
295 |
|
|
xyz[1]=saretval[1]; |
296 |
|
|
xyz[2]=saretval[2]; |
297 |
|
|
} |
298 |
|
|
if (xyzdu!= NULL) |
299 |
|
|
{ |
300 |
|
|
xyzdu[0]=saretval[3]; |
301 |
|
|
xyzdu[1]=saretval[4]; |
302 |
|
|
xyzdu[2]=saretval[5]; |
303 |
|
|
} |
304 |
|
|
if (xyzdv!=NULL) |
305 |
|
|
{ |
306 |
|
|
xyzdv[0]=saretval[9]; |
307 |
|
|
xyzdv[1]=saretval[10]; |
308 |
|
|
xyzdv[2]=saretval[11]; |
309 |
|
|
} |
310 |
|
|
//affectation normale |
311 |
|
|
xyzduu[0]=saretval[6]; |
312 |
|
|
xyzduu[1]=saretval[7]; |
313 |
|
|
xyzduu[2]=saretval[8]; |
314 |
|
|
xyzduv[0]=saretval[12]; |
315 |
|
|
xyzduv[1]=saretval[13]; |
316 |
|
|
xyzduv[2]=saretval[14]; |
317 |
|
|
xyzdvv[0]=saretval[18]; |
318 |
|
|
xyzdvv[1]=saretval[19]; |
319 |
|
|
xyzdvv[2]=saretval[20]; |
320 |
|
|
} |
321 |
|
|
|
322 |
|
|
void SLD_SURFACE::inverser(double* uv,double *xyz,double precision) |
323 |
|
|
{//Param�tre pr�cision |
324 |
|
|
if (stsurface!=NULL) |
325 |
|
|
{ |
326 |
|
|
stsurface->inverser(uv,xyz,precision); |
327 |
|
|
return; |
328 |
|
|
} |
329 |
|
|
CComVariant vUV; |
330 |
|
|
swSurface->ReverseEvaluate(xyz[0], xyz[1], xyz[2], &vUV); |
331 |
|
|
SafeDoubleArray saUV(vUV); |
332 |
|
|
uv[0] = saUV[0]; |
333 |
|
|
uv[1] = saUV[1]; |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
int SLD_SURFACE::est_periodique_u(void) |
337 |
|
|
{ |
338 |
|
|
return stsurface->est_periodique_u(); |
339 |
|
|
} |
340 |
|
|
|
341 |
|
|
int SLD_SURFACE::est_periodique_v(void) |
342 |
|
|
{ |
343 |
|
|
return stsurface->est_periodique_v(); |
344 |
|
|
} |
345 |
|
|
|
346 |
|
|
double SLD_SURFACE::get_periode_u(void) |
347 |
|
|
{ |
348 |
|
|
return stsurface->get_periode_u(); |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
double SLD_SURFACE::get_periode_v(void) |
352 |
|
|
{ |
353 |
|
|
return stsurface->get_periode_v(); |
354 |
|
|
} |
355 |
|
|
|
356 |
|
|
double SLD_SURFACE::get_umin() |
357 |
|
|
{ |
358 |
|
|
if (stsurface != NULL) |
359 |
|
|
return stsurface->get_umin(); |
360 |
|
|
return u_min; |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
double SLD_SURFACE::get_umax() |
364 |
|
|
{ |
365 |
|
|
if (stsurface != NULL) |
366 |
|
|
return stsurface->get_umax(); |
367 |
|
|
return u_max; |
368 |
|
|
} |
369 |
|
|
|
370 |
|
|
double SLD_SURFACE::get_vmin() |
371 |
|
|
{ |
372 |
|
|
if (stsurface != NULL) |
373 |
|
|
return stsurface->get_vmin(); |
374 |
|
|
return v_min; |
375 |
|
|
} |
376 |
|
|
|
377 |
|
|
double SLD_SURFACE::get_vmax() |
378 |
|
|
{ |
379 |
|
|
if (stsurface != NULL) |
380 |
|
|
return stsurface->get_vmax(); |
381 |
|
|
return v_max; |
382 |
|
|
} |
383 |
|
|
|
384 |
francois |
763 |
void SLD_SURFACE::enregistrer(ostream& o,double version) |
385 |
francois |
283 |
{ |
386 |
|
|
o << "%" << get_id() << "=SURFACE_SLD("<< idoriginal.c_str() << ");" << endl; |
387 |
|
|
} |
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
int SLD_SURFACE::get_type_geometrique(TPL_LISTE_ENTITE<double> ¶m) |
392 |
|
|
{ |
393 |
|
|
if (stsurface!=NULL) |
394 |
|
|
return stsurface->get_type_geometrique(param);; |
395 |
|
|
return 0; |
396 |
|
|
} |
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
void SLD_SURFACE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> ¶m) |
401 |
|
|
{ |
402 |
|
|
stsurface->get_param_NURBS(indx_premier_ptctr,param); |
403 |
|
|
} |
404 |
|
|
|
405 |
|
|
|
406 |
|
|
#endif |
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|