public void Refresh(int i, int j, int minI, int minJ) { List <DTW.Pair> path = DTW.OptimalWarpingPath(totalCostMatrix, minI, minJ); int iOffset = i - writeableBitmap.PixelWidth; int jOffset = j - writeableBitmap.PixelHeight; if (iOffset < 0) { iOffset = 0; } if (jOffset < 0) { jOffset = 0; } // draw cost matrix int color; for (int x = 0; x < writeableBitmap.PixelWidth; x++) { for (int y = 0; y < writeableBitmap.PixelHeight; y++) { double val = cellCostMatrix[iOffset + x, jOffset + y]; if (totalCostMatrix[iOffset + x, jOffset + y] == double.PositiveInfinity) { color = undefColor; } else if (val < 0) { color = minColor; } else if (val >= colorPalette.Length) { color = maxColor; } else { color = colorPalette[(int)val]; } pixels[writeableBitmap.PixelWidth * y + x] = color; } } // draw path foreach (DTW.Pair p in path) { if (p.i1 <= iOffset || p.i2 <= jOffset) { break; } pixels[writeableBitmap.PixelWidth * (p.i2 - jOffset - 1) + (p.i1 - iOffset - 1)] = pathColor; } // paint writeableBitmap.WritePixels(new Int32Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight), pixels, writeableBitmap.PixelWidth * 4, 0); InvalidateVisual(); }