Allink
v0.1
|
00001 /*********************************************************************** 00002 ElPoly:This progam provide a graphical visualisation of the data 00003 opend by VarData using openGL glut. The most important option are 00004 the possibility of changing the backfold of the polymers with 'c', 00005 see the subsequent file in the list with '>', see the bond with 'b'. 00006 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it> 00007 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 ***********************************************************************/ 00023 #include "ElPoly.h" 00024 00025 #ifdef __glut_h__ 00026 Draw *Dr; 00027 void Figure(){ 00028 //Dr->Draw1(); 00029 Dr->DFigure(); 00030 } 00031 void reshape(int w,int h){ 00032 Dr->Dreshape(w,h); 00033 } 00034 void Timer(int v){ 00035 Dr->DTimer(v); 00036 } 00037 void MouseMove(int x,int y){ 00038 Dr->DMouseMove(x,y); 00039 } 00040 void special(int k, int x, int y){ 00041 Dr->Dspecial(k,x,y); 00042 } 00043 int ElPoly::Graphics(int argc,char **argv){ 00044 InvScaleUn = 1./pEdge(0); 00045 Dr = new Draw(); 00046 for(int d=0;d<3;d++) Dr->Edge[d] = pEdge(d); 00047 Dr->InvScaleUn = InvScaleUn; 00048 Dr->xi = -.4;Dr->yi = -.4;Dr->zi = .0; 00049 Dr->xp = 0.;Dr->yp = 0.;Dr->zp = 0.; 00050 Dr->xa = 0.;Dr->ya = 0.;Dr->za = 0.; 00051 Vicinanze = 0.; 00052 Saturation = 1.; 00053 // IfColour = 0; 00054 // IfChains = 0; 00055 Quad = 0; 00056 Point = 0; 00057 Cylinder = 0; 00058 MetalCylinder = 0; 00059 Hexagon = 0; 00060 Cube = 0; 00061 DrawOutput = EL_OPENGL; 00062 Cylinder = (GLuint *)calloc(pNNano(),sizeof(GLuint)); 00063 sprintf(Block2Draw,"ALL"); 00064 Dr->Window(argc,argv); 00065 CreateMenu(); 00066 ChooseDraw(cWhat2Draw); 00067 ElMenuChoise(What2Draw); 00068 ElMenuVisual(What2Draw); 00069 for(int n=0;n<pNNano();n++){ 00070 Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height); 00071 } 00072 //Dr->Picture();exit(0); 00073 glutPostRedisplay(); 00074 glutMainLoop(); 00075 } 00076 void ElPoly::DrRunTime(){ 00077 //DrSurface(); 00078 } 00079 int ElPoly::DrIntorno(int p,double Blue){ 00080 double Near = 0.; 00081 double PreChain = 0.; 00082 if(!IfIntorno||pType(p)==2) 00083 Near = 0.; 00084 else if(IfIntorno == 1){ 00085 Near = Ch[pChain(p)].Pos[3]*InvScaleUn; 00086 if(PreChain != pChain(p)){ 00087 } 00088 } 00089 if(Near > Vicinanze) 00090 return 1; 00091 return 0; 00092 } 00093 void ElPoly::DrBondOpenGl(double *Pos1,double *Pos2,float *Color){ 00094 glColor4fv(Color); 00095 glPushMatrix();//Line 00096 glBegin(GL_LINES); 00097 glVertex3d(Pos1[0],Pos1[1],Pos1[2]); 00098 glVertex3d(Pos2[0],Pos2[1],Pos2[2]); 00099 glEnd(); 00100 glPopMatrix();//Line 00101 } 00102 void ElPoly::DrBond(int p){ 00103 if(!pNLink())return; 00104 double Pos1[3]; 00105 double Pos2[3]; 00106 for(int l=0;l<Ln[p].NLink;l++){ 00107 int link = Ln[p].Link[l]; 00108 for(int d=0;d<3;d++){ 00109 Pos1[d] = pPos(p,d)*InvScaleUn; 00110 Pos2[d] = pPos(link,d)*InvScaleUn; 00111 } 00112 for(int d=0;d<3;d++){ 00113 if(Pos1[d] - Pos2[d] > .5*pEdge(d)*InvScaleUn){ 00114 Pos2[d] += pEdge(d)*InvScaleUn; 00115 } 00116 else if(Pos1[d] - Pos2[d] < -.5*pEdge(d)*InvScaleUn){ 00117 Pos2[d] -= pEdge(d)*InvScaleUn; 00118 } 00119 } 00120 DrawBond(Pos1,Pos2,ColorType[pType(p)]); 00121 } 00122 } 00123 void ElPoly::DrawFuncHeader(){ 00124 #ifdef __glut_h__ 00125 if(DrawOutput == EL_OPENGL){ 00126 glDisable(GL_LIGHTING); 00127 //glEnable(GL_LIGHTING); 00128 glDeleteLists(Dr->Particles,1); 00129 Dr->Particles = glGenLists(1); 00130 if(pNPart() > 50000) NVisSkip = 2; 00131 else if (pNPart() > 100000) NVisSkip = 4; 00132 for(int n=0;n<pNNano();n++){ 00133 glDeleteLists(Cylinder[n],1); 00134 Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height); 00135 if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_WALL)){ 00136 glDeleteLists(GlWall,1); 00137 GlWall = Dr->DefWall(); 00138 } 00139 } 00140 glNewList(Dr->Particles,GL_COMPILE); 00141 glDisable(GL_LIGHTING); 00142 Draw_Part = &ElPoly::DrPartOpenGl; 00143 Draw_Nano = &ElPoly::DrNanoOpenGl; 00144 if(IfLine) Draw_Bond = &ElPoly::DrBondOpenGl; 00145 else Draw_Bond = &ElPoly::DrBondNo; 00146 } 00147 else if(DrawOutput == EL_POVRAY){ 00148 #endif // __glut_h_ 00149 Draw_Part = &ElPoly::DrPartPovRay; 00150 Draw_Nano = &ElPoly::DrNanoPovRay; 00151 Draw_Bond = &ElPoly::DrBondPovRay; 00152 HeaderPovRay(); 00153 SigErr(DrawOutFile != NULL,"DrawOutFile already allocated, can't use the file"); 00154 char FName[60]; 00155 sprintf(FName,"PovSnap%05d.pov",pStep()); 00156 DrawOutFile = fopen(FName,"w"); 00157 int ImSize[2] = {1000,1000}; 00158 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); 00159 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"); 00160 fprintf(DrawOutFile,"#include \"PovHeader.inc\"\n"); 00161 fprintf(DrawOutFile,"// System \n"); 00162 #ifdef __glut_h__ 00163 } 00164 #endif // __glut_h_ 00165 } 00166 void ElPoly::DrawFuncFooter(){ 00167 #ifdef __glut_h__ 00168 if(DrawOutput == EL_OPENGL){ 00169 glEndList(); 00170 } 00171 else if(DrawOutput == EL_POVRAY){ 00172 #endif // __glut_h_ 00173 fprintf(DrawOutFile,"// End of POV-Ray 3.x generation\n"); 00174 fclose(DrawOutFile); 00175 #ifdef __glut_h__ 00176 } 00177 #endif // __glut_h_ 00178 } 00179 void ElPoly::DrPartOpenGl(int p){ 00180 int Typ = pType(p) < 6 ? pType(p) : 5; 00181 //ColorType[Typ][0] = pVel(p,3); 00182 glColor4fv(ColorType[Typ]); 00183 glPushMatrix();//Particle 00184 glBegin(GL_POINTS); 00185 glVertex3f(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00186 glEnd(); 00187 glPopMatrix();//Particle 00188 } 00189 void ElPoly::DrCrossLinks(char *FileName){ 00190 FILE *FRead = fopen(FileName,"r"); 00191 if(FRead == NULL) return; 00192 char cLine[STRSIZE]; 00193 int c1=0; 00194 int c2=0; 00195 glDisable(GL_LIGHTING); 00196 glColor4f(.5,0.0,.4,1.0); 00197 for(int k=0;!(fgets(cLine,STRSIZE,FRead)==NULL);k++){ 00198 fscanf(FRead,"%d %d\n",&c1,&c2); 00199 glPushMatrix();//Line 00200 glBegin(GL_LINES); 00201 glVertex3d(pPos(c1,0)*InvScaleUn, 00202 pPos(c1,1)*InvScaleUn, 00203 pPos(c1,2)*InvScaleUn*ScaleFact); 00204 double Pos[3] = {pPos(c2,0),pPos(c2,1),pPos(c2,2)}; 00205 for(int d=0;d<3;d++){ 00206 if(pPos(c1,d) - Pos[d] > .5*pEdge(d)) 00207 Pos[d] += pEdge(d); 00208 else if(pPos(c1,d) - Pos[d] < -.5*pEdge(d)) 00209 Pos[d] -= pEdge(d); 00210 } 00211 glVertex3d(((Pos[0])*InvScaleUn), 00212 ((Pos[1])*InvScaleUn), 00213 ((Pos[2])*InvScaleUn*ScaleFact)); 00214 glEnd(); 00215 glPopMatrix();//Line 00216 } 00217 } 00218 void ElPoly::DrPartList(){ 00219 double Pos1[3]; 00220 double Pos2[3]; 00221 DrawFuncHeader(); 00222 for(int n=0;n<pNNano();n++) DrawNano(n); 00223 glDisable(GL_LIGHTING); 00224 DrCrossLinks("CrossLinks.dat"); 00225 for(int b=0,NPep=0,cOff=0,pOff=0;b<pNBlock();cOff+=pNChain(b++)){ 00226 if(strcmp(Block2Draw,"ALL")){ 00227 if(strcmp(Block[b].Name,Block2Draw) ){ 00228 pOff += pNChain(b)*pNPCh(b); 00229 continue; 00230 } 00231 } 00232 if(!strncmp(Block[b].Name,"PEP",3)){ 00233 DrProtein(Nano[NPep].ArchFile,b); 00234 NPep++; 00235 continue; 00236 } 00237 for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){ 00238 int Chc = Ch[pChain(p)].Type; 00239 if(!CHAIN_IF_TYPE(Chc,NChType)) continue; 00240 if(NPType != BEAD_EVERY && pType(p) != NPType) continue; 00241 // if(Pm[p].CId != 3) continue; 00242 // Dr->Numera(Pm[p].Pos,p); 00243 DrawPart(p); 00244 DrBond(p); 00245 } 00246 // for(int c=cOff;c<cOff+pNChain(b);c+=NVisSkip,pOff+=pNPCh(b)*NVisSkip){ 00247 // for(int p=pOff,link=0;p<MIN(pOff+pNPCh(b),pNPart());p++){ 00248 // int Chc = Ch[pChain(p)].Type; 00249 // if(!CHAIN_IF_TYPE(Chc,NChType)) continue; 00250 // DrawPart(p); 00251 // DrBond(p); 00252 // } 00253 // } 00254 } 00255 DrawFuncFooter(); 00256 } 00257 void ElPoly::DrNanoOpenGl(int n){ 00258 if(Dr->IfMaterial){ 00259 glEnable(GL_LIGHTING); 00260 glEnable( GL_LIGHT0 ); 00261 } 00262 else 00263 glDisable(GL_LIGHTING); 00264 Point2Shape(Nano[n].Shape); 00265 double Red = fabs(Nano[n].Hamaker)/3.; 00266 double Alpha = 1.;//Nano[n].Hamaker/10.; 00267 GLfloat Color[4] = {Red,.1,.1,Alpha}; 00268 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color); 00269 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color); 00270 glColor4fv(Color); 00271 if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_NONE)) return; 00272 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CLUSTER)){ 00273 Alpha = .2; 00274 DrProtein(Nano[n].ArchFile,Nano[n].nBlock); 00275 return; 00276 } 00277 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_JANUS)){ 00278 // Point2Shape(Nano[n].Shape); 00279 // DrField(64,Nano[n].Rad,n); 00280 // continue; 00281 } 00282 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_PORE)){ 00283 PorePos(); 00284 } 00285 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CYL)){ 00286 // Point2Shape(Nano[n].Shape); 00287 // DrField(64,SQR(Nano[n].Rad),n); 00288 // continue; 00289 } 00290 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_TIP)){ 00291 DrField(32,SQR(Nano[n].Rad),n); 00292 return; 00293 } 00294 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_BOUND)){ 00295 DrField(32,SQR(Nano[n].Rad),n); 00296 return; 00297 } 00298 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_TORUS)){ 00299 double OldPos[5] = {Nano->Pos[0],Nano->Pos[1],Nano->Pos[2],Nano->Rad,Nano->Height}; 00300 //StalkPos(OldPos); 00301 DrField(64,SQR(Nano[n].Rad),n); 00302 return; 00303 } 00304 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_STALK)){ 00305 DrField(64,SQR(Nano[n].Rad),n); 00306 return; 00307 } 00308 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_HARM)){ 00309 DrField(64,SQR(Nano[n].Rad),n); 00310 return; 00311 } 00312 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_WALL)){ 00313 DrField(16,SQR(Nano[n].Rad),n); 00314 return; 00315 } 00316 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_UMBR)){ 00317 glPushMatrix();//Nano 00318 glBegin(GL_QUADS); 00319 glNormal3f(0.,0.,-1.); 00320 glVertex3f(0.,0.,Nano[n].Pos[CNorm]*InvScaleUn); 00321 glVertex3f(0.,pEdge(1)*InvScaleUn,Nano[n].Pos[CNorm]*InvScaleUn); 00322 glVertex3f(pEdge(0)*InvScaleUn,pEdge(1)*InvScaleUn,Nano[n].Pos[CNorm]*InvScaleUn); 00323 glVertex3f(pEdge(0)*InvScaleUn,0.,Nano[n].Pos[CNorm]*InvScaleUn); 00324 glEnd();//GL_QUADS 00325 glPopMatrix();//Nano 00326 return; 00327 } 00328 Vettore Ax(Nano[n].Axis[0],Nano[n].Axis[1],Nano[n].Axis[2]); 00329 Vettore Zed(0.,0.,1.); 00330 Vettore Axis(3); 00331 Ax.Normalize(); 00332 Axis.VetV(&Zed,&Ax); 00333 double Angle = Zed.Angle(&Ax,&Zed); 00334 //Quadri q(Axis.x,Angle); 00335 //double data[16]; 00336 //q.RotMatrix(data,4); 00337 //Matrice M(q,4); 00338 Matrice M(Axis.x,Angle,4); 00339 glPushMatrix();//Nano 00340 glTranslated((pNanoPos(n,0)*InvScaleUn), 00341 (pNanoPos(n,1)*InvScaleUn), 00342 (pNanoPos(n,2)*InvScaleUn*ScaleFact)); 00343 glMultMatrixd(M.data); 00344 //glRotatef(Angle*DEG_RAD,Axis.x[0],Axis.x[1],Axis.x[2]); 00345 //glCallList(Cylinder[n]); 00346 if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_SPH)){ 00347 glutSolidSphere(Nano[n].Rad*InvScaleUn,20,20); 00348 } 00349 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_EXT)){ 00350 glColor4f(Red,.1,.1,.5); 00351 glCallList(Cylinder[n]); 00352 } 00353 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_PORE)){ 00354 glColor4f(Red,.1,.1,.5); 00355 glCallList(Cylinder[n]); 00356 } 00357 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_JANUS)){ 00358 glCallList(Cylinder[n]); 00359 } 00360 else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CYL)){ 00361 glCallList(Cylinder[n]); 00362 } 00363 else{ 00364 glCallList(Cylinder[n]); 00365 } 00366 glPopMatrix();//Nano 00367 return; 00368 Red = fabs(Nano[n].Hamaker)/3.; 00369 if(!VAR_IF_TYPE(Nano[n].Shape,SHAPE_WALL))return; 00370 glDisable(GL_LIGHTING); 00371 // double x = (pNanoPos(n,0) - .5*pEdge(0))*InvScaleUn; 00372 // double y = (pNanoPos(n,1) - .5*pEdge(1))*InvScaleUn; 00373 // double z = (pNanoPos(n,2))*InvScaleUn*ScaleFact; 00374 double x = pNanoPos(n,0)*InvScaleUn; 00375 double y = pNanoPos(n,1)*InvScaleUn; 00376 double z = pNanoPos(n,2)*InvScaleUn*ScaleFact; 00377 //Quadri q(Axis.x,Angle); 00378 //double data[16]; 00379 //q.RotMatrix(data,4); 00380 //Matrice M(q,4); 00381 glPushMatrix();//Nano 00382 glTranslated(x,y,z); 00383 glMultMatrixd(M.data); 00384 glCallList(GlWall); 00385 glPopMatrix();//Nano 00386 // glPushMatrix();//Nano 00387 // glTranslated(x,y,z); 00388 // //glCallList(GlWall); 00389 // glPopMatrix();//Nano 00390 } 00391 void ElPoly::DrProtein(const char *ArchFile,int b){ 00392 glDisable(GL_LIGHTING); 00393 FILE *Arch = fopen(ArchFile,"r"); 00394 if(Arch == NULL) {printf("File %s not present \n",ArchFile);return;} 00395 char cLine[STRSIZE]; 00396 double Pos1[3]; 00397 double Pos2[3]; 00398 double Mid[3]; 00399 int l1 = 0; 00400 int l2 = 0; 00401 double Elong = 0.; 00402 double Alpha = 1.; 00403 for(int p=Block[b].InitIdx;fgets(cLine,STRSIZE,Arch);p++){ 00404 DrawPart(p); 00405 sscanf(cLine,"%d %d %lf %lf\n",&l1,&l2,&Elong,&Alpha); 00406 l1 += Block[b].InitIdx; 00407 l2 += Block[b].InitIdx; 00408 if(l1 == l2) continue; 00409 for(int d=0;d<3;d++){ 00410 Pos1[d] = pPos(l1,d)*InvScaleUn; 00411 Pos2[d] = pPos(l2,d)*InvScaleUn; 00412 Pos2[d] += floor((pPos(l1,d) - pPos(l2,d))*pInvEdge(d)+.5)*pEdge(d)*InvScaleUn; 00413 Mid[d] = .5*(Pos1[d]+Pos2[d]); 00414 } 00415 DrawBond(Pos1,Mid,ColorType[pType(l1)]); 00416 DrawBond(Mid,Pos2,ColorType[pType(l2)]); 00417 } 00418 fclose(Arch); 00419 } 00420 void ElPoly::DrColor(){ 00421 glDisable(GL_LIGHTING); 00422 GLuint Cube = Dr->DefCube(NEdge); 00423 glDeleteLists(Dr->Particles,1); 00424 Dr->Particles = glGenLists(1); 00425 glNewList(Dr->Particles,GL_COMPILE); 00426 if(1==0){ 00427 glPushMatrix();//RefPoint 00428 double RefPos[3] = {(ShiftPos[0]+.5)*pEdge(0),(ShiftPos[1]+.5)*pEdge(1),(ShiftPos[2]+.5)*pEdge(2)}; 00429 glTranslated((RefPos[0]*InvScaleUn), 00430 (RefPos[1]*InvScaleUn), 00431 (RefPos[2]*InvScaleUn*ScaleFact)); 00432 glColor4f( .7,.1,.1,1.); 00433 glutSolidSphere(0.1,20,20); 00434 glPopMatrix();//RefPos 00435 } 00436 int NDrawn = 0; 00437 for(int p=0,link=0;p<pNPart();p++){ 00438 double Red = pVel(p,0)/pVelMax(0)*Saturation; 00439 if(Red < 0.) Red = -Red; 00440 double Green = pVel(p,1)/pVelMax(1); 00441 double Blue = pVel(p,2)/pVelMax(2); 00442 //if(Red < .3) continue; 00443 double Alpha = 1.;//Pm[p].Vel[3]/pVel(3); 00444 double Add = 1./(double)NEdge/3.; 00445 if(1==0){ 00446 if(Green > .1){ 00447 glColor4f(0.,Green,0.,Alpha); 00448 glPushMatrix();//Cube 00449 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00450 glCallList(Cube); 00451 glPopMatrix();//Cube 00452 } 00453 if(Blue > .1){ 00454 glColor4f(0.,0.,Blue,Alpha); 00455 glPushMatrix();//Cube 00456 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,(pPos(p,2)*InvScaleUn+Add)*ScaleFact); 00457 glCallList(Cube); 00458 glPopMatrix();//Cube 00459 } 00460 if(Red > .1){ 00461 glColor4f(Red,0.,0.,Alpha); 00462 glPushMatrix();//Cube 00463 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,(pPos(p,2)*InvScaleUn+Add*2.)*ScaleFact); 00464 glCallList(Cube); 00465 glPopMatrix();//Cube 00466 } 00467 } 00468 else{ 00469 if(Green + Blue + Red> .01) 00470 { 00471 glColor4f(Red,Green,Blue,Alpha); 00472 glPushMatrix();//Cube 00473 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00474 glCallList(Cube); 00475 glPopMatrix();//Cube 00476 } 00477 } 00478 } 00479 glEndList(); 00480 } 00481 void ElPoly::DrVectors(){ 00482 glDisable(GL_LIGHTING); 00483 glDeleteLists(Dr->Particles,1); 00484 Dr->Particles = glGenLists(1); 00485 glNewList(Dr->Particles,GL_COMPILE); 00486 ShiftRef(BF_CHAIN); 00487 Vettore Freccia(pEdge(0)*InvScaleUn,0.,0.); 00488 Vettore Axis(3); 00489 Vettore ChDir(3); 00490 Vettore ChPos(3); 00491 Vettore Ax0(1,0,0); 00492 Vettore Ax1(0,1,0); 00493 Vettore Ax2(0,0,1); 00494 for(int b=0,c1=0,NPep=0;b<pNBlock();c1+=Block[b++].NChain){ 00495 if(strcmp(Block2Draw,"ALL")){ 00496 if(strcmp(Block[b].Name,Block2Draw) ) continue; 00497 } 00498 if(!strncmp(Block[b].Name,"PEP",3)){ 00499 //DrProtein(Nano[++NPep].ArchFile,b); 00500 continue; 00501 } 00502 // if(strncmp(Block[b].Name,"TT",2))continue; 00503 for(int c=c1;c<c1+pNChain(b);c++){ 00504 if(!CHAIN_IF_TYPE(c,NChType)) continue; 00505 for(int d=0;d<3;d++){ 00506 ChDir.Set(Ch[c].Dir[d]*InvScaleUn,d); 00507 ChPos.Set((Ch[c].Pos[d]-Ch[c].Dir[d]*.5)*InvScaleUn,d); 00508 } 00509 double Red = Ch[c].Angle/M_PI; 00510 double Green = 1.-Red;//Ax2.Angle(&Ax1,&ChDir)/M_PI; 00511 double Blue = 0.;//sin(Ax0.Angle(&Ax2,&ChDir))-Green; 00512 double Alpha = 1.; 00513 if(Red > 0.35 && Red < .65); 00514 // else Blue = 0.; 00515 else continue; 00516 glColor4f(Red,Green,Blue,Alpha); 00517 glPushMatrix();//Arrow 00518 double Length1 = ChDir.Norm(); 00519 double Length2 = Freccia.Norm(); 00520 for(int d=0;d<3;d++){ 00521 Axis.Set(.5*(ChDir.Val(d)/Length1+Freccia.Val(d)/Length2),d); 00522 } 00523 glTranslated(ChPos.Val(0),ChPos.Val(1),ChPos.Val(2)); 00524 glRotatef(180.,Axis.Val(0),Axis.Val(1),Axis.Val(2)); 00525 glScaled(Length1/Length2,1.0,1.0); 00526 glNormal3f(ChDir.Val(0),ChDir.Val(1),ChDir.Val(2)); 00527 glCallList(Arrow); 00528 glPopMatrix();//Arrow 00529 int p1 = c*pNPCh(); 00530 for(int ppc=0;ppc<pNPCh();ppc++){ 00531 int p = ppc+p1; 00532 DrawPart(p); 00533 if(IfLine) DrBond(p); 00534 } 00535 } 00536 } 00537 glEndList(); 00538 } 00539 void ElPoly::DrVector(Vettore v,Vettore Origin){ 00540 glDisable(GL_LIGHTING); 00541 glPushMatrix();//Arrow 00542 Vettore Freccia(pEdge(0)*InvScaleUn,0.,0.); 00543 Vettore Axis(3); 00544 double Length1 = v.Norm(); 00545 double Length2 = Freccia.Norm(); 00546 for(int d=0;d<3;d++){ 00547 Axis.Set(d,.5*(v[d]/Length1 + Freccia[d]/Length2)); 00548 } 00549 glTranslated(Origin[0],Origin[1],Origin[2]); 00550 glRotatef(180.,Axis[0],Axis[1],Axis[2]); 00551 glScaled(Length1/Length2,1.0,1.0); 00552 glNormal3f(v[0],v[1],v[2]); 00553 glCallList(Arrow); 00554 glPopMatrix();//Arrow 00555 } 00556 void ElPoly::DrChains(){ 00557 glDisable(GL_LIGHTING); 00558 double Values=200.; 00559 glDeleteLists(Dr->Particles,1); 00560 Dr->Particles = glGenLists(1); 00561 glNewList(Dr->Particles,GL_COMPILE); 00562 Folding(); 00563 for(int c=0;c<pNChain();c++){ 00564 //Numera(Ch[c].Pos,c); 00565 int Chc = Ch[c].Type; 00566 if(!CHAIN_IF_TYPE(Chc,NChType)) continue; 00567 double Red = 0.; 00568 if(CHAIN_IF_TYPE(Chc,CHAIN_UP)) 00569 Red = 1.; 00570 double Blue=0.; 00571 if(CHAIN_IF_TYPE(Chc,CHAIN_FLABBY)) 00572 Blue =1.; 00573 double Green=.7; 00574 if(CHAIN_IF_TYPE(Chc,CHAIN_TILTED)) 00575 Green =.5; 00576 glPushMatrix(); 00577 glTranslatef((GLfloat)(Ch[c].Pos[0]*InvScaleUn), 00578 (GLfloat)(Ch[c].Pos[1]*InvScaleUn), 00579 (GLfloat)(Ch[c].Pos[2]*InvScaleUn*ScaleFact)); 00580 glColor4f(Red,Green,Blue,1.); 00581 glCallList(Hexagon); 00582 glPopMatrix(); 00583 } 00584 glEndList(); 00585 return ; 00586 double Unity= 1./(double)Values*pEdge(0)*InvScaleUn; 00587 double *dDensity; 00588 dDensity = (double *)calloc(Values,sizeof(double)); 00589 PairCorrelation(dDensity,Values,1,CHAIN_UP); 00590 double Max=0.; 00591 for(int v=0;v<Values;v++){ 00592 if(Max < dDensity[v]){ 00593 Max = dDensity[v]; 00594 } 00595 } 00596 for(int v=0;v<Values;v++){ 00597 dDensity[v] /= Max; 00598 } 00599 for(int v=0;v<Values-1;v++){ 00600 glPushMatrix(); 00601 glBegin(GL_LINES); 00602 glColor4f(1.,0.,1.,1.); 00603 glVertex3d((Values-v)*Unity,pEdge(1)*InvScaleUn,dDensity[v]); 00604 glVertex3d((Values-(v+1))*Unity,pEdge(1)*InvScaleUn,dDensity[v+1]); 00605 glEnd(); 00606 glPopMatrix(); 00607 } 00608 glEndList(); 00609 free(dDensity); 00610 } 00611 //obsolete? 00612 void ElPoly::DrPosCol(){ 00613 glDisable(GL_LIGHTING); 00614 glDeleteLists(Dr->Particles,1); 00615 Dr->Particles = glGenLists(1); 00616 glNewList(Dr->Particles,GL_COMPILE); 00617 glPointSize(3); 00618 glLineWidth(3); 00619 for(int p=0,link=0;p<pNPart();p++){ 00620 glColor4f(pVel(p,0)/pVelMax(0),pVel(p,1)/pVelMax(1),pVel(p,2)/pVelMax(2),pVel(p,3)/pVelMax(3)); 00621 if(pType(p) == 2){ 00622 glPushMatrix();//Particle 00623 glTranslated((pPos(p,0)*InvScaleUn), 00624 (pPos(p,1)*InvScaleUn), 00625 (pPos(p,2)*InvScaleUn*ScaleFact)); 00626 glColor4f( 1.,.1,.1,1.); 00627 if(Nano->Shape == SHAPE_CYL) 00628 glCallList(Cylinder[0]); 00629 else 00630 glutSolidSphere(Nano->Rad*InvScaleUn,20,20); 00631 glPopMatrix();//Particle 00632 } 00633 else{ 00634 glPushMatrix();//Particle 00635 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00636 glCallList(Cube); 00637 glPopMatrix();//Particle 00638 } 00639 } 00640 glEndList(); 00641 } 00642 void ElPoly::DrCrossLinks(){ 00643 glDisable(GL_LIGHTING); 00644 glDeleteLists(Dr->Particles,1); 00645 Dr->Particles = glGenLists(1); 00646 glNewList(Dr->Particles,GL_COMPILE); 00647 glPointSize(3); 00648 glLineWidth(3); 00649 for(int p=0,link=0;p<pNPart();p++){ 00650 int Chc = Ch[pChain(p)].Type; 00651 if(!CHAIN_IF_TYPE(Chc,NChType) && pType(p)!=2) continue; 00652 int Typ = pType(p) < 6 ? pType(p) : 5; 00653 glColor4fv(ColorType[Typ]); 00654 if(IfLine){ 00655 glColor4f(0.0,1.0,0.,1.0); 00656 for(int l=0;l<Ln[p].NLink;l++){ 00657 link = Ln[p].Link[l]; 00658 double Shift[3] = {0.,0.,0.}; 00659 if(link != p+1){ 00660 glColor4f(1.0,.0,0.,1.0); 00661 for(int d=0;d<3;d++) 00662 Shift[d] = -floor((pPos(p,d)-pPos(link,d))/pEdge(d)+.5)*pEdge(d); 00663 } 00664 else continue; 00665 glPushMatrix();//Line 00666 glBegin(GL_LINES); 00667 glVertex3d((pPos(p,0)*InvScaleUn), 00668 (pPos(p,1)*InvScaleUn), 00669 (pPos(p,2)*InvScaleUn*ScaleFact)); 00670 glVertex3d(((pPos(link,0)-Shift[0])*InvScaleUn), 00671 ((pPos(link,1)-Shift[1])*InvScaleUn), 00672 ((pPos(link,2)-Shift[2])*InvScaleUn*ScaleFact)); 00673 glEnd(); 00674 glPopMatrix();//Line 00675 } 00676 } 00677 glPushMatrix();//Particle 00678 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn); 00679 //glutSolidSphere(.007,20,20); 00680 glCallList(Point); 00681 glPopMatrix();//Particle 00682 } 00683 glEndList(); 00684 } 00685 void ElPoly::Menu(){ 00686 // submenu = glutCreateMenu(processEvent); 00687 // glutAddMenuEntry("SottoPrima",3); 00688 00689 // menu = glutCreateMenu(processEvent); 00690 // glutAddMenuEntry("Move",1); 00691 // glutAddMenuEntry("Stop",2); 00692 // glutAddSubMenu("Altro",submenu); 00693 // glutAttachMenu(GLUT_RIGHT_BUTTON); 00694 } 00695 void ElPoly::ESlide1(void){ 00696 // if(Dr->Step > 100) glutIdleFunc(NULL); 00697 Dr->zw += .1; 00698 Dr->IfInfo = 0; 00699 glutPostRedisplay(); 00700 Dr->Step++; 00701 Dr->Picture(); 00702 Dr->IfInfo = 1;; 00703 //Dr->Picture(); 00704 //glutTimerFunc(30, Timer, 0); 00705 } 00706 void ElPoly::ESlide(void){ 00707 Dr->IfInfo = 0; 00708 glutPostRedisplay(); 00709 if(quando < NFileTot) 00710 quando++; 00711 //quando += 10; 00712 else{ 00713 glutIdleFunc(NULL); 00714 } 00715 OpenFile(quando); 00716 RenderPart(); 00717 Dr->Step++; 00718 Dr->Picture(); 00719 glutPostRedisplay(); 00720 Dr->IfInfo = 1; 00721 //glutTimerFunc(30, Timer, 0); 00722 } 00723 #endif //__glut_h__