Beispiel #1
0
        /* Navigation */

        /**
         * Report neighbor opposite the given vertex of simplex.
         * @param vertex a vertex of simplex
         * @param simplex we want the neighbor of this Simplex
         * @return the neighbor opposite vertex of simplex; null if none
         * @throws IllegalArgumentException if vertex is not in this Simplex
         */
        public Simplex neighborOpposite(Object vertex, Simplex simplex)
        {
            if (!simplex.contains(vertex))
            {
                throw new InvalidOperationException("Bad vertex; not in simplex");
            }

            for (Iterator it = ((Set)_neighbors.get(simplex)).iterator(); it.hasNext();)
            {
                Simplex s = (Simplex)it.next();
                for (Iterator otherIt = simplex.iterator(); otherIt.hasNext();)
                {
                    var v = otherIt.next();
                    if (v.Equals(vertex))
                    {
                        continue;
                    }
                    if (!s.contains(v))
                    {
                        s = null;
                        break;
                    }
                }

                if (s == null)
                {
                    continue;
                }

                return(s);
            }
            return(null);
        }
 /**
  * Draw all the empty circles (one for each triangle) of the DT.
  */
 public void drawAllCircles()
 {
     // Loop through all triangles of the DT
     for (Iterator it = dt.iterator(); it.hasNext();)
     {
         Simplex triangle = (Simplex)it.next();
         for (Iterator otherIt = initialTriangle.iterator(); otherIt.hasNext();)
         {
             Pnt p = (Pnt)otherIt.next();
             if (triangle.contains(p))
             {
                 triangle = null;
                 break;
             }
         }
         if (triangle != null)
         {
             Pnt    c      = Pnt.circumcenter((Pnt[])triangle.toArray(new Pnt[0]));
             double radius = c.subtract((Pnt)triangle.iterator().next()).magnitude();
             draw(c, radius, null);
         }
     }
 }
		/* Navigation */

		/**
		 * Report neighbor opposite the given vertex of simplex.
		 * @param vertex a vertex of simplex
		 * @param simplex we want the neighbor of this Simplex
		 * @return the neighbor opposite vertex of simplex; null if none
		 * @throws IllegalArgumentException if vertex is not in this Simplex
		 */
		public Simplex neighborOpposite(Object vertex, Simplex simplex)
		{
			if (!simplex.contains(vertex))
				throw new InvalidOperationException("Bad vertex; not in simplex");

			for (Iterator it = ((Set)_neighbors.get(simplex)).iterator(); it.hasNext(); )
			{
				Simplex s = (Simplex)it.next();
				for (Iterator otherIt = simplex.iterator(); otherIt.hasNext(); )
				{
					var v = otherIt.next();
					if (v.Equals(vertex)) continue;
					if (!s.contains(v))
					{
						s = null;
						break;
					}
				}
				
				if (s == null)
					continue;

				return s;
			}
			return null;
		}
Beispiel #4
0
        /**
         * Place a new point site into the DT.
         * @param site the new Pnt
         * @return set of all new triangles created
         */
        public Set delaunayPlace(Pnt site)
        {
            Set        newTriangles = new HashSet();
            Set        oldTriangles = new HashSet();
            Set        doneSet      = new HashSet();
            LinkedList waitingQ     = new LinkedList();

            // Locate containing triangle
            if (debug)
            {
                Console.WriteLine("Locate");
            }
            Simplex triangle = locate(site);

            // Give up if no containing triangle or if site is already in DT
            var triangle_null = triangle == null;

            if (triangle_null || triangle.contains(site))
            {
                return(newTriangles);
            }

            // Find Delaunay cavity (those triangles with site in their circumcircles)
            if (debug)
            {
                Console.WriteLine("Cavity");
            }
            waitingQ.add(triangle);
            while (!waitingQ.isEmpty())
            {
                triangle = (Simplex)waitingQ.removeFirst();
                if (site.vsCircumcircle((Pnt[])triangle.toArray(new Pnt[0])) == 1)
                {
                    continue;
                }
                oldTriangles.add(triangle);
                Iterator it = this.neighbors(triangle).iterator();
                for (; it.hasNext();)
                {
                    Simplex tri = (Simplex)it.next();
                    if (doneSet.contains(tri))
                    {
                        continue;
                    }
                    doneSet.add(tri);
                    waitingQ.add(tri);
                }
            }
            // Create the new triangles
            if (debug)
            {
                Console.WriteLine("Create");
            }
            for (Iterator it = Simplex.boundary(oldTriangles).iterator(); it.hasNext();)
            {
                Set facet = (Set)it.next();
                facet.add(site);
                newTriangles.add(new Simplex(facet));
            }
            // Replace old triangles with new triangles
            if (debug)
            {
                Console.WriteLine("Update");
            }
            this.update(oldTriangles, newTriangles);

            // Update mostRecent triangle
            if (!newTriangles.isEmpty())
            {
                mostRecent = (Simplex)newTriangles.iterator().next();
            }
            return(newTriangles);
        }