[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/modellor InnerWallModellor.java, 1.
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2007-05-18 19:10:27
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5534/src/net/sourceforge/bprocessor/model/modellor Modified Files: InnerWallModellor.java Log Message: did some work on windows. Started to implement wooden sheets on the side of inner walls but ran out of time Index: InnerWallModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/InnerWallModellor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InnerWallModellor.java 9 May 2007 09:05:43 -0000 1.3 --- InnerWallModellor.java 18 May 2007 19:10:23 -0000 1.4 *************** *** 49,58 **** public static final double JOIST_DEPTH = 0.070; ! /** The classification id for a innerwall */ ! public static final String INNERWALL_CLASS = "-1.-205"; ! /** The classification id for a innerwall */ public static final String EXTERIOR = "-1.-80"; /** The space of this modellor */ private Space space; --- 49,64 ---- public static final double JOIST_DEPTH = 0.070; ! /** Thickness of the wood sheets */ ! public static final double SHEET_THICKNESS = 0.005; ! /** The classification id for a wall */ ! public static final String WALL = "-1.-205.01"; ! ! /** The classification id for exterior */ public static final String EXTERIOR = "-1.-80"; + /** The classification id for a window */ + public static final String WINDOW = "-1.-205.02"; + /** The space of this modellor */ private Space space; *************** *** 64,69 **** private double joistInterval = 0.5; ! /** Says whether or not the modellor should be build, ! * is false when there is no-need to rebuild the innerwall */ private boolean build = true; --- 70,79 ---- private double joistInterval = 0.5; ! /** ! * Says whether or not the modellor should be build, ! * is false when there is no-need to rebuild the innerwall. ! * While true the innerwall will be rebuild every time the ! * update method is called ! */ private boolean build = true; *************** *** 73,76 **** --- 83,87 ---- /** The net of the modellor */ private Net net; + /** * The empty constructor *************** *** 159,166 **** } if (net != null) { ! addSupport(); space.clear(); space.add(net); buildFramework(net); build = false; } --- 170,179 ---- } if (net != null) { ! addWallSupport(); ! addWindowSupport(); space.clear(); space.add(net); buildFramework(net); + buildWoodSheets(net); build = false; } *************** *** 168,173 **** } private void buildFramework(Net net) { ! Map<Edge, Edge> edge2Run = getRuns(net); Set<Edge> runs = new HashSet<Edge>(edge2Run.values()); Edge right = null; --- 181,190 ---- } + /** + * Builds the framework of the innerwall given a net + * @param net a net to build the framework from + */ private void buildFramework(Net net) { ! Map<Edge, Edge> edge2Run = getRuns(net.getEdges()); Set<Edge> runs = new HashSet<Edge>(edge2Run.values()); Edge right = null; *************** *** 201,204 **** --- 218,222 ---- space.add(base); Space joist = new Space("joist", Space.CONSTRUCTION, space.getLevel() + 1, true); + joist.setClassification(woodJoist()); space.add(joist); Vertex dir = e.getDirection(); *************** *** 236,247 **** base.extrude(length, sides); space.addAll(sides); } } ! private Map<Edge, Edge> getRuns(Net net) { Map<Edge, Edge> edge2Run = new HashMap<Edge, Edge>(); ! if (net != null) { ! Collection<Edge> netEdges = net.getEdges(); ! for (Edge e : netEdges) { if (edge2Run.get(e) == null) { List<Edge> run = e.parrallelRun(); --- 254,306 ---- base.extrude(length, sides); space.addAll(sides); + } + } + + private void buildWoodSheets(Net net) { + List<Edge> outline = netOutline(net); + if (!outline.isEmpty()) { + List<Edge> outlineCopy1 = new LinkedList<Edge>(); + List<Edge> outlineCopy2 = new LinkedList<Edge>(); + for (Edge outlineEdge : outline) { + outlineCopy1.add(outlineEdge); + outlineCopy2.add(outlineEdge); + } + Surface sheet1 = new Surface(outlineCopy1); + Surface sheet2 = new Surface(outlineCopy2); + Space sheetSpace1 = new Space("sheet1", Space.CONSTRUCTION, space.getLevel() + 1, true); + sheetSpace1.setClassification(woodSheet()); + Space sheetSpace2 = new Space("sheet2", Space.CONSTRUCTION, space.getLevel() + 1, true); + sheetSpace2.setClassification(woodSheet()); + Vertex j = cs.getJ().copy(); + j.normalize(); + j.scale(SHEET_THICKNESS + JOIST_DEPTH); + sheet2.move(j.getX(), j.getY(), j.getZ()); + double correction = 1; + space.insert(sheet1); + space.insert(sheet2); + if (j.dot(sheet1.normal()) < 0) { + correction = -1; + } + Set<Surface> surfaces = new HashSet<Surface>(); + surfaces.add(sheet1); + surfaces.add(sheet2); + Geometry.simplifyGeometry(surfaces); + sheet1.extrude(SHEET_THICKNESS * correction, surfaces); + sheet2.extrude(SHEET_THICKNESS * correction, surfaces); + } else { + log.info("Couldnt make sheets on the innerwall"); } } ! /** ! * Maps each edge in a set to an edge representing the run of that edge. ! * A run being the an amount of parrallel cennected edges. ! * @param edges a collection of edges ! * @return the described map ! */ ! private Map<Edge, Edge> getRuns(Collection<Edge> edges) { Map<Edge, Edge> edge2Run = new HashMap<Edge, Edge>(); ! if (edges != null) { ! for (Edge e : edges) { if (edge2Run.get(e) == null) { List<Edge> run = e.parrallelRun(); *************** *** 269,276 **** private static Surface joistBase() { List<Vertex> vl = new LinkedList<Vertex>(); ! Vertex first = new Vertex(0, 0, 0); ! vl.add(new Vertex(JOIST_WIDTH, 0, 0)); ! vl.add(new Vertex(JOIST_WIDTH, JOIST_DEPTH, 0)); ! vl.add(new Vertex(0, JOIST_DEPTH, 0)); List<Edge> el = new LinkedList<Edge>(); Vertex prevV = first; --- 328,335 ---- private static Surface joistBase() { List<Vertex> vl = new LinkedList<Vertex>(); ! Vertex first = new Vertex(0, SHEET_THICKNESS, 0); ! vl.add(new Vertex(JOIST_WIDTH, SHEET_THICKNESS, 0)); ! vl.add(new Vertex(JOIST_WIDTH, JOIST_DEPTH + SHEET_THICKNESS, 0)); ! vl.add(new Vertex(0, JOIST_DEPTH + SHEET_THICKNESS, 0)); List<Edge> el = new LinkedList<Edge>(); Vertex prevV = first; *************** *** 284,287 **** --- 343,351 ---- } + /** + * Builds a net from a single surface + * (Should be able to handle a set of surfaces) + * @return a net for building the framework + */ private Net buildNet() { if (space != null && !space.getEnvelope().isEmpty()) { *************** *** 304,325 **** } if (horizontal != null && vertical != null) { ! Vertex origin = horizontal.getFrom(); ! Vertex topToBottom = vertical.otherVertex(origin).minus(origin); ! Vertex interval = horizontal.getDirection(); ! interval.scale(joistInterval / interval.length()); ! Vertex current = origin.copy(); ! current.move(interval.getX(), interval.getY(), interval.getZ()); ! while (origin.minus(current).length() < horizontal.getLength() - joistInterval) { ! Vertex from = current.copy(); ! Vertex to = from.add(topToBottom); ! net.insert(from); ! net.insert(to); ! net.insert(new Edge(from, to)); ! current.move(interval.getX(), interval.getY(), interval.getZ()); ! } Vertex i; Vertex j; Vertex n; ! n = new Vertex(0, 0, 1); j = surface.normal(); if (surface.getBackDomain() == space) { --- 368,376 ---- } if (horizontal != null && vertical != null) { ! Vertex origin = vertical.getFrom(); Vertex i; Vertex j; Vertex n; ! n = vertical.getDirection(); j = surface.normal(); if (surface.getBackDomain() == space) { *************** *** 331,334 **** --- 382,399 ---- n.normalize(); cs = new CoordinateSystem(i, j, n, origin); + Project.getInstance().world().add(cs); + Vertex topToBottom = vertical.otherVertex(origin).minus(origin); + Vertex interval = horizontal.getDirection(); + interval.scale(joistInterval / interval.length()); + Vertex current = origin.copy(); + current.move(interval.getX(), interval.getY(), interval.getZ()); + while (origin.minus(current).length() < horizontal.getLength() - JOIST_WIDTH) { + Vertex from = current.copy(); + Vertex to = from.add(topToBottom); + net.insert(from); + net.insert(to); + net.insert(new Edge(from, to)); + current.move(interval.getX(), interval.getY(), interval.getZ()); + } } else { log.error("The surface found did not meet the requirements"); *************** *** 344,348 **** * innerwalls. */ ! private void addSupport() { if (net != null) { log.info("net not null"); --- 409,414 ---- * innerwalls. */ ! private Set<Edge> addWallSupport() { ! Set<Edge> supports = new HashSet<Edge>(); if (net != null) { log.info("net not null"); *************** *** 355,360 **** Classification backClass = back.getClassification(); if ((frontClass != null && backClass != null) && ! ((frontClass.getFullId(front).equalsIgnoreCase(INNERWALL_CLASS) && front != space) || ! (backClass.getFullId(back).equalsIgnoreCase(INNERWALL_CLASS) && back != space))) { log.info("found suiteable surface"); Edge left = null; --- 421,426 ---- Classification backClass = back.getClassification(); if ((frontClass != null && backClass != null) && ! ((frontClass.getFullId(front).equalsIgnoreCase(WALL) && front != space) || ! (backClass.getFullId(back).equalsIgnoreCase(WALL) && back != space))) { log.info("found suiteable surface"); Edge left = null; *************** *** 383,395 **** from = cs.unTranslate(from); Edge support1 = new Edge(to, from); ! net.insert(support1); Edge support2 = support1.copy(); Vertex move = cs.getI().copy(JOIST_WIDTH / cs.getI().length()); support2.move(move); ! net.insert(support2); ! } } } } } --- 449,561 ---- from = cs.unTranslate(from); Edge support1 = new Edge(to, from); ! supports.add(support1); Edge support2 = support1.copy(); Vertex move = cs.getI().copy(JOIST_WIDTH / cs.getI().length()); support2.move(move); ! supports.add(support2); ! } ! } ! } ! Collection<Edge> delete = new LinkedList<Edge>(); ! for (Edge netEdge : net.getEdges()) { ! double netX = cs.translate(netEdge.getFrom()).getX(); ! if (vertical(netEdge)) { ! for (Edge supportEdge : supports) { ! double supportX = cs.translate(supportEdge.getFrom()).getX(); ! if ((netX > supportX - JOIST_WIDTH) && ! (netX < supportX + JOIST_WIDTH)) { ! delete.add(netEdge); ! break; ! } ! } } } + for (Edge e : delete) { + e.delete(); + } + List<Edge> supportsList = new LinkedList<Edge>(supports); + supports = new HashSet<Edge>(net.insert(supportsList)); + } + return supports; + } + + private Set<Edge> addWindowSupport() { + Set<Edge> supports = new HashSet<Edge>(); + if (net != null) { + Set<Surface> envelope = space.getEnvelope(); + Set<Edge> delete = new HashSet<Edge>(); + for (Surface s : envelope) { + for (Surface h : s.getHoles()) { + Space front = h.getFrontDomain(); + Space back = h.getBackDomain(); + Classification frontClass = front.getClassification(); + Classification backClass = back.getClassification(); + if ((frontClass != null && backClass != null) && + ((frontClass.getFullId(front).equalsIgnoreCase(WINDOW) && front != space) || + (backClass.getFullId(back).equalsIgnoreCase(WINDOW) && back != space))) { + Edge left = null; + Edge right = null; + double min = Double.POSITIVE_INFINITY; + double max = Double.NEGATIVE_INFINITY; + for (Edge e : h.getEdges()) { + if (vertical(e)) { + Vertex from = cs.translate(e.getFrom()); + double x = from.getX(); + if (min > x) { + min = x; + left = e; + } + if (max < x) { + max = x; + right = e; + } + } + } + Vertex leftTo = cs.translate(left.getTo()); + Vertex leftFrom = cs.translate(left.getFrom()); + leftFrom.setY(0); + leftFrom.setZ(0); + leftTo.setY(0); + leftTo.setZ(getHeight()); + leftTo.move(-JOIST_WIDTH, 0, 0); + leftFrom.move(-JOIST_WIDTH, 0, 0); + + Vertex rightTo = cs.translate(right.getTo()); + Vertex rightFrom = cs.translate(right.getFrom()); + rightFrom.setY(0); + rightFrom.setZ(0); + rightTo.setY(0); + rightTo.setZ(getHeight()); + + + for (Edge e : net.getEdges()) { + Vertex from = cs.translate(e.getFrom()); + if (vertical(e) && + from.getX() > (leftFrom.getX() - JOIST_WIDTH) && + from.getX() < (rightFrom.getX() + JOIST_WIDTH)) { + delete.add(e); + } + } + + leftFrom = cs.unTranslate(leftFrom); + leftTo = cs.unTranslate(leftTo); + Edge leftEdge = new Edge(leftFrom, leftTo); + supports.add(leftEdge); + + + rightFrom = cs.unTranslate(rightFrom); + rightTo = cs.unTranslate(rightTo); + Edge rightEdge = new Edge(rightFrom, rightTo); + supports.add(rightEdge); + } + } + } + for (Edge e : delete) { + e.delete(); + } + List<Edge> supportsList = new LinkedList<Edge>(supports); + supports = new HashSet<Edge>(net.insert(supportsList)); } + return supports; } *************** *** 485,488 **** --- 651,671 ---- } + /** + * gets the height of the innerwall element + * @return a height + */ + private double getHeight() { + double height = 0; + if (net != null) { + Set<Edge> runs = new HashSet<Edge>(getRuns(net.getEdges()).values()); + for (Edge run : runs) { + if (vertical(run) && height < run.getLength()) { + height = run.getLength(); + } + } + } + return height; + } + private boolean horizontal(Edge e) { Vertex to = e.getTo(); *************** *** 497,500 **** --- 680,747 ---- Math.abs(to.getY() - from.getY()) < Geometry.EPS); } + + /** + * Finds the outline of a net, if it makes sence. + * The outline must be a sequence of connected outer edges, so that + * the last edge is connected to the first. Also all outer edges most be + * in the outline. + * @param net a net + * @return a list of connected edges making up the net outline + */ + private List<Edge> netOutline(Net net) { + /*Find outer edges*/ + Set<Edge> outer = new HashSet<Edge>(); + for (Edge current : net.getEdges()) { + if (current.getSurfaces().size() < 2) { + outer.add(current); + } + } + /*If there are outer edges sort them in order*/ + if (!outer.isEmpty()) { + LinkedList<Edge> outline = new LinkedList<Edge>(); + Edge first = (Edge)outer.iterator().next(); + outline.add(first); + outer.remove(first); + Vertex nextVertex = first.getTo(); + boolean doneAll = false; + while (!doneAll) { + Edge next = null; + for (Edge e : nextVertex.getEdges()) { + if (outer.contains(e)) { + next = (Edge)e; + break; + } + } + if (next != null) { + outer.remove(next); + nextVertex = next.otherVertex(nextVertex); + outline.add(next); + } else { + doneAll = true; + } + } + if (outer.isEmpty() && + first.getFrom().getEdges().contains(outline.getLast())) { + return outline; + } else { + log.warn("Outline not well defined, " + + " outer edges left: " + outer.size() + + " outline connected: " + first.getFrom().getEdges().contains(outline.getLast())); + } + } + return new LinkedList<Edge>(); + } + + private static Classification woodJoist() { + Classification c = Project.getInstance().getClassification("-1.-205.01.01", 0); + Classification type = Project.getInstance().getProductType("-1.-205.01.A01"); + c.setTypeClassification(type); + return c; + } + + private static Classification woodSheet() { + Classification c = Project.getInstance().getClassification("-1.-205.01.03", 0); + return c; + } /** |