private Structure.Region FindRegion(MappedPoint point) { for (int i = 0; i < interpolationPoints.Count; i += 4) { if (point.X >= interpolationPoints[i].X && point.X <= interpolationPoints[i + 2].X && point.Y >= interpolationPoints[i + 1].Y && point.Y <= interpolationPoints[i].Y) { this.tempAdd = addresses[i / 4]; this.tempS = contractivityFactors[i / 4]; MappedPoint[] points = new MappedPoint[]{ interpolationPoints[i], interpolationPoints[i+1],interpolationPoints[i+2], interpolationPoints[i+3]}; Structure.Region region = new FractalCompression.Structure.Region(points); region[0, region.Size] = interpolationPoints[0].Val; region[0, 0] = interpolationPoints[1].Val; region[region.Size, 0] = interpolationPoints[2].Val; region[region.Size, region.Size] = interpolationPoints[3].Val; return region; } } tempS = -1; tempAdd = -1; return null; }
// a - regionsInDomainRow private static FractalCompression.Structure.Region[,] PrepareRegions(Bitmap bitmap, int bigDelta, int a, out FractalCompression.Structure.Region[,] regions, out List<MappedPoint> interpolPoints) { int smallDelta = bigDelta / a; int regionsInColumn = bitmap.Height / smallDelta; int domainsInRow = bitmap.Width / bigDelta; int regionsInRow = domainsInRow * a; regions = new FractalCompression.Structure.Region[regionsInColumn, regionsInRow]; interpolPoints = new List<MappedPoint>(); int eastX, northY = 0; MappedPoint[] mp = new MappedPoint[4]; for (int i = 0; i < regionsInColumn; ++i) { eastX = 0; for (int j = 0; j < regionsInRow; ++j) { mp[0] = CreateMappedPoint(bitmap, eastX, northY + smallDelta - 1); mp[1] = CreateMappedPoint(bitmap, eastX, northY); mp[2] = CreateMappedPoint(bitmap, eastX + smallDelta - 1, northY); mp[3] = CreateMappedPoint(bitmap, eastX + smallDelta - 1, northY + smallDelta - 1); for (int k = 0; k < mp.Length; ++k) interpolPoints.Add(mp[k]); /*interpolPoints.Add(mp[1]); if (j == regionsInRow - 1) interpolPoints.Add(mp[2]); if (i == regionsInColumn - 1) { interpolPoints.Add(mp[0]); if (j == regionsInRow - 1) interpolPoints.Add(mp[3]); }*/ regions[i, j] = new FractalCompression.Structure.Region(mp); eastX += smallDelta; } northY += smallDelta; } Console.WriteLine(interpolPoints.Count +" interpolation points prepared"); return regions; }
private void DivideRegion(FractalCompression.Structure.Region r) { int hx = (r.Vertices[1].X + r.Vertices[2].X) / 2; int hy = (r.Vertices[2].Y + r.Vertices[3].Y) / 2; Point pN = new Point(hx, r.Vertices[1].Y); Point pE = new Point(r.Vertices[3].X, hy); Point pS = new Point(hx, r.Vertices[0].Y); Point pW = new Point(r.Vertices[0].X, hy); Point pC = new Point(hx, hy); FractalCompression.Structure.Region[] nRegs = new FractalCompression.Structure.Region[4]; nRegs[0] = new FractalCompression.Structure.Region(r.Vertices[0], new Point(pW.X, pW.Y + 1), new Point(pC.X, pC.Y + 1), pS); nRegs[1] = new FractalCompression.Structure.Region(pW, r.Vertices[1], pN, pC); nRegs[2] = new FractalCompression.Structure.Region(new Point(pC.X + 1, pC.Y), new Point(pN.X + 1, pN.Y), r.Vertices[2], pE); nRegs[3] = new FractalCompression.Structure.Region(new Point(pS.X + 1, pS.Y), new Point(pC.X + 1, pC.Y + 1), new Point(pE.X, pE.Y + 1), r.Vertices[3]); for (int i = 0; i < nRegs.Length; i++) { squeue2.Enqueue(nRegs[i]); for (int j = 0; j < 4; j++) AddInterpolationPoint(nRegs[i], j, bitmap); /*{ Point vert = nRegs[i].Vertices[j]; iqueue.Enqueue(new MappedPoint(vert.X, vert.Y, MNTools.GetBitmapValue(vert.X, vert.Y, bitmap))); }*/ /*AddInterpolationPoint(nRegs[0], 0, bitmap); AddInterpolationPoint(nRegs[0], 1, bitmap); AddInterpolationPoint(nRegs[1], 1, bitmap); AddInterpolationPoint(nRegs[2], 1, bitmap); AddInterpolationPoint(nRegs[2], 2, bitmap); for(int j=0; j<4; ++j) AddInterpolationPoint(nRegs[3], j, bitmap);*/ } }
public static FractalCompression.Structure.Region MapDomainToRegion(Domain domain, FractalCompression.Structure.Region region, Bitmap bitmap, Mapper mapper, int a) { //int smallDelta = region.Size + 1; int bigDelta = domain.Size + 1; int smallDelta = bigDelta / a; int domainMaxX = domain.Vertices[3].X; Point regCorner = region.Vertices[1]; double[,] mappedVals = new double [smallDelta, smallDelta]; int x, y; for (int i = 0; i < bigDelta; i++) { y = domain.Vertices[1].Y + i; x = domain.Vertices[1].X; if (i == 0) { mappedVals[0, 0] = MNTools.GetBitmapValue(region.Vertices[1].X, region.Vertices[1].Y, bitmap); for (int j = 1; j < bigDelta; ++j) { x += a; if (x > domainMaxX) break; MappedPoint mp = mapper.MapPoint(x, y, MNTools.GetBitmapValue(x, y, bitmap)); mappedVals[mp.X - regCorner.X, mp.Y - regCorner.Y] = mp.Val; } mappedVals[0, smallDelta - 1] = MNTools.GetBitmapValue(region.Vertices[2].X, region.Vertices[2].Y, bitmap); } else if (i == bigDelta - 1) { mappedVals[0, smallDelta - 1] = MNTools.GetBitmapValue(region.Vertices[0].X, region.Vertices[0].Y, bitmap); for (int j = 1; j < bigDelta; ++j) { x += a; if (x > domainMaxX) break; MappedPoint mp = mapper.MapPoint(x, y, MNTools.GetBitmapValue(x, y, bitmap)); mappedVals[mp.X - regCorner.X, mp.Y - regCorner.Y] = mp.Val; } mappedVals[smallDelta - 1, smallDelta - 1] = MNTools.GetBitmapValue(region.Vertices[3].X, region.Vertices[3].Y, bitmap); } else { for (int j = 0; j < bigDelta; ++j) { x += a; if (x > domainMaxX) break; MappedPoint mp = mapper.MapPoint(x, y, MNTools.GetBitmapValue(x, y, bitmap)); mappedVals[mp.X - regCorner.X, mp.Y - regCorner.Y] = mp.Val; } } } FractalCompression.Structure.Region mappedRegion = new FractalCompression.Structure.Region(region.Vertices, mappedVals); return mappedRegion; }