Example #1
0
        public void SaveToFile(string filename, IList <byte> input, IList <INeuron> neurons, int width, int height)
        {
            var model = new SomFileModel
            {
                Neurons = neurons,
                Height  = height,
                Width   = width,
                Input   = input
            };

            SaveToFile(filename, model);
        }
Example #2
0
        private void SaveToFile(string filename, SomFileModel model)
        {
            using (var outputFile = new BinaryWriter(new FileStream(filename, FileMode.OpenOrCreate)))
            {
                outputFile.Write((byte)(model.Neurons.Count - 1));
                foreach (var neuron in model.Neurons)
                {
                    outputFile.Write(neuron.R);
                    outputFile.Write(neuron.G);
                    outputFile.Write(neuron.B);
                }

                outputFile.Write(model.Width);
                outputFile.Write(model.Height);

                var  former = model.Input[0];
                byte count  = 0;

                for (var i = 0; i < model.Input.Count; i++)
                {
                    if (model.Input[i] == former && count < byte.MaxValue)
                    {
                        count++;

                        if (i == model.Input.Count - 1)
                        {
                            outputFile.Write(former);
                            outputFile.Write(count);
                        }
                    }
                    else
                    {
                        outputFile.Write(former);
                        outputFile.Write(count);

                        former = model.Input[i];
                        count  = 1;
                    }
                }
            }
        }