Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/model ClippingPlane.java,NONE,1.1 package.h
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-11-01 07:31:27
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18843/src/net/sourceforge/bprocessor/gl/model Added Files: ClippingPlane.java package.html Log Message: initial import --- NEW FILE: package.html --- <body> Defines the package that contains the GL model </body> --- NEW FILE: ClippingPlane.java --- //--------------------------------------------------------------------------------- // $Id: ClippingPlane.java,v 1.1 2005/11/01 07:31:19 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.gl.model; import java.util.Collection; import java.util.Iterator; import java.util.ArrayList; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Project; import org.apache.log4j.Logger; /** * The Clippingplane */ public class ClippingPlane { /** 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 corners */ private ArrayList corners; /** * The constructor * @param plane The plane the clippingplane is represented by */ public ClippingPlane(Plane plane) { this.plane = plane; findCorners(); } /** * Getter for plan representing the clippingplane * @return The plane */ public Plane getPlane() { return plane; } /** * 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(); 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); } } return res; } /** * Find the 4 corners among intersections */ public void findCorners() { log.info(plane); Collection c = findIntersections(); Iterator it = c.iterator(); double minX = Integer.MAX_VALUE; double minY = Integer.MAX_VALUE; double minZ = Integer.MAX_VALUE; double maxX = Integer.MIN_VALUE; double maxY = Integer.MIN_VALUE; double maxZ = Integer.MIN_VALUE; while (it.hasNext()) { Vertex v = (Vertex)it.next(); log.info(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(); } if (v.getZ() < minZ) { minZ = v.getZ(); } if (v.getZ() > maxZ) { maxZ = v.getZ(); } } double[] abcd = plane.getDoublev(); corners = new ArrayList(); if (Math.abs(minX * abcd[0] + minY * abcd[1] + maxZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v1", minX, minY, maxZ)); } if (Math.abs(minX * abcd[0] + maxY * abcd[1] + maxZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v2", minX, maxY, maxZ)); } if (Math.abs(minX * abcd[0] + minY * abcd[1] + minZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v3", minX, minY, minZ)); } if (Math.abs(minX * abcd[0] + maxY * abcd[1] + minZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v4", minX, maxY, minZ)); } if (Math.abs(maxX * abcd[0] + minY * abcd[1] + minZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v7", maxX, minY, minZ)); } if (Math.abs(maxX * abcd[0] + maxY * abcd[1] + minZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v8", maxX, maxY, minZ)); } if (Math.abs(maxX * abcd[0] + minY * abcd[1] + maxZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v5", maxX, minY, maxZ)); } if (Math.abs(maxX * abcd[0] + maxY * abcd[1] + maxZ * abcd[2] + abcd[3]) < 0.001) { corners.add(new Vertex("v6", maxX, maxY, maxZ)); } } /** * Getter for corners * @return The corners */ public Collection getCorners() { return corners; } /** * 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] + "]"; } } |