[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model ClippingPlane.java, 1.11, 1.12 Geome
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-10-30 10:42:21
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28353/src/net/sourceforge/bprocessor/model Modified Files: ClippingPlane.java Geometry.java CoordinateSystem.java Log Message: Made some modifications to ClippingPlane, made them parametric to watch them in the object view, and added new methods to it, so that it can represent a slice. Still need lots of work Index: ClippingPlane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClippingPlane.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ClippingPlane.java 5 Oct 2006 11:27:04 -0000 1.11 --- ClippingPlane.java 30 Oct 2006 10:42:17 -0000 1.12 *************** *** 10,13 **** --- 10,14 ---- import java.util.Iterator; import java.util.ArrayList; + import java.util.List; import java.util.Set; import java.util.HashSet; *************** *** 18,22 **** * The Clippingplane */ ! public class ClippingPlane extends Geometric { /** * --- 19,23 ---- * The Clippingplane */ ! public class ClippingPlane extends Geometric implements Parametric { /** * *************** *** 45,48 **** --- 46,55 ---- private boolean isActive; + /** The depth of the cut, if 0 the cut is infinit */ + private double clipdepth = 0; + + /** The joined clippingplane */ + private ClippingPlane friend; + /** * The constructor *************** *** 128,145 **** */ public void delete() { ! Iterator it = Project.getInstance().getCameras().iterator(); ! while (it.hasNext()) { ! Camera cam = (Camera)it.next(); ! Iterator clipIt = cam.getClipplanes().iterator(); ! while (clipIt.hasNext()) { ! ClippingPlane clip = (ClippingPlane)clipIt.next(); ! if (clip == this) { ! cam.removeClipplane(this); ! Project.getInstance().changed(cam); ! break; ! } ! } } - return; } --- 135,143 ---- */ public void delete() { ! Camera c = Project.getInstance().getCurrentCamera(); ! c.removeClipplane(this); ! if (friend != null) { ! c.removeClipplane(friend); } } *************** *** 169,173 **** */ public Collection findIntersections() { ! Collection edges = Project.getInstance().getActiveSpace().getEdges(); ArrayList silluet = new ArrayList(); Collection res = new ArrayList(); --- 167,172 ---- */ public Collection findIntersections() { ! Space space = Project.getInstance().getActiveSpace(); ! Collection edges = Geometry.getActiveEdges(space); ArrayList silluet = new ArrayList(); Collection res = new ArrayList(); *************** *** 190,194 **** } } ! Collection surfaces = Project.getInstance().getActiveSpace().getSurfaces(); it = surfaces.iterator(); while (it.hasNext()) { --- 189,193 ---- } } ! Collection surfaces = Geometry.getActiveSurfaces(space); it = surfaces.iterator(); while (it.hasNext()) { *************** *** 292,295 **** --- 291,297 ---- public void setActive(boolean isActive) { this.isActive = isActive; + if (friend != null) { + friend.isActive = isActive; + } } *************** *** 297,300 **** --- 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,305 **** --- 308,392 ---- return new Vertex(x, y, z).projectOnto(plane.normal()); } + + /** + * @see net.sourceforge.bprocessor.model.Parametric#getAttributes() + */ + public List getAttributes() { + if (friend != null && clipdepth == 0) { + return friend.getAttributes(); + } + ArrayList res = new ArrayList(); + if (isActive()) { + res.add(new Attribute("isActive", Boolean.TRUE)); + } else { + 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; + } + + /** + * @see net.sourceforge.bprocessor.model.Parametric#getGeneralName() + */ + public String getGeneralName() { + String s = "Clippingplane"; + return s; + } + + /** + * @see net.sourceforge.bprocessor.model.Parametric#setAttributes(List) + */ + public void setAttributes(List attributes) { + if (friend != null && clipdepth == 0) { + friend.setAttributes(attributes); + } + Iterator iter = attributes.iterator(); + while (iter.hasNext()) { + Attribute a = (Attribute)iter.next(); + 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; + } + } } Index: Geometry.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Geometry.java 19 Oct 2006 15:28:51 -0000 1.34 --- Geometry.java 30 Oct 2006 10:42:17 -0000 1.35 *************** *** 28,31 **** --- 28,92 ---- /** + * Find all edges in given space and all its subspaces that are active parts, + * that is all edges in spaces that have no subspaces. + * @param s The space to start from + * @return The collection of edges + */ + public static Collection getActiveEdges(Space s) { + if (s.getElements().isEmpty()) { + Collection c = s.getEdges(); + if (c.isEmpty()) { + Collection e = new ArrayList(); + Iterator iter = s.getEnvelope().iterator(); + while (iter.hasNext()) { + e.addAll(((Surface)iter.next()).getEdges()); + } + return e; + } + return c; + } else { + ArrayList edges = new ArrayList(); + Iterator iter = s.getElements().iterator(); + while (iter.hasNext()) { + Space cur = (Space)iter.next(); + Collection c = getActiveEdges(cur); + edges.addAll(c); + } + return edges; + } + } + + /** + * Find all surfaces in given space and all its subspaces that are active parts, + * that is all surfaces in spaces that have no subspaces. + * @param s The space to start from + * @return The collection of surfaces + */ + public static Collection getActiveSurfaces(Space s) { + if (s.getElements().isEmpty()) { + Collection c = s.getSurfaces(); + if (c.isEmpty()) { + return s.getEnvelope(); + } else { + return c; + } + } else { + ArrayList surfaces = new ArrayList(); + Iterator iter = s.getElements().iterator(); + while (iter.hasNext()) { + try { + Space cur = (Space)iter.next(); + surfaces.addAll(getActiveSurfaces(cur)); + } catch (ClassCastException e) { + log.info("Elements in " + s + " were not only spaces"); + e.printStackTrace(); + break; + } + } + return surfaces; + } + } + + /** * Calculate the normal that points outwards * @param vertices The vertices describing a planar polygon Index: CoordinateSystem.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/CoordinateSystem.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** CoordinateSystem.java 17 Oct 2006 12:20:00 -0000 1.29 --- CoordinateSystem.java 30 Oct 2006 10:42:17 -0000 1.30 *************** *** 586,588 **** --- 586,608 ---- } } + + /** + * make a copy of the coordinatsystem + * @return the copy + */ + public CoordinateSystem copy() { + CoordinateSystem n = new CoordinateSystem(); + n.setAttributes(this.getAttributes()); + return n; + } + + /** + * flip the coordinatesystem on its head; + */ + public void flip() { + Vertex tmp = i; + i = j; + j = tmp; + n.scale(-1); + } } |