Beispiel #1
0
        /// <summary>
        ///  Choose two points of triangle and add
        ///  dir: a forbidden one (0 stands for "both allowed")
        /// </summary>
        public void triangulate(Queue <int> qeVertexes1, Queue <int> qeVertexes2, Queue <int> qeDirection, List <HashSet <int> > matrix)
        {
            int    f      = qeVertexes1.Dequeue();
            int    s      = qeVertexes2.Dequeue();
            vertex first  = vertexes[f];
            vertex second = vertexes[s];
            int    dir    = qeDirection.Dequeue();

            drawSide(first, second);
            //matrix[f].Add(s);
            //matrix[s].Add(f);
            bool   checkVert = false;
            double min       = 2;
            int    n         = 0;

            for (int m = 0; m < vertexes.Count; m++)
            {
                if ((dir != 0 && getVertexDir(first, second, vertexes[m]) == dir))
                {
                    continue;
                }

                if (matrix[f].Contains(m) && matrix[s].Contains(m))
                {
                    //triangles.Add(new Triangle(first, second, vertexes[m]));
                    return;
                }

                double fs   = Math.Pow(first.x - second.x, 2) + Math.Pow(first.y - second.y, 2);
                double fm   = Math.Pow(first.x - vertexes[m].x, 2) + Math.Pow(first.y - vertexes[m].y, 2);
                double ms   = Math.Pow(vertexes[m].x - second.x, 2) + Math.Pow(vertexes[m].y - second.y, 2);
                double curr = (-fs + fm + ms) / (2 * Math.Sqrt(fm * ms));
                if (curr < min)
                {
                    min       = curr;
                    checkVert = true;
                    n         = m;
                }
            }

            if (checkVert)
            {
                //triangles.Add(new Triangle(first, second, vertexes[n]));
                matrix[f].Add(n);
                matrix[s].Add(n);
                matrix[n].Add(f);
                matrix[n].Add(s);
                drawSide(first, vertexes[n]);
                drawSide(second, vertexes[n]);
                qeVertexes1.Enqueue(f);
                qeVertexes2.Enqueue(n);
                qeVertexes1.Enqueue(n);
                qeVertexes2.Enqueue(s);
                qeDirection.Enqueue(-getVertexDir(first, second, vertexes[n]));
                qeDirection.Enqueue(-getVertexDir(first, second, vertexes[n]));
            }
        }
Beispiel #2
0
        abstract public void divideImage(int bright, Rectangle _parent);                /// Divide figure to smaller figures.

        public void drawLine(int _x, int _y, int _currWidth, int _currHight, bool vert) ///
        {
            bmp = (Bitmap)Form1.Mem;
            if (vert)
            {
                for (int i = _y; i < _currHight + y; i++)
                {
                    Form1.bmpLines.SetPixel((_currWidth + x), i, Color.Black);
                    if ((_currHight == 1 || _currHight == 2) && (_currWidth == 1 || _currWidth == 2))
                    {
                        Color  curr = bmp.GetPixel((_currWidth + x), i);
                        vertex M1   = new vertex((_currWidth + x), i, curr);
                        Form1.vertexes.Add(M1);
                        //if (_currWidth + x != 256 && _currWidth + x + 1 != 256 && (i + 1) != 256 && (i - 1) >= 0 && (_currWidth + x - 1) >= 0)
                        //{
                        //    curr = bmp.GetPixel((_currWidth + x), i + 1);
                        //    Form1.vertexes.Add(new vertex((_currWidth + x), i + 1, curr));
                        //    curr = bmp.GetPixel((_currWidth + x + 1), i + 1);
                        //    Form1.vertexes.Add(new vertex((_currWidth + x + 1), i + 1, curr));
                        //    curr = bmp.GetPixel((_currWidth + x), i - 1);
                        //    Form1.vertexes.Add(new vertex((_currWidth + x), i - 1, curr));
                        //    curr = bmp.GetPixel((_currWidth + x - 1), i - 1);
                        //    Form1.vertexes.Add(new vertex((_currWidth + x - 1), i - 1, curr));
                        //    Form1.bmpLines.SetPixel((_currWidth + x), i, Color.Red);
                        //}
                    }
                }
            }
            else
            {
                for (int i = _x; i < _currWidth + x; i++)
                {
                    Form1.bmpLines.SetPixel(i, _currHight + y, Color.Black);
                    if ((_currHight == 1 || _currHight == 2) && (_currWidth == 1 || _currWidth == 2))
                    {
                        Color  curr = bmp.GetPixel(i, _currHight + y);
                        vertex M1   = new vertex(i, _currHight + y, curr);
                        Form1.vertexes.Add(M1);
                        //Form1.bmpLines.SetPixel(i, _currHight + y, Color.Red);
                        //if (_currHight + y != 256 && _currHight + y + 1 != 256 && (i + 1) != 256 && (i - 1) >= 0 && (_currHight + y - 1) >= 0)
                        //{
                        //    curr = bmp.GetPixel(i + 1, _currHight + y);
                        //    Form1.vertexes.Add(new vertex(i + 1, _currHight + y, curr));
                        //    curr = bmp.GetPixel((i + 1), _currHight + y + 1);
                        //    Form1.vertexes.Add(new vertex((i + 1), _currHight + y + 1, curr));
                        //    curr = bmp.GetPixel(i - 1, _currHight + y);
                        //    Form1.vertexes.Add(new vertex(i - 1, _currHight + y, curr));
                        //    curr = bmp.GetPixel(i - 1, (_currHight + y - 1));
                        //    Form1.vertexes.Add(new vertex(i - 1, (_currHight + y - 1), curr));
                        //    Form1.bmpLines.SetPixel(i, (_currHight + y), Color.Red);
                        //}
                    }
                }
            }
        }
