public override bool Equals(Object obj) { if (obj is RegionParameters) { RegionParameters r = (RegionParameters)obj; return(PatternType.Equals(r.PatternType) && Start == r.Start && End == r.End && Depth == r.Depth); } return(false); }
public Dictionary<string, Part> GetParts(IEnumerable<Bitmap> positives, IEnumerable<Bitmap> negatives) { Dictionary<string, Part> parts = new Dictionary<string, Part>(); List<string> edgetypes = new List<string>() { "repeating" }; ArrayList interiortypes = new ArrayList { "horizontal", "vertical", "single" }; RegionParameters minhoriz = new RegionParameters(null, c_minCornerSize, c_minCornerSize, 1); RegionParameters maxhoriz = new RegionParameters(null, c_maxCornerSize, c_maxCornerSize, c_maxCornerSize); RegionParameters minvert = new RegionParameters(null, c_minCornerSize, c_minCornerSize, 1); RegionParameters maxvert = new RegionParameters(null, c_maxCornerSize, c_maxCornerSize, c_maxCornerSize); int smallestWidth = int.MaxValue; int smallestHeight = int.MaxValue; foreach (Bitmap example in positives) { if (example.Width < smallestWidth) smallestWidth = example.Width; if (example.Height < smallestHeight) smallestHeight = example.Height; } smallestHeight -= 2; smallestWidth -= 2; maxhoriz.Depth = (int)Math.Min(smallestHeight / 2, maxhoriz.Depth); maxhoriz.Start = (int)Math.Min(smallestWidth / 2, maxhoriz.Start); maxhoriz.End = (int)Math.Min(smallestWidth / 2, maxhoriz.End); maxvert.Depth = (int)Math.Min(smallestWidth / 2, maxvert.Depth); maxvert.Start = (int)Math.Min(smallestHeight / 2, maxvert.Start); maxvert.End = (int)Math.Min(smallestHeight / 2, maxvert.End); parts.Add("topleft", new Part(GetCornerValues(smallestWidth, smallestHeight))); parts.Add("topright", new Part(GetCornerValues(smallestWidth, smallestHeight))); parts.Add("bottomleft", new Part(GetCornerValues(smallestWidth, smallestHeight))); parts.Add("bottomright", new Part(GetCornerValues(smallestWidth, smallestHeight))); parts.Add("top", new Part(GetEdgeValues(edgetypes, minhoriz, maxhoriz))); parts.Add("bottom", new Part(GetEdgeValues(edgetypes, minhoriz, maxhoriz))); parts.Add("left", new Part(GetEdgeValues(edgetypes, minvert, maxvert))); parts.Add("right", new Part(GetEdgeValues(edgetypes, minvert, maxvert))); parts.Add("interior", new Part(interiortypes)); return parts; }
private ArrayList GetEdgeValues(List<string> types, RegionParameters min, RegionParameters max) { ArrayList values = new ArrayList(); foreach (string type in types) { for (int depth = min.Depth; depth <= max.Depth; depth++) { for (int left = min.Start; left <= max.Start; left++) { for (int right = min.End; right <= max.End; right++) { object value = new RegionParameters(type, left, right, depth); values.Add(value); } } } } return values; }