00001 //----------------------------------------------------------------------------- 00002 // Author: Jim Holmström 00003 // Date: 2002-02-13 00004 //----------------------------------------------------------------------------- 00005 00006 #ifndef __INPUTGENERATORUPDOWN_H 00007 #define __INPUTGENERATORUPDOWN_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 InputGeneratorUpDown : public IInputGenerator 00020 { 00021 public: 00022 InputGeneratorUpDown(IInputGenerator * ig, double stepSize, double scale) : m_inputGenerator(*ig) 00023 { 00024 m_stepSize = stepSize; // move stepSize each GetInput call 00025 m_scale = scale; 00026 00027 m_minY = -1 + m_scale; 00028 m_maxY = 1 - m_scale; 00029 00030 // The movement of the distribution is represented by a position along the 00031 // edge of the line (0, maxY) to (0, minY) 00032 m_translate.push_back(0); // start x-position 00033 m_translate.push_back(m_maxY); // start y-position 00034 00035 m_dir.push_back(0.0); 00036 m_dir.push_back(0.0); 00037 00038 m_vector.push_back(0.0); 00039 m_vector.push_back(0.0); 00040 } 00041 00042 virtual ~InputGeneratorUpDown() 00043 { 00044 delete &m_inputGenerator; 00045 } 00046 00047 00051 virtual Vector GetInput() 00052 { 00053 static int currentDir = -1; // starts by moving down. 00054 00055 // Get input from the input generator, scale and translate. 00056 m_vector = (m_inputGenerator.GetInput() * m_scale) + m_translate; 00057 00058 // down 00059 if(m_translate[1] > m_minY && currentDir == -1) 00060 { 00061 m_dir[0] = 0.0; 00062 m_dir[1] = -m_stepSize; 00063 } 00064 else // up 00065 if(m_translate[1] < m_maxY && currentDir == 1) 00066 { 00067 m_dir[0] = 0.0; 00068 m_dir[1] = m_stepSize; 00069 } 00070 else // change direction 00071 currentDir = currentDir * -1; 00072 00073 m_translate = m_translate + m_dir; 00074 00075 return m_vector; 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 double m_stepSize; 00106 Vector m_dir; 00107 Vector m_translate; 00108 Vector m_vector; 00109 IInputGenerator & m_inputGenerator; 00110 double m_minY; 00111 double m_maxY; 00112 }; 00113 00114 00118 class InputRepresentationUpDown : public IGLInputRepresentation 00119 { 00120 public: 00121 InputRepresentationUpDown(InputGeneratorUpDown * i, IGLInputRepresentation * ir) 00122 : m_inputGenerator(*i), m_inputRepresentation(*ir) { } 00123 00124 virtual ~InputRepresentationUpDown() 00125 { 00126 delete &m_inputRepresentation; 00127 } 00128 00129 virtual void GLOutputDistribution() const 00130 { 00131 Vector translate(2); 00132 translate = m_inputGenerator.GetTranslation(); 00133 double scale = m_inputGenerator.GetScale(); 00134 00135 glPushMatrix(); 00136 glTranslatef(translate[0], translate[1], 0); 00137 glScalef(scale, scale, 0); 00138 m_inputRepresentation.GLOutputDistribution(); 00139 glPopMatrix(); 00140 } 00141 00142 virtual void GLOutputSignal() const 00143 { 00144 // draw the last input point. 00145 Vector const & v = m_inputGenerator.GetLastInput(); 00146 glBegin(GL_POINTS); 00147 { 00148 glVertex2d(v[0], v[1]); 00149 } 00150 glEnd(); 00151 } 00152 00153 private: 00154 InputGeneratorUpDown & m_inputGenerator; 00155 IGLInputRepresentation & m_inputRepresentation; 00156 }; 00157 00158 #endif 00159