private NeuralVisuals CreateNeuralVisuals()
        {
            NeuralVisuals retVal = new NeuralVisuals();

            Dictionary<INeuronContainer, Transform3D> containerTransforms = new Dictionary<INeuronContainer, Transform3D>();

            #region Neurons

            foreach (PartBase part in _parts)
            {
                if (!(part is INeuronContainer))
                {
                    continue;
                }

                NeuralContainerVisual container = new NeuralContainerVisual();
                container.Container = (INeuronContainer)part;

                // Neurons
                ModelVisual3D model;
                BuildNeuronVisuals(out container.Neurons, out model, container.Container.Neruons_All, container.Container, containerTransforms, _itemColors, _centerOffset);
                container.NeuronVisual = model;

                retVal.Containers.Add(container);
            }

            #endregion
            #region Links

            if (_neuronLinks != null)
            {
                Model3DGroup posLines = null, negLines = null;
                DiffuseMaterial posDiffuse = null, negDiffuse = null;

                foreach (var output in _neuronLinks)
                {
                    Transform3D toTransform = GetContainerTransform(containerTransforms, output.Container, _centerOffset);

                    foreach (var link in UtilityCore.Iterate(output.InternalLinks, output.ExternalLinks))
                    {
                        Transform3D fromTransform = GetContainerTransform(containerTransforms, link.FromContainer, _centerOffset);

                        BuildLinkVisual(ref posLines, ref posDiffuse, ref negLines, ref negDiffuse, fromTransform.Transform(link.From.Position), toTransform.Transform(link.To.Position), link.Weight, link.BrainChemicalModifiers, _itemColors);
                    }
                }

                if (posLines != null)
                {
                    ModelVisual3D model = new ModelVisual3D();
                    model.Content = posLines;
                    retVal.Links.Add(model);
                }

                if (negLines != null)
                {
                    ModelVisual3D model = new ModelVisual3D();
                    model.Content = negLines;
                    retVal.Links.Add(model);
                }
            }

            #endregion

            // Exit Function
            return retVal;
        }
        private void Overlay_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!_isInitialized)
                {
                    return;
                }

                #region Remove existing

                // Back Visuals
                foreach (Visual3D visual in _viewportBack.Children.ToArray())
                {
                    if (_startingVisualsBack.Contains(visual))
                    {
                        continue;
                    }

                    _viewportBack.Children.Remove(visual);
                }

                // Fore Visuals
                foreach (Visual3D visual in _viewport.Children.ToArray())
                {
                    if (_startingVisualsFore.Contains(visual))
                    {
                        continue;
                    }

                    _viewport.Children.Remove(visual);
                }

                // Options panels
                pnlNeuralOptions.Visibility = Visibility.Collapsed;

                #endregion

                if (radNeural.IsChecked.Value)
                {
                    #region Neural

                    if (_neuronVisuals == null)
                    {
                        _neuronVisuals = CreateNeuralVisuals();
                    }

                    foreach (NeuralContainerVisual container in _neuronVisuals.Containers)
                    {
                        _viewport.Children.Add(container.NeuronVisual);
                    }

                    pnlNeuralOptions.Visibility = Visibility.Visible;

                    // Show the optional visuals if requested
                    ShowHideLinks();
                    ShowHideParts_Background();

                    #endregion
                }
                //else if (radParts.IsChecked.Value)
                //{
                //}
                //else if (radMass.IsChecked.Value)
                //{
                //}
                //else if (radCargo.IsChecked.Value)
                //{
                //}
                //else if (radGraphs.IsChecked.Value)
                //{
                //}
                else
                {
                    throw new ApplicationException("Unknown selected tab");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }