Exemplo n.º 1
0
        public Edge3d get()
        {
            Edge3d res = data[0];

            data.RemoveAt(0);
            return(res);
        }
Exemplo n.º 2
0
        public override List <Triangle3d> build()
        {
            /* First find a hull edge -- just connect bottommost to second from bottom */
            Point3d bot, bot2; /* bottom point and adjacent point*/

            bot  = this.Bottom();
            bot2 = search2d(bot);

            /* intialize the edge stack */
            EdgeStack es = new EdgeStack();

            es.put(bot, bot2);
            es.put(bot2, bot);
            List <Triangle3d> faces = new List <Triangle3d>(20);
            Edge3d            e     = new Edge3d(bot, bot2);

            //faces.addElement(e);

            /* now the main loop -- keep finding faces till there are no more to be found */
            while (!es.isEmpty())
            {
                e = es.get();
                Point3d cand = search(e);
                faces.Add(new Triangle3d(e.start, e.end, cand));
                es.putp(e.start, cand);
                es.putp(cand, e.end);
            }
            return(faces);
        }
Exemplo n.º 3
0
 public override bool Equals(Object o)
 {
     if (o is Edge3d)
     {
         Edge3d e = (Edge3d)o;
         return(start.Equals(e.end) && end.Equals(e.start) ||
                (end.Equals(e.end) && start.Equals(e.start)));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public void putp(Edge3d e)
        {
            int ind = data.IndexOf(e);

            if (ind == -1)
            {
                data.Insert(0, e);
            }
            else
            {
                data.RemoveAt(ind);
            }
        }
Exemplo n.º 5
0
        public override List <Triangle3d> build()
        {
            EdgeStack         es    = new EdgeStack();
            List <Triangle3d> faces = new List <Triangle3d>();

            if (pts.Length < 2)
            {
                return(faces);
            }
            faces.Add(new Triangle3d(pts[0], pts[1], pts[2]));
            faces.Add(new Triangle3d(pts[0], pts[2], pts[1]));
            /* now the main loop -- add vertices one at a time */
            for (int i = 3; i < pts.Length; i++)
            {
                /* delete faces that this vertex can see*/
                bool inside = true; //are we inside the hull?
                for (int j = 0; j < faces.Count; j++)
                {
                    Triangle3d t = faces[j];
                    if (t.inside(pts[i]))
                    {
                        inside = false;
                        /* update boundary of hole */
                        es.putp(t.tri[0], t.tri[1]);
                        es.putp(t.tri[1], t.tri[2]);
                        es.putp(t.tri[2], t.tri[0]);
                    }
                }
                if (inside)
                {
                    continue;
                }

                while (!es.isEmpty())
                {
                    Edge3d e = es.get();
                    faces.Add(new Triangle3d(e.start, e.end, pts[i]));
                }
            }
            return(faces);
        }
Exemplo n.º 6
0
        protected Point3d search(Edge3d e)
        {
            int i;

            for (i = 0; pts[i] == e.start || pts[i] == e.end; i++)
            {
                /* nothing */
            }
            Point3d   cand  = pts[i];
            HalfSpace candh = new HalfSpace(e.start, e.end, cand);

            for (i = i + 1; i < pts.Length; i++)
            {
                if (pts[i] != e.start && pts[i] != e.end && candh.inside(pts[i]))
                {
                    cand  = pts[i];
                    candh = new HalfSpace(e.start, e.end, cand);
                }
            }
            return(cand);
        }
Exemplo n.º 7
0
        public override List <Triangle3d> build()
        {
            Triangle3d face1, face2;                   //first two faces created

            EdgeStack         es    = new EdgeStack(); //used to find boundary of hole
            List <Triangle3d> faces = new List <Triangle3d>();

            this.findmaxmin();

            //make p[3] the furthest from p[0]p[1]
            HalfSpace h = new HalfSpace(pts[0], pts[1]);

            for (int i = 3; i < pts.Length; i++)
            {
                if (h.normal.dot(pts[i]) > h.normal.dot(pts[2]))
                {
                    Point3d temp = pts[2];
                    pts[2] = pts[i];
                    pts[i] = temp;
                }
            }

            face1 = new Triangle3d(pts[0], pts[1], pts[2]);
            face2 = new Triangle3d(pts[0], pts[2], pts[1]);
            faces.Add(face1);
            faces.Add(face2);

            /* associate remaining points with one of these two faces */
            for (int i = 3; i < pts.Length; i++)
            {
                if (!face1.add(pts[i]))
                {
                    face2.add(pts[i]);
                }
            }

            for (int i = 0; i < faces.Count; i++)
            {
                List <Point3d> ps       = new List <Point3d>();
                Triangle3d     selected = faces[i];

                Point3d newp = selected.extreme();
                if (newp == null)
                {
                    continue;
                }

                for (int j = 0; j < faces.Count; j++)
                {
                    Triangle3d t = faces[j];
                    if (t.inside(newp))
                    {
                        es.putp(t.tri[0], t.tri[1]);
                        es.putp(t.tri[1], t.tri[2]);
                        es.putp(t.tri[2], t.tri[0]);
                        /*add the points associated with this face to ps */
                        ps.AddRange(t.pts);
                    }
                }

                while (!es.isEmpty())
                {
                    Edge3d         e   = es.get();
                    Triangle3d     t   = new Triangle3d(e.start, e.end, newp);
                    List <Point3d> ps2 = new List <Point3d>(ps.Count);

                    for (int j = ps.Count - 1; j >= 0; j--)
                    {
                        Point3d p = ps[j];
                        if ((!p.Equals(newp)) && !t.add(p))
                        {
                            ps2.Add(p);
                        }
                    }
                    ps = ps2;
                    faces.Add(t);
                }
            }

            return(faces);
        }
Exemplo n.º 8
0
 public void put(Edge3d e)
 {
     data.Insert(0, e);
 }