private void UpdateZ() { double scale = mPoleZeroScale[comboBoxPoleZeroScale.SelectedIndex]; PoleZeroDispMode dispMode = (PoleZeroDispMode)comboBoxPoleZeroDispMode.SelectedIndex; var im = new Image(); var bm = new WriteableBitmap( 512, 512, 96, 96, dispMode == PoleZeroDispMode.Magnitude ? PixelFormats.Gray32Float : PixelFormats.Bgra32, null); var pxF = new float[bm.PixelHeight * bm.PixelWidth]; var pxBgra = new int[bm.PixelHeight * bm.PixelWidth]; im.Source = bm; im.Stretch = Stretch.None; im.HorizontalAlignment = HorizontalAlignment.Left; im.VerticalAlignment = VerticalAlignment.Top; int pos = 0; for (int yI = 0; yI < bm.PixelHeight; yI++) { for (int xI = 0; xI < bm.PixelWidth; xI++) { double y = 2.6666666666666 / scale * (bm.PixelHeight / 2 - yI) / bm.PixelHeight; double x = 2.6666666666666 / scale * (xI - bm.PixelWidth / 2) / bm.PixelHeight; var z = new WWComplex(x, y); var h = EvalH(z); var hM = h.Magnitude(); if (hM < 0.1) { hM = 0.1; } float hL = (float)((Math.Log10(hM) + 1.0f) / 5.0f); pxF[pos] = hL; pxBgra[pos] = PhaseToBgra(h.Phase()); ++pos; } } switch (dispMode) { case PoleZeroDispMode.Magnitude: bm.WritePixels(new Int32Rect(0, 0, bm.PixelWidth, bm.PixelHeight), pxF, bm.BackBufferStride, 0); break; case PoleZeroDispMode.Phase: bm.WritePixels(new Int32Rect(0, 0, bm.PixelWidth, bm.PixelHeight), pxBgra, bm.BackBufferStride, 0); break; } canvasZ.Children.Clear(); canvasZ.Children.Add(im); double circleRadius = 192.0 * scale; Ellipse unitCircle = new Ellipse { Width = circleRadius * 2, Height = circleRadius * 2, Stroke = new SolidColorBrush { Color = Colors.Black } }; unitCircle.Width = circleRadius * 2; unitCircle.Height = circleRadius * 2; canvasZ.Children.Add(unitCircle); Canvas.SetLeft(unitCircle, 256.0 - circleRadius); Canvas.SetTop(unitCircle, 256.0 - circleRadius); Canvas.SetZIndex(unitCircle, 1); }
/// <summary> /// グラデーションサンプル表示。 /// </summary> private void UpdateGradation() { PoleZeroDispMode dispMode = (PoleZeroDispMode)comboBoxPoleZeroDispMode.SelectedIndex; float maxMagnitude = 5.0f; var im = new Image(); var bm = new WriteableBitmap( (int)canvasGradation.Width, (int)canvasGradation.Height, 96, 96, dispMode == PoleZeroDispMode.Magnitude ? PixelFormats.Gray32Float : PixelFormats.Bgra32, null); im.Source = bm; im.Stretch = Stretch.None; im.HorizontalAlignment = HorizontalAlignment.Left; im.VerticalAlignment = VerticalAlignment.Top; var pxF = new float[bm.PixelHeight * bm.PixelWidth]; var pxBgra = new int[bm.PixelHeight * bm.PixelWidth]; for (int yI = 0; yI < bm.PixelHeight; yI++) { double hM = maxMagnitude * yI / bm.PixelHeight; if (hM < 0.1) { hM = 0.1; } float hL = (float)((Math.Log10(hM) + 1.0f) / 5.0f); double phase = yI * 2.0 * Math.PI / bm.PixelHeight; int bgra = PhaseToBgra(phase); for (int xI = 0; xI < bm.PixelWidth; xI++) { // 下から上に塗る。 pxF[xI + (bm.PixelHeight - 1 - yI) * bm.PixelWidth] = hL; pxBgra[xI + (bm.PixelHeight - 1 - yI) * bm.PixelWidth] = bgra; } } if (dispMode == PoleZeroDispMode.Magnitude) { bm.WritePixels(new Int32Rect(0, 0, bm.PixelWidth, bm.PixelHeight), pxF, bm.BackBufferStride, 0); } else { bm.WritePixels(new Int32Rect(0, 0, bm.PixelWidth, bm.PixelHeight), pxBgra, bm.BackBufferStride, 0); } canvasGradation.Children.Clear(); canvasGradation.Children.Add(im); double graduationScale; string unitText; if (dispMode == PoleZeroDispMode.Magnitude) { groupBoxPoleZeroLegend.Header = "Magnitude"; graduationScale = 1.0; unitText = ""; } else { groupBoxPoleZeroLegend.Header = "Phase"; graduationScale = 60.0; unitText = "°"; } labelGradation0.Content = string.Format("{0}{1}", 0.0 * graduationScale, unitText); labelGradation1.Content = string.Format("{0}{1}", 1.0 * graduationScale, unitText); labelGradation2.Content = string.Format("{0}{1}", 2.0 * graduationScale, unitText); labelGradation3.Content = string.Format("{0}{1}", 3.0 * graduationScale, unitText); labelGradation4.Content = string.Format("{0}{1}", 4.0 * graduationScale, unitText); labelGradation5.Content = string.Format("{0}{1}", 5.0 * graduationScale, unitText); labelGradation6.Content = string.Format("{0}{1}", 6.0 * graduationScale, unitText); }