static void Main(string[] args) { float op1 = 4; float op2 = -7; Console.WriteLine(op1.Add(op2)); Console.ReadKey(); }
/// <summary> /// Get the E and D matrix for whitening or coloring. Implemented using Accord.net. /// </summary> /// <param name="covMat"></param> /// <param name="eps"></param> /// <param name="ignoredSingularValue"></param> /// <param name="beta"> when beta is 0.5, it is coloring. When beta is -0.5, it is whitening.You can also try other values</param> /// <returns>a tuple of E and D matrices as the first and second element</returns> private static Tuple <float[, ], float[, ]> GetWCMatrices(float[,] covMat, float eps = 0.00001f, float ignoredSingularValue = 0.00001f, float beta = -0.5f) { //no use the singular value decompositoin to do the whitening var stopwatch = new Stopwatch(); stopwatch.Start(); //mathnet is a little faster tha accord.net float[] diag; float[,] E; //bool useTF = false; //test for tensorflow //if (useTF) //{ // //TFSharpUtils.SVD(covMat, out diag, out E); GC.Collect(); //} // else //{ var m = MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfArray(covMat); var svdMathnet = m.Svd(true); diag = svdMathnet.S.ToArray(); E = svdMathnet.U.ToArray(); //} stopwatch.Stop(); //UnityEngine.Debug.Log("------Otained Singular values and matrix using"+( useTF ?"tensorflow":"math.net")+ ". Time cost: " + (float)stopwatch.ElapsedMilliseconds / 1000); stopwatch.Restart(); //count the valid components based on the singular values and get rid of the too small ones int countValid = 0; for (int i = 0; i < diag.Length; ++i) { countValid = i; if (diag[i] < ignoredSingularValue) { break; } } float[] validDiag = new float[countValid]; Array.Copy(diag, validDiag, countValid); //create the diagonal matrix from singular value with pow of -0.5 by default(should not use other power normally) float[,] D = Matrix.Diagonal(countValid, countValid, validDiag.Add(eps).Pow(beta)); //create the E matrix for valid singular values int[] indices = new int[countValid]; for (int i = 0; i < countValid; ++i) { indices[i] = i; } float[,] validE = E.GetColumns(indices); stopwatch.Stop(); //UnityEngine.Debug.Log("------Proccessed singular values and matrix. Time cost: " + (float)stopwatch.ElapsedMilliseconds / 1000); return(new Tuple <float[, ], float[, ]>(validE, D)); }
public float[] GetCentralVector() { var vectorSum = new float[Size]; foreach (WordVector item in vectors) { vectorSum = vectorSum.Add(item.Vector); } return(vectorSum.Multiply(1 / Size)); }
public void TestVectorAddition() { var x = new float[] { 1, 2, 3 }; var result = x.Add(x); Assert.IsNotNull(result); Assert.AreEqual(2, result[0]); Assert.AreEqual(4, result[1]); Assert.AreEqual(6, result[2]); }
private static float[] ExtrudePoint(float[] a, float[] b, float[] c, float width) { var seg1 = b.Substract(a).NormalizeVector(); var seg2 = b.Substract(c).NormalizeVector(); var normal1 = new float[] { -seg1[1], seg1[0], seg1[2] }; var normal2 = new float[] { seg2[1], -seg2[0], seg2[2] }; var bisectorDistance = width / Math.Sqrt(1 + normal1.VectorDotProduct(normal2)); var dir = normal1.Add(normal2).NormalizeVector().VectorScale((float)bisectorDistance); return(b.Add(dir)); }
/// <summary> /// Рисование связи между вершинами /// </summary> /// <param name="g">Где рисовать? Объект <see cref="Graphics"/>.</param> /// <param name="from">Центр вершины, от которой идёт связь.</param> /// <param name="to">Центр вершины, к которой идёт связь.</param> /// <param name="radius">Отступ от вершины.</param> /// <param name="straight">Рисовать ребро прямой или кривой Безье?</param> public static void DrawLink(this Graphics g, PointF from, PointF to, float radius, bool straight = false) { //Считаем точки входа ребёр графа в вершины var pt1 = new Vector(to.X - from.X, to.Y - from.Y); pt1.Normalize(); pt1 *= radius; var pt2 = new Vector(from.X - to.X, from.Y - to.Y); pt2.Normalize(); pt2 *= radius; pt1 = pt1.Rotate(GapAngle); pt2 = pt2.Rotate(-GapAngle); pt1 = pt1.Add(from); pt2 = pt2.Add(to); if (straight) { DrawStraightLink(g, pt1.ToPointF(), pt2.ToPointF()); } else { DrawBezierLink(g, pt1.ToPointF(), pt2.ToPointF()); } }
public static void AtomicFloatTest() { float i = 10F; Equal(11F, i.IncrementAndGet()); Equal(10F, i.DecrementAndGet()); i = 20F; True(i.CompareAndSet(20F, 30F)); Equal(30F, i); False(i.CompareAndSet(20F, 50F)); Equal(30F, i); Equal(80F, i.Add(50F)); Equal(80F, i); Equal(80F, i.GetAndAccumulate(10F, static (x, y) => x + y)); Equal(90F, i); Equal(10F, i.AccumulateAndGet(80F, static (x, y) => x - y)); Equal(10F, i); Equal(10F, i.GetAndSet(25F)); Equal(25F, i); Equal(42F, i.UpdateAndGet(static current => 42F));
public MainWindow() { InitializeComponent(); _tempsize = DensityScrollViewer.ContentHorizontalOffset; Closing += (s, e) => ViewModelLocator.Cleanup(); Messenger.Default.Register <DataRoad>(this, "ShowInfo", message => { Info = message; }); Messenger.Default.Register <float>(this, "ShowInfoDistance", message => { Distance = message; }); Messenger.Default.Register <ObservableCollection <Graphics> >(this, "ShowGeneralGraff", message => GeneralGraff.DrawGraphic(message, collor = true)); var timer = new System.Windows.Threading.DispatcherTimer { Interval = new TimeSpan(0, 0, 1), IsEnabled = true }; timer.Tick += (o, t) => { TimeBlock.Text = " " + DateTime.Now.ToLongTimeString() + "\n" + DateTime.Now.ToLongDateString(); }; timer.Start(); Messenger.Default.Register <List <List <object> > >(this, "GreatGraphic", message => { LineSeries LS; AreaSeries AS; ColumnSeries CL; List <byte> CountGener; List <float> Distance; List <float> Layer123; List <double> Plotnost; List <Graphics> dataValues; LinearAxis linerAxx; LinearAxis linerAxy; Setter setter; Style style; Style legendStyle; Setter legendSetterw; Setter legendSetterl; AreaDataPoint areaDataPoint; int max; Control control; LineDataPoint lineDataPoint; Setter setterpoint; switch (_greatGraphicName) { case "CountChart": CountGener = new List <byte>(); Distance = new List <float>(); foreach (var count in message[0]) { CountGener.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); for (var i = 0; i < CountGener.Count - 1; i++) { var graph = new Graphics(); graph.CountLayer = CountGener[i]; graph.Distance = Distance[i]; dataValues.Add(graph); } setter = new Setter(); setter.Property = BackgroundProperty; setter.Value = Brushes.Black; style = new Style(); var columnDataPoint = new ColumnDataPoint(); style.TargetType = columnDataPoint.GetType(); style.Setters.Add(setter); CL = new ColumnSeries { ItemsSource = dataValues, DependentValuePath = "CountLayer", IndependentValuePath = "Distance" }; CL.DataPointStyle = style; linerAxx = new LinearAxis(); linerAxy = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Minimum = 0; linerAxy.Maximum = 4; linerAxx.Title = "Расстояние, [м]"; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Количество слоёв", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(CL); LayoutRoot.Children.Add(chart); break; case "ChartLayer3": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer3 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №1", }; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.DodgerBlue; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setterpoint); style.Setters.Add(setter); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer3", IndependentValuePath = "Distance", }; AS.DataPointStyle = style; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartLayer2": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer2 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №2", }; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.DarkRed; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer2", IndependentValuePath = "Distance" }; AS.DataPointStyle = style; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartLayer1": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer1 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.OliveDrab; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer1", IndependentValuePath = "Distance" }; AS.DataPointStyle = style; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №3", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartAll": var Layer1 = new List <float>(); var Layer2 = new List <float>(); var Layer3 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer1.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } foreach (var count in message[2]) { Layer2.Add(Convert.ToByte(count)); } foreach (var count in message[3]) { Layer3.Add(Convert.ToByte(count)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer3[0]); for (var i = 0; i < Layer1.Count - 1; i++) { var graph = new Graphics(); graph.Layer3 = Layer3[i]; graph.Layer2 = Layer2[i]; graph.Layer1 = Layer1[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer3[i] > max) { max = Convert.ToInt16(Layer3[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; //// var setter1 = new Setter(); var setterpoint1 = new Setter(); setterpoint1.Property = OpacityProperty; setterpoint1.Value = (double)0; setter1.Property = BackgroundProperty; setter1.Value = Brushes.OliveDrab; var style1 = new Style(); var areaDataPoint1 = new AreaDataPoint(); style1.TargetType = areaDataPoint1.GetType(); style1.Setters.Add(setter1); style1.Setters.Add(setterpoint1); var ser1 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer1", IndependentValuePath = "Distance", Title = "Слой №3" }; ser1.DataPointStyle = style1; /// var setter2 = new Setter(); var setterpoint2 = new Setter(); setterpoint2.Property = OpacityProperty; setterpoint2.Value = (double)0; setter2.Property = BackgroundProperty; setter2.Value = Brushes.DarkRed; var style2 = new Style(); var areaDataPoint2 = new AreaDataPoint(); style2.TargetType = areaDataPoint2.GetType(); style2.Setters.Add(setter2); style2.Setters.Add(setterpoint2); var ser2 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer2", IndependentValuePath = "Distance", Title = "Слой №2" }; ser2.DataPointStyle = style2; /// var setter3 = new Setter(); var setterpoint3 = new Setter(); setterpoint3.Property = OpacityProperty; setterpoint3.Value = (double)0; setter3.Property = BackgroundProperty; setter3.Value = Brushes.DodgerBlue; var style3 = new Style(); var areaDataPoint3 = new AreaDataPoint(); style3.TargetType = areaDataPoint3.GetType(); style3.Setters.Add(setter3); style3.Setters.Add(setterpoint3); var ser3 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer3", IndependentValuePath = "Distance", Title = "Слой №1" }; ser3.DataPointStyle = style3; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоёв", }; var setterlegendcollor = new Setter(); var setterlegendborder = new Setter(); setterlegendcollor.Property = BackgroundProperty; setterlegendcollor.Value = new SolidColorBrush(Color.FromRgb(3, 94, 129)); setterlegendborder.Property = BorderBrushProperty; setterlegendborder.Value = new SolidColorBrush(Color.FromRgb(3, 94, 129)); legendStyle = new Style(); control = new Control(); legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(setterlegendcollor); legendStyle.Setters.Add(setterlegendborder); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(ser3); chart.Series.Add(ser2); chart.Series.Add(ser1); LayoutRoot.Children.Add(chart); break; case "Plotnost": Plotnost = new List <double>(); Distance = new List <float>(); foreach (var count in message[0]) { Plotnost.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Plotnost[0]); for (var i = 0; i < Plotnost.Count - 1; i++) { var graph = new Graphics(); graph.IntensityN1 = Plotnost[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Plotnost[i] > max) { max = Convert.ToInt16(Plotnost[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "[кг/м^3]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.OliveDrab; style = new Style(); lineDataPoint = new LineDataPoint(); style.TargetType = lineDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); LS = new LineSeries() { ItemsSource = dataValues, DependentValuePath = "IntensityN1", IndependentValuePath = "Distance" }; LS.DataPointStyle = style; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Плотность", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(LS); LayoutRoot.Children.Add(chart); break; case "GeneralGraff": CountGener = new List <byte>(); Distance = new List <float>(); foreach (var count in message[0]) { CountGener.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } var dataValues1 = new ObservableCollection <Graphics>(); for (var i = 0; i < CountGener.Count - 1; i++) { var graph = new Graphics(); graph.GeneralState = CountGener[i]; graph.Distance = Distance[i]; dataValues1.Add(graph); } Gridnorm = new Grid(); Gridd = new Graff(); Gridd.DrawGraphic(dataValues1, collor = false); Gridd.Width = 1111; Gridd.Height = 234; var text1 = new TextBlock(); var text2 = new TextBlock(); var collor1 = new TextBlock(); var collor2 = new TextBlock(); var collortext1 = new TextBlock(); var collortext2 = new TextBlock(); collor1.Background = Brushes.Red; collor2.Background = Brushes.Green; collor1.Width = 50; collor1.Height = 50; collor2.Width = 50; collor2.Height = 50; collor1.HorizontalAlignment = HorizontalAlignment.Left; collor1.VerticalAlignment = VerticalAlignment.Top; collor2.HorizontalAlignment = HorizontalAlignment.Left; collor2.VerticalAlignment = VerticalAlignment.Top; collor1.Margin = new Thickness(370, 650, 0, 0); collor2.Margin = new Thickness(690, 650, 0, 0); collortext1.Text = "- не соответствует"; collortext2.Text = "- соответствует"; collortext1.FontSize = 19; collortext2.FontSize = 19; collortext1.HorizontalAlignment = HorizontalAlignment.Left; collortext1.VerticalAlignment = VerticalAlignment.Top; collortext2.HorizontalAlignment = HorizontalAlignment.Left; collortext2.VerticalAlignment = VerticalAlignment.Top; collortext1.Margin = new Thickness(440, 657, 0, 0); collortext2.Margin = new Thickness(760, 657, 0, 0); text1.Text = "Общее состояние дорожного покрытия"; text2.Text = "Расстояние, [м]"; text2.FontStyle = FontStyles.Italic; text1.FontSize = 22; text2.FontSize = 19; text1.HorizontalAlignment = HorizontalAlignment.Left; text1.VerticalAlignment = VerticalAlignment.Top; text2.HorizontalAlignment = HorizontalAlignment.Left; text2.VerticalAlignment = VerticalAlignment.Top; text1.Margin = new Thickness(440, 350, 0, 0); text2.Margin = new Thickness(570, 530, 0, 0); Gridnorm.Children.Add(collortext1); Gridnorm.Children.Add(collortext2); Gridnorm.Children.Add(collor1); Gridnorm.Children.Add(collor2); Gridnorm.Children.Add(text1); Gridnorm.Children.Add(text2); Gridnorm.Children.Add(Gridd); Gridnorm.Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)); LayoutRoot.Children.Add(Gridnorm); Gridnorm.MouseLeftButtonDown += MouseLeftButtonDownGrid1; Gridd.MouseLeftButtonDown += MouseLeftButtonDownGrid1; break; } }); }
/// <summary> /// Apply filter. /// </summary> /// <param name="images">Bitmap array</param> /// <returns>Bitmap</returns> public Bitmap Apply(params Bitmap[] images) { // data int N = images.GetLength(0); float[][][,] data = new float[N][][, ]; int height = images[0].Height; int width = images[1].Width; float[][,] weights = new float[N][, ]; // to rgb array for (int i = 0; i < N; i++) { data[i] = BitmapMatrix.ToRGB(images[i]); } // initialize weights for (int i = 0; i < N; i++) { weights[i] = Matrice.One(height, width); } // applying params weights = Mul(weights, Exp(data, this.sigma)); // normalizing float[,] z = new float[height, width]; for (int i = 0; i < N; i++) { z = z.Add(weights[i]); } for (int i = 0; i < N; i++) { weights[i] = weights[i].Div(z); } // pyramids float[][,] pyrW; float[][,] pyrIr; float[][,] pyrIg; float[][,] pyrIb; // outputs float[][,] zero = gap.Forward(new float[height, width]); float[][,] r = (float[][, ])zero.Clone(); float[][,] g = (float[][, ])zero.Clone(); float[][,] b = (float[][, ])zero.Clone(); int levels = r.GetLength(0); // do job for (int i = 0; i < N; i++) { pyrW = gap.Forward(weights[i]); zero = data[i]; pyrIr = lap.Forward(zero[0]); pyrIg = lap.Forward(zero[1]); pyrIb = lap.Forward(zero[2]); for (int l = 0; l < levels; l++) { z = pyrW[l]; r[l] = r[l].Add(z.Mul(pyrIr[l])); g[l] = g[l].Add(z.Mul(pyrIg[l])); b[l] = b[l].Add(z.Mul(pyrIb[l])); } } // reconstruction Bitmap bitmap = BitmapMatrix.FromRGB(new float[][, ] { lap.Backward(r), lap.Backward(g), lap.Backward(b) }); return(bitmap); }
public float[,] CreateImage(string method, int[] size) // Create float image using given properties { float[,] image = new float[size[0], size[1]]; if (method == "Quarters") { for (int i = 0; i < Math.Floor((double)size[0] / 2); i++) // 1st quarter { for (int j = 0; j < Math.Floor((double)size[1] / 2); j++) { image[i, j] = 1; } } for (int i = (int)Math.Floor((double)size[0] / 2); i < size[0]; i++) // 2nd quarter { for (int j = 0; j < Math.Floor((double)size[1] / 2); j++) { image[i, j] = 2; } } for (int i = 0; i < Math.Floor((double)size[0] / 2); i++) // 3rd quarter { for (int j = (int)Math.Floor((double)size[1] / 2); j < size[1]; j++) { image[i, j] = 3; } } for (int i = (int)Math.Floor((double)size[0] / 2); i < size[0]; i++) // 4th quarter { for (int j = (int)Math.Floor((double)size[1] / 2); j < size[1]; j++) { image[i, j] = 4; } } } if (method == "Running numbers" || method == "Add residual" || method == "Running Numbers") { for (int i = 0; i < size[0]; i++) { for (int j = 0; j < size[1]; j++) { image[i, j] = (i + j); } } } if (method == "Add residual") { image = image.Add(0.00001).ToSingle(); } if (method == "Ones") { for (int i = 0; i < size[0]; i++) { for (int j = 0; j < size[1]; j++) { image[i, j] = 1; } } } return(image); }
public static SvgMeshData GetMeshData(CoreSvg.Models.Path path, List <float[]> points, Style style, bool constrained = true) { var triangulation = points.Count > 4 ? (constrained ? GetConstrainedDelaunayTriangulation(points) : GetDelaunayIndexes(points)) : null; var data = triangulation is null?GetVertices(points).ToList() : GetVertices(triangulation.Vertices.SelectMany(a => a).ToArray()).ToList(); var meshIndices = triangulation is null ? (data.Count == 3) ? new List <int> { 0, 1, 2 } : (data.Count == 4) ? new List <int> { 0, 1, 2, 0, 2, 3 } : new List <int> { } : triangulation.Triangles; if (style.LinearGradient != null) { var gradient1 = new float[] { (float)style.LinearGradient.X1, (float)style.LinearGradient.Y1, 0f }; var gradient2 = new float[] { (float)style.LinearGradient.X2, (float)style.LinearGradient.Y2, 0f }; var gradientTransform = StyleHelper.GetTransform(style.LinearGradient.GradientTransform); var translate = gradientTransform.Translate.Add(style.Transform.Translate); var scale = new float[] { style.Transform.Scale.X(), style.Transform.Scale.Y(), 0f }; gradient1 = gradient1.Add(new float[] { translate.X(), translate.Y(), 0f }).MultiplyComponents(scale); gradient2 = gradient2.Add(new float[] { translate.X(), translate.Y(), 0f }).MultiplyComponents(scale); data.ForEach(v => { var current = new float[] { v.PosX, v.PosY, 0f }; gradient1.SegmentClosestPoint(gradient2, current, out var offset); var stop = style.LinearGradient.Stops.FirstOrDefault(a => a.Offset == offset); var color = Color.Black; if (stop is null) { var stops = style.LinearGradient.Stops.OrderBy(a => Math.Abs(a.Offset - offset)).Take(2).ToList(); var stopStyle = StyleHelper.GetStyle(stops[0].Style, null, null); var stopColor1 = Color.FromArgb((byte)(stopStyle.StopOpacity * 255), stopStyle.StopColor); stopStyle = StyleHelper.GetStyle(stops[1].Style, null, null); var stopColor2 = Color.FromArgb((byte)(stopStyle.StopOpacity * 255), stopStyle.StopColor); var stopOffsetDif = stops[1].Offset - stops[0].Offset; var stop1Offset = (offset - stops[0].Offset) / stopOffsetDif; var stop2Offset = 1f - stop1Offset; color = Color.FromArgb((byte)(stopColor1.A * stop1Offset) + (byte)(stopColor2.A * stop2Offset), (byte)(stopColor1.R * stop1Offset) + (byte)(stopColor2.R * stop2Offset), (byte)(stopColor1.G * stop1Offset) + (byte)(stopColor2.G * stop2Offset), (byte)(stopColor1.B * stop1Offset) + (byte)(stopColor2.B * stop2Offset)); } v.R = color.R / 255f; v.G = color.G / 255f; v.B = color.B / 255f; v.A = color.A / 255f; }); } else { data.ForEach(v => { v.R = style.Fill.R / 255f; v.G = style.Fill.G / 255f; v.B = style.Fill.B / 255f; v.A = style.Fill.A / 255f; }); } return(new SvgMeshData() { Vertices = data, Indices = meshIndices }); }
public static IArray <float> Add(this float self, IArray <float> vector) { return(vector.Select(x => self.Add(x))); }