InputGeneratorJump.hpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // Author: Jim Holmström
00003 // Date:   2002-02-13
00004 //-----------------------------------------------------------------------------
00005 
00006 #ifndef __INPUTGENERATORJUMP_H
00007 #define __INPUTGENERATORJUMP_H
00008 
00009 #include <Random.hpp>
00010 #include "IInputGenerator.hpp"
00011 #include <GNGRepresentation/IGLInputRepresentation.hpp>
00012 
00013 #include <cstdlib>
00014 #include <GL/glut.h>
00015 
00019 class InputGeneratorJump : public IInputGenerator
00020 { 
00021 public:
00022   InputGeneratorJump(IInputGenerator * ig, unsigned int jumpDelay, double scale) : m_inputGenerator(*ig)
00023   {
00024     m_jumpDelay = jumpDelay;
00025     m_scale = scale;
00026     m_steps = 0;
00027 
00028     m_minX = -1 + m_scale;
00029     m_minY = -1 + m_scale;
00030     m_maxX = 1 - m_scale;
00031     m_maxY = 1 - m_scale;
00032   
00033     m_translate.push_back(m_minX);  // start x-position   
00034     m_translate.push_back(m_maxY);  // start y-position
00035 
00036     m_dir.push_back(0.0);
00037     m_dir.push_back(0.0);
00038     
00039     m_vector.push_back(0.0);
00040     m_vector.push_back(0.0);
00041   }
00042   
00043   virtual ~InputGeneratorJump() 
00044   { 
00045     delete &m_inputGenerator; 
00046   }
00047 
00051   virtual Vector GetInput()
00052   {
00053     m_steps++;
00054     // Get input from the input generator, scale and translate.
00055     m_vector = (m_inputGenerator.GetInput() * m_scale) + m_translate;
00056      
00057     // jump from upper left to lower right and vv.
00058     if(m_steps % m_jumpDelay == 0)
00059     {
00060       m_translate[0] = m_translate[0] * -1.0;
00061       m_translate[1] = m_translate[1] * -1.0;
00062     }
00063 
00064     return m_vector;
00065   }
00066   
00072   virtual Vector GetOutput()
00073   {
00074     return m_inputGenerator.GetOutput();
00075   }
00076 
00077   
00081   virtual Vector const & GetLastInput() const { return m_vector; }  
00082 
00086   virtual unsigned int GetDimension() const { return m_inputGenerator.GetDimension(); }
00087 
00091   Vector GetTranslation() { return m_translate; }
00092 
00096   double GetScale() { return m_scale; }
00097 
00101   virtual GeneratorType GetGeneratorType() const { return ClassesGenerator; }
00102   
00103 protected:
00104   double m_scale;
00105   unsigned int m_steps;
00106   unsigned int m_jumpDelay;
00107   Vector m_dir;
00108   Vector m_translate;
00109   Vector m_vector;  
00110   IInputGenerator & m_inputGenerator;
00111   double m_minY;
00112   double m_maxY;
00113   double m_minX;
00114   double m_maxX;
00115 };
00116 
00117 
00121 class InputRepresentationJump : public IGLInputRepresentation
00122 {
00123 public:
00124   InputRepresentationJump(InputGeneratorJump * i, IGLInputRepresentation * ir)
00125   : m_inputGenerator(*i), m_inputRepresentation(*ir) { }
00126 
00127   virtual ~InputRepresentationJump() 
00128     { 
00129         delete &m_inputRepresentation; 
00130     }
00131   
00132   virtual void GLOutputDistribution() const
00133   {
00134     Vector translate(2);
00135     translate = m_inputGenerator.GetTranslation();
00136     double scale = m_inputGenerator.GetScale();
00137 
00138     glPushMatrix();
00139      glTranslatef(translate[0], translate[1], 0);
00140      glScalef(scale, scale, 0);
00141      m_inputRepresentation.GLOutputDistribution();
00142     glPopMatrix();
00143   }
00144   
00145   virtual void GLOutputSignal() const
00146   {
00147     // draw the last input point.
00148     Vector const & v = m_inputGenerator.GetLastInput();
00149     glBegin(GL_POINTS);
00150     {           
00151       glVertex2d(v[0], v[1]);
00152     }    
00153     glEnd();
00154   }
00155   
00156 private:
00157   InputGeneratorJump & m_inputGenerator;
00158   IGLInputRepresentation & m_inputRepresentation;
00159 };
00160 
00161 #endif
00162 

Generated on Mon Mar 22 16:40:48 2004 for GNG_GL by doxygen 1.3.6