Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model SurfaceAnalysis.java, 1.4, 1.5
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2007-03-28 12:35:50
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25111/src/net/sourceforge/bprocessor/model Modified Files: SurfaceAnalysis.java Log Message: Genericitification of surface analysis Index: SurfaceAnalysis.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/SurfaceAnalysis.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SurfaceAnalysis.java 21 Dec 2006 13:33:02 -0000 1.4 --- SurfaceAnalysis.java 28 Mar 2007 12:02:22 -0000 1.5 *************** *** 12,16 **** import java.util.HashMap; import java.util.HashSet; - import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; --- 12,15 ---- *************** *** 30,37 **** * @return True if edge is contained in a CoordinateSystem */ ! private boolean contains(Collection systems, Edge edge) { ! Iterator iter = systems.iterator(); ! while (iter.hasNext()) { ! CoordinateSystem system = (CoordinateSystem) iter.next(); if (system.plane().contains(edge)) { return true; --- 29,34 ---- * @return True if edge is contained in a CoordinateSystem */ ! private boolean contains(Collection<CoordinateSystem> systems, Edge edge) { ! for (CoordinateSystem system : systems) { if (system.plane().contains(edge)) { return true; *************** *** 47,55 **** * @return true if system is contained in collection */ ! private boolean contains(Collection systems, CoordinateSystem system) { ! Iterator iter = systems.iterator(); Plane plane = system.plane(); ! while (iter.hasNext()) { ! CoordinateSystem current = (CoordinateSystem) iter.next(); if (plane.contains(current.getOrigin())) { Vertex n1 = system.getN(); --- 44,50 ---- * @return true if system is contained in collection */ ! private boolean contains(Collection<CoordinateSystem> systems, CoordinateSystem system) { Plane plane = system.plane(); ! for (CoordinateSystem current : systems) { if (plane.contains(current.getOrigin())) { Vertex n1 = system.getN(); *************** *** 69,76 **** */ public void clearPlanes(Space space) { ! Collection planes = space.getCoordinateSystems(); ! Iterator iter = planes.iterator(); ! while (iter.hasNext()) { ! CoordinateSystem current = (CoordinateSystem) iter.next(); space.remove(current); } --- 64,69 ---- */ public void clearPlanes(Space space) { ! Collection<CoordinateSystem> planes = space.getCoordinateSystems(); ! for (CoordinateSystem current : planes) { space.remove(current); } *************** *** 83,87 **** * @return collection of CoordinateSystem */ ! public Collection planeAnalysis(Space space) { return planeAnalysis(space, space.getEdges()); } --- 76,80 ---- * @return collection of CoordinateSystem */ ! public Collection<CoordinateSystem> planeAnalysis(Space space) { return planeAnalysis(space, space.getEdges()); } *************** *** 92,164 **** * @return Collection of CoordinateSystem */ ! public Collection planeAnalysis(Space space, Collection start) { ! Collection systems = new LinkedList(); ! Collection edges = space.getEdges(); { ! Set mark = new HashSet(); ! Map neighbours = new HashMap(); { ! Collection vertices = space.getVertices(); ! Map edgemap = new HashMap(); ! { ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex current = (Vertex) iter.next(); ! edgemap.put(current, new LinkedList()); ! } } ! { ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! Vertex from = current.getFrom(); ! List fl = (List) edgemap.get(from); ! fl.add(current); ! Vertex to = current.getTo(); ! List tl = (List) edgemap.get(to); ! tl.add(current); ! } } ! { ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! List incident = new LinkedList(); ! { ! Vertex from = current.getFrom(); ! List fl = (List) edgemap.get(from); ! Iterator flit = fl.iterator(); ! while (flit.hasNext()) { ! Edge edge = (Edge) flit.next(); ! if (edge != current) { ! incident.add(edge); ! } } } ! { ! Vertex to = current.getTo(); ! List tl = (List) edgemap.get(to); ! Iterator tlit = tl.iterator(); ! while (tlit.hasNext()) { ! Edge edge = (Edge) tlit.next(); ! if (edge != current) { ! incident.add(edge); ! } } } - neighbours.put(current, incident); } } } ! LinkedList queue = new LinkedList(start); while (!queue.isEmpty()) { ! Edge current = (Edge) queue.removeFirst(); if (!mark.contains(current)) { mark.add(current); ! List incident = (List) neighbours.get(current); ! List pls = new LinkedList(); ! Iterator it = incident.iterator(); ! while (it.hasNext()) { ! Edge edge = (Edge) it.next(); CoordinateSystem system = CoordinateSystem.create(current, edge); if (system != null) { --- 85,139 ---- * @return Collection of CoordinateSystem */ ! public Collection<CoordinateSystem> planeAnalysis(Space space, Collection<Edge> start) { ! Collection<CoordinateSystem> systems = new LinkedList(); ! Collection<Edge> edges = space.getEdges(); { ! Set<Edge> mark = new HashSet(); ! Map<Edge, List<Edge>> neighbours = new HashMap(); { ! Collection<Vertex> vertices = space.getVertices(); ! Map<Vertex, List<Edge>> edgemap = new HashMap(); ! for (Vertex current : vertices) { ! edgemap.put(current, new LinkedList()); } ! for (Edge current : edges) { ! Vertex from = current.getFrom(); ! List<Edge> fl = edgemap.get(from); ! fl.add(current); ! Vertex to = current.getTo(); ! List<Edge> tl = edgemap.get(to); ! tl.add(current); } ! for (Edge current : edges) { ! List<Edge> incident = new LinkedList(); ! { ! Vertex from = current.getFrom(); ! List<Edge> fl = edgemap.get(from); ! for (Edge edge : fl) { ! if (edge != current) { ! incident.add(edge); } } ! } ! { ! Vertex to = current.getTo(); ! List<Edge> tl = edgemap.get(to); ! for (Edge edge : tl) { ! if (edge != current) { ! incident.add(edge); } } } + neighbours.put(current, incident); } } ! LinkedList<Edge> queue = new LinkedList(start); while (!queue.isEmpty()) { ! Edge current = queue.removeFirst(); if (!mark.contains(current)) { mark.add(current); ! List<Edge> incident = neighbours.get(current); ! List<CoordinateSystem> pls = new LinkedList(); ! for (Edge edge : incident) { CoordinateSystem system = CoordinateSystem.create(current, edge); if (system != null) { *************** *** 184,191 **** */ public void clearSurfaces(Space space) { ! Collection surfaces = new LinkedList(space.getSurfaces()); ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); space.remove(current); } --- 159,164 ---- */ public void clearSurfaces(Space space) { ! Collection<Surface> surfaces = new LinkedList(space.getSurfaces()); ! for (Surface current : surfaces) { space.remove(current); } *************** *** 199,208 **** * @return collection of surfaces */ ! public Collection surfaceAnalysis(Space space, Collection start) { ! Collection systems = planeAnalysis(space, start); ! Iterator iter = systems.iterator(); ! Collection added = new LinkedList(); ! while (iter.hasNext()) { ! CoordinateSystem current = (CoordinateSystem) iter.next(); added.addAll(surfaceAnalysis(space, current, start)); } --- 172,179 ---- * @return collection of surfaces */ ! public Collection<Surface> surfaceAnalysis(Space space, Collection<Edge> start) { ! Collection<CoordinateSystem> systems = planeAnalysis(space, start); ! Collection<Surface> added = new LinkedList(); ! for (CoordinateSystem current : systems) { added.addAll(surfaceAnalysis(space, current, start)); } *************** *** 215,222 **** */ public void surfaceAnalysis(Space space) { ! Collection systems = space.getCoordinateSystems(); ! Iterator iter = systems.iterator(); ! while (iter.hasNext()) { ! CoordinateSystem current = (CoordinateSystem) iter.next(); surfaceAnalysis(space, current, space.getEdges()); } --- 186,191 ---- */ public void surfaceAnalysis(Space space) { ! Collection<CoordinateSystem> systems = space.getCoordinateSystems(); ! for (CoordinateSystem current : systems) { surfaceAnalysis(space, current, space.getEdges()); } *************** *** 231,244 **** * @return collection of Surfaces */ ! public Collection surfaceAnalysis(Space space, CoordinateSystem system, Collection start) { Plane plane = system.plane(); ! Map vmap = new LinkedHashMap(); ! Map emap = new LinkedHashMap(); { ! List vertices = new LinkedList(space.getVertices()); Entity.sort(vertices); ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex current = (Vertex) iter.next(); if (plane.contains(current)) { vmap.put(current, new VertexNode(current)); --- 200,212 ---- * @return collection of Surfaces */ ! public Collection<Surface> surfaceAnalysis(Space space, CoordinateSystem system, ! Collection<Edge> start) { Plane plane = system.plane(); ! Map<Vertex, VertexNode> vmap = new LinkedHashMap(); ! Map<Edge, EdgeNode> emap = new LinkedHashMap(); { ! List<Vertex> vertices = new LinkedList(space.getVertices()); Entity.sort(vertices); ! for (Vertex current : vertices) { if (plane.contains(current)) { vmap.put(current, new VertexNode(current)); *************** *** 247,257 **** } { ! List edges = new LinkedList(space.getEdges()); Entity.sort(edges); ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! VertexNode from = (VertexNode) vmap.get(current.getFrom()); ! VertexNode to = (VertexNode) vmap.get(current.getTo()); if (from != null && to != null) { EdgeNode node = new EdgeNode(current, from, to); --- 215,223 ---- } { ! List<Edge> edges = new LinkedList(space.getEdges()); Entity.sort(edges); ! for (Edge current : edges) { ! VertexNode from = vmap.get(current.getFrom()); ! VertexNode to = vmap.get(current.getTo()); if (from != null && to != null) { EdgeNode node = new EdgeNode(current, from, to); *************** *** 262,287 **** } } ! { ! Iterator iter = vmap.values().iterator(); ! while (iter.hasNext()) { ! VertexNode current = (VertexNode) iter.next(); ! current.sort(system); ! } } { ! Set keys = emap.keySet(); ! Collection surfaces = space.getSurfaces(); ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); if (keys.containsAll(current.getEdges())) { SurfaceNode surfacenode = new SurfaceNode(current); int direction = Surface.direction(current.getEdges(), system); if (direction == Surface.RIGHT) { ! Iterator eit = current.getEdges().iterator(); ! VertexNode from = (VertexNode) vmap.get(current.getFirstVertex()); ! while (eit.hasNext()) { ! Edge edge = (Edge) eit.next(); ! EdgeNode node = (EdgeNode) emap.get(edge); VertexNode to = node.other(from); node.setRight(to, surfacenode); --- 228,245 ---- } } ! for (VertexNode current : vmap.values()) { ! current.sort(system); } { ! Set<Edge> keys = emap.keySet(); ! Collection<Surface> surfaces = space.getSurfaces(); ! for (Surface current : surfaces) { if (keys.containsAll(current.getEdges())) { SurfaceNode surfacenode = new SurfaceNode(current); int direction = Surface.direction(current.getEdges(), system); if (direction == Surface.RIGHT) { ! VertexNode from = vmap.get(current.getFirstVertex()); ! for (Edge edge : current.getEdges()) { ! EdgeNode node = emap.get(edge); VertexNode to = node.other(from); node.setRight(to, surfacenode); *************** *** 290,297 **** } if (direction == Surface.LEFT) { - Iterator eit = current.getEdges().iterator(); VertexNode from = (VertexNode) vmap.get(current.getFirstVertex()); ! while (eit.hasNext()) { ! Edge edge = (Edge) eit.next(); EdgeNode node = (EdgeNode) emap.get(edge); VertexNode to = node.other(from); --- 248,253 ---- } if (direction == Surface.LEFT) { VertexNode from = (VertexNode) vmap.get(current.getFirstVertex()); ! for (Edge edge : current.getEdges()) { EdgeNode node = (EdgeNode) emap.get(edge); VertexNode to = node.other(from); *************** *** 303,314 **** } } ! Set added = new HashSet(); ! Set removed = new HashSet(); { ! Iterator iter = start.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); if (emap.containsKey(current)) { ! EdgeNode node = (EdgeNode) emap.get(current); // node.left = null; // node.right = null; --- 259,268 ---- } } ! Set<Surface> added = new HashSet(); ! Set<Surface> removed = new HashSet(); { ! for (Edge current : start) { if (emap.containsKey(current)) { ! // EdgeNode node = emap.get(current); // node.left = null; // node.right = null; *************** *** 316,355 **** } } ! { ! Iterator iter = start.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! if (emap.containsKey(current)) { ! EdgeNode node = (EdgeNode) emap.get(current); ! surfaceAnalysis(node, system, added, removed); ! } } } ! { ! Iterator iter = removed.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! space.remove(current); ! } } ! { ! Iterator iter = added.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! space.add(current); ! } } ! { ! Iterator iter = added.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! Geometry.holeAnalysis(current); ! } } return added; } ! private List rightContour(EdgeNode start) { ! List edges = new LinkedList(); VertexNode to = start.to; EdgeNode current = start; --- 270,293 ---- } } ! for (Edge current : start) { ! if (emap.containsKey(current)) { ! EdgeNode node = (EdgeNode) emap.get(current); ! surfaceAnalysis(node, system, added, removed); } } ! for (Surface current : removed) { ! space.remove(current); } ! for (Surface current : added) { ! space.add(current); } ! for (Surface current : added) { ! Geometry.holeAnalysis(current); } return added; } ! private List<Edge> rightContour(EdgeNode start) { ! List<Edge> edges = new LinkedList(); VertexNode to = start.to; EdgeNode current = start; *************** *** 367,372 **** } ! private List leftContour(EdgeNode start) { ! List edges = new LinkedList(); VertexNode to = start.to; EdgeNode current = start; --- 305,310 ---- } ! private List<Edge> leftContour(EdgeNode start) { ! List<Edge> edges = new LinkedList(); VertexNode to = start.to; EdgeNode current = start; *************** *** 384,390 **** } ! private void assign(Surface surface, Collection surfaces) { if (!surfaces.isEmpty()) { ! Surface other = (Surface) surfaces.iterator().next(); Vertex n1 = surface.normal(); Vertex n2 = other.normal(); --- 322,328 ---- } ! private void assign(Surface surface, Collection<Surface> surfaces) { if (!surfaces.isEmpty()) { ! Surface other = surfaces.iterator().next(); Vertex n1 = surface.normal(); Vertex n2 = other.normal(); *************** *** 404,408 **** private void surfaceAnalysis (EdgeNode start, CoordinateSystem system, ! Set added, Set removed) { if (start.left == null) { SurfaceNode s = new SurfaceNode(); --- 342,346 ---- private void surfaceAnalysis (EdgeNode start, CoordinateSystem system, ! Set<Surface> added, Set<Surface> removed) { if (start.left == null) { SurfaceNode s = new SurfaceNode(); *************** *** 416,420 **** } if (start.left != start.right) { ! List edges = leftContour(start); if (edges.size() > 2) { int turn = Surface.direction(edges, system); --- 354,358 ---- } if (start.left != start.right) { ! List<Edge> edges = leftContour(start); if (edges.size() > 2) { int turn = Surface.direction(edges, system); *************** *** 439,443 **** } if (start.right != start.left) { ! List edges = rightContour(start); if (edges.size() > 2) { int turn = Surface.direction(edges, system); --- 377,381 ---- } if (start.right != start.left) { ! List<Edge> edges = rightContour(start); if (edges.size() > 2) { int turn = Surface.direction(edges, system); *************** *** 460,464 **** private Vertex vertex; /** edges */ ! private List edges; /** --- 398,402 ---- private Vertex vertex; /** edges */ ! private List<EdgeNode> edges; /** *************** *** 528,534 **** List right = new LinkedList(); ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! EdgeNode current = (EdgeNode) iter.next(); VertexNode other = current.other(this); Vertex delta = other.vertex.minus(vertex); --- 466,470 ---- List right = new LinkedList(); ! for (EdgeNode current : edges) { VertexNode other = current.other(this); Vertex delta = other.vertex.minus(vertex); *************** *** 567,574 **** } { ! EdgeNode previous = (EdgeNode) edges.get(edges.size() - 1); ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! EdgeNode current = (EdgeNode) iter.next(); if (previous.to == this) { previous.toSucc = current; --- 503,508 ---- } { ! EdgeNode previous = edges.get(edges.size() - 1); ! for (EdgeNode current : edges) { if (previous.to == this) { previous.toSucc = current; *************** *** 761,765 **** * the current geometric tools. */ ! private Set surfaces; /** --- 695,699 ---- * the current geometric tools. */ ! private Set<Surface> surfaces; /** |