Beispiel #3
0
        private int getVertexDir(vertex first, vertex second, vertex third)
        {
            int turn = (third.x - first.x) * (second.y - first.y) - (third.y - first.y) * (second.x - first.x);

            if (turn > 0)
            {
                return(1); //r
            }
            if (turn < 0)
            {
                return(-1); //l
            }
            return(0);
        }
Beispiel #4
0
 public void drawSide( vertex begin, vertex end)
 {
     graphics.DrawLine(new Pen(Color.Black), new Point(begin.x, begin.y), new Point(end.x, end.y));
 }
Beispiel #5
0
 ///
 public void drawLine(int _x, int _y, int _currWidth, int _currHight, bool vert)
 {
     bmp = (Bitmap)Form1.Mem;
     if (vert)
     {
         for (int i = _y; i < _currHight + y; i++)
         {
             Form1.bmpLines.SetPixel((_currWidth + x), i, Color.Black);
             if ((_currHight == 1 || _currHight == 2) && (_currWidth == 1 || _currWidth == 2))
             {
                 Color curr = bmp.GetPixel((_currWidth + x), i);
                 vertex M1 = new vertex((_currWidth + x), i, curr);
                 Form1.vertexes.Add(M1);
                 //if (_currWidth + x != 256 && _currWidth + x + 1 != 256 && (i + 1) != 256 && (i - 1) >= 0 && (_currWidth + x - 1) >= 0)
                 //{
                 //    curr = bmp.GetPixel((_currWidth + x), i + 1);
                 //    Form1.vertexes.Add(new vertex((_currWidth + x), i + 1, curr));
                 //    curr = bmp.GetPixel((_currWidth + x + 1), i + 1);
                 //    Form1.vertexes.Add(new vertex((_currWidth + x + 1), i + 1, curr));
                 //    curr = bmp.GetPixel((_currWidth + x), i - 1);
                 //    Form1.vertexes.Add(new vertex((_currWidth + x), i - 1, curr));
                 //    curr = bmp.GetPixel((_currWidth + x - 1), i - 1);
                 //    Form1.vertexes.Add(new vertex((_currWidth + x - 1), i - 1, curr));
                 //    Form1.bmpLines.SetPixel((_currWidth + x), i, Color.Red);
                 //}
             }
         }
     }
     else
     {
         for (int i = _x; i < _currWidth + x; i++)
         {
             Form1.bmpLines.SetPixel(i, _currHight + y, Color.Black);
             if ((_currHight == 1 || _currHight == 2) && (_currWidth == 1 || _currWidth == 2))
             {
                 Color curr = bmp.GetPixel(i, _currHight + y);
                 vertex M1 = new vertex(i, _currHight + y, curr);
                 Form1.vertexes.Add(M1);
                 //Form1.bmpLines.SetPixel(i, _currHight + y, Color.Red);
                 //if (_currHight + y != 256 && _currHight + y + 1 != 256 && (i + 1) != 256 && (i - 1) >= 0 && (_currHight + y - 1) >= 0)
                 //{
                 //    curr = bmp.GetPixel(i + 1, _currHight + y);
                 //    Form1.vertexes.Add(new vertex(i + 1, _currHight + y, curr));
                 //    curr = bmp.GetPixel((i + 1), _currHight + y + 1);
                 //    Form1.vertexes.Add(new vertex((i + 1), _currHight + y + 1, curr));
                 //    curr = bmp.GetPixel(i - 1, _currHight + y);
                 //    Form1.vertexes.Add(new vertex(i - 1, _currHight + y, curr));
                 //    curr = bmp.GetPixel(i - 1, (_currHight + y - 1));
                 //    Form1.vertexes.Add(new vertex(i - 1, (_currHight + y - 1), curr));
                 //    Form1.bmpLines.SetPixel(i, (_currHight + y), Color.Red);
                 //}
             }
         }
     }
 }
Beispiel #6
0
 public bool Equals(vertex other)
 {
     return ((this.x == other.x) && (this.y == other.y));
 }
Beispiel #7
0
 public Triangle(vertex _v1, vertex _v2, vertex _v3)
 {
     v1 = _v1;
     v2 = _v2;
     v3 = _v3;
 }
Beispiel #8
0
 private int getVertexDir(vertex first, vertex second, vertex third)
 {
     int turn = (third.x - first.x) * (second.y - first.y) - (third.y - first.y) * (second.x - first.x);
     if (turn > 0)
     {
         return 1; //r
     }
     if (turn < 0)
     {
         return -1; //l
     }
     return 0;
 }
Beispiel #9
0
 public void drawSide(vertex begin, vertex end)
 {
     graphics.DrawLine(new Pen(Color.Black), new Point(begin.x, begin.y), new Point(end.x, end.y));
 }
Beispiel #10
0
 public Triangle(vertex _v1, vertex _v2, vertex _v3)
 {
     v1 = _v1;
     v2 = _v2;
     v3 = _v3;
 }
Beispiel #11
0
 public bool Equals(vertex other)
 {
     return((this.x == other.x) && (this.y == other.y));
 }