Allink  v0.1
ElPolyDraw.cpp
1 /***********************************************************************
2 ElPoly:This progam provide a graphical visualisation of the data
3 opend by VarData using openGL glut. The most important option are
4 the possibility of changing the backfold of the polymers with 'c',
5 see the subsequent file in the list with '>', see the bond with 'b'.
6 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it>
7 
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ***********************************************************************/
23 #include "ElPoly.h"
24 
25 #ifdef __glut_h__
26 Draw *Dr;
27 void Figure(){
28  //Dr->Draw1();
29  Dr->DFigure();
30 }
31 void reshape(int w,int h){
32  Dr->Dreshape(w,h);
33 }
34 void Timer(int v){
35  Dr->DTimer(v);
36 }
37 void MouseMove(int x,int y){
38  Dr->DMouseMove(x,y);
39 }
40 void special(int k, int x, int y){
41  Dr->Dspecial(k,x,y);
42 }
43 int ElPoly::Graphics(int argc,char **argv){
44  InvScaleUn = 1./pEdge(0);
45  Dr = new Draw();
46  for(int d=0;d<3;d++) Dr->Edge[d] = pEdge(d);
47  Dr->InvScaleUn = InvScaleUn;
48  Dr->xi = -.4;Dr->yi = -.4;Dr->zi = .0;
49  Dr->xp = 0.;Dr->yp = 0.;Dr->zp = 0.;
50  Dr->xa = 0.;Dr->ya = 0.;Dr->za = 0.;
51  Vicinanze = 0.;
52  Saturation = 1.;
53  // IfColour = 0;
54  // IfChains = 0;
55  Quad = 0;
56  Point = 0;
57  Cylinder = 0;
58  MetalCylinder = 0;
59  Hexagon = 0;
60  Cube = 0;
61  DrawOutput = EL_OPENGL;
62  Cylinder = (GLuint *)calloc(pNNano(),sizeof(GLuint));
63  sprintf(Block2Draw,"ALL");
64  Dr->Window(argc,argv);
65  CreateMenu();
69  for(int n=0;n<pNNano();n++){
70  Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
71  }
72  //Dr->Picture();exit(0);
73  glutPostRedisplay();
74  glutMainLoop();
75 }
77  //DrSurface();
78 }
79 int ElPoly::DrIntorno(int p,double Blue){
80  double Near = 0.;
81  double PreChain = 0.;
82  if(!IfIntorno||pType(p)==2)
83  Near = 0.;
84  else if(IfIntorno == 1){
85  Near = Ch[pChain(p)].Pos[3]*InvScaleUn;
86  if(PreChain != pChain(p)){
87  }
88  }
89  if(Near > Vicinanze)
90  return 1;
91  return 0;
92 }
93 void ElPoly::DrBondOpenGl(double *Pos1,double *Pos2,float *Color){
94  glColor4fv(Color);
95  glPushMatrix();//Line
96  glBegin(GL_LINES);
97  glVertex3d(Pos1[0],Pos1[1],Pos1[2]);
98  glVertex3d(Pos2[0],Pos2[1],Pos2[2]);
99  glEnd();
100  glPopMatrix();//Line
101 }
102 void ElPoly::DrBond(int p){
103  if(!pNLink())return;
104  double Pos1[3];
105  double Pos2[3];
106  for(int l=0;l<Ln[p].NLink;l++){
107  int link = Ln[p].Link[l];
108  for(int d=0;d<3;d++){
109  Pos1[d] = pPos(p,d)*InvScaleUn;
110  Pos2[d] = pPos(link,d)*InvScaleUn;
111  }
112  for(int d=0;d<3;d++){
113  if(Pos1[d] - Pos2[d] > .5*pEdge(d)*InvScaleUn){
114  Pos2[d] += pEdge(d)*InvScaleUn;
115  }
116  else if(Pos1[d] - Pos2[d] < -.5*pEdge(d)*InvScaleUn){
117  Pos2[d] -= pEdge(d)*InvScaleUn;
118  }
119  }
120  DrawBond(Pos1,Pos2,ColorType[pType(p)]);
121  }
122 }
124 #ifdef __glut_h__
125  if(DrawOutput == EL_OPENGL){
126  glDisable(GL_LIGHTING);
127  //glEnable(GL_LIGHTING);
128  glDeleteLists(Dr->Particles,1);
129  Dr->Particles = glGenLists(1);
130  if(pNPart() > 50000) NVisSkip = 2;
131  else if (pNPart() > 100000) NVisSkip = 4;
132  for(int n=0;n<pNNano();n++){
133  glDeleteLists(Cylinder[n],1);
134  Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
135  if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_WALL)){
136  glDeleteLists(GlWall,1);
137  GlWall = Dr->DefWall();
138  }
139  }
140  glNewList(Dr->Particles,GL_COMPILE);
141  glDisable(GL_LIGHTING);
145  else Draw_Bond = &ElPoly::DrBondNo;
146  }
147  else if(DrawOutput == EL_POVRAY){
148 #endif // __glut_h_
152  HeaderPovRay();
153  SigErr(DrawOutFile != NULL,"DrawOutFile already allocated, can't use the file");
154  char FName[60];
155  sprintf(FName,"PovSnap%05d.pov",pStep());
156  DrawOutFile = fopen(FName,"w");
157  int ImSize[2] = {1000,1000};
158  fprintf(DrawOutFile,"// POV 3.x input script : plot.pov\n// command: povray +W%d +H%d -I%s -O%s.tga +P +X +A +FT +C\n",ImSize[0],ImSize[1],FName,FName);
159  fprintf(DrawOutFile,"#if (version < 3.5)\n#error \"POV3DisplayDevice has been compiled for POV-Ray 3.5 or above.\\nPlease upgrade POV-Ray.\"\n#end\n");
160  fprintf(DrawOutFile,"#include \"PovHeader.inc\"\n");
161  fprintf(DrawOutFile,"// System \n");
162 #ifdef __glut_h__
163  }
164 #endif // __glut_h_
165 }
167 #ifdef __glut_h__
168  if(DrawOutput == EL_OPENGL){
169  glEndList();
170  }
171  else if(DrawOutput == EL_POVRAY){
172 #endif // __glut_h_
173  fprintf(DrawOutFile,"// End of POV-Ray 3.x generation\n");
174  fclose(DrawOutFile);
175 #ifdef __glut_h__
176  }
177 #endif // __glut_h_
178 }
180  int Typ = pType(p) < 6 ? pType(p) : 5;
181  //ColorType[Typ][0] = pVel(p,3);
182  glColor4fv(ColorType[Typ]);
183  glPushMatrix();//Particle
184  glBegin(GL_POINTS);
185  glVertex3f(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact);
186  glEnd();
187  glPopMatrix();//Particle
188 }
189 void ElPoly::DrCrossLinks(char *FileName){
190  FILE *FRead = fopen(FileName,"r");
191  if(FRead == NULL) return;
192  char cLine[STRSIZE];
193  int c1=0;
194  int c2=0;
195  glDisable(GL_LIGHTING);
196  glColor4f(.5,0.0,.4,1.0);
197  for(int k=0;!(fgets(cLine,STRSIZE,FRead)==NULL);k++){
198  fscanf(FRead,"%d %d\n",&c1,&c2);
199  glPushMatrix();//Line
200  glBegin(GL_LINES);
201  glVertex3d(pPos(c1,0)*InvScaleUn,
202  pPos(c1,1)*InvScaleUn,
203  pPos(c1,2)*InvScaleUn*ScaleFact);
204  double Pos[3] = {pPos(c2,0),pPos(c2,1),pPos(c2,2)};
205  for(int d=0;d<3;d++){
206  if(pPos(c1,d) - Pos[d] > .5*pEdge(d))
207  Pos[d] += pEdge(d);
208  else if(pPos(c1,d) - Pos[d] < -.5*pEdge(d))
209  Pos[d] -= pEdge(d);
210  }
211  glVertex3d(((Pos[0])*InvScaleUn),
212  ((Pos[1])*InvScaleUn),
213  ((Pos[2])*InvScaleUn*ScaleFact));
214  glEnd();
215  glPopMatrix();//Line
216  }
217 }
219  double Pos1[3];
220  double Pos2[3];
221  DrawFuncHeader();
222  for(int n=0;n<pNNano();n++) DrawNano(n);
223  glDisable(GL_LIGHTING);
224  DrCrossLinks("CrossLinks.dat");
225  for(int b=0,NPep=0,cOff=0,pOff=0;b<pNBlock();cOff+=pNChain(b++)){
226  if(strcmp(Block2Draw,"ALL")){
227  if(strcmp(Block[b].Name,Block2Draw) ){
228  pOff += pNChain(b)*pNPCh(b);
229  continue;
230  }
231  }
232  if(!strncmp(Block[b].Name,"PEP",3)){
233  DrProtein(Nano[NPep].ArchFile,b);
234  NPep++;
235  continue;
236  }
237  for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){
238  int Chc = Ch[pChain(p)].Type;
239  if(!CHAIN_IF_TYPE(Chc,NChType)) continue;
240  if(NPType != BEAD_EVERY && pType(p) != NPType) continue;
241  // if(Pm[p].CId != 3) continue;
242  // Dr->Numera(Pm[p].Pos,p);
243  DrawPart(p);
244  DrBond(p);
245  }
246  // for(int c=cOff;c<cOff+pNChain(b);c+=NVisSkip,pOff+=pNPCh(b)*NVisSkip){
247  // for(int p=pOff,link=0;p<MIN(pOff+pNPCh(b),pNPart());p++){
248  // int Chc = Ch[pChain(p)].Type;
249  // if(!CHAIN_IF_TYPE(Chc,NChType)) continue;
250  // DrawPart(p);
251  // DrBond(p);
252  // }
253  // }
254  }
255  DrawFuncFooter();
256 }
258  if(Dr->IfMaterial){
259  glEnable(GL_LIGHTING);
260  glEnable( GL_LIGHT0 );
261  }
262  else
263  glDisable(GL_LIGHTING);
264  Point2Shape(Nano[n].Shape);
265  double Red = fabs(Nano[n].Hamaker)/3.;
266  double Alpha = 1.;//Nano[n].Hamaker/10.;
267  GLfloat Color[4] = {Red,.1,.1,Alpha};
268  glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color);
269  glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color);
270  glColor4fv(Color);
271  if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_NONE)) return;
272  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CLUSTER)){
273  Alpha = .2;
274  DrProtein(Nano[n].ArchFile,Nano[n].nBlock);
275  return;
276  }
277  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_JANUS)){
278  // Point2Shape(Nano[n].Shape);
279  // DrField(64,Nano[n].Rad,n);
280  // continue;
281  }
282  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_PORE)){
283  PorePos();
284  }
285  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CYL)){
286  // Point2Shape(Nano[n].Shape);
287  // DrField(64,SQR(Nano[n].Rad),n);
288  // continue;
289  }
290  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_TIP)){
291  DrField(32,SQR(Nano[n].Rad),n);
292  return;
293  }
294  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_BOUND)){
295  DrField(32,SQR(Nano[n].Rad),n);
296  return;
297  }
298  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_TORUS)){
299  double OldPos[5] = {Nano->Pos[0],Nano->Pos[1],Nano->Pos[2],Nano->Rad,Nano->Height};
300  //StalkPos(OldPos);
301  DrField(64,SQR(Nano[n].Rad),n);
302  return;
303  }
304  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_STALK)){
305  DrField(64,SQR(Nano[n].Rad),n);
306  return;
307  }
308  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_HARM)){
309  DrField(64,SQR(Nano[n].Rad),n);
310  return;
311  }
312  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_WALL)){
313  DrField(16,SQR(Nano[n].Rad),n);
314  return;
315  }
316  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_UMBR)){
317  glPushMatrix();//Nano
318  glBegin(GL_QUADS);
319  glNormal3f(0.,0.,-1.);
320  glVertex3f(0.,0.,Nano[n].Pos[CNorm]*InvScaleUn);
321  glVertex3f(0.,pEdge(1)*InvScaleUn,Nano[n].Pos[CNorm]*InvScaleUn);
322  glVertex3f(pEdge(0)*InvScaleUn,pEdge(1)*InvScaleUn,Nano[n].Pos[CNorm]*InvScaleUn);
323  glVertex3f(pEdge(0)*InvScaleUn,0.,Nano[n].Pos[CNorm]*InvScaleUn);
324  glEnd();//GL_QUADS
325  glPopMatrix();//Nano
326  return;
327  }
328  Vettore Ax(Nano[n].Axis[0],Nano[n].Axis[1],Nano[n].Axis[2]);
329  Vettore Zed(0.,0.,1.);
330  Vettore Axis(3);
331  Ax.Normalize();
332  Axis.VetV(&Zed,&Ax);
333  double Angle = Zed.Angle(&Ax,&Zed);
334  //Quadri q(Axis.x,Angle);
335  //double data[16];
336  //q.RotMatrix(data,4);
337  //Matrice M(q,4);
338  Matrice M(Axis.x,Angle,4);
339  glPushMatrix();//Nano
340  glTranslated((pNanoPos(n,0)*InvScaleUn),
341  (pNanoPos(n,1)*InvScaleUn),
342  (pNanoPos(n,2)*InvScaleUn*ScaleFact));
343  glMultMatrixd(M.data);
344  //glRotatef(Angle*DEG_RAD,Axis.x[0],Axis.x[1],Axis.x[2]);
345  //glCallList(Cylinder[n]);
346  if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_SPH)){
347  glutSolidSphere(Nano[n].Rad*InvScaleUn,20,20);
348  }
349  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_EXT)){
350  glColor4f(Red,.1,.1,.5);
351  glCallList(Cylinder[n]);
352  }
353  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_PORE)){
354  glColor4f(Red,.1,.1,.5);
355  glCallList(Cylinder[n]);
356  }
357  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_JANUS)){
358  glCallList(Cylinder[n]);
359  }
360  else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CYL)){
361  glCallList(Cylinder[n]);
362  }
363  else{
364  glCallList(Cylinder[n]);
365  }
366  glPopMatrix();//Nano
367  return;
368  Red = fabs(Nano[n].Hamaker)/3.;
369  if(!VAR_IF_TYPE(Nano[n].Shape,SHAPE_WALL))return;
370  glDisable(GL_LIGHTING);
371  // double x = (pNanoPos(n,0) - .5*pEdge(0))*InvScaleUn;
372  // double y = (pNanoPos(n,1) - .5*pEdge(1))*InvScaleUn;
373  // double z = (pNanoPos(n,2))*InvScaleUn*ScaleFact;
374  double x = pNanoPos(n,0)*InvScaleUn;
375  double y = pNanoPos(n,1)*InvScaleUn;
376  double z = pNanoPos(n,2)*InvScaleUn*ScaleFact;
377  //Quadri q(Axis.x,Angle);
378  //double data[16];
379  //q.RotMatrix(data,4);
380  //Matrice M(q,4);
381  glPushMatrix();//Nano
382  glTranslated(x,y,z);
383  glMultMatrixd(M.data);
384  glCallList(GlWall);
385  glPopMatrix();//Nano
386  // glPushMatrix();//Nano
387  // glTranslated(x,y,z);
388  // //glCallList(GlWall);
389  // glPopMatrix();//Nano
390 }
391 void ElPoly::DrProtein(const char *ArchFile,int b){
392  glDisable(GL_LIGHTING);
393  FILE *Arch = fopen(ArchFile,"r");
394  if(Arch == NULL) {printf("File %s not present \n",ArchFile);return;}
395  char cLine[STRSIZE];
396  double Pos1[3];
397  double Pos2[3];
398  double Mid[3];
399  int l1 = 0;
400  int l2 = 0;
401  double Elong = 0.;
402  double Alpha = 1.;
403  for(int p=Block[b].InitIdx;fgets(cLine,STRSIZE,Arch);p++){
404  DrawPart(p);
405  sscanf(cLine,"%d %d %lf %lf\n",&l1,&l2,&Elong,&Alpha);
406  l1 += Block[b].InitIdx;
407  l2 += Block[b].InitIdx;
408  if(l1 == l2) continue;
409  for(int d=0;d<3;d++){
410  Pos1[d] = pPos(l1,d)*InvScaleUn;
411  Pos2[d] = pPos(l2,d)*InvScaleUn;
412  Pos2[d] += floor((pPos(l1,d) - pPos(l2,d))*pInvEdge(d)+.5)*pEdge(d)*InvScaleUn;
413  Mid[d] = .5*(Pos1[d]+Pos2[d]);
414  }
415  DrawBond(Pos1,Mid,ColorType[pType(l1)]);
416  DrawBond(Mid,Pos2,ColorType[pType(l2)]);
417  }
418  fclose(Arch);
419 }
421  glDisable(GL_LIGHTING);
422  GLuint Cube = Dr->DefCube(NEdge);
423  glDeleteLists(Dr->Particles,1);
424  Dr->Particles = glGenLists(1);
425  glNewList(Dr->Particles,GL_COMPILE);
426  if(1==0){
427  glPushMatrix();//RefPoint
428  double RefPos[3] = {(ShiftPos[0]+.5)*pEdge(0),(ShiftPos[1]+.5)*pEdge(1),(ShiftPos[2]+.5)*pEdge(2)};
429  glTranslated((RefPos[0]*InvScaleUn),
430  (RefPos[1]*InvScaleUn),
431  (RefPos[2]*InvScaleUn*ScaleFact));
432  glColor4f( .7,.1,.1,1.);
433  glutSolidSphere(0.1,20,20);
434  glPopMatrix();//RefPos
435  }
436  int NDrawn = 0;
437  for(int p=0,link=0;p<pNPart();p++){
438  double Red = pVel(p,0)/pVelMax(0)*Saturation;
439  if(Red < 0.) Red = -Red;
440  double Green = pVel(p,1)/pVelMax(1);
441  double Blue = pVel(p,2)/pVelMax(2);
442  //if(Red < .3) continue;
443  double Alpha = 1.;//Pm[p].Vel[3]/pVel(3);
444  double Add = 1./(double)NEdge/3.;
445  if(1==0){
446  if(Green > .1){
447  glColor4f(0.,Green,0.,Alpha);
448  glPushMatrix();//Cube
449  glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact);
450  glCallList(Cube);
451  glPopMatrix();//Cube
452  }
453  if(Blue > .1){
454  glColor4f(0.,0.,Blue,Alpha);
455  glPushMatrix();//Cube
456  glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,(pPos(p,2)*InvScaleUn+Add)*ScaleFact);
457  glCallList(Cube);
458  glPopMatrix();//Cube
459  }
460  if(Red > .1){
461  glColor4f(Red,0.,0.,Alpha);
462  glPushMatrix();//Cube
463  glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,(pPos(p,2)*InvScaleUn+Add*2.)*ScaleFact);
464  glCallList(Cube);
465  glPopMatrix();//Cube
466  }
467  }
468  else{
469  if(Green + Blue + Red> .01)
470  {
471  glColor4f(Red,Green,Blue,Alpha);
472  glPushMatrix();//Cube
473  glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact);
474  glCallList(Cube);
475  glPopMatrix();//Cube
476  }
477  }
478  }
479  glEndList();
480 }
482  glDisable(GL_LIGHTING);
483  glDeleteLists(Dr->Particles,1);
484  Dr->Particles = glGenLists(1);
485  glNewList(Dr->Particles,GL_COMPILE);
486  ShiftRef(BF_CHAIN);
487  Vettore Freccia(pEdge(0)*InvScaleUn,0.,0.);
488  Vettore Axis(3);
489  Vettore ChDir(3);
490  Vettore ChPos(3);
491  Vettore Ax0(1,0,0);
492  Vettore Ax1(0,1,0);
493  Vettore Ax2(0,0,1);
494  for(int b=0,c1=0,NPep=0;b<pNBlock();c1+=Block[b++].NChain){
495  if(strcmp(Block2Draw,"ALL")){
496  if(strcmp(Block[b].Name,Block2Draw) ) continue;
497  }
498  if(!strncmp(Block[b].Name,"PEP",3)){
499  //DrProtein(Nano[++NPep].ArchFile,b);
500  continue;
501  }
502  // if(strncmp(Block[b].Name,"TT",2))continue;
503  for(int c=c1;c<c1+pNChain(b);c++){
504  if(!CHAIN_IF_TYPE(c,NChType)) continue;
505  for(int d=0;d<3;d++){
506  ChDir.Set(Ch[c].Dir[d]*InvScaleUn,d);
507  ChPos.Set((Ch[c].Pos[d]-Ch[c].Dir[d]*.5)*InvScaleUn,d);
508  }
509  double Red = Ch[c].Angle/M_PI;
510  double Green = 1.-Red;//Ax2.Angle(&Ax1,&ChDir)/M_PI;
511  double Blue = 0.;//sin(Ax0.Angle(&Ax2,&ChDir))-Green;
512  double Alpha = 1.;
513  if(Red > 0.35 && Red < .65);
514  // else Blue = 0.;
515  else continue;
516  glColor4f(Red,Green,Blue,Alpha);
517  glPushMatrix();//Arrow
518  double Length1 = ChDir.Norm();
519  double Length2 = Freccia.Norm();
520  for(int d=0;d<3;d++){
521  Axis.Set(.5*(ChDir.Val(d)/Length1+Freccia.Val(d)/Length2),d);
522  }
523  glTranslated(ChPos.Val(0),ChPos.Val(1),ChPos.Val(2));
524  glRotatef(180.,Axis.Val(0),Axis.Val(1),Axis.Val(2));
525  glScaled(Length1/Length2,1.0,1.0);
526  glNormal3f(ChDir.Val(0),ChDir.Val(1),ChDir.Val(2));
527  glCallList(Arrow);
528  glPopMatrix();//Arrow
529  int p1 = c*pNPCh();
530  for(int ppc=0;ppc<pNPCh();ppc++){
531  int p = ppc+p1;
532  DrawPart(p);
533  if(IfLine) DrBond(p);
534  }
535  }
536  }
537  glEndList();
538 }
540  glDisable(GL_LIGHTING);
541  glPushMatrix();//Arrow
542  Vettore Freccia(pEdge(0)*InvScaleUn,0.,0.);
543  Vettore Axis(3);
544  double Length1 = v.Norm();
545  double Length2 = Freccia.Norm();
546  for(int d=0;d<3;d++){
547  Axis.Set(d,.5*(v[d]/Length1 + Freccia[d]/Length2));
548  }
549  glTranslated(Origin[0],Origin[1],Origin[2]);
550  glRotatef(180.,Axis[0],Axis[1],Axis[2]);
551  glScaled(Length1/Length2,1.0,1.0);
552  glNormal3f(v[0],v[1],v[2]);
553  glCallList(Arrow);
554  glPopMatrix();//Arrow
555 }
557  glDisable(GL_LIGHTING);
558  double Values=200.;
559  glDeleteLists(Dr->Particles,1);
560  Dr->Particles = glGenLists(1);
561  glNewList(Dr->Particles,GL_COMPILE);
562  Folding();
563  for(int c=0;c<pNChain();c++){
564  //Numera(Ch[c].Pos,c);
565  int Chc = Ch[c].Type;
566  if(!CHAIN_IF_TYPE(Chc,NChType)) continue;
567  double Red = 0.;
568  if(CHAIN_IF_TYPE(Chc,CHAIN_UP))
569  Red = 1.;
570  double Blue=0.;
571  if(CHAIN_IF_TYPE(Chc,CHAIN_FLABBY))
572  Blue =1.;
573  double Green=.7;
574  if(CHAIN_IF_TYPE(Chc,CHAIN_TILTED))
575  Green =.5;
576  glPushMatrix();
577  glTranslatef((GLfloat)(Ch[c].Pos[0]*InvScaleUn),
578  (GLfloat)(Ch[c].Pos[1]*InvScaleUn),
579  (GLfloat)(Ch[c].Pos[2]*InvScaleUn*ScaleFact));
580  glColor4f(Red,Green,Blue,1.);
581  glCallList(Hexagon);
582  glPopMatrix();
583  }
584  glEndList();
585  return ;
586  double Unity= 1./(double)Values*pEdge(0)*InvScaleUn;
587  double *dDensity;
588  dDensity = (double *)calloc(Values,sizeof(double));
589  PairCorrelation(dDensity,Values,1,CHAIN_UP);
590  double Max=0.;
591  for(int v=0;v<Values;v++){
592  if(Max < dDensity[v]){
593  Max = dDensity[v];
594  }
595  }
596  for(int v=0;v<Values;v++){
597  dDensity[v] /= Max;
598  }
599  for(int v=0;v<Values-1;v++){
600  glPushMatrix();
601  glBegin(GL_LINES);
602  glColor4f(1.,0.,1.,1.);
603  glVertex3d((Values-v)*Unity,pEdge(1)*InvScaleUn,dDensity[v]);
604  glVertex3d((Values-(v+1))*Unity,pEdge(1)*InvScaleUn,dDensity[v+1]);
605  glEnd();
606  glPopMatrix();
607  }
608  glEndList();
609  free(dDensity);
610 }
611 //obsolete?
613  glDisable(GL_LIGHTING);
614  glDeleteLists(Dr->Particles,1);
615  Dr->Particles = glGenLists(1);
616  glNewList(Dr->Particles,GL_COMPILE);
617  glPointSize(3);
618  glLineWidth(3);
619  for(int p=0,link=0;p<pNPart();p++){
620  glColor4f(pVel(p,0)/pVelMax(0),pVel(p,1)/pVelMax(1),pVel(p,2)/pVelMax(2),pVel(p,3)/pVelMax(3));
621  if(pType(p) == 2){
622  glPushMatrix();//Particle
623  glTranslated((pPos(p,0)*InvScaleUn),
624  (pPos(p,1)*InvScaleUn),
625  (pPos(p,2)*InvScaleUn*ScaleFact));
626  glColor4f( 1.,.1,.1,1.);
627  if(Nano->Shape == SHAPE_CYL)
628  glCallList(Cylinder[0]);
629  else
630  glutSolidSphere(Nano->Rad*InvScaleUn,20,20);
631  glPopMatrix();//Particle
632  }
633  else{
634  glPushMatrix();//Particle
635  glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact);
636  glCallList(Cube);
637  glPopMatrix();//Particle
638  }
639  }
640  glEndList();
641 }
643  glDisable(GL_LIGHTING);
644  glDeleteLists(Dr->Particles,1);
645  Dr->Particles = glGenLists(1);
646  glNewList(Dr->Particles,GL_COMPILE);
647  glPointSize(3);
648  glLineWidth(3);
649  for(int p=0,link=0;p<pNPart();p++){
650  int Chc = Ch[pChain(p)].Type;
651  if(!CHAIN_IF_TYPE(Chc,NChType) && pType(p)!=2) continue;
652  int Typ = pType(p) < 6 ? pType(p) : 5;
653  glColor4fv(ColorType[Typ]);
654  if(IfLine){
655  glColor4f(0.0,1.0,0.,1.0);
656  for(int l=0;l<Ln[p].NLink;l++){
657  link = Ln[p].Link[l];
658  double Shift[3] = {0.,0.,0.};
659  if(link != p+1){
660  glColor4f(1.0,.0,0.,1.0);
661  for(int d=0;d<3;d++)
662  Shift[d] = -floor((pPos(p,d)-pPos(link,d))/pEdge(d)+.5)*pEdge(d);
663  }
664  else continue;
665  glPushMatrix();//Line
666  glBegin(GL_LINES);
667  glVertex3d((pPos(p,0)*InvScaleUn),
668  (pPos(p,1)*InvScaleUn),
669  (pPos(p,2)*InvScaleUn*ScaleFact));
670  glVertex3d(((pPos(link,0)-Shift[0])*InvScaleUn),
671  ((pPos(link,1)-Shift[1])*InvScaleUn),
672  ((pPos(link,2)-Shift[2])*InvScaleUn*ScaleFact));
673  glEnd();
674  glPopMatrix();//Line
675  }
676  }
677  glPushMatrix();//Particle
678  glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn);
679  //glutSolidSphere(.007,20,20);
680  glCallList(Point);
681  glPopMatrix();//Particle
682  }
683  glEndList();
684 }
686  // submenu = glutCreateMenu(processEvent);
687  // glutAddMenuEntry("SottoPrima",3);
688 
689  // menu = glutCreateMenu(processEvent);
690  // glutAddMenuEntry("Move",1);
691  // glutAddMenuEntry("Stop",2);
692  // glutAddSubMenu("Altro",submenu);
693  // glutAttachMenu(GLUT_RIGHT_BUTTON);
694 }
695 void ElPoly::ESlide1(void){
696  // if(Dr->Step > 100) glutIdleFunc(NULL);
697  Dr->zw += .1;
698  Dr->IfInfo = 0;
699  glutPostRedisplay();
700  Dr->Step++;
701  Dr->Picture();
702  Dr->IfInfo = 1;;
703  //Dr->Picture();
704  //glutTimerFunc(30, Timer, 0);
705 }
706 void ElPoly::ESlide(void){
707  Dr->IfInfo = 0;
708  glutPostRedisplay();
709  if(quando < NFileTot)
710  quando++;
711  //quando += 10;
712  else{
713  glutIdleFunc(NULL);
714  }
715  OpenFile(quando);
716  RenderPart();
717  Dr->Step++;
718  Dr->Picture();
719  glutPostRedisplay();
720  Dr->IfInfo = 1;
721  //glutTimerFunc(30, Timer, 0);
722 }
723 #endif //__glut_h__
GLfloat xp
Translation, wheel.
Definition: Draw.h:155
double InvScaleUn
Rescale the three orthogonal directions.
Definition: Draw.h:181
CHAIN * Ch
Information on all chains.
Definition: VarData.h:1050
int pNLink()
Maximum number of bonds.
double Vicinanze
Boh.
Definition: ElPoly.h:455
void RenderPart(void)
Choose the visualisation (obsolete)
void DMouseMove(int x, int y)
How the scene rotate (Camera view should be implemented)
Definition: DrawControl.cpp:63
int IfInfo
Removes the info line.
Definition: Draw.h:232
double InvScaleUn
Define the shrink factor between the box edges.
Definition: ElPoly.h:457
void Menu()
Creates the menu.
Definition: ElPolyDraw.cpp:685
void DrRunTime()
Draws in run time (expensive)
Definition: ElPolyDraw.cpp:76
void Dreshape(int w, int h)
Principal reshape function.
Definition: Draw.cpp:237
int Type
Type of the chain (see list CHAIN_)
Definition: VarData.h:246
double pVel(int p, int d)
Return the velocity.
void DrBondNo(double *Pos1, double *Pos2, float *Color)
Null function.
Definition: ElPoly.h:324
BLOCK * Block
Information for every block.
Definition: VarData.h:1054
void DrNanoOpenGl(int n)
OpenGl draw function.
Definition: ElPolyDraw.cpp:257
int NFileTot
Total number of file.
Definition: ElPoly.h:420
int Graphics(int argc, char **argv)
Boh.
Definition: ElPolyDraw.cpp:43
LINKS * Ln
Array of linking between the particles.
Definition: VarData.h:1048
Draw provides the basic configuration of the openGL libraries used in every derived program...
Definition: Draw.h:15
double Norm()
Return the norm of a Vettore.
double ShiftPos[3]
Reference position.
Definition: VarData.h:1058
NANO * Nano
Extra particle.
Definition: VarData.h:1044
double Normalize()
Normlizes a Vettore.
int OpenFile(int f)
Opens the f file of the list open.
Definition: ElPolyEl.cpp:147
int pChain(int p)
Return the chain.
Geometrical operations on vectors.
Definition: MatematicaVect.h:9
void DFigure(void)
Definition of the scene on which the objects will be drawn.
Definition: DrawScene.cpp:35
char cWhat2Draw[STRSIZE]
What to draw.
Definition: VarData.h:1042
void ElMenuVisual(int option)
Choose what to visualize.
DRAW_PART Draw_Nano
Pointer to a distance.
Definition: ElPoly.h:306
double Rad
Size.
Definition: VarData.h:445
int quando
Current number of the file list.
Definition: ElPoly.h:424
double pInvEdge(int d)
Inverted xyzr edges of the simulation box.
Definition: VarData.h:920
int DefCube(int NSquare)
Cube.
double Height
Height of the cylinder.
Definition: VarData.h:449
int NChType
Type of chain selected.
Definition: VarData.h:1080
void ESlide1()
Sequence of pictures.
Definition: ElPolyDraw.cpp:695
int pType(int p)
Return the type.
void DrProtein(const char *FileName, int nBlock)
Load and draw the linking of a protein.
Definition: ElPolyDraw.cpp:391
void Dspecial(int k, int x, int y)
Boh.
void CreateMenu()
Creates the menu.
double Val(int N)
Value of the N column.
int Picture()
Write a tiff file of the data in pixel.
Definition: DrawFile.cpp:183
double * x
Where the data are stored.
double ScaleFact
Normal scaling factor (z zooming)
Definition: ElPoly.h:461
void DrPartPovRay(int p)
PovRay draw function.
int InitIdx
Initial particle position.
Definition: VarData.h:265
int Angle(int NBin)
Calculation of the contact angle angle Boh?
Definition: ElPolyEl.cpp:78
double Pos[3]
Position.
Definition: VarData.h:427
void DTimer(int v)
Not working.
Definition: Draw.cpp:144
void DrBondPovRay(double *Pos1, double *Pos2, float *Color)
Draw the bonds.
int Shape
0 none, 1 spherical, 2 cylindrical 3 wall
Definition: VarData.h:473
double pNanoPos(int n, int d)
Return back folded nano position.
double pEdge(int d)
xyzr edges of the simulation box
Definition: VarData.h:918
void HeaderPovRay()
Print the header for povray.
int pNPCh()
Number of particle per chain.
double Saturation
Saturation of the color (increase intensity)
Definition: ElPoly.h:388
double PorePos()
Find the position of the pore.
int NPType
Type of particle selected.
Definition: VarData.h:1082
int DefCylinder(double Rad, double Height)
Cylinder.
int Folding()
Boh...
Definition: VarDataEl.cpp:302
int pNBlock()
Number of blocks.
void DrPartList()
Create a list of all the particles.
Definition: ElPolyDraw.cpp:218
int NEdge
Number of particles per edge.
Definition: VarData.h:1084
void DrawNano(int n)
Pointer to a generic function.
Definition: ElPoly.h:308
int IfMaterial
Activate the illumination for a specific material.
Definition: Draw.h:240
void DrBond(int p)
Finde the neighbour of the particle p and draw the bond.
Definition: ElPolyDraw.cpp:102
void Point2Shape(int iShape)
Point to the shape function.
Definition: VarDataEl.cpp:490
FILE * DrawOutFile
Output file for drawing.
Definition: ElPoly.h:463
void DrawFuncFooter()
Dnd the visualization.
Definition: ElPolyDraw.cpp:166
void ShiftRef(int BackFold)
Backfold the system wrt the reference position.
int pNNano()
Number of nanoparticles.
void DrVector(Vettore v, Vettore Origin)
Draw a vector.
Definition: ElPolyDraw.cpp:539
double VetV(const Vettore *u, const Vettore *v)
Vectorial product between two Vettore returns the area.
int DefWall()
Wall.
GLuint Particles
Refers to the list of the total position of the particles which will be generated in another program...
Definition: Draw.h:200
void DrawFuncHeader()
Assign the pointer to the corrispondent draw function, intilize the visualization.
Definition: ElPolyDraw.cpp:123
int DrawOutput
Boh.
Definition: ElPoly.h:447
int NVisSkip
How many lipids are skipped in the visualization.
Definition: ElPoly.h:443
double Pos[4]
xyzr Postion of the chain
Definition: VarData.h:238
int PairCorrelation(double *Point, int NSample, int How, int Type)
1-d pair correlation
Definition: VarDataExp.cpp:24
Matrice computes the algebric operations on matrices.
void DrNanoPovRay(int n)
PovRay draw function.
void ESlide()
Sequence of pictures.
Definition: ElPolyDraw.cpp:706
char * ChooseDraw(int ExtWhat2Draw)
Convert the internal definition for the menu of ElPoly in string.
Definition: ElPolyEl.cpp:279
int IfLine
Boh.
Definition: ElPoly.h:435
void DrCrossLinks()
Visualize the cross links.
Definition: ElPolyDraw.cpp:642
int Step
Current step for the picture&#39;s name.
Definition: Draw.h:244
void DrawPart(int p)
Pointer to a generic function.
Definition: ElPoly.h:302
int NChain
chains
Definition: VarData.h:263
GLfloat xa
Angles.
Definition: Draw.h:155
int What2Draw
Draw the content in the appropriate visulization.
Definition: ElPoly.h:441
double pVelMax(int d)
Maximum velocity.
Definition: VarData.h:926
char Block2Draw[20]
Name of the block to draw.
Definition: ElPoly.h:390
int EndIdx
End particle position.
Definition: VarData.h:267
void DrChains()
Position of every chain in hexagons.
Definition: ElPolyDraw.cpp:556
double pPos(int p, int d)
Return back folded position.
void ElMenuChoise(int option)
Choose what to visualize.
void DrBondOpenGl(double *Pos1, double *Pos2, float *Color)
Draw the bonds.
Definition: ElPolyDraw.cpp:93
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
void DrVectors()
Draw the chains as vectors.
Definition: ElPolyDraw.cpp:481
double Edge[3]
Box size.
Definition: Draw.h:262
DRAW_PART Draw_Part
Pointer to a distance/field function.
Definition: ElPoly.h:300
int DrIntorno(int p, double Blue)
Visualize only particles within a certain distance.
Definition: ElPolyDraw.cpp:79
DRAW_BOND Draw_Bond
Pointer to a distance/field function.
Definition: ElPoly.h:318
void DrawBond(double *Pos1, double *Pos2, float *Color)
Pointer to a generic function.
Definition: ElPoly.h:322
void Window(int argc, char **argv)
Initial definition of the window.
Definition: Draw.cpp:108
void DrPartOpenGl(int p)
OpenGl draw function.
Definition: ElPolyDraw.cpp:179
void DrColor()
Visualisation of the particle system with velocity color scheme.
Definition: ElPolyDraw.cpp:420
int IfIntorno
If it visualizes only the particles/chains within a certain distance.
Definition: ElPoly.h:429
void Set(double Val, int Col)
Set the N column.
double * data
Stored entries.
void DrPosCol()
Boh.
Definition: ElPolyDraw.cpp:612
void DrField(int NGrid, double IsoLevel, int nNano, FILE *FWrite)
Draw a scalar field.
int CNorm
Normal coordinate.
Definition: VarData.h:1074
int pStep()
Number of steps.
int pNPart()
Number of particle.