[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Geometry.java,NONE,1.1 Surface.java,1
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2005-10-18 08:17:18
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv855/src/net/sourceforge/bprocessor/model Modified Files: Surface.java CoordinateSystem.java Added Files: Geometry.java Log Message: Fast target added to build.xml Geometry implements surface finding algorithms Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Surface.java 11 Oct 2005 12:04:51 -0000 1.39 --- Surface.java 18 Oct 2005 08:17:07 -0000 1.40 *************** *** 708,725 **** Edge e0 = (Edge) edges.get(0); Edge e1 = (Edge) edges.get(1); ! Vertex v0, v1, v2; ! v0 = getFirtVertex(); ! v1 = e0.otherVertex(v0); ! v2 = e1.otherVertex(v1); ! ! origin = v0; ! i = v1.minus(v0); ! i.scale(1 / i.length()); ! Vertex v = v2.minus(v1); ! n = i.cross(v); ! n.scale(1 / n.length()); ! j = i.cross(n); ! j.scale(1 / j.length()); ! return new CoordinateSystem(i, j, n, origin); } else { return null; --- 708,712 ---- Edge e0 = (Edge) edges.get(0); Edge e1 = (Edge) edges.get(1); ! return new CoordinateSystem(e0, e1); } else { return null; --- NEW FILE: Geometry.java --- //--------------------------------------------------------------------------------- // $Id: Geometry.java,v 1.1 2005/10/18 08:17:07 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Set; /** * The Geometry class is for various geometric things */ public class Geometry { /** * Insert the list of edges in the model by splitting * surfaces etc. * @param edges The list of edges */ public static void insert(List edges) { Edge first = (Edge) edges.get(0); Edge last = (Edge) edges.get(edges.size() - 1); Vertex from = first.getFrom(); Set siblings = from.getEdges(); siblings.remove(first); siblings.remove(last); Iterator iter = siblings.iterator(); System.out.println("--- processing ---"); while (!siblings.isEmpty()) { System.out.println(siblings); Edge current = (Edge) siblings.iterator().next(); CoordinateSystem system = new CoordinateSystem(first, current); VertexNode node = new VertexNode(from, system); node.insert(first); siblings = node.insert(siblings); node.sort(); System.out.println("-- NODE --"); System.out.println(node); System.out.println("----------"); } } /** * Find surfaces that the new edges forms in the plane the coordinate system * of the VertexNode * @param vertex The Vertex * @param first The first EdgeNode * @param edges The edges */ private static void findSurfaces(VertexNode vertex, EdgeNode first, List edges) { Surface clockwise = clockwiseSurface(vertex, first, edges); Project.getInstance().intern(clockwise); } /** * Find the clockwise surface that edges forms in the coordinate system of * the VertexNode * @param vertex The Vertex * @param first The first EdgeNode * @param edges The edges * @return The Surface */ private static Surface clockwiseSurface(VertexNode vertex, EdgeNode first, List edges) { ArrayList result = new ArrayList(); result.addAll(edges); Vertex from = ((Edge) edges.get(0)).getFrom(); Vertex to = ((Edge) edges.get(edges.size() - 1)).getTo(); EdgeNode currentEdge = first; VertexNode current = vertex; while (current.vertex() != to) { currentEdge = current.clockwise(currentEdge); result.add(currentEdge.edge()); current = currentEdge.other(current); } return new Surface("", result); } /** * The VertexNode class is used for internal surface calculations */ private static class VertexNode { /** The vertex */ private Vertex vertex; /** The edgenodes */ private List edgenodes; /** The coordinate system */ private CoordinateSystem system; /** * Constructor for VertexNode * @param vertex The vertex * @param system The coordinate systen */ public VertexNode(Vertex vertex, CoordinateSystem system) { this.vertex = vertex; this.system = system; edgenodes = new LinkedList(); } /** * Insert a list of edges into this VertexNode by * finding all edges in that lies in the coordinate * system, and sorting the edges clockwise * @param edges List of edges * @return The edges that are not inserted */ public Set insert(Set edges) { Set result = new HashSet(); Iterator iter = edges.iterator(); while (iter.hasNext()) { Edge current = (Edge) iter.next(); if (insert(current) != null) { result.add(current); } } return result; } /** * Test if this edges is in the coordinate system and * insert if yes. * @param edge The edge * @return The EdgeNode if inserted */ public EdgeNode insert(Edge edge) { Vertex v = edge.otherVertex(vertex).minus(vertex); double dz = v.dot(system.getN()); if (dz == 0.0) { double dx = v.dot(system.getI()); double dy = v.dot(system.getJ()); EdgeNode node = new EdgeNode(edge, dx, dy); insert(node); return node; } else { return null; } } /** * Insert an EdgeNode * @param node The EdgeNode */ public void insert(EdgeNode node) { edgenodes.add(node); } /** * Get the vertex * @return The vertex */ public Vertex vertex() { return vertex; } /** * Get the system * @return The system */ public CoordinateSystem system() { return system; } /** * Sort the EdgeNodes clockwise around the vertex */ public void sort() { LinkedList right = new LinkedList(); LinkedList left = new LinkedList(); Iterator iter = edgenodes.iterator(); while (iter.hasNext()) { EdgeNode current = (EdgeNode) iter.next(); if (current.dx == 0) { if (current.dy < 0) { right.addLast(current); } if (current.dy > 0) { left.addLast(current); } } if (current.dx > 0) { right.addLast(current); } if (current.dx < 0) { left.addLast(current); } } Object[] rights = right.toArray(); Arrays.sort(rights); Object[] lefts = left.toArray(); Arrays.sort(lefts); LinkedList result = new LinkedList(); for (int i = 0; i < rights.length; i++) { result.addLast(((EdgeNode) rights[i]).edge); } for (int i = 0; i < lefts.length; i++) { result.addLast(((EdgeNode) lefts[i]).edge); } edgenodes = result; } /** * Return the edgenode counterclockwise around the vertex from the edge * @param edge The edgenode * @return The counterclockwise edgenode */ public EdgeNode counterclockwise(EdgeNode edge) { Object[] sorted = edgenodes.toArray(); int index = 0; for (int i = 0; i < sorted.length; i++) { if (sorted[i] == edge) { index = i; } } index++; if (index == sorted.length) { return (EdgeNode) sorted[0]; } else { return (EdgeNode) sorted[index]; } } /** * Return the edgenode clockwise around the vertex from the edge * @param edge The edgenode * @return The clockwise edgenode */ public EdgeNode clockwise(EdgeNode edge) { Object[] sorted = edgenodes.toArray(); int index = 0; for (int i = 0; i < sorted.length; i++) { if (sorted[i] == edge) { index = i; } } if (index == 0) { return (EdgeNode) sorted[sorted.length - 1]; } else { return (EdgeNode) sorted[index - 1]; } } /** * Return a String describing this VertexNode * @return String describing this VertexNode */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("{" + vertex + "\n"); Iterator iter = edgenodes.iterator(); while (iter.hasNext()) { EdgeNode current = (EdgeNode) iter.next(); buffer.append(" " + current.edge() + "\n"); } buffer.append("}\n"); return buffer.toString(); } } /** * The EdgeNode class is used for surface calculations */ private static class EdgeNode implements Comparable { /** The edge */ private Edge edge; /** The dx */ private double dx; /** The dy */ private double dy; /** * Constructor for EdgeNode * @param edge The edge * @param dx The dx * @param dy The dy */ public EdgeNode(Edge edge, double dx, double dy) { this.edge = edge; this.dx = dx; this.dy = dy; } /** * Return the Edge * @return The Edge */ public Edge edge() { return edge; } /** * Return the other end * @param node The node * @return The other end */ public VertexNode other(VertexNode node) { Vertex other = edge.otherVertex(node.vertex()); CoordinateSystem system = node.system(); VertexNode result = new VertexNode(other, system); Set edges = other.getEdges(); edges.remove(edge); result.insert(edges); result.insert(this); result.sort(); return result; } /** * Compare one edgenode to a nother * @param other The other * @return The result of comparison */ public int compareTo(Object other) { EdgeNode entry = (EdgeNode) other; if (this.dx == 0) { return -1; } if (entry.dx == 0) { return 1; } if ((this.dy / this.dx) < (entry.dy / entry.dx)) { return -1; } else { return 1; } } } } Index: CoordinateSystem.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/CoordinateSystem.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CoordinateSystem.java 11 Oct 2005 12:04:51 -0000 1.3 --- CoordinateSystem.java 18 Oct 2005 08:17:07 -0000 1.4 *************** *** 49,52 **** --- 49,81 ---- this.origin = origin; } + + /** + * Constructor for CoordinateSystem that constructs a CoordinateSystem + * from two edges. The edges are assumed to have a common Vertex. + * The origin of the Coordinate System will be the vertex from e1 + * that are not shared between the two edges. + * @param e1 Edge one + * @param e2 Edge two + */ + public CoordinateSystem(Edge e1, Edge e2) { + super(); + Vertex v0, v1, v2; + if (e2.contains(e1.getFrom())) { + v0 = e1.getTo(); + v1 = e1.getFrom(); + } else { + v0 = e1.getFrom(); + v1 = e1.getTo(); + } + v2 = e2.otherVertex(v1); + origin = v0; + i = v1.minus(v0); + i.scale(1 / i.length()); + Vertex v = v2.minus(v1); + n = i.cross(v); + n.scale(1 / n.length()); + j = i.cross(n); + j.scale(1 / j.length()); + } /** |