Allink  v0.1
ForcesDraw.cpp
1 #include "Forces.h"
2 #ifdef __glut_h__
3 #include "../include/Draw.h"
4 Draw *Dr;
5 //OpenGL
6 int Forces::Graphics(int argc,char **argv){
7  Dr = new Draw();
8  for(int d=0;d<3;d++) Dr->Edge[d] = pEdge(d);
9  Dr->InvScaleUn = pInvEdge(0);
10  Dr->Window(argc,argv);
11  // Dr->xp = 0.;Dr->zp = 0.;
12  Dr->xa = -60.;Dr->ya = -00.;Dr->za = -38.;
13  Dr->xf = 160.;Dr->yf = -25.;Dr->zf = 0.;
14  Dr->xi = -.4;Dr->yi = -.4;Dr->zi = 0.;
15  for(int n=0;n<pNNano();n++){
16  Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
17  }
18  glutPostRedisplay();
19  glutMainLoop();
20  //Interp();
21 }
22 void Figure(){
23  //Dr->Draw1();
24  Dr->DFigure();
25  //Dr->DMinimal();
26 }
27 void ParticleRealTime(){
28  return ;
29  Dr->OpenImage("RadDistrNanoR1_0H0_4h32_0.tif");
30  glPopMatrix();
31  glRasterPos3d(-.35,-.4,-.32);
32  glPixelZoom(.5,.5);
33  glDrawPixels(Dr->ImWidth,Dr->ImHeight,GL_RGBA,GL_UNSIGNED_BYTE,Dr->pixel);
34  glPushMatrix();
35 }
36 void reshape(int w,int h){
37  Dr->Dreshape(w,h);
38 }
39 void Timer(int v){
40  Dr->DTimer(v);
41 }
42 void MouseMove(int x,int y){
43  Dr->DMouseMove(x,y);
44 }
45 void mouse(int button, int state,int x,int y){
46  Dr->Dmouse(button,state,x,y);
47 };
48 void special(int k, int x, int y){
49  Dr->Dspecial(k,x,y);
50 }
52  if(VAR_IF_TYPE(SysShape,SYS_2D) && !IfLine)
53  DrawCarpet();
54  else
55  DrawParticles();
56 }
58  double Num=0.;
59  Dr->Diap++;
60  Dr->tDiap=glutGet(GLUT_ELAPSED_TIME);
61  double Speed=25.;
62  double fps = Dr->Diap*1000.0/(Dr->tDiap-Dr->tDiapBase);
63  double Ratio = 0.;
64  double NRatio = 0.;
65  if (Dr->tDiap - Dr->tDiapBase > 1000) {
66  fprintf(stderr,"Frame per second %lf\r",fps);
67  Dr->tDiapBase = Dr->tDiap;
68  Dr->Diap = 0;
69  }
70  if(Dr->tDiap - Dr->tDiapBase > 1000/Speed){
71  for(int i=0;i<NUpdate;i++){
72  Dynamics();
73  //Interp();
74  if(VAR_IF_TYPE(CalcMode,CALC_NcVT))
75  Dr->Step += pNPCh()-1;
76  }
77  if(IfMovie && (pStep()%5)==0){
78  Dr->Step++;
79  Dr->Picture();
80  }
81  Dr->za += 1.;
82  CurrTime = time(NULL);
83  Ratio += Dr->Step/(1000.*(CurrTime-InitTime));
84  NRatio += 1.;
85  double v2 = 0.;
86  for(int p=0;p<pNPart();p++){
87  for(int d=0;d<3;d++){
88  v2 += SQR(pVel(p,d));
89  }
90  }
91  sprintf(Dr->info,"NPart %d loop/s %lf acc/step %lf in/out %lf T %lf Pot %lf",pNPart(),Ratio/NRatio,(NRemoval+NInsertion)/(double)pStep(),NInsertion/(double)NRemoval,v2/(double)(3*pNPart()),OldNrgSys);
92  DrawScene();
93  glutPostRedisplay();
94  glutTimerFunc(1000, Timer, 1);
95  }
96 }
98  if(!VAR_IF_TYPE(SysShape,SYS_ELECTRO)){
99  return;
100  }
101  glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
102  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
103  glEnable(GL_DEPTH_TEST);
104  glEnable(GL_LIGHT1);
105  glEnable(GL_LIGHTING);
106  double InvScaleUn = Dr->InvScaleUn;
107  int NBin = 30;
108  double InvNBin = 1./(double)NBin;
109  Vettore v1(3);
110  Vettore v2(3);
111  Vettore v3(3);
112  Vettore v4(3);
113  Vettore vN(3);
114  int Typ = 1;
115  for(int sx=0;sx<NBin-1;sx++){
116  for(int sy=0;sy<NBin-1;sy++){
117  v1.x[0] = sx*pEdge(0)*InvNBin;
118  v2.x[0] = (sx+1)*pEdge(0)*InvNBin;
119  v3.x[0] = (sx+1)*pEdge(0)*InvNBin;
120  v4.x[0] = (sx)*pEdge(0)*InvNBin;
121  v1.x[1] = sy*pEdge(1)*InvNBin;
122  v2.x[1] = (sy)*pEdge(1)*InvNBin;
123  v3.x[1] = (sy+1)*pEdge(1)*InvNBin;
124  v4.x[1] = (sy+1)*pEdge(1)*InvNBin;
125  v1.x[2] = .2*pEdge(2)*sin(6*v1.x[0]*pInvEdge(0))*sin(4*v1.x[1]*pInvEdge(1)) + .4*pEdge(2);
126  v2.x[2] = .2*pEdge(2)*sin(6*v2.x[0]*pInvEdge(0))*sin(4*v2.x[1]*pInvEdge(1)) + .4*pEdge(2);
127  v3.x[2] = .2*pEdge(2)*sin(6*v3.x[0]*pInvEdge(0))*sin(4*v3.x[1]*pInvEdge(1)) + .4*pEdge(2);
128  v4.x[2] = .2*pEdge(2)*sin(6*v4.x[0]*pInvEdge(0))*sin(4*v4.x[1]*pInvEdge(1)) + .4*pEdge(2);
129  for(int d=0;d<3;d++){
130  v1.x[d] *= InvScaleUn;
131  v2.x[d] *= InvScaleUn;
132  v3.x[d] *= InvScaleUn;
133  v4.x[d] *= InvScaleUn;
134  }
135  glColor4fv(ColorType[Typ]);
136  glLightfv(GL_LIGHT0, GL_AMBIENT,ColorType[Typ]);
137  glLightfv(GL_LIGHT1, GL_DIFFUSE,ColorType[Typ]);
138  glLightfv(GL_LIGHT1, GL_POSITION,ColorType[Typ]);
139  vN.Normalize();
140  glPushMatrix();//Particle
141  glBegin(GL_POLYGON);
142  vN = v1^v2;
143  glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
144  glVertex3d(v1.x[0],v1.x[1],v1.x[2]);
145  vN = v2^v3;
146  glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
147  glVertex3d(v2.x[0],v2.x[1],v2.x[2]);
148  vN = v3^v4;
149  glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
150  glVertex3d(v3.x[0],v3.x[1],v3.x[2]);
151  vN = v4^v1;
152  glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
153  glVertex3d(v4.x[0],v4.x[1],v4.x[2]);
154  glEnd();
155  glPopMatrix();//Particle
156  }
157  }
158  glDisable(GL_DEPTH_TEST);
159  glDisable(GL_LIGHT1);
160  glDisable(GL_LIGHTING);
161 }
163  if(!VAR_IF_TYPE(SysShape,SYS_2D)){
164  return;
165  }
166  glDeleteLists(Dr->Particles,1);
167  Dr->Particles = glGenLists(1);
168  glNewList(Dr->Particles,GL_COMPILE);
169  // glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
170  // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
171  // glEnable(GL_DEPTH_TEST);
172  glEnable(GL_LIGHT1);
173  glEnable(GL_LIGHTING);
174  //glFrontFace(GL_CCW);
175  //glShadeModel(GL_SMOOTH);
176  double InvScaleUn = Dr->InvScaleUn;
177  Vettore v1(3);
178  Vettore v2(3);
179  Vettore v3(3);
180  Vettore vN(3);
181  for(int sx=0;sx<nEdge[0]-1;sx++){
182  for(int sy=0;sy<nEdge[1]-1;sy++){
183  int pRight[3] = {sx*nEdge[1]+sy,(sx+1)*nEdge[1]+sy,(sx+1)*nEdge[1]+sy+1};
184  for(int d=0;d<3;d++){
185  v1.x[d] = pPos(pRight[0],d)*InvScaleUn;
186  v2.x[d] = pPos(pRight[1],d)*InvScaleUn;
187  v3.x[d] = pPos(pRight[2],d)*InvScaleUn;
188  }
189  int Typ = pType(sx*pNChain()+sy);
190  glColor4fv(ColorType[Typ]);
191  glLightfv(GL_LIGHT0, GL_AMBIENT,ColorType[Typ]);
192  glLightfv(GL_LIGHT1, GL_DIFFUSE,ColorType[Typ]);
193  //glLightfv(GL_LIGHT1, GL_POSITION,ColorType[Typ]);
194  //vN = v1^v2;
195  vN.x[0] = v1.x[1]*v2.x[2] - v1.x[2]*v2.x[1];
196  vN.x[1] = v1.x[2]*v2.x[0] - v1.x[0]*v2.x[2];
197  vN.x[2] = v1.x[0]*v2.x[1] - v1.x[1]*v2.x[0];
198  vN.Normalize();
199  glPushMatrix();//Particle
200  //glColor4f(.2,1.,.2,1.);
201  glBegin(GL_TRIANGLES);
202  glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
203  glVertex3d(v1.x[0],v1.x[1],v1.x[2]);
204  glVertex3d(v2.x[0],v2.x[1],v2.x[2]);
205  glVertex3d(v3.x[0],v3.x[1],v3.x[2]);
206  glEnd();
207  glPopMatrix();//Particle
208  int pLeft[3] = {sx*pNChain()+sy,(sx+1)*pNChain()+sy+1,sx*pNChain()+sy+1};
209  for(int d=0;d<3;d++){
210  v1.x[d] = pPos(pLeft[0],d)*InvScaleUn;
211  v2.x[d] = pPos(pLeft[1],d)*InvScaleUn;
212  v3.x[d] = pPos(pLeft[2],d)*InvScaleUn;
213  }
214  vN.x[0] = v1.x[1]*v2.x[2] - v1.x[2]*v2.x[1];
215  vN.x[1] = v1.x[2]*v2.x[0] - v1.x[0]*v2.x[2];
216  vN.x[2] = v1.x[0]*v2.x[1] - v1.x[1]*v2.x[0];
217  // vN = v1^v2;
218  vN.Normalize();
219  glPushMatrix();//Particle
220  //glColor4f(.2,.5,.2,1.);
221  glBegin(GL_TRIANGLES);
222  glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
223  glVertex3d(v1.x[0],v1.x[1],v1.x[2]);
224  glVertex3d(v2.x[0],v2.x[1],v2.x[2]);
225  glVertex3d(v3.x[0],v3.x[1],v3.x[2]);
226  glEnd();
227  glPopMatrix();//Particle
228  }
229  }
230  DrawNano();
231  glEndList();
232 }
234  double InvScaleUn = Dr->InvScaleUn;
235  double Diameter = .01;
236  glDeleteLists(Dr->Particles,1);
237  Dr->Particles = glGenLists(1);
238  glNewList(Dr->Particles,GL_COMPILE);
239  glDisable(GL_LIGHTING);
240  glLineWidth(3);
241  glPointSize(5);
242  for(int p=0,link=0;p<pNPart();p++){
243  float Red = Pm[p].Pos[2]*.5*pInvEdge(2);
244  int Typ = pType(p) < 6 ? pType(p) : 5;
245  glColor4f(Red*ColorType[Typ][0],ColorType[Typ][1],ColorType[Typ][2],1.);
246  //glColor4fv(ColorType[Typ]);
247  //Dr->Numera(Pm[p].Pos,p);
248  if(IfLine && Ln[p].NLink >0) DrBondLine(p);
249  if(Dr->IfPoint){
250  glPushMatrix();//Particle
251  //glBegin(GL_POINTS);
252  glTranslatef((GLfloat)(pPos(p,0)*InvScaleUn),
253  (GLfloat)(pPos(p,1)*InvScaleUn),
254  (GLfloat)(pPos(p,2)*InvScaleUn));
255  //else if(IfColour) glCallList(Quad);
256  int Typ = pType(p) < 6 ? pType(p) : 5;
257  glColor4fv(ColorType[Typ]);
258  if(!IfSphere) glCallList(Dr->Point);
259  else glutSolidSphere(Diameter,20,20);
260  glPopMatrix();//Particle
261  }
262  }
263  if(VAR_IF_TYPE(SysShape,SYS_LEAVES)){
264  glBegin(GL_LINES);
265  glColor4f(.7,.7,.0,1.);
266  glPushMatrix();//Line
267  glVertex3f(0.,.5,.6);
268  glVertex3f(1.,.5,.6);
269  glPopMatrix();//Line
270  glPushMatrix();//Line
271  glVertex3f(0.,.5,.4);
272  glVertex3f(1.,.5,.4);
273  glPopMatrix();//Line
274  glPushMatrix();//Line
275  glVertex3f((GLfloat)(pPos(0,0)*InvScaleUn),
276  (GLfloat)(pPos(0,1)*InvScaleUn),
277  (GLfloat)(pPos(0,2)*InvScaleUn));
278  glVertex3f((GLfloat)(pPos(NEdge-1,0)*InvScaleUn),
279  (GLfloat)(pPos(NEdge-1,1)*InvScaleUn),
280  (GLfloat)(pPos(NEdge-1,2)*InvScaleUn));
281  glPopMatrix();//Line
282  glPushMatrix();//Line
283  glVertex3f((GLfloat)(Pm[NEdge].Pos[0]*InvScaleUn),
284  (GLfloat)(Pm[NEdge].Pos[1]*InvScaleUn),
285  (GLfloat)(Pm[NEdge].Pos[2]*InvScaleUn));
286  glVertex3f((GLfloat)(Pm[2*NEdge-1].Pos[0]*InvScaleUn),
287  (GLfloat)(Pm[2*NEdge-1].Pos[1]*InvScaleUn),
288  (GLfloat)(Pm[2*NEdge-1].Pos[2]*InvScaleUn));
289  glPopMatrix();//Line
290  glEnd();
291  }
292  if(IfLine){
293  for(int p=0;p<NShow-1;p++){
294  //printf("%d (%lf %lf %lf)\n",p,Pl[p].Pos[0],Pl[p].Pos[1],Pl[p].Pos[2]);
295  if(Pl[p].Idx == NEdge-2) continue;
296  glPushMatrix();//Particle
297  glColor4f(1.,.0,.0,1.);
298  //glBegin(GL_POINTS);
299  glBegin(GL_LINES);
300  glVertex3f((GLfloat)(Pl[p].Pos[0]*InvScaleUn),
301  (GLfloat)(Pl[p].Pos[1]*InvScaleUn),
302  (GLfloat)(Pl[p].Pos[2]*InvScaleUn));
303  glVertex3f((GLfloat)(Pl[p+1].Pos[0]*InvScaleUn),
304  (GLfloat)(Pl[p+1].Pos[1]*InvScaleUn),
305  (GLfloat)(Pl[p+1].Pos[2]*InvScaleUn));
306  glEnd();
308 // glTranslatef((GLfloat)(Pl[p].Pos[0]*InvScaleUn),
309 // (GLfloat)(Pl[p].Pos[1]*InvScaleUn),
310 // (GLfloat)(Pl[p].Pos[2]*InvScaleUn));
311 // glCallList(Point);
312  glPopMatrix();//Particle
313  }
314  }
315  DrawNano();
316  DrawSoil();
317  glEndList();
318 }
319 void Forces::DrBondLine(int p){
320  double InvScaleUn = Dr->InvScaleUn;
321  if(pNLink()==0)return;
322  glDisable(GL_LIGHTING);
323  for(int l=0;l<Ln[p].NLink;l++){
324  int link = Ln[p].Link[l];
325  double Pos[3] = {pPos(link,0),pPos(link,1),pPos(link,2)};
326  double Mid[3];
327  int IfContinue = 1;
328  for(int d=0;d<3;d++){
329  double Bf = floor((pPos(p,d) - pPos(link,d))*pInvEdge(d)+.5)*pEdge(d);
330  if(fabs(Bf) > 0. & !PeriodicImage[d]) IfContinue = 0;
331  else Pos[d] += Bf;
332  Mid[d] = .5*(pPos(p,d)+Pos[d])*InvScaleUn;
333  }
334  //if(!IfContinue) continue;
335  glPushMatrix();//Line
336  glBegin(GL_LINES);
337  glColor4fv(ColorType[pType(p)]);
338  glVertex3d((pPos(p,0)*InvScaleUn),
339  (pPos(p,1)*InvScaleUn),
340  (pPos(p,2)*InvScaleUn));
341  glVertex3d(Mid[0],Mid[1],Mid[2]);
342  glColor4fv(ColorType[pType(link)]);
343  glVertex3d(Mid[0],Mid[1],Mid[2]);
344  glVertex3d(((Pos[0])*InvScaleUn),
345  ((Pos[1])*InvScaleUn),
346  ((Pos[2])*InvScaleUn));
347  glEnd();
348  glPopMatrix();//Line
349  }
350 }
352  glDisable(GL_LIGHTING);
353  for(int n=0;n<pNNano();n++){
354  if(Nano[n].Shape == 0) continue;
355  Vettore Ax(Nano[n].Axis[0],Nano[n].Axis[1],Nano[n].Axis[2]);
356  Vettore Zed(0.,0.,1.);
357  double Angle = Zed.Angle(&Ax,&Zed);
358  Quadri q(Ax.x,Angle);
359  Matrice M(q,4);
360  glPushMatrix();//Nano
361  glTranslated((pNanoPos(n,0)*Dr->InvScaleUn),
362  (pNanoPos(n,1)*Dr->InvScaleUn),
363  (pNanoPos(n,2)*Dr->InvScaleUn));
364  glColor4f( 1.,.1,.1,1.);
365  if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_SPH)){
366  glutSolidSphere(Nano[n].Rad,20,20);
367  }
368  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CYL)){
369  glCallList(Cylinder[n]);
370  }
371  glPopMatrix();//Nano
372  }
373 }
375  //submenu = glutCreateMenu(processEvent);
376  glutAddMenuEntry("SottoPrima",3);
377 
378  //menu = glutCreateMenu(processEvent);
379  glutAddMenuEntry("Move",1);
380  glutAddMenuEntry("Stop",2);
381  glutAddSubMenu("Altro",submenu);
382  glutAttachMenu(GLUT_RIGHT_BUTTON);
383 }
384 void Forces::keyboard(unsigned char key,int x, int y){
385  double StepDiameter = 0.01;
386  switch (key){
387  case 'a':
388  CreateInitial();
389  DrawScene();
390  glutPostRedisplay();
391  break;
392  case 'b':
393  IfLine += 1;
394  if(IfLine == 2) IfLine =0;
395  sprintf(Dr->info,"Bonding visualisation");
396  DrawScene();
397  glutPostRedisplay();
398  break;
399  case 'c':
400  IfExt++;
401  if(IfExt==0)
402  sprintf(Dr->info,"Increasing radius");
403  else if(IfExt==1)
404  sprintf(Dr->info,"Increasing height");
405  else if(IfExt==2)
406  sprintf(Dr->info,"Increasing angle");
407  else if(IfExt==3)
408  sprintf(Dr->info,"D^4 term");
409  else if(IfExt==4)
410  sprintf(Dr->info,"D^2 term");
411  else if(IfExt==5)
412  sprintf(Dr->info,"Elastic term");
413  else if(IfExt==6)
414  sprintf(Dr->info,"Moving center ->x");
415  else if(IfExt==7)
416  sprintf(Dr->info,"Moving center ->z");
417  else
418  IfExt = -1;
419  break;
420  case 'd':
421  if(IfExt == 0){
422  for(int n=0;n<pNNano();n++)
423  Nano[n].Rad += StepDiameter;
424  sprintf(Dr->info,"Nano->Rad %lf",Nano->Rad);
425  }
426  else if(IfExt == 1){
427  for(int n=0;n<pNNano();n++)
428  Nano[n].Height += StepDiameter;
429  sprintf(Dr->info,"Nano->Height %lf",Nano->Height);
430  }
431  else if(IfExt == 2){
432  for(int n=0;n<pNNano();n++)
433  Nano[n].Hamaker += 5.;
434  if(Nano->Hamaker >= 90.) Nano->Hamaker = 0.;
435  sprintf(Dr->info,"ExtAngle %lf",Nano->Hamaker);
436  }
437  else if(IfExt == 3){
438  Kf.SLap *= 10.;
439  sprintf(Dr->info,"D^4 %lf ratio %lf",Kf.SLap,pow(Kf.SLap/Kf.El[2],.25));
440  }
441  else if(IfExt == 4){
442  Kf.Lap += 1.;
443  sprintf(Dr->info,"D^2 %lf",Kf.Lap);
444  }
445  else if(IfExt == 5){
446  Kf.El[2] += 10.;
447  sprintf(Dr->info,"elastic %lf ratio %lf",Kf.El[2],pow(Kf.SLap/Kf.El[2],.25));
448  }
449  else if(IfExt == 6){
450  //for(int n=0;n<pNNano();n++)
451  Nano[0].Pos[0] += StepDiameter;
452  sprintf(Dr->info,"Nano->Pos x %lf",Nano->Pos[0]);
453  }
454  else if(IfExt == 7){
455  for(int n=0;n<pNNano();n++)
456  Nano[n].Pos[2] += StepDiameter;
457  sprintf(Dr->info,"Nano->Pos z %lf",Nano->Pos[2]);
458  }
459  for(int n=0;n<pNNano();n++)
460  Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
461  AddRigid();
462  IfFillMatrix = 1;
463  glutPostRedisplay();
464  break;
465  case 'D':
466  if(IfExt == 0){
467  for(int n=0;n<pNNano();n++)
468  Nano[n].Rad -= StepDiameter;
469  sprintf(Dr->info,"Rad %lf",Nano->Rad);
470  }
471  else if(IfExt == 1){
472  for(int n=0;n<pNNano();n++)
473  Nano[n].Height -= StepDiameter;
474  sprintf(Dr->info,"Height %lf",Nano->Height);
475  }
476  else if(IfExt == 2){
477  if(Nano->Hamaker < 0.) Nano->Hamaker = 0.;
478  Nano->Hamaker -= 5.;
479  sprintf(Dr->info,"ExtAngle %lf",Nano->Hamaker);
480  }
481  else if(IfExt == 3){
482  Kf.SLap /= 10.;
483  sprintf(Dr->info,"D^4 %lf ratio %lf",Kf.SLap,pow(Kf.SLap/Kf.El[2],.25));
484  }
485  else if(IfExt == 4){
486  Kf.Lap -= 1.;
487  sprintf(Dr->info,"D^2 %lf",Kf.Lap);
488  }
489  else if(IfExt == 5){
490  Kf.El[2] -= 10.;
491  sprintf(Dr->info,"elastic %lf ratio %lf",Kf.El[2],pow(Kf.SLap/Kf.El[2],.25));
492  }
493  else if(IfExt == 6){
494  //for(int n=0;n<pNNano();n++)
495  Nano[0].Pos[0] -= StepDiameter;
496  sprintf(Dr->info,"Nano->Pos x %lf",Nano->Pos[0]);
497  }
498  else if(IfExt == 7){
499  for(int n=0;n<pNNano();n++)
500  Nano[n].Pos[2] -= StepDiameter;
501  sprintf(Dr->info,"Nano->Pos z %lf",Nano->Pos[2]);
502  }
503  for(int n=0;n<pNNano();n++)
504  Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
505  AddRigid();
506  IfFillMatrix = 1;
507  glutPostRedisplay();
508  break;
509  case 'e':
510  IfSpline=1;
511  IfInterp++;
512  if(IfInterp == 7)
513  IfInterp = 0;
514  Interp();
515  //Dynamics();
516  //printf("IfInterp %d\n",IfInterp);
517  glutPostRedisplay();
518  break;
519  case 'I':
520  Info();
521  break;
522  case 'm':
523  //Menu();
524  Bead2Move++;
525  if(Bead2Move > pNPart()) Bead2Move = 0;
527  sprintf(Dr->info,"Part2Move %d",Bead2Move);
528  DrawScene();
529  glutPostRedisplay();
530  break;
531  case 'M':
532  Bead2Move--;
533  if(Bead2Move < 0) Bead2Move = pNPart();
535  sprintf(Dr->info,"Part2Move %d",Bead2Move);
536  DrawScene();
537  glutPostRedisplay();
538  break;
539  case 'o':
540  Dynamics();
541  DrawScene();
542  glutPostRedisplay();
543  break;
544  case 'O':
545  InitTime = time(NULL);
546  glutIdleFunc(DynamicsMotion);
547  break;
548  case 'r':
549  glutIdleFunc(NULL);
550  Dr->InitConstant();
551  sprintf(Dr->info,"initial configuration");
552  glutPostRedisplay();
553  break;
554  case 'R':
555  ReadConfDinamica(ConfFile);
556  IfFillMatrix = 1;
557  FillMatrix();
558  sprintf(Dr->info,"reload configuration");
559  glutPostRedisplay();
560  break;
561  case 'S':
562  Solve();
563  DrawScene();
564  glutPostRedisplay();
565  break;
566  case 't':
567  PullBead();
568  DrawScene();
569  glutPostRedisplay();
570  break;
571  case 'T':
572  PushBead();
573  //sprintf(info,"Perspective view");
574  DrawScene();
575  glutPostRedisplay();
576  break;
577  case 'u':
578  Dynamics();
579  DrawScene();
580  glutPostRedisplay();
581  break;
582  case 'v':
583  BeadType++;
585  if(BeadType >= 4)
586  BeadType = 0;
587  glutPostRedisplay();
588  break;
589  case 'V':
590  Pm[Bead2Move].Typ = 0;
591  glutPostRedisplay();
592  break;
593  case 'w':
594  VAR_REM_TYPE(SysType,VAR_SYS_TXVL);
595  VAR_ADD_TYPE(SysType,VAR_SYS_XVT);
596  SysFormat = VAR_SYS_TXVL;
597  SetNBlock(1);
598  Block[0].NChain = pNChain();
599  Block[0].InitIdx = 0;
600  Block[0].NPCh = pNPCh();
601  Block[0].EndIdx = pNPart();
602  sprintf(Block[0].Name,"GAS");
603  char FileName[60];
604  sprintf(FileName,"Trajectory%09d.dat",pStep());
605  Write(FileName);
606  break;
607  case 27:
608  exit(0);
609  break;
610  case 40:
611  break;
612  default:
613  break;
614  }
615  Dr->keyboardDraw(key);
616 }
618  if(!IfSpline) return 0;
619  if(IfInterp==FIT_SPLINE3){
621  sprintf(Dr->info,"Interpolating via Spline3 %d",NShow);
622  }
623  else if(IfInterp==FIT_SPLINE4){
625  sprintf(Dr->info,"Interpolating via Spline4 %d",NShow);
626  }
627  else if(IfInterp==FIT_PARAB2){
629  sprintf(Dr->info,"Interpolating via Parabola2 %d",NShow);
630  }
631  else if(IfInterp==FIT_CUBIC){
633  sprintf(Dr->info,"Interpolating via Cubic %d",NShow);
634  }
635  else if(IfInterp==FIT_FORTH){
637  sprintf(Dr->info,"Interpolating via Forth %d",NShow);
638  }
639  else if(IfInterp==FIT_BSPLINE){
641  sprintf(Dr->info,"Interpolating via BSpline %d",NShow);
642  }
643  else if(IfInterp==FIT_POLY){
645  sprintf(Dr->info,"Interpolating via %dth grade poly %d",pNPart()-1,NShow);
646  }
647  return 0;
648 }
649 #endif //__glut_h__
int InterSpline3(PART *PmIn, PART *PmOut, int NIn, int NOut)
third order spline
double InvScaleUn
Rescale the three orthogonal directions.
Definition: Draw.h:181
int pNLink()
Maximum number of bonds.
void keyboard(unsigned char key, int x, int y)
Additional key bindings.
Definition: ForcesDraw.cpp:384
void DMouseMove(int x, int y)
How the scene rotate (Camera view should be implemented)
Definition: DrawControl.cpp:63
void DrawNano()
Draws cylinder or spheres.
Definition: ForcesDraw.cpp:351
int NInsertion
Count accepted moves.
Definition: Forces.h:767
int InterSpline4(PART *PmIn, PART *PmOut, int NIn, int NOut)
forth order spline
void Dreshape(int w, int h)
Principal reshape function.
Definition: Draw.cpp:237
double pVel(int p, int d)
Return the velocity.
BLOCK * Block
Information for every block.
Definition: VarData.h:1054
LINKS * Ln
Array of linking between the particles.
Definition: VarData.h:1048
void AddRigid()
Add all rigid bodies as a boundary condition.
Draw provides the basic configuration of the openGL libraries used in every derived program...
Definition: Draw.h:15
void DrawCarpet()
Two dimensional surface.
Definition: ForcesDraw.cpp:162
NANO * Nano
Extra particle.
Definition: VarData.h:1044
double Normalize()
Normlizes a Vettore.
double Hamaker
Strength of the interaction.
Definition: VarData.h:447
bool Write(char *OutFile)
Writes a "system-file" or a "x y z" file".
double Lap
Prefactor of the Laplacian.
Definition: Forces.h:147
Geometrical operations on vectors.
Definition: MatematicaVect.h:9
int Diap
Number of frames.
Definition: Draw.h:228
void PullBead()
Move a particle.
void DFigure(void)
Definition of the scene on which the objects will be drawn.
Definition: DrawScene.cpp:35
void DrawScene()
Draw the scene.
Definition: ForcesDraw.cpp:51
int SetNBlock(int Val)
Set NBlock.
double Rad
Size.
Definition: VarData.h:445
double pInvEdge(int d)
Inverted xyzr edges of the simulation box.
Definition: VarData.h:920
double Height
Height of the cylinder.
Definition: VarData.h:449
void DrBondLine(int p)
Alternative drawing of the particle position.
Definition: ForcesDraw.cpp:319
int pType(int p)
Return the type.
double El[3]
Elastic force.
Definition: Forces.h:151
void Dynamics()
Sum up all the forces and update the positions.
Definition: ForcesLoop.cpp:20
void DrawSoil()
Two dimensional soil.
Definition: ForcesDraw.cpp:97
double Pos[3]
xyz Position of the particle
Definition: VarData.h:216
int IfInterp
If interpolates with the splines.
Definition: Forces.h:755
void Dspecial(int k, int x, int y)
Boh.
void FillMatrix()
Fill the entries of the interaction matrix.
Definition: Forces.cpp:270
int IfExt
Boh.
Definition: Forces.h:825
int Picture()
Write a tiff file of the data in pixel.
Definition: DrawFile.cpp:183
int NShow
Boh.
Definition: Forces.h:819
double * x
Where the data are stored.
int IfFillMatrix
If the matrix has to be changed.
Definition: Forces.h:763
int NRemoval
Count accepted moves.
Definition: Forces.h:769
void keyboardDraw(unsigned char key)
Combines the key with the functions.
int ImWidth
Width and height of the image.
Definition: Draw.h:153
int InitIdx
Initial particle position.
Definition: VarData.h:265
void CreateInitial()
Create an initial configuration and an appropriate force field.
Definition: ForcesCreate.cpp:2
int CalcMode
Calculation mode.
Definition: Forces.h:747
double Pos[3]
Position.
Definition: VarData.h:427
void DTimer(int v)
Not working.
Definition: Draw.cpp:144
int IfSpline
Boh.
Definition: Forces.h:827
void Info()
System&#39;s info.
Definition: Forces.cpp:564
double pNanoPos(int n, int d)
Return back folded nano position.
GLuint Point
Refers to the list of the point.
Definition: Draw.h:193
double pEdge(int d)
xyzr edges of the simulation box
Definition: VarData.h:918
int pNPCh()
Number of particle per chain.
GLuint * Cylinder
List referring the cylinder.
Definition: Forces.h:815
int DefCylinder(double Rad, double Height)
Cylinder.
int InterBSpline(PART *PmIn, PART *PmOut, int NIn, int NOut)
BSpline.
void PushBead()
Move a particle.
void InitConstant()
Initializes all the view constants.
void Menu()
Menu.
Definition: ForcesDraw.cpp:374
int NEdge
Number of particles per edge.
Definition: VarData.h:1084
int OpenImage(const char *FileName)
Open a image to be store in pixel.
Definition: DrawFile.cpp:180
KFORCES Kf
Prefactor of the forces.
Definition: Forces.h:779
int NUpdate
How many timesteps before redrawing.
Definition: Forces.h:773
int InterParab2(PART *PmIn, PART *PmOut, int NIn, int NOut)
Discontinous parabolas.
int SysShape
Shape of system.
Definition: Forces.h:745
int SysType
Contains the definition of the system.
Definition: VarData.h:1086
int IfPoint
Decides to draw points or spheres.
Definition: Draw.h:230
int InterPoly(PART *PmIn, PART *PmOut, int NIn, int nOut)
NIn-polynomian.
int pNNano()
Number of nanoparticles.
GLuint Particles
Refers to the list of the total position of the particles which will be generated in another program...
Definition: Draw.h:200
int nEdge[3]
Number of particle per edge.
Definition: Forces.h:743
int InterForth(PART *PmIn, PART *PmOut, int NIn, int NOut)
Discontinous forth degree.
int NPCh
particles per chain
Definition: VarData.h:259
Matrice computes the algebric operations on matrices.
int IfSphere
Visualize spheres or points.
Definition: Forces.h:831
int SysFormat
Contains the definition of the file format.
Definition: VarData.h:1088
int IfLine
Boh.
Definition: Forces.h:837
int Step
Current step for the picture&#39;s name.
Definition: Draw.h:244
void DrawParticles()
Alternative drawing of the particle position.
Definition: ForcesDraw.cpp:233
int IfMovie
Produce the images for the video.
Definition: Forces.h:821
int NChain
chains
Definition: VarData.h:263
GLfloat xa
Angles.
Definition: Draw.h:155
Quaternion class.
int Graphics(int argc, char **argv)
Initialize the scene.
Definition: ForcesDraw.cpp:6
int EndIdx
End particle position.
Definition: VarData.h:267
GLfloat xf
Orientation of the light.
Definition: Draw.h:155
double pPos(int p, int d)
Return back folded position.
int pNChain()
Number of chain.
double Angle(Vettore *u, Vettore *v)
Computes the angle between two Vetttore.
GLfloat xi
Position of the info string.
Definition: Draw.h:155
double Edge[3]
Box size.
Definition: Draw.h:262
int Interp()
Show interpolating lines.
Definition: ForcesDraw.cpp:617
int InterCubica(PART *PmIn, PART *PmOut, int NIn, int NOut)
Discontinous cubic.
char * info
Info line.
Definition: Draw.h:276
void Window(int argc, char **argv)
Initial definition of the window.
Definition: Draw.cpp:108
void SelectBead(int p)
Select a particle.
int ReadConfDinamica(char *File)
Read the config file.
Definition: Forces.cpp:585
void DynamicsView()
Idle function to run the dynamics.
Definition: ForcesDraw.cpp:57
PART * Pm
Particle information of all particle.
Definition: VarData.h:1046
int Typ
Type.
Definition: VarData.h:226
PART * Pl
Splines.
Definition: Forces.h:787
double SLap
Prefactor of the square laplacian.
Definition: Forces.h:149
GLubyte * pixel
Principal image (always allocated)
Definition: Draw.h:270
void Dmouse(int button, int state, int x, int y)
To launch the menu.
Definition: DrawControl.cpp:86
int Bead2Move
Bead to move.
Definition: Forces.h:737
int pStep()
Number of steps.
int pNPart()
Number of particle.
int BeadType
Boundary condition for a single particle.
Definition: Forces.h:833
void Solve()
Solve a system of four oder differential equation.
Definition: ForcesLoop.cpp:9
int NSpline
Total number of points for drawing a spline.
Definition: Forces.h:777