[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Project.java, 1.199, 1.200
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-12-08 11:37:37
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv29684/src/net/sourceforge/bprocessor/model Modified Files: Project.java Log Message: Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.199 retrieving revision 1.200 diff -C2 -d -r1.199 -r1.200 *** Project.java 26 Nov 2010 14:20:31 -0000 1.199 --- Project.java 8 Dec 2010 11:37:29 -0000 1.200 *************** *** 44,56 **** import org.apache.log4j.Logger; - import dk.au.perpos.spatialsupport.locationmodel.Location; - import dk.au.perpos.spatialsupport.routefinding.Area; - import dk.au.perpos.spatialsupport.routefinding.Boundary; - import dk.au.perpos.spatialsupport.routefinding.LocationModel; - import dk.au.perpos.spatialsupport.routefinding.Opening; - import dk.au.perpos.spatialsupport.routefinding.Point2d; - import dk.au.perpos.spatialsupport.routefinding.Segment; - import dk.au.perpos.spatialsupport.routefinding.io.PPLMPrinter; - /** * The Project --- 44,47 ---- *************** *** 1308,1368 **** } - - private boolean eq(Point2d p1, - Point2d p2) { - if (p1.getX() != p2.getX()) { - return false; - } - if (p1.getY() != p2.getY()) { - return false; - } - return true; - } - private boolean eq(Segment s1, Segment s2) { - if (eq(s1.getFrom(), s2.getFrom()) && eq(s1.getTo(), s2.getTo())) { - return true; - } - if (eq(s1.getFrom(), s2.getTo()) && eq(s1.getTo(), s2.getFrom())) { - return true; - } - return false; - } - private Segment find(Area location, Segment segment) { - List<Boundary> all = new LinkedList(); - all.add(location.getExternalBoundary()); - all.addAll(location.getInternalBoundaries()); - for (Boundary boundary : all) { - for (Segment current : boundary.getSegments()) { - if (eq(current, segment)) { - return current; - } - } - } - return null; - } - - private List<Point2d> convert(List<Vertex> vertices) { - List<Point2d> points = new LinkedList(); - for (Vertex current : vertices) { - points.add(convert(current)); - } - return points; - } - - private Point2d convert(Vertex vertex) { - Point2d point - = new Point2d(); - point.setX(vertex.getX()); - point.setY(vertex.getY()); - return point; - } - - private Segment convert(Edge edge) { - Segment segment = new Segment(); - segment.setFrom(convert(edge.getFrom())); - segment.setTo(convert(edge.getTo())); - return segment; - } - @SuppressWarnings("unused") private List<Edge> bounds(List<Surface> surfaces) { --- 1299,1302 ---- *************** *** 1379,1670 **** } - private List<Area> createLocationModel(Space space, int level, - Map<Surface, Area> locations, Map<Edge, List<Opening>> openings) { - List<Area> locs = new LinkedList(); - List<Surface> envelope = new LinkedList(space.getEnvelope()); - int no = 0; - if (envelope.size() > 0) { - for (Surface current : envelope) { - locs.add(createLocationModel(space, level, locations, openings, current, no)); - no++; - } - } else { - locs.add(createLocationModel(space, level, locations, openings, null, 0)); - } - return locs; - } - - private Area createLocationModel(Space space, int level, - Map<Surface, Area> locations, Map<Edge, List<Opening>> openings, - Surface surface, int no) { - Area location = new Area(); - if (no > 0) { - location.setId(space.getName() + "-" + no); - } else { - System.out.println("using just the name " + space.getName()); - location.setId(space.getName()); - } - if (level == 1) { - location.setDescription("Site"); - } else if (level == 2) { - location.setDescription("Building"); - } else if (level == 3) { - location.setDescription("Floor"); - } else { - location.setDescription("Room"); - } - - if (surface != null) { - List<Edge> all = new LinkedList(surface.getEdges()); - List<Vertex> vertices = surface.getVertices(); - - { - Vertex first = vertices.get(0); - double z = first.getZ(); - location.setFloor(z); - location.setHeight(4); - } - - Boundary boundary = new Boundary(convert(vertices)); - location.setExternalBoundary(boundary); - - { - List<Surface> holes = new LinkedList(surface.getHoles()); - if (holes.size() > 0) { - Command.Inverse inv = new Command.Inverse(holes); - Collection<Edge> soup = Surface.edges(holes); - List<Edge> loners = new LinkedList(); - for (Edge current : soup) { - List<Surface> lst = inv.surfaces(current); - if (lst.size() == 1) { - loners.add(current); - } - } - - all.addAll(loners); - - List<List<Edge>> internals = new LinkedList(); - Set<Edge> bag = new HashSet(loners); - while (!bag.isEmpty()) { - List<Edge> partition = new LinkedList(); - Queue<Edge> queue = new LinkedList(); - Edge leader = bag.iterator().next(); - bag.remove(leader); - queue.add(leader); - partition.add(leader); - while (!queue.isEmpty()) { - Edge current = queue.remove(); - List<Edge> fl = inv.edges(current.from); - List<Edge> tl = inv.edges(current.to); - List<Edge> lst = new LinkedList(); - lst.addAll(fl); - lst.addAll(tl); - for (Edge adjacant : lst) { - if (bag.contains(adjacant)) { - bag.remove(adjacant); - partition.add(adjacant); - queue.add(adjacant); - } - } - } - internals.add(partition); - } - for (List<Edge> partition : internals) { - List<Edge> internal = Command.Offset.order(partition); - List<Vertex> verts = Command.Offset.vertices(internal); - Boundary b = new Boundary(convert(verts)); - location.addInternalBoundary(b); - } - } - } - - - locations.put(surface, location); - int count = 1; - for (Edge edge : all) { - if (edge.isSmooth()) { - Segment segment = convert(edge); - segment = find(location, segment); - Opening opening = new Opening(); - opening.setId(String.valueOf(count++)); - opening.setDistance(0.0); - opening.setWidth(segment.getLength()); - opening.setSegment(segment); - location.addOpening(opening); - List<Opening> lst = openings.get(edge); - lst.add(opening); - } - } - } else { - List<Surface> surfaces = new LinkedList(); - for (Surface current : space.getSurfaces()) { - if (current.getExterior() == null) { - surfaces.add(current); - } - } - if (surfaces.size() > 0) { - Command.Inverse inv = new Command.Inverse(surfaces); - Collection<Edge> soup = Surface.edges(surfaces); - List<Edge> loners = new LinkedList(); - for (Edge current : soup) { - List<Surface> lst = inv.surfaces(current); - if (lst.size() == 1) { - loners.add(current); - } - } - List<Edge> external = Command.Offset.order(loners); - List<Vertex> verts = Command.Offset.vertices(external); - Boundary b = new Boundary(convert(verts)); - location.setExternalBoundary(b); - } - } - - Map<Surface, Area> s2l = new HashMap(); - Map<Edge, List<Opening>> e2o = new HashMap(); - List<Edge> smoothies = new LinkedList(); - for (Edge edge : space.getEdges()) { - if (edge.isSmooth()) { - List<Opening> lst = new LinkedList(); - e2o.put(edge, lst); - smoothies.add(edge); - } - } - for (Item element : space.getElements()) { - if (!element.isVoid()) { - List<Area> children = createLocationModel((Space) element, level + 1, s2l, e2o); - for (Area child : children) { - location.addChild(child); - } - } - } - for (Edge edge : smoothies) { - System.out.println(edge + " is smooth"); - List<Opening> lst = e2o.get(edge); - for (Opening opening : lst) { - System.out.println(" " + opening); - } - if (lst.size() == 2) { - Opening from = lst.get(0); - Opening to = lst.get(1); - dk.au.perpos.spatialsupport.routefinding.Connection connection - = new dk.au.perpos.spatialsupport.routefinding.Connection(); - connection.setFrom(from); - connection.setTo(to); - connection.setId("door"); - } - } - return location; - } - - private Area createFlatLocationModel() { - Area root = new Area(); - root.setId("building"); - root.setDescription("none"); - Map<Surface, Area> map = new HashMap(); - Map<Edge, List<Surface>> e2s = new HashMap(); - int openingId = 0; - int connectionId = 0; - for (Edge edge : world().getEdges()) { - e2s.put(edge, new LinkedList()); - } - for (Surface surface : world().getSurfaces()) { - - for (Edge edge : surface.getEdges()) { - List<Surface> surfaces = e2s.get(edge); - surfaces.add(surface); - } - Area node = new Area(); - map.put(surface, node); - node.setHeight(3); - List<Point2d> points = new LinkedList(); - for (Vertex vertex : surface.getVertices()) { - Point2d point - = new Point2d(); - point.setX(vertex.getX()); - point.setY(vertex.getY()); - points.add(point); - } - Boundary area = new Boundary(); - { - Point2d previous = points.get(points.size() - 1); - for (Point2d current : points) { - Segment segment = new Segment(); - segment.setFrom(previous); - segment.setTo(current); - area.add(segment); - previous = current; - } - } - - node.setExternalBoundary(area); - Item front = surface.getFrontDomain(); - Item back = surface.getBackDomain(); - String name = "room"; - if (!front.isVoid()) { - name = front.getName(); - } - if (!back.isVoid()) { - name = back.getName(); - } - node.setId(name); - node.setDescription("room"); - root.addChild(node); - } - for (Edge edge : world.getEdges()) { - if (edge.isSmooth()) { - List<Surface> surfaces = e2s.get(edge); - Surface s1 = surfaces.get(0); - Surface s2 = surfaces.get(1); - Area n1 = map.get(s1); - Area n2 = map.get(s2); - Opening o1 = new Opening(); - openingId++; - o1.setId("opening-" + String.valueOf(openingId)); - Segment segment = convert(edge); - Segment seg1 = find(n1, segment); - o1.setSegment(seg1); - o1.setWidth(edge.getLength()); - n1.addOpening(o1); - - Opening o2 = new Opening(); - openingId++; - o2.setId("opening-" + String.valueOf(openingId)); - Segment seg2 = find(n2, segment); - o2.setSegment(seg2); - o2.setWidth(edge.getLength()); - n2.addOpening(o2); - - dk.au.perpos.spatialsupport.routefinding.Connection connection - = new dk.au.perpos.spatialsupport.routefinding.Connection(); - connectionId++; - connection.setId("connection-" + String.valueOf(connectionId)); - connection.setFrom(o1); - connection.setTo(o2); - } - } - return root; - } - - private void processBoundary(Area location) { - - } - - /** - * - * @param out OutputStream - */ - public void exportPPLM(OutputStream out) { - world().setName(getName()); - List<Area> roots = createLocationModel(world(), 1, new HashMap(), new HashMap()); - Area root = roots.get(0); - - processBoundary(root); - LocationModel model = new LocationModel(); - model.setLocation(root); - PPLMPrinter printer = new PPLMPrinter(new PrintStream(out)); - printer.printLocationModel(model); - } - - /** * Returns true of space is visible --- 1313,1316 ---- *************** *** 1975,2006 **** } ! /** ! * ! */ ! public void exportJLMA() { ! Area root = createFlatLocationModel(); ! PrintStream out = System.out; ! out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); ! out.println("<GST>"); ! out.println("<GSTNode name=\"bygning\">"); ! for (Area node : root.getChildren()) { ! out.println("<GSTNode name =\"" + node.getId() + "\">"); ! out.println("<Area>"); ! for (Point2d point ! : node.getExternalBoundary().getPoints()) { ! out.println("<Point2D x=\"" + point.getX() + "\" y=\"" + point.getY() + "\" />"); ! } ! out.println("</Area>"); ! out.println("<Type type=\"" + node.getDescription() + "\" />"); ! for (Location other : node.getConnected()) { ! out.println("<Connected to=\"ali://bygning/" + other.getId() + "\" />"); ! } ! out.println("</GSTNode>"); ! ! } ! out.println("</GSTNode>"); ! out.println("</GST>"); ! } ! /** * --- 1621,1625 ---- } ! /** * |