From e6ab4a8ed100d5d5b7611c74cf3ccd556f1f1d71 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Thu, 29 Feb 2024 19:04:34 +0100 Subject: Initial commit --- plugins/CppnExplorer/include/CppnExplorer.hpp | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 plugins/CppnExplorer/include/CppnExplorer.hpp (limited to 'plugins/CppnExplorer/include') diff --git a/plugins/CppnExplorer/include/CppnExplorer.hpp b/plugins/CppnExplorer/include/CppnExplorer.hpp new file mode 100644 index 0000000..5ca20c5 --- /dev/null +++ b/plugins/CppnExplorer/include/CppnExplorer.hpp @@ -0,0 +1,129 @@ +#ifndef __CPPN_EXPLORER_HPP__ +#define __CPPN_EXPLORER_HPP__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace hyperneat +{ + class CppnExplorer + { + public: + CppnExplorer(); + ~CppnExplorer(); + + void run(const Genome& genome, const NeuralNetPrms* nnPrms = nullptr, sf::RenderTarget* target = nullptr); + void shutdown(); + void draw(); + + // void run(const Genome& genome, const NeuralNetPrms& nnPrms); + // void shutdown(); + + private: + void windowHandler(); + void eventHandler(); + void neuralNetGenerator(); + void fieldGenerator(); + + class Neuron + { + public: + Neuron(const NeuralNet::Neuron& refNeuron); + + sf::VertexArray _synapses = sf::VertexArray(sf::Lines); + sf::CircleShape _nucleus = sf::CircleShape(4.0f * PIXEL_SIZE, 12); + }; + + Cppn _cppn; + Genome _genome; + NeuralNetPrms _nnPrms; + Vector _neurons; + NeuralNet _neuralNet; + bool _withNeuralNet = false; + Atomic _neuralNetReady = {false}; + + sf::RenderWindow _window; + Atomic _windowOpen = {false}; + sf::RenderTarget* _target = nullptr; + const sf::Color _uiColor = {255, 255, 255, 8}; + + sf::Image _fieldImage; + sf::RectangleShape _fieldSprite; + sf::Texture _fieldTexture; + size_t _currentField = 0; + Atomic _fieldReady = {false}; + + Thread _windowHandler; + Thread _fieldGenerator; + Thread _neuralNetGenerator; + + static constexpr unsigned RESOLUTION = 512; + static constexpr float PIXEL_SIZE = 1.0f / static_cast(RESOLUTION); + + // class Neuron + // { + // public: + // enum class Type { + // INPUT, + // HIDDEN, + // OUTPUT + // }; + + // Type _type; + // sf::CircleShape _body = sf::CircleShape(0.0f, 30); + // sf::CircleShape _nucleus = sf::CircleShape(0.0f, 30); + // sf::VertexArray _synapses = sf::VertexArray(sf::Lines); + // }; + + // void print(const sf::Color* field); + // void placeCursorAt(const sf::Vector2f& newPos); + // void createNeuron(Neuron& repNeuron, const NeuralNet::Neuron& srcNeuron); + + // Cppn _cppn; + // Genome _genome; + // NeuralNet _neuralNet; + // NeuralNetPrms _nnPrms; + + // const unsigned RESOLUTION = 512; + // sf::RenderWindow _window; + // Atomic _running; + // Thread _executor; + + // const sf::Color WEIGHTS = { 128, 0, 255 }; + // const sf::Color INV_WEIGHTS = { 255, 0, 128 }; + // const sf::Color BIAS = { 0, 255, 255 }; + // const sf::Color* _field = &WEIGHTS; + + // sf::Image _valueImage; + // sf::Texture _valueTexture; + // sf::RectangleShape _valueSprite; + // sf::Image _biasImage; + // sf::Texture _biasTexture; + // sf::RectangleShape _biasSprite; + // bool _showBias = false; + + // const sf::Color _uiColor = { 64, 64, 64 }; + // const float PIXEL = 1.0f / static_cast(RESOLUTION); + + // sf::Vector2f _cursorPos = { 0.0f, 0.0f }; + // sf::RectangleShape _cursorH = sf::RectangleShape(sf::Vector2f(0.2f, PIXEL * 3.0f)); + // sf::RectangleShape _cursorV = sf::RectangleShape(sf::Vector2f(PIXEL * 3.0f, 0.2f)); + // sf::VertexArray _grid = sf::VertexArray(sf::Lines); + + // bool _showField = true; + // bool _showNeurons = true; + // bool _showGrid = true; + // Vector _neurons; + }; +} + +#endif -- cgit v1.2.1