Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool OffsetTool.java, 1.9, 1.10
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-10-09 13:27:26
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6699/src/net/sourceforge/bprocessor/gl/tool Modified Files: OffsetTool.java Log Message: clean up, now works for all surfaces. (no matter orientation) Index: OffsetTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/OffsetTool.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** OffsetTool.java 19 Sep 2006 12:22:05 -0000 1.9 --- OffsetTool.java 9 Oct 2006 13:27:15 -0000 1.10 *************** *** 29,32 **** --- 29,33 ---- import net.sourceforge.bprocessor.model.Vertex; + import org.apache.log4j.Logger; /** * OffsetTool *************** *** 34,37 **** --- 35,41 ---- public class OffsetTool extends AbstractPencil { + /** The logger */ + private static Logger log = Logger.getLogger(OffsetTool.class); + /** The current contour */ private List contour; *************** *** 53,57 **** /** Dragging flag */ private boolean dragging; ! /** The point the offset are started from */ private Vertex edgePoint; --- 57,61 ---- /** Dragging flag */ private boolean dragging; ! /** The point the offset are started from */ private Vertex edgePoint; *************** *** 100,104 **** contour.addAll(Edge.offset(edges, surface, -(current.vertex().minus(start.vertex()).length()), directionMap)); - //directionMap = findDirections(contour, surface.normal()); feedback(contour); outNormal = startEdge.getDirection().cross(surface.normal()); --- 104,107 ---- *************** *** 109,112 **** --- 112,116 ---- } } + lastOffsetPoint = current.vertex().copy(); } else { Vertex projection = outNormal.copy(); *************** *** 142,146 **** while (it.hasNext()) { Direction d = (Direction)it.next(); ! Vertex dir = d.getDirection().copy(); dir.scale(length); d.getVertex().move(dir.getX(), dir.getY(), dir.getZ()); --- 146,151 ---- while (it.hasNext()) { Direction d = (Direction)it.next(); ! Vertex dir; ! dir = d.getDirection().copy(1); dir.scale(length); d.getVertex().move(dir.getX(), dir.getY(), dir.getZ()); *************** *** 215,294 **** /** - * Finds the directions each vertex must move inorder for - * the contour to be expanded correctly. These are put in - * the direction map. - * @param edges the contour, the list must be ordered - * @param surfaceNormal the normal of the surface we are offsetting - * @return the directionmap - */ - private Map findDirections(List edges, Vertex surfaceNormal) { - //The direction of a vertex should be the sum of the normals of each - //of its edges, and scaled propably so it does not twist the contour out of shape - Map directions = new HashMap(); - Edge firstEdge = null; - Edge e1 = null; - Edge e2 = null; - Iterator it = edges.iterator(); - if (it.hasNext()) { - firstEdge = (Edge)it.next(); - e1 = firstEdge; - } - while (it.hasNext()) { - e2 = (Edge)it.next(); - Vertex dir1 = e1.getDirection().cross(surfaceNormal); - Vertex dir2 = e2.getDirection().cross(surfaceNormal); - dir1.scale(1 / dir1.length()); - dir2.scale(1 / dir2.length()); - Vertex mainDir = dir1.add(dir2); - mainDir.scale(1 / mainDir.dot(dir1)); - if (e2.contains(e1.getTo())) { - directions.put(e1.getTo(), mainDir); - } else { - directions.put(e1.getFrom(), mainDir); - } - e1 = e2; - } - //Here I make sure the first vertex gets a direction - Vertex dir1 = e1.getDirection().cross(surfaceNormal); - Vertex dir2 = firstEdge.getDirection().cross(surfaceNormal); - dir1.scale(1 / dir1.length()); - dir2.scale(1 / dir2.length()); - Vertex mainDir = dir1.add(dir2); - mainDir.scale(1 / mainDir.dot(dir1)); - if (firstEdge.contains(e1.getTo())) { - directions.put(e1.getTo(), mainDir); - } else { - directions.put(e1.getFrom(), mainDir); - } - return directions; - } - - /** - * Copies the edges of a surface maintaining the connectivity. - * @param surface the surface - * @return a list of the edges - */ - private List copyContour(Surface surface) { - List edges = new LinkedList(); - Vertex from = null; - Vertex to = null; - Vertex first = null; - Iterator it = surface.getVertices().iterator(); - if (it.hasNext()) { - first = ((Vertex)it.next()).copy(); - from = first; - } - while (it.hasNext()) { - to = ((Vertex)it.next()).copy(); - Edge offsetEdge = new Edge(from, to); - edges.add(offsetEdge); - from = to; - } - Edge offsetEdge = new Edge(from, first); - edges.add(offsetEdge); - return edges; - } - - /** * Invoked when a mouse is dragged with button down. * @param e The MouseEvent object --- 220,223 ---- |