コード例 #1
0
		public bool debug = false;            // Used for debugging

		/**
		 * Constructor.
		 * All sites must fall within the initial triangle.
		 * @param triangle the initial triangle
		 */
		public DelaunayTriangulation(Simplex triangle) : base(triangle)
		{
			mostRecent = triangle;
		}
コード例 #2
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;
    }
コード例 #3
0
		private Graphics g;                   // Stored graphics context

		/**
		 * Create and initialize the DT.
		 */
		public DelaunayPanel()
		{
			initialTriangle = new Simplex(new Pnt[] {
            new Pnt(-initialSize, -initialSize),
            new Pnt( initialSize, -initialSize),
            new Pnt(           0,  initialSize)});
			dt = new DelaunayTriangulation(initialTriangle);
		}
コード例 #4
0
		/**
		 * Main program; used for testing.
		 */
		public static void main(String[] args) {
        Simplex tri = new Simplex(new Pnt[] {new Pnt(-10,10), new Pnt(10,10), new Pnt(0,-10)});
       Console.WriteLine("Triangle created: " + tri);
        DelaunayTriangulation dt = new DelaunayTriangulation(tri);
		Console.WriteLine("DelaunayTriangulation created: " + dt);
        dt.delaunayPlace(new Pnt(0,0));
        dt.delaunayPlace(new Pnt(1,0));
        dt.delaunayPlace(new Pnt(0,1));
        Console.WriteLine("After adding 3 points, the DelaunayTriangulation is a " + dt);
        dt.printStuff();
    }
コード例 #5
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;
		}
コード例 #6
0
		/**
		 * True iff simplices are neighbors.
		 * Two simplices are neighbors if they are the same dimension and they share
		 * a facet.
		 * @param simplex the other Simplex
		 * @return true iff this Simplex is a neighbor of simplex
		 */
		public bool isNeighbor(Simplex simplex)
		{
			HashSet h = new HashSet(this);
			h.removeAll(simplex);
			return (this.size() == simplex.size()) && (h.size() == 1);
		}
コード例 #7
0
		/**
		 * True iff the simplex is in this Triangulation.
		 * @param simplex the simplex to check
		 * @return true iff the simplex is in this Triangulation
		 */
		public bool contains(Simplex simplex)
		{
			return this._neighbors.containsKey(simplex);
		}
コード例 #8
0
		private HashMap _neighbors;  // Maps Simplex to Set of neighbors

		/**
		 * Constructor.
		 * @param simplex the initial Simplex.
		 */
		public Triangulation(Simplex simplex)
		{
			this._neighbors = new HashMap();
			this._neighbors.put(simplex, new HashSet());
		}
コード例 #9
0
		/**
		 * Report neighbors of the given simplex.
		 * @param simplex a Simplex
		 * @return the Set of neighbors of simplex
		 */
		public Set neighbors(Simplex simplex)
		{
			return new HashSet((Set)this._neighbors.get(simplex));
		}
コード例 #10
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);
        }
コード例 #11
0
        public bool debug          = false;           // Used for debugging

        /**
         * Constructor.
         * All sites must fall within the initial triangle.
         * @param triangle the initial triangle
         */
        public DelaunayTriangulation(Simplex triangle) : base(triangle)
        {
            mostRecent = triangle;
        }