[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.103, 1.104 Vertex.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-12-13 08:21:38
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv365/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Vertex.java Command.java Log Message: final grid algorithm Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** Edge.java 11 Dec 2007 14:49:02 -0000 1.103 --- Edge.java 13 Dec 2007 08:21:34 -0000 1.104 *************** *** 386,390 **** * @return The shortes Edge connecting this Edge and the other */ ! public Edge intersection(Edge other) { if (this.getLength() < 0.0000001) { if (other.getLength() < 0.0000001) { --- 386,390 ---- * @return The shortes Edge connecting this Edge and the other */ ! public Edge shortestEdge(Edge other) { if (this.getLength() < 0.0000001) { if (other.getLength() < 0.0000001) { *************** *** 456,459 **** --- 456,481 ---- /** + * + * @param edge Edge + * @return vertex + */ + public Vertex intersection(Edge edge) { + Edge shortest = shortestEdge(edge); + if (shortest != null) { + if (shortest.getLength() < 0.0000001) { + Vertex vertex = shortest.getFrom(); + if (from.equalEps(vertex)) { + return from; + } else if (to.equalEps(vertex)) { + return to; + } else { + return vertex; + } + } + } + return null; + } + + /** * Finds the intersection between a Vertex and this * edge. The intersection is defined as the vertex Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** Vertex.java 11 Dec 2007 14:49:02 -0000 1.74 --- Vertex.java 13 Dec 2007 08:21:34 -0000 1.75 *************** *** 9,12 **** --- 9,14 ---- import java.util.ArrayList; import java.util.Collection; + import java.util.Collections; + import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; *************** *** 514,517 **** --- 516,561 ---- } + + /** + * + * @param vertices list of vertices + */ + public static void sortByX(List<Vertex> vertices) { + final Comparator<Vertex> comparator = new Comparator<Vertex>() { + public int compare(Vertex v1, Vertex v2) { + if (v1.x == v2.x) { + return 0; + } else if (v1.x < v2.x) { + return -1; + } else { + return 1; + } + } + }; + Collections.sort(vertices, comparator); + } + + + /** + * + * @param vertices list of vertices + */ + public static void sortByY(List<Vertex> vertices) { + final Comparator<Vertex> comparator = new Comparator<Vertex>() { + public int compare(Vertex v1, Vertex v2) { + if (v1.y == v2.y) { + return 0; + } else if (v1.y < v2.y) { + return -1; + } else { + return 1; + } + } + }; + Collections.sort(vertices, comparator); + } + + + /** * Center Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** Command.java 12 Dec 2007 16:11:49 -0000 1.56 --- Command.java 13 Dec 2007 08:21:34 -0000 1.57 *************** *** 10,15 **** import java.util.ArrayList; import java.util.Collection; - import java.util.Collections; - import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; --- 10,13 ---- *************** *** 763,767 **** * @param surfaces surface */ ! public static void addTo(Space owner, Collection<Surface> surfaces) { Collection<Edge> edges = Surface.edges(surfaces); Collection<Vertex> vertices = Edge.vertices(edges); --- 761,765 ---- * @param surfaces surface */ ! public static void addSurfacesTo(Space owner, Collection<Surface> surfaces) { Collection<Edge> edges = Surface.edges(surfaces); Collection<Vertex> vertices = Edge.vertices(edges); *************** *** 782,785 **** --- 780,800 ---- /** + * Add edges and their vertices, then perform surface-analysis + * @param owner Space + * @param edges edges + */ + public static void addEdgesTo(Space owner, Collection<Edge> edges) { + Collection<Vertex> points = Edge.vertices(edges); + for (Vertex current : points) { + owner.add(current); + } + for (Edge current : edges) { + owner.add(current); + } + SurfaceAnalysis analysis = new SurfaceAnalysis(); + analysis.surfaceAnalysis(owner, edges); + } + + /** * Pyramid */ *************** *** 823,827 **** Space union = new Container("Pyramid", Space.CONSTRUCTION, true); ! addTo(union, list(s0, side0, side1, side2, side3)); return union; --- 838,842 ---- Space union = new Container("Pyramid", Space.CONSTRUCTION, true); ! addSurfacesTo(union, list(s0, side0, side1, side2, side3)); return union; *************** *** 911,915 **** ! addTo(union, surfaces); for (Vertex current : union.getVertices()) { --- 926,930 ---- ! addSurfacesTo(union, surfaces); for (Vertex current : union.getVertices()) { *************** *** 1369,1373 **** } ! Shape.addTo(union, inserted); { --- 1384,1388 ---- } ! Shape.addSurfacesTo(union, inserted); { *************** *** 1499,1503 **** Space union = new Container("Layer", Space.CONSTRUCTION, true); for (Prism current : prisms) { ! Shape.addTo(union, current.surfaces()); } net.getOwner().add(union); --- 1514,1518 ---- Space union = new Container("Layer", Space.CONSTRUCTION, true); for (Prism current : prisms) { ! Shape.addSurfacesTo(union, current.surfaces()); } net.getOwner().add(union); *************** *** 1615,1620 **** } ! private Space createVertical(Surface surface, double dx) { ! Space net = Space.createNet("Vertical Net"); HashMap map = new HashMap(); --- 1630,1708 ---- } ! private void fill(List<Vertex> vertices, List<Edge> edges) { ! Iterator<Vertex> iter = vertices.iterator(); ! Vertex from = iter.next(); ! while (iter.hasNext()) { ! Vertex to = iter.next(); ! edges.add(new Edge(from, to)); ! from = to; ! } ! } ! ! private void stipple(List<Edge> edges, ! List<Vertex> vertices) { ! Iterator<Vertex> iter = vertices.iterator(); ! for (int k = 0; k < (vertices.size() / 2); k++) { ! Vertex f = iter.next(); ! Vertex t = iter.next(); ! edges.add(new Edge(f, t)); ! } ! } ! ! private void fillx(List<Edge> edges, ! List<Vertex> vertices, ! Vertex[][] grid, ! int j, ! int n, ! double xmin, ! double dx) { ! Iterator<Vertex> iter = vertices.iterator(); ! for (int k = 0; k < (vertices.size() / 2); k++) { ! Vertex f = iter.next(); ! Vertex t = iter.next(); ! ! List<Vertex> points = new LinkedList(); ! points.add(f); ! double x = xmin; ! for (int i = 0; i < n; i++) { ! x += dx; ! if (f.x < x && x < t.x) { ! points.add(grid[i][j]); ! } ! } ! points.add(t); ! fill(points, edges); ! } ! } ! ! private void filly(List<Edge> edges, ! List<Vertex> vertices, ! Vertex[][] grid, ! int i, ! int m, ! double ymin, ! double dy) { ! Iterator<Vertex> iter = vertices.iterator(); ! for (int k = 0; k < (vertices.size() / 2); k++) { ! Vertex f = iter.next(); ! Vertex t = iter.next(); ! ! List<Vertex> points = new LinkedList(); ! points.add(f); ! double y = ymin; ! for (int j = 0; j < m; j++) { ! y += dy; ! if (f.y < y && y < t.y) { ! points.add(grid[i][j]); ! } ! } ! points.add(t); ! fill(points, edges); ! } ! } ! ! ! private Space create(Surface surface, double dx, double dy) { ! Space net = Space.createNet("Grid"); HashMap map = new HashMap(); *************** *** 1636,1639 **** --- 1724,1734 ---- system.translateIt(vertices); + HashMap<Edge, List<Vertex>> cuts = new HashMap(); + for (Edge current : contour) { + cuts.put(current, new LinkedList()); + } + + List<Edge> all = new LinkedList(); + BoundingBox box = new BoundingBox(vertices); double xmin = box.xmin().getX(); *************** *** 1643,1701 **** double width = xmax - xmin; ! int n = round(width / dx); ! List<Edge> verticals = new LinkedList(); ! for (int i = 0; i < n; i++) { ! double x = xmin + (i + 1) * dx; ! Vertex from = new Vertex(x, ymin, 0); ! Vertex to = new Vertex(x, ymax, 0); ! Edge edge = new Edge(from, to); ! List<Vertex> intersections = new LinkedList(); ! for (Edge current : contour) { ! double x0 = current.from.x; ! double x1 = current.to.x; ! if (x0 > x1) { ! double tmp = x1; ! x1 = x0; ! x0 = tmp; } ! if (x0 <= x && x < x1) { ! Edge intersect = current.intersection(edge); ! if (intersect != null) { ! if (intersect.getLength() < 0.0000001) { ! intersections.add(intersect.from); } } } ! } ! final Comparator<Vertex> comparator = new Comparator<Vertex>() { ! public int compare(Vertex v1, Vertex v2) { ! if (v1.y == v2.y) { ! return 0; ! } else if (v1.y < v2.y) { ! return -1; } else { ! return 1; } } ! }; ! ! if (intersections.size() > 0) { ! Collections.sort(intersections, comparator); ! Iterator<Vertex> iter = intersections.iterator(); ! for (int j = 0; j < (intersections.size() / 2); j++) { ! Vertex f = iter.next(); ! Vertex t = iter.next(); ! verticals.add(new Edge(f, t)); } } } ! system.unTranslateIt(Edge.vertices(verticals)); ! system.unTranslateIt(Edge.vertices(contour)); ! Geometry.insertEdges(net, contour); ! Geometry.insertEdges(net, verticals); return net; } --- 1738,1875 ---- double width = xmax - xmin; + double height = ymax - ymin; + int n; + int m; ! if (dx > 0) { ! n = round(width / dx); ! } else { ! n = 0; ! } ! if (dy > 0) { ! m = round(height / dy); ! } else { ! m = 0; ! } ! Vertex[][] grid = null; ! if (n > 0 && m > 0) { ! grid = new Vertex[n][m]; ! { ! double x = xmin; ! for (int i = 0; i < n; i++) { ! x = x + dx; ! double y = ymin; ! for (int j = 0; j < m; j++) { ! y = y + dy; ! grid[i][j] = new Vertex(x, y, 0); ! } } ! } ! } ! ! ! if (n > 0) { ! List<Edge> verticals = new LinkedList(); ! ! for (int i = 0; i < n; i++) { ! double x = xmin + (i + 1) * dx; ! Vertex from = new Vertex(x, ymin, 0); ! Vertex to = new Vertex(x, ymax, 0); ! Edge edge = new Edge(from, to); ! List<Vertex> intersections = new LinkedList(); ! for (Edge current : contour) { ! double x0 = current.from.x; ! double x1 = current.to.x; ! if (x0 > x1) { ! double tmp = x1; ! x1 = x0; ! x0 = tmp; ! } ! if (x0 <= x && x < x1) { ! Vertex intersect = current.intersection(edge); ! if (intersect != null) { ! intersections.add(intersect); ! if (!current.contains(intersect)) { ! cuts.get(current).add(intersect); ! } } } } ! ! if (intersections.size() > 0) { ! Vertex.sortByY(intersections); ! if (m > 0) { ! filly(verticals, intersections, grid, i, m, ymin, dy); } else { ! stipple(verticals, intersections); } } ! } ! all.addAll(verticals); ! } ! ! if (m > 0) { ! ! List<Edge> horizontals = new LinkedList(); ! ! for (int j = 0; j < m; j++) { ! double y = ymin + (j + 1) * dy; ! Vertex from = new Vertex(xmin, y, 0); ! Vertex to = new Vertex(xmax, y, 0); ! Edge edge = new Edge(from, to); ! List<Vertex> intersections = new LinkedList(); ! for (Edge current : contour) { ! double y0 = current.from.y; ! double y1 = current.to.y; ! if (y0 > y1) { ! double tmp = y1; ! y1 = y0; ! y0 = tmp; ! } ! if (y0 <= y && y < y1) { ! Vertex intersect = current.intersection(edge); ! if (intersect != null) { ! intersections.add(intersect); ! if (!current.contains(intersect)) { ! cuts.get(current).add(intersect); ! } ! } ! } ! } ! ! if (intersections.size() > 0) { ! Vertex.sortByX(intersections); ! if (n > 0) { ! fillx(horizontals, intersections, grid, j, n, xmin, dx); ! } else { ! stipple(horizontals, intersections); ! } } } + all.addAll(horizontals); } ! ! List<Edge> segments = new LinkedList(); ! for (Edge current : contour) { ! List<Vertex> points = cuts.get(current); ! points.add(current.from); ! points.add(current.to); ! if (Math.abs(current.from.x - current.to.x) > 0.0000001) { ! Vertex.sortByX(points); ! } else { ! Vertex.sortByY(points); ! } ! fill(points, segments); ! } ! ! ! all.addAll(segments); ! ! system.unTranslateIt(Edge.vertices(all)); ! ! Shape.addEdgesTo(net, all); return net; } *************** *** 1790,1805 **** } ! { ! ! Collection<Vertex> points = Edge.vertices(all); ! for (Vertex current : points) { ! net.add(current); ! } ! for (Edge current : all) { ! net.add(current); ! } ! SurfaceAnalysis analysis = new SurfaceAnalysis(); ! analysis.surfaceAnalysis(net, all); ! } return net; } --- 1964,1969 ---- } ! Shape.addEdgesTo(net, all); ! return net; } *************** *** 1812,1820 **** double ydistance = parameters.getDouble("y distance"); Space net; ! if (xdistance > 0.0000001 && ydistance > 0.00001) { ! net = createGrid(surface, xdistance, ydistance); ! } else { ! net = createVertical(surface, xdistance); ! } Space owner = surface.getOwner(); owner.add(net); --- 1976,1980 ---- double ydistance = parameters.getDouble("y distance"); Space net; ! net = create(surface, xdistance, ydistance); Space owner = surface.getOwner(); owner.add(net); |