[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java,1.30,1.31 Vertex.java,1.22,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-02-03 13:01:58
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10169/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Vertex.java Surface.java Mesh.java Plane.java Log Message: Deleting an edge will combine adjacent coplanar surfaces Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** Surface.java 2 Feb 2006 14:18:35 -0000 1.71 --- Surface.java 3 Feb 2006 13:01:49 -0000 1.72 *************** *** 164,184 **** public Vertex getFirstVertex() { List edges = getEdges(); ! if (edges.size() == 0) { ! return null; ! } else if (edges.size() == 1) { ! Edge e0 = (Edge) edges.get(0); ! return e0.getFrom(); ! } else { ! Edge e0 = (Edge) edges.get(0); ! Edge e1 = (Edge) edges.get(1); ! Vertex current = null; ! if (!e1.contains(e0.getFrom())) { ! return e0.getFrom(); ! } ! if (!e1.contains(e0.getTo())) { ! return e0.getTo(); ! } ! } ! return null; } --- 164,168 ---- public Vertex getFirstVertex() { List edges = getEdges(); ! return Edge.first(edges); } Index: Mesh.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Mesh.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Mesh.java 2 Feb 2006 10:53:44 -0000 1.8 --- Mesh.java 3 Feb 2006 13:01:49 -0000 1.9 *************** *** 9,12 **** --- 9,13 ---- import java.util.Collection; + import java.util.Collections; import java.util.HashMap; import java.util.Iterator; *************** *** 168,171 **** --- 169,179 ---- { + // Find adjacent surfaces that must be combined to one surface. + // + // First the adjacent surfaces are partioned into groups of + // coplanar surfaces. + // If there is only one group consisting of two coplanar surfaces + // these two surfaces are combined. + List partions = new LinkedList(); List work = new LinkedList(surfaces); *************** *** 173,179 **** Iterator iter = work.iterator(); Surface first = (Surface) iter.next(); ! CoordinateSystem system = first.coordinateSystem(); List partion = new LinkedList(); ! } } --- 181,260 ---- Iterator iter = work.iterator(); Surface first = (Surface) iter.next(); ! iter.remove(); ! Plane plane = first.plane(); List partion = new LinkedList(); ! partion.add(first); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! if (plane.contains(current)) { ! partion.add(current); ! iter.remove(); ! } ! } ! partions.add(partion); ! } ! int count = 0; ! List partion = null; ! { ! Iterator iter = partions.iterator(); ! while (iter.hasNext()) { ! List current = (List) iter.next(); ! if (current.size() == 2) { ! count++; ! partion = current; ! } ! } ! } ! if (count == 1) { ! Surface s1 = (Surface) partion.get(0); ! Surface s2 = (Surface) partion.get(1); ! List edges1 = new LinkedList(); ! List edges2 = new LinkedList(); ! { ! boolean gab = false; ! List prefix = new LinkedList(); ! Iterator iter = s1.getEdges().iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! if (!s2.contains(current)) { ! if (!gab) { ! prefix.add(current); ! } else { ! edges1.add(current); ! } ! } else { ! gab = true; ! } ! } ! edges1.addAll(prefix); ! } ! { ! boolean gab = false; ! List prefix = new LinkedList(); ! Iterator iter = s2.getEdges().iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! if (!s1.contains(current)) { ! if (!gab) { ! prefix.add(current); ! } else { ! edges2.add(current); ! } ! } else { ! gab = true; ! } ! } ! edges2.addAll(prefix); ! } ! if (Edge.first(edges1) == Edge.first(edges2)) { ! Collections.reverse(edges2); ! } ! edges1.addAll(edges2); ! Surface surface = new Surface(edges1); ! add(surface); ! if (s1.getExterior() != null) { ! s1.getExterior().addHole(surface); ! // FIXME: Assign spaces ! } } } Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Vertex.java 1 Feb 2006 11:45:25 -0000 1.22 --- Vertex.java 3 Feb 2006 13:01:49 -0000 1.23 *************** *** 218,222 **** */ public double dot(Vertex v) { ! return this.getX() * v.getX() + this.getY() * v.getY() + this.getZ() * v.getZ(); } --- 218,222 ---- */ public double dot(Vertex v) { ! return x * v.x + y * v.y + z * v.z; } Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Edge.java 1 Feb 2006 11:45:25 -0000 1.30 --- Edge.java 3 Feb 2006 13:01:49 -0000 1.31 *************** *** 12,15 **** --- 12,16 ---- import java.util.HashSet; import java.util.Iterator; + import java.util.List; import java.util.Set; *************** *** 34,37 **** --- 35,65 ---- /** Constructor */ private boolean constructor; + + /** + * Return the first vertex in a list of edges. + * The first vertex is defined as the a vertex + * in the first edge that are not shared with the + * second edge + * @param edges The list edges + * @return The first vertex + */ + public static Vertex first(List edges) { + if (edges.size() == 0) { + return null; + } else if (edges.size() == 1) { + Edge e0 = (Edge) edges.get(0); + return e0.getFrom(); + } else { + Edge e0 = (Edge) edges.get(0); + Edge e1 = (Edge) edges.get(1); + if (!e1.contains(e0.getFrom())) { + return e0.getFrom(); + } + if (!e1.contains(e0.getTo())) { + return e0.getTo(); + } + } + return null; + } /** Index: Plane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Plane.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Plane.java 13 Jan 2006 15:59:31 -0000 1.13 --- Plane.java 3 Feb 2006 13:01:49 -0000 1.14 *************** *** 7,10 **** --- 7,13 ---- package net.sourceforge.bprocessor.model; + import java.util.Collection; + import java.util.Iterator; + import org.apache.log4j.Logger; *************** *** 66,69 **** --- 69,116 ---- /** + * Distance from vertex to this plane + * @param vertex The vertex + * @return The distance + */ + public double distance(Vertex vertex) { + return (a * vertex.getX() + b * vertex.getY() + c * vertex.getZ() + d); + } + + /** + * Test if the vertex lies in this plane + * @param vertex The vertex + * @return True if the vertex lies in this plane + */ + public boolean contains(Vertex vertex) { + return Math.abs(distance(vertex)) < 0.0000001; + } + + /** + * Test if edge lies in this plane + * @param edge The edge + * @return True if edge lies in this plane + */ + public boolean contains(Edge edge) { + return contains(edge.getFrom()) && contains(edge.getTo()); + } + + /** + * Test if surface lies in this plane + * @param surface The surface + * @return True if surface lies in this plane + */ + public boolean contains(Surface surface) { + Collection vertices = surface.getVertices(); + Iterator iter = vertices.iterator(); + while (iter.hasNext()) { + Vertex current = (Vertex) iter.next(); + if (!contains(current)) { + return false; + } + } + return true; + } + + /** * Find the orthogonal plane to this plane * @param rayIn the ray into the view |