//----------------------------------------------------------------------------- static public Single[] MinMax(Single[,] prmData) { Single min = Single.MaxValue; Single max = Single.MinValue; Int32 rows = prmData.GetLength(0); Int32 cols = prmData.GetLength(1); int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (prmData[i, j] < min) { min = prmData[i, j]; } if (prmData[i, j] > max) { max = prmData[i, j]; } } } return(new Single[2] { min, max }); }
public static Single[,] Process(Single[,] array, Int32 timeLength, Int32 valueLength) { var rs = new Single[timeLength, valueLength]; var scale1 = (Single)array.GetLength(0) / timeLength; var scale2 = (Single)array.GetLength(1) / valueLength; for (var i = 0; i < timeLength; i++) { for (var j = 0; j < valueLength; j++) { var d1 = i * scale1; var d2 = j * scale2; var n1 = (Int32)Math.Floor(d1); var n2 = (Int32)Math.Floor(d2); var leftUp = (d1 - n1) * (d2 - n2); var rightUp = (n1 + 1 - d1) * (d2 - n2); var rightDown = (n1 + 1 - d1) * (n2 + 1 - d2); var leftDown = (d1 - n1) * (n2 + 1 - d2); rs[i, j] = array[n1, n2] * rightDown + array[n1 + 1, n2] * leftDown + array[n1 + 1, n2 + 1] * leftUp + array[n1, n2 + 1] * rightUp; } } return(rs); }
public Map_TerrainBlock_c(int blockX, int blockY, Single[,] heightMap) : base((Int32)PacketType.Map_TerrainBlock_c) { this.blockX = blockX; this.blockY = blockY; this.heightMap = heightMap; }
/// <summary> /// Populates the _prmEdges array with edges between points in the PRM. /// </summary> private void ConnectPRMEdges() { int len = _prmPoints.Count; _prmEdges = new Single[len, len]; for (var i = 0; i < len; i++) { for (var j = i + 1; j < len; j++) { _prmEdges[i, j] = _prmEdges[j, i] = Single.NegativeInfinity; float dist = Vector3.Distance(_prmPoints[i], _prmPoints[j]); // Ignore pairs that are too far away if (dist > maxPRMConnectionDistance) { continue; } // Ignore pairs with obstacles between them. // A capsule check is the fastest way I've found to do this that is accurate. if (Physics.CheckCapsule(_prmPoints[i], _prmPoints[j], _agentRadius, LayerMask.GetMask("Obstacles"))) { continue; } _prmEdges[i, j] = _prmEdges[j, i] = dist; _numEdges++; } } }
/// <summary> /// Immediately releases the unmanaged resources used by this object. /// </summary> /// <returns>True if the object is completely disposed.</returns> protected virtual Boolean Disposing() { _data = null; _width = 0; _height = 0; return(true); }
/// <summary>Constructs a new Cholesky Decomposition.</summary> /// /// <param name="value">The matrix to be decomposed.</param> /// <param name="robust">True to perform a square-root free LDLt decomposition, /// false otherwise.</param> /// <param name="lowerTriangular">True to assume the <paramref name="value">value /// matrix</paramref> is a lower triangular symmetric matrix, false otherwise.</param> /// public CholeskyDecompositionF(Single[,] value, bool robust, bool lowerTriangular) { if (value == null) { throw new ArgumentNullException("value", "Matrix cannot be null."); } if (value.GetLength(0) != value.GetLength(1)) { throw new DimensionMismatchException("value", "Matrix is not square."); } if (robust) { LDLt(value); // Compute square-root free decomposition } else { LLt(value); // Compute standard Cholesky decomposition } if (lowerTriangular) { symmetric = true; } }
/// <summary> /// Constructs a new Cholesky Decomposition. /// </summary> /// /// <param name="value"> /// The symmetric matrix, given in upper triangular form, to be decomposed.</param> /// <param name="robust"> /// True to perform a square-root free LDLt decomposition, false otherwise.</param> /// <param name="inPlace"> /// True to perform the decomposition in place, storing the factorization in the /// lower triangular part of the given matrix.</param> /// <param name="valueType"> /// How to interpret the matrix given to be decomposed. Using this parameter, a lower or /// upper-triangular matrix can be interpreted as a symmetric matrix by assuming both lower /// and upper parts contain the same elements. Use this parameter in conjunction with inPlace /// to save memory by storing the original matrix and its decomposition at the same memory /// location (lower part will contain the decomposition's L matrix, upper part will contains /// the original matrix).</param> /// public CholeskyDecompositionF(Single[,] value, bool robust = false, bool inPlace = false, MatrixType valueType = MatrixType.UpperTriangular) { if (value.Rows() != value.Columns()) { throw new DimensionMismatchException("value", "Matrix is not square."); } if (!inPlace) { value = value.Copy(); } this.n = value.Rows(); this.L = value.ToUpperTriangular(valueType, result: value); this.robust = robust; if (robust) { LDLt(); // Compute square-root free decomposition } else { LLt(); // Compute standard Cholesky decomposition } }
public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) { double thevalue = Main.GlobalTime * 2.0; double movespeed = Main.GlobalTime * 0.2; //NPC theboss=Main.npc[NPC.FindFirstNPC((SGAmod.Instance).NPCType("Asterism"))]; //float valie=((float)theboss.life/(float)theboss.lifeMax); //Main.spriteBatch.End(); //Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.GameViewMatrix.ZoomMatrix); //var deathShader = GameShaders.Misc["WaterProcessor"]; //GameShaders.Misc["WaterProcessor"].Apply(new DrawData?(new DrawData(this._distortionTarget, Vector2.Zero, Color.White))); //deathShader.UseOpacity(0.5f); //deathShader.Apply(null); //if (maxDepth >= 0 && minDepth < 0) Single[,] singles = { { 3.40282347E+38f, 3.40282347E+38f }, { 4f, 4f } }; float[] alphaz = { 1f, 0.5f }; float[] movedir = { 1f, 1f }; for (int i = 0; i < 2; i += 1) { if (maxDepth >= singles[i, 0] && minDepth < singles[i, 1]) { Texture2D texa = ModContent.GetTexture("SGAmod/noise"); int sizechunk = texa.Width; for (int y = 0; y < Main.screenHeight + sizechunk; y += sizechunk) { for (int x = -sizechunk * 2; x < Main.screenWidth + sizechunk * 4; x += sizechunk) { //thevalue += (y * 0.15) + ((x) / 610); float thecoloralpha = 0.5f + (float)Math.Sin(thevalue) * 0.05f; Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.GameViewMatrix.ZoomMatrix); ArmorShaderData shader = GameShaders.Armor.GetShaderFromItemId(ItemID.ShadowDye); shader.Apply(null); shader = GameShaders.Armor.GetShaderFromItemId(ItemID.MidnightRainbowDye); shader.Apply(null); spriteBatch.Draw(texa, new Rectangle(x - ((int)(Main.GlobalTime * movedir[i] * 30) % sizechunk * 3), y, sizechunk, sizechunk), (acolor) * (thecoloralpha * SGAmod.ProgramSkyAlpha * alphaz[i])); } } } } if (maxDepth >= 3.40282347E+38f && minDepth < 3.40282347E+38f) { Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.GameViewMatrix.ZoomMatrix); ArmorShaderData shader2 = GameShaders.Armor.GetShaderFromItemId(ItemID.StardustDye); shader2.Apply(null); Texture2D sun = ModContent.GetTexture("Terraria/Sun"); spriteBatch.Draw(sun, new Vector2(Main.screenWidth / 2, Main.screenHeight / 8), null, Color.DeepPink * SGAmod.ProgramSkyAlpha, 0, new Vector2(sun.Width / 2f, sun.Height / 2f), new Vector2(5f, 5f) * SGAmod.ProgramSkyAlpha, SpriteEffects.None, 0f); } Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.GameViewMatrix.ZoomMatrix); //Main.spriteBatch.End(); //Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.Transform); }
/// <summary>Least squares solution of <c>X * A = B</c></summary> /// <param name="value">Right-hand-side matrix with as many columns as <c>A</c> and any number of rows.</param> /// <returns>A matrix that minimized the two norm of <c>X * Q * R - B</c>.</returns> /// <exception cref="T:System.ArgumentException">Matrix column dimensions must be the same.</exception> /// <exception cref="T:System.InvalidOperationException">Matrix is rank deficient.</exception> public Single[,] SolveTranspose(Single[,] value) { if (value == null) { throw new ArgumentNullException("value", "Matrix cannot be null."); } if (value.Columns() != qr.Rows()) { throw new ArgumentException("Matrix row dimensions must agree."); } if (!this.FullRank) { throw new InvalidOperationException("Matrix is rank deficient."); } // Copy right hand side int count = value.Rows(); var X = value.Transpose(); // Compute Y = transpose(Q)*B for (int k = 0; k < p; k++) { for (int j = 0; j < count; j++) { Single s = 0; for (int i = k; i < n; i++) { s += qr[i, k] * X[i, j]; } s = -s / qr[k, k]; for (int i = k; i < n; i++) { X[i, j] += s * qr[i, k]; } } } // Solve R*X = Y; for (int k = m - 1; k >= 0; k--) { for (int j = 0; j < count; j++) { X[k, j] /= Rdiag[k]; } for (int i = 0; i < k; i++) { for (int j = 0; j < count; j++) { X[i, j] -= X[k, j] * qr[i, k]; } } } return(Matrix.Create(count, p, X, transpose: true)); }
private unsafe void LDLt(Single[,] value) { n = value.GetLength(0); L = new Single[n, n]; D = new Single[n]; robust = true; Single[,] a = value; Single[] v = new Single[n]; this.positiveDefinite = true; this.symmetric = true; Single d = D[0] = v[0] = a[0, 0]; if (d == 0) { this.positiveDefinite = false; } for (int j = 1; j < n; j++) { L[j, 0] = a[j, 0] / d; } for (int j = 1; j < n; j++) { d = 0; for (int k = 0; k < j; k++) { v[k] = L[j, k] * D[k]; d += L[j, k] * v[k]; } d = D[j] = v[j] = a[j, j] - d; // Use a tolerance for positive-definiteness this.positiveDefinite &= (d > (Single)1e-14 * Math.Abs(a[j, j])); for (int k = j + 1; k < n; k++) { Single s = 0; for (int i = 0; i < j; i++) { s += L[k, i] * v[i]; } L[k, j] = (a[k, j] - s) / d; this.symmetric = this.symmetric & (a[k, j] == a[j, k]); } } for (int i = 0; i < n; i++) { L[i, i] += 1; } }
public TcTorBlock32(Int32 prmIndex, Int32 prmRows, Int32 prmColumns) { Index = prmIndex; Rows = prmRows; Columns = prmColumns; East = 0; North = 0; Points = new Single[prmRows, prmColumns]; }
/// <summary> /// Initializes a new instance of Noise2D. /// </summary> /// <param name="width">The width of the noise map.</param> /// <param name="height">The height of the noise map.</param> /// <param name="generator">The generator module.</param> public Noise2D(Int32 width, Int32 height, ModuleBase generator = null) { _generator = generator; _width = width; _height = height; _data = new Single[width, height]; _ucWidth = width + _ucBorder * 2; _ucHeight = height + _ucBorder * 2; _ucData = new Single[width + _ucBorder * 2, height + _ucBorder * 2]; }
/// <summary> /// Solves a set of equation systems of type <c>A * X = B</c>. /// </summary> /// <param name="value">Right hand side matrix with as many rows as <c>A</c> and any number of columns.</param> /// <returns>Matrix <c>X</c> so that <c>L * U * X = B</c>.</returns> /// public Single[,] Solve(Single[,] value) { if (value == null) { throw new ArgumentNullException("value"); } if (value.GetLength(0) != rows) { throw new DimensionMismatchException("value", "The matrix should have the same number of rows as the decomposition."); } if (!Nonsingular) { throw new InvalidOperationException("Matrix is singular."); } // Copy right hand side with pivoting int count = value.GetLength(1); Single[,] X = value.Get(pivotVector, null); // Solve L*Y = B(piv,:) for (int k = 0; k < cols; k++) { for (int i = k + 1; i < cols; i++) { for (int j = 0; j < count; j++) { X[i, j] -= X[k, j] * lu[i, k]; } } } // Solve U*X = Y; for (int k = cols - 1; k >= 0; k--) { for (int j = 0; j < count; j++) { X[k, j] /= lu[k, k]; } for (int i = 0; i < k; i++) { for (int j = 0; j < count; j++) { X[i, j] -= X[k, j] * lu[i, k]; } } } return(X); }
/// <summary> /// Solves a set of equation systems of type <c>X * A = B</c>. /// </summary> /// <param name="value">Right hand side matrix with as many columns as <c>A</c> and any number of rows.</param> /// <returns>Matrix <c>X</c> so that <c>X * L * U = A</c>.</returns> /// public Single[,] SolveTranspose(Single[,] value) { if (value == null) { throw new ArgumentNullException("value"); } if (value.GetLength(0) != rows) { throw new DimensionMismatchException("value", "The matrix should have the same number of rows as the decomposition."); } if (!Nonsingular) { throw new SingularMatrixException("Matrix is singular."); } // Copy right hand side with pivoting var X = value.Get(null, pivotVector); int count = X.GetLength(1); // Solve L*Y = B(piv,:) for (int k = 0; k < rows; k++) { for (int i = k + 1; i < rows; i++) { for (int j = 0; j < count; j++) { X[j, i] -= X[j, k] * lu[i, k]; } } } // Solve U*X = Y; for (int k = rows - 1; k >= 0; k--) { for (int j = 0; j < count; j++) { X[j, k] /= lu[k, k]; } for (int i = 0; i < k; i++) { for (int j = 0; j < count; j++) { X[j, i] -= X[j, k] * lu[i, k]; } } } return(X); }
/// <summary> /// Creates a new Cholesky decomposition directly from /// an already computed left triangular matrix <c>L</c>. /// </summary> /// <param name="leftTriangular">The left triangular matrix from a Cholesky decomposition.</param> /// public static CholeskyDecompositionF FromLeftTriangularMatrix(Single[,] leftTriangular) { var chol = new CholeskyDecompositionF(); chol.n = leftTriangular.Rows(); chol.L = leftTriangular; chol.positiveDefinite = true; chol.robust = false; chol.D = Vector.Ones <Single>(chol.n); return(chol); }
private unsafe void LLt(Single[,] value) { n = value.GetLength(0); L = new Single[n, n]; D = new Single[n]; for (int i = 0; i < D.Length; i++) { D[i] = 1; } robust = false; Single[,] a = value; this.positiveDefinite = true; this.symmetric = true; fixed(Single *ptrL = L) { for (int j = 0; j < n; j++) { Single *Lrowj = ptrL + j * n; Single d = 0; for (int k = 0; k < j; k++) { Single *Lrowk = ptrL + k * n; Single s = 0; for (int i = 0; i < k; i++) { s += Lrowk[i] * Lrowj[i]; } Lrowj[k] = s = (a[j, k] - s) / Lrowk[k]; d += s * s; this.symmetric = this.symmetric & (a[k, j] == a[j, k]); } d = a[j, j] - d; // Use a tolerance for positive-definiteness this.positiveDefinite &= (d > (Single)1e-14 * Math.Abs(a[j, j])); Lrowj[j] = (Single)System.Math.Sqrt((double)System.Math.Max(d, 0)); for (int k = j + 1; k < n; k++) { Lrowj[k] = 0; } } } }
public TimingRingData(byte ringNum, byte[] includedPhases, Single[,] phaseIntervalTimes) { _id = ringNum; _phases = new List <PhaseTimingData>(); _phaseSequence = new List <byte>(); _activePhaseIndex = 1; //PhaseData newPhase = new PhaseData(); //add dummy phase to zero index //_phases.Add(newPhase); SetPhaseIntervalTimes(includedPhases, phaseIntervalTimes); }
public static DenseMatrix ReadDenseMatrixFromFile(string fileName, string varName = "DataMatrix") { double[,] res = null; DenseMatrix dmRes = null; if (!ServiceTools.CheckIfDirectoryExists(fileName)) { return(null); } NetCDFDataSet ds = null; try { ds = new NetCDFDataSet("msds:nc?file=" + fileName + "&enableRollback=false", ResourceOpenMode.ReadOnly); } catch (Exception ex) { throw ex; } //Variable<double> thDataVar = ds.AddVariable<double>("dataMatrix", dmData.ToArray(), "y", "x"); //Variable<double> thDataVar = ds.Variables foreach (Variable theVar in ds) { if (theVar.Name != varName) { continue; } else { if (theVar.TypeOfData == typeof(double)) { res = (double[, ])theVar.GetData(); dmRes = DenseMatrix.OfArray(res); } else if (theVar.TypeOfData == typeof(Single)) { Single[,] res1 = (Single[, ])theVar.GetData(); dmRes = DenseMatrix.Create(theVar.Dimensions[0].Length, theVar.Dimensions[1].Length, ((i, j) => { return(Convert.ToDouble(res1[i, j])); })); } break; } } return(dmRes); }
//----------------------------------------------------------------------------- static public Double Average(Single[,] prmData) { Int32 rows = prmData.GetLength(0); Int32 cols = prmData.GetLength(1); int i, j; Double sum = 0.0; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { sum += prmData[i, j]; } } return(sum / rows * cols); }
//----------------------------------------------------------------------------- static public Double StDev(Single[,] prmData, Double prmAvg) { Int32 rows = prmData.GetLength(0); Int32 cols = prmData.GetLength(1); int i, j; Double sum = 0.0; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { sum += Math.Pow(prmData[i, j] - prmAvg, 2); } } return(Math.Sqrt(sum / (rows * cols - 1))); }
/// <summary> /// Creates a new Cholesky decomposition directly from /// an already computed left triangular matrix <c>L</c>. /// </summary> /// <param name="leftTriangular">The left triangular matrix from a Cholesky decomposition.</param> /// public static CholeskyDecompositionF FromLeftTriangularMatrix(Single[,] leftTriangular) { var chol = new CholeskyDecompositionF(); chol.n = leftTriangular.GetLength(0); chol.L = leftTriangular; chol.symmetric = true; chol.positiveDefinite = true; chol.robust = false; chol.D = new Single[chol.n]; for (int i = 0; i < chol.D.Length; i++) { chol.D[i] = 1; } return(chol); }
/// <summary> /// Construct an eigenvalue decomposition.</summary> /// <param name="value"> /// The matrix to be decomposed.</param> /// <param name="assumeSymmetric"> /// Defines if the matrix should be assumed as being symmetric /// regardless if it is or not. Default is <see langword="false"/>.</param> /// <param name="inPlace"> /// Pass <see langword="true"/> to perform the decomposition in place. The matrix /// <paramref name="value"/> will be destroyed in the process, resulting in less /// memory comsumption.</param> public EigenvalueDecompositionF(Single[,] value, bool assumeSymmetric, bool inPlace) { if (value == null) { throw new ArgumentNullException("value", "Matrix cannot be null."); } if (value.GetLength(0) != value.GetLength(1)) { throw new ArgumentException("Matrix is not a square matrix.", "value"); } n = value.GetLength(1); V = new Single[n, n]; d = new Single[n]; e = new Single[n]; this.symmetric = assumeSymmetric; if (this.symmetric) { V = inPlace ? value : (Single[, ])value.Clone(); // Tridiagonalize. this.tred2(); // Diagonalize. this.tql2(); } else { H = inPlace ? value : (Single[, ])value.Clone(); ort = new Single[n]; // Reduce to Hessenberg form. this.orthes(); // Reduce Hessenberg to real Schur form. this.hqr2(); } }
//------------------------------------------------------------------ protected void Write(BinaryWriter wrt, Single[,] prmPoints) { Int32 rows = prmPoints.GetLength(0); Int32 columns = prmPoints.GetLength(1); Int32 length = rows * columns; Byte[] byteStream; for (int i = 0; i < rows; i++) { byteStream = new Byte[columns * sizeof(Single)]; for (int j = 0; j < columns; j++) { Array.Copy(BitConverter.GetBytes(prmPoints[i, j]), 0, byteStream, j * sizeof(Single), sizeof(Single)); } wrt.Write(byteStream); } }
private void WriteDistance(Single[,] result, string path) { var p_size = result.GetLength(0); var d_size = result.GetLength(1); using (var writer = new StreamWriter(path)) { writer.WriteLine("{"); for (var p = 0; p < p_size; p++) { writer.Write("{{{0:0}", result[p, 0]); for (var d = 1; d < d_size; d++) { writer.Write(",{0:0}", result[p, d]); } writer.WriteLine("},"); } writer.WriteLine("};"); } }
private void setnet(Single[,] Net, Point[] Pos) { int maxlength = (int)(Math.Min(canvas1.Width, canvas1.Height) * 0.9); int minlength = maxlength / size; for (int i = 0; i < size; i++) { Pos[i].X = R.Next(minlength, maxlength); Pos[i].Y = R.Next(minlength, maxlength); for (int j = 0; j <= i; j++) { Net[i, j] = distance(Pos[i], Pos[j]); Net[j, i] = Net[i, j]; if (i == j) { Net[i, j] = 0; } } } }
/// <summary> /// Called when ditherer is about to be prepared. /// </summary> protected virtual void OnPrepare() { // creates coeficient matrix and determines the matrix factor/divisor/maximum CachedMatrix = CreateCoeficientMatrix(); Single maximum = GetMatrixFactor(); // prepares the cache arrays Int32 width = CachedMatrix.GetLength(1); Int32 height = CachedMatrix.GetLength(0); CachedSummedMatrix = new Single[height, width]; // caches the matrix (and division by a sum) for (Int32 y = 0; y < height; y++) { for (Int32 x = 0; x < width; x++) { CachedSummedMatrix[y, x] = CachedMatrix[y, x] / maximum; } } }
//----------------------------------------------------------------------------- static public Double TorAverage(Single[,] prmData) { Int32 rows = prmData.GetLength(0); Int32 cols = prmData.GetLength(1); int i, j; Double count = 0.0; Double sum = 0.0; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (prmData[i, j] != c_TorNullHeight) { sum += prmData[i, j]; count++; } } } return(count > 0 ? sum / count : c_TorNullHeight); }
//----------------------------------------------------------------------------- static public Double TorStDev(Single[,] prmData, Double prmAvg) { Int32 rows = prmData.GetLength(0); Int32 cols = prmData.GetLength(1); int i, j; Double sum = 0.0; Double count = 0.0; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (prmData[i, j] != c_TorNullHeight) { sum += Math.Pow(prmData[i, j] - prmAvg, 2); count++; } } } return(count > 1 ? Math.Sqrt(sum / (count - 1)) : c_TorNullHeight); }
private void shownet(Single[,] Net) { canvas1.Children.Clear(); Line myLine; for (int i = 0; i < size; i++) { for (int j = 0; j < i; j++) { if (Net[i, j] != 0) { myLine = new Line(); myLine.Stroke = Brushes.Black; myLine.X1 = Positions[i].X; myLine.X2 = Positions[j].X; myLine.Y1 = Positions[i].Y; myLine.Y2 = Positions[j].Y; myLine.StrokeThickness = 1; canvas1.Children.Add(myLine); } } } Rectangle myMarker; for (int i = 0; i < size; i++) { myMarker = new Rectangle(); myMarker.Stroke = Brushes.Black; myMarker.Fill = Brushes.Red; myMarker.Height = 10; myMarker.Width = 10; myMarker.SetValue(Canvas.TopProperty, Positions[i].Y - myMarker.Height / 2); myMarker.SetValue(Canvas.LeftProperty, Positions[i].X - myMarker.Width / 2); canvas1.Children.Add(myMarker); } }
public void SetPhaseIntervalTimes(byte[] includedPhases, Single[,] phaseIntervalTimes) { int PhaseIndex = -1; _phases.Clear(); foreach (byte phaseNum in includedPhases) { //if (phaseNum == 0) // break; //PhaseIndex = phaseNum - (4 * (ringNum - 1)); PhaseIndex++; PhaseTimingData newPhase = new PhaseTimingData(phaseNum, phaseIntervalTimes[PhaseIndex, 0], phaseIntervalTimes[PhaseIndex, 1], phaseIntervalTimes[PhaseIndex, 2], phaseIntervalTimes[PhaseIndex, 3]); _phases.Add(newPhase); if (phaseIntervalTimes[PhaseIndex, 0] > 0) { _phaseSequence.Add(phaseNum); } } }
public Mesh(string Filepath, bool BodyMesh) { BinaryReader Reader = new BinaryReader(File.Open(Filepath, FileMode.Open)); IsBodyMesh = BodyMesh; m_Version = Endian.SwapInt32(Reader.ReadInt32()); m_BoneCount = Endian.SwapInt32(Reader.ReadInt32()); for (int i = 0; i < m_BoneCount; i++) { byte StrLen = Reader.ReadByte(); string BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLen)); m_BoneNames.Add(BoneName); } m_FaceCount = Endian.SwapInt32(Reader.ReadInt32()); m_Faces = new Face[m_FaceCount]; for (int i = 0; i < m_FaceCount; i++) { m_Faces[i].AVertexIndex = Endian.SwapInt32(Reader.ReadInt32()); m_Faces[i].BVertexIndex = Endian.SwapInt32(Reader.ReadInt32()); m_Faces[i].CVertexIndex = Endian.SwapInt32(Reader.ReadInt32()); } m_BndCount = Endian.SwapInt32(Reader.ReadInt32()); /*m_BoneBindings = new int[m_BndCount, 5]; for (int i = 0; i < m_BndCount; i++) for (int j = 0; j < 5; j++) m_BoneBindings[i, j] = Endian.SwapInt32(Reader.ReadInt32());*/ for (int i = 0; i < m_BndCount; i++) { BoneBinding Binding = new BoneBinding(); Binding.BoneIndex = Endian.SwapInt32(Reader.ReadInt32()); Binding.FirstVertex = Endian.SwapInt32(Reader.ReadInt32()); Binding.VertexCount = Endian.SwapInt32(Reader.ReadInt32()); Binding.FirstBlendedVert = Endian.SwapInt32(Reader.ReadInt32()); Binding.BlendedVertexCount = Endian.SwapInt32(Reader.ReadInt32()); m_BoneBindings.Add(Binding); } m_RealVertexCount = Endian.SwapInt32(Reader.ReadInt32()); m_TexVerticies = new Single[m_RealVertexCount, 3]; for (int i = 0; i < m_RealVertexCount; i++) { m_TexVerticies[i, 0] = i; m_TexVerticies[i, 1] = Reader.ReadSingle(); m_TexVerticies[i, 2] = Reader.ReadSingle(); } m_BlendCount = Endian.SwapInt32(Reader.ReadInt32()); for (int i = 0; i < m_BlendCount; i++) { BlendData Blend = new BlendData(); Blend.WeightFixed = (float)(Endian.SwapInt32(Reader.ReadInt32())) / 0x8000; Blend.OtherVertexIndex = Endian.SwapInt32(Reader.ReadInt32()); m_BlendData.Add(Blend); } m_TotalVertexCount = Endian.SwapInt32(Reader.ReadInt32()); m_VertexData = new Single[m_TotalVertexCount, 6]; m_TransformedVertices = new Vertex[m_TotalVertexCount]; for (int i = 0; i < m_TotalVertexCount; i++) { m_VertexData[i, 0] = Reader.ReadSingle(); m_VertexData[i, 1] = Reader.ReadSingle(); m_VertexData[i, 2] = Reader.ReadSingle(); //Normals m_VertexData[i, 3] = Reader.ReadSingle(); m_VertexData[i, 4] = Reader.ReadSingle(); m_VertexData[i, 5] = Reader.ReadSingle(); if (i < m_RealVertexCount) { if (m_TransformedVertices[i] == null) m_TransformedVertices[i] = new Vertex(); //Fixed vertex m_TransformedVertices[i].TextureCoord.X = m_TexVerticies[i, 1]; m_TransformedVertices[i].TextureCoord.Y = m_TexVerticies[i, 2]; } else { if (m_TransformedVertices[i] == null) m_TransformedVertices[i] = new Vertex(); //Blended vertex m_TransformedVertices[i].Blend.WeightFixed = m_BlendData[i - m_RealVertexCount].WeightFixed; m_TransformedVertices[i].Blend.OtherVertexIndex = m_BlendData[i - m_RealVertexCount].OtherVertexIndex; } } }
private void ResetVariables() { H = new Single[dim, 2]; // Jacobian matrix HT = new Single[2, dim]; // Transpose Jacobina matrix Z = new Single[dim, 1]; // measurement value matrix hX = new Single[dim, 1]; // estimate value matrix PoHT = new Single[2, dim]; HPoHTR = new Single[dim, dim]; IHPoHTR = new Single[dim, dim]; K = new Single[2, dim]; // Kalman gain KdZ = new Single[2, 1]; Xk = new Single[3, 1]; // state Xke = new Single[3, 1]; // estimate state KH = new Single[2, 2] { { 1, 0 }, { 0, 1 } }; KHPo = new Single[2, 2] { { 1, 0 }, { 0, 1 } }; P = new Single[2, 2]; // covariance matrix }
public Single[,] rotation; /* The rotation of the camera coordinate system with respect to the world coordinate system. The world coordinate system coincides with the depth camera coordinate system. */ public StreamTransform() { translation = new Single[3]; rotation = new Single[3,3]; }
/// <summary> /// Construct an eigenvalue decomposition.</summary> /// /// <param name="value"> /// The matrix to be decomposed.</param> /// <param name="assumeSymmetric"> /// Defines if the matrix should be assumed as being symmetric /// regardless if it is or not. Default is <see langword="false"/>.</param> /// <param name="inPlace"> /// Pass <see langword="true"/> to perform the decomposition in place. The matrix /// <paramref name="value"/> will be destroyed in the process, resulting in less /// memory comsumption.</param> /// <param name="sort"> /// Pass <see langword="true"/> to sort the eigenvalues and eigenvectors at the end /// of the decomposition.</param> /// public EigenvalueDecompositionF(Single[,] value, bool assumeSymmetric, bool inPlace = false, bool sort = false) { if (value == null) throw new ArgumentNullException("value", "Matrix cannot be null."); if (value.GetLength(0) != value.GetLength(1)) throw new ArgumentException("Matrix is not a square matrix.", "value"); n = value.GetLength(1); V = new Single[n, n]; d = new Single[n]; e = new Single[n]; this.symmetric = assumeSymmetric; if (this.symmetric) { V = inPlace ? value : (Single[,])value.Clone(); // Tridiagonalize. this.tred2(); // Diagonalize. this.tql2(); } else { H = inPlace ? value : (Single[,])value.Clone(); ort = new Single[n]; // Reduce to Hessenberg form. this.orthes(); // Reduce Hessenberg to real Schur form. this.hqr2(); } if (sort) { // Sort eigenvalues and vectors in descending order var idx = Vector.Range(n); Array.Sort(idx, (i, j) => { if (Math.Abs(d[i]) == Math.Abs(d[j])) return -Math.Abs(e[i]).CompareTo(Math.Abs(e[j])); return -Math.Abs(d[i]).CompareTo(Math.Abs(d[j])); }); this.d = this.d.Get(idx); this.e = this.e.Get(idx); this.V = this.V.Get(null, idx); } }
static void Main(string[] args) { BinaryReader Reader = new BinaryReader( File.Open("avatardata\\heads\\meshes\\fahc101fa_longwave-head-head.mesh", FileMode.Open)); m_Version = Endian.SwapInt32(Reader.ReadInt32()); Console.WriteLine("Version: " + m_Version + "\n"); m_BoneCount = Endian.SwapInt32(Reader.ReadInt32()); Console.WriteLine("Number of bones: " + m_BoneCount); for (int i = 0; i < m_BoneCount; i++) { byte StrLen = Reader.ReadByte(); string BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLen)); m_BoneNames.Add(BoneName); Console.WriteLine(BoneName); } m_FaceCount = Endian.SwapInt32(Reader.ReadInt32()); m_Faces = new Face[m_FaceCount]; Console.WriteLine("Number of faces: " + m_FaceCount); for (int i = 0; i < m_FaceCount; i++) { m_Faces[i].X = Endian.SwapInt32(Reader.ReadInt32()); m_Faces[i].Y = Endian.SwapInt32(Reader.ReadInt32()); m_Faces[i].Z = Endian.SwapInt32(Reader.ReadInt32()); } m_BndCount = Endian.SwapInt32(Reader.ReadInt32()); m_BoneBindings = new int[m_BndCount, 5]; Console.WriteLine("Number of bonebindings: " + m_BndCount); for (int i = 0; i < m_BndCount; i++) for (int j = 0; j < 5; j++) m_BoneBindings[i, j] = Endian.SwapInt32(Reader.ReadInt32()); m_NumTexVerticies = Endian.SwapInt32(Reader.ReadInt32()); m_TexVerticies = new Single[m_NumTexVerticies, 3]; Console.WriteLine("Number of texture verticies: " + m_NumTexVerticies); switch (m_Version) { case 0: for (int i = 0; i < m_NumTexVerticies; i++) { //These coordinates aren't reversed, and the Endian class //doesn't support swapping Single values, so do it manually... m_TexVerticies[i, 0] = i; byte[] XOffset = Reader.ReadBytes(4); byte[] YOffset = Reader.ReadBytes(4); Array.Reverse(XOffset); Array.Reverse(YOffset); m_TexVerticies[i, 1] = BitConverter.ToSingle(XOffset, 0); m_TexVerticies[i, 2] = BitConverter.ToSingle(YOffset, 0); } break; default: for (int i = 0; i < m_NumTexVerticies; i++) { m_TexVerticies[i, 0] = i; m_TexVerticies[i, 1] = Reader.ReadSingle(); //X offset m_TexVerticies[i, 2] = Reader.ReadSingle(); //Y offset } break; } m_BlendCount = Endian.SwapInt32(Reader.ReadInt32()); m_BlendData = new int[m_BlendCount, 2]; Console.WriteLine("Number of blends: " + m_BlendCount); for (int i = 0; i < m_BlendCount; i++) { m_BlendData[i, 1] = Endian.SwapInt32(Reader.ReadInt32()); m_BlendData[i, 0] = Endian.SwapInt32(Reader.ReadInt32()); } m_VertexCount = Endian.SwapInt32(Reader.ReadInt32()); m_VertexData = new Single[m_VertexCount, 7]; Console.WriteLine("Number of verticies: " + m_VertexCount); switch (m_Version) { case 0: for (int i = 0; i < m_VertexCount; i++) { m_VertexData[i, 0] = i; for (int j = 0; j < 6; j++) m_VertexData[i, j] = Reader.ReadSingle(); } break; default: for (int i = 0; i < m_VertexCount; i++) { m_VertexData[i, 0] = i; //These coordinates are apparently reversed, but since the file is Big-Endian, //and the default is reading Little-Endian, there should be no need to convert... for (int j = 0; j < 6; j++) m_VertexData[i, j] = Reader.ReadSingle(); } break; } Console.ReadLine(); }
public DijkstraGraph(Int32 vertexCount) { _vertexCount = vertexCount; _adjacencyMatrix = new Single[_vertexCount,_vertexCount]; }
/// <summary> /// Construct an eigenvalue decomposition.</summary> /// <param name="value"> /// The matrix to be decomposed.</param> /// <param name="assumeSymmetric"> /// Defines if the matrix should be assumed as being symmetric /// regardless if it is or not. Default is <see langword="false"/>.</param> /// <param name="inPlace"> /// Pass <see langword="true"/> to perform the decomposition in place. The matrix /// <paramref name="value"/> will be destroyed in the process, resulting in less /// memory comsumption.</param> public EigenvalueDecompositionF(Single[,] value, bool assumeSymmetric, bool inPlace) { if (value == null) { throw new ArgumentNullException("value", "Matrix cannot be null."); } if (value.GetLength(0) != value.GetLength(1)) { throw new ArgumentException("Matrix is not a square matrix.", "value"); } n = value.GetLength(1); V = new Single[n, n]; d = new Single[n]; e = new Single[n]; this.symmetric = assumeSymmetric; if (this.symmetric) { V = inPlace ? value : (Single[,])value.Clone(); // Tridiagonalize. this.tred2(); // Diagonalize. this.tql2(); } else { H = inPlace ? value : (Single[,])value.Clone(); ort = new Single[n]; // Reduce to Hessenberg form. this.orthes(); // Reduce Hessenberg to real Schur form. this.hqr2(); } }