protected override void OnVisualParentChanged(DependencyObject oldParent) { base.OnVisualParentChanged(oldParent); Children.Clear(); foreach (var point in Field.Points) { Sphere sphere = new Sphere { Center = point.Position, Radius = Math.Pow(Math.Log(1 + Math.Abs(point.Potential)), 0.2) - 1, Material = new DiffuseMaterial { Brush = point.Potential > 0 ? Brushes.Red : Brushes.Blue } }; Children.Add(sphere); } }
private void UpdateUI() { Children.Clear(); var grid = GridSource; if (grid == null) return; double sphereRadius = SphereRadius; Material sphereMaterial = new DiffuseMaterial(Brushes.Cyan); sphereMaterial.Freeze(); for (int k = 0; k < grid.Depth; k++) { int kLocal = k; Dispatcher.BeginInvoke(() => { for (int i = 0; i < grid.Width; i++) { for (int j = 0; j < grid.Height; j++) { Point3D position = grid.Grid[i, j, kLocal]; Sphere sphere = new Sphere { Radius = sphereRadius, Center = position, Material = sphereMaterial, Slices = 4, Stacks = 2 }; Children.Add(sphere); } } }, DispatcherPriority.Background); } }