[Bprocessor-commit] facade/src/net/sourceforge/bprocessor/facade/modellor NetFacadeModellor.java,
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2007-03-15 10:15:12
|
Update of /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25870/src/net/sourceforge/bprocessor/facade/modellor Modified Files: NetFacadeModellor.java Log Message: improved the drawing of frames in the double posted facades Index: NetFacadeModellor.java =================================================================== RCS file: /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor/NetFacadeModellor.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** NetFacadeModellor.java 13 Mar 2007 09:49:11 -0000 1.20 --- NetFacadeModellor.java 15 Mar 2007 10:15:08 -0000 1.21 *************** *** 125,129 **** */ public Modellor newInstance(Space s) { - //genFrameTest(); NetFacadeModellor mod = new NetFacadeModellor(); mod.setSpace(s); --- 125,128 ---- *************** *** 373,378 **** while (fields.hasNext()) { Surface field = (Surface)fields.next(); ! //assuming here that each window is a rectangle. ! if (field.getEdges().size() == 4) { Surface cut1 = cutType1(); Surface cut2 = cutType2(); --- 372,376 ---- while (fields.hasNext()) { Surface field = (Surface)fields.next(); ! if (field.getEdges().size() > 3) { Surface cut1 = cutType1(); Surface cut2 = cutType2(); *************** *** 381,406 **** cut2.setBackDomain(frame); cut2.setFrontDomain(frame); ! ! Iterator it = field.getEdges().iterator(); ! Edge e1 = (Edge)it.next(); ! Edge e2 = (Edge)it.next(); ! Set<Surface> frame1 = generateFrame(cut1, e2.getLength(), e1.getLength()); ! Set<Surface> frame2 = generateFrame(cut2, e2.getLength(), e1.getLength()); ! ! frame.removeSurface(cut1); ! frame.removeSurface(cut2); ! Vertex common = Edge.commonVertex(e1, e2); ! Vertex i = e1.otherVertex(common).minus(common); ! Vertex n = e2.otherVertex(common).minus(common); ! Vertex j = front.normal(); if (front.getBackDomain() == space) { ! j.scale(-1); } ! i.normalize(); ! j.normalize(); ! n.normalize(); ! CoordinateSystem anker = new CoordinateSystem(i, j, n, common); ! unTranslateGeometry(frame1, anker); ! unTranslateGeometry(frame2, anker); space.addAll(frame1); space.addAll(frame2); --- 379,390 ---- 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); space.addAll(frame1); space.addAll(frame2); *************** *** 646,650 **** Set tops = new HashSet(); Surface top = s.extrusionall(delta * deltaCorrection, sides, tops); - tops.addAll(sides); for (Object o1 : tops) { --- 630,633 ---- *************** *** 758,802 **** return getGeneralName(); } ! /** * Generates a frame based an a surface descibing a cut of the frame * @param cut the cut surface ! * @param height height of the frame ! * @param width with of the frame * @return the set of surfaces in the frame */ ! private static Set<Surface> generateFrame(Surface cut, double height, double width) { ! Set topPost = genFramePost(cut, width); ! Set leftPost = genFramePost(cut, height); ! Set rightPost = genFramePost(cut, height); ! Set bottomPost = genFramePost(cut, width); ! CoordinateSystem csTop = new CoordinateSystem(new Vertex(0, 0, -1), ! new Vertex(0, 1, 0), ! new Vertex(1, 0, 0), ! new Vertex(0, 0, height)); ! CoordinateSystem csRight = new CoordinateSystem(new Vertex(-1, 0, 0), ! new Vertex(0, 1, 0), ! new Vertex(0, 0, -1), ! new Vertex(width, 0, height)); ! CoordinateSystem csBottom = new CoordinateSystem(new Vertex(0, 0, 1), ! new Vertex(0, 1, 0), ! new Vertex(-1, 0, 0), ! new Vertex(width, 0, 0)); ! unTranslateGeometry(bottomPost, csBottom); ! unTranslateGeometry(rightPost, csRight); ! unTranslateGeometry(topPost, csTop); ! Set<Surface> surfaces = new HashSet<Surface>(); ! HashSet surfs = new HashSet(leftPost); ! surfs.addAll(rightPost); ! surfs.addAll(topPost); ! surfs.addAll(bottomPost); ! Iterator it = surfs.iterator(); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! surfaces.add(s); } return surfaces; } /** --- 741,805 ---- return getGeneralName(); } ! /** * Generates a frame based an a surface descibing a cut of the frame * @param cut the cut surface ! * @param contour the outer contour of the frame ! * @param out a vector pointing towards the outside of the frame * @return the set of surfaces in the frame */ ! 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(); ! } Set<Surface> surfaces = new HashSet<Surface>(); ! HashSet surfs = new HashSet(); ! if (contour.size() > 2) { ! Vertex j = out; ! Iterator it = contour.iterator(); ! Edge prev = contour.get(contour.size() - 1); ! Edge current = (Edge)it.next(); ! Edge next; ! double bottomAngle = angle(prev, current); ! double topAngle; ! while (it.hasNext()) { ! next = (Edge)it.next(); ! topAngle = angle(current, next); ! Vertex origin = Edge.commonVertex(current, prev); ! Vertex n = current.otherVertex(origin).minus(origin); ! Vertex i = j.cross(n); ! n.normalize(); ! i.normalize(); ! CoordinateSystem cs = new CoordinateSystem(i, j, n, origin); ! Set post = genFramePost(cut, current.getLength(), bottomAngle, topAngle); ! unTranslateGeometry(post, cs); ! surfs.addAll(post); ! prev = current; ! current = next; ! bottomAngle = topAngle; ! } ! next = contour.get(0); ! topAngle = angle(current, next); ! Vertex origin = Edge.commonVertex(current, prev); ! Vertex n = current.otherVertex(origin).minus(origin); ! Vertex i = j.cross(n); ! n.normalize(); ! i.normalize(); ! 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(); ! while (surfIt.hasNext()) { ! Surface s = (Surface)surfIt.next(); ! surfaces.add(s); ! } } return surfaces; } + /** *************** *** 818,822 **** } } ! private static Surface cutType1() { List<Vertex> vl = new LinkedList<Vertex>(); --- 821,825 ---- } } ! private static Surface cutType1() { List<Vertex> vl = new LinkedList<Vertex>(); *************** *** 854,858 **** return cut; } ! /** * Generates one frame post. --- 857,861 ---- return cut; } ! /** * Generates one frame post. *************** *** 861,871 **** * @return the surfaces of the new post */ ! private static Set genFramePost(Surface cut, double length) { Surface copy = cut.copy(new HashMap()); copy.setBackDomain(cut.getBackDomain()); copy.setFrontDomain(cut.getFrontDomain()); ! Plane topPlane = new Plane(1, 0, 1, new Vertex(0, 0, length / 2)); ! Plane bottomPlane = new Plane(-1, 0, 1, new Vertex(0 , 0, -length / 2)); ! Set surfaces = new HashSet(); surfaces.add(copy); --- 864,877 ---- * @return the surfaces of the new post */ ! private static Set genFramePost(Surface cut, double length, double bottomAngle, double topAngle) { Surface copy = cut.copy(new HashMap()); copy.setBackDomain(cut.getBackDomain()); copy.setFrontDomain(cut.getFrontDomain()); ! Plane topPlane = new Plane(Math.cos(topAngle / 2), 0, ! Math.sin(topAngle / 2), ! new Vertex(0, 0, length / 2)); ! Plane bottomPlane = new Plane(Math.cos(-bottomAngle / 2), 0, ! Math.sin(-bottomAngle / 2), ! new Vertex(0 , 0, -length / 2)); Set surfaces = new HashSet(); surfaces.add(copy); *************** *** 878,880 **** --- 884,922 ---- return surfaces; } + + private static double angle(Edge e1, Edge e2) { + double angle = Double.NaN; + Vertex common = Edge.commonVertex(e1, e2); + if (common != null) { + Vertex dir1 = e1.otherVertex(common).minus(common); + Vertex dir2 = e2.otherVertex(common).minus(common); + angle = dir1.angle(dir2); + } + return angle; + } + + /** + * Test if a surface is right hand turned around a vector + * @param s surface + * @param j vector + * @return true if the surface is right hand turned + */ + private static boolean rightHand(Surface s, Vertex j) { + double determinant = 0; + List<Edge> el = s.getEdges(); + if (el.size() > 2) { + Edge prev = el.get(el.size() - 1); + for (Edge current : el) { + Vertex origin = Edge.commonVertex(current, prev); + Vertex n = current.otherVertex(origin).minus(origin); + Vertex testI = prev.otherVertex(origin).minus(origin); + CoordinateSystem testCS = new CoordinateSystem(testI, j, n, origin); + determinant = testCS.determinant(); + if (Math.abs(determinant) > 0.000001) { + break; + } + } + } + return determinant > 0; + } } |