[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Surface.java,1.93,1.94
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-05-01 10:04:23
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6755/src/net/sourceforge/bprocessor/model Modified Files: Surface.java Log Message: Added a controlled extrude method and a method to exchange a edge with another (should be moved to Edge at some point). To make the controlled extrude work the mothod call in extrudeTool have to be changed, there is no modifier way of using it yet Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** Surface.java 24 Apr 2006 08:45:48 -0000 1.93 --- Surface.java 1 May 2006 10:04:10 -0000 1.94 *************** *** 151,161 **** vertices.add(current); Edge edge = (Edge) iter.next(); current = edge.otherVertex(current); if (current == null) { ! throw new Error("other vertex null"); } } } else { ! throw new Error("first vertex null"); } } --- 151,162 ---- vertices.add(current); Edge edge = (Edge) iter.next(); + Vertex prev = current; current = edge.otherVertex(current); if (current == null) { ! throw new Error("other vertex that " + prev + " null in surface " + this); } } } else { ! throw new Error("first vertex null in Surface " + this); } } *************** *** 225,228 **** --- 226,287 ---- /** + * Replace one edge e1 and its vertices with e2's + * @param e1 The edge to replace + * @param e2 The replacing edge + */ + public void replace(Edge e1, Edge e2) { + //FIXME not tested enough to be trusted 100% + List lst = new ArrayList(); + Edge[] edges = new Edge[getEdges().size()]; + getEdges().toArray(edges); + for (int i = 0; i < edges.length; i++) { + if (edges[i] == e1) { + log.info("Found the edge " + edges[i]); + Edge prev; + Edge next; + if (i == 0) { + if (edges[edges.length - 1].contains(e1.getFrom())) { + prev = edges[edges.length - 1]; + next = edges[i + 1]; + } else { + next = edges[edges.length - 1]; + prev = edges[i + 1]; + } + } else { + if (edges[(i + 1) % edges.length].contains(e1.getTo())) { + next = edges[(i + 1) % edges.length]; + prev = edges[i - 1]; + } else { + next = edges[i - 1]; + prev = edges[(i + 1) % edges.length]; + } + } + if (prev.getFrom() == e1.getFrom()) { + prev.setFrom(e2.getTo()); + } else if (prev.getTo() == e1.getFrom()) { + prev.setTo(e2.getTo()); + } else { + log.info("AHHH1 prev:" + prev + ", e1:" + e1 + ", e2:" + e2); + } + if (next.getTo() == e1.getTo()) { + next.setTo(e2.getFrom()); + } else if (next.getFrom() == e1.getTo()) { + next.setFrom(e2.getFrom()); + } else { + log.info("AHHH2 next:" + next + ", e1:" + e1 + ", e2:" + e2); + } + log.info("Next were " + next); + log.info("Prev were " + prev); + log.info("Replaced with " + e2); + lst.add(e2); + } else { + log.info("Just reinserted edge " + edges[i]); + lst.add(edges[i]); + } + } + setEdges(lst); + } + + /** * Replace the edge with the edges * @param edge The original edge *************** *** 474,478 **** } - // FIXME should return the sides instead of assigning // spaces here. --- 533,536 ---- *************** *** 515,518 **** --- 573,789 ---- } + return top; + } + + /** + * Make the new vertices, edges and surfaces for extrusion + * @param delta the direction of extrusion + * @param sides Will contain the sides that are created + * @param e2e a edge to new extruded parallel edge map + * @param v2e a vertex to orthogonal edge map + * @param e2s a edge to extruded surface map + * @param v2dir a vertex to direction map + * @return The top in the extruded surface + */ + public Surface extrudeControlled(double delta, Set sides, Map e2e, Map v2e, Map e2s, Map v2dir) { + Vertex normal = normal(); + boolean makeNewTop = true; + 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++) { + if (isFree(v[i])) { + if (v2dir.containsKey(v[i])) { + Direction d = (Direction)v2dir.get(v[i]); + vmap[i] = d.getVertex(); + d.alterDirection(normal); + } else { + vmap[i] = v[i].copy(); + v2dir.put(v[i], new Direction(vmap[i], normal)); + getOwner().add(vmap[i]); + } + } else { + // We just have to move the existing surface + makeNewTop = false; + if (v2dir.containsKey(v[i])) { + Direction d = (Direction)v2dir.get(v[i]); + vmap[i] = d.getVertex(); + d.alterDirection(normal); + } else { + vmap[i] = v[i]; + v2dir.put(v[i], new Direction(v[i], normal)); + } + } + } + + for (int i = 0; i < n; i++) { + if (e2e.containsKey(e[i])) { + topmap[i] = (Edge)e2e.get(e[i]); + } else { + if (vmap[i] == v[i] || vmap[(i + 1) % n] == v[(i + 1) % n]) { + topmap[i] = e[i]; + } else { + topmap[i] = new Edge(vmap[i], vmap[(i + 1) % n]); + getOwner().add(topmap[i]); + } + e2e.put(e[i], topmap[i]); + } + } + + List lst = new LinkedList(); + for (int i = 0; i < n; i++) { + if (v2e.containsKey(v[i])) { + sidemap[i] = (Edge)v2e.get(v[i]); + } else { + if (v[i] == vmap[i]) { + if (i != 0 && sidemap[i - 1] == null) { + lst.add(e[i - 1]); + } + sidemap[i] = null; + if (i == n - 1 && sidemap[0] == null) { + lst.add(e[n - 1]); + } + } else { + if (!makeNewTop) { + Collection newE = new LinkedList(); + if (vmap[(i + 1) % n] == v[(i + 1) % n] && + vmap[(i + n - 1) % n] == v[(i + n - 1) % n]) { + // both the parent and previous edge have to be split + newE = e[(i + n - 1) % n].split(vmap[i]); + newE.addAll(e[i].split(vmap[i])); + } else if (vmap[(i + 1) % n] == v[(i + 1) % n]) { + //it is the next edge that is supposed to be split + newE = e[i].split(vmap[i]); + } else if (vmap[(i + n - 1) % n] == v[(i + n - 1) % n]) { + //it is the previous edges that is supposed to be split + newE = e[(i + n - 1) % n].split(vmap[i]); + } else { + sidemap[i] = new Edge(v[i], vmap[i]); + + } + if (vmap[(i + n - 1) % n] != v[(i + n - 1) % n]) { + //we have to add the new top edge between the prev and this to the list + lst.add(topmap[(i + n - 1) % n]); + } + Iterator iter = newE.iterator(); + while (iter.hasNext()) { + Edge current = (Edge)iter.next(); + if (current.contains(v[i])) { + //FIXME SHOULD only be one edge but is sometimes two + sidemap[i] = current; + } else { + lst.add(current); + } + } + } else { + sidemap[i] = new Edge(v[i], vmap[i]); + lst.add(e[i]); + } + v2e.put(v[i], sidemap[i]); + getOwner().add(sidemap[i]); + } + } + } + this.setEdges(lst); + + for (int i = 0; i < n; i++) { + if (e2s.containsKey(e[i])) { + facemap[i] = (Surface)e2s.get(e[i]); + } else { + if (sidemap[i] == null || sidemap[(i + 1) % n] == null) { + // We should not make a new surface + } else { + 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); + e2s.put(b, facemap[i]); + getOwner().insert(facemap[i]); + sides.add(facemap[i]); + } + } + } + + if (makeNewTop) { + List newEdges = new LinkedList(); + for (int i = 0; i < n; i++) { + newEdges.add(topmap[n - i - 1]); + } + top = new Surface(newEdges); + getOwner().insert(top); + } else { + top = this; + } + + // FIXME should return the sides instead of assigning + // spaces here. + boolean flip = false; + + if (exterior != null) { + Vertex n0 = normal(); + Vertex n1 = exterior.normal(); + Vertex o = n0.add(n1); + if (o.isZero()) { + flip = true; + } + } + + if (!makeNewTop) { + // We have to assign the other way arround + delta = -delta; + } + for (int i = 0; i < n; i++) { + if (facemap[i] != null) { + if (delta < 0) { + facemap[i].setBackDomain(getBackDomain()); + if (exterior != null) { + if (flip) { + facemap[i].setFrontDomain(exterior.getFrontDomain()); + } else { + facemap[i].setFrontDomain(exterior.getBackDomain()); + } + } + } else { + facemap[i].setFrontDomain(getFrontDomain()); + if (exterior != null) { + if (flip) { + facemap[i].setBackDomain(exterior.getBackDomain()); + } else { + facemap[i].setBackDomain(exterior.getFrontDomain()); + } + } + } + } + } + if (makeNewTop) { + if (delta < 0) { + top.setBackDomain(getBackDomain()); + } else { + top.setFrontDomain(getFrontDomain()); + } + } return top; *************** *** 520,523 **** --- 791,820 ---- /** + * Check if the given vertex is free, that is + * 1) it is only part of the parent surface (this) + * 2) if it is part of more surfaces two of these have to be coplanar (this have to be one) + * @param vertex The vertex to check + * @return True if the vertex is bounded and false otherwise + */ + private boolean isFree(Vertex vertex) { + Set sur = vertex.getSurfaces(); + if (sur.size() > 1) { + // we have to do further checks + Iterator iter = sur.iterator(); + while (iter.hasNext()) { + Surface cur = (Surface)iter.next(); + log.info(vertex + " Saw " + cur); + if (cur != this && this.plane().contains(cur)) { + return true; + } + } + // if the while loop does not return then return false + return false; + } else { + return true; + } + } + + /** * Adds a hole surface to this surface. * @param hole the hole to add. |