Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Command.java, 1.66, 1.67
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2008-02-07 13:04:17
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5595/src/net/sourceforge/bprocessor/model Modified Files: Command.java Log Message: improvements to offset Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Command.java 25 Jan 2008 13:06:02 -0000 1.66 --- Command.java 7 Feb 2008 13:04:21 -0000 1.67 *************** *** 135,139 **** public static class OffsetNormal extends Command { private Surface surface; - /** * --- 135,138 ---- *************** *** 146,149 **** --- 145,149 ---- parameters.put("direction", ""); parameters.put("controlled", true); + parameters.put("holes", true); } *************** *** 155,158 **** --- 155,235 ---- } + private static Surface offset(Surface surface, double distance) { + // prolog + HashMap map = new HashMap(); + Surface copy = (Surface) surface.copy(map); + Vertex normal = surface.normal(); + + // epilog + Vertex direction = normal.scale(distance); + for (Vertex current : copy.getVertices()) { + current.set(current.add(direction)); + } + return copy; + } + + private static Surface offset(Surface surface, Space space, double distance) { + // prolog + HashMap map = new HashMap(); + Surface copy = (Surface) surface.copy(map); + Vertex normal = surface.normal(); + List<Vertex> vertices = surface.getVertices(); + + Map<Vertex, Collection<Edge>> edgemap = new HashMap(); + { + Collection<Surface> envelope = space.getEnvelope(); + Collection<Edge> edges = Surface.edges(envelope); + for (Vertex current : vertices) { + edgemap.put(current, new LinkedList()); + } + for (Edge current : edges) { + { + Collection<Edge> lst = edgemap.get(current.from); + if (lst != null) { + lst.add(current); + } + } + { + Collection<Edge> lst = edgemap.get(current.to); + if (lst != null) { + lst.add(current); + } + } + } + } + Map<Vertex, Vertex> directions = new HashMap(); + for (Vertex current : vertices) { + Collection<Edge> edges = edgemap.get(current); + Collection<Edge> candidates = new LinkedList(); + for (Edge edge : edges) { + Vertex other = edge.otherVertex(current); + Vertex direction = other.minus(current); + double dot = direction.dot(normal); + if (Math.abs(dot) > 0.0000001) { + candidates.add(edge); + } + } + if (candidates.size() == 1) { + Edge edge = candidates.iterator().next(); + Vertex other = edge.otherVertex(current); + Vertex direction = other.minus(current); + directions.put(current, direction); + } else { + directions.put(current, normal); + } + } + + + // epilog + for (Vertex original : vertices) { + Vertex direction = directions.get(original); + Vertex current = (Vertex) map.get(original); + double factor = direction.dot(normal); + double t = distance / factor; + current.set(current.add(direction.scale(t))); + } + return copy; + } + /** {@inheritDoc} */ @Override *************** *** 161,211 **** double distance = parameters.getDouble("distance"); Container space = (Container) owner.find((String)parameters.get("direction")); if (space != null) { if (surface.getBackDomain() == space) { distance = -distance; } } boolean controlled = parameters.getBoolean("controlled"); ! HashMap map = new HashMap(); ! Surface copy = (Surface) surface.copy(map); ! Vertex normal = surface.normal(); if (controlled) { ! List<Vertex> vertices = surface.getVertices(); ! Map<Vertex, Collection<Edge>> edgemap = owner.edgeMap(vertices); ! Map<Vertex, Vertex> directions = new HashMap(); ! for (Vertex current : vertices) { ! Collection<Edge> edges = edgemap.get(current); ! Collection<Edge> candidates = new LinkedList(); ! for (Edge edge : edges) { ! Vertex other = edge.otherVertex(current); ! Vertex direction = other.minus(current); ! double dot = direction.dot(normal); ! if (Math.abs(dot) > 0.0000001) { ! candidates.add(edge); } } - if (candidates.size() == 1) { - Edge edge = candidates.iterator().next(); - Vertex other = edge.otherVertex(current); - Vertex direction = other.minus(current); - directions.put(current, direction); - } else { - directions.put(current, normal); - } - } - for (Vertex original : vertices) { - Vertex direction = directions.get(original); - Vertex current = (Vertex) map.get(original); - double factor = direction.dot(normal); - double t = distance / factor; - current.set(current.add(direction.scale(t))); } } else { ! Vertex direction = normal.scale(distance); ! for (Vertex current : copy.getVertices()) { ! current.set(current.add(direction)); ! } } --- 238,291 ---- double distance = parameters.getDouble("distance"); Container space = (Container) owner.find((String)parameters.get("direction")); + boolean front = true; if (space != null) { if (surface.getBackDomain() == space) { distance = -distance; + front = false; } + } else { + space = surface.getFrontDomain(); } + boolean controlled = parameters.getBoolean("controlled"); + boolean holes = parameters.getBoolean("holes"); ! System.out.println("offset " + distance + " in direction of " + space); ! ! Surface copy = null; if (controlled) { ! ! copy = offset(surface, space, distance); ! if (holes) { ! Vertex n0 = surface.normal(); ! for (Surface current : surface.getHoles()) { ! Vertex n = current.normal(); ! double t = n0.dot(n); ! Space sp; ! double d; ! if (front) { ! if (t > 0) { ! sp = current.getFrontDomain(); ! d = distance; ! } else { ! sp = current.getBackDomain(); ! d = -distance; ! } ! } else { ! if (t > 0) { ! sp = current.getBackDomain(); ! d = distance; ! } else { ! sp = current.getFrontDomain(); ! d = -distance; ! } } + Surface hole = offset(current, sp, d); + Geometry.insertEdges(hole.getEdges()); } } } else { ! copy = offset(surface, distance); } |