[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model ClippingPlane.java, 1.32, 1.33
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2008-09-10 22:53:37
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27090/src/net/sourceforge/bprocessor/model Modified Files: ClippingPlane.java Log Message: ClippingPlane improved Index: ClippingPlane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClippingPlane.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** ClippingPlane.java 9 Sep 2008 14:03:09 -0000 1.32 --- ClippingPlane.java 10 Sep 2008 22:53:44 -0000 1.33 *************** *** 8,14 **** --- 8,16 ---- import java.util.Collection; + import java.util.HashMap; import java.util.Iterator; import java.util.ArrayList; import java.util.List; + import java.util.Map; import java.util.Set; import java.util.HashSet; *************** *** 33,37 **** /** The silhouette */ ! private ArrayList<Edge> silhouette; /** The plane of the ClippingPlane */ --- 35,39 ---- /** The silhouette */ ! private Container silhouette; /** The plane of the ClippingPlane */ *************** *** 40,47 **** /** If the ClippingPlane is on or off */ private boolean isActive; ! /** To make a visual slice */ private boolean slice = false; ! /** * The constructor --- 42,49 ---- /** If the ClippingPlane is on or off */ private boolean isActive; ! /** To make a visual slice */ private boolean slice = false; ! /** * The constructor *************** *** 52,60 **** this.isActive = true; this.plane = system.plane(); - this.silhouette = new ArrayList<Edge>(); this.corners = new ArrayList<Vertex>(); Project.getInstance().addObserver(this); } ! /** * Copy the ClippingPlane --- 54,61 ---- this.isActive = true; this.plane = system.plane(); this.corners = new ArrayList<Vertex>(); Project.getInstance().addObserver(this); } ! /** * Copy the ClippingPlane *************** *** 66,70 **** return copy; } ! /** * Getter for plan representing the ClippingPlane --- 67,71 ---- return copy; } ! /** * Getter for plan representing the ClippingPlane *************** *** 77,81 **** return plane; } ! /** * gets the center --- 78,82 ---- return plane; } ! /** * gets the center *************** *** 85,89 **** return system.getOrigin(); } ! /** * gets the normal of the ClippingPlane --- 86,90 ---- return system.getOrigin(); } ! /** * gets the normal of the ClippingPlane *************** *** 93,97 **** return system.getN().copy(); } ! /** * Update this clipping from the defining CoordinateSystem attribute --- 94,98 ---- return system.getN().copy(); } ! /** * Update this clipping from the defining CoordinateSystem attribute *************** *** 99,106 **** public void update() { plane = null; ! computeSilhouette(); findCorners(); } ! /** * Set the number clipping plane this plane represents in the GL --- 100,107 ---- public void update() { plane = null; ! silhouette = null; findCorners(); } ! /** * Set the number clipping plane this plane represents in the GL *************** *** 119,123 **** return number; } ! /** * Getter for corners --- 120,124 ---- return number; } ! /** * Getter for corners *************** *** 130,134 **** return corners; } ! /** * collects the vertices for this ClippingPlane --- 131,135 ---- return corners; } ! /** * collects the vertices for this ClippingPlane *************** *** 140,145 **** return result; } ! ! /** * {@inheritDoc} --- 141,146 ---- return result; } ! ! /** * {@inheritDoc} *************** *** 150,154 **** c.removeClipplane(this); } ! /** * Returns true if surface is contained in this ClippingPlane --- 151,155 ---- c.removeClipplane(this); } ! /** * Returns true if surface is contained in this ClippingPlane *************** *** 160,164 **** return plane.contains(surface); } ! /** * Returns true if edge is contained in this ClippingPlane --- 161,165 ---- return plane.contains(surface); } ! /** * Returns true if edge is contained in this ClippingPlane *************** *** 170,174 **** return plane.contains(edge); } ! /** --- 171,175 ---- return plane.contains(edge); } ! /** *************** *** 186,245 **** */ public Collection<Edge> getLines() { ! return silhouette; } ! ! ! private void computeSilhouette() { ! Container space = Project.getInstance().getActiveSpace(); ! Collection<Edge> edges = Geometry.getActiveEdges(space); ! silhouette.clear(); ! Plane plane = system.plane(); ! for (Edge current : edges) { if (plane.contains(current)) { ! Edge edge = current.copy(); ! edge.setStrippled(false); ! silhouette.add(edge); } } ! Collection<Surface> surfaces = Geometry.getActiveSurfaces(space); ! for (Surface current : surfaces) { Collection<Edge> contour = current.getEdges(); ! Vertex first = null; for (Edge edge : contour) { ! Vertex v = plane.intersection(edge); ! if (v != null) { ! if (first == null) { ! first = v; } else { ! Edge newE = new Edge(first, v); ! newE.setStrippled(true); ! first = null; ! silhouette.add(newE); ! break; } } } } } - - /** ! * Find intersections with all edges and return the vertices ! * (Have side effects) ! * @return The set of all intersection vertices */ ! public Collection<Vertex> findIntersections() { ! return Edge.vertices(silhouette); } ! /** ! * Find the 4 corners among intersections ! * (Have side effects) */ public void findCorners() { ! Collection c = findIntersections(); CoordinateSystem system = getPlane().coordinateSystem(); ! if (c.isEmpty()) { if (!corners.isEmpty()) { Vertex v1 = system.translate((Vertex)corners.get(0)); --- 187,247 ---- */ public Collection<Edge> getLines() { ! return silhouette.getEdges(); } ! ! private Container calculateSilhouette(Mesh input) { ! Container silhouette = new Container("Section", Space.CONSTRUCTION, true); ! Plane plane = getPlane(); ! Map map = new HashMap(); ! Map<Edge, Surface> e2s = new HashMap(); ! for (Edge current : input.edges()) { if (plane.contains(current)) { ! Edge edge = (Edge) current.copy(map); ! silhouette.insert(edge); } } ! for (Surface current : input.surfaces()) { Collection<Edge> contour = current.getEdges(); ! Vertex from = null; for (Edge edge : contour) { ! Vertex vertex = plane.intersection(edge); ! if (vertex != null) { ! if (from != null) { ! Edge line = new Edge(from, vertex); ! line.setStrippled(true); ! line = silhouette.insert(line); ! e2s.put(line, current); ! from = null; } else { ! from = vertex; } } } } + SurfaceAnalysis analysis = new SurfaceAnalysis(); + analysis.surfaceAnalysis(silhouette, plane.coordinateSystem(), silhouette.getEdges()); + return silhouette; } /** ! * Returns the silhouette ! * @return silhouette */ ! public Container getSilhouette() { ! if (silhouette == null) { ! Container space = Project.getInstance().getActiveSpace(); ! Mesh input = space.mesh(); ! silhouette = calculateSilhouette(input); ! } ! return silhouette; } ! /** ! * Find the 4 corners among the silhouette */ public void findCorners() { ! Collection vertices = getSilhouette().getVertices(); CoordinateSystem system = getPlane().coordinateSystem(); ! if (vertices.isEmpty()) { if (!corners.isEmpty()) { Vertex v1 = system.translate((Vertex)corners.get(0)); *************** *** 258,262 **** } } else { ! Iterator it = c.iterator(); double minX = Integer.MAX_VALUE; double minY = Integer.MAX_VALUE; --- 260,264 ---- } } else { ! Iterator it = vertices.iterator(); double minX = Integer.MAX_VALUE; double minY = Integer.MAX_VALUE; *************** *** 337,341 **** return s; } ! /** {@inheritDoc} */ public String title() { --- 339,343 ---- return s; } ! /** {@inheritDoc} */ public String title() { |