コード例 #1
0
        public void storeSegments()                     //获取边(被取代)
        {
            verNum = sket.GetSketchPoints2().Length;
            adj    = new int[verNum, verNum];
            //Debug.Print("Storing segments: ");
            object[] segments = sket.GetSketchSegments();
            foreach (SketchSegment seg in segments)
            {
                bool flag = false;
                int  type = seg.GetType();
                switch (type)
                {
                case 0:
                    flag = false;
                    segs.Line  temLine = new segs.Line(seg);
                    SketchLine line    = (SketchLine)seg;
                    temLine.setPoint(addPoint(line.GetStartPoint2()), addPoint(line.GetEndPoint2()));
                    //temLine.setPoint(findPoint(line.GetStartPoint2()), findPoint(line.GetEndPoint2()));
                    for (int i = 0; i < segLin.Count; i++)
                    {
                        if (temLine.same(segLin[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segLin.Add(temLine);
                        pois[temLine.sPoint].setNext(temLine.ePoint);
                        pois[temLine.ePoint].setNext(temLine.sPoint);

                        pois[temLine.sPoint].setNextSeg(0, segLin.Count - 1);
                        pois[temLine.ePoint].setNextSeg(0, segLin.Count - 1);

                        adj[temLine.sPoint, temLine.ePoint] = 1;
                        adj[temLine.ePoint, temLine.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(line.GetStartPoint2()) + "->" + findPoint(line.GetEndPoint2()) + ")");
                    break;

                case 1:
                    segs.Arc  temArc = new segs.Arc(seg);
                    SketchArc arc    = (SketchArc)seg;
                    temArc.setPoint(addPoint(arc.GetStartPoint2()), addPoint(arc.IGetEndPoint2()));
                    //temArc.setPoint(findPoint(arc.GetStartPoint2()), findPoint(arc.IGetEndPoint2()));
                    for (int i = 0; i < segArc.Count; i++)
                    {
                        if (temArc.same(segArc[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segArc.Add(temArc);
                        pois[temArc.sPoint].setNext(temArc.ePoint);
                        pois[temArc.ePoint].setNext(temArc.sPoint);

                        pois[temArc.sPoint].setNextSeg(1, segArc.Count - 1);
                        pois[temArc.ePoint].setNextSeg(1, segArc.Count - 1);

                        adj[temArc.sPoint, temArc.ePoint] = 1;
                        adj[temArc.ePoint, temArc.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(arc.GetStartPoint2()) + "->" + findPoint(arc.GetEndPoint2()) + ")");
                    break;

                case 2:
                    flag = false;
                    segs.Ellipse  temEllipse = new segs.Ellipse(seg);
                    SketchEllipse ellipse    = (SketchEllipse)seg;
                    temEllipse.setPoint(addPoint(ellipse.GetStartPoint2()), addPoint(ellipse.GetEndPoint2()), addPoint(ellipse.GetCenterPoint2()));
                    //temEllipse.setPoint(findPoint(ellipse.GetStartPoint2()), findPoint(ellipse.GetEndPoint2()), findPoint(ellipse.GetCenterPoint2()));
                    for (int i = 0; i < segEll.Count; i++)
                    {
                        if (temEllipse.same(segEll[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segEll.Add(temEllipse);
                        pois[temEllipse.sPoint].setNext(temEllipse.ePoint);
                        pois[temEllipse.ePoint].setNext(temEllipse.sPoint);

                        pois[temEllipse.sPoint].setNextSeg(2, segEll.Count - 1);
                        pois[temEllipse.ePoint].setNextSeg(2, segEll.Count - 1);

                        adj[temEllipse.sPoint, temEllipse.ePoint] = 1;
                        adj[temEllipse.ePoint, temEllipse.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(ellipse.GetStartPoint2()) + "->" + findPoint(ellipse.GetEndPoint2()) + ")");
                    break;

                case 3:
                    flag = false;
                    segs.Spline   temSpline = new segs.Spline(seg);
                    SketchSpline  spline    = (SketchSpline)seg;
                    SketchPoint[] tempoints = spline.GetPoints2();
                    for (int i = 0; i < tempoints.Length; i++)
                    {
                        int index = addPoint(tempoints[i]);
                        temSpline.setPoint(index);
                    }

                    /*
                     * for(int i = 0; i < tempoints.Length; i++)
                     * {
                     *  int index = findPoint(tempoints[i]);
                     *  temSpline.setPoint(index);
                     * }
                     */
                    for (int i = 0; i < segSpl.Count; i++)
                    {
                        if (temSpline.same(segSpl[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segSpl.Add(temSpline);
                        pois[temSpline.sPoint].setNext(temSpline.ePoint);
                        pois[temSpline.ePoint].setNext(temSpline.sPoint);

                        pois[temSpline.sPoint].setNextSeg(3, segSpl.Count - 1);
                        pois[temSpline.ePoint].setNextSeg(3, segSpl.Count - 1);

                        adj[temSpline.sPoint, temSpline.ePoint] = 1;
                        adj[temSpline.ePoint, temSpline.sPoint] = 1;
                    }
                    //Debug.Print("Spline");
                    break;

                case 5:
                    segs.Parabola  temParabola = new segs.Parabola(seg);
                    SketchParabola parabola    = (SketchParabola)seg;
                    temParabola.setPoint(addPoint(parabola.GetStartPoint2()), addPoint(parabola.IGetEndPoint2()));
                    //temParabola.setPoint(findPoint(parabola.GetStartPoint2()), findPoint(parabola.IGetEndPoint2()));
                    for (int i = 0; i < segPar.Count; i++)
                    {
                        if (temParabola.same(segPar[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segPar.Add(temParabola);
                        pois[temParabola.sPoint].setNext(temParabola.ePoint);
                        pois[temParabola.ePoint].setNext(temParabola.sPoint);

                        pois[temParabola.sPoint].setNextSeg(5, segPar.Count - 1);
                        pois[temParabola.ePoint].setNextSeg(5, segPar.Count - 1);

                        adj[temParabola.sPoint, temParabola.ePoint] = 1;
                        adj[temParabola.ePoint, temParabola.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(parabola.GetStartPoint2()) + "->" + findPoint(parabola.GetEndPoint2()) + ")");
                    break;

                case 4:
                    break;
                }
            }
        }
コード例 #2
0
        public void storeSegments2()                    //获取边与点,取代上面三个函数,目前使用中
        {
            if (sket.GetSketchPoints2() == null)
            {
                Debug.Print("No points!");
                return;
            }
            verNum = sket.GetSketchPoints2().Length;            //以下为保存边、边的邻接点;点、点的邻接边的操作
            adj    = new int[verNum, verNum];
            for (int i = 0; i < verNum; i++)                    //初始化邻接点数组,为之后的最小环提取做准备,在存储点与边的同时需要存储邻接关系
            {
                for (int j = 0; j < verNum; j++)
                {
                    adj[i, j] = INF;
                }
            }
            object[] segments = sket.GetSketchSegments();
            foreach (SketchSegment seg in segments)             //此时遍历所有边,判断边的类型,而后分类存储
            {
                bool flag = false;
                int  type = seg.GetType();
                switch (type)
                {
                case 0:
                    flag = false;
                    loopSeg    temLine = new loopSeg(seg);
                    SketchLine line    = (SketchLine)seg;
                    temLine.setPoint(addPoint(line.GetStartPoint2()), addPoint(line.GetEndPoint2()));
                    temLine.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temLine.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temLine);

                        pois[temLine.start].setNext(temLine.end);
                        pois[temLine.end].setNext(temLine.start);

                        pois[temLine.start].setNextSeg2(temLine.index);
                        pois[temLine.end].setNextSeg2(temLine.index);

                        adj[temLine.start, temLine.end] = 1;
                        adj[temLine.end, temLine.start] = 1;
                    }
                    break;

                case 1:
                    flag = false;
                    loopSeg   temArc = new loopSeg(seg);
                    SketchArc arc    = (SketchArc)seg;
                    temArc.setPoint(addPoint(arc.GetStartPoint2()), addPoint(arc.GetEndPoint2()));
                    temArc.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temArc.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temArc);

                        pois[temArc.start].setNext(temArc.end);
                        pois[temArc.end].setNext(temArc.start);

                        pois[temArc.start].setNextSeg2(temArc.index);
                        pois[temArc.end].setNextSeg2(temArc.index);

                        adj[temArc.start, temArc.end] = 1;
                        adj[temArc.end, temArc.start] = 1;
                    }
                    break;

                case 2:
                    flag = false;
                    loopSeg       temEll = new loopSeg(seg);
                    SketchEllipse ell    = (SketchEllipse)seg;
                    temEll.setPoint(addPoint(ell.GetStartPoint2()), addPoint(ell.GetEndPoint2()));
                    temEll.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temEll.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temEll);

                        pois[temEll.start].setNext(temEll.end);
                        pois[temEll.end].setNext(temEll.start);

                        pois[temEll.start].setNextSeg2(temEll.index);
                        pois[temEll.end].setNextSeg2(temEll.index);

                        adj[temEll.start, temEll.end] = 1;
                        adj[temEll.end, temEll.start] = 1;
                    }
                    break;

                case 3:
                    flag = false;
                    loopSeg      temSpl = new loopSeg(seg);
                    SketchSpline spl    = (SketchSpline)seg;
                    object[]     tem    = spl.GetPoints2();
                    temSpl.setPoint(addPoint((SketchPoint)tem[0]), addPoint((SketchPoint)tem[tem.Length - 1]));
                    temSpl.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temSpl.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temSpl);

                        pois[temSpl.start].setNext(temSpl.end);
                        pois[temSpl.end].setNext(temSpl.start);

                        pois[temSpl.start].setNextSeg2(temSpl.index);
                        pois[temSpl.end].setNextSeg2(temSpl.index);

                        adj[temSpl.start, temSpl.end] = 1;
                        adj[temSpl.end, temSpl.start] = 1;
                    }
                    break;

                case 5:
                    flag = false;
                    loopSeg        temPar = new loopSeg(seg);
                    SketchParabola par    = (SketchParabola)seg;
                    temPar.setPoint(addPoint(par.GetStartPoint2()), addPoint(par.GetEndPoint2()));
                    temPar.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temPar.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temPar);

                        pois[temPar.start].setNext(temPar.end);
                        pois[temPar.end].setNext(temPar.start);

                        pois[temPar.start].setNextSeg2(temPar.index);
                        pois[temPar.end].setNextSeg2(temPar.index);

                        adj[temPar.start, temPar.end] = 1;
                        adj[temPar.end, temPar.start] = 1;
                    }
                    break;

                case 4:
                    break;
                }
            }
        }