Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.64, 1.65 ClippingPlane.
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-11-07 10:51:26
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31928/src/net/sourceforge/bprocessor/model Modified Files: Edge.java ClippingPlane.java Camera.java Plane.java Log Message: changes to clippingplane tool and visualization Index: ClippingPlane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClippingPlane.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ClippingPlane.java 30 Oct 2006 10:42:17 -0000 1.12 --- ClippingPlane.java 7 Nov 2006 10:51:24 -0000 1.13 *************** *** 8,11 **** --- 8,12 ---- import java.util.Collection; + import java.util.HashMap; import java.util.Iterator; import java.util.ArrayList; *************** *** 19,23 **** * The Clippingplane */ ! public class ClippingPlane extends Geometric implements Parametric { /** * --- 20,24 ---- * The Clippingplane */ ! public class ClippingPlane extends Geometric implements Parametric, Observer { /** * *************** *** 39,42 **** --- 40,46 ---- /** The silluet */ private ArrayList silluet; + + /** The edge map */ + private HashMap toModel; /** The plane of the clipingplane */ *************** *** 46,54 **** private boolean isActive; ! /** The depth of the cut, if 0 the cut is infinit */ ! private double clipdepth = 0; ! ! /** The joined clippingplane */ ! private ClippingPlane friend; /** --- 50,55 ---- private boolean isActive; ! /** To make a visual slice */ ! private boolean slice = false; /** *************** *** 62,65 **** --- 63,68 ---- this.silluet = new ArrayList(); this.corners = new ArrayList(); + this.toModel = new HashMap(); + Project.getInstance().addObserver(this); update(); } *************** *** 71,75 **** public Plane getPlane() { if (plane == null) { ! plane = cs.plane(); } return plane; --- 74,83 ---- public Plane getPlane() { if (plane == null) { ! CoordinateSystem c = cs.copy(); ! Vertex n = c.getN().copy(); ! n.normalize(); ! n.scale(0.01); ! c.move(n.getX(), n.getY(), n.getZ()); ! plane = c.plane(); } return plane; *************** *** 137,143 **** Camera c = Project.getInstance().getCurrentCamera(); c.removeClipplane(this); - if (friend != null) { - c.removeClipplane(friend); - } } --- 145,148 ---- *************** *** 167,178 **** */ public Collection findIntersections() { Space space = Project.getInstance().getActiveSpace(); Collection edges = Geometry.getActiveEdges(space); ! ArrayList silluet = new ArrayList(); Collection res = new ArrayList(); Iterator it = edges.iterator(); while (it.hasNext()) { Edge e = (Edge)it.next(); ! Vertex v = getPlane().intersection(e); if (v != null) { res.add(v); --- 172,185 ---- */ public Collection findIntersections() { + toModel.clear(); Space space = Project.getInstance().getActiveSpace(); Collection edges = Geometry.getActiveEdges(space); ! silluet.clear(); Collection res = new ArrayList(); + Plane plan = cs.plane(); Iterator it = edges.iterator(); while (it.hasNext()) { Edge e = (Edge)it.next(); ! Vertex v = plan.intersection(e); if (v != null) { res.add(v); *************** *** 180,189 **** Vertex transTo = cs.translate(e.getTo()); Vertex transFrom = cs.translate(e.getFrom()); ! if (Math.abs(transTo.getZ()) < 0.01 && ! Math.abs(transFrom.getZ()) < 0.01) { res.add(e.getTo().copy()); res.add(e.getFrom().copy()); Edge eCopy = e.copy(); ! eCopy.setStrippled(true); silluet.add(eCopy); } --- 187,198 ---- Vertex transTo = cs.translate(e.getTo()); Vertex transFrom = cs.translate(e.getFrom()); ! if (Math.abs(transTo.getZ()) < 0.00001 && ! Math.abs(transFrom.getZ()) < 0.00001) { res.add(e.getTo().copy()); res.add(e.getFrom().copy()); Edge eCopy = e.copy(); ! // edges should be solid ! eCopy.setStrippled(false); ! toModel.put(eCopy, e); silluet.add(eCopy); } *************** *** 198,202 **** while (iter.hasNext()) { Edge e = (Edge)iter.next(); ! Vertex v = getPlane().intersection(e); if (v != null) { if (first == null) { --- 207,211 ---- while (iter.hasNext()) { Edge e = (Edge)iter.next(); ! Vertex v = plan.intersection(e); if (v != null) { if (first == null) { *************** *** 207,210 **** --- 216,220 ---- first = null; silluet.add(newE); + toModel.put(newE, newE); break; } *************** *** 212,218 **** } } - if (silluet.size() > 0) { - this.silluet = silluet; - } return res; } --- 222,225 ---- *************** *** 291,297 **** public void setActive(boolean isActive) { this.isActive = isActive; - if (friend != null) { - friend.isActive = isActive; - } } --- 298,301 ---- *************** *** 299,305 **** public void move(double x, double y, double z) { center().move(x, y, z); ! if (friend != null) { ! friend.center().move(x, y, z); ! } } --- 303,307 ---- public void move(double x, double y, double z) { center().move(x, y, z); ! update(); } *************** *** 313,319 **** */ public List getAttributes() { - if (friend != null && clipdepth == 0) { - return friend.getAttributes(); - } ArrayList res = new ArrayList(); if (isActive()) { --- 315,318 ---- *************** *** 322,327 **** res.add(new Attribute("isActive", Boolean.FALSE)); } ! res.add(new Attribute("Clip depth", new Double(clipdepth))); ! res.add(new Attribute("Friend", friend, false)); return res; } --- 321,330 ---- res.add(new Attribute("isActive", Boolean.FALSE)); } ! if (isSlice()) { ! res.add(new Attribute("isSlice", Boolean.TRUE)); ! } else { ! res.add(new Attribute("isSlice", Boolean.FALSE)); ! } ! res.add(new Attribute("Flip", Boolean.FALSE)); return res; } *************** *** 339,345 **** */ public void setAttributes(List attributes) { - if (friend != null && clipdepth == 0) { - friend.setAttributes(attributes); - } Iterator iter = attributes.iterator(); while (iter.hasNext()) { --- 342,345 ---- *************** *** 347,392 **** if (a.getName().equals("isActive")) { setActive(((Boolean)a.getValue()).booleanValue()); ! } else if (a.getName().equals("Clip depth")) { ! setClipdepth(((Double)a.getValue()).doubleValue()); } else { log.warn("Don't know attribute " + a.getName()); } } } /** ! * Return the clipdepth ! * @return the clipdepth */ ! public double getClipdepth() { ! return clipdepth; } /** ! * Setter for the clipdepth ! * @param clipdepth the new clipdepth */ ! public void setClipdepth(double clipdepth) { ! this.clipdepth = Math.abs(clipdepth); ! if (clipdepth != 0) { ! if (friend != null) { ! Project.getInstance().getCurrentCamera().removeClipplane(friend); ! } ! //make a new friend ! CoordinateSystem newcs = cs.copy(); ! newcs.flip(); ! Vertex move = newcs.n.copy(); ! move.scale(-clipdepth); ! newcs.move(move.getX(), move.getY(), move.getZ()); ! ClippingPlane cp = new ClippingPlane(newcs); ! Project.getInstance().getCurrentCamera().addClipplane(cp); ! cp.friend = this; ! this.friend = cp; ! } else { ! if (friend != null) { ! Project.getInstance().getCurrentCamera().removeClipplane(friend); } - friend = null; } } } --- 347,398 ---- if (a.getName().equals("isActive")) { setActive(((Boolean)a.getValue()).booleanValue()); ! } else if (a.getName().equals("isSlice")) { ! setSlice(((Boolean)a.getValue()).booleanValue()); ! } else if (a.getName().equals("Flip")) { ! if ((Boolean)a.getValue() == Boolean.TRUE) { ! cs.flip(); ! } } else { log.warn("Don't know attribute " + a.getName()); } } + update(); } /** ! * @return Returns the slice. */ ! public boolean isSlice() { ! return slice; } /** ! * @param slice The slice to set. */ ! public void setSlice(boolean slice) { ! this.slice = slice; ! } ! ! /** ! * Find the edge or surface the given edge corrospond to in the model ! * @param e the Edge in the conture ! * @return The geometry in the model or null if none ! */ ! public Geometric toModel(Edge e) { ! if (toModel != null) { ! Object o = toModel.get(e); ! if (o != null) { ! return (Geometric)o; } } + return null; + } + + /** + * Update + * @param entity Changed entity + */ + public void update(Object entity) { + update(); } } Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** Edge.java 2 Nov 2006 14:45:38 -0000 1.64 --- Edge.java 7 Nov 2006 10:51:24 -0000 1.65 *************** *** 310,314 **** */ public Edge intersection(Edge other) { ! Vertex p1 = this.getFrom(); Vertex p2 = this.getTo(); --- 310,325 ---- */ public Edge intersection(Edge other) { ! if (this.getLength() < 0.0000001) { ! if (other.getLength() < 0.0000001) { ! return new Edge(this.getFrom(), other.getFrom()); ! } else { ! //have to find the sortest edge from this (point) to other (edge) ! //by use of projection ! Vertex v1 = other.getDirection(); ! Vertex v2 = new Edge(other.getFrom(), this.getFrom()).getDirection(); ! Vertex proj = v2.projectOnto(v1); ! return new Edge(other.getFrom().add(proj), this.getFrom()); ! } ! } Vertex p1 = this.getFrom(); Vertex p2 = this.getTo(); Index: Camera.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Camera.java 31 Oct 2006 14:22:51 -0000 1.25 --- Camera.java 7 Nov 2006 10:51:24 -0000 1.26 *************** *** 16,19 **** --- 16,21 ---- import org.apache.log4j.Logger; + import net.java.games.jogl.GL; + /** * Camera for view placement in the model have a center and at camera position *************** *** 564,571 **** */ public void addClipplane(ClippingPlane cp) { ! clipplanes.add(cp); ! int num = clipplanes.indexOf(cp); ! log.info("Got number " + num); ! cp.setNumber(num); } --- 566,574 ---- */ public void addClipplane(ClippingPlane cp) { ! if (clipplanes.size() < GL.GL_MAX_CLIP_PLANES - 1) { ! clipplanes.add(cp); ! int num = clipplanes.indexOf(cp); ! cp.setNumber(num); ! } } *************** *** 577,579 **** --- 580,626 ---- clipplanes.remove(cp); } + + /** + * Static modification of the camera to point down on the current center + * @param currentCamera The camera to change + */ + public static void makeTop(Camera currentCamera) { + double[] center = currentCamera.getCenter(); + double dist = currentCamera.dist(); + currentCamera.camera = new double[]{center[0], center[1], center[2] + dist}; + currentCamera.roll = new double[]{0, 1, 0}; + } + + /** + * Static modification of the camera + * @param currentCamera The camera to change + */ + public static void makeButtom(Camera currentCamera) { + double[] center = currentCamera.getCenter(); + double dist = currentCamera.dist(); + currentCamera.camera = new double[]{center[0], center[1], center[2] - dist}; + currentCamera.roll = new double[]{0, 1, 0}; + } + + /** + * Static modification of the camera + * @param currentCamera The camera to change + */ + public static void makeLeft(Camera currentCamera) { + double[] center = currentCamera.getCenter(); + double dist = currentCamera.dist(); + currentCamera.camera = new double[]{center[0], center[1] - dist, center[2]}; + currentCamera.roll = new double[]{0, 0, 1}; + } + + /** + * Static modification of the camera + * @param currentCamera The camera to change + */ + public static void makeRight(Camera currentCamera) { + double[] center = currentCamera.getCenter(); + double dist = currentCamera.dist(); + currentCamera.camera = new double[]{center[0], center[1] + dist, center[2]}; + currentCamera.roll = new double[]{0, 0, 1}; + } } Index: Plane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Plane.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Plane.java 21 Aug 2006 20:32:17 -0000 1.25 --- Plane.java 7 Nov 2006 10:51:24 -0000 1.26 *************** *** 189,193 **** double v0 = -(a * x0 + b * y0 + c * z0 + d); double t = v0 / vd; ! if (!endless && (t < -0.001 || t > 1.001)) { return null; } --- 189,193 ---- double v0 = -(a * x0 + b * y0 + c * z0 + d); double t = v0 / vd; ! if (!endless && (t < 0.001 || t > 1.001)) { return null; } |