[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.112, 1.113 Surface.java
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-04-22 08:13:56
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv14268/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Surface.java Camera.java Space.java Project.java Log Message: Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.227 retrieving revision 1.228 diff -C2 -d -r1.227 -r1.228 *** Surface.java 25 Jun 2009 23:28:42 -0000 1.227 --- Surface.java 22 Apr 2010 08:13:47 -0000 1.228 *************** *** 514,520 **** getEdges().toArray(edges); - // FIXME Generalize to - // replace one edge with list of edges. - for (int i = 0; i < edges.length; i++) { Edge current = edges[i]; --- 514,517 ---- *************** *** 1273,1292 **** */ public boolean surrounds(Surface hole, boolean boundary) { ! Iterator iter = hole.getVertices().iterator(); ! while (iter.hasNext()) { ! Vertex current = (Vertex) iter.next(); ! if (boundary) { ! if (!onBoundary(current)) { ! if (!surrounds(current)) { ! return false; } } } else { ! if (!surrounds(current)) { ! return false; ! } } } - return true; } --- 1270,1297 ---- */ public boolean surrounds(Surface hole, boolean boundary) { ! if (hole != null) { ! List<Vertex> vertices = hole.getVertices(); ! if (vertices != null) { ! for (Vertex current : vertices) { ! if (boundary) { ! if (!onBoundary(current)) { ! if (!surrounds(current)) { ! return false; ! } ! } ! } else { ! if (!surrounds(current)) { ! return false; ! } } } + return true; } else { ! throw new Error("vertices null"); } + } else { + System.out.println("hole " + hole); + return false; } } *************** *** 2084,2088 **** Collection<Vertex> vertices = this.getVertices(); if (vertices == null) { ! throw new Exception("surface inconsistent"); } return true; --- 2089,2093 ---- Collection<Vertex> vertices = this.getVertices(); if (vertices == null) { ! throw new Exception("surface " + this + " inconsistent"); } return true; Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.112 retrieving revision 1.113 diff -C2 -d -r1.112 -r1.113 *** Edge.java 5 Feb 2010 13:32:50 -0000 1.112 --- Edge.java 22 Apr 2010 08:13:47 -0000 1.113 *************** *** 514,524 **** e2.setStrippled(this.getStrippled()); added.add(e2); if (getOwner() != null) { getOwner().add(e1); getOwner().add(e2); ! Set surfaces = getSurfaces(); ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); current.replace(this, e1, e2); } --- 514,523 ---- e2.setStrippled(this.getStrippled()); added.add(e2); + if (getOwner() != null) { getOwner().add(e1); getOwner().add(e2); ! Set<Surface> surfaces = getSurfaces(); ! for (Surface current : surfaces) { current.replace(this, e1, e2); } Index: Camera.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** Camera.java 5 Feb 2010 13:32:50 -0000 1.62 --- Camera.java 22 Apr 2010 08:13:47 -0000 1.63 *************** *** 789,792 **** --- 789,809 ---- printer.println(" </Camera>"); } + + /** + * Returns true of space is visible + * @param space Space + * @return true of space is visible + */ + public boolean visible(Space space) { + if (space == null) { + return true; + } else { + if (hiddenGeometrics.contains(space)) { + return false; + } else { + return visible(space.getOwner()); + } + } + } } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.187 retrieving revision 1.188 diff -C2 -d -r1.187 -r1.188 *** Project.java 9 Mar 2010 13:02:00 -0000 1.187 --- Project.java 22 Apr 2010 08:13:47 -0000 1.188 *************** *** 114,118 **** private static boolean useDisplayLists; private static boolean doExport; ! private HashMap cameras = new HashMap(); --- 114,118 ---- private static boolean useDisplayLists; private static boolean doExport; ! private static boolean doExportXml; private HashMap cameras = new HashMap(); *************** *** 1150,1153 **** --- 1150,1155 ---- } else if (a.getName().equals("Export")) { doExport = ((Boolean) a.getValue()).booleanValue(); + } else if (a.getName().equals("Export XML")) { + doExportXml = ((Boolean) a.getValue()).booleanValue(); } else if (a.getName().equals("Export Path")) { setExportPath((String)a.getValue()); *************** *** 1171,1174 **** --- 1173,1177 ---- res.add(new Attribute("Export", Boolean.valueOf(doExport))); res.add(new Attribute("Export Path", getExportPath())); + res.add(new Attribute("Export XML", Boolean.valueOf(doExportXml))); res.add(new Attribute("Brunata Server", Boolean.valueOf(brunata))); res.add(new Attribute("Script", script)); *************** *** 1785,1843 **** } - private void processBoundary1(Area location) { - if (location.getChildren().isEmpty()) { - // - } else { - double xmin = Double.POSITIVE_INFINITY; - double xmax = Double.NEGATIVE_INFINITY; - double ymin = Double.POSITIVE_INFINITY; - double ymax = Double.NEGATIVE_INFINITY; - - LinkedList<Boundary> internals = new LinkedList(); - for (Area current : location.getChildren()) { - processBoundary1(current); - Boundary external = current.getExternalBoundary(); - if (external != null) { - internals.add(current.getExternalBoundary()); - } else { - System.out.println("failed to create boundary on " + current); - } - } - LinkedList<Point2d> points = new LinkedList(); - for (Boundary boundary : internals) { - points.addAll(boundary.getPoints()); - } - for (Point2d current : points) { - if (current.getX() < xmin) { - xmin = current.getX(); - } - if (current.getX() > xmax) { - xmax = current.getX(); - } - if (current.getY() < ymin) { - ymin = current.getY(); - } - if (current.getY() > ymax) { - ymax = current.getY(); - } - } - Point2d p1 = new Point2d(xmin, ymin); - Point2d p2 = new Point2d(xmin, ymax); - Point2d p3 = new Point2d(xmax, ymax); - Point2d p4 = new Point2d(xmax, ymin); - Segment s1 = new Segment(p1, p2); - Segment s2 = new Segment(p2, p3); - Segment s3 = new Segment(p3, p4); - Segment s4 = new Segment(p4, p1); - Boundary external = new Boundary(); - external.add(s1); - external.add(s2); - external.add(s3); - external.add(s4); - location.setExternalBoundary(external); - - } - } - /** * --- 1788,1791 ---- *************** *** 1856,1867 **** } /** ! * ! * @param out OutputStream */ ! public void exportOBJ(OutputStream out) { ! PrintStream printer = new PrintStream(out); ! List<Space> spaces = world.collectSpaces(); ! List<Space> constructs = new LinkedList(); for (Space current : spaces) { --- 1804,1819 ---- } + /** ! * Returns true of space is visible ! * @param space Space ! * @return true of space is visible */ ! public boolean visible(Space space) { ! return getCurrentCamera().visible(space); ! } ! ! ! private List<Space> constructs(Collection<Space> spaces) { List<Space> constructs = new LinkedList(); for (Space current : spaces) { *************** *** 1870,1880 **** } } ! List<Space> containers = new LinkedList(); for (Space current : constructs) { Space tesselation = current.tesselate(); tesselation.setMaterial(current.getMaterial()); containers.add(tesselation); } ! Space.export(containers, printer); } --- 1822,1941 ---- } } ! return constructs; ! } ! ! private List<Material> materials(Collection<Space> constructs) { ! Set<Material> mark = new HashSet(); for (Space current : constructs) { + Material material = current.getMaterial(); + if (material != null) { + mark.add(material); + } + } + return new LinkedList(mark); + } + + private boolean mkdirs(File file) { + if (file.isDirectory()) { + return true; + } else { + if (!file.exists()) { + return file.mkdirs(); + } + } + return false; + } + + private void cleandir(File directory) { + for (File current : directory.listFiles()) { + if (current.isFile()) { + current.delete(); + } + } + } + + /** + * + * @param path String + * @throws Exception Exception + */ + public void exportXmlAll(String path) throws Exception { + File file = new File(path); + if (mkdirs(file)) { + cleandir(file); + List<Space> constructs = constructs(world.collectSpaces()); + List<Material> materials = materials(constructs); + File mtlfile = new File(file, "materials.mtl"); + exportMtl(materials, new FileOutputStream(mtlfile)); + int count = 1; + List<String> names = new LinkedList(); + for (Space current : constructs) { + + String name = current.getName(); + if (name.length() == 0) { + name = "construct-" + count++; + } + if (visible(current)) { + names.add(name); + File objfile = new File(file, name + ".obj"); + OutputStream out = new FileOutputStream(objfile); + PrintStream printer = new PrintStream(out); + printer.println("mtllib materials.mtl"); + exportObj(current, out); + } + } + { + File scnfile = new File(file, "scene.xml"); + PrintStream printer = new PrintStream(new FileOutputStream(scnfile)); + printer.println("<Scene>"); + for (String current : names) { + printer.println(" <ObjFile name=\"" + current + ".obj\"/>"); + } + printer.println("</Scene>"); + } + } + } + + /** + * + * @param path String + * @throws Exception Exception + */ + public void exportObjAll(String path) throws Exception { + List<Space> constructs = constructs(world.collectSpaces()); + List<Material> materials = materials(constructs); + exportObj(constructs, materials, path); + } + + private void exportObj(List<Space> spaces, + List<Material> materials, + String path) throws Exception { + exportMtl(materials, new FileOutputStream(path + ".mtl")); + OutputStream out = new FileOutputStream(path + ".obj"); + PrintStream printer = new PrintStream(out); + printer.println("mtllib " + path + ".mtl"); + exportObj(spaces, out); + } + + private void exportObj(List<Space> spaces, OutputStream out) { + List<Space> containers = new LinkedList(); + for (Space current : spaces) { Space tesselation = current.tesselate(); tesselation.setMaterial(current.getMaterial()); containers.add(tesselation); } ! Space.export(containers, new PrintStream(out)); ! } ! ! private void exportObj(Space construct, OutputStream out) { ! List<Space> spaces = new LinkedList(); ! spaces.add(construct); ! exportObj(spaces, out); ! } ! ! private void exportMtl(List<Material> materials, OutputStream out) { ! for (Material current : getMaterials()) { ! current.export(out); ! } } *************** *** 1885,1891 **** try { export(getExportPath()); ! } catch (IOException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); } } --- 1946,1951 ---- try { export(getExportPath()); ! } catch (Exception e) { ! // empty } } *************** *** 1894,1901 **** * Export to the given path * @param path String ! * @throws IOException Error */ ! public void export(String path) throws IOException { ! exportXml(path); } --- 1954,1965 ---- * Export to the given path * @param path String ! * @throws Exception Exception */ ! public void export(String path) throws Exception { ! if (doExportXml) { ! exportXmlAll(path); ! } else { ! exportObjAll(path); ! } } *************** *** 1928,1932 **** } } - List<Space> containers = new LinkedList(); for (Space current : constructs) { Space tesselation = current.tesselate(); --- 1992,1995 ---- *************** *** 1950,1957 **** Instance instance = (Instance) current; Space proto = instance.getProto(); ! if (proto.getName().equals("Light")) { ! String value = "<Light" + " id=\"" + instance.getId() + "\"" + " name=\"" + instance.getName() + "\"" + ">"; printer.println(value); --- 2013,2022 ---- Instance instance = (Instance) current; Space proto = instance.getProto(); ! if (proto.getName().equals("OmniLight")) { ! String luminance = (String) instance.getParameters().get("luminance"); ! String value = "<OmniLight" + " id=\"" + instance.getId() + "\"" + " name=\"" + instance.getName() + "\"" + + " luminance=\"" + luminance + "\"" + ">"; printer.println(value); *************** *** 1963,1968 **** + "/>"; printer.println(str); ! printer.println("</Light>"); } } } --- 2028,2049 ---- + "/>"; printer.println(str); ! printer.println("</OmniLight>"); ! } ! if (proto.getName().equals("SpotLight")) { ! String value = "<SpotLight" ! + " id=\"" + instance.getId() + "\"" ! + " name=\"" + instance.getName() + "\"" ! + ">"; ! printer.println(value); ! Vertex origin = instance.getAnchor().getOrigin(); ! String str = " <position" ! + " x=\"" + origin.getX() + "\"" ! + " y=\"" + origin.getY() + "\"" ! + " z=\"" + origin.getZ() + "\"" ! + "/>"; ! printer.println(str); ! printer.println("</SpotLight>"); } + } } *************** *** 1973,2002 **** /** - * Export object file to given path - * @param path String - * @throws IOException Exception - */ - public void exportObj(String path) throws IOException { - System.out.println("export to " + path + ".obj"); - String objname = path + ".obj"; - String mtlname = path + ".mtl"; - { - OutputStream out = new FileOutputStream(new File(mtlname)); - for (Material current : getMaterials()) { - current.export(out); - } - out.close(); - } - { - OutputStream out = new FileOutputStream(new File(objname)); - PrintStream printer = new PrintStream(out); - printer.println("mtllib " + mtlname); - exportOBJ(out); - out.close(); - } - } - - - /** * */ --- 2054,2057 ---- *************** *** 2133,2136 **** --- 2188,2192 ---- } + } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.249 retrieving revision 1.250 diff -C2 -d -r1.249 -r1.250 *** Space.java 26 Feb 2010 13:48:09 -0000 1.249 --- Space.java 22 Apr 2010 08:13:47 -0000 1.250 *************** *** 384,387 **** --- 384,411 ---- /** + * + * @param vertex Vertex + * @return Vertex + */ + public Vertex insertAll(Vertex vertex) { + Space space = (Space) this; + if (vertex.getOwner() != null) { + if (vertex.getOwner() == space) { + return vertex; + } else { + vertex = vertex.copy(); + } + } + + Vertex actual = space.findVertex(vertex); + + if (actual == null) { + actual = vertex; + space.add(actual); + } + return actual; + } + + /** * Insert a vertex * @param vertex The vertex *************** *** 403,413 **** actual = vertex; space.add(actual); ! Set es = space.findEdge(actual); ! if (es.size() > 0) { ! Iterator iter = es.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! current.split(actual); ! } } } --- 427,434 ---- actual = vertex; space.add(actual); ! ! Set<Edge> es = space.findEdge(actual); ! for (Edge current : es) { ! current.split(actual); } } *************** *** 730,733 **** --- 751,796 ---- /** + * + * @param surface Surface + */ + public void insertAll(Surface surface) { + List<Edge> edges = surface.getEdges(); + List<Edge> lst = new LinkedList<Edge>(); + for (Edge current : edges) { + lst.add(insertAll(current)); + } + surface.setEdges(lst); + add(surface); + } + + /** + * @param edge Edge + * @return Edge + */ + public Edge insertAll(Edge edge) { + if (edge.getOwner() == this) { + return edge; + } + + Vertex from = insertAll(edge.getFrom()); + Vertex to = insertAll(edge.getTo()); + if (from == to) { + return null; + } + + edge.setFrom(from); + edge.setTo(to); + + Edge existing = findEdge(edge); + + if (existing != null) { + return existing; + } else { + add(edge); + return edge; + } + } + + /** * Insert a surface * @param surface The surface *************** *** 736,747 **** public Surface insert(Surface surface) { List<Edge> edges = surface.getEdges(); - edges = surface.getEdges(); List<Edge> lst = new LinkedList<Edge>(); ! { ! Iterator<Edge> iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! lst.add(insert(current)); ! } } surface.setEdges(lst); --- 799,805 ---- public Surface insert(Surface surface) { List<Edge> edges = surface.getEdges(); List<Edge> lst = new LinkedList<Edge>(); ! for (Edge current : edges) { ! lst.add(insert(current)); } surface.setEdges(lst); *************** *** 1659,1676 **** List<Surface> triangles = tesselator.tesselate(current); for (Surface triangle : triangles) { ! Surface inserted = holder.insert(triangle); ! Vertex n = inserted.normal(); if (n.dot(normal) > 0) { if (current.getFrontDomain() == this) { ! inserted.setFrontDomain(interior); } else { ! inserted.setBackDomain(interior); } } else { if (current.getFrontDomain() == this) { ! inserted.setBackDomain(interior); } else { ! inserted.setFrontDomain(interior); } } --- 1717,1735 ---- List<Surface> triangles = tesselator.tesselate(current); + for (Surface triangle : triangles) { ! holder.insertAll(triangle); ! Vertex n = triangle.normal(); if (n.dot(normal) > 0) { if (current.getFrontDomain() == this) { ! triangle.setFrontDomain(interior); } else { ! triangle.setBackDomain(interior); } } else { if (current.getFrontDomain() == this) { ! triangle.setBackDomain(interior); } else { ! triangle.setFrontDomain(interior); } } *************** *** 1688,1693 **** Space tesselation = tesselate(); tesselation.export(out); - //getOwner().add(holder); - //Project.getInstance().changed(Project.getInstance()); } --- 1747,1750 ---- |