public void Interpret(InterpretArgs args) { Bitmap pixels = (Bitmap)args.Tree["capturedpixels"]; if (featureTree != null) { List <Tree> found = new List <Tree>(); if (args.Tree.HasTag("invalidated")) { IBoundingBox invalidated = args.Tree["invalidated"] as IBoundingBox; if (invalidated != null && !BoundingBox.Equals(invalidated, args.Tree) && args.Tree.HasTag("previous") && args.Tree["previous"] != null) { featureTree.MatchInvalidatedRegion(pixels, found, _prevFeatures, invalidated); } else { featureTree.MultiThreadedMatch(pixels, found); } } else { featureTree.MultiThreadedMatch(pixels, found); } foreach (Tree f in found) { args.SetAncestor(f, args.Tree); } } }
static void LoadGeneratedGCodeFile(string sPath) { // read gcode file GenericGCodeParser parser = new GenericGCodeParser(); GCodeFile gcode; using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { using (TextReader reader = new StreamReader(fs)) { gcode = parser.Parse(reader); } } // write back out gcode we loaded //StandardGCodeWriter writer = new StandardGCodeWriter(); //using ( StreamWriter w = new StreamWriter("../../../sample_output/writeback.gcode") ) { // writer.WriteFile(gcode, w); //} GCodeToToolpaths converter = new GCodeToToolpaths(); MakerbotInterpreter interpreter = new MakerbotInterpreter(); interpreter.AddListener(converter); InterpretArgs interpArgs = new InterpretArgs(); interpreter.Interpret(gcode, interpArgs); View.SetPaths(converter.PathSet); if (LastSettings != null) { View.PathDiameterMM = (float)LastSettings.Machine.NozzleDiamMM; } }
private void InterpretHelper(InterpretArgs args, Tree node) { string path = PathDescriptor.GetPath(node, args.Tree); JObject data = (JObject)_runtimeIntent.GetData(path); if (data != null) { foreach (var key in data.Properties()) { bool parsedbool = false; if (bool.TryParse(data[key.Name].Value <string>(), out parsedbool)) { args.Tag(node, key.Name, parsedbool); } else { args.Tag(node, key.Name, data[key.Name].Value <string>()); } } } foreach (Tree child in node.GetChildren()) { InterpretHelper(args, child); } }
public void Interpret(InterpretArgs args) { List <Tree> features = FeatureDetectionLayer.GetFeaturesFromTree(args.Tree); foreach (Tree feature in features) { args.Remove(feature); } }
private void InterpretHelper(InterpretArgs args, Tree currNode) { if (currNode.Height > 3 && currNode["type"] != null && currNode["type"].Equals("content")) { args.Tag(currNode, "is_text", true); } foreach (Tree child in currNode.GetChildren()) { InterpretHelper(args, child); } }
public void Interpret(InterpretArgs args) { try { PythonInterpretArgs pargs = new PythonInterpretArgs(args); if (_interpretFunc != null) { _scope.Engine.Operations.Invoke(_interpretFunc, pargs); } } catch (Exception e) { throw PythonScriptHost.Instance.GetFormattedException(e, Name); } }
public static int Main(string[] args) { FeatureDetectionLayer layer = new FeatureDetectionLayer(); layer.Init(null); Bitmap bmp = Bitmap.FromFile("../prefab/AdobePreferences.png"); Dictionary <string, object> tags = new Dictionary <string, object>(); Tree tree = Tree.FromPixels(bmp, tags); InterpretArgs iargs = new InterpretArgs(tree, new Tree.BatchTransform(tree), null); layer.Interpret(iargs); return(0); }
public static void SetAncestorsByContainment(List <Tree> nodes, InterpretArgs args) { nodes.Sort(CompareByAreaAndFeaturesFirst); for (int i = 0; i < nodes.Count - 1; i++) { Tree curr = nodes[i]; for (int j = i + 1; j < nodes.Count; j++) { Tree next = nodes[j]; if (BoundingBox.IsInsideInclusive(curr, next)) { args.SetAncestor(curr, next); } } } }
public void Interpret(InterpretArgs args) { ptypes = (List <Ptype>)shared[Features.FeatureDetectionLayer.SHARED_PTYPES_KEY]; found.Clear(); //Finding prototype occurrences Bitmap pixels = (Bitmap)args.Tree["capturedpixels"]; IEnumerable <Tree> features = args.Tree.GetChildren(); foreach (Ptype p in ptypes) { p.Model.Finder.FindOccurrences(p, pixels, features, found); } //Creating the spatial hierarchy Tree.AddNodesToCollection(args.Tree, found); SetAncestorsByContainment(found, args); }
public void InterpretHelper(InterpretArgs args, Tree currNode) { IEnumerable <Tree> textChildren = currNode.GetChildren().Where(c => c.ContainsTag("is_text") && (bool)c["is_text"]); List <Tree> readingOrder = SortNodesInReadingOrder(textChildren); for (int i = 0; i < readingOrder.Count - 1; i++) { Tree curr = readingOrder[i]; Tree next = readingOrder[i + 1]; args.Tag(curr, "group_next", GroupNext(curr, next)); } //recurse foreach (Tree child in currNode.GetChildren()) { InterpretHelper(args, child); } }
private void InterpretHelper(InterpretArgs args, Tree node) { if (node.ContainsTag("type") && node["type"].Equals("ptype")) { args.Tag(node, "is_target", "true"); } else if (node.ContainsTag("type") && !node["type"].Equals("ptype")) { foreach (Tree child in node.GetChildren()) { if (child.ContainsTag("type") && !child["type"].Equals("feature") && child.GetChildren().Count() == 0) { args.Tag(child, "is_target", "true"); } } } foreach (Tree child in node.GetChildren()) { InterpretHelper(args, child); } }
static void LoadGCodeFile(string sPath) { GenericGCodeParser parser = new GenericGCodeParser(); GCodeFile gcode; using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { using (TextReader reader = new StreamReader(fs)) { gcode = parser.Parse(reader); } } GCodeToToolpaths converter = new GCodeToToolpaths(); MakerbotInterpreter interpreter = new MakerbotInterpreter(); interpreter.AddListener(converter); InterpretArgs interpArgs = new InterpretArgs(); interpreter.Interpret(gcode, interpArgs); ToolpathSet Paths = converter.PathSet; View.SetPaths(Paths); }
/// <summary> /// Finds the unpredictable content using the backround regions of elements. /// </summary> /// <param name="node"></param> /// <param name="image"></param> /// <param name="background"></param> /// <param name="isForeground"></param> private static List <Tree> FindAndAddContent(InterpretArgs args, Tree node, Bitmap image, Bitmap isForeground) { Ptype ptype = (Ptype)node["ptype"]; List <Tree> allFound = new List <Tree>(); if (ptype != null) { ptype.Model.Finder.SetForeground(node, image, isForeground); } //recurse. if no siblings are overlapping (the majority case) then we can run each child in parallel. // if (!anyOverlapping(node.children())){ // List<Future<ICollection<Tree>>> asyncResults = new List<Future<ICollection<Tree>>>(); // for(final Tree child : node.children()){ // Callable<ICollection<Tree>> callable = new Callable<ICollection<Tree>>(){ // public ICollection<Tree> call(){ // return findAndAddContent(args, ptype, child, image, isForeground); // } // }; // Future<ICollection<Tree>> results = Utils.service.submit(callable); // asyncResults.add(results); // } // // for(Future<ICollection<Tree>> res : asyncResults){ // // try { // allFound.addAll(res.get()); // } catch (InterruptedException e) { // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. // } catch (ExecutionException e) { // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. // } // } // } // else //we can't run children in parallel if any nodes overlap. // //nodes only overlap when there's a false positive. so we might be able // //to trigger something here and automatically correct that. // { foreach (Tree child in node.GetChildren()) { FindAndAddContent(args, child, image, isForeground); } if (ptype != null) { ptype.Model.Finder.FindContent(node, image, isForeground, allFound); foreach (Tree found in allFound) { args.SetAncestor(found, node); } allFound.AddRange(node.GetChildren()); PrototypeDetectionLayer.SetAncestorsByContainment(allFound, args); } // } return(allFound); }
public void Interpret(InterpretArgs args) { Bitmap bitmap = (Bitmap)args.Tree["capturedpixels"]; FindAndAddContent(args, args.Tree, bitmap, foreground); }
public void Interpret(InterpretArgs args) { InterpretHelper(args, args.Tree); }
public void Compute() { RequestCancel = false; printer = new SingleMaterialFFFPrintGenerator(Meshes, SliceSet, PrintSettings); if (PrintSettings.EnableSupportReleaseOpt) { printer.LayerPostProcessor = new SupportConnectionPostProcessor() { ZOffsetMM = PrintSettings.SupportReleaseGap }; } // if we aren't interpreting GCode, we want generator to return its path set printer.AccumulatePathSet = (InterpretGCodePaths == false); // set clip region Box2d clip_box = new Box2d(Vector2d.Zero, new Vector2d(CC.Settings.BedSizeXMM / 2, CC.Settings.BedSizeYMM / 2)); printer.PathClipRegions = new List <GeneralPolygon2d>() { new GeneralPolygon2d(new Polygon2d(clip_box.ComputeVertices())) }; printer.ErrorF = (msg, trace) => { if (RequestCancel == false) { DebugUtil.Log(2, "Slicer Error! msg: {0} stack {1}", msg, trace); } }; DebugUtil.Log(2, "Generating gcode..."); try { if (printer.Generate() == false) { throw new Exception("generate failed"); // this will be caught below } gcode = printer.Result; //DebugUtil.Log(2, "Interpreting gcode..."); if (InterpretGCodePaths) { GCodeToToolpaths converter = new GCodeToToolpaths(); MakerbotInterpreter interpreter = new MakerbotInterpreter(); interpreter.AddListener(converter); InterpretArgs interpArgs = new InterpretArgs(); interpreter.Interpret(gcode, interpArgs); paths = converter.PathSet; } else { paths = printer.AccumulatedPaths; } //DebugUtil.Log(2, "Detecting layers..."); layerInfo = new LayersDetector(paths); Success = true; } catch (Exception e) { DebugUtil.Log("ToolpathGenerator.Compute: exception: " + e.Message); Success = false; } Finished = true; }
public PythonInterpretArgs(InterpretArgs interpretArgs) { tree = interpretArgs.Tree; runtime_storage = new PythonRuntimeStorageWrapper(interpretArgs.RuntimeStorage); args = interpretArgs; }
private void InterpretHelper(InterpretArgs args, Tree currNode) { var children = currNode.GetChildren().Where(n => n["is_text"] != null && (bool)n["is_text"]); var sorted = GroupNextLayer.SortNodesInReadingOrder(children); bool createNew = true; List <Tree> togroup = new List <Tree>(); for (int i = 1; i < sorted.Count; i++) { Tree currChild = sorted[i]; Tree prevChild = sorted[i - 1]; if (prevChild["group_next"] != null && (bool)prevChild["group_next"]) { if (createNew) { createNew = false; togroup.Add(prevChild); } togroup.Add(currChild); } else { if (togroup.Count > 0) { IBoundingBox bounding = BoundingBox.Union(togroup); var tags = new Dictionary <string, object>(); tags["type"] = "grouped_text"; tags["is_text"] = true; Tree grouped = Tree.FromBoundingBox(bounding, tags); foreach (Tree t in togroup) { args.SetAncestor(t, grouped); } args.SetAncestor(grouped, currNode); togroup.Clear(); } createNew = true; } } if (togroup.Count > 0) { IBoundingBox bounding = BoundingBox.Union(togroup); var tags = new Dictionary <string, object>(); tags["type"] = "grouped_text"; tags["is_text"] = true; Tree grouped = Tree.FromBoundingBox(bounding, tags); foreach (Tree t in togroup) { args.SetAncestor(t, grouped); } args.SetAncestor(grouped, currNode); togroup.Clear(); } foreach (Tree child in currNode.GetChildren()) { InterpretHelper(args, child); } }