Esempio n. 1
0
 public NeuronBackPointer(INeuron neuron, INeuronContainer container, NeuralLink[] links)
 {
     this.Neuron = neuron;
     this.Container = container;
     this.Links = links;
 }
Esempio n. 2
0
        /// <summary>
        /// This is used when saving to DNA.
        /// Individual parts don't hold links, so when you call PartBase.GetNewDNA, the links will always be null.
        /// This populates dna.InternalLinks and dna.ExternalLinks based on the links stored in outputs.
        /// </summary>
        /// <param name="dna">This is the dna to populate</param>
        /// <param name="dnaSource">This is the container that the dna came from</param>
        /// <param name="outputs">This is all of the containers, and their links</param>
        public static void PopulateDNALinks(ShipPartDNA dna, INeuronContainer dnaSource, IEnumerable<ContainerOutput> outputs)
        {
            // Find the output for the source passed in
            ContainerOutput output = outputs.Where(o => o.Container == dnaSource).FirstOrDefault();
            if (output == null)
            {
                return;
            }

            // Internal
            dna.InternalLinks = null;
            if (output.InternalLinks != null)
            {
                dna.InternalLinks = output.InternalLinks.Select(o => new NeuralLinkDNA()
                    {
                        From = o.From.Position,
                        To = o.To.Position,
                        Weight = o.Weight,
                        BrainChemicalModifiers = o.BrainChemicalModifiers == null ? null : o.BrainChemicalModifiers.ToArray()		// using ToArray to make a copy
                    }).ToArray();
            }

            // External
            dna.ExternalLinks = null;
            if (output.ExternalLinks != null)
            {
                dna.ExternalLinks = output.ExternalLinks.Select(o => new NeuralLinkExternalDNA()
                    {
                        FromContainerPosition = o.FromContainer.Position,
                        FromContainerOrientation = o.FromContainer.Orientation,
                        From = o.From.Position,
                        To = o.To.Position,
                        Weight = o.Weight,
                        BrainChemicalModifiers = o.BrainChemicalModifiers == null ? null : o.BrainChemicalModifiers.ToArray()		// using ToArray to make a copy
                    }).ToArray();
            }
        }
Esempio n. 3
0
 public NeuralLink(INeuronContainer fromContainer, INeuronContainer toContainer, INeuron from, INeuron to, double weight, double[] brainChemicalModifiers)
 {
     this.FromContainer = fromContainer;
     this.ToContainer = toContainer;
     this.From = from;
     this.To = to;
     this.Weight = weight;
     this.BrainChemicalModifiers = brainChemicalModifiers;
 }
Esempio n. 4
0
 public ContainerOutput(INeuronContainer container, NeuralLink[] internalLinks, NeuralLink[] externalLinks)
 {
     this.Container = container;
     this.InternalLinks = internalLinks;
     this.ExternalLinks = externalLinks;
 }
Esempio n. 5
0
 public ContainerInput(long token, INeuronContainer container, NeuronContainerType containerType, Point3D position, Quaternion orientation, double? internalRatio, Tuple<NeuronContainerType, ExternalLinkRatioCalcType, double>[] externalRatios, int brainChemicalCount, NeuralLinkDNA[] internalLinks, NeuralLinkExternalDNA[] externalLinks)
 {
     this.Token = token;
     this.Container = container;
     this.ContainerType = containerType;
     this.Position = position;
     this.Orientation = orientation;
     this.InternalRatio = internalRatio;
     this.ExternalRatios = externalRatios;
     this.BrainChemicalCount = brainChemicalCount;
     this.InternalLinks = internalLinks;
     this.ExternalLinks = externalLinks;
 }
        private static Transform3D GetContainerTransform(Dictionary<INeuronContainer, Transform3D> existing, INeuronContainer container)
        {
            if (!existing.ContainsKey(container))
            {
                Transform3DGroup transform = new Transform3DGroup();
                transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(container.Orientation)));
                transform.Children.Add(new TranslateTransform3D(container.Position.ToVector()));
                existing.Add(container, transform);
            }

            return existing[container];
        }
        private static void BuildNeuronVisuals(out List<Tuple<INeuron, SolidColorBrush>> outNeurons, out ModelVisual3D model, IEnumerable<INeuron> inNeurons, INeuronContainer container, ItemColors colors)
        {
            outNeurons = new List<Tuple<INeuron, SolidColorBrush>>();

            Model3DGroup geometries = new Model3DGroup();

            int neuronCount = inNeurons.Count();
            double neuronRadius;
            if (neuronCount < 20)
            {
                neuronRadius = .03d;
            }
            else if (neuronCount > 100)
            {
                neuronRadius = .007d;
            }
            else
            {
                neuronRadius = UtilityCore.GetScaledValue(.03d, .007d, 20, 100, neuronCount);
            }

            foreach (INeuron neuron in inNeurons)
            {
                MaterialGroup material = new MaterialGroup();
                SolidColorBrush brush = new SolidColorBrush(neuron.IsPositiveOnly ? colors.Neuron_Zero_ZerPos : colors.Neuron_Zero_NegPos);
                DiffuseMaterial diffuse = new DiffuseMaterial(brush);
                material.Children.Add(diffuse);
                material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80C0C0C0")), 50d));

                GeometryModel3D geometry = new GeometryModel3D();
                geometry.Material = material;
                geometry.BackMaterial = material;
                geometry.Geometry = UtilityWPF.GetSphere_LatLon(2, neuronRadius);
                geometry.Transform = new TranslateTransform3D(neuron.Position.ToVector());

                geometries.Children.Add(geometry);

                outNeurons.Add(new Tuple<INeuron, SolidColorBrush>(neuron, brush));
            }

            model = new ModelVisual3D();
            model.Content = geometries;
            //model.Transform = new TranslateTransform3D(position.ToVector());
            model.Transform = GetContainerTransform(new Dictionary<INeuronContainer, Transform3D>(), container);
        }
        private static Transform3D GetContainerTransform(Dictionary<INeuronContainer, Transform3D> existing, INeuronContainer container, Vector3D centerOffset)
        {
            if (!existing.ContainsKey(container))
            {
                Transform3DGroup transform = new Transform3DGroup();

                // Get the largest neuron position, and create a scale so that it fits inside of the container's scale
                double maxRadius = Math.Sqrt(container.Neruons_All.Max(o => o.Position.ToVector().LengthSquared));

                if (maxRadius > container.Radius && !Math1D.IsNearZero(maxRadius))
                {
                    double scale = container.Radius / maxRadius;

                    transform.Children.Add(new ScaleTransform3D(new Vector3D(scale, scale, scale)));		// this needs to be added to the group before the others?
                }

                transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(container.Orientation)));
                transform.Children.Add(new TranslateTransform3D(centerOffset + container.Position.ToVector()));

                existing.Add(container, transform);
            }

            return existing[container];
        }