Ejemplo n.º 1
0
        public void sketchReGroupping()
        {
            SKContextDGNode head        = sketch.sketchContextDG.firstNode;
            SKContextDGNode nextNode    = new SKContextDGNode();
            SKContextDGNode curNode     = new SKContextDGNode();
            Sketch          currentpage = sketch.currentpage.Value.content; //当前页

            /*
             * 1.	从SKContextDG中取出输入时间戳最早的节点nodeCur,标记为Head;
             * 2.	从nodeCur出发,找到其tPointer指针所指向的下一个节点nodeNext;
             * 3.	如果当前nodeNext不为空(TT),执行步骤3.1
             */
            curNode = head;


            for (nextNode = curNode.tPointer; ; nextNode = nextNode.tPointer)
            {
                if (nextNode != null) //TT
                {
                    /*
                     * 3.1	对于当前的nodeNext,判断其sPointer指针是否为空;
                     * 3.2	如果sPointer非空(ST),判断sPointer所指节点nodePre是否与nodeCur属于同一个group。
                     *      如果是,则nodeCur和nodeNext之间是强关联类型(TT&ST),nodeNext与nodeCur属于同一个group,
                     *      将nodeNext设为nodeCur,重复步骤2;
                     *      如果nodePre与nodeCur不属于同一个group,则将nodeNext与nodePre归为同一个group,
                     *      将当前nodeCur标记为Tail,从SKContextDG中寻找输入时间戳大于nodeNext的下一个节点记为nodeNext;
                     * 3.3	如果sPointer为空(SF),则nodeCur与nodeNext之间是弱关联II类型(TT&SF),
                     *      视nodeNext为新group的头节点,将其标记为Head,同时,将nodeCur标记为Tail;
                     */
                    int tmp = nextNode.sPointer.Count;
                    if (nextNode.sPointer.Count > 0)
                    {
                        //如果nextnode和curnode空间邻近,则它们属于同一group
                        bool isContain = nextNode.sPointer.Contains(curNode);
                        if (isContain)                          // curNode 和 nextNode是强关联(TT && ST)
                        {
                            nextNode.groupID = curNode.groupID; //属于同一group
                            curNode          = nextNode;
                        }
                        else
                        {
                            //nodeCur与nodeNext之间是弱关联II类型(TT&SF)
                            //检测nextnode和历史node的关系,判断它应该归属于哪一个group
                            //先处理简单情况,nextNode只和属于同一个group的历史节点有空间邻近的关系
                            foreach (SKContextDGNode snode in nextNode.sPointer)
                            {
                                nextNode.groupID = snode.groupID;
                            }
                            curNode = nextNode;
                        }
                    }
                    else//spointer = null 没有与之空间邻近的节点,独立成为一个group
                    {
                        //nodeNext为新group的头节点,将其标记为Head
                        sketch.sketchContextDG.DGHeadList.Add(nextNode);
                        curNode = nextNode;
                    }
                }
                else //TF
                {
                    /*
                     * 4. 如果当前nodeNext为空(TF),从SKContextDG中寻找输入时间戳大于nodeCur节点的最早输入节点,
                     *    令其为nodeNext,
                     *    4.1 如果nodeNext非空,判断其sPointer指针是否为空;
                     *    4.2 如果sPointer非空(ST),判断sPointer所指节点nodePre是否与nodeCur属于同一个group,
                     *        如果是,则nodeCur和nodeNext之间是弱关联I类型(TF&ST),nodeNext与nodeCur属于同一个group,
                     *        将nodeNext设为nodeCur,重复步骤2;
                     *    4.3 如果sPointer为空(SF),则nodeCur与nodeNext之间无关联,视nodeNext为新group的头节点,将其标记为Head,同时,将nodeCur标记为Tail
                     */
                    //先找到nextNdoe节点
                    foreach (SKContextDGNode nd in sketch.sketchContextDG.DGHeadList)
                    {
                        if (nd.timeStamp > curNode.timeStamp)//HeadList都是按序进入的,故只需找到第一个比curNode时间戳大的节点即可
                        {
                            nextNode = nd;
                        }

                        if (nextNode != null)
                        {
                            break;
                        }
                    }
                    if (nextNode == null)
                    {
                        break;
                    }

                    if (nextNode.sPointer != null)
                    {
                        bool isContain = nextNode.sPointer.Contains(curNode);
                        if (isContain)
                        {
                            nextNode.groupID = curNode.groupID;
                            curNode          = nextNode;
                        }
                        else
                        {
                            foreach (SKContextDGNode snode in nextNode.sPointer)
                            {
                                nextNode.groupID = snode.groupID;
                            }
                            curNode = nextNode;
                        }
                    }
                    else
                    {
                        //spointer = null 没有与之空间邻近的节点,独立成为一个group
                        //nodeNext为新group的头节点,将其标记为Head
                        sketch.sketchContextDG.DGHeadList.Add(nextNode);
                        curNode = nextNode;
                    }
                }
            }

            //更新semantic group
            int nGroupCount = -1;

            foreach (SKContextDGNode nd in sketch.sketchContextDG.DGNodeList)
            {
                if (nd.groupID > nGroupCount)
                {
                    nGroupCount = nd.groupID;
                }
            }

            sketch.semanticGroupList.Clear();

            for (int i = 1; i <= nGroupCount; i++)
            {
                SemanticGroup semanticSg = new SemanticGroup();
                sketch.semanticGroupList.Add(semanticSg);
                semanticSg.semanticGroupID = i;
            }

            foreach (SKContextDGNode nn in sketch.sketchContextDG.DGNodeList)
            {
                foreach (SemanticGroup smsg in sketch.semanticGroupList)
                {
                    if ((nn.groupID == smsg.semanticGroupID) && (!smsg.groupList.Contains(nn.strokeGroup)))
                    {
                        smsg.groupList.Add(nn.strokeGroup);
                        smsg.setBoundingBox();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //YHY-090421
        public void bottomUpRecognize(SemanticGroup smsg)
        {
            //bool flagContain = false;

            //get geo compositon of all templates
            GetGeoInfoOfTemplateNodeList();

            foreach (StrokeGroup sg in smsg.groupList)
            {
                Graphic geoType = sg.GRAPH;
                switch (geoType)
                {
                case Graphic.Line:
                    smsg.nCountLine++;
                    break;

                case Graphic.Circle:
                    smsg.nCountCircle++;
                    break;

                case Graphic.Curve:
                    smsg.nCountCurve++;
                    break;

                default:
                    break;
                }
            }

            List <GeoInfoOfTemplateNode> copyOfgeoOfTemplateNodeList = new List <GeoInfoOfTemplateNode>();

            foreach (GeoInfoOfTemplateNode DomNode in geoOfTemplateNodeList)
            {
                GeoInfoOfTemplateNode copyofDomainNode = new GeoInfoOfTemplateNode();
                copyofDomainNode.nCountCircle = DomNode.nCountCircle;
                copyofDomainNode.nCountLine   = DomNode.nCountLine;
                copyofDomainNode.nCountCurve  = DomNode.nCountCurve;
                copyofDomainNode.templateName = DomNode.templateName;
                foreach (string sss in DomNode.geoComposition)
                {
                    copyofDomainNode.geoComposition.Add(sss);
                }
                copyOfgeoOfTemplateNodeList.Add(copyofDomainNode);
            }

            geoOfTemplateNodeList.Clear();

            foreach (GeoInfoOfTemplateNode domainNode in copyOfgeoOfTemplateNodeList)
            {
                if (domainNode.nCountLine == smsg.nCountLine && domainNode.nCountCircle == smsg.nCountCircle)
                {
                    geoOfTemplateNodeList.Add(domainNode);
                }
            }

            /*
             * foreach (StrokeGroup sg in smsg.groupList)
             * {
             *  Graphic geoType = sg.GRAPH;
             *  switch (geoType)
             *  {
             *      case Graphic.Line:
             *          flagContain = false;
             *
             *          foreach (GeoInfoOfTemplateNode domainNode in geoOfTemplateNodeList)
             *          {
             *              GeoInfoOfTemplateNode domainNode1 = new GeoInfoOfTemplateNode();
             *              domainNode1.templateName = domainNode.templateName;
             *              foreach (string ss in domainNode.geoComposition)
             *              {
             *                  domainNode1.geoComposition.Add(ss);
             *              }
             *
             *              foreach (string s in domainNode.geoComposition)
             *              {
             *                  if (s == "line")
             *                  {
             *                      flagContain = true;
             *                      domainNode.geoComposition.Remove(s);
             *                  }
             *              }
             *              if (flagContain == false)
             *                  geoOfTemplateNodeList.Remove(domainNode);
             *          }
             *
             *          break;
             *      case Graphic.Circle:
             *          flagContain = false;
             *
             *          foreach (GeoInfoOfTemplateNode domainNode in geoOfTemplateNodeList)
             *          {
             *              GeoInfoOfTemplateNode domainNode1 = new GeoInfoOfTemplateNode();
             *              domainNode1.templateName = domainNode.templateName;
             *              foreach (string ss in domainNode.geoComposition)
             *              {
             *                  domainNode1.geoComposition.Add(ss);
             *              }
             *
             *              foreach (string s in domainNode1.geoComposition)
             *              {
             *                  if (s == "circle")
             *                  {
             *                      flagContain = true;
             *                      domainNode.geoComposition.Remove(s);
             *                  }
             *              }
             *              if (flagContain == false)
             *                  geoOfTemplateNodeList.Remove(domainNode);
             *          }
             *          break;
             *      case Graphic.Curve:
             *          flagContain = false;
             *
             *          foreach (GeoInfoOfTemplateNode domainNode in geoOfTemplateNodeList)
             *          {
             *              GeoInfoOfTemplateNode domainNode1 = new GeoInfoOfTemplateNode();
             *              domainNode1.templateName = domainNode.templateName;
             *              foreach (string ss in domainNode.geoComposition)
             *              {
             *                  domainNode1.geoComposition.Add(ss);
             *              }
             *
             *              foreach (string s in domainNode.geoComposition)
             *              {
             *                  if (s == "curve")
             *                  {
             *                      flagContain = true;
             *                      domainNode.geoComposition.Remove(s);
             *                  }
             *              }
             *              if (flagContain == false)
             *                  geoOfTemplateNodeList.Remove(domainNode);
             *          }
             *          break;
             *      default:
             *          break;
             *  }
             * }*/
        }