コード例 #1
0
        public static int CompareByAreaAndFeaturesFirst(Tree a, Tree b)
        {
            int val =  CompareByArea(a, b);
            if (val == 0)
            {
                if (a.HasTag("type") && a["type"].Equals("feature") && 
                    (!b.HasTag("type") || !b["type"].Equals("feature")))
                    return -1;
                else if (b.HasTag("type") && b["type"].Equals("feature"))
                    return 1;
            }

            return val;
        }
コード例 #2
0
ファイル: ViewableTreeNode.cs プロジェクト: nunb/authoring
        public ViewableTreeNode(Tree node)
        {
            Node = node;
            Children = new BindingList<ViewableTreeNode>();
            foreach (Tree child in node.GetChildren())
            {
                Children.Add(new ViewableTreeNode(child));
            }

            if (node.HasTag("type")){

                Id = "{x=" + node.Left + ", y=" + node.Top + ", width=" + node.Width + ", height=" + node.Height + "}";

                //switch(node["type"].ToString()){

                //    case "ptype":
                //        Id = ((string)node["ptype_id"]);
                //        break;

                //    default:
                //        Id = node["type"].ToString();
                //        break;
                //}
                

            }

            else
                Id = "node";
        }
コード例 #3
0
        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;
            }
           
        }
コード例 #4
0
ファイル: Selector.cs プロジェクト: nunb/authoring
        private static bool AttributeEquals(Tree node, string attr, string value)
        {
            return node.HasTag(attr) && node[attr].ToString().ToLower().Equals(value);

        }
コード例 #5
0
ファイル: Selector.cs プロジェクト: nunb/authoring
        private static bool TestLeaf(Tree node, string value)
        {
            bool boolValue = false;
            bool couldParse = bool.TryParse(value, out boolValue);

            if (!couldParse)
                return false;

            bool isLeaf = ( !(node.HasTag("type") && node["type"].Equals("frame")) && node.GetChildren().Count() == 0 );

            return boolValue == isLeaf;
        }
コード例 #6
0
        private static Tree GetClosestHelper(int left, int top, Tree node, out double closestDistance)
        {
            double currBestDist = double.MaxValue;
            Tree closestTarget = null;
            if(node.HasTag("is_target") && node["is_target"].ToString().ToLower().Equals("true") 
                && (!node.HasTag("is_minor") || node["is_minor"].ToString().ToLower().Equals("false") || Keyboard.IsKeyDown(Key.LeftCtrl) ) )
            {
                currBestDist = DistanceBetweenPointAndRectangle(left, top, node);
                closestTarget = node;
            }

            

            double bestChildDist = double.MaxValue;
            Tree closestChild = null;

            foreach (Tree child in node.GetChildren())
            {
                double childDist = double.MaxValue;
                Tree childCandidate = GetClosestHelper(left, top, child, out childDist);
                if (childCandidate != null && childDist < bestChildDist)
                {
                    bestChildDist = childDist;
                    closestChild = childCandidate;
                }
            }

            if (bestChildDist < currBestDist)
            {
                closestTarget = closestChild;
                currBestDist = bestChildDist;
            }

            closestDistance = currBestDist;

            return closestTarget;
        }
コード例 #7
0
        private static void GetFeaturesFromTree(Tree tree, List<Tree> features)
        {
            if (tree.HasTag("type") && tree["type"].Equals("feature"))
                features.Add(tree);

            foreach (Tree child in tree.GetChildren())
                GetFeaturesFromTree(child, features);
        }
コード例 #8
0
ファイル: PathDescriptor.cs プロジェクト: prefab/code
        private static int GetNodeIndex(Tree node, Tree parent)
        {
            int index = 0;

            string pixelhash = null;
            string type = "none";
            if(node.HasTag("type"))
                type = node["type"].ToString();

            if(node.HasTag("type") && node["type"].Equals("content"))
                pixelhash = node["pixel_hash"].ToString();

            if(parent != null){
                var children = parent.GetChildren();
                List<Tree> sorted = new List<Tree>(children);
                sorted.Sort(BoundingBox.CompareByTopThenLeft);
                foreach(Tree sibling in sorted){
                    if(sibling == node)
                        return index;
                    else{
                        string sibtype = "none";
                        if(sibling.HasTag("type"))
                            sibtype = sibling["type"].ToString();

                        if(sibtype.Equals("ptype") && type.Equals("ptype")){
                            if(sibling["ptype_id"].Equals(node["ptype_id"]))
                                index++;
                        }else if(sibtype.Equals(type)){
                            index++;
                        }
                    }
                }
            }

            return index;
        }
コード例 #9
0
ファイル: PathDescriptor.cs プロジェクト: prefab/code
        private static void GetLocalPath(Tree node, Tree parent, StringBuilder sb)
        {
            if (node.HasTag("type"))
            {
                switch (node["type"].ToString())
                {
                    case "ptype":
                        sb.Append(node["ptype_id"].ToString());
                        break;

                    case "frame":
                        sb.Append("frame");
                        break;

                    case "content":
                        sb.Append("content[@pixel_hash=" + node["pixel_hash"] + "]");

                        break;

                    default:
                        sb.Append(node["type"]);
                        break;

                }
            }

            int index = GetNodeIndex(node, parent);
            sb.Append("[" + index + "]");
        }