public Feature Create(Bitmap bitmap) { foreach (Feature feature in features) { if (Bitmap.ExactlyMatches(bitmap, feature.Bitmap)) { return feature; } } Feature f = new Feature(features.Count, bitmap); features.Add(f); return f; }
private static Ptype CreatePtypeFromMutable(Mutable prototypebuildargs, Model[] models, Feature.Factory features, IEnumerable<Mutable> allptypes) { Dictionary<string, Bitmap> ptypefeatureshash = prototypebuildargs.Features; Dictionary<string,Feature> ptypefeatures = new Dictionary<string, Feature>(); foreach (String fname in ptypefeatureshash.Keys) { Feature feature = features.Create(ptypefeatureshash[fname]); ptypefeatures.Add(fname, feature); } Model model = null; foreach(Model m in models) if(m.Name.Equals(prototypebuildargs.Model)) { model = m; break; } Dictionary<string, Region> rdict = (Dictionary<string,Region>)new Dictionary<string,Region>(prototypebuildargs.Regions); // if (prototypebuildargs instanceof Hierarchical.HierarchicalMutable) // { // Hierarchical.HierarchicalMutable mhp = (Hierarchical.HierarchicalMutable)prototypebuildargs; // Dictionary<String, Ptype> children = new Dictionary<String, Ptype>(); // for (int c = 0; c < mhp.childrenNames.size(); c++) // { // Mutable ptype = null; // for(Mutable p : allptypes){ // if(p.id.equals(mhp.children.get(c))){ // ptype = p; // break; // } // } // children.put(mhp.childrenNames.get(c), createPtypeFromMutable( ptype, models, features, allptypes)); // } // return new Hierarchical(mhp.id, fdict, rdict, model, children); // } // else return new Ptype(prototypebuildargs.Id, ptypefeatures, rdict, model); }
private IEnumerable<Tree> GetCorrespondingTopLefts(Feature topleft, IBoundingBox topright, IEnumerable<Tree> features) { List<Tree> brs = new List<Tree>(); foreach(Tree f in features){ if(topleft.Equals(f["feature"]) && IsLeftOf(f, topright) && IsHorizontallyAligned(topright, f)){ brs.Add(f); } } return brs; }
private IEnumerable<Tree> GetBottomRightsFromBottomLeft(Feature bottomright, IBoundingBox bottomleft, IEnumerable<Tree> features) { List<Tree> brs = new List<Tree>(); foreach(Tree f in features){ if(bottomright.Equals(f["feature"]) && IsLeftOf(bottomleft, f) && IsHorizontallyAligned(f, bottomleft)){ brs.Add(f); } } return brs; }
private IEnumerable<Tree> GetTopRightsFromBottomRight(Feature topright, IBoundingBox bottomright, IEnumerable<Tree> features) { List<Tree> brs = new List<Tree>(); foreach(Tree f in features){ if(topright.Equals(f["feature"]) && IsAbove(f, bottomright) && IsVerticallyAligned(bottomright, f)){ brs.Add(f); } } return brs; }
private IEnumerable<Tree> GetCorrespondingBottomRights(Feature bottomright, IBoundingBox topright, IEnumerable<Tree> features) { List<Tree> brs = new List<Tree>(); foreach(Tree f in features){ if(bottomright.Equals(f["feature"]) && IsAbove(topright, f) && IsVerticallyAligned(f, topright)){ brs.Add(f); } } return brs; }
private Tree GetTopLeft(Feature topleft, IBoundingBox topright, IBoundingBox bottomleft, IEnumerable<Tree> features) { foreach(Tree f in features){ if(topleft.Equals(f["feature"]) && IsAbove(f, bottomleft) && IsHorizontallyAligned(f, topright) && IsVerticallyAligned(bottomleft, f)) return f; } return null; }
public FeatureWrapper(Point hotspot, Feature feature){ this.Hotspot = hotspot; this.Feature = feature; }
/// <summary> /// Renders a corner part to a grid at the specified location. Each pixel /// of the corner is used to color a cell of the grid. /// </summary> /// <param name="corner">The corner feature to render.</param> /// <param name="location">The location in the grid where the corner will be rendered.</param> /// <param name="grid">The grid object that will be populated with the corner's pixels</param> public static void AddFeatureToGrid(Feature feature, Prefab.Point location, Grid grid) { for (int row = 0; row < feature.Bitmap.Height; row++) { for (int col = 0; col < feature.Bitmap.Width; col++) { AddPixelToGrid(feature.Bitmap[row, col], new Prefab.Point(location.X + col, location.Y + row), grid); } } }
/// <summary> /// Returns the bitmap offset that points to the least occurring pixel in this feature /// as specified by the pixel frequencies. Transparent pixels are ignored. /// </summary> /// <param name="feature">The feature used to find the offset.</param> /// <param name="pixelFrequencies">The frequencies of each pixel.</param> /// <returns>The bitmap offset that points to the least occurring pixel in this feature /// as specified by the pixel frequencies.</returns> private static Point GetLeastCommonPixel(Feature feature, Dictionary<int, int> pixelFrequencies) { int freqency = int.MaxValue; Point leastCommon = null; for (int row = 0; row < feature.Bitmap.Height; row++) { for (int column = 0; column < feature.Bitmap.Width; column++) { if (feature.Bitmap[row, column] != Feature.TRANSPARENT_VALUE && pixelFrequencies[feature.Bitmap[row, column]] < freqency) { leastCommon = new Point(column, row); freqency = pixelFrequencies[feature.Bitmap[row, column]]; } } } return leastCommon; }