ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/outil/src/ot_boite_3d.cpp
Revision: 1019
Committed: Tue Jun 4 21:16:50 2019 UTC (6 years ago) by francois
File size: 6683 byte(s)
Log Message:
restructuration de magic
outil est sorti de lib pour pouvoir etre utiliser en dehors de lib
template est merge avec outil
poly_occ et un sous projet de magic qui utilise le nouveau outil

File Contents

# User Rev Content
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     // ot_boite_3D.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 � 11H23
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25 francois 481 #include "ot_boite_3d.h"
26 francois 283 #include <math.h>
27 francois 632 #include <algorithm>
28 francois 283
29    
30    
31     BOITE_3D::BOITE_3D(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):x(xmin),y(ymin),z(zmin),dx(xmax-xmin),dy(ymax-ymin),dz(zmax-zmin)
32     {
33 francois 954 bool recentrage=false;
34     if ((dx<0.0000001) && (dy<0.0000001) && (dz<0.0000001)) recentrage=true;
35 francois 950 if (dx<0.0000001)
36     {
37     dx=0.00000001;
38 francois 954 if (recentrage==true) x=x-dx/2.;
39 francois 950 }
40     if (dy<0.0000001)
41     {
42     dy=0.00000001;
43 francois 954 if (recentrage==true) y=y-dy/2.;
44 francois 950 }
45     if (dz<0.0000001)
46     {
47     dz=0.00000001;
48 francois 954 if (recentrage==true) z=z-dz/2.;
49 francois 950 }
50 francois 283 }
51    
52     BOITE_3D::BOITE_3D(void)
53     {
54     }
55    
56     void BOITE_3D::reinit(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
57     {
58     x=xmin;
59     y=ymin;
60     z=zmin;
61     dx=xmax-xmin;
62     dy=ymax-ymin;
63     dz=zmax-zmin;
64 francois 954 bool recentrage=false;
65     if ((dx<0.0000001) && (dy<0.0000001) && (dz<0.0000001)) recentrage=true;
66     if (dx<0.0000001)
67 francois 950 {
68     dx=0.00000001;
69 francois 954 if (recentrage==true) x=x-dx/2.;
70 francois 950 }
71     if (dy<0.0000001)
72     {
73     dy=0.00000001;
74 francois 954 if (recentrage==true) y=y-dy/2.;
75 francois 950 }
76     if (dz<0.0000001)
77     {
78     dz=0.00000001;
79 francois 954 if (recentrage==true) z=z-dz/2.;
80 francois 950 }
81 francois 283 }
82    
83     void BOITE_3D::reinit(BOITE_3D& boite)
84     {
85     x=boite.x;
86     y=boite.y;
87     z=boite.z;
88     dx=boite.dx;
89     dy=boite.dy;
90     dz=boite.dz;
91     }
92    
93     BOITE_3D::BOITE_3D(const BOITE_3D& mdd):x(mdd.x),y(mdd.y),z(mdd.z),dx(mdd.dx),dy(mdd.dy),dz(mdd.dz)
94     {
95     }
96    
97     BOITE_3D::BOITE_3D(BOITE_3D& mdd):x(mdd.x),y(mdd.y),z(mdd.z),dx(mdd.dx),dy(mdd.dy),dz(mdd.dz)
98     {
99     }
100    
101     BOITE_3D::~BOITE_3D()
102     {
103     }
104    
105     double BOITE_3D::get_xmin(void)
106     {
107     return x;
108     }
109    
110     double BOITE_3D::get_xmax(void)
111     {
112     return (x+dx);
113     }
114    
115     double BOITE_3D::get_ymin(void)
116     {
117     return y;
118     }
119    
120     double BOITE_3D::get_ymax(void)
121     {
122     return (y+dy);
123     }
124    
125     double BOITE_3D::get_zmin(void)
126     {
127     return z;
128     }
129    
130     double BOITE_3D::get_zmax(void)
131     {
132     return (z+dz);
133     }
134    
135 francois 632 /*BOITE_3D BOITE_3D::operator=(BOITE_3D& boite)
136 francois 283 {
137     x=boite.x;
138     y=boite.y;
139     z=boite.z;
140     dx=boite.dx;
141     dy=boite.dy;
142     dz=boite.dz;
143     return *this;
144 francois 632 }*/
145 francois 283 double BOITE_3D::get_rayon(void)
146     {
147     return (0.5*sqrt(dx*dx+dy*dy+dz*dz));
148     }
149    
150     void BOITE_3D::get_centre(double *coo)
151     {
152     coo[0]=x+dx*0.5;
153     coo[1]=y+dy*0.5;
154     coo[2]=z+dz*0.5;
155     }
156    
157     double BOITE_3D::get_xcentre(void)
158     {
159     return x+dx*0.5;
160     }
161    
162     double BOITE_3D::get_ycentre(void)
163     {
164     return y+dy*0.5;
165     }
166    
167     double BOITE_3D::get_zcentre(void)
168     {
169     return z+dz*0.5;
170     }
171    
172 couturad 913 double BOITE_3D::get_volume(void)
173     {
174     return(get_xmax()-get_xmin())*(get_ymax()-get_ymin())*(get_zmax()-get_zmin());
175     }
176    
177 francois 378 void BOITE_3D::change_grosseur(double f)
178     {
179     double centre[3];
180     get_centre(centre);
181     dx=dx*f;
182     dy=dy*f;
183     dz=dz*f;
184     reinit(centre[0]-dx/2.,centre[1]-dy/2.,centre[2]-dz/2.,centre[0]+dx/2.,centre[1]+dy/2.,centre[2]+dz/2.);
185     }
186 francois 283
187     int BOITE_3D::operator*(BOITE_3D& boite)
188     {
189     if ( x+dx>=boite.x)
190     if ( y+dy>=boite.y)
191     if ( z+dz>=boite.z)
192     if ( x<(boite.x+boite.dx))
193     if ( y<(boite.y+boite.dy))
194     if ( z<(boite.z+boite.dz))
195     return 1;
196     return 0;
197     }
198    
199 couturad 951
200     int BOITE_3D::get_intersection(BOITE_3D& boite)
201     {
202     if((boite.get_xmin()<=get_xmax() && boite.get_xmax()>=get_xmin()) || (get_xmin()<=boite.get_xmax() && get_xmax()>=boite.get_xmin()))
203     if((boite.get_ymin()<=get_ymax() && boite.get_ymax()>=get_ymin()) || (get_ymin()<=boite.get_ymax() && get_ymax()>=boite.get_ymin()))
204     if((boite.get_zmin()<=get_zmax() && boite.get_zmax()>=get_zmin()) || (get_zmin()<=boite.get_zmax() && get_zmax()>=boite.get_zmin())) return 1;
205     return 0;
206     }
207    
208    
209    
210 francois 945 int BOITE_3D::operator*(const BOITE_3D& boite)
211     {
212     if ( x+dx>=boite.x)
213     if ( y+dy>=boite.y)
214     if ( z+dz>=boite.z)
215     if ( x<(boite.x+boite.dx))
216     if ( y<(boite.y+boite.dy))
217     if ( z<(boite.z+boite.dz))
218     return 1;
219     return 0;
220     }
221    
222 couturad 951
223 francois 632 BOITE_3D operator&(const BOITE_3D& boite1,const BOITE_3D& boite2)
224     {
225     double xmin1=boite1.x;
226     double ymin1=boite1.y;
227     double zmin1=boite1.z;
228     double xmin2=boite2.x;
229     double ymin2=boite2.y;
230     double zmin2=boite2.z;
231     double xmax1=boite1.x+boite1.dx;
232     double ymax1=boite1.y+boite1.dy;
233     double zmax1=boite1.z+boite1.dz;
234     double xmax2=boite2.x+boite2.dx;
235     double ymax2=boite2.y+boite2.dy;
236     double zmax2=boite2.z+boite2.dz;
237     double xmin=std::max(xmin1,xmin2);
238     double ymin=std::max(ymin1,ymin2);
239     double zmin=std::max(zmin1,zmin2);
240     double xmax=std::min(xmax1,xmax2);
241     double ymax=std::min(ymax1,ymax2);
242     double zmax=std::min(zmax1,zmax2);
243     BOITE_3D tmp(xmin,ymin,zmin,xmax,ymax,zmax);
244     return tmp;
245     }
246    
247    
248     BOITE_3D operator+(const BOITE_3D& boite1,const BOITE_3D& boite2)
249     {
250     double xmin1=boite1.x;
251     double ymin1=boite1.y;
252     double zmin1=boite1.z;
253     double xmin2=boite2.x;
254     double ymin2=boite2.y;
255     double zmin2=boite2.z;
256     double xmax1=boite1.x+boite1.dx;
257     double ymax1=boite1.y+boite1.dy;
258     double zmax1=boite1.z+boite1.dz;
259     double xmax2=boite2.x+boite2.dx;
260     double ymax2=boite2.y+boite2.dy;
261     double zmax2=boite2.z+boite2.dz;
262     double xmin=std::min(xmin1,xmin2);
263     double ymin=std::min(ymin1,ymin2);
264     double zmin=std::min(zmin1,zmin2);
265     double xmax=std::max(xmax1,xmax2);
266     double ymax=std::max(ymax1,ymax2);
267     double zmax=std::max(zmax1,zmax2);
268     BOITE_3D tmp(xmin,ymin,zmin,xmax,ymax,zmax);
269     return tmp;
270     }
271 francois 283 int BOITE_3D::contient(double xx,double yy,double zz)
272     {
273     if (xx>=x)
274     if (yy>=y)
275     if (zz>=z)
276     if (xx<=x+dx)
277     if (yy<=y+dy)
278     if (zz<=z+dz)
279     return 1;
280    
281    
282     return 0;
283     }
284    
285    
286 couturad 926