ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_arete.cpp
Revision: 19
Committed: Wed Jun 20 17:47:45 2007 UTC (17 years, 10 months ago) by francois
Original Path: magic/lib/geometrie/geometrie/src/mg_arete.cpp
File size: 11589 byte(s)
Log Message:
ajout d'un index dans les param NURBS

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
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     // mg_arete.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 à 11H22
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #include "mg_arete.h"
27     //#include "message.h"
28     //#include "affiche.h"
29     #include "geom.h"
30     #include <math.h>
31     #include "ot_mathematique.h"
32     #include "constantegeo.h"
33    
34     MG_ARETE::MG_ARETE(std::string idori,unsigned long num,MG_COSOMMET* mgcosom1,MG_COSOMMET* mgcosom2,MG_COURBE* crb,int sens):MG_ELEMENT_TOPOLOGIQUE(num,idori),cosommet1(mgcosom1),cosommet2(mgcosom2),courbe(crb),orientation(sens)
35     {
36     }
37    
38     MG_ARETE::MG_ARETE(std::string idori,MG_COSOMMET* mgcosom1,MG_COSOMMET* mgcosom2,MG_COURBE* crb,int sens):MG_ELEMENT_TOPOLOGIQUE(idori),cosommet1(mgcosom1),cosommet2(mgcosom2),courbe(crb),orientation(sens)
39     {
40     }
41    
42     MG_ARETE::MG_ARETE(MG_ARETE& mdd):MG_ELEMENT_TOPOLOGIQUE(mdd),cosommet1(mdd.cosommet1),cosommet2(mdd.cosommet2),courbe(mdd.courbe),orientation(mdd.orientation)
43     {
44     }
45    
46     MG_ARETE::MG_ARETE(std::string idori,unsigned long num,class MG_COURBE* crb,int sens):MG_ELEMENT_TOPOLOGIQUE(num,idori),courbe(crb),orientation(sens)
47     {
48     }
49     MG_ARETE::MG_ARETE(std::string idori,class MG_COURBE* crb,int sens):MG_ELEMENT_TOPOLOGIQUE(idori),courbe(crb),orientation(sens)
50     {
51     }
52    
53     MG_ARETE::~MG_ARETE()
54     {
55     // if (lst_coarete.size()!=0) afficheur << WARCOARETE << this->get_id()<< enderr;
56     segment.vide();
57     }
58    
59     void MG_ARETE::changer_cosommet1(class MG_COSOMMET* cosom)
60     {
61     cosommet1=cosom;
62     }
63     void MG_ARETE::changer_cosommet2(class MG_COSOMMET* cosom)
64     {
65     cosommet2=cosom;
66     }
67     MG_COSOMMET* MG_ARETE::get_cosommet1(void)
68     {
69     return cosommet1;
70     }
71     MG_COSOMMET* MG_ARETE::get_cosommet2(void)
72     {
73     return cosommet2;
74     }
75     MG_COURBE* MG_ARETE::get_courbe(void)
76     {
77     return courbe;
78     }
79     int MG_ARETE::get_orientation(void)
80     {
81     return orientation;
82     }
83    
84    
85    
86    
87     void MG_ARETE::ajouter_mg_coarete(class MG_COARETE* coarete)
88     {
89     lst_coarete.insert(lst_coarete.end(),coarete);
90     }
91    
92     int MG_ARETE::get_nb_mg_coarete(void)
93     {
94     return lst_coarete.size();
95     }
96    
97    
98     void MG_ARETE::evaluer(double t,double *xyz)
99     {
100     if (orientation!=MEME_SENS) t=courbe->get_tmin()+courbe->get_tmax()-t;
101     courbe->evaluer(t,xyz);
102     }
103    
104     void MG_ARETE::deriver(double t,double *xyz)
105     {
106     if (orientation!=MEME_SENS) t=courbe->get_tmin()+courbe->get_tmax()-t;
107     courbe->deriver(t,xyz);
108     if (orientation!=MEME_SENS)
109     {
110     xyz[0]=-xyz[0];
111     xyz[1]=-xyz[1];
112     xyz[2]=-xyz[2];
113     }
114     }
115    
116     void MG_ARETE::deriver_seconde(double t,double *ddxyz,double* dxyz,double* xyz)
117     {
118     if (orientation!=MEME_SENS) t=courbe->get_tmin()+courbe->get_tmax()-t;
119     courbe->deriver_seconde(t,ddxyz,dxyz,xyz);
120     if (orientation!=MEME_SENS)
121     {
122     dxyz[0]=-dxyz[0];
123     dxyz[1]=-dxyz[1];
124     dxyz[2]=-dxyz[2];
125     }
126     }
127    
128     void MG_ARETE::inverser(double& t,double *xyz,double precision)
129     {
130     courbe->inverser(t,xyz,precision);
131     if (orientation!=MEME_SENS) t=courbe->get_tmin()+courbe->get_tmax()-t;
132     }
133    
134     double MG_ARETE::get_tmin(void)
135     {
136     return cosommet1->get_t();
137     }
138    
139     double MG_ARETE::get_tmax(void)
140     {
141     if (!courbe->est_periodique()) return cosommet2->get_t();
142     double tmin=cosommet1->get_t();
143     double tmax=cosommet2->get_t();
144     if (tmax<tmin+1e-6) tmax=tmax+courbe->get_periode();
145     return tmax;
146     }
147    
148     double MG_ARETE::get_longueur(double t1,double t2,double precis)
149     {
150     if (orientation!=MEME_SENS)
151     {
152     t1=courbe->get_tmin()+courbe->get_tmax()-t1;
153     t2=courbe->get_tmin()+courbe->get_tmax()-t2;
154     return (-courbe->get_longueur(t1,t2,precis));
155     }
156     return courbe->get_longueur(t1,t2,precis);
157    
158     }
159    
160     double MG_ARETE::get_M(double t)
161     {
162     if (orientation!=MEME_SENS) t=courbe->get_tmin()+courbe->get_tmax()-t;
163     return courbe->get_M(t);
164     }
165    
166    
167    
168     void MG_ARETE::supprimer_mg_coarete(class MG_COARETE* coarete)
169     {
170     std::vector<MG_COARETE*>::iterator i;
171     for (i=lst_coarete.begin();i!=lst_coarete.end();i++)
172     {
173     if ((*i)==coarete)
174     {
175     lst_coarete.erase(i);
176     return;
177     }
178     }
179     }
180    
181    
182    
183     MG_COARETE* MG_ARETE::get_mg_coarete(int num)
184     {
185     return lst_coarete[num];
186     }
187    
188    
189     TPL_LISTE_ENTITE<class MG_SEGMENT*>* MG_ARETE::get_lien_segement(void)
190     {
191     return &segment;
192     }
193    
194     int MG_ARETE::get_dimension(void)
195     {
196     return 1;
197     }
198    
199     void MG_ARETE::enregistrer(std::ostream& o)
200     {
201     int nb=get_nb_ccf();
202     o << "%" << get_id() << "=ARETE("<< get_idoriginal() << ",$" << courbe->get_id() << ",$"<<cosommet1->get_id() << ",$" <<cosommet2->get_id() << "," << orientation << "," << nb;
203     if (nb!=0)
204     {
205     o << ",(";
206     for (int i=0;i<nb;i++)
207     {
208     char nom[3];
209     get_type_ccf(i,nom);
210     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
211     if (i!=nb-1) o << "," ;
212     }
213     o << ")";
214     }
215     o << ");" << std::endl;
216     }
217    
218    
219 francois 19 void MG_ARETE::get_intersection_de_deux_droites_passant_par_t1_t2(double t1, double t2,double* point_iners)
220 5 {
221     double pent1[3];
222     double xyz1[3];
223     double pent2[3];
224 francois 19 double xyz2[3];
225 5
226 francois 19 evaluer(t1,xyz1);
227     deriver(t1,pent1);
228 5
229 francois 19 evaluer(t2,xyz2);
230     deriver(t2,pent2);
231 5
232    
233     OT_VECTEUR_3D a(xyz2[0],xyz2[1],xyz2[2]); //vecteur milieu de l'arc
234     OT_VECTEUR_3D b(pent2[0],pent2[1],pent2[2]);// pente au milieu de l'arc
235     OT_VECTEUR_3D c(xyz1[0],xyz1[1],xyz1[2]); //vecteur au cosommet1 de l'arc
236     OT_VECTEUR_3D d(pent1[0],pent1[1],pent1[2]);// pente au cosommet1 de l'arc
237    
238    
239     OT_VECTEUR_3D cxd ( c.get_y()*d.get_z()-c.get_z()*d.get_y(),c.get_z()*d.get_x()-c.get_x()*d.get_z(),c.get_x()*d.get_y()-c.get_y()*d.get_x());
240    
241     double cxd_scal_a= cxd*a;
242     double cxd_scal_b= cxd*b;
243    
244 francois 19 double k1= - cxd_scal_a/cxd_scal_b;
245 5
246     OT_VECTEUR_3D P1_INTERSECTION=a+k1*b;
247    
248 francois 19 point_iners[0]=P1_INTERSECTION[0];
249     point_iners[1]=P1_INTERSECTION[1];
250     point_iners[2]=P1_INTERSECTION[2];
251 5
252 francois 19 }
253 5
254    
255    
256 francois 19 void MG_ARETE:: get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
257     {
258 5
259 francois 19
260     TPL_LISTE_ENTITE<double> param1;
261     int type=courbe->get_type_geometrique(param1);
262    
263     if((type==MGCo_CIRCLE||type==MGCo_ELLIPSE)&&(cosommet1!=cosommet2))
264     {
265    
266     double CENTQUATREVIGHT=3.1415926535897932384626433832795;
267    
268    
269     double tcs1=cosommet1->get_t();
270     double tcs2=cosommet2->get_t();
271    
272    
273    
274 5 //===================================================
275     // Construction of the control of points
276     //===================================================
277     double xyz[3];
278     // The first parameter indicate the code access
279     param.ajouter(1);
280    
281     // The follewing two parameters of the list indicate the orders of the net points
282    
283     param.ajouter(4);
284     param.ajouter(0);
285    
286     // The follewing two parameters indicate the number of rows and colons of the control points
287     // respectively to the two parameters directions
288    
289     param.ajouter(7);
290     param.ajouter(0);
291    
292    
293 francois 19
294     //the cordinates of the controls points
295    
296    
297    
298     double ouverture=fabs(tcs2-tcs1);
299    
300    
301    
302     if (ouverture<=CENTQUATREVIGHT)
303     {
304    
305 5 param.ajouter(0);
306     param.ajouter(0);
307     param.ajouter(0);
308 francois 19 param.ajouter(0.5);
309     param.ajouter(0.5);
310 5 param.ajouter(1);
311     param.ajouter(1);
312     param.ajouter(1);
313 francois 19
314    
315     double xyz1[3];
316     double xyz1_inters[3];
317     double xyz2_inters[3];
318     double xyz2[3];
319     double xyz3[3];
320     double t_mid=(tcs1+tcs2)/2;
321    
322     evaluer(tcs1,xyz1);
323    
324     param.ajouter(xyz1[0]);
325     param.ajouter(xyz1[1]);
326     param.ajouter(xyz1[2]);
327 5 param.ajouter(1);
328    
329 francois 19 evaluer(t_mid,xyz2);
330 5
331 francois 19 get_intersection_de_deux_droites_passant_par_t1_t2(tcs1, t_mid,xyz1_inters);
332    
333     param.ajouter(xyz1_inters[0]);
334     param.ajouter(xyz1_inters[1]);
335     param.ajouter(xyz1_inters[2]);
336     param.ajouter(0.5);
337    
338     get_intersection_de_deux_droites_passant_par_t1_t2(t_mid, tcs2,xyz2_inters);
339    
340     param.ajouter(xyz2_inters[0]);
341     param.ajouter(xyz2_inters[1]);
342     param.ajouter(xyz2_inters[2]);
343     param.ajouter(0.5);
344    
345     evaluer(tcs2,xyz3);
346    
347     param.ajouter(xyz3[0]);
348     param.ajouter(xyz3[1]);
349 5 param.ajouter(xyz3[2]);
350     param.ajouter(1);
351    
352 francois 19 indx_premier_ptctr=13;
353    
354     }
355    
356     if (ouverture>CENTQUATREVIGHT)
357     {
358    
359    
360     param.ajouter(0);
361     param.ajouter(0);
362     param.ajouter(0);
363     param.ajouter(0.25);
364     param.ajouter(0.25);
365 5 param.ajouter(0.5);
366 francois 19 param.ajouter(0.5);
367     param.ajouter(0.75);
368     param.ajouter(0.75);
369     param.ajouter(1);
370     param.ajouter(1);
371     param.ajouter(1);
372 5
373 francois 19 double xyz1[3];
374     double xyz1_inters[3];
375     double xyz2_inters[3];
376     double xyz2[3];
377     double xyz3[3];
378     double t1_midl=(tcs1+tcs2)/2;
379     double t_mid=(tcs1+t1_midl)/2;
380 5
381 francois 19 evaluer(tcs1,xyz1);
382    
383     param.ajouter(xyz1[0]);
384     param.ajouter(xyz1[1]);
385     param.ajouter(xyz1[2]);
386     param.ajouter(1);
387    
388    
389     get_intersection_de_deux_droites_passant_par_t1_t2(tcs1, t_mid,xyz1_inters);
390    
391     param.ajouter(xyz1_inters[0]);
392     param.ajouter(xyz1_inters[1]);
393     param.ajouter(xyz1_inters[2]);
394 5 param.ajouter(0.5);
395 francois 19
396     get_intersection_de_deux_droites_passant_par_t1_t2(t_mid, t1_midl,xyz2_inters);
397 5
398 francois 19 param.ajouter(xyz2_inters[0]);
399     param.ajouter(xyz2_inters[1]);
400     param.ajouter(xyz2_inters[2]);
401     param.ajouter(0.5);
402    
403     evaluer(t1_midl,xyz3);
404    
405 5 param.ajouter(xyz3[0]);
406     param.ajouter(xyz3[1]);
407     param.ajouter(xyz3[2]);
408     param.ajouter(1);
409 francois 19
410    
411    
412     t_mid=(t1_midl+tcs2)/2;
413     //C'est un point double
414     //evaluer(t1_midl,xyz1);
415    
416     //param.ajouter(xyz1[0]);
417     //param.ajouter(xyz1[1]);
418     //param.ajouter(xyz1[2]);
419     //param.ajouter(1);
420    
421    
422    
423     get_intersection_de_deux_droites_passant_par_t1_t2(t1_midl, t_mid,xyz1_inters);
424    
425     param.ajouter(xyz1_inters[0]);
426     param.ajouter(xyz1_inters[1]);
427     param.ajouter(xyz1_inters[2]);
428     param.ajouter(0.5);
429    
430     get_intersection_de_deux_droites_passant_par_t1_t2(t_mid, tcs2,xyz2_inters);
431    
432     param.ajouter(xyz2_inters[0]);
433     param.ajouter(xyz2_inters[1]);
434     param.ajouter(xyz2_inters[2]);
435     param.ajouter(0.5);
436    
437     evaluer(tcs2,xyz3);
438    
439     param.ajouter(xyz3[0]);
440     param.ajouter(xyz3[1]);
441     param.ajouter(xyz3[2]);
442     param.ajouter(1);
443    
444     indx_premier_ptctr=17;
445     }
446    
447 5 }
448    
449    
450    
451    
452 francois 19
453    
454 5 if ((cosommet1==cosommet2)&&(type==MGCo_ELLIPSE||type==MGCo_CIRCLE))
455 francois 19 courbe->get_param_NURBS(indx_premier_ptctr,param);
456 5
457     if (type==MGCo_LINE)
458     {
459    
460     // The first parameter indicate the code access
461     param.ajouter(1);
462     // The follewing two parameters of the list indicate the orders of the net points
463    
464     param.ajouter(2);
465 francois 19 param.ajouter(0);
466 5
467     // The follewing two parameters indicate the number of rows and colons of the control points
468     // respectively to the two parameters directions
469    
470     param.ajouter(2);
471 francois 19 param.ajouter(0);
472 5
473     // this present the knot vector in the u-direction
474    
475     param.ajouter(0);
476     param.ajouter(0);
477     param.ajouter(1);
478     param.ajouter(1);
479    
480     double xyz[3];
481     double tcs1=cosommet1->get_t();
482    
483     double tcs2=cosommet2->get_t();
484    
485     evaluer(tcs1,xyz);
486    
487     param.ajouter(xyz[0]);
488     param.ajouter(xyz[1]);
489     param.ajouter(xyz[2]);
490     param.ajouter(1);
491    
492     evaluer(tcs2,xyz);
493    
494     param.ajouter(xyz[0]);
495     param.ajouter(xyz[1]);
496     param.ajouter(xyz[2]);
497     param.ajouter(1);
498 francois 19
499     indx_premier_ptctr=9;
500 5 }
501    
502     }