[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.62, 1.63 Vertex.java, 1
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-10-19 09:56:23
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv552/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Vertex.java Surface.java Geometry.java Space.java Log Message: Refactored geometry insertion Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** Edge.java 16 Oct 2006 15:14:51 -0000 1.62 --- Edge.java 19 Oct 2006 09:56:21 -0000 1.63 *************** *** 96,105 **** while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! if (current.coincides(vertex)) { ! result.add(current); } } return result; } /** --- 96,126 ---- while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! if (!current.protect()) { ! if (current.coincides(vertex)) { ! result.add(current); ! } } } return result; } + + /** + * Find edge that are equivalent to edge + * @param edges Collection of edges + * @param edge Edge + * @return equivalent edge + */ + public static Edge findEdge(Collection edges, Edge edge) { + Iterator iter = edges.iterator(); + while (iter.hasNext()) { + Edge current = (Edge) iter.next(); + if (!current.protect()) { + if (current.equivalent(edge)) { + return current; + } + } + } + return null; + } /** *************** *** 184,187 **** --- 205,223 ---- /** + * Return true if this edge is equivalent to the other edge + * @param other Edge + * @return True if equivalent + */ + public boolean equivalent(Edge other) { + if (other.getFrom() == from && other.getTo() == to) { + return true; + } + if (other.getFrom() == to && other.getTo() == from) { + return true; + } + return false; + } + + /** * Get the name * @return The name Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.115 retrieving revision 1.116 diff -C2 -d -r1.115 -r1.116 *** Surface.java 14 Oct 2006 23:41:03 -0000 1.115 --- Surface.java 19 Oct 2006 09:56:21 -0000 1.116 *************** *** 61,64 **** --- 61,83 ---- /** + * Find equivalent surface in collection of surfaces + * @param surfaces Collection of surfaces + * @param surface Surface + * @return equivalent surface + */ + public static Surface findSurface(Collection surfaces, Surface surface) { + Iterator iter = surfaces.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + if (!current.protect()) { + if (current.equivalent(surface)) { + return current; + } + } + } + return null; + } + + /** * Constructor for surface */ *************** *** 146,149 **** --- 165,178 ---- /** + * Test if this surface is equivalent to the other surface + * @param other Surface + * @return true if equivalent + */ + public boolean equivalent(Surface other) { + Set others = new HashSet(other.getEdges()); + return others.containsAll(edges); + } + + /** * Return an ordered list of vertices around this Surface. * @return An ordered list of vertices around this Surface Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** Space.java 16 Oct 2006 06:49:25 -0000 1.82 --- Space.java 19 Oct 2006 09:56:21 -0000 1.83 *************** *** 514,521 **** * Insert a vertex * @param vertex The vertex - * @param split Split edges * @return The vertex */ ! public Vertex insert(Vertex vertex, boolean split) { Space space = this; if (vertex.getOwner() != null) { --- 514,520 ---- * Insert a vertex * @param vertex The vertex * @return The vertex */ ! public Vertex insert(Vertex vertex) { Space space = this; if (vertex.getOwner() != null) { *************** *** 527,558 **** } ! Vertex actual = null; ! { ! Set vertices = ! space.findByLocation (vertex.getX(), vertex.getY(), vertex.getZ(), 0.0000001); ! if (!vertices.isEmpty()) { ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex current = (Vertex) iter.next(); ! if (!current.protect()) { ! actual = current; ! } ! } ! } ! } if (actual == null) { actual = vertex; space.add(actual); ! if (split) { ! Set es = space.findEdge(actual); ! if (es.size() > 0) { ! Iterator iter = es.iterator(); ! while (iter.hasNext()) { ! Edge e = (Edge) iter.next(); ! if (!e.getStrippled() && !e.protect()) { ! e.split(actual); ! } ! } } } --- 526,540 ---- } ! Vertex actual = space.findVertex(vertex); if (actual == null) { actual = vertex; space.add(actual); ! Set es = space.findEdge(actual); ! if (es.size() > 0) { ! Iterator iter = es.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! current.split(actual); } } *************** *** 636,674 **** * Insert a edge * @param edge The edge - * @param split Split edges * @return The edge */ ! public Edge insert(Edge edge, boolean split) { ! Space space = this; ! ! Edge actual = edge; if (edge.getLength() == 0) { return null; } ! Vertex from = space.insert(edge.getFrom(), split); ! Vertex to = space.insert(edge.getTo(), split); edge.setFrom(from); edge.setTo(to); ! { ! Collection edges = space.getEdges(); ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! if (!current.protect()) { ! if (current.getFrom() == edge.getFrom() && current.getTo() == edge.getTo()) { ! actual = current; ! break; ! } ! if (current.getFrom() == edge.getTo() && current.getTo() == edge.getFrom()) { ! actual = current; ! break; ! } ! } ! } ! } ! if (actual == edge) { ! space.add(edge); } - return actual; } --- 618,641 ---- * Insert a edge * @param edge The edge * @return The edge */ ! public Edge insert(Edge edge) { if (edge.getLength() == 0) { return null; } ! ! Vertex from = insert(edge.getFrom()); ! Vertex to = insert(edge.getTo()); edge.setFrom(from); edge.setTo(to); ! ! Edge existing = findEdge(edge); ! ! if (existing != null) { ! return existing; ! } else { ! add(edge); ! return edge; } } *************** *** 889,944 **** * Insert a surface * @param surface The surface - * @param split Allow splits * @return The surface */ ! public Surface insert(Surface surface, boolean split) { List edges = surface.getEdges(); - - Collection vertices = this.getVertices(); - { - Iterator iter = vertices.iterator(); - while (iter.hasNext()) { - Vertex current = (Vertex) iter.next(); - Collection es = Edge.findEdge(edges, current); - Iterator esit = es.iterator(); - while (esit.hasNext()) { - Edge edge = (Edge) esit.next(); - System.out.println("split " + edge + " by " + current); - Collection rep = edge.split(current); - Iterator i = rep.iterator(); - Edge e1 = (Edge) i.next(); - Edge e2 = (Edge) i.next(); - System.out.println("replace " + edge + " with " + e1 + " and " + e2); - surface.replace(edge, e1, e2); - } - } - } edges = surface.getEdges(); ! List actual = new LinkedList(); { Iterator iter = edges.iterator(); while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! actual.add(insert(current, split)); } } ! Surface shadow = surface; ! { ! Collection surfaces = getSurfaces(); ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! Set others = new HashSet(current.getEdges()); ! if (others.containsAll(actual)) { ! shadow = current; ! } ! } ! } ! if (shadow == surface) { ! surface.setEdges(actual); add(surface); Geometry.holeAnalysis(surface); } else { ! Vertex n1 = shadow.normal(); Vertex n2 = surface.normal(); double dot = n1.dot(n2); --- 856,882 ---- * Insert a surface * @param surface The surface * @return The surface */ ! public Surface insert(Surface surface) { List edges = surface.getEdges(); edges = surface.getEdges(); ! List lst = new LinkedList(); { Iterator iter = edges.iterator(); while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! lst.add(insert(current)); } } ! surface.setEdges(lst); ! ! Surface existing = findSurface(surface); ! ! if (existing == null) { add(surface); Geometry.holeAnalysis(surface); + existing = surface; } else { ! Vertex n1 = existing.normal(); Vertex n2 = surface.normal(); double dot = n1.dot(n2); *************** *** 953,965 **** } if (front != null) { ! shadow.setFrontDomain(front); } if (back != null) { ! shadow.setBackDomain(back); } surface.setFrontDomain(null); surface.setBackDomain(null); } ! return shadow; } --- 891,903 ---- } if (front != null) { ! existing.setFrontDomain(front); } if (back != null) { ! existing.setBackDomain(back); } surface.setFrontDomain(null); surface.setBackDomain(null); } ! return existing; } *************** *** 1121,1124 **** --- 1059,1092 ---- /** + * Find vertex that coincides with the vertex + * @param vertex Vertex + * @return vertex that concides + */ + public Vertex findVertex(Vertex vertex) { + Collection vertices = getVertices(); + return Vertex.findVertex(vertices, vertex); + } + + /** + * Find surface that coincides with the given surface + * @param surface Surface + * @return equivalent surface + */ + public Surface findSurface(Surface surface) { + Collection surfaces = getSurfaces(); + return Surface.findSurface(surfaces, surface); + } + + /** + * Find equivalent edge + * @param edge Edge + * @return equivalent edge + */ + public Edge findEdge(Edge edge) { + Collection edges = getEdges(); + return Edge.findEdge(edges, edge); + } + + /** * Get the modellor * @return The modellor Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** Vertex.java 5 Oct 2006 11:27:04 -0000 1.47 --- Vertex.java 19 Oct 2006 09:56:21 -0000 1.48 *************** *** 41,44 **** --- 41,63 ---- /** + * Find vertex that coincides with the vertex + * @param vertices Collection + * @param vertex Vertex + * @return set of vertices + */ + public static Vertex findVertex(Collection vertices, Vertex vertex) { + Iterator iter = vertices.iterator(); + while (iter.hasNext()) { + Vertex current = (Vertex) iter.next(); + if (!current.protect()) { + if (current.coincides(vertex)) { + return current; + } + } + } + return null; + } + + /** * Constructor for persistence layer */ Index: Geometry.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Geometry.java 9 Oct 2006 14:03:15 -0000 1.32 --- Geometry.java 19 Oct 2006 09:56:21 -0000 1.33 *************** *** 769,773 **** while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! Edge edge = space.insert(current, false); if (edge != null) { actual.add(edge); --- 769,773 ---- while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! Edge edge = space.insert(current); if (edge != null) { actual.add(edge); *************** *** 785,789 **** while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! Edge edge = space.insert(current, true); if (edge != null) { actual.add(edge); --- 785,789 ---- while (iter.hasNext()) { Edge current = (Edge) iter.next(); ! Edge edge = space.insert(current); if (edge != null) { actual.add(edge); |