[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Surface.java, 1.135, 1.136
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-02-13 15:40:31
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv626/src/net/sourceforge/bprocessor/model Modified Files: Surface.java Log Message: extrusion onto planes Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.135 retrieving revision 1.136 diff -C2 -d -r1.135 -r1.136 *** Surface.java 31 Jan 2007 20:56:40 -0000 1.135 --- Surface.java 13 Feb 2007 15:05:14 -0000 1.136 *************** *** 1844,1846 **** --- 1844,1974 ---- return closest; } + + /** + * @param p The plane to extrude onto + * @param sides The the collection of already extruded sides (if none the resulting is added) + * @param tops The top surfaces + * @return the new created extrusion top surface + */ + public Surface extrusionAllOnto(Plane p, Collection sides, Set tops) { + Surface top = extrusionOnto(p, sides); + tops.add(top); + Iterator iter = getHoles().iterator(); + while (iter.hasNext()) { + Surface hole = (Surface) iter.next(); + Surface holetop = hole.extrusionAllOnto(p, sides, tops); + top.addHole(holetop); + } + return top; + } + + /** + * @param p the plane to extrude onto + * @param sides the collection of all resulting side surfaces + * @return the new extrusion top surface + */ + public Surface extrusionOnto(Plane p, Collection sides) { + if (p == null) { + log.info("p were null for " + this); + return null; + } + Vertex normal = normal(); + List vertices = getVertices(); + List edges = getEdges(); + int n = vertices.size(); + Vertex[] v = new Vertex[n]; + Edge[] e = new Edge[n]; + Vertex[] vmap = new Vertex[n]; + Edge[] topmap = new Edge[n]; + Edge[] sidemap = new Edge[n]; + Surface[] facemap = new Surface[n]; + Surface top = null; + vertices.toArray(v); + edges.toArray(e); + + for (int i = 0; i < n; i++) { + Vertex inter = p.intersection(v[i], normal, true); + if (inter != null) { + vmap[i] = inter; + } else { + log.info("The found intersection were null"); + vmap[i] = v[i].copy().add(normal); + } + } + + for (int i = 0; i < n; i++) { + topmap[i] = new Edge(vmap[i], vmap[(i + 1) % n]); + } + + for (int i = 0; i < n; i++) { + sidemap[i] = new Edge(v[i], vmap[i]); + } + + for (int i = 0; i < n; i++) { + Edge b = e[i]; + Edge r = sidemap[i]; + Edge l = sidemap[(i + 1) % n]; + Edge t = topmap[i]; + List newEdges = new LinkedList(); + newEdges.add(r); + newEdges.add(t); + newEdges.add(l); + newEdges.add(b); + facemap[i] = new Surface(newEdges); + sides.add(facemap[i]); + } + + { + List newEdges = new LinkedList(); + for (int i = 0; i < n; i++) { + newEdges.add(topmap[n - i - 1]); + } + top = new Surface(newEdges); + } + + // FIXME should return the sides instead of assigning + // spaces here. + boolean flip = false; + boolean inside = false; + + + if (exterior != null) { + Vertex n0 = normal(); + Vertex n1 = exterior.normal(); + Vertex o = n0.add(n1); + if (o.isZero()) { + flip = true; + } + inside = exterior.getOwner() == getOwner(); + } + + int delta = 1; + for (int i = 0; i < n; i++) { + if (delta < 0) { + facemap[i].setBackDomain(getBackDomain()); + if (exterior != null && inside) { + if (flip) { + facemap[i].setFrontDomain(exterior.getFrontDomain()); + } else { + facemap[i].setFrontDomain(exterior.getBackDomain()); + } + } + } else { + facemap[i].setFrontDomain(getFrontDomain()); + if (exterior != null && inside) { + if (flip) { + facemap[i].setBackDomain(exterior.getBackDomain()); + } else { + facemap[i].setBackDomain(exterior.getFrontDomain()); + } + } + } + } + if (delta < 0) { + top.setBackDomain(getBackDomain()); + } else { + top.setFrontDomain(getFrontDomain()); + } + return top; + } } |