[Bprocessor-commit] /model/src/net/sourceforge/bprocessor/model Surface.java, 1.181, 1.182
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-09-27 10:47:18
|
Update of /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13767/src/net/sourceforge/bprocessor/model Modified Files: Surface.java Log Message: made normal0 more general by taking a list of edges to make a normal according to. Moved alle extrude methods to be the same place in the surface class. Made some major changes to controlledExtrusion Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.181 retrieving revision 1.182 diff -C2 -d -r1.181 -r1.182 *** Surface.java 27 Sep 2007 08:33:13 -0000 1.181 --- Surface.java 27 Sep 2007 10:47:09 -0000 1.182 *************** *** 777,783 **** Vertex normal = normal(); ! List vertices = getVertices(); ! List edges = getEdges(); int n = vertices.size(); --- 777,783 ---- Vertex normal = normal(); ! List<Vertex> vertices = getVertices(); ! List<Edge> edges = getEdges(); int n = vertices.size(); *************** *** 870,878 **** * @return The resulting top surface */ ! public Surface extrusionControlled(double delta, Set sides, Map v2dir) { ! return extrudeControlled(delta, sides, new HashMap(), new HashMap(), new HashMap(), v2dir); } /** * Make the new vertices, edges and surfaces for extrusion * @param delta the length of extrusion in meters --- 870,1012 ---- * @return The resulting top surface */ ! public Surface extrusionControlled(double delta, Set<Surface> sides, ! Map<Vertex, Direction> v2dir) { ! return extrudeControlled(delta, sides, new HashMap<Edge, Edge>(), ! new HashMap<Vertex, Edge>(), new HashMap<Edge, Surface>(), v2dir); } /** + * @param p the plane to extrude onto + * @param sides the collection of all resulting side surfaces + * @param distance The distance of the extrusion as a backup when plane is orthogonal + * @return the new extrusion top surface + */ + public Surface extrusionOnto(Plane p, double distance, Collection<Surface> 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 { + Vertex ncopy = normal.copy(); + ncopy.scale(distance); + vmap[i] = v[i].copy().add(ncopy); + } + } + + 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(); + } + // positive for angles less then 90 degrees and negative otherwise + double delta = normal.dot(sidemap[0].getDirection()); + 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; + } + + /** + * @param p The plane to extrude onto + * @param sides The the collection of already extruded sides (if none the resulting is added) + * @param distance the distance of the extrusion as a backup if the plane is orthogonal + * @param tops The top surfaces + * @return the new created extrusion top surface + */ + public Surface extrusionAllOnto(Plane p, double distance, + Collection<Surface> sides, Set<Surface> tops) { + Surface top = extrusionOnto(p, distance, sides); + tops.add(top); + Iterator iter = getHoles().iterator(); + while (iter.hasNext()) { + Surface hole = (Surface) iter.next(); + Surface holetop = hole.extrusionAllOnto(p, distance, sides, tops); + top.addHole(holetop); + } + return top; + } + + /** * Make the new vertices, edges and surfaces for extrusion * @param delta the length of extrusion in meters *************** *** 884,894 **** * @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(); ! normal.scale(delta); boolean makeNewTop = true; ! List vertices = getVertices(); ! List edges = getEdges(); int n = vertices.size(); --- 1018,1029 ---- * @return The top in the extruded surface */ ! public Surface extrudeControlled(double delta, Set<Surface> sides, Map<Edge, Edge> e2e, ! Map<Vertex, Edge> v2e, Map<Edge, Surface> e2s, Map<Vertex, Direction> v2dir) { Vertex normal = normal(); ! Plane p = new Plane(normal.getX(), normal.getY(), normal.getZ(), this.getFirstVertex()); boolean makeNewTop = true; ! List<Vertex> vertices = getVertices(); ! List<Edge> edges = getEdges(); int n = vertices.size(); *************** *** 908,912 **** --- 1043,1056 ---- edges.toArray(e); + for (Surface hole : getHoles()) { + sides.add(hole.extrudeControlled(delta, sides, e2e, v2e, e2s, v2dir)); + } + for (int i = 0; i < n; i++) { + double min = 0, max = Double.POSITIVE_INFINITY; + if (delta < 0) { + min = Double.NEGATIVE_INFINITY; + max = 0; + } if (isVertexBounded(v[i])) { if (v2dir.containsKey(v[i])) { *************** *** 916,931 **** } else { vmap[i] = v[i].copy(); ! v2dir.put(v[i], new Direction(vmap[i], normal)); } } 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)); } } --- 1060,1102 ---- } else { vmap[i] = v[i].copy(); ! v2dir.put(v[i], new Direction(vmap[i], normal, min, max)); } } else { // We just have to move the existing surface makeNewTop = false; + Collection<Edge> connected = v[i].getEdges(); + connected.removeAll(this.getEdges()); + Edge connectedEdge = null; + if (connected.size() == 1) { + connectedEdge = connected.iterator().next(); + } + Vertex dir; + Direction direction; + if (connectedEdge != null) { + Vertex edgeVertex = connectedEdge.otherVertex(v[i]).minus(v[i]); + dir = normal.projectOnto(edgeVertex); + dir.normalize(); + double angle = normal.angle(edgeVertex); + if (angle > Math.PI / 2) { + //connected Edge points backwards + min = -connectedEdge.getLength(); + max = Double.POSITIVE_INFINITY; + } else { + //connected Edge points along normal + max = connectedEdge.getLength(); + min = Double.NEGATIVE_INFINITY; + } + direction = new Direction(v[i], dir, min, max); + } else { + dir = normal; + direction = new Direction(v[i], dir, min, max); + } if (v2dir.containsKey(v[i])) { Direction d = (Direction)v2dir.get(v[i]); vmap[i] = d.getVertex(); ! d.alterDirection(dir); } else { vmap[i] = v[i]; ! v2dir.put(v[i], direction); } } *************** *** 934,940 **** for (int i = 0; i < n; i++) { //move points delta ! vmap[i].setX(vmap[i].getX() + normal.getX()); ! vmap[i].setY(vmap[i].getY() + normal.getY()); ! vmap[i].setZ(vmap[i].getZ() + normal.getZ()); //make edges if (e2e.containsKey(e[i])) { --- 1105,1110 ---- for (int i = 0; i < n; i++) { //move points delta ! Direction dir = v2dir.get(v[i]); ! vmap[i].set(p.intersection(vmap[i], dir.getDirection(), true)); //make edges if (e2e.containsKey(e[i])) { *************** *** 950,954 **** } ! List lst = new LinkedList(); for (int i = 0; i < n; i++) { if (v2e.containsKey(v[i])) { --- 1120,1124 ---- } ! List<Edge> lst = new LinkedList<Edge>(); for (int i = 0; i < n; i++) { if (v2e.containsKey(v[i])) { *************** *** 965,969 **** } 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]) { --- 1135,1139 ---- } else { if (!makeNewTop) { ! Collection<Edge> newE = new LinkedList<Edge>(); if (vmap[(i + 1) % n] == v[(i + 1) % n] && vmap[(i + n - 1) % n] == v[(i + n - 1) % n]) { *************** *** 1016,1020 **** Edge l = sidemap[(i + 1) % n]; Edge t = topmap[i]; ! List newEdges = new LinkedList(); newEdges.add(r); newEdges.add(t); --- 1186,1190 ---- Edge l = sidemap[(i + 1) % n]; Edge t = topmap[i]; ! List<Edge> newEdges = new LinkedList<Edge>(); newEdges.add(r); newEdges.add(t); *************** *** 1029,1037 **** if (makeNewTop) { ! List newEdges = new LinkedList(); for (int i = 0; i < n; i++) { newEdges.add(topmap[n - i - 1]); } top = new Surface(newEdges); } else { top = this; --- 1199,1208 ---- if (makeNewTop) { ! List<Edge> newEdges = new LinkedList<Edge>(); for (int i = 0; i < n; i++) { newEdges.add(topmap[n - i - 1]); } top = new Surface(newEdges); + sides.add(top); } else { top = this; *************** *** 1090,1094 **** /** ! * Check if the given vertex is free (do not have a edge to follow in move og pull), that is * 1) it is only part of the parent surface (this) or * 2) it is only connected to one edge not in this surface, which is not in --- 1261,1265 ---- /** ! * Check if the given vertex is bounded, that is * 1) it is only part of the parent surface (this) or * 2) it is only connected to one edge not in this surface, which is not in *************** *** 1102,1106 **** case 3: //If the third connected edge is not in the plane of the surface ! //it is not free otherwise it is Plane plane = this.plane(); for (Edge e : connected) { --- 1273,1277 ---- case 3: //If the third connected edge is not in the plane of the surface ! //it is not bounded otherwise it is Plane plane = this.plane(); for (Edge e : connected) { *************** *** 1118,1121 **** --- 1289,1295 ---- } break; + default: + + break; } return true; *************** *** 1424,1435 **** public Vertex normal() { ! return normal0(); } /** * USE normal for the normal * @return value */ ! public Vertex normal0() { int size = edges.size(); Edge[] e = new Edge[size]; --- 1598,1610 ---- public Vertex normal() { ! return normal0(edges); } /** * USE normal for the normal + * @param edges The collection of edges to calculate the normal from * @return value */ ! public static Vertex normal0(Collection<Edge> edges) { int size = edges.size(); Edge[] e = new Edge[size]; *************** *** 1885,2020 **** /** - * @param p The plane to extrude onto - * @param sides The the collection of already extruded sides (if none the resulting is added) - * @param distance the distance of the extrusion as a backup if the plane is orthogonal - * @param tops The top surfaces - * @return the new created extrusion top surface - */ - public Surface extrusionAllOnto(Plane p, double distance, - Collection<Surface> sides, Set<Surface> tops) { - Surface top = extrusionOnto(p, distance, sides); - tops.add(top); - Iterator iter = getHoles().iterator(); - while (iter.hasNext()) { - Surface hole = (Surface) iter.next(); - Surface holetop = hole.extrusionAllOnto(p, distance, sides, tops); - top.addHole(holetop); - } - return top; - } - - /** - * @param p the plane to extrude onto - * @param sides the collection of all resulting side surfaces - * @param distance The distance of the extrusion as a backup when plane is orthogonal - * @return the new extrusion top surface - */ - public Surface extrusionOnto(Plane p, double distance, Collection<Surface> 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 { - Vertex ncopy = normal.copy(); - ncopy.scale(distance); - vmap[i] = v[i].copy().add(ncopy); - } - } - - 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(); - } - // positive for angles less then 90 degrees and negative otherwise - double delta = normal.dot(sidemap[0].getDirection()); - 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; - } - - /** * Find the last hit vertex, when the given edge is used as sweepline across the surface * @precondtion The given edge is in the surface --- 2060,2063 ---- |