private static SketchSample[] GetNearbySketches(SketchSample sketch, SketchSample[] all, double radius) { double radiusSquared = radius * radius; return(all. Where(o => o.Token != sketch.Token). Select(o => new { Sketch = o, DistSquared = (o.Position - sketch.Position).LengthSquared }). Where(o => o.DistSquared <= radiusSquared). OrderBy(o => o.DistSquared). Select(o => o.Sketch). ToArray()); }
private void ShowImage(SketchSample sketch, Point position, bool isLarge) { double size = isLarge ? SKETCHSIZE_LARGE : SKETCHSIZE_SMALL; #region Get image UIElement image = isLarge ? sketch.Image_Large : sketch.Image_Small; if (image == null) { var bitmap = GetBitmap(sketch.NNInput); Color?borderColor = null; if (sketch.IsMatch) { borderColor = sketch.Color.ToRGB(); } image = GetImageCtrl(bitmap, size, borderColor); if (isLarge) { sketch.Image_Large = image; } else { sketch.Image_Small = image; } } #endregion double halfSize = size / 2; Canvas.SetLeft(image, position.X - halfSize); Canvas.SetTop(image, position.Y - halfSize); canvas.Children.Add(image); }
private static SketchSample[] GetNearbySketches(SketchSample sketch, SketchSample[] all, double radius) { double radiusSquared = radius * radius; return all. Where(o => o.Token != sketch.Token). Select(o => new { Sketch = o, DistSquared = (o.Position - sketch.Position).LengthSquared }). Where(o => o.DistSquared <= radiusSquared). OrderBy(o => o.DistSquared). Select(o => o.Sketch). ToArray(); }
private void ShowImage(SketchSample sketch, Point position, bool isLarge) { double size = isLarge ? SKETCHSIZE_LARGE : SKETCHSIZE_SMALL; #region Get image UIElement image = isLarge ? sketch.Image_Large : sketch.Image_Small; if (image == null) { var bitmap = GetBitmap(sketch.NNInput); Color? borderColor = null; if (sketch.IsMatch) { borderColor = sketch.Color.ToRGB(); } image = GetImageCtrl(bitmap, size, borderColor); if (isLarge) { sketch.Image_Large = image; } else { sketch.Image_Small = image; } } #endregion double halfSize = size / 2; Canvas.SetLeft(image, position.X - halfSize); Canvas.SetTop(image, position.Y - halfSize); canvas.Children.Add(image); }
private void ShowNearbySketches(SketchSample[] nearby, Point3D center3D, RayHitTestParameters cameraRay, Point center2D) { // Get a plane that is perpendicular to the look ray ITriangle plane = Math3D.GetPlane(center3D, cameraRay.Direction); // Project the points onto that plane var nearbyOnPlane = nearby. Select(o => new { Sketch = o, PlanePoint = Math3D.GetClosestPoint_Plane_Point(plane, o.Position) }). ToArray(); RotateTransform3D rotate = new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRotation(new DoubleVector(cameraRay.Direction, _camera.UpDirection), new DoubleVector(new Vector3D(0, 0, -1), new Vector3D(0, 1, 0))))); // Lay these images down along the directions of the projected points // nearby is sorted by distance from the center image #region Attempt1 double halfLarge = SKETCHSIZE_LARGE / 2; double halfSmall = SKETCHSIZE_SMALL / 2; double stepDist = SKETCHSIZE_SMALL * .05; int startIncrement = Convert.ToInt32(Math.Floor((halfSmall + halfLarge) / stepDist)); List<Rect> existing = new List<Rect>(); existing.Add(new Rect(center2D.X - halfLarge, center2D.Y - halfLarge, SKETCHSIZE_LARGE, SKETCHSIZE_LARGE)); foreach (var nextSketch in nearbyOnPlane) { Vector direction = rotate.Transform(nextSketch.PlanePoint - center3D).ToVector2D(); Vector dirUnit = direction.ToUnit(); if (Math2D.IsInvalid(dirUnit)) { dirUnit = Math3D.GetRandomVector_Circular_Shell(1).ToVector2D(); } dirUnit = new Vector(dirUnit.X, -dirUnit.Y); Point point = new Point(); Rect rect = new Rect(); for (int cntr = startIncrement; cntr < 1000; cntr++) { point = center2D + (dirUnit * (stepDist * cntr)); rect = new Rect(point.X - halfSmall, point.Y - halfSmall, SKETCHSIZE_SMALL, SKETCHSIZE_SMALL); if (!existing.Any(o => o.IntersectsWith(rect))) { break; } } existing.Add(rect); //ShowImage(nextSketch.Sketch, center2D + (dirUnit * 100), false); ShowImage(nextSketch.Sketch, point, false); } #endregion }
private static void TestSamples_Distance(out Tuple<int, int, double>[] distance_Input, out Tuple<int, int, double>[] distance_Output, SketchSample[] sketches) { #region Get Distances var inputs = new List<Tuple<int, int, double>>(); var outputs = new List<Tuple<int, int, double>>(); for (int outer = 0; outer < sketches.Length - 1; outer++) { for (int inner = outer + 1; inner < sketches.Length; inner++) { double distance = Math3D.GetDistance(sketches[outer].NNInput, sketches[inner].NNInput); inputs.Add(Tuple.Create(outer, inner, distance)); distance = Math3D.GetDistance(sketches[outer].NNOutput, sketches[inner].NNOutput); outputs.Add(Tuple.Create(outer, inner, distance)); } } distance_Input = inputs.ToArray(); distance_Output = outputs.ToArray(); #endregion if (distance_Input.Length == 0) { return; } //#region Normalize //double inputMax = distance_Input.Max(o => o.Item3); //double outputMax = distance_Output.Max(o => o.Item3); //distance_Input = distance_Input. // Select(o => Tuple.Create(o.Item1, o.Item2, o.Item3 / inputMax)). // ToArray(); //distance_Output = distance_Output. // Select(o => Tuple.Create(o.Item1, o.Item2, o.Item3 / inputMax)). // ToArray(); //#endregion }
private static Visual3D TestSamples_Draw(SketchSample[] sketches, double[] hues) { const double RADIUS = .5; const double DOTRADIUS = .035; #region Materials SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("50FFFFFF")), 2); var material_Color = hues.Select(o => { ColorHSV color = new ColorHSV(o, 75, 75); MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color.ToRGB()))); material.Children.Add(specular); return new { Color = color, Material = material }; }).ToArray(); ColorHSV color_Gray = new ColorHSV(0, 0, 50); MaterialGroup material_Gray = new MaterialGroup(); material_Gray.Children.Add(new DiffuseMaterial(new SolidColorBrush(color_Gray.ToRGB()))); material_Gray.Children.Add(specular); #endregion Model3DGroup group = new Model3DGroup(); foreach (SketchSample sketch in sketches) { int? matchIndex = UtilityEncog.IsMatch(sketch.NNOutput); Material material; if (matchIndex == null) { sketch.IsMatch = false; sketch.Color = color_Gray; material = material_Gray; } else { sketch.IsMatch = true; sketch.Color = material_Color[matchIndex.Value].Color; material = material_Color[matchIndex.Value].Material; } sketch.Position = Math3D.GetRandomVector_Spherical(RADIUS).ToPoint(); sketch.Translate_3DDot = new TranslateTransform3D(sketch.Position.ToVector()); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetSphere_Ico(DOTRADIUS, 1, true); geometry.Transform = sketch.Translate_3DDot; group.Children.Add(geometry); } ModelVisual3D visual = new ModelVisual3D(); visual.Content = group; return visual; }