ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_arete.cpp
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Original Path: magic/lib/geometrie/geometrie/src/mg_arete.cpp
File size: 9391 byte(s)
Log Message:

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    
220    
221     void MG_ARETE:: get_param_NURBS(TPL_LISTE_ENTITE<double> &param)
222     {
223    
224    
225     TPL_LISTE_ENTITE<double> param1;
226     int type=courbe->get_type_geometrique(param1);
227    
228     if((type==MGCo_CIRCLE||type==MGCo_ELLIPSE)&&(cosommet1!=cosommet2))
229     {
230    
231     double pent1[3];
232     double xyz1[3];
233     double pent2[3];
234     double xyz2[3];
235     double pent3[3];
236     double xyz3[3];
237    
238     double tcs1=cosommet1->get_t();
239     double tcs2=cosommet2->get_t();
240    
241     double t_mil=(tcs1+tcs2)/2;
242    
243     evaluer(tcs1,xyz1);
244     deriver(tcs1,pent1);
245    
246     evaluer(tcs2,xyz3);
247     deriver(tcs2,pent3);
248    
249     evaluer(t_mil,xyz2);
250     deriver(t_mil,pent2);
251    
252     evaluer(tcs2,xyz3);
253     deriver(tcs2,pent3);
254    
255     double k1,k2;
256    
257    
258     OT_VECTEUR_3D a(xyz2[0],xyz2[1],xyz2[2]); //vecteur milieu de l'arc
259     OT_VECTEUR_3D b(pent2[0],pent2[1],pent2[2]);// pente au milieu de l'arc
260     OT_VECTEUR_3D c(xyz1[0],xyz1[1],xyz1[2]); //vecteur au cosommet1 de l'arc
261     OT_VECTEUR_3D d(pent1[0],pent1[1],pent1[2]);// pente au cosommet1 de l'arc
262    
263    
264     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());
265    
266     double cxd_scal_a= cxd*a;
267     double cxd_scal_b= cxd*b;
268    
269     k1= - cxd_scal_a/cxd_scal_b;
270    
271     OT_VECTEUR_3D P1_INTERSECTION=a+k1*b;
272    
273     a.change_x(xyz3[0]) ;
274     a.change_y(xyz3[1]) ;
275     a.change_z(xyz3[2]) ;
276    
277     b.change_x(pent3[0]) ;
278     b.change_y(pent3[1]) ;
279     b.change_z(pent3[2]) ;
280    
281    
282     cxd_scal_a= cxd*a;
283     cxd_scal_b= cxd*b;
284     k2= - cxd_scal_a/cxd_scal_b;
285    
286     OT_VECTEUR_3D P2_INTERSECTION=a+k2*b;
287    
288     //===================================================
289     // Construction of the control of points
290     //===================================================
291     double xyz[3];
292     // The first parameter indicate the code access
293     param.ajouter(1);
294    
295     // The follewing two parameters of the list indicate the orders of the net points
296    
297     param.ajouter(4);
298     param.ajouter(0);
299    
300     // The follewing two parameters indicate the number of rows and colons of the control points
301     // respectively to the two parameters directions
302    
303     param.ajouter(7);
304     param.ajouter(0);
305    
306     // this present the knot vector in the u-direction
307    
308     param.ajouter(0);
309     param.ajouter(0);
310     param.ajouter(0);
311     param.ajouter(0);
312     param.ajouter(1);
313     param.ajouter(1);
314     param.ajouter(1);
315     param.ajouter(1);
316    
317     //the cordinates of the controls points
318    
319     param.ajouter(xyz1[0]);
320     param.ajouter(xyz2[1]);
321     param.ajouter(xyz3[2]);
322     param.ajouter(1);
323    
324     param.ajouter(P1_INTERSECTION.get_x());
325     param.ajouter(P1_INTERSECTION.get_y());
326     param.ajouter(P1_INTERSECTION.get_z());
327     param.ajouter(0.5);
328    
329    
330     param.ajouter(P2_INTERSECTION.get_x());
331     param.ajouter(P2_INTERSECTION.get_y());
332     param.ajouter(P2_INTERSECTION.get_z());
333     param.ajouter(0.5);
334    
335     param.ajouter(xyz3[0]);
336     param.ajouter(xyz3[1]);
337     param.ajouter(xyz3[2]);
338     param.ajouter(1);
339     }
340    
341    
342    
343    
344     if ((cosommet1==cosommet2)&&(type==MGCo_ELLIPSE||type==MGCo_CIRCLE))
345     courbe->get_param_NURBS(param);
346    
347     if (type==MGCo_LINE)
348     {
349    
350     // The first parameter indicate the code access
351     param.ajouter(1);
352     // The follewing two parameters of the list indicate the orders of the net points
353    
354     param.ajouter(2);
355    
356     // The follewing two parameters indicate the number of rows and colons of the control points
357     // respectively to the two parameters directions
358    
359     param.ajouter(2);
360    
361     // this present the knot vector in the u-direction
362    
363     param.ajouter(0);
364     param.ajouter(0);
365     param.ajouter(1);
366     param.ajouter(1);
367    
368     double xyz[3];
369     double tcs1=cosommet1->get_t();
370    
371     double tcs2=cosommet2->get_t();
372    
373     evaluer(tcs1,xyz);
374    
375     param.ajouter(xyz[0]);
376     param.ajouter(xyz[1]);
377     param.ajouter(xyz[2]);
378     param.ajouter(1);
379    
380     evaluer(tcs2,xyz);
381    
382     param.ajouter(xyz[0]);
383     param.ajouter(xyz[1]);
384     param.ajouter(xyz[2]);
385     param.ajouter(1);
386     }
387    
388     }