Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.66, 1.67
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2006-12-18 18:17:54
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22721/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Log Message: New methods for offsetting. One simply get the directions the vertices should move, and one to do a copy of the edges and place them. Both support variable offsets for each edge. Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Edge.java 16 Nov 2006 14:25:42 -0000 1.66 --- Edge.java 18 Dec 2006 18:17:39 -0000 1.67 *************** *** 14,17 **** --- 14,19 ---- import java.util.HashSet; import java.util.Iterator; + import java.util.LinkedHashMap; + import java.util.LinkedList; import java.util.List; import java.util.Map; *************** *** 628,631 **** --- 630,791 ---- /** + * Makes a map from a vertex to the direction the vertex should move + * in order to make an offset. The edges must all belong to + * the same surface. + * @param which the edges to offset + * @param inner the surface the edges belong to + * @param offset the amount to offset + * @return an offset-direction map for each vertex + */ + public static Map offsetDirections(List which, Surface inner, double offset) { + Map offsets = new HashMap(); + Iterator it = which.iterator(); + while (it.hasNext()) { + offsets.put(it.next(), Double.valueOf(offset)); + } + return offsetDirections(which, inner, offsets); + } + + /** + * Makes a map from a vertex to the direction the vertex should move + * in order to make an offset. The amount each edge should be offset is given in + * an offset map, from an edge to a double value. The edges must all belong to + * the same surface. + * @param which the edges to offset + * @param inner the surface the edges belong to + * @param offsetMap map from edges to its offset + * @return an offset-direction map for each vertex + */ + public static Map offsetDirections(List which, Surface inner, Map offsetMap) { + Map v2Dir = new HashMap(); + Edge e1 = null; + Edge e2 = null; + Edge first = null; + Vertex work; + boolean done = false; + Iterator edges2 = inner.getEdges().iterator(); + if (edges2.hasNext()) { + first = (Edge)edges2.next(); + e1 = first; + } + if (edges2.hasNext()) { + e2 = (Edge)edges2.next(); + } else { + done = true; + } + Vertex normal = inner.normal(); + while (!done) { + work = commonVertex(e1, e2); + if (which.contains(e1) || which.contains(e2)) { + Vertex dir1 = work.minus(e1.otherVertex(work)); + Vertex dir2 = e2.otherVertex(work).minus(work); + Vertex org1 = new Vertex(0, 0, 0); + Vertex org2 = new Vertex(0, 0, 0);; + if (which.contains(e1)) { + org1 = dir1.cross(normal); + org1.normalize(); + org1.scale(((Double)offsetMap.get(e1)).doubleValue()); + } + if (which.contains(e2)) { + org2 = dir2.cross(normal); + org2.normalize(); + org2.scale(((Double)offsetMap.get(e2)).doubleValue()); + } + org1 = org1.add(work); + org2 = org2.add(work); + + Line l1 = new Line(org1, dir1); + Line l2 = new Line(org2, dir2); + Vertex mainDir = work.minus(l1.intersection(l2)); + v2Dir.put(work, mainDir); + + e1 = e2; + if (edges2.hasNext()) { + e2 = (Edge)edges2.next(); + } else if (e2 != first) { + e2 = first; + } else { + done = true; + } + } + } + return v2Dir; + } + /** + * Makes a copy of a list of edges and places it at a specified offset. + * The offset for each edge is given in the offset map. + * @param which the edges to offset + * @param inner the surface the edges belong to + * @param offsetMap map from edges to its offset + * @return a list of the constructed edges. + */ + public static List placeOffset(List which, Surface inner, Map offsetMap) { + Map v2v = new HashMap(); + Map e2e = new LinkedHashMap(); + Iterator it = which.iterator(); + while (it.hasNext()) { + Edge e = (Edge)it.next(); + Vertex from = e.getFrom(); + Vertex to = e.getTo(); + if (v2v.get(from) == null) { + v2v.put(from, from.copy()); + } + if (v2v.get(to) == null) { + v2v.put(to, to.copy()); + } + e2e.put(e, new Edge((Vertex)v2v.get(from), (Vertex)v2v.get(to))); + } + Map directions = offsetDirections(which, inner, offsetMap); + Edge e1 = null; + Edge e2 = null; + Edge first = null; + Vertex work; + boolean done = false; + Iterator edges2 = inner.getEdges().iterator(); + if (edges2.hasNext()) { + first = (Edge)edges2.next(); + e1 = first; + } + if (edges2.hasNext()) { + e2 = (Edge)edges2.next(); + } else { + done = true; + } + Vertex normal = inner.normal(); + while (!done) { + work = commonVertex(e1, e2); + if (which.contains(e1)) { + Vertex dir1 = work.minus(e1.otherVertex(work)); + dir1 = dir1.cross(normal); + dir1.normalize(); + Vertex workDir = (Vertex)directions.get(work); + workDir.normalize(); + workDir.scale(((Double)offsetMap.get(e1)).doubleValue() / + workDir.dot(dir1)); + ((Vertex)v2v.get(work)).move(workDir.getX(), workDir.getY(), workDir.getZ()); + } else if (which.contains(e2)) { + Vertex dir2 = e2.otherVertex(work).minus(work); + dir2 = dir2.cross(normal); + dir2.normalize(); + Vertex workDir = (Vertex)directions.get(work); + workDir.normalize(); + workDir.scale(((Double)offsetMap.get(e2)).doubleValue() / + workDir.dot(dir2)); + ((Vertex)v2v.get(work)).move(workDir.getX(), workDir.getY(), workDir.getZ()); + } + e1 = e2; + if (edges2.hasNext()) { + e2 = (Edge)edges2.next(); + } else if (e2 != first) { + e2 = first; + } else { + done = true; + } + } + return new LinkedList(e2e.values()); + } + + + /** * Create a offset from a list of lines and a surface * PRECONDITION: all the edges have to be in the given surface and the edges *************** *** 640,644 **** return offset(which, inner, offset, null); } ! /** * Create a offset from a list of lines and a surface --- 800,804 ---- return offset(which, inner, offset, null); } ! /** * Create a offset from a list of lines and a surface *************** *** 651,654 **** --- 811,832 ---- */ public static List offset(List which, Surface inner, double offset, Map directions) { + Map offsetMap = new HashMap(); + Iterator it = which.iterator(); + while (it.hasNext()) { + offsetMap.put(it.next(), Double.valueOf(offset)); + } + return offset(which, inner, offsetMap, directions); + } + + /** + * Create a offset from a list of lines and a surface + * PRECONDITION: all the edges have to be in the given surface. + * @param which The list of edges in inner that are going to be offset + * @param inner The surface + * @param offsetMap mapping each edge to the amount it should be offset + * @param directions The movement directions send a empty list to retrieve direction map + * @return The generated list of Edges + */ + public static List offset(List which, Surface inner, Map offsetMap, Map directions) { HashSet edges = new HashSet(which); ArrayList res = new ArrayList(); *************** *** 661,665 **** Edge prevEdge = null; Edge firstEdge = null; ! // Find all the affected vertices and make the edges Iterator iter = inner.getEdges().iterator(); while (iter.hasNext()) { --- 839,843 ---- Edge prevEdge = null; Edge firstEdge = null; ! // Find all the affected vertices and make the new edges Iterator iter = inner.getEdges().iterator(); while (iter.hasNext()) { *************** *** 746,750 **** dir.scale(-1); dir = dir.copy(); ! dir.scale(offset); cur.getVertex().move(dir.getX(), dir.getY(), dir.getZ()); } --- 924,928 ---- dir.scale(-1); dir = dir.copy(); ! dir.scale(((Double)offsetMap.values().iterator().next()).doubleValue()); cur.getVertex().move(dir.getX(), dir.getY(), dir.getZ()); } |