Allink
v0.1
|
00001 /* 00002 * ElPolyDrawSurf - Drawing of the surfaces defined by the chain position 00003 opyright (C) 2008-2010 by Giovanni Marelli <sabeiro@virgilio.it> 00004 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; If not, see <http://www.gnu.org/licenses/>. 00018 ***********************************************************************/ 00019 #include "ElPoly.h" 00020 #include <vector> 00021 00022 #ifdef __glut_h__ 00023 extern Draw *Dr; 00024 void ElPoly::DrPolygon(){ 00025 glEnable(GL_LIGHTING); 00026 glEnable( GL_LIGHT0 ); 00027 glDeleteLists(Dr->Particles,1); 00028 Dr->Particles = glGenLists(1); 00029 glNewList(Dr->Particles,GL_COMPILE); 00030 for(int n=0;n<pNNano();n++) DrawNano(n); 00031 double Cm[3]; 00032 for(int p=0;p<pNPart();p+=Ln[p].NLink+1){ 00033 //if(Pm[p].Pos[2] > .6*pEdge(2) || Pm[p].Pos[2] < .3*pEdge(2)) continue; 00034 double Red = 0.0; 00035 double Green = .4 + .3*Mat->Casuale(); 00036 double Blue = 0.0; 00037 GLfloat DrMatColor [] = {Red,Green,Blue,1.}; 00038 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,DrMatColor); 00039 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,DrMatColor); 00040 glColor4f(Red,Green,Blue,1.); 00041 glPushMatrix(); 00042 glBegin(GL_POLYGON); 00043 //glBegin(GL_TRIANGLE); 00044 //glBegin(GL_TRIANGLE_STRIP); 00045 glNormal3d(pVel(p,0)*InvScaleUn,pVel(p,1)*InvScaleUn,pVel(p,2)*InvScaleUn); 00046 glVertex3d(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00047 for(int d=0;d<3;d++) Cm[d] = pPos(p,d); 00048 for(int l=0;l<Ln[p].NLink;l++){ 00049 int l1 = Ln[p].Link[l]; 00050 glNormal3d(pVel(l1,0),pVel(l1,1),pVel(l1,2)); 00051 glVertex3d(pPos(l1,0)*InvScaleUn,pPos(l1,1)*InvScaleUn,pPos(l1,2)*InvScaleUn*ScaleFact); 00052 for(int d=0;d<3;d++){ 00053 Cm[d] += pPos(p,d); 00054 } 00055 } 00056 glEnd(); 00057 glPopMatrix(); 00058 if(IfLine){ 00059 for(int d=0;d<3;d++){ 00060 Cm[d] /= (double)(Ln[p].NLink+1); 00061 } 00062 glColor4f(.1,.3,1.,1.); 00063 glBegin(GL_LINES); 00064 glNormal3d(0.,0.,1.); 00065 glVertex3d(Cm[0]*InvScaleUn,Cm[1]*InvScaleUn,Cm[2]*InvScaleUn*ScaleFact); 00066 glVertex3d((Cm[0]-pVel(p,0))*InvScaleUn,(Cm[1]-pVel(p,1))*InvScaleUn,(Cm[2]-pVel(p,2))*InvScaleUn*ScaleFact); 00067 glEnd(); 00068 } 00069 } 00070 glEndList(); 00071 } 00072 void ElPoly::DrNormalPoint(int p,int NEdge){ 00073 int link[4]; 00074 link[0] = p + NEdge; 00075 if(link[0] >= pNPart()) link[0] -= pNPart(); 00076 link[1] = p + 1; 00077 if(link[1] >= pNPart()) link[1] -= pNPart(); 00078 link[2] = p - NEdge; 00079 if(link[2] < 0 ) link[2] += pNPart(); 00080 link[3] = p - 1; 00081 if(link[3] < 0 ) link[3] += pNPart(); 00082 double Normals[5][3]; 00083 for(int l=0;l<4;l++){ 00084 for(int d=0;d<3;d++){ 00085 int d1 = (d+1)%3; 00086 int d2 = (d+2)%3; 00087 Normals[l][d] = (pPos(p,d1)-pPos(link[l],d2))*(pPos(p,d2)-pPos(link[l],d)); 00088 } 00089 } 00090 double Norm; 00091 for(int d=0;d<3;d++){ 00092 Normals[4][d] = Normals[0][d] + Normals[1][d] + Normals[2][d] + Normals[3][d]; 00093 Norm += SQR(Normals[4][d]); 00094 } 00095 Norm = 1./sqrt(Norm); 00096 for(int d=0;d<3;d++){ 00097 Normals[4][d] /= Norm; 00098 } 00099 glNormal3d(Normals[4][0],Normals[4][1],Normals[4][2]); 00100 } 00101 void ElPoly::DrSquareMesh(){ 00102 if(Dr->IfMaterial){ 00103 glEnable(GL_LIGHTING); 00104 glEnable( GL_LIGHT0 ); 00105 } 00106 else 00107 glDisable(GL_LIGHTING); 00108 glDeleteLists(Dr->Particles,1); 00109 Dr->Particles = glGenLists(1); 00110 glNewList(Dr->Particles,GL_COMPILE); 00111 int NEdge = (int)sqrt(pNPart()); 00112 if(NEdge*NEdge != pNPart()) NEdge += 1; 00113 GLfloat Color[4]; 00114 for(int p=0;p<pNPart();p++){ 00115 double Depth = pPos(p,2)*pInvEdge(CNorm)*Saturation+ExtParam; 00116 Dr->DepthMap(Depth,Color); 00117 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color); 00118 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color); 00119 glColor4fv(Color); 00120 int l1 = p+1; 00121 if((l1%NEdge) == 0)continue; 00122 int l2 = p + NEdge + 1; 00123 if(l2 >= pNPart()-1)continue; 00124 int l3 = p + NEdge; 00125 if(l3 >= pNPart()-1)continue; 00126 //glPushMatrix(); 00127 glBegin(GL_POLYGON); 00128 DrNormalPoint(p,NEdge); 00129 glVertex3d(Pm[p].Pos[0]*InvScaleUn,Pm[p].Pos[1]*InvScaleUn,Pm[p].Pos[2]*InvScaleUn*ScaleFact); 00130 DrNormalPoint(l1,NEdge); 00131 glVertex3d(Pm[l1].Pos[0]*InvScaleUn,Pm[l1].Pos[1]*InvScaleUn,Pm[l1].Pos[2]*InvScaleUn*ScaleFact); 00132 DrNormalPoint(l2,NEdge); 00133 glVertex3d(Pm[l2].Pos[0]*InvScaleUn,Pm[l2].Pos[1]*InvScaleUn,Pm[l2].Pos[2]*InvScaleUn*ScaleFact); 00134 DrNormalPoint(l3,NEdge); 00135 glVertex3d(Pm[l3].Pos[0]*InvScaleUn,Pm[l3].Pos[1]*InvScaleUn,Pm[l3].Pos[2]*InvScaleUn*ScaleFact); 00136 glEnd(); 00137 //glPopMatrix(); 00138 } 00139 glEndList(); 00140 glDisable(GL_LIGHTING); 00141 } 00142 #include "ElPolyDrawSurf.h" 00143 void ElPoly::DrField(int NGrid,double IsoLevel,int nNano){ 00144 glEnable(GL_LIGHTING); 00145 glEnable( GL_LIGHT0 ); 00146 glMaterialfv(GL_BACK, GL_AMBIENT, DrAmbientRed); 00147 glMaterialfv(GL_BACK, GL_DIFFUSE, DrDiffuseRed); 00148 glMaterialfv(GL_FRONT, GL_AMBIENT, DrAmbientBlue); 00149 glMaterialfv(GL_FRONT, GL_DIFFUSE, DrDiffuseBlue); 00150 glMaterialfv(GL_FRONT, GL_SPECULAR, DrSpecularWhite); 00151 glMaterialf( GL_FRONT, GL_SHININESS, 25.0); 00152 double CubeDist[8]; 00153 double EdgeVertex[12][3]; 00154 double EdgeNormal[12][3]; 00155 double InvNGrid = 1./(double)NGrid; 00156 double Pos[3]; 00157 double Pos1[3]; 00158 glBegin(GL_TRIANGLES); 00159 //glBegin(GL_LINES); 00160 //glBegin(GL_POINTS); 00161 for(int gx=0;gx<NGrid;gx++){ 00162 Pos[0] = gx*InvNGrid*pEdge(0); 00163 for(int gy=0;gy<NGrid;gy++){ 00164 Pos[1] = gy*InvNGrid*pEdge(1); 00165 for(int gz=0;gz<NGrid;gz++){ 00166 Pos[2] = gz*InvNGrid*pEdge(2); 00167 for(int v=0;v<8;v++){ 00168 for(int d=0;d<3;d++){ 00169 Pos1[d] = Pos[d] + VertCube[v][d]*InvNGrid*pEdge(d); 00170 } 00171 CubeDist[v] = NanoDist2(Pos1,nNano); 00172 } 00173 int Flag = 0; 00174 for(int v=0;v<8;v++){ 00175 if(CubeDist[v] <= IsoLevel) 00176 Flag |= 1<<v; 00177 } 00178 int CubeShape = CubeTop[Flag]; 00179 if(CubeShape==0) continue; 00180 for(int e=0;e<12;e++){ 00181 if(CubeShape & (1<<e)){ 00182 double Delta = CubeDist[EdgeConn[e][1]] - CubeDist[EdgeConn[e][0]]; 00183 double OffSet = (IsoLevel-CubeDist[EdgeConn[e][0]])/Delta; 00184 if(Delta == 0.0){ 00185 OffSet = .5; 00186 } 00187 EdgeNormal[e][0] = NanoDist2(Pos[0]-0.01,Pos[1],Pos[2],nNano) 00188 - NanoDist2(Pos[0]+0.01,Pos[1],Pos[2],nNano); 00189 EdgeNormal[e][1] = NanoDist2(Pos[0],Pos[1]-0.01,Pos[2],nNano) 00190 - NanoDist2(Pos[0],Pos[1]+0.01,Pos[2],nNano); 00191 EdgeNormal[e][2] = NanoDist2(Pos[0],Pos[1],Pos[2]-0.01,nNano) 00192 - NanoDist2(Pos[0],Pos[1],Pos[2]+0.01,nNano); 00193 double Norm = sqrt(SQR(EdgeNormal[e][0])+SQR(EdgeNormal[e][1])+SQR(EdgeNormal[e][2])); 00194 for(int d=0;d<3;d++){ 00195 EdgeVertex[e][d] = Pos[d] + (VertCube[EdgeConn[e][0]][d]+OffSet*EdgeDir[e][d])*InvNGrid*pEdge(d); 00196 EdgeVertex[e][d] *= InvScaleUn; 00197 EdgeNormal[e][d] *= 1./Norm; 00198 } 00199 } 00200 } 00201 for(int t=0;t<5;t++){ 00202 if(TrConnTable[Flag][3*t] < 0.) break; 00203 for(int d=0;d<3;d++){ 00204 int v = TrConnTable[Flag][3*t+d]; 00205 //glColor4f(1.0,0.1,0.1,1.0); 00206 glNormal3d(EdgeNormal[v][0],EdgeNormal[v][1],EdgeNormal[v][2]); 00207 glVertex3d(EdgeVertex[v][0],EdgeVertex[v][1],EdgeVertex[v][2]); 00208 } 00209 } 00210 } 00211 } 00212 } 00213 glEnd(); 00214 } 00215 void ElPoly::DrQuad1(){ 00216 glEnable(GL_LIGHTING); 00217 glEnable( GL_LIGHT0 ); 00218 glDeleteLists(Dr->Particles,1); 00219 Dr->Particles = glGenLists(1); 00220 glNewList(Dr->Particles,GL_COMPILE); 00221 //glEnable(GL_POLYGON_STIPPLE); 00222 double RedMax = fabs(log(fabs(pVel(0,0))*Saturation)); 00223 for(int p=0;p<pNPart();p++){ 00224 if(RedMax < fabs(log(fabs(pVel(0,0))*Saturation)) ) 00225 RedMax = fabs(log(fabs(pVel(0,0))*Saturation)); 00226 } 00227 int NDraw = 0; 00228 for(int p=0;p<pNPart();p++){ 00229 if(pPos(p,2) < .7*pEdge(2)) continue; 00230 //double Red = fabs(log(fabs(pPos(p,0))*Sat))/RedMax; 00231 double Red = fabs(pVel(p,0)*Saturation/pVelMax(0)); 00232 double Green = pVel(p,1)/pVelMax(1)*Saturation; 00233 double Blue = pVel(p,2)/pVelMax(2)*Saturation; 00234 GLfloat DrMatColor [] = {Red,Green,Blue,1.}; 00235 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,DrMatColor); 00236 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,DrMatColor); 00237 //if(Red<0.1) continue; 00238 glColor4f(Red,Green,Blue,1.); 00239 glPushMatrix(); 00240 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00241 glCallList(Quad); 00242 glPopMatrix(); 00243 NDraw++; 00244 } 00245 printf("%d\n",NDraw); 00246 glEndList(); 00247 } 00248 void ElPoly::DrQuad(){ 00249 glEnable(GL_LIGHTING); 00250 glEnable( GL_LIGHT0 ); 00251 //CompileList(); 00252 glDeleteLists(Dr->Particles,1); 00253 Dr->Particles = glGenLists(1); 00254 glNewList(Dr->Particles,GL_COMPILE); 00255 int Incr = 1;//4; 00256 double Offset = 1./(double)NEdge; 00257 for(int p=0;p<pNPart();p+=Incr){ 00258 double Red = pVel(p,0)*Saturation;// + pPos(p,2)*Sat; 00259 double Green = pVel(p,1)*Saturation; 00260 double Blue = pVel(p,2)*Saturation; 00261 GLfloat DrMatColor [] = {Red,Green,Blue,1.}; 00262 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,DrMatColor); 00263 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,DrMatColor); 00264 //if(Red < 0.0001 && Green < 0.2 && Blue < 0.2) continue; 00265 glColor4f(Red,Green,Blue,1.0); 00266 glPushMatrix(); 00267 glTranslated(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,0.); 00268 glCallList(Quad); 00269 glPopMatrix(); 00270 // glPushMatrix(); 00271 // glTranslated(-pPos(p,0)*InvScaleUn-Offset,pPos(p,1)*InvScaleUn,0.); 00272 // glCallList(Quad); 00273 // glPopMatrix(); 00274 } 00275 glEndList();return; 00276 } 00277 void ElPoly::DrPotential(){ 00278 glEnable(GL_LIGHTING); 00279 glEnable( GL_LIGHT0 ); 00280 glDeleteLists(Dr->Particles,1); 00281 Dr->Particles = glGenLists(1); 00282 glNewList(Dr->Particles,GL_COMPILE); 00283 int Nx = 0; 00284 int Ny = 0; 00285 for(int p=0;p<pNPart();p++){ 00286 if(pPos(p,CLat2) < pPos(p+1,CLat2)) 00287 Ny++; 00288 else break; 00289 } 00290 Ny++; 00291 Nx = (int)(pNPart()/(double)Ny); 00292 const int NIso = 20; 00293 double Min = pPos(0,CNorm); 00294 double Max = pPos(0,CNorm); 00295 for(int p=0;p<pNPart();p++){ 00296 if(Min > pPos(p,CNorm)) Min = pPos(p,CNorm); 00297 if(Max < pPos(p,CNorm)) Max = pPos(p,CNorm); 00298 } 00299 Min = 1./MIN(fabs(Min),1.); 00300 Max = 1./MIN(1.,Max); 00301 for(int p=0;p<pNPart();p++){ 00302 int l1 = p+1; 00303 if( !(l1%Ny) ) continue; 00304 int l2 = p + Ny; 00305 if(l2 >= pNPart() - 1) continue; 00306 int l3 = p + Ny + 1; 00307 double Red = 1.; 00308 double Blue = 1.; 00309 double Green = 1.; 00310 double Alpha = 1.; 00311 if(pPos(p,CNorm) < 0.){ 00312 Red = 0.; 00313 Green = fabs(pPos(p,CNorm)*Min)*Saturation; 00314 //Green = fabs(pPos(p,2)*1.)*Sat; 00315 Blue = 0.; 00316 Alpha = MAX(Green-.2,0.); 00317 } 00318 else if(pPos(p,CNorm) > 0.){ 00319 Red = 0.; 00320 Green = 0.; 00321 Blue = (pPos(p,CNorm)*pInvEdge(CNorm))*Saturation; 00322 //Blue = pPos(p,2)*1.*Sat; 00323 Alpha = MAX(Blue,0.); 00324 } 00325 else 00326 Alpha = 0.; 00327 GLfloat DrMatColor [] = {Red,Green,Blue,Alpha}; 00328 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,DrMatColor); 00329 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,DrMatColor); 00330 glColor4d(Red,Green,Blue,Alpha); 00331 // glPushMatrix();//Particle 00332 glBegin(GL_POINTS); 00333 glVertex3f(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn*ScaleFact); 00334 glEnd(); 00335 // glPopMatrix();//Particle 00336 glBegin(GL_POLYGON); 00337 glNormal3f(0.,0.,1.); 00338 glVertex3d(pPos(p,0)*InvScaleUn,pPos(p,1)*InvScaleUn,pPos(p,2)*InvScaleUn); 00339 glVertex3d(pPos(l1,0)*InvScaleUn,pPos(l1,1)*InvScaleUn,pPos(l1,2)*InvScaleUn); 00340 glVertex3d(pPos(l3,0)*InvScaleUn,pPos(l3,1)*InvScaleUn,pPos(l3,2)*InvScaleUn); 00341 glVertex3d(pPos(l2,0)*InvScaleUn,pPos(l2,1)*InvScaleUn,pPos(l2,2)*InvScaleUn); 00342 glEnd(); 00343 } 00344 glEndList(); 00345 // int Values = NEdge/4; 00346 // double *Border = (double *)calloc(2*Values,sizeof(double)); 00347 // double *Norm = (double *)calloc(2*Values,sizeof(double)); 00348 // for(int p=0;p<pNPart();p++){ 00349 // int v = (int)(pPos(p,0)/pEdge(0)*Values); 00350 // if( v >= Values) continue; 00351 // if(pPos(p,1) > .5*pEdge(1)){ 00352 // Border[2*v] += pPos(p,1)*pPos(p,2); 00353 // Norm[2*v] += pPos(p,2); 00354 // } 00355 // else{ 00356 // Border[2*v+1] += pPos(p,1)*pPos(p,2); 00357 // Norm[2*v+1] += pPos(p,2]; 00358 // } 00359 // } 00360 // glColor4f(.4,0.0,.6,1.0); 00361 // glBegin(GL_LINE_STRIP); 00362 // glNormal3f(0.,0.,1.); 00363 // for(int v=0,vv=0;v<2*Values-1;v+=2,vv++){ 00364 // if(!(Norm[v] > 0. ) )continue; 00365 // glVertex3f(vv/(double)Values*pEdge(0)*InvScaleUn,Border[v]*InvScaleUn/Norm[v],0.); 00366 // } 00367 // glEnd(); 00368 // glBegin(GL_LINE_STRIP); 00369 // for(int v=1,vv=0;v<2*Values-1;v+=2,vv++){ 00370 // if(!(Norm[v] > 0. ) )continue; 00371 // glVertex3f(vv/(double)Values*pEdge(0)*InvScaleUn,Border[v]*InvScaleUn/Norm[v],0.); 00372 // } 00373 // glEnd(); 00374 // glBegin(GL_LINE_STRIP); 00375 // for(int v=0,vv=0;v<2*Values-1;v+=2,vv++){ 00376 // if(!(Norm[v] > 0. ) )continue; 00377 // glVertex3f(-vv/(double)Values*pEdge(0)*InvScaleUn,Border[v]*InvScaleUn/Norm[v],0.); 00378 // } 00379 // glEnd(); 00380 // glBegin(GL_LINE_STRIP); 00381 // for(int v=1,vv=0;v<2*Values-1;v+=2,vv++){ 00382 // if(!(Norm[v] > 0. ) )continue; 00383 // glVertex3f(-vv/(double)Values*pEdge(0)*InvScaleUn,Border[v]*InvScaleUn/Norm[v],0.); 00384 // } 00385 // glEnd(); 00386 // glEndList(); 00387 } 00388 void ElPoly::DrDensity(){ 00389 if(Dr->IfMaterial){ 00390 glEnable(GL_LIGHTING); 00391 glEnable( GL_LIGHT0 ); 00392 } 00393 else 00394 glDisable(GL_LIGHTING); 00395 glDeleteLists(Dr->Particles,1); 00396 Dr->Particles = glGenLists(1); 00397 glNewList(Dr->Particles,GL_COMPILE); 00398 double Offset = 1./(double)NEdge; 00399 for(int p=0,c=0,t=0;p<pNPart();p++){ 00400 if( Ln[p].NLink != 3 ) continue; 00401 if(c == pChain(p)) continue; 00402 if(NPType != BEAD_EVERY && pType(p) != NPType) continue; 00403 c = pChain(p); 00404 double Red = pVel(p,0)*Saturation/pVelMax(0);// + pPos(p,2)*Sat; 00405 double Green = pVel(p,1)*Saturation/pVelMax(1); 00406 double Blue = pVel(p,2)*Saturation/pVelMax(2); 00407 double Alpha = 1.0;//7.+(Green+Blue); 00408 if(Blue + Red + Green < .08){Blue = 1.; Red = 1.;Green = 1.;Alpha=0.;} 00409 GLfloat DrMatColor [] = {Red,Green,Blue,Alpha}; 00410 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,DrMatColor); 00411 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,DrMatColor); 00412 int l1 = Ln[p].Link[0]; 00413 //if(l1 > Gen->NPart) continue; 00414 int l2 = Ln[p].Link[2]; 00415 //if(l2 > Gen->NPart) continue; 00416 int l3 = Ln[p].Link[1]; 00417 //if(Green > 0.) continue; 00418 // Green = 0.; Blue = 0.; 00419 glColor4f(Red,Green,Blue,Alpha); 00420 // if(pPos(p,2)>12.) pPos(p,2) = 12.; 00421 // if(pPos(l1,2)>12.) pPos(l1,2) = 12.; 00422 // if(pPos(l2,2)>12.) pPos(l2,2) = 12.; 00423 // if(pPos(l3,2)>12.) pPos(l3,2) = 12.; 00424 Vettore v1(pPos(p,0),pPos(p,1),pPos(p,2)*ScaleFact); 00425 Vettore v2(pPos(l1,0),pPos(l1,1),pPos(l1,2)*ScaleFact); 00426 Vettore v3(pPos(l2,0),pPos(l2,1),pPos(l2,2)*ScaleFact); 00427 Vettore v4(pPos(l3,0),pPos(l3,1),pPos(l3,2)*ScaleFact); 00428 v1.Mult(InvScaleUn); 00429 v2.Mult(InvScaleUn); 00430 v3.Mult(InvScaleUn); 00431 v4.Mult(InvScaleUn); 00432 Vettore u(3); 00433 Vettore v(3); 00434 Vettore vN(3); 00435 vN.NormalSurf(&v1,&v2,&v3); 00436 glPushMatrix();//Particle 00437 glBegin(GL_QUADS); 00438 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00439 u = v2-v1;v = v3-v1;vN = u ^ v;//vN.Normalize(); 00440 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00441 glVertex3d(v4.x[0],v4.x[1],v4.x[2]); 00442 u = v1-v2;v = v3-v2;vN = u ^ v;//vN.Normalize(); 00443 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00444 glVertex3d(v3.x[0],v3.x[1],v3.x[2]); 00445 u = v2-v3;v = v4-v3;vN = u ^ v;//vN.Normalize(); 00446 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00447 glVertex3d(v2.x[0],v2.x[1],v2.x[2]); 00448 u = v1-v4;v = v3-v4;vN = u ^ v;//vN.Normalize(); 00449 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00450 glVertex3d(v1.x[0],v1.x[1],v1.x[2]); 00451 glEnd(); 00452 glPopMatrix();//Particle 00453 //continue; 00454 glPushMatrix();//Particle 00455 glBegin(GL_QUADS); 00456 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00457 glVertex3d(-v1.x[0],v1.x[1],v1.x[2]); 00458 glVertex3d(-v2.x[0],v2.x[1],v2.x[2]); 00459 glVertex3d(-v3.x[0],v3.x[1],v3.x[2]); 00460 glVertex3d(-v4.x[0],v4.x[1],v4.x[2]); 00461 glEnd(); 00462 glPopMatrix();//Particle 00463 } 00464 glEndList(); 00465 } 00466 void ElPoly::DrInterpSurface(){ 00467 glEnable(GL_LIGHTING); 00468 glEnable( GL_LIGHT0 ); 00469 int NPoint = 32; 00470 GLfloat Deltax = 1./(GLfloat) NPoint; 00471 PART *PSample = (PART *)calloc(NPoint*NPoint,sizeof(PART)); 00472 int NSample = (int)sqrt(pNPart()); 00473 glColor4f(1.0,.0,1.,1.); 00474 glEnableClientState(GL_VERTEX_ARRAY); 00475 glEnableClientState(GL_NORMAL_ARRAY); 00476 glEnable(GL_VERTEX_ARRAY); 00477 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00478 glFrontFace(GL_CCW); //Tell OGL which orientation shall be the front face 00479 glDeleteLists(Dr->Particles,1); 00480 Dr->Particles = glGenLists(1); 00481 glNewList(Dr->Particles,GL_COMPILE); 00482 //InterSpline3(Pm,PSample,NSample*NSample,NPoint*NPoint); 00483 glVertexPointer(3,GL_DOUBLE,sizeof(PART),&PSample[0].Pos[0]); 00484 glNormalPointer(GL_DOUBLE,sizeof(PART),&PSample[0].Vel[0]); 00485 vector <GLuint> VecIndices; 00486 for(int i=0;i<NPoint-1;i++){ 00487 for(int j=0;j<NPoint-1;j++){ 00488 VecIndices.push_back(i*NPoint + j); 00489 VecIndices.push_back((i+1)*NPoint + j); 00490 VecIndices.push_back((i+1)*NPoint + (j+1)); 00491 00492 VecIndices.push_back(i*NPoint + j); 00493 VecIndices.push_back((i+1)*NPoint + (j+1)); 00494 VecIndices.push_back((i)*NPoint + (j+1)); 00495 } 00496 } 00497 int NIndex = VecIndices.size(); 00498 GLuint *Indices = (GLuint *)calloc(NIndex,sizeof(GLuint)); 00499 for(int i=0;i<NIndex;i++){ 00500 Indices[i] = VecIndices[i]; 00501 } 00502 glDrawElements(GL_TRIANGLES,NIndex,GL_UNSIGNED_INT,Indices); 00503 VecIndices.clear(); 00504 free(Indices); 00505 glEndList(); 00506 return; 00507 } 00508 void ElPoly::DrDoubleTria(Vettore *v00,Vettore *v01,Vettore *v11,Vettore *v10,Vettore *vN){ 00509 glPushMatrix();//Particle 00510 glBegin(GL_TRIANGLES); 00511 // vN->NormalSurf(v00,v01,v11); 00512 // vN->Normalize(); 00513 // glNormal3f(vN->x[0],vN->x[1],vN->x[2]); 00514 // glVertex3d(v00->x[0],v00->x[1],v00->x[2]); 00515 // vN->NormalSurf(v01,v00,v11); 00516 // vN->Normalize(); 00517 // glNormal3f(vN->x[0],vN->x[1],vN->x[2]); 00518 // glVertex3d(v01->x[0],v01->x[1],v01->x[2]); 00519 // vN->NormalSurf(v11,v01,v10); 00520 // vN->Normalize(); 00521 // glNormal3f(vN->x[0],vN->x[1],vN->x[2]); 00522 // glVertex3d(v11->x[0],v11->x[1],v11->x[2]); 00523 // glEnd(); 00524 vN->NormalSurf(v00,v01,v11); 00525 vN->Normalize(); 00526 glNormal3f(vN->x[0],vN->x[1],vN->x[2]); 00527 glVertex3d(v00->x[0],v00->x[1],v00->x[2]); 00528 glVertex3d(v01->x[0],v01->x[1],v01->x[2]); 00529 glVertex3d(v11->x[0],v11->x[1],v11->x[2]); 00530 glEnd(); 00531 glPopMatrix();//Particle 00532 vN->NormalSurf(v00,v11,v10); 00533 vN->Normalize(); 00534 glPushMatrix();//Particle 00535 glBegin(GL_TRIANGLES); 00536 glNormal3f(vN->x[0],vN->x[1],vN->x[2]); 00537 glVertex3d(v00->x[0],v00->x[1],v00->x[2]); 00538 glVertex3d(v11->x[0],v11->x[1],v11->x[2]); 00539 glVertex3d(v10->x[0],v10->x[1],v10->x[2]); 00540 glEnd(); 00541 glPopMatrix();//Particle 00542 } 00543 void ElPoly::DrTria(Vettore *v00,Vettore *v01,Vettore *v11,Vettore *vN){ 00544 vN->NormalSurf(v00,v01,v11); 00545 vN->Normalize(); 00546 glPushMatrix();//Particle 00547 glBegin(GL_TRIANGLES); 00548 glNormal3f(vN->x[0],vN->x[1],vN->x[2]); 00549 glVertex3d(v00->x[0],v00->x[1],v00->x[2]); 00550 glVertex3d(v01->x[0],v01->x[1],v01->x[2]); 00551 glVertex3d(v11->x[0],v11->x[1],v11->x[2]); 00552 glEnd(); 00553 glPopMatrix();//Particle 00554 } 00555 void ElPoly::DrTriaContour(Vettore *v00,Vettore *v01,Vettore *v11){ 00556 glPushMatrix();//Particle 00557 glBegin(GL_LINES); 00558 glVertex3d(v00->x[0],v00->x[1],v00->x[2]); 00559 glVertex3d(v01->x[0],v01->x[1],v01->x[2]); 00560 glEnd(); 00561 glBegin(GL_LINES); 00562 glVertex3d(v01->x[0],v01->x[1],v01->x[2]); 00563 glVertex3d(v11->x[0],v11->x[1],v11->x[2]); 00564 glEnd(); 00565 glBegin(GL_LINES); 00566 glVertex3d(v11->x[0],v11->x[1],v11->x[2]); 00567 glVertex3d(v00->x[0],v00->x[1],v00->x[2]); 00568 glEnd(); 00569 glPopMatrix();//Particle 00570 } 00571 void ElPoly::DrSmooth(double *Plot,int NSample,double Min,double Max){ 00572 if(Dr->IfMaterial){ 00573 glEnable(GL_LIGHTING); 00574 glEnable( GL_LIGHT0 ); 00575 } 00576 else 00577 glDisable(GL_LIGHTING); 00578 double FactC1 = 1./(double)NSample*InvScaleUn*pEdge(CLat1); 00579 double FactC2 = 1./(double)NSample*InvScaleUn*pEdge(CLat2); 00580 double FactCN = InvScaleUn*ScaleFact; 00581 GLfloat Color[4]; 00582 Vettore v00(3); 00583 Vettore v01(3); 00584 Vettore v11(3); 00585 Vettore v10(3); 00586 Vettore vN(3); 00587 Min *= InvScaleUn; 00588 Max *= InvScaleUn; 00589 double Delta = 1./(Max-Min); 00590 for(int s=0;s<NSample-1;s++){ 00591 for(int ss=0;ss<NSample-1;ss++){ 00592 v00.x[CLat1]=(s+.5)*FactC1; 00593 v00.x[CLat2]=(ss+.5)*FactC2; 00594 v00.x[CNorm]=Plot[s*NSample+ss]*FactCN; 00595 v01.x[CLat1]=(s+1.5)*FactC1; 00596 v01.x[CLat2]=(ss+.5)*FactC2; 00597 v01.x[CNorm]=Plot[(s+1)*NSample+ss]*FactCN; 00598 v11.x[CLat1]=(s+1.5)*FactC1; 00599 v11.x[CLat2]=(ss+1.5)*FactC2; 00600 v11.x[CNorm]=Plot[(s+1)*NSample+(ss+1)]*FactCN; 00601 v10.x[CLat1]=(s+.5)*FactC1; 00602 v10.x[CLat2]=(ss+1.5)*FactC2; 00603 v10.x[CNorm]=Plot[s*NSample+ss+1]*FactCN; 00604 //glColor4f(.4,.4,.6,1.); 00605 //DrDoubleTria(&v00,&v01,&v11,&v10,&vN); 00606 glBegin(GL_POLYGON); 00607 vN.NormalSurf(&v00,&v01,&v11); 00608 vN.Normalize(); 00609 glNormal3f(vN.x[0],vN.x[1],vN.x[2]); 00610 double Depth = (v00.x[CNorm]-Min)*Delta*Saturation+ExtParam; 00611 Dr->DepthMap(Depth,Color); 00612 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color); 00613 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color); 00614 glColor4fv(Color); 00615 glVertex3d(v00.x[0],v00.x[1],v00.x[2]); 00616 Depth = (v01.x[CNorm]-Min)*Delta*Saturation+ExtParam; 00617 Dr->DepthMap(Depth,Color); 00618 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color); 00619 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color); 00620 glColor4fv(Color); 00621 glVertex3d(v01.x[0],v01.x[1],v01.x[2]); 00622 Depth = (v11.x[CNorm]-Min)*Delta*Saturation+ExtParam; 00623 Dr->DepthMap(Depth,Color); 00624 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color); 00625 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color); 00626 glColor4fv(Color); 00627 glVertex3d(v11.x[0],v11.x[1],v11.x[2]); 00628 Depth = (v10.x[CNorm]-Min)*Delta*Saturation+ExtParam; 00629 Dr->DepthMap(Depth,Color); 00630 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Color); 00631 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Color); 00632 glColor4fv(Color); 00633 glVertex3d(v10.x[0],v10.x[1],v10.x[2]); 00634 glEnd(); 00635 } 00636 } 00637 glDisable(GL_LIGHTING); 00638 } 00639 void ElPoly::DrSample(int NSample){ 00640 NSample *= 4; 00641 MOMENTI m1 = SampleSurfaceMem(NSample); 00642 printf("plane min=%lf av=%lf max=%lf\n",m1.Min,m1.Uno,m1.Max); 00643 glDeleteLists(Dr->Particles,1); 00644 Dr->Particles = glGenLists(1); 00645 glNewList(Dr->Particles,GL_COMPILE); 00646 DrSmooth(PlotMem,NSample,.9*m1.Min,.9*m1.Max); 00647 glEndList(); 00648 } 00649 void ElPoly::DrStalk(){ 00650 glDeleteLists(Dr->Particles,1); 00651 Dr->Particles = glGenLists(1); 00652 glNewList(Dr->Particles,GL_COMPILE); 00653 glDisable(GL_NORMALIZE); 00654 double Offset = 1./(double)NEdge; 00655 Vettore v1(3); 00656 Vettore v2(3); 00657 Vettore v3(3); 00658 Vettore v4(3); 00659 Vettore vN(3); 00660 glFrontFace(GL_CCW); 00661 //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00662 //glShadeModel(GL_SMOOTH); 00663 for(int p=0,c=0,t=0;p<pNPart();p++){ 00664 if( Ln[p].NLink != 3 ) continue; 00665 if(c == pChain(p)) continue; 00666 if( NPType != BEAD_EVERY && pType(p) != NPType && pType(p) != BEAD_NANO) continue; 00667 c = pChain(p); 00668 double Red = pVel(p,0)*Saturation;// + pPos(p,2)*Sat; 00669 double Green = pVel(p,1)*Saturation; 00670 double Blue = pVel(p,2)*Saturation; 00671 double Alpha = 1.0;//7.+(Green+Blue); 00672 int l1 = Ln[p].Link[0]; 00673 //if(l1 > Gen->NPart) continue; 00674 int l2 = Ln[p].Link[2]; 00675 //if(l2 > Gen->NPart) continue; 00676 int l3 = Ln[p].Link[1]; 00677 // Green = 0.; Blue = 0.; 00678 glColor4f(Red,Green,Blue,Alpha); 00679 v1.x[0]=pPos(p,0)*InvScaleUn; 00680 v1.x[1]=pPos(p,1)*InvScaleUn; 00681 v1.x[2]=pPos(p,2)*InvScaleUn*ScaleFact; 00682 v2.x[0]=pPos(l1,0)*InvScaleUn; 00683 v2.x[1]=pPos(l1,1)*InvScaleUn; 00684 v2.x[2]=pPos(l1,2)*InvScaleUn*ScaleFact; 00685 v3.x[0]=pPos(l3,0)*InvScaleUn; 00686 v3.x[1]=pPos(l3,1)*InvScaleUn; 00687 v3.x[2]=pPos(l3,2)*InvScaleUn*ScaleFact; 00688 v4.x[0]=pPos(l2,0)*InvScaleUn; 00689 v4.x[1]=pPos(l2,1)*InvScaleUn; 00690 v4.x[2]=pPos(l2,2)*InvScaleUn*ScaleFact; 00691 vN.NormalSurf(&v1,&v2,&v3); 00692 vN.Rescale(.2); 00693 glPushMatrix();//Particle 00694 glBegin(GL_QUADS); 00695 glNormal3f(vN.x[0],vN.x[1],-vN.x[2]); 00696 glVertex3d(v4.x[0],v4.x[1],v4.x[2]); 00697 glVertex3d(v3.x[0],v3.x[1],v3.x[2]); 00698 glVertex3d(v2.x[0],v2.x[1],v2.x[2]); 00699 glVertex3d(v1.x[0],v1.x[1],v1.x[2]); 00700 glEnd(); 00701 glPopMatrix();//Particle 00702 } 00703 glEndList(); 00704 } 00705 void ElPoly::DrCreateStalk(){ 00706 int NSample = 24; 00707 double Threshold = 0.; 00708 int NLevel = 4; 00709 double **Plot = (double **) calloc(NLevel,sizeof(double)); 00710 for(int l=0;l<NLevel;l++){ 00711 Plot[l] = (double *)calloc(NSample*NSample,sizeof(double)); 00712 } 00713 Stalk(NSample,NLevel,Plot,Threshold); 00714 //Drawing 00715 glColorMaterial(GL_FRONT_AND_BACK,GL_EMISSION); 00716 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00717 double FactC1 = 1./(double)NSample*InvScaleUn*pEdge(CLat1); 00718 double FactC2 = 1./(double)NSample*InvScaleUn*pEdge(CLat2); 00719 double FactCN = InvScaleUn*ScaleFact; 00720 Vettore v00(3); 00721 Vettore v01(3); 00722 Vettore v11(3); 00723 Vettore v10(3); 00724 Vettore vN(3); 00725 glDeleteLists(Dr->Particles,1); 00726 Dr->Particles = glGenLists(1); 00727 glNewList(Dr->Particles,GL_COMPILE); 00728 for(int s=0;s<NSample-1;s++){ 00729 for(int ss=0;ss<NSample-1;ss++){ 00730 for(int l=0;l<NLevel;l++){ 00731 if(l==0 || l == 3) continue; 00732 glColor4f((double)l*.25,.5,.8,1.); 00733 v00.x[CLat1]=(s+.5)*FactC1; 00734 v00.x[CLat2]=(ss+.5)*FactC2; 00735 v00.x[CNorm]=Plot[l][s*NSample+ss]*FactCN; 00736 v01.x[CLat1]=(s+1.5)*FactC1; 00737 v01.x[CLat2]=(ss+.5)*FactC2; 00738 v01.x[CNorm]=Plot[l][(s+1)*NSample+ss]*FactCN; 00739 v11.x[CLat1]=(s+1.5)*FactC1; 00740 v11.x[CLat2]=(ss+1.5)*FactC2; 00741 v11.x[CNorm]=Plot[l][(s+1)*NSample+ss+1]*FactCN; 00742 v10.x[CLat1]=(s+.5)*FactC1; 00743 v10.x[CLat2]=(ss+1.5)*FactC2; 00744 v10.x[CNorm]=Plot[l][s*NSample+ss+1]*FactCN; 00745 if(Plot[l][(s)*NSample+ss] <= 0.){ 00746 if(l==0) 00747 v00.x[CNorm]=Plot[3][(s)*NSample+ss+1]*FactCN; 00748 if(l==1) 00749 v00.x[CNorm]=Plot[2][(s)*NSample+ss+1]*FactCN; 00750 if(l==2) 00751 v00.x[CNorm]=Plot[1][(s)*NSample+ss+1]*FactCN; 00752 if(l==3) 00753 v00.x[CNorm]=Plot[0][(s)*NSample+ss+1]*FactCN; 00754 if(v00.x[CNorm] <= 0.) continue; 00755 } 00756 if(Plot[l][(s+1)*NSample+ss] <= 0.){ 00757 if(l==0) 00758 v01.x[CNorm]=Plot[3][(s)*NSample+ss]*FactCN; 00759 if(l==1) 00760 v01.x[CNorm]=Plot[2][(s)*NSample+ss]*FactCN; 00761 if(l==2) 00762 v01.x[CNorm]=Plot[1][(s)*NSample+ss]*FactCN; 00763 if(l==3) 00764 v01.x[CNorm]=Plot[0][(s)*NSample+ss]*FactCN; 00765 if(v01.x[CNorm] <= 0.) continue; 00766 } 00767 if(Plot[l][s*NSample+ss+1] <= 0.){ 00768 if(l==0) 00769 v10.x[CNorm]=Plot[3][(s)*NSample+ss]*FactCN; 00770 if(l==1) 00771 v10.x[CNorm]=Plot[2][(s)*NSample+ss]*FactCN; 00772 if(l==2) 00773 v10.x[CNorm]=Plot[1][(s)*NSample+ss]*FactCN; 00774 if(l==3) 00775 v10.x[CNorm]=Plot[0][(s)*NSample+ss]*FactCN; 00776 if(v10.x[CNorm] <= 0.) continue; 00777 } 00778 if(Plot[l][(s+1)*NSample+(ss+1)] <= 0.){ 00779 if(l==0) 00780 v11.x[CNorm]=Plot[3][(s)*NSample+ss+1]*FactCN; 00781 if(l==1) 00782 v11.x[CNorm]=Plot[2][(s)*NSample+ss+1]*FactCN; 00783 if(l==2) 00784 v11.x[CNorm]=Plot[1][(s)*NSample+ss+1]*FactCN; 00785 if(l==3) 00786 v11.x[CNorm]=Plot[0][(s)*NSample+ss+1]*FactCN; 00787 if(v11.x[CNorm] <= 0.) continue; 00788 } 00789 DrDoubleTria(&v00,&v01,&v11,&v10,&vN); 00790 } 00791 } 00792 } 00793 glEndList(); 00794 //Freeing 00795 for(int l=0;l<NLevel;l++){ 00796 free(Plot[l]); 00797 } 00798 free(Plot); 00799 } 00800 void ElPoly::DrSpectrum(){ 00801 int NSample = 32; 00802 double Unity = 1./(double)NSample*pEdge(0)*InvScaleUn; 00803 double *Plot = (double *) calloc(SQR(NSample),sizeof(double)); 00804 double *PlotR = (double *) calloc(SQR(NSample),sizeof(double)); 00805 SampleSurface(Plot,NSample,NChType); 00806 //InterBSpline2D(Plot,PlotR,NSample,NSample); 00807 Spettro2d(Plot,NSample); 00808 double Min = 0.; 00809 double Max = 1000000.; 00810 for(int s=0;s<SQR(NSample);s++){ 00811 Plot[s] += .5*pEdge(CNorm)/ScaleFact; 00812 if(Max < Plot[s]) Max = Plot[s]; 00813 if(Min > Plot[s]) Min = Plot[s]; 00814 } 00815 //Drawing 00816 glDeleteLists(Dr->Particles,1); 00817 Dr->Particles = glGenLists(1); 00818 glNewList(Dr->Particles,GL_COMPILE); 00819 DrSmooth(Plot,NSample,Min,Max); 00820 glEndList(); 00821 //Freeing 00822 free(PlotR); 00823 free(Plot); 00824 return; 00825 double *Points = (double *)calloc(NSample,sizeof(double)); 00826 Spettro2d(Points,NSample,NChType); 00827 double Max1=0.,Max2=0.; 00828 for(int s=0;s<NSample;s++){ 00829 if(Max1 < Points[s]){ 00830 Max2 = Max1; 00831 Max1 = Points[s]; 00832 continue; 00833 } 00834 if(Max2 < Points[s]){ 00835 Max2 = Points[s]; 00836 continue; 00837 } 00838 } 00839 for(int s=0;s<NSample;s++){ 00840 Points[s] /= Max2; 00841 } 00842 //SampleSurface(Plot,NSample,2,CHAIN_DOWN); 00843 for(int s=NSample/2;s<NSample-1;s++){ 00844 glPushMatrix(); 00845 glBegin(GL_LINES); 00846 glColor4f(1.,0.,1.,1.); 00847 glVertex3d((2*s-NSample)*Unity,0.,Points[s]); 00848 glVertex3d((2*(s+1)-NSample)*Unity,0.,Points[s+1]); 00849 glEnd(); 00850 glPopMatrix(); 00851 } 00852 glEndList(); 00853 free(Points); 00854 free(Plot); 00855 } 00856 void ElPoly::DrDerivative(){ 00857 int NSample = 20; 00858 double Unity= 1./(double)NSample*pEdge(0)*InvScaleUn; 00859 SPLINE Weight; 00860 Weight.a0 = 1.; Weight.a1 = 0.; Weight.a2=1.;Weight.a3=0.;Weight.a4=0.; 00861 Matrice *Surface= new Matrice(NSample,NSample); 00862 SampleSurface(Surface,NSample,NChType); 00863 Matrice *Resp = new Matrice(NSample,NSample); 00864 SpatialDerivative(Surface,Resp,Weight,NSample); 00865 glDeleteLists(Dr->Particles,1); 00866 Dr->Particles = glGenLists(1); 00867 glNewList(Dr->Particles,GL_COMPILE); 00868 for(int s=1;s<NSample-2;s++){ 00869 for(int ss=1;ss<NSample-2;ss++){ 00870 //printf("Plot[%d][%d]= %lf\n",s,ss,Plot[s][ss]); 00871 glPushMatrix();//Particle 00872 glColor4f(0.,1.,1.,1.); 00873 glBegin(GL_TRIANGLES); 00874 glNormal3f(0.,0.,1.); 00875 glVertex3d((s+.5)*Unity,(ss+.5)*Unity,Resp->Val(s,ss)*InvScaleUn); 00876 glVertex3d((s+1.5)*Unity,(ss+.5)*Unity,Resp->Val(s+1,ss)*InvScaleUn); 00877 glVertex3d((s+1.5)*Unity,(ss+1.5)*Unity,Resp->Val(s+1,ss+1)*InvScaleUn); 00878 glEnd(); 00879 glPopMatrix();//Particle 00880 glPushMatrix();//Particle 00881 glColor4f(0.5,.0,0.5,1.); 00882 glBegin(GL_TRIANGLES); 00883 glNormal3f(0.,0.,1.); 00884 glVertex3d((s+.5)*Unity,(ss+.5)*Unity,Resp->Val(s,ss)*InvScaleUn); 00885 glVertex3d((s+1.5)*Unity,(ss+1.5)*Unity,Resp->Val(s+1,ss+1)*InvScaleUn); 00886 glVertex3d((s+.5)*Unity,(ss+1.5)*Unity,Resp->Val(s,ss+1)*InvScaleUn); 00887 glEnd(); 00888 glPopMatrix();//Particle 00889 } 00890 } 00891 delete Surface; 00892 delete Resp; 00893 glEndList(); 00894 } 00895 void ElPoly::DrIsoipse(int Values,int NIsoipse,int CoordN){ 00896 if(CoordN < 0 || CoordN > 3) return; 00897 glDeleteLists(Dr->Particles,1); 00898 Dr->Particles = glGenLists(1); 00899 glNewList(Dr->Particles,GL_COMPILE); 00900 double InvIsoipse = 1./(double)NIsoipse; 00901 int Coord1 = (CoordN+1)%3; 00902 int Coord2 = (CoordN+2)%3; 00903 int *Plot = (int *) calloc(Values*Values*NIsoipse,sizeof(int)); 00904 for(int p=0;p<pNPart();p++){ 00905 int v = (int) (pPos(p,Coord1)*NIsoipse/pEdge(Coord1)); 00906 if( v < 0 || v > Values) continue; 00907 int vv = (int) (pPos(p,Coord2)*NIsoipse/pEdge(Coord2)); 00908 if( vv < 0 || vv > Values) continue; 00909 int i = (int) (pPos(p,CoordN)*NIsoipse/pEdge(CoordN)); 00910 if( i < 0 || i > NIsoipse) continue; 00911 Plot[(v*Values + vv)*NIsoipse + i] = p; 00912 } 00913 for(int i=0;i<NIsoipse;i++){ 00914 glBegin(GL_POLYGON); 00915 glNormal3f(0.,0.,1.); 00916 double Zed = i*pEdge(CoordN)*InvIsoipse*InvScaleUn*ScaleFact; 00917 for(int p=0;p<pNPart();p++){ 00918 int v = (int) (pPos(p,CoordN)*NIsoipse/pEdge(CoordN)); 00919 if( v != i) continue; 00920 for(int v=0;v<Values-1;v++){ 00921 int pMin = 0; 00922 int pMax = 0; 00923 for(int vv=0;vv<Values;vv++){ 00924 if(Plot[(v*Values+vv)*NIsoipse+i] == 0 && Plot[(v*Values+vv+1)*NIsoipse+i] != 0) 00925 pMin = Plot[(v*Values+vv+1)*NIsoipse+i]; 00926 if(Plot[(v*Values+vv)*NIsoipse+i] != 0 && Plot[(v*Values+vv+1)*NIsoipse+i] == 0){ 00927 pMax = Plot[(v*Values+vv)*NIsoipse+i]; 00928 break; 00929 } 00930 } 00931 glVertex3d(pPos(pMin,Coord1)*InvScaleUn,pPos(pMin,Coord2)*InvScaleUn,Zed); 00932 glVertex3d(pPos(pMax,Coord1)*InvScaleUn,pPos(pMax,Coord2)*InvScaleUn,Zed); 00933 } 00934 glEnd(); 00935 } 00936 } 00937 free(Plot); 00938 glEndList(); 00939 } 00940 void ElPoly::DrShell(){ 00941 int NSample = 40; 00942 PART *Pn = (PART *)calloc(NSample*NSample,sizeof(PART)); 00943 } 00944 void ElPoly::DrVoronoi(){ 00945 int NDim = 2; 00946 int NCell = pNChain(); 00947 int Batch = 1000; 00948 int DontCreate = 4; 00949 int SampleType = 1;//Halton 00950 int NSample = 1000; 00951 int NItMax = 4; 00952 int NItFix = 1; 00953 int Seme = 4532643; 00954 int NIt = 0; 00955 double ItDiff = 0.; 00956 double Energy = 0.; 00957 double *Pos = (double *)calloc(NCell*NDim,sizeof(double)); 00958 for(int c=0;c<NCell;c++){ 00959 for(int d=0;d<NDim;d++){ 00960 Pos[c*NDim+d] = Ch[c].Pos[d]; 00961 } 00962 } 00963 //cvt(NDim,NCell,Batch,DontCreate,SampleType,NSample,NItMax,NItFix,&Seme,Pos,&NIt,&ItDiff,&Energy); 00964 Hexagon = Dr->DefHexagon(); 00965 glDeleteLists(Dr->Particles,1); 00966 Dr->Particles = glGenLists(1); 00967 glNewList(Dr->Particles,GL_COMPILE); 00968 for(int c=0;c<NCell;c++){ 00969 glPushMatrix(); 00970 glColor4f(.2,.5,.3,1.); 00971 glBegin(GL_POINTS); 00972 glNormal3f(0.,0.,1.); 00973 glVertex3d(Pos[c*NDim+0]*InvScaleUn, 00974 Pos[c*NDim+1]*InvScaleUn,.5*pEdge(2)*InvScaleUn); 00975 glEnd(); 00976 //glCallList(Hexagon); 00977 glPopMatrix(); 00978 glColor4f(.8,.2,.5,1.); 00979 glPushMatrix(); 00980 glTranslated(Ch[c].Pos[0]*InvScaleUn, 00981 Ch[c].Pos[1]*InvScaleUn,.5*pEdge(2)*InvScaleUn); 00982 glCallList(Hexagon); 00983 glPopMatrix(); 00984 } 00985 glEndList(); 00986 } 00987 void ElPoly::DrSurface(){ 00988 DrVoronoi(); 00989 int Vertex = 6; 00990 int **Triangle = (int **)calloc(Vertex+1,sizeof(int)); 00991 for(int v=0;v<Vertex+1;v++){ 00992 *(Triangle+v) = (int *)calloc(pNChain(),sizeof(int)); 00993 } 00994 //Arrange(Triangle,Vertex); 00995 glDeleteLists(Dr->Particles,1); 00996 Dr->Particles = glGenLists(1); 00997 glNewList(Dr->Particles,GL_COMPILE); 00998 for(int c=0;c<pNChain();c++){ 00999 int Chc = Ch[c].Type; 01000 if(!CHAIN_IF_TYPE(Chc,NChType)) continue; 01001 // glBegin(GL_POLYGON); 01002 int l = Triangle[Vertex-1][c]; 01003 int l1 = Triangle[0][c]; 01004 glPushMatrix();//Particle 01005 // double PosX1 = .333*(Ch[l].Pos[0]+Ch[c].Pos[0]+Ch[l1].Pos[0])*InvScaleUn; 01006 // double PosY1 = .333*(Ch[l].Pos[1]+Ch[c].Pos[1]+Ch[l1].Pos[1])*InvScaleUn; 01007 // double PosZ1 = .333*(Ch[l].Pos[2]+Ch[c].Pos[2]+Ch[l1].Pos[2])*InvScaleUn; 01008 for(int v=0;v<Vertex;v++){ 01009 l = Triangle[v][c]; 01010 if(v<Vertex-1) l1 = Triangle[v+1][c]; 01011 else l1 = Triangle[0][c]; 01012 // double PosX = .333*(Ch[l].Pos[0]+Ch[c].Pos[0]+Ch[l1].Pos[0])*InvScaleUn; 01013 // double PosY = .333*(Ch[l].Pos[1]+Ch[c].Pos[1]+Ch[l1].Pos[1])*InvScaleUn; 01014 // double PosZ = .333*(Ch[l].Pos[2]+Ch[c].Pos[2]+Ch[l1].Pos[2])*InvScaleUn; 01015 double Shift[3] = {0.,0.,0.}; 01016 for(int d=0;d<3;d++) Shift[d] = -floor((Ch[c].Pos[d]-Ch[l].Pos[d])/pEdge(d)+.5)*pEdge(d); 01017 glPushMatrix();//Line 01018 glBegin(GL_LINES); 01019 glNormal3f(0.,0.,1.); 01020 glVertex3f(Ch[c].Pos[0]*InvScaleUn,Ch[c].Pos[1]*InvScaleUn,Ch[c].Pos[2]*InvScaleUn*ScaleFact); 01021 glVertex3f((Ch[l].Pos[0]-Shift[0])*InvScaleUn,(Ch[l].Pos[1]-Shift[1])*InvScaleUn,(Ch[l].Pos[2]-Shift[2])*InvScaleUn*ScaleFact); 01022 glEnd(); 01023 //PosX1 = PosX;PosY1=PosY;PosZ1=PosZ; 01024 glPopMatrix();//Line 01025 } 01026 // printf("\n"); 01027 // printf("(%lf %lf %lf) \n",Ch[c].Pos[0],Ch[c].Pos[1],Ch[c].Pos[2]); 01028 glColor4f(1.,1.,0.,1.); 01029 //glEnd(); 01030 glPopMatrix();//Particle 01031 glPushMatrix(); 01032 glTranslated(Ch[c].Pos[0]*InvScaleUn, 01033 Ch[c].Pos[1]*InvScaleUn, 01034 Ch[c].Pos[2]*InvScaleUn*ScaleFact); 01035 glColor4f(1.,0.,0.,1.); 01036 glCallList(Point); 01037 // glutSolidSphere(.05,20,20); 01038 glPopMatrix(); 01039 glPushMatrix();//Info 01040 glColor3f(1.0,1.0,1.0); 01041 // glTranslated(Ch[c].Pos[0]*InvScaleUn,Ch[c].Pos[1]*InvScaleUn,Ch[c].Pos[2]*InvScaleUn); 01042 glRasterPos3f(Ch[c].Pos[0]*InvScaleUn, 01043 Ch[c].Pos[1]*InvScaleUn, 01044 Ch[c].Pos[2]*InvScaleUn*ScaleFact); 01045 char *Numero = (char*)calloc(20,sizeof(char)); 01046 sprintf(Numero,"%d",c);//CalcnPos(Ch[c].Pos)); 01047 for(int i=0;i<strlen(Numero);i++) 01048 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Numero[i]); 01049 free(Numero); 01050 glPopMatrix();//Info 01051 } 01052 glEndList(); 01053 free(Triangle); 01054 // GLuint *Surface = (GLuint *)malloc(3*Gen->NChain*sizeof(GLuint)); 01055 // for(int c=0,cc=0;c<Gen->NChain;c++){ 01056 // for(int d=0;d<3;d++){ 01057 // Surface[3*c+d] = (GLuint) Ch[c].Pos[d]; 01058 // } 01059 // printf("(%u %u %u) (%lf %lf %lf) \n",Surface[3*c+0],Surface[3*c+1],Surface[3*c+2],Ch[c].Pos[0],Ch[c].Pos[1],Ch[c].Pos[2]); 01060 // } 01061 //glEnable(GL_VERTEX_ARRAY); 01062 // glDrawElements(GL_TRIANGLES,Gen->NChain,GL_UNSIGNED_INT,Surface); 01063 //free(Surface); 01064 } 01065 void ElPoly::Tile(){ 01066 double Dx = sqrt(pEdge(CLat1)*pEdge(CLat2)/(double)pNPart()); 01067 int NLat1 = (int)(pEdge(CLat1)/Dx); 01068 int NLat2 = (int)(pEdge(CLat2)/Dx); 01069 printf("Dx %lf NLat1 %d NLat2 %d %d\n",Dx,NLat1,NLat2,SQR(NLat1) + SQR(NLat2)); 01070 if( NLat1*NLat2 != pNPart()) return; 01071 glDeleteLists(Dr->Particles,1); 01072 Dr->Particles = glGenLists(1); 01073 glNewList(Dr->Particles,GL_COMPILE); 01074 Vettore v1(3); 01075 Vettore v2(3); 01076 Vettore v3(3); 01077 Vettore v4(3); 01078 Vettore vN(3); 01079 printf("Ciccia\n"); 01080 for(int nx = 0;nx<NLat1-2;nx+=2){ 01081 for(int ny = 0;ny<NLat2-2;ny+=2){ 01082 int l1 = nx*NLat2 + ny; 01083 int l2 = nx*NLat2 + ny + 1; 01084 int l3 = (nx+1)*NLat2 + ny + 1; 01085 int l4 = (nx+1)*NLat2 + ny; 01086 v1.x[0]=pPos(l1,0)*InvScaleUn; 01087 v1.x[1]=pPos(l1,1)*InvScaleUn; 01088 v1.x[2]=pPos(l1,2)*InvScaleUn*ScaleFact; 01089 v2.x[0]=pPos(l2,0)*InvScaleUn; 01090 v2.x[1]=pPos(l2,1)*InvScaleUn; 01091 v2.x[2]=pPos(l2,2)*InvScaleUn*ScaleFact; 01092 v3.x[0]=pPos(l3,0)*InvScaleUn; 01093 v3.x[1]=pPos(l3,1)*InvScaleUn; 01094 v3.x[2]=pPos(l3,2)*InvScaleUn*ScaleFact; 01095 v4.x[0]=pPos(l4,0)*InvScaleUn; 01096 v4.x[1]=pPos(l4,1)*InvScaleUn; 01097 v4.x[2]=pPos(l4,2)*InvScaleUn*ScaleFact; 01098 vN.NormalSurf(&v1,&v2,&v3); 01099 DrDoubleTria(&v1,&v2,&v3,&v4,&vN); 01100 } 01101 } 01102 glEndList(); 01103 } 01104 void ElPoly::DrIsolevel(int NSample,double IsoLevel){ 01105 NSample = 20; 01106 double VolEl = pVol()/(double)CUB(NSample); 01107 double *Plot = (double *)calloc(CUBE(NSample),sizeof(double)); 01108 double Min = 0.; 01109 double Max = 0.; 01110 VAR_TRIANGLE *Tri = NULL; 01111 for(int p=0;p<pNPart();p++){ 01112 //if(Pm[p].Typ != 1) continue; 01113 double Posx = pPos(p,0) - floor(pPos(p,0)*pInvEdge(0))*pEdge(0); 01114 double Posy = pPos(p,1) - floor(pPos(p,1)*pInvEdge(1))*pEdge(1); 01115 double Posz = pPos(p,2) - floor(pPos(p,2)*pInvEdge(2))*pEdge(2); 01116 int sx = (int)(Posx*pInvEdge(0)*NSample); 01117 int sy = (int)(Posy*pInvEdge(1)*NSample); 01118 int sz = (int)(Posz*pInvEdge(2)*NSample); 01119 int sTot = (sx*NSample+sy)*NSample+sz; 01120 Plot[sTot] += VolEl; 01121 if(Max < Plot[sTot]) Max = Plot[sTot]; 01122 if(Min > Plot[sTot]) Min = Plot[sTot]; 01123 } 01124 //IsoLevel = .1*Max; 01125 printf("Min %lf Max %lf Isolevel %lf\n",Min,Max,IsoLevel); 01126 int NTri = 0; 01127 Tri = MarchingCubes(Plot,NSample,IsoLevel,&NTri); 01128 free(Plot); 01129 int NVertex = CUBE(2*NSample-1); 01130 double *WeightL = (double *) calloc(NVertex,sizeof(double)); 01131 double MaxW = 1.; 01132 for(int t=0;t<NTri;t++){ 01133 int vRef = Tri[t].v[0]; 01134 //printf("%d %lf\n",t,WeightL[vRef]); 01135 } 01136 glDeleteLists(Dr->Particles,1); 01137 Dr->Particles = glGenLists(1); 01138 glNewList(Dr->Particles,GL_COMPILE); 01139 for(int n=0;n<pNNano();n++) DrawNano(n); 01140 for(int t=0;t<NTri;t++){ 01141 //if(Tri[t].p[0].x[2]> Nano->Pos[2] + 3.||Tri[t].p[0].x[2] < Nano->Pos[2] - 3.) continue; 01142 int vRef = Tri[t].v[0]; 01143 double Green = WeightL[vRef]*MaxW + .3 + .4*Mat->Casuale(); 01144 glColor4f(0.1,Green,0.2,1.); 01145 //glColor4f(HueUp[p].r,HueUp[p].g,HueUp[p].b,HueUp[p].a); 01146 glBegin(GL_TRIANGLES); 01147 glNormal3f(Tri[t].n[0].x[0]*InvScaleUn, 01148 Tri[t].n[0].x[1]*InvScaleUn, 01149 Tri[t].n[0].x[2]*InvScaleUn*ScaleFact); 01150 glVertex3f(Tri[t].p[0].x[0]*InvScaleUn, 01151 Tri[t].p[0].x[1]*InvScaleUn, 01152 Tri[t].p[0].x[2]*InvScaleUn*ScaleFact); 01153 glNormal3f(Tri[t].n[1].x[0]*InvScaleUn, 01154 Tri[t].n[1].x[1]*InvScaleUn, 01155 Tri[t].n[1].x[2]*InvScaleUn*ScaleFact); 01156 glVertex3f(Tri[t].p[1].x[0]*InvScaleUn, 01157 Tri[t].p[1].x[1]*InvScaleUn, 01158 Tri[t].p[1].x[2]*InvScaleUn*ScaleFact); 01159 glNormal3f(Tri[t].n[2].x[0]*InvScaleUn, 01160 Tri[t].n[2].x[1]*InvScaleUn, 01161 Tri[t].n[2].x[2]*InvScaleUn*ScaleFact); 01162 glVertex3f(Tri[t].p[2].x[0]*InvScaleUn, 01163 Tri[t].p[2].x[1]*InvScaleUn, 01164 Tri[t].p[2].x[2]*InvScaleUn*ScaleFact); 01165 glEnd(); 01166 if(IfLine){ 01167 glColor4f(0.1,.3,1.,1.); 01168 glBegin(GL_LINES); 01169 glVertex3d(Tri[t].c.x[0]*InvScaleUn, 01170 Tri[t].c.x[1]*InvScaleUn, 01171 Tri[t].c.x[2]*InvScaleUn*ScaleFact); 01172 glVertex3d((Tri[t].c.x[0]+Tri[t].n[0].x[0])*InvScaleUn, 01173 (Tri[t].c.x[1]+Tri[t].n[0].x[1])*InvScaleUn, 01174 (Tri[t].c.x[2]+Tri[t].n[0].x[2])*InvScaleUn*ScaleFact); 01175 glEnd(); 01176 } 01177 } 01178 glEndList(); 01179 free(WeightL); 01180 } 01181 #endif //USE_GL