/// <summary> /// Adds an image to a grid. The ColumnSpan and RowSpan properties are set equal to the /// dimensions of the bitmap. /// </summary> /// <param name="image"></param> /// <param name="location"></param> /// <param name="grid"></param> public static void AddImageToGrid(Bitmap image, Prefab.Point location, Grid grid) { Image img = ViewablePrototypeItem.ToImage(image); grid.Children.Add(img); Grid.SetColumn(img, location.X); Grid.SetRow(img, location.Y); Grid.SetColumnSpan(img, image.Width); Grid.SetRowSpan(img, image.Height); }
//public List<System.Drawing.Bitmap> GetAllFrames() //{ // return GetFramesInRange(0, FrameCount); //} public List <BitmapSource> GetFramesInRange(int startInclusive, int count) { List <BitmapSource> frames = new List <BitmapSource>(); for (int i = startInclusive; i < startInclusive + count; i++) { if (i < FrameCount) { System.Drawing.Bitmap bmp = GetBitmap(i); BitmapSource src = ViewablePrototypeItem.ToBitmapSource(Bitmap.FromSystemDrawingBitmap(bmp)); frames.Add(src); } } return(frames); }
public void RemovePtypes(IEnumerable <string> ptypesremoved) { foreach (string ptype in ptypesremoved) { ViewablePrototypeItem prev = PrototypeItems.FirstOrDefault((i) => i.Guid == ptype); ViewablePrototypeItem selectedPrev = SelectedPrototypes.FirstOrDefault((i) => i.Guid == ptype); if (prev != null) { PrototypeItems.Remove(prev); } if (selectedPrev != null) { SelectedPrototypes.Remove(selectedPrev); } } }
public Visual Visualize(Ptype ptype, object parameter = null) { if (!ptype.Model.Name.Equals("onepart")) { throw new Exception("One Part Model cannot render prototypes created by other models."); } Feature part = ptype.Feature("part"); Image img = new Image(); img.Source = ViewablePrototypeItem.ToBitmapSource(part.Bitmap); img.SnapsToDevicePixels = true; img.Stretch = System.Windows.Media.Stretch.Uniform; RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor); return(img); }
public void AddPtypes(string library, IEnumerable <Ptype> ptypesadded) { PrototypeItems.RaiseListChangedEvents = false; foreach (Ptype ptype in ptypesadded) { ViewablePrototypeItem prev = PrototypeItems.FirstOrDefault((i) => i.Guid.Equals(ptype.Id)); var examples = PtypeSerializationUtility.GetTrainingExamples(library, ptype.Id); if (prev == null) { PrototypeItems.Insert(0, new ViewablePrototypeItem(ptype, library, examples.Positives, examples.Negatives)); } else { int index = PrototypeItems.IndexOf(prev); PrototypeItems.Remove(prev); PrototypeItems.Insert(index, new ViewablePrototypeItem(ptype, library, examples.Positives, examples.Negatives)); } } PrototypeItems.RaiseListChangedEvents = true; PrototypeItems.ResetBindings(); }
public void SetProperties(Tree node, Tree root, Bitmap wholeScreenshot, string ptypeLib, PrefabInterpretationLogic interpLogic, Bitmap image = null, IEnumerable <string> annotationLibs = null) { Annotations.Clear(); AnnotationLibraries.Clear(); List <string> keys = new List <string>(node.GetTags().Select(kvp => kvp.Key)); foreach (string key in keys) { if (!key.Equals("ptype") && !key.Equals("invalidated")) { object attribute = node[key]; if (attribute == null) { attribute = ""; } AnnotationKeyValuePair annotation = new AnnotationKeyValuePair(key, attribute.ToString()); annotation.IsEditingChanged += new DependencyPropertyChangedEventHandler(annotation_IsEditingChanged); Annotations.Add(annotation); } } Node = node; if (node.HasTag("type")) { switch (node["type"].ToString()) { case "ptype": Ptype ptype = (Ptype)node["ptype"]; var exs = PtypeSerializationUtility.GetTrainingExamples(ptypeLib, ptype.Id); Prototype = new ViewablePrototypeItem(ptype, ptypeLib, exs.Positives, exs.Negatives, image); break; case "content": case "feature": Prototype = new ViewablePrototypeItem(null, ptypeLib, new List <ImageAnnotation>(), new List <ImageAnnotation>(), image); break; default: break; } } SetAnnotationLibraries(annotationLibs); StaticMetadata = "x=" + node.Left + ", y=" + node.Top + ", width=" + node.Width + ", height=" + node.Height; NodePath = PathDescriptor.GetPath(node, root); if (image != null) { //string bitmapid = wholeScreenshot.GetHashCode().ToString(); //var annotations = interpLogic.GetAnnotationsMatchingNode(node, root, bitmapid); //string annotationsStr = "[\n"; //foreach (string lib in annotations.Keys) //{ // foreach (IAnnotation ia in annotations[lib]) // { // annotationsStr += "{\"library\" : \"" + lib + "\"\n"; // annotationsStr += "\"id\" : \"" + ia.Id + "\"\n"; // annotationsStr += ", \"data\"" + JsonConvert.SerializeObject(ia.Data) + "\n"; // annotationsStr += "}"; // annotationsStr += ","; // } //} //annotationsStr.Remove(annotationsStr.Length - 1); //annotationsStr += "\n]"; //AnnotationValueBox.Text = annotationsStr; } }
public void SetProperties(Tree node, Tree root, Bitmap wholeScreenshot, string ptypeLib, PrefabInterpretationLogic interpLogic, Bitmap image = null, IEnumerable<string> annotationLibs = null) { Annotations.Clear(); AnnotationLibraries.Clear(); List<string> keys = new List<string>(node.GetTags().Select(kvp => kvp.Key)); foreach (string key in keys) { if (!key.Equals("ptype") && !key.Equals("invalidated")) { object attribute = node[key]; if (attribute == null) attribute = ""; AnnotationKeyValuePair annotation = new AnnotationKeyValuePair(key, attribute.ToString()); annotation.IsEditingChanged += new DependencyPropertyChangedEventHandler(annotation_IsEditingChanged); Annotations.Add(annotation); } } Node = node; if (node.HasTag("type")) { switch (node["type"].ToString()) { case "ptype": Ptype ptype = (Ptype)node["ptype"]; var exs = PtypeSerializationUtility.GetTrainingExamples(ptypeLib, ptype.Id); Prototype = new ViewablePrototypeItem(ptype, ptypeLib, exs.Positives, exs.Negatives, image); break; case "content": case "feature": Prototype = new ViewablePrototypeItem(null, ptypeLib, new List<ImageAnnotation>(), new List<ImageAnnotation>(), image); break; default: break; } } SetAnnotationLibraries(annotationLibs); StaticMetadata = "x=" + node.Left + ", y=" + node.Top + ", width=" + node.Width + ", height=" + node.Height; NodePath = PathDescriptor.GetPath(node, root); if(image != null) { //string bitmapid = wholeScreenshot.GetHashCode().ToString(); //var annotations = interpLogic.GetAnnotationsMatchingNode(node, root, bitmapid); //string annotationsStr = "[\n"; //foreach (string lib in annotations.Keys) //{ // foreach (IAnnotation ia in annotations[lib]) // { // annotationsStr += "{\"library\" : \"" + lib + "\"\n"; // annotationsStr += "\"id\" : \"" + ia.Id + "\"\n"; // annotationsStr += ", \"data\"" + JsonConvert.SerializeObject(ia.Data) + "\n"; // annotationsStr += "}"; // annotationsStr += ","; // } //} //annotationsStr.Remove(annotationsStr.Length - 1); //annotationsStr += "\n]"; //AnnotationValueBox.Text = annotationsStr; } }
private BitmapSource GetBitmapSource(int index) { return(ViewablePrototypeItem.ToBitmapSource(Bitmap.FromSystemDrawingBitmap(_frames.GetBitmap(index)))); }