Allink  v0.1
Animation.cpp
00001 #include "DrEffect.h"
00002 #ifdef __glut_h__
00003 DrEffect *DrE;
00004 void Animation::DrMessage(const char * s, ...)
00005 {
00006 #ifdef DEBUG
00007   va_list args;
00008   va_start(args, s);
00009   vfprintf(stderr, s, args);
00010   fprintf(stderr, "\n");
00011   va_end(args);
00012 #else
00013   return;
00014 #endif
00015 }
00016 void ParticleList(){
00017   //Pol->RenderPart();
00018 }
00019 void ParticleRealTime(){
00020   return;
00021 }
00022 void reshape(int w,int h){
00023   DrE->Dreshape(w,h);
00024 }
00025 void Timer(int v){
00026   DrE->DTimer(v);
00027 }
00028 void MouseMove(int x,int y){
00029   DrE->DMouseMove(x,y);
00030 }
00031 void mouse(int button, int state,int x,int y){
00032   DrE->Dmouse(button,state,x,y);
00033 };
00034 void special(int k, int x, int y){
00035   DrE->Dspecial(k,x,y);
00036 }
00037 void Slide(){}
00038 void DrawParticles(){}
00039 void Particle(){}
00040 void keyboard(unsigned char key,int x, int y){
00041   DrE->keyboardDraw(key);
00042 }
00043 void Menu(){}
00044 void Figure(){
00045   //Dr->Draw1();
00046   DrE->ShowImage();
00047 }
00048 void Figure1(){
00049   DrE->Draw1();
00050 }
00051 Animation::Animation(QWidget *parent): QGLWidget(parent){
00052   FileName = new char[160];
00053   DrE = new DrEffect();
00054   st = DrE->Hist;
00055   sprintf(FileName,"RadDistrNanoR3.8H0.5.tif");
00056   xRot = 0;
00057   yRot = 0;
00058   zRot = 0;
00059   Grana = 0;
00060   NVar=0;
00061   NMass=0;
00062   Valori = 20;
00063   v1 = new VarDatFile(NMass,NVar,Valori);
00064 }
00065 void Animation::initializeGL(){
00066   DrMessage("Animation.InitialiezeGL");
00067   DrE->Window();return;  //Dr->OpenImage(FileName);
00068   //qglClearColor(trolltechPurple.dark());
00069   //object = makeObject();
00070   glClearColor(.0,.0,.0,.0);//colore sfondo
00071   glShadeModel(GL_SMOOTH);// Enables Smooth Shading
00072   glClearDepth(1.0f);// Depth Buffer Setup
00073   glEnable(GL_DEPTH_TEST);//Controllo di profondit`a
00074   //  glDepthMask(GL_FALSE);
00075   //  glDepthRange(0,-10.);
00076   glDepthFunc(GL_LEQUAL);// The Type Of Depth Test To Do
00077   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00078   glEnable(GL_CULL_FACE);
00079 }
00080 void Animation::NomeFile(const QString &S){
00081   DrMessage("Animation.NomeFile");
00082   sprintf(FileName,"%s",S.ascii());
00083 }
00084 void Animation::NomeFile(char *ExtName){
00085   DrMessage("Animation.NomeFile");
00086   sprintf(FileName,"%s",ExtName);
00087   Open();
00088 }
00089 void Animation::Open(){
00090   DrMessage("Animation.Open");
00091   DrE->OpenImage(FileName);
00092   paintGL();
00093   repaint();
00094 }
00095 void Animation::Filter(){
00096   DrMessage("Animation.Filter");
00097   //DrE->Edges();
00098   DrE->EffectFilter();
00099   paintGL();
00100   repaint();
00101 }
00102 void Animation::Motion(){
00103   DrMessage("Animation.Motion");
00104   DrE->EffectMotion();
00105   paintGL();
00106   repaint();
00107 }
00108 void Animation::FilterContrast(){
00109   DrMessage("Animation.FilterContrast");
00110   DrE->Contrast();
00111   paintGL();
00112   repaint();
00113 }
00114 void Animation::FilterIncrease(){
00115   DrMessage("Animation.FilterIncrease");
00116   DrE->EffectIncrease();
00117   paintGL();
00118   repaint();
00119 }
00120 void Animation::FilterMC(){
00121   DrMessage("Animation.FilterMC");
00122   DrE->EffectMC();
00123   paintGL();
00124   repaint();
00125 }
00126 void Animation::IncrSlide(){
00127   DrMessage("Animation.IncrSlide");
00128   Slide++;
00129   paintGL();
00130   repaint();
00131 }
00132 void Animation::FilterCoarseGrain(){
00133   DrMessage("Animation.FilterCoarseGrain");
00134   DrE->EffectCoarseGrain(Grana);
00135   paintGL();
00136   repaint();
00137 }
00138 void Animation::Run(){
00139   DrMessage("Animation.Run");
00140   DrE->Run();
00141 }
00142 void Animation::ImpGrana(int ExtGrana){
00143   if(Grana < 0 || Grana > 32) return;
00144   Grana = ExtGrana;
00145 }
00146 void Animation::resizeGL(int width,int height){
00147   DrMessage("Animation.resizeGL");
00148   DrE->Dreshape(width,height);return;
00149   int side = qMin(width, height);
00150   glViewport((width - side) / 2, (height - side) / 2, side, side);
00151   glMatrixMode(GL_PROJECTION);
00152   glLoadIdentity();
00153   gluPerspective(60,(GLfloat) width/(GLfloat) height,.1,200.);//ang,rapp,zmin,zmax  
00154   //glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
00155   glMatrixMode(GL_MODELVIEW);
00156 }
00157 void Animation::paintGL(){
00158   DrMessage("Animation.paintGL");
00159   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00160   glLoadIdentity();
00161   //glPushMatrix();
00162   glTranslatef(0.,0.,-.6);
00163   glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
00164   glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
00165   glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
00166   glColor4f(.0,1.0,.0,1.);
00167   DrE->ShowImage();
00168   //  glutWireCube((GLfloat).5);
00169   //  Dr->Draw1();
00170   //glutSolidSphere(.1,20,20);
00171   //glPopMatrix();
00172 }
00173 void Animation::paintEvent(QPaintEvent (event)){
00174   DrMessage("Animation.paintEvent");
00175   QPainter p(this);
00176   //paintGL();
00177 } 
00178 void Animation::mousePressEvent(QMouseEvent *event)
00179 {
00180   lastPos = event->pos();
00181 }
00182 void Animation::mouseMoveEvent(QMouseEvent *event){
00183   //  Dr->DMouseMove(event->x(),event->y());return;
00184   int dx = event->x() - lastPos.x();
00185   int dy = event->y() - lastPos.y();
00186   
00187   if (event->buttons() & Qt::LeftButton) {
00188     setXRotation(xRot + 8 * dy);
00189     setYRotation(yRot + 8 * dx);
00190   } else if (event->buttons() & Qt::RightButton) {
00191     setXRotation(xRot + 8 * dy);
00192     setZRotation(zRot + 8 * dx);
00193   }
00194   lastPos = event->pos();
00195 }
00196 void Animation::setXRotation(int angle)
00197 {
00198   //normalizeAngle(&angle);
00199   if (angle != xRot) {
00200     xRot = angle;
00201     emit xRotationChanged(angle);
00202     updateGL();
00203   }
00204 }
00205 void Animation::setYRotation(int angle)
00206 {
00207   //normalizeAngle(&angle);
00208   if (angle != yRot) {
00209     yRot = angle;
00210     emit yRotationChanged(angle);
00211     updateGL();
00212   }
00213 }
00214 void Animation::setZRotation(int angle)
00215 {
00216   //normalizeAngle(&angle);
00217   if (angle != zRot) {
00218     zRot = angle;
00219     emit zRotationChanged(angle);
00220     updateGL();
00221   }
00222 }
00223 void Animation::Histo(){
00224   DrMessage("Animation.Histo");
00225   DrE->Histo();
00226   st = DrE->Hist;
00227   NMass = DrE->NChar;
00228   NVar = DrE->NLevel;
00229   Valori = 20;
00230   return ;
00231   delete v1;
00232   v1 = new VarDatFile(st,NMass,NVar,Valori);
00233   v1->ScriviTutto("Histo.dat",0,1.,1.);
00234   //Punta();
00235 }
00236 void Animation::NablaPhi(){
00237   DrMessage("Animation.NablaPhi");
00238   DrE->NablaPhi();
00239   st = DrE->Phi;
00240   NMass = DrE->BuffSize();
00241   NVar = 2;
00242   Valori = 100;
00243   delete v1;
00244   v1 = new VarDatFile(st,NMass,NVar,Valori);
00245   v1->ScriviTutto("NablaPhi.dat",0,1.,1.);
00246   v1->ScriviTutto("NablaPhiLogLog.dat",0,1.,1.);
00247   //Punta();
00248 }
00249 void Animation::Punta(){
00250   delete v1;
00251   v1 = new VarDatFile(st,NMass,NVar,Valori);
00252   DrMessage("Animation.Punta");
00253   emit PuntaCoord(st,NMass,NVar,Valori);
00254   //emit PuntaCoord(v1);
00255 }
00256 void Animation::BlackWhite(){
00257   DrMessage("Animation.BlackWhite");
00258   DrE->BlackWhite();
00259   repaint();
00260 }
00261 void Animation::Binary(){
00262   DrMessage("Animation.Binary");
00263   DrE->Binary(0);
00264   repaint();
00265 }
00266 
00267 #endif// __glut_h__