[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.109, 1.110 Plane.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2008-10-23 04:52:21
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv24692/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Plane.java Log Message: clipping algorithm Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** Edge.java 8 Oct 2008 10:26:39 -0000 1.109 --- Edge.java 23 Oct 2008 04:52:13 -0000 1.110 *************** *** 509,514 **** --- 509,516 ---- Vertex to = getTo(); Edge e1 = new Edge(from, vertex); + e1.setStrippled(this.getStrippled()); added.add(e1); Edge e2 = new Edge(vertex, to); + e2.setStrippled(this.getStrippled()); added.add(e2); if (getOwner() != null) { Index: Plane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Plane.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Plane.java 15 Oct 2008 08:25:51 -0000 1.39 --- Plane.java 23 Oct 2008 04:52:13 -0000 1.40 *************** *** 11,18 **** --- 11,21 ---- import java.util.Comparator; import java.util.HashMap; + import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; + import java.util.Queue; + import java.util.Set; import net.sourceforge.bprocessor.model.SurfaceAnalysis.EdgeStructure; *************** *** 225,273 **** } ! /** ! * Calculates the intersection between the input geometry and this Plane ! * @param input Geometry in the form of a Mesh ! * @return intersection in the form of a Container ! */ ! public Container intersection(Mesh input) { ! Container silhouette = new Container("Section", Space.CONSTRUCTION, true); ! List<Surface> surfaces = new LinkedList(); ! List<Entry> entries = new LinkedList(); ! Map map = new HashMap(); ! Map<Edge, Entry> planar = new HashMap(); ! for (Space current : input.elements()) { ! if (!current.isVoid()) { ! Space element = current.shallowCopy(); ! map.put(current, element); ! silhouette.add(element); ! } else { ! map.put(current, silhouette.getEmpty()); } } ! for (Edge current : input.edges()) { ! if (contains(current)) { ! Edge edge = (Edge) current.copy(map); ! silhouette.insert(edge); ! Entry entry = new Entry(edge, Entry.PLANAR); ! entries.add(entry); ! planar.put(current, entry); } } ! for (Surface current : input.surfaces()) { Collection<Edge> contour = current.getEdges(); ! if (planar.keySet().containsAll(contour)) { ! for (Edge edge : contour) { ! Entry entry = planar.get(edge); ! entry.surfaces().add(current); } - Surface surface = (Surface) current.copy(map); - silhouette.insert(surface); - Space front = current.getFrontDomain(); - front = (Space) map.get(front); - Space back = current.getBackDomain(); - back = (Space) map.get(back); - surface.setFrontDomain((Container) front); - surface.setBackDomain((Container) back); } else { { LinkedList<Vertex> intersections = new LinkedList(); --- 228,332 ---- } ! private class Intersector implements Runnable { ! private Mesh input; ! private boolean assign = true; ! ! private Container silhouette = new Container("Section", Space.CONSTRUCTION, true); ! private List<Surface> surfaces = new LinkedList(); ! private Map map = new HashMap(); ! private Set<Edge> planar = new HashSet(); ! private Set<Surface> mark = new HashSet(); ! ! /** ! * Constructor ! * @param input Mesh ! */ ! public Intersector(Mesh input) { ! this.input = input; ! } ! ! /** ! * Insert a shallow copy of all elements in the silhouette ! */ ! private void copyElements() { ! for (Space current : input.elements()) { ! if (!current.isVoid()) { ! Space element = current.shallowCopy(); ! map.put(current, element); ! silhouette.add(element); ! } else { ! map.put(current, silhouette.getEmpty()); ! } } } ! ! /** ! * Insert a copy of all planar edges in the silhouette ! */ ! private void copyPlanarEdges() { ! for (Edge current : input.edges()) { ! if (contains(current)) { ! Edge edge = (Edge) current.copy(map); ! silhouette.insert(edge); ! planar.add(current); ! } } } ! ! private void intersect(Collection<Surface> surfaces) { ! for (Surface current : surfaces) { ! handle(current); ! } ! } ! ! private void handle(Surface surface) { ! if (!mark.contains(surface)) { ! mark.add(surface); ! if (surface.getExterior() != null) { ! handle(surface.getExterior()); ! } ! intersect(surface); ! } ! } ! ! private void insert(Edge line) { ! Queue<Edge> queue = new LinkedList(); ! queue.offer(line); ! while (!queue.isEmpty()) { ! splitting: ! { ! Edge edge = queue.remove(); ! for (Vertex current : silhouette.getVertices()) { ! if (edge.coincides(current)) { ! Collection<Edge> added = edge.split(current); ! queue.addAll(added); ! break splitting; ! } ! } ! silhouette.insert(edge); ! } ! } ! } ! ! private void intersect(Surface current) { Collection<Edge> contour = current.getEdges(); ! if (planar.containsAll(contour)) { ! // Insert a copy a planar surface along with space assignments ! if (assign) { ! Surface surface = (Surface) current.copy(map); ! silhouette.insert(surface); ! ! // Assign ! Space front = current.getFrontDomain(); ! front = (Space) map.get(front); ! Space back = current.getBackDomain(); ! back = (Space) map.get(back); ! surface.setFrontDomain((Container) front); ! surface.setBackDomain((Container) back); } } else { + // Compute intersections with the plane and compute a new + // contour for surface intersected with plane. + { LinkedList<Vertex> intersections = new LinkedList(); *************** *** 300,303 **** --- 359,363 ---- if (intersections.size() > 1) { + // Insert intersection lines in silhouette { final Vertex leader = intersections.getFirst(); *************** *** 336,343 **** if (silhouette.findEdge(line) == null) { line.setStrippled(true); ! silhouette.insert(line); ! Entry entry = new Entry(line, Entry.INTERSECTION); ! entries.add(entry); ! entry.surfaces().add(current); } } --- 396,400 ---- if (silhouette.findEdge(line) == null) { line.setStrippled(true); ! insert(line); } } *************** *** 345,376 **** } } { - List<Edge> frame = new LinkedList(); - for (Edge edge : lst) { - frame.add(silhouette.insert(edge)); - } - Vertex normal = current.normal(); ! Surface leader = new Surface(frame); ! silhouette.add(leader); ! Vertex n = leader.normal(); ! Container front = current.getFrontDomain(); ! front = (Container) map.get(front); ! Container back = current.getBackDomain(); ! back = (Container) map.get(back); ! if (n.dot(normal) < 0) { ! leader.setFrontDomain(back); ! leader.setBackDomain(front); ! } else { ! leader.setFrontDomain(front); ! leader.setBackDomain(back); } - - CoordinateSystem system = current.coordinateSystem(); - SurfaceAnalysis analysis = new SurfaceAnalysis(); - EdgeStructure structure = analysis.new EdgeStructure(silhouette, system, frame); - Collection<Surface> faces = structure.surfaceAnalysis(frame); - surfaces.addAll(faces); } } --- 402,440 ---- } } + + // Insert intersecting surface into silhouette for the purpose of space assignment { ! if (assign) { ! ! List<Edge> frame = new LinkedList(); ! for (Edge edge : lst) { ! frame.add(silhouette.insert(edge)); ! } ! ! Vertex normal = current.normal(); ! ! Surface leader = new Surface(frame); ! silhouette.add(leader); ! Vertex n = leader.normal(); ! Container front = current.getFrontDomain(); ! front = (Container) map.get(front); ! Container back = current.getBackDomain(); ! back = (Container) map.get(back); ! if (n.dot(normal) < 0) { ! leader.setFrontDomain(back); ! leader.setBackDomain(front); ! } else { ! leader.setFrontDomain(front); ! leader.setBackDomain(back); ! } ! ! CoordinateSystem system = current.coordinateSystem(); ! SurfaceAnalysis analysis = new SurfaceAnalysis(); ! EdgeStructure structure = analysis.new EdgeStructure(silhouette, system, frame); ! Collection<Surface> faces = structure.surfaceAnalysis(frame); ! surfaces.addAll(faces); } } } *************** *** 379,472 **** } ! ! ! CoordinateSystem system = coordinateSystem(); ! SurfaceAnalysis analysis = new SurfaceAnalysis(); ! ! EdgeStructure structure = analysis.new EdgeStructure(silhouette, system, silhouette.getEdges()); ! Collection<Surface> faces = structure.surfaceAnalysis(silhouette.getEdges()); ! ! SpaceAnalysis analizer = new SpaceAnalysis(); ! for (Surface face : faces) { ! analizer.subsume(face, 1); ! analizer.subsume(face, -1); ! } ! ! for (Surface surface : surfaces) { ! surface.delete(); ! } ! ! { ! List<Edge> deletion = new LinkedList(); ! for (Edge edge : silhouette.getEdges()) { ! if (!contains(edge)) { ! deletion.add(edge); ! } } ! for (Edge edge : deletion) { ! edge.delete(); } ! } ! return silhouette; ! } ! ! private class Entry { ! public static final int PLANAR = 0; ! public static final int INTERSECTION = 1; ! ! ! private Edge edge; ! private int kind; ! private List<Surface> surfaces; ! private double x; ! private double y0; ! private double y1; ! private double x0; ! private double x1; ! ! public Entry(Edge edge, int kind) { ! this.edge = edge; ! this.kind = kind; ! surfaces = new LinkedList(); ! } ! ! public List<Surface> surfaces() { ! return surfaces; ! } ! ! public boolean eq(double a, double b) { ! return Math.abs(a - b) < 0.0000001; ! } ! ! public boolean ignore() { ! return eq(y0, y1); ! } ! ! public void order() { ! if (edge.from.y < edge.to.y) { ! y0 = edge.from.y; ! x0 = edge.from.x; ! y1 = edge.to.y; ! x1 = edge.from.x; ! } else { ! y0 = edge.to.y; ! x0 = edge.to.x; ! y1 = edge.from.y; ! x1 = edge.to.x; } } ! public void findIntersectingX(double y) { ! double dx = x1 - x0; ! double dy = y1 - y0; ! x = x1 + ((y - y0 / dy)) * dx; } ! public String toString() { ! return "{" + edge + " " + y0 + " " + y1 + "}"; } } /** * Return the projection of the vertex into this Plane * @param vertex Vertex --- 443,521 ---- } ! /** ! * Compute space assignments ! */ ! private void assign() { ! CoordinateSystem system = coordinateSystem(); ! ! SurfaceAnalysis analysis = new SurfaceAnalysis(); ! ! EdgeStructure structure = ! analysis.new EdgeStructure(silhouette, system, silhouette.getEdges()); ! Collection<Surface> faces = structure.surfaceAnalysis(silhouette.getEdges()); ! ! SpaceAnalysis analizer = new SpaceAnalysis(); ! for (Surface face : faces) { ! analizer.subsume(face, 1); ! analizer.subsume(face, -1); } ! ! // Delete extra geometry ! for (Surface surface : surfaces) { ! surface.delete(); } ! ! { ! List<Edge> deletion = new LinkedList(); ! for (Edge edge : silhouette.getEdges()) { ! if (!contains(edge)) { ! deletion.add(edge); ! } ! } ! for (Edge edge : deletion) { ! edge.delete(); ! } } } ! public void run() { ! if (assign) { ! copyElements(); ! } ! ! copyPlanarEdges(); ! ! intersect(input.surfaces()); ! ! if (assign) { ! assign(); ! } ! ! for (Surface current : silhouette.getSurfaces()) { ! Geometry.holeAnalysis(current); ! } } ! /** ! * Container ! * @return silhouette ! */ ! public Container silhouette() { ! return silhouette; } } /** + * Calculates the intersection between the input geometry and this Plane + * @param input Geometry in the form of a Mesh + * @return intersection in the form of a Container + */ + public Container intersection(Mesh input) { + Intersector intersector = new Intersector(input); + intersector.run(); + return intersector.silhouette(); + } + + /** * Return the projection of the vertex into this Plane * @param vertex Vertex |