[Bprocessor-commit] facade/src/net/sourceforge/bprocessor/facade/modellor NetFacadeModellor.java,
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2007-05-16 09:01:38
|
Update of /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14052/src/net/sourceforge/bprocessor/facade/modellor Modified Files: NetFacadeModellor.java Log Message: classification fix Index: NetFacadeModellor.java =================================================================== RCS file: /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor/NetFacadeModellor.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** NetFacadeModellor.java 16 Apr 2007 15:54:36 -0000 1.29 --- NetFacadeModellor.java 16 May 2007 09:01:30 -0000 1.30 *************** *** 52,55 **** --- 52,58 ---- private static final double FRAME_DEPTH = 0.05; + /** The classification id for exterior */ + public static final String EXTERIOR = "-1.-80"; + /** serial id */ private static final long serialVersionUID = 1L; *************** *** 68,72 **** /** The depth of the facade */ ! private double depth = 0.4; /** The front surface of the facade */ --- 71,75 ---- /** The depth of the facade */ ! private double depth = 0.12; /** The front surface of the facade */ *************** *** 79,82 **** --- 82,88 ---- private static Logger log = Logger.getLogger(NetFacadeModellor.class); + /** Times a facade has been generated */ + private int facades = 0; + /** * Empty constructor for the net facade *************** *** 136,152 **** */ private Surface findFront(Space s) { - Iterator it = s.getEnvelope().iterator(); Surface frontCandidate = null; ! if (it.hasNext()) { ! frontCandidate = (Surface)it.next(); ! } ! while (it.hasNext()) { ! Surface surface = (Surface)it.next(); ! Classification frontClass = surface.getFrontDomain().getClassification(); ! Classification backClass = surface.getBackDomain().getClassification(); ! ! if ((frontClass != null && frontClass.getFullId(null).equalsIgnoreCase("-80")) || ! (backClass != null && backClass.getFullId(null).equalsIgnoreCase("-80"))) { ! frontCandidate = surface; } } --- 142,157 ---- */ private Surface findFront(Space s) { Surface frontCandidate = null; ! if (!s.getEnvelope().isEmpty()) { ! frontCandidate = s.getEnvelope().iterator().next(); ! for (Surface surface : s.getEnvelope()) { ! Classification frontClass = surface.getFrontDomain().getClassification(); ! Classification backClass = surface.getBackDomain().getClassification(); ! if ((frontClass != null && ! frontClass.getFullId(null).equalsIgnoreCase(EXTERIOR)) || ! (backClass != null && ! backClass.getFullId(null).equalsIgnoreCase(EXTERIOR))) { ! frontCandidate = surface; ! } } } *************** *** 172,176 **** update = true; } - if (!space.getEnvelope().contains(front)) { update = false; --- 177,180 ---- *************** *** 194,201 **** space.setModellor(null); } - //space = null; - //net = null; - //frame = null; - //front = null; } --- 198,201 ---- *************** *** 237,244 **** a = attributes.get("Front"); if (a != null) { - Iterator sit = space.getOwner().getSurfaces().iterator(); boolean legalSurface = false; ! while (sit.hasNext()) { ! Surface s = (Surface)sit.next(); if (s.getName().equals(a.getValue()) && front != s) { legalSurface = true; --- 237,242 ---- a = attributes.get("Front"); if (a != null) { boolean legalSurface = false; ! for (Surface s : space.getOwner().getSurfaces()) { if (s.getName().equals(a.getValue()) && front != s) { legalSurface = true; *************** *** 309,315 **** public void setFrameWidth(double frameWidth) { this.frameWidth = frameWidth; ! Iterator it = net.getEdges().iterator(); ! while (it.hasNext()) { ! Edge e = (Edge)it.next(); e.setParameters(new ParameterBlock()); } --- 307,311 ---- public void setFrameWidth(double frameWidth) { this.frameWidth = frameWidth; ! for (Edge e : net.getEdges()) { e.setParameters(new ParameterBlock()); } *************** *** 323,335 **** frame.clear(); frame = null; ! } space.clear(); space.add(getNet()); prepareNet(getNet()); if (single) { createSingleFacade(getNet()); } else { createDoubleFacade(getNet()); } } --- 319,342 ---- frame.clear(); frame = null; ! } ! double time = System.nanoTime(); space.clear(); space.add(getNet()); prepareNet(getNet()); if (single) { + log.info("calling create1"); createSingleFacade(getNet()); } else { + log.info("calling create2"); createDoubleFacade(getNet()); } + time = (System.nanoTime() - time) / 1000000; + facades++; + int fields = 0; + if (net != null) { + fields = net.getSurfaces().size(); + } + log.info("Facade no.: " + facades + " with: " + fields + " fields " + + " were generated in: " + time); } *************** *** 339,346 **** */ private void prepareNet(Net n) { ! Collection edges = n.getEdges(); ! Iterator itE = edges.iterator(); ! while (itE.hasNext()) { ! Edge e = (Edge)itE.next(); Map env = e.getParameters().environment(); if (env.get("width") == null) { --- 346,351 ---- */ private void prepareNet(Net n) { ! Collection<Edge> edges = n.getEdges(); ! for (Edge e : edges) { Map env = e.getParameters().environment(); if (env.get("width") == null) { *************** *** 348,354 **** } } ! Iterator itS = n.getSurfaces().iterator(); ! while (itS.hasNext()) { ! Surface s = (Surface)itS.next(); Map env = s.getParameters().environment(); if (env.get("type") == null) { --- 353,357 ---- } } ! for (Surface s : n.getSurfaces()) { Map env = s.getParameters().environment(); if (env.get("type") == null) { *************** *** 384,391 **** space.add(frame); } if (net != null) { ! Iterator fields = net.getSurfaces().iterator(); ! while (fields.hasNext()) { ! Surface field = (Surface)fields.next(); if (field.getEdges().size() > 3) { Map envF = field.getParameters().environment(); --- 387,393 ---- space.add(frame); } + log.info("create"); if (net != null) { ! for (Surface field : net.getSurfaces()) { if (field.getEdges().size() > 3) { Map envF = field.getParameters().environment(); *************** *** 397,416 **** } } ! Surface cut2 = cutType2(); ! cut1.setBackDomain(frame); cut1.setFrontDomain(frame); - cut2.setBackDomain(frame); cut2.setFrontDomain(frame); Vertex out = front.normal(); if (front.getBackDomain() == space) { out.scale(-1); ! } Set<Surface> frame1 = generateFrame(cut1, field.getEdges(), out); ! Set<Surface> frame2 = generateFrame(cut2, field.getEdges(), out); ! ! frame.removeSurface(cut1); ! frame.removeSurface(cut2); frame1.addAll(frame2); ! space.addAll(frame1); Geometry.simplifyGeometry(frame1); } --- 399,422 ---- } } ! Surface cut2 = cutType2(); ! Set<Surface> cuts = new HashSet<Surface>(); ! cut1.setFrontDomain(frame); cut2.setFrontDomain(frame); + cut1.setBackDomain(frame); + cut2.setBackDomain(frame); + + cuts.add(cut1); + cuts.add(cut2); + space.addAll(cuts); Vertex out = front.normal(); if (front.getBackDomain() == space) { out.scale(-1); ! } ! log.info("create"); Set<Surface> frame1 = generateFrame(cut1, field.getEdges(), out); ! Set<Surface> frame2 = generateFrame(cut2, field.getEdges(), out); frame1.addAll(frame2); ! space.addAll(frame1); Geometry.simplifyGeometry(frame1); } *************** *** 432,441 **** } if (net != null) { ! List outline = netOutline(net); ! Iterator it = outline.iterator(); ! List outlineCopies = new LinkedList(); ! while (it.hasNext()) { ! outlineCopies.add(((Edge)it.next()).copy()); ! } if (!outlineCopies.isEmpty()) { /* make the shell of the facade */ --- 438,446 ---- } if (net != null) { ! List<Edge> outline = netOutline(net); ! List<Edge> outlineCopies = new LinkedList<Edge>(); ! for (Edge e : outline) { ! outlineCopies.add(e.copy()); ! } if (!outlineCopies.isEmpty()) { /* make the shell of the facade */ *************** *** 447,457 **** Geometry.holeAnalysis(frameSurfEx); /* Put holes into the shell */ ! Iterator fields = net.getSurfaces().iterator(); ! while (fields.hasNext()) { ! Surface field = (Surface)fields.next(); Map offsetMap = new HashMap(); Iterator fieldEdges = field.getEdges().iterator(); ! Map envF = field.getParameters().environment(); ! while (fieldEdges.hasNext()) { Edge e = (Edge)fieldEdges.next(); --- 452,459 ---- Geometry.holeAnalysis(frameSurfEx); /* Put holes into the shell */ ! for (Surface field : net.getSurfaces()) { Map offsetMap = new HashMap(); Iterator fieldEdges = field.getEdges().iterator(); ! Map envF = field.getParameters().environment(); while (fieldEdges.hasNext()) { Edge e = (Edge)fieldEdges.next(); *************** *** 545,585 **** Geometry.holeAnalysis(hole); ! } /*else if (frameSize == 0) { ! Map offmap1 = new HashMap<Edge, Double>(); ! for (Object o : hole.getEdges()) { ! Edge e = (Edge)o; ! offmap1.put(e, FRAME_IDENTATION); ! } ! Surface in = new Surface(Edge.placeOffset(hole.getEdges(), hole, offmap1)); ! Space f = new Space(type + " Frame", ! Space.CONSTRUCTION, ! Space.ELEMENT_LEVEL, ! true); ! Space g = new Space("Glass", ! Space.CONSTRUCTION, ! Space.ELEMENT_LEVEL, ! true); ! g.setTransparent(true); ! space.add(g); ! space.add(f); ! assignSame(front, in, space, f); ! assignSame(front, hole, space, g); ! in = space.insert(in); ! Geometry.holeAnalysis(in); ! ! Set sides = new HashSet(); ! Surface inEx = extrudeIntoSpace(in, FRAME_DEPTH, sides); ! space.add(inEx); ! assignSame(front, inEx, space, frame); ! Geometry.holeAnalysis(inEx); ! ! //assignOpposite(front, hole, space, f); ! Geometry.holeAnalysis(hole); ! }*/ } /** * Finds the outline of a net, if it makes sence. ! * The outline most 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. --- 547,556 ---- Geometry.holeAnalysis(hole); ! } } /** * 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. *************** *** 587,596 **** * @return a list of connected edges making up the net outline */ ! private List netOutline(Net net) { /*Find outer edges*/ - Iterator edges = net.getEdges().iterator(); Set<Edge> outer = new HashSet<Edge>(); ! while (edges.hasNext()) { ! Edge current = (Edge)edges.next(); if (current.getSurfaces().size() == 1) { outer.add(current); --- 558,565 ---- * @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() == 1) { outer.add(current); *************** *** 607,614 **** while (!doneAll) { Edge next = null; ! boolean done = false; ! Iterator nextEdges = nextVertex.getEdges().iterator(); ! while (nextEdges.hasNext()) { ! Object e = nextEdges.next(); if (outer.contains(e)) { next = (Edge)e; --- 576,580 ---- while (!doneAll) { Edge next = null; ! for (Edge e : nextVertex.getEdges()) { if (outer.contains(e)) { next = (Edge)e; *************** *** 636,640 **** } } ! return new LinkedList(); } --- 602,606 ---- } } ! return new LinkedList<Edge>(); } *************** *** 781,784 **** --- 747,858 ---- return Space.SPACE_LEVEL; } + + private Set<Surface> generateFrame2(Surface cut, + Surface contourSurf, + Space frameSpace, + Vertex out) { + Set<Surface> generatedSurfaces = new HashSet<Surface>(); + if (contourSurf.getEdges().size() < 3) { + return generatedSurfaces; + } + if (!rightHand(contourSurf, out)) { + contourSurf.flip(); + } + List<Edge> contour = contourSurf.getEdges(); + + Edge first = contour.get(0); + Edge second = contour.get(1); + Vertex common = Edge.commonVertex(first, second); + Vertex unCommon = first.otherVertex(common); + Vertex firstDir = common.minus(unCommon); + if (cut.normal().dot(firstDir) > 0) { + cut.setFrontDomain(frameSpace); + } else { + cut.setBackDomain(frameSpace); + } + Vertex i = out.cross(firstDir); + firstDir.normalize(); + out.normalize(); + i.normalize(); + CoordinateSystem cs = new CoordinateSystem(i, out, firstDir, unCommon); + List<Edge> cutEdges = cut.getEdges(); + Geometry.unTranslateGeometry(Geometry.collect(cutEdges), cs); + + Edge current = first; + for (Edge next : contour) { + if (next == first) { + continue; + } + Collection<Surface> extrusion = makeExtrusion(current, next, cutEdges); + cutEdges = findNewCutEdges(cutEdges, extrusion); + generatedSurfaces.addAll(extrusion); + current = next; + } + Collection<Surface> extrusion = makeExtrusion(contour.get(contour.size() - 1), + first, cutEdges); + cutEdges = findNewCutEdges(cutEdges, extrusion); + for (int k = 0; k < cutEdges.size(); k++) { + Edge oldEdge = cut.getEdges().get(k); + for (Surface s : oldEdge.getSurfaces()) { + s.replaceSingle(oldEdge, cutEdges.get(k)); + } + } + generatedSurfaces.addAll(extrusion); + return generatedSurfaces; + } + + private static Collection<Surface> makeExtrusion(Edge e1, Edge e2, + List<Edge> cutEdges) { + double angle = angle(e1, e2); + Vertex shared = Edge.commonVertex(e1, e2); + Vertex i = e2.otherVertex(shared).minus(shared); + Vertex j = e1.otherVertex(shared).minus(shared); + Vertex n = i.cross(j); + j = n.cross(i); + n.normalize(); + j.normalize(); + i.normalize(); + CoordinateSystem local = new CoordinateSystem(i, j, n, new Vertex(0, 0, 0)); + Vertex angleV = new Vertex(Math.sin(angle / 2), -Math.cos(angle / 2), 0); + angleV = local.unTranslate(angleV); + Plane plane = new Plane(angleV.getX(), angleV.getY(), angleV.getZ(), shared); + j.scale(-1); + Collection<Surface> extrusion = Edge.extrude(cutEdges, j, plane); + return extrusion; + } + + private static List<Edge> findNewCutEdges(List<Edge> contour, Collection<Surface> extrusion) { + Map<Edge, Edge> old2new = new HashMap<Edge, Edge>(); + for (Surface s : extrusion) { + List<Edge> edges = s.getEdges(); + Edge contourEdge = null; + for (Edge e : edges) { + if (contour.contains(e)) { + contourEdge = e; + } + } + if (contourEdge == null) { + log.error("Surface: " + s + " was not extruded from contour: " + contour); + continue; + } + for (Edge e : edges) { + if (Edge.commonVertex(e, contourEdge) == null) { + old2new.put(contourEdge, e); + } + } + } + List<Edge> newContour = new LinkedList<Edge>(); + for (Edge old : contour) { + Edge edge = old2new.get(old); + if (edge != null) { + newContour.add(edge); + } else { + log.error("Contour edge: " + old + + " does not have an adjacent edge in: " + extrusion); + } + } + return newContour; + } + /** *************** *** 791,796 **** private static Set<Surface> generateFrame(Surface cut, List<Edge> contour, Vertex out) { Surface test = new Surface(contour); ! boolean rightHand = rightHand(test, out); ! if (!rightHand) { test.flip(); contour = test.getEdges(); --- 865,869 ---- private static Set<Surface> generateFrame(Surface cut, List<Edge> contour, Vertex out) { Surface test = new Surface(contour); ! if (!rightHand(test, out)) { test.flip(); contour = test.getEdges(); *************** *** 816,820 **** CoordinateSystem cs = new CoordinateSystem(i, j, n, origin); Set post = genFramePost(cut, current.getLength(), bottomAngle, topAngle); ! unTranslateGeometry(post, cs); surfs.addAll(post); prev = current; --- 889,893 ---- CoordinateSystem cs = new CoordinateSystem(i, j, n, origin); Set post = genFramePost(cut, current.getLength(), bottomAngle, topAngle); ! Geometry.unTranslateGeometry(post, cs); surfs.addAll(post); prev = current; *************** *** 831,835 **** CoordinateSystem cs = new CoordinateSystem(i, j, n, origin); Set post = genFramePost(cut, current.getLength(), bottomAngle, topAngle); ! unTranslateGeometry(post, cs); surfs.addAll(post); Iterator surfIt = surfs.iterator(); --- 904,908 ---- CoordinateSystem cs = new CoordinateSystem(i, j, n, origin); Set post = genFramePost(cut, current.getLength(), bottomAngle, topAngle); ! Geometry.unTranslateGeometry(post, cs); surfs.addAll(post); Iterator surfIt = surfs.iterator(); *************** *** 843,865 **** - /** - * untranslates a set of geometry. - * @param geometry the geometry - * @param system the coordinate system to untranslate according to - */ - private static void unTranslateGeometry(Set geometry, CoordinateSystem system) { - List<Vertex> vertices = new LinkedList<Vertex>(Geometry.collect(geometry)); - List<Vertex> unTranslatedVertices = system.unTranslate(vertices); - Iterator it = vertices.iterator(); - Iterator unTranslatedIt = unTranslatedVertices.iterator(); - while (it.hasNext() && unTranslatedIt.hasNext()) { - Vertex v = (Vertex)it.next(); - Vertex vUnTranslated = (Vertex)unTranslatedIt.next(); - v.setX(vUnTranslated.getX()); - v.setY(vUnTranslated.getY()); - v.setZ(vUnTranslated.getZ()); - } - } - private static Surface cutType1() { List<Vertex> vl = new LinkedList<Vertex>(); --- 916,919 ---- |