Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.76, 1.77 Vertex.java, 1
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2007-03-22 14:37:34
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3066/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Vertex.java Space.java Mesh.java Log Message: Progress on mesh algorithms Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** Edge.java 22 Mar 2007 11:44:29 -0000 1.76 --- Edge.java 22 Mar 2007 14:37:26 -0000 1.77 *************** *** 229,235 **** String name; if (id == null) { ! name = "None"; } else { ! name = "E" + id; } return name; --- 229,239 ---- String name; if (id == null) { ! name = "E"; } else { ! if (getOwner() == null) { ! name = "e" + id; ! } else { ! name = "E" + id; ! } } return name; Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.124 retrieving revision 1.125 diff -C2 -d -r1.124 -r1.125 *** Space.java 12 Mar 2007 08:32:47 -0000 1.124 --- Space.java 22 Mar 2007 14:37:26 -0000 1.125 *************** *** 2721,2723 **** --- 2721,2744 ---- } + /** + * + * @param mesh Mesh + * @return new mesh + */ + public Mesh insert(Mesh mesh) { + Collection<Vertex> vertices = new LinkedList(); + Collection<Edge> edges = new LinkedList(); + Collection<Surface> surfaces = new LinkedList(); + mesh.split(this.getVertices()); + for (Vertex vertex : mesh.vertices()) { + vertices.add(insert(vertex)); + } + for (Edge edge : mesh.edges()) { + edges.add(insert(edge)); + } + for (Surface surface : mesh.surfaces()) { + surfaces.add(insert(surface)); + } + return new Mesh(surfaces, edges, vertices); + } } Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** Vertex.java 19 Mar 2007 11:53:11 -0000 1.55 --- Vertex.java 22 Mar 2007 14:37:26 -0000 1.56 *************** *** 103,107 **** name = "V"; } else { ! name = "V" + id; } return name; --- 103,111 ---- name = "V"; } else { ! if (getOwner() == null) { ! name = "v" + id; ! } else { ! name = "V" + id; ! } } return name; Index: Mesh.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Mesh.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Mesh.java 21 Mar 2007 13:44:13 -0000 1.12 --- Mesh.java 22 Mar 2007 14:37:26 -0000 1.13 *************** *** 9,12 **** --- 9,14 ---- import java.util.Collection; + import java.util.LinkedList; + import java.util.List; /** *************** *** 38,40 **** --- 40,181 ---- this.vertices = vertices; } + + /** + * + * @return vertices + */ + public Collection<Vertex> vertices() { + return vertices; + } + + /** + * + * @return edges + */ + public Collection<Edge> edges() { + return edges; + } + + /** + * + * @return surfaces + */ + public Collection<Surface> surfaces() { + return surfaces; + } + + /** + * + */ + public void identify() { + long count = 1; + for (Edge current : edges) { + if (current.id == null) { + current.setId(new Long(count++)); + } + } + count = 1; + for (Vertex current : vertices) { + if (current.id == null) { + current.setId(new Long(count++)); + } + } + } + + /** + * Insert the other mesh into this mesh. + * The other mesh is assumed to not contain + * duplicates. + * @param other The mesh to insert into this mesh. + */ + public void insert(Mesh other) { + // Version 1 + // Replace vertices in other + // Split edges in other + // Replace edges in other + // Replace surfaces in other + // Insert new geometry + + // Version 2 + // Split edges in other + // Insert vertices + // Insert edges + // Insert surfaces + + // Plan 1 + // Insert geometry + // implement version 2. + } + + /** + * + * @param others Collection of vertices + */ + public void split(Collection<Vertex> others) { + Collection<Edge> added = new LinkedList(); + Collection<Edge> removed = new LinkedList(); + for (Vertex vertex : others) { + split(vertex, added, removed); + } + edges.removeAll(removed); + edges.addAll(added); + } + + /** + * + * @param vertex Vertex + * @param added Collection + * @param removed Collection + * @return Boolean + */ + public boolean split(Vertex vertex, + Collection<Edge> added, Collection<Edge> removed) { + boolean add = false; + for (Edge edge : edges) { + if (edge.coincides(vertex)) { + split(edge, vertex, added, removed); + add = true; + } + } + return add; + } + + private void split(Edge edge, Vertex vertex, + Collection<Edge> added, Collection<Edge> removed) { + Edge e1 = new Edge(edge.from, vertex); + Edge e2 = new Edge(vertex, edge.to); + added.add(e1); + added.add(e2); + removed.add(edge); + Collection<Surface> surfaces = adjacent(edge); + for (Surface current : surfaces) { + Vertex from = current.getFirstVertex(); + List<Edge> edges = current.getEdges(); + LinkedList<Edge> replacement = new LinkedList(); + for (Edge original : edges) { + if (original == edge) { + if (original.from == from) { + replacement.add(e1); + replacement.add(e2); + } else { + replacement.add(e2); + replacement.add(e1); + } + } else { + replacement.add(original); + } + } + current.setEdges(replacement); + } + } + + private Collection<Surface> adjacent(Edge edge) { + LinkedList<Surface> result = new LinkedList(); + for (Surface current : surfaces) { + if (current.contains(edge)) { + result.add(current); + } + } + return result; + } } |