[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model ClippingPlane.java, NONE, 1.1 Camera
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-06-06 09:22:34
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21509/src/net/sourceforge/bprocessor/model Modified Files: Camera.java Added Files: ClippingPlane.java Log Message: Refactored clippingplanes to the model (still needs to do xml saving along with camera as well as display them on the attribute view) and changed the storing of clipping planes to the camera instead of View... Index: Camera.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Camera.java 23 May 2006 16:48:28 -0000 1.15 --- Camera.java 6 Jun 2006 09:22:31 -0000 1.16 *************** *** 8,11 **** --- 8,12 ---- import java.util.ArrayList; + import java.util.Collection; import java.util.Iterator; import java.util.List; *************** *** 55,58 **** --- 56,62 ---- private int type; + /** The list of clipplanes to this camera*/ + private ArrayList clipplanes; + /** * The constructor for the persistence layer *************** *** 75,78 **** --- 79,83 ---- this.roll = roll; this.focalwidth = 65; + this.clipplanes = new ArrayList(); if (type == ORTHOGRAPHIC || type == PERSPECTIVE) { this.type = type; *************** *** 503,505 **** --- 508,537 ---- return "Camera"; } + + /** + * Getter for the list of clippingplanes + * @return the list of clippingplanes + */ + public Collection getClipplanes() { + return clipplanes; + } + + /** + * Adds a clippingplane to the list of clippingplanes + * @param cp the clippingplane to add + */ + public void addClipplane(ClippingPlane cp) { + clipplanes.add(cp); + int num = clipplanes.indexOf(cp); + log.info("Got number " + num); + cp.setNumber(num); + } + + /** + * Remove the given clippingplane from the list of clippingplanes + * @param cp The clippingplane to remove + */ + public void removeClipplane(ClippingPlane cp) { + clipplanes.remove(cp); + } } --- NEW FILE: ClippingPlane.java --- //--------------------------------------------------------------------------------- // $Id: ClippingPlane.java,v 1.1 2006/06/06 09:22:31 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.Collection; import java.util.Iterator; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import org.apache.log4j.Logger; /** * The Clippingplane */ public class ClippingPlane extends Geometric { /** The logger */ private static Logger log = Logger.getLogger(ClippingPlane.class); /** The number clipping plane in the GL this one represents*/ private int number; /** The placement of the clippingplane */ private Plane plane; /** The coordinate sytem of the clipping plane */ private CoordinateSystem system; /** The corners */ private ArrayList corners; /** The silluet */ private ArrayList silluet; /** * The constructor * @param system The coordinatesystem the clippingplane is represented by */ public ClippingPlane(CoordinateSystem system) { this.system = system; update(); } /** * Getter for plan representing the clippingplane * @return The plane */ public Plane getPlane() { return plane; } /** * Getter for the origin * @return The origin */ public Vertex origin() { Vertex origin = origin = system.origin(); // FIXME Interning the origin to give it an ID.. // It needs an ID to be in a hashtable, but this // means that the origin point will be drawn an // clickable etc. if (origin.getId() == null) { //Project.getInstance().intern(origin); } return origin; } /** * gets the center * @return center */ public Vertex center() { return origin(); } /** * Update this clipping from the defining coordinatesystem attribute * */ public void update() { plane = system.plane(); findCorners(); } /** * Set the number clipping plane this plane represents in the GL * @param number The clipping plane number */ public void setNumber(int number) { this.number = number; } /** * Getter for the number attribute that represents the number * of the corrosponding clippingplane in GL * @return The number */ public int getNumber() { return number; } /** * Find intersections with all edges and return the vertices * @return The set of all intersection vertices */ public Collection findIntersections() { Collection edges = Project.getInstance().getEdges(); silluet = new ArrayList(); Collection res = new ArrayList(); Iterator it = edges.iterator(); while (it.hasNext()) { Edge e = (Edge)it.next(); Vertex v = plane.intersection(e); if (v != null) { res.add(v); } } Collection surfaces = Project.getInstance().getSurfaces(); it = surfaces.iterator(); while (it.hasNext()) { Surface s = (Surface)it.next(); Collection lines = s.getEdges(); Iterator iter = lines.iterator(); Vertex first = null; while (iter.hasNext()) { Edge e = (Edge)iter.next(); Vertex v = plane.intersection(e); if (v != null) { if (first == null) { first = v; } else { Edge newE = new Edge(first, v); newE.setConstructor(true); first = null; silluet.add(newE); break; } } } } return res; } /** * Find the 4 corners among intersections */ public void findCorners() { Collection c = findIntersections(); if (c.isEmpty()) { if (!corners.isEmpty()) { Vertex v1 = system.translate((Vertex)corners.get(0)); v1.setZ(0); Vertex v2 = system.translate((Vertex)corners.get(1)); v2.setZ(0); Vertex v3 = system.translate((Vertex)corners.get(2)); v3.setZ(0); Vertex v4 = system.translate((Vertex)corners.get(3)); v4.setZ(0); corners = new ArrayList(); corners.add(system.unTranslate(v1)); corners.add(system.unTranslate(v2)); corners.add(system.unTranslate(v3)); corners.add(system.unTranslate(v4)); } } else { Iterator it = c.iterator(); double minX = Integer.MAX_VALUE; double minY = Integer.MAX_VALUE; double maxX = Integer.MIN_VALUE; double maxY = Integer.MIN_VALUE; while (it.hasNext()) { Vertex v = (Vertex)it.next(); v = system.translate(v); if (v.getX() < minX) { minX = v.getX(); } if (v.getX() > maxX) { maxX = v.getX(); } if (v.getY() < minY) { minY = v.getY(); } if (v.getY() > maxY) { maxY = v.getY(); } } Vertex v1 = new Vertex(minX - 1, minY - 1, 0.0); Vertex v2 = new Vertex(minX - 1, maxY + 1, 0.0); Vertex v3 = new Vertex(maxX + 1, maxY + 1, 0.0); Vertex v4 = new Vertex(maxX + 1, minY - 1, 0.0); v1 = system.unTranslate(v1); v2 = system.unTranslate(v2); v3 = system.unTranslate(v3); v4 = system.unTranslate(v4); corners = new ArrayList(); corners.add(v1); corners.add(v2); corners.add(v3); corners.add(v4); } } /** * Getter for corners * @return The corners */ public Collection getCorners() { return corners; } /** * collects the vertices for this clipplane * @return the set of vertices */ public Set collect() { Set result = new HashSet(); result.add(origin()); return result; } /** * FIXME: empty implementation to make compile * (pfff make sure stuff compiles before you check in please) */ public void delete() { return; } /** * Makes a string representation of the clippingplane * @return The string representing til object */ public String toString() { double[] p = plane.getDoublev(); return "[" + p[0] + ", " + p[1] + ", " + p[2] + ", " + p[3] + "]"; } /** * Gettter for the intersected geometry * @return The intersection edges */ public Collection getLines() { return silluet; } } |