InputGeneratorDefaultNonstationary.hpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // Author: Jim Holmström
00003 // Date:   2002-02-13
00004 //-----------------------------------------------------------------------------
00005 
00006 #ifndef __INPUTGENERATORDEFAULTNONSTATIONARY_H
00007 #define __INPUTGENERATORDEFAULTNONSTATIONARY_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 InputGeneratorDefaultNonstationary : public IInputGenerator
00020 { 
00021 public:
00022   InputGeneratorDefaultNonstationary(IInputGenerator * ig, double stepSize, double scale) 
00023   : m_inputGenerator(*ig)
00024   {
00025     m_stepSize = stepSize; // move stepSize each GetInput call
00026     m_scale = scale;
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     // The movement of the distribution is represented by a position along the
00034     //   edge of the square (maxX, maxY) to (minX, minY)
00035     m_translate.push_back(m_maxX);  // start x-position   
00036     m_translate.push_back(m_maxY);  // start y-position
00037 
00038     m_dir.push_back(0.0);
00039     m_dir.push_back(0.0);
00040     
00041     m_vector.push_back(0.0);
00042     m_vector.push_back(0.0);
00043   }
00044 
00045   virtual ~InputGeneratorDefaultNonstationary() 
00046     { 
00047         delete &m_inputGenerator; 
00048     }
00049   
00053   virtual Vector GetInput()
00054   {
00055     //m_vector[0] = Random::Randomize() * m_scale / 2.0 + m_translate[0];
00056     //m_vector[1] = Random::Randomize() * m_scale / 2.0 + m_translate[1];
00057 
00058     // Get input from the input generator, scale and translate.
00059     m_vector = (m_inputGenerator.GetInput() * m_scale) + m_translate;
00060     
00061     // left
00062     if(m_translate[1] >= m_maxY && m_translate[0] > m_minX)
00063     {
00064       m_dir[0] = -m_stepSize;
00065       m_dir[1] = 0.0;
00066     }
00067     else // down
00068     if(m_translate[1] > m_minY && m_translate[0] <= m_minX)
00069     {
00070       m_dir[0] = 0.0;
00071       m_dir[1] = -m_stepSize;
00072     }
00073     else // right
00074     if(m_translate[1] <= m_minY && m_translate[0] < m_maxX)
00075     {
00076       m_dir[0] = m_stepSize;
00077       m_dir[1] = 0.0;
00078     }
00079     else // up
00080     if(m_translate[1] < m_maxY && m_translate[0] >= m_maxX)
00081     {
00082       m_dir[0] = 0.0;
00083       m_dir[1] = m_stepSize;
00084     }
00085     
00086     m_translate = m_translate + m_dir;
00087 
00088     return m_vector;
00089   }
00090 
00096   virtual Vector GetOutput()
00097   {
00098     return m_inputGenerator.GetOutput();
00099   }
00100  
00104   virtual Vector const & GetLastInput() const { return m_vector; }  
00105 
00109   virtual unsigned int GetDimension() const { return m_inputGenerator.GetDimension(); }
00110 
00114   Vector GetTranslation() { return m_translate; }
00115 
00119   double GetScale() { return m_scale; }
00120 
00124   virtual GeneratorType GetGeneratorType() const { return ClassesGenerator; }
00125 
00126   
00127 protected:
00128   double m_scale;
00129   double m_stepSize;
00130   Vector m_dir;
00131   Vector m_translate;
00132   Vector m_vector;  
00133   IInputGenerator & m_inputGenerator;
00134   double m_minX;
00135   double m_minY;
00136   double m_maxX;
00137   double m_maxY;
00138 };
00139 
00140 
00144 class InputRepresentationDefaultNonstationary : public IGLInputRepresentation
00145 {
00146 public:
00147   InputRepresentationDefaultNonstationary(InputGeneratorDefaultNonstationary * i, IGLInputRepresentation * ir)
00148   : m_inputGenerator(*i), m_inputRepresentation(*ir) { }
00149   
00150   virtual ~InputRepresentationDefaultNonstationary() 
00151     { 
00152         delete &m_inputRepresentation; 
00153     }
00154   
00155   virtual void GLOutputDistribution() const
00156   {
00157     Vector translate(2);
00158     translate = m_inputGenerator.GetTranslation();
00159     double scale = m_inputGenerator.GetScale();
00160 
00161     glPushMatrix();
00162      glTranslatef(translate[0], translate[1], 0);
00163      glScalef(scale, scale, 0);
00164      m_inputRepresentation.GLOutputDistribution();
00165     glPopMatrix();
00166   }
00167   
00168   virtual void GLOutputSignal() const
00169   {
00170     // draw the last input point.
00171     Vector const & v = m_inputGenerator.GetLastInput();
00172     glBegin(GL_POINTS);
00173     {           
00174       glVertex2d(v[0], v[1]);
00175     }    
00176     glEnd();
00177   }
00178   
00179 private:
00180   InputGeneratorDefaultNonstationary & m_inputGenerator;
00181   IGLInputRepresentation &             m_inputRepresentation;
00182 };
00183 
00184 #endif
00185 

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