private void ComputeChart(Func <threeDimensionalPointDTO, double> Mapping) { if (LeftLens.Equals(selected)) { NavigationService.Navigate(new ThreeDimensionalLensPage(model.LeftAnalyzeLensResponse.points, Mapping)); } else if (RightLens.Equals(selected)) { NavigationService.Navigate(new ThreeDimensionalLensPage(model.RightAnalyzeLensResponse.points, Mapping)); } }
private void PaintLens(object sender, SKPaintSurfaceEventArgs args) { analyzeLensResponseDTO analyzeLensResponseDTO = RightLens.Equals(sender) ? model.RightAnalyzeLensResponse : model.LeftAnalyzeLensResponse; SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); SKPaint blackSKPaint = new SKPaint { Style = SKPaintStyle.Fill, Color = SKColors.Black }; canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), blackSKPaint); if (analyzeLensResponseDTO != null && analyzeLensResponseDTO.points != null & analyzeLensResponseDTO.points.Any()) { int sqrt = Convert.ToInt32(Math.Sqrt(analyzeLensResponseDTO.points.Count())); int side = (sqrt - 1) / 2; ICollection <analyzedPointDTO> points = analyzeLensResponseDTO.points.Where(p => IsInside(p, side + 1)).ToList(); double max = compare && model.RightAnalyzeLensResponse != null && model.LeftAnalyzeLensResponse != null?Math.Max(model.RightAnalyzeLensResponse.points.Where(p => IsInside(p, side + 1)).Select(mapping).Max(), model.LeftAnalyzeLensResponse.points.Where(p => IsInside(p, side + 1)).Select(mapping).Max()) : points.Where(p => IsInside(p, side + 1)).Select(mapping).Max(); double min = compare && model.RightAnalyzeLensResponse != null && model.LeftAnalyzeLensResponse != null?Math.Min(model.RightAnalyzeLensResponse.points.Where(p => IsInside(p, side + 1)).Select(mapping).Min(), model.LeftAnalyzeLensResponse.points.Where(p => IsInside(p, side + 1)).Select(mapping).Min()) : points.Where(p => IsInside(p, side + 1)).Select(mapping).Min(); double range = (max - min) / 6.0; if (range > 0) { double centerX = info.Width / 2.0; double centerY = info.Height / 2.0; double bitmapSide = Math.Min(centerX, centerY); double radius = bitmapSide * 5 / 6; double doubleRange = range * 2; double tripleRange = range * 3; double fiveRange = range * 5; double sqrtRange = sqrt / 6.0; double doubleSqrtRange = sqrtRange * 2; double tripleSqrtRange = sqrtRange * 3; double fiveSqrtRange = sqrtRange * 5; using (SKBitmap bitmap = new SKBitmap(1, sqrt)) { for (int i = sqrt - 1; i >= 0; i--) { SKColor color = SKColors.Black; switch (Math.Floor(i / sqrtRange)) { case 0: color = new SKColor(Convert.ToByte(Math.Round(i / sqrtRange * 255)), Convert.ToByte(Math.Round(i / sqrtRange * 255)), 255); break; case 1: color = new SKColor(Convert.ToByte(Math.Round((doubleSqrtRange - i) / sqrtRange * 255)), 255, 255); break; case 2: color = new SKColor(0, 255, Convert.ToByte(Math.Round((tripleSqrtRange - i) / sqrtRange * 255))); break; case 3: color = new SKColor(Convert.ToByte(Math.Round((i - tripleSqrtRange) / sqrtRange * 255)), 255, 0); break; case 4: color = new SKColor(255, Convert.ToByte(Math.Round((fiveSqrtRange - i) / sqrtRange * 255)), 0); break; default: color = new SKColor(255, 0, Convert.ToByte(Math.Round((i - fiveSqrtRange) / sqrtRange * 255))); break; } bitmap.SetPixel(0, i, color); } canvas.DrawBitmap(bitmap.Resize(new SKImageInfo(Convert.ToInt32(bitmapSide / 6.0), Convert.ToInt32(bitmapSide)), SKBitmapResizeMethod.Mitchell), new SKRect(Convert.ToSingle(info.Width - bitmapSide / 6.0), 0, Convert.ToSingle(info.Width), info.Height)); } blackSKPaint.TextSize = info.Height / 32f; float textRange = (info.Height - blackSKPaint.TextSize * 3) / 6f; canvas.DrawText(string.Format("{0:N2}", min), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2, blackSKPaint); canvas.DrawText(string.Format("{0:N2}", min + range), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2 + textRange, blackSKPaint); canvas.DrawText(string.Format("{0:N2}", min + range * 2), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2 + textRange * 2, blackSKPaint); canvas.DrawText(string.Format("{0:N2}", min + range * 3), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2 + textRange * 3, blackSKPaint); canvas.DrawText(string.Format("{0:N2}", min + range * 4), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2 + textRange * 4, blackSKPaint); canvas.DrawText(string.Format("{0:N2}", min + range * 5), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2 + textRange * 5, blackSKPaint); canvas.DrawText(string.Format("{0:N2}", max), Convert.ToSingle(info.Width - bitmapSide / 8), blackSKPaint.TextSize * 2 + textRange * 6, blackSKPaint); using (SKBitmap bitmap = new SKBitmap(sqrt, sqrt)) { foreach (analyzedPointDTO point in points) { SKColor color = SKColors.Black; double value = mapping.Invoke(point) - min; switch (Math.Floor(value / range)) { case 0: color = new SKColor(Convert.ToByte(Math.Round(value / range * 255)), Convert.ToByte(Math.Round(value / range * 255)), 255); break; case 1: color = new SKColor(Convert.ToByte(Math.Round((doubleRange - value) / range * 255)), 255, 255); break; case 2: color = new SKColor(0, 255, Convert.ToByte(Math.Round((tripleRange - value) / range * 255))); break; case 3: color = new SKColor(Convert.ToByte(Math.Round((value - tripleRange) / range * 255)), 255, 0); break; case 4: color = new SKColor(255, Convert.ToByte(Math.Round((fiveRange - value) / range * 255)), 0); break; default: color = new SKColor(255, 0, Convert.ToByte(Math.Round((value - fiveRange) / range * 255))); break; } bitmap.SetPixel(Convert.ToInt32(side - point.x), Convert.ToInt32(side - point.y), color); } if (mask) { using (SKPath path = new SKPath()) { path.AddCircle(Convert.ToSingle(centerX), Convert.ToSingle(centerY), Convert.ToSingle(radius)); canvas.ClipPath(path, SKClipOperation.Intersect); } } canvas.DrawBitmap(bitmap.Resize(new SKImageInfo(Convert.ToInt32(radius), Convert.ToInt32(radius)), SKBitmapResizeMethod.Mitchell), new SKRect(Convert.ToSingle(centerX - radius), Convert.ToSingle(centerY - radius), Convert.ToSingle(centerX + radius), Convert.ToSingle(centerY + radius))); } } } }