ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_arete.cpp
Revision: 71
Committed: Mon Mar 31 21:10:47 2008 UTC (17 years, 1 month ago) by souaissa
Original Path: magic/lib/geometrie/geometrie/src/mg_arete.cpp
File size: 11809 byte(s)
Log Message:
vectorisation est une propriete des entites

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