[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Space.java, 1.216, 1.217
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-12-12 10:48:11
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv1791/src/net/sourceforge/bprocessor/model Modified Files: Space.java Log Message: Removed a lot of copying code Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.216 retrieving revision 1.217 diff -C2 -d -r1.216 -r1.217 *** Space.java 12 Dec 2007 10:41:07 -0000 1.216 --- Space.java 12 Dec 2007 10:48:11 -0000 1.217 *************** *** 1483,1500 **** /** - * Copy this space and return the copy - * @return the copy of this space - */ - public Space copy() { - Map<Vertex, Vertex> copiedVertices = new HashMap<Vertex, Vertex>(); - Map<Edge, Edge> copiedEdges = new HashMap<Edge, Edge>(); - Map<Surface, Surface> copiedSurfaces = new HashMap<Surface, Surface>(); - Map<Space, Space> copiedSpaces = new HashMap<Space, Space>(); - Space copy = this.copy(copiedVertices, copiedEdges, - copiedSurfaces, copiedSpaces); - return copy; - } - - /** * * @return new space --- 1483,1486 ---- *************** *** 1514,1758 **** /** - * Copy the envelope of the owner - * - */ - public void copyOwnerEnvelope() { - Collection envelope = getEnvelope(); - Iterator iter = envelope.iterator(); - while (iter.hasNext()) { - Surface current = (Surface) iter.next(); - current.copyall(this); - } - } - - /** - * Copy this space and return the copy - * @param copiedVertices map of vertices and their copies. - * @param copiedEdges map of edges and their copies. - * @param copiedSurfaces map of surfaces and their copies. - * @param copiedSpaces map of spaces and their copies. - * @return the copy of this space - */ - private Space copy(Map<Vertex, Vertex> copiedVertices, - Map<Edge, Edge> copiedEdges, - Map<Surface, Surface> copiedSurfaces, - Map<Space, Space> copiedSpaces) { - Space copy = new Space("", - this.getType(), - this.isContainer()); - copy.setName(this.getName()); - copy.setUnion(this.isUnion()); - copy.setTransparent(transparent); - Set<Surface> envelopeCopy = copyEnvelope(copiedVertices, - copiedEdges, - copiedSurfaces, - copy); - copy.setEnvelope(envelopeCopy); - if (copy.isContainer()) { - copyInteriorGeometry(copiedVertices, - copiedEdges, - copiedSurfaces, - copy); - copyInteriorSpaces(copiedVertices, - copiedEdges, - copiedSurfaces, - copiedSpaces, - copy); - } - return copy; - } - - /** - * Copies the interior spaces of this space. - * The method maintains the four copy maps of vertices, edges, - * surfaces and spaces. - * @param copiedVertices map of vertices and their copies. - * @param copiedEdges map of edges and their copies. - * @param copiedSurfaces map of surfaces and their copies. - * @param copiedSpaces map of spaces and their copies. - * @param copy the copy of this space - */ - private void copyInteriorSpaces(Map<Vertex, Vertex> copiedVertices, - Map<Edge, Edge> copiedEdges, - Map<Surface, Surface> copiedSurfaces, - Map<Space, Space> copiedSpaces, - Space copy) { - Iterator it = elements.values().iterator(); - while (it.hasNext()) { - Space sp = (Space)it.next(); - if (sp != sp.getOwner().getEmpty()) { - Space newSpace = sp.copy(copiedVertices, - copiedEdges, - copiedSurfaces, - copiedSpaces); - copiedSpaces.put(sp, newSpace); - copy.add(newSpace); - copy.setName(copy.getName()); - } - } - } - - /** - * Copies the interior surfaces edges and vertices of this space. - * The method maintains the three copy maps of vertices, edges and - * surfaces. - * @param copiedVertices map of vertices and their copies. - * @param copiedEdges map of edges and their copies. - * @param copiedSurfaces map of surfaces and their copies. - * @param copy the copy of this space - */ - private void copyInteriorGeometry(Map<Vertex, Vertex> copiedVertices, - Map<Edge, Edge> copiedEdges, - Map<Surface, Surface> copiedSurfaces, - Space copy) { - Iterator it = vertices.values().iterator(); - while (it.hasNext()) { - Vertex v = (Vertex)it.next(); - Vertex vCopy = v.copy(); - copiedVertices.put(v, vCopy); - copy.add(vCopy); - } - it = edges.values().iterator(); - while (it.hasNext()) { - Edge e = (Edge)it.next(); - Edge eCopy = new Edge(copiedVertices.get(e.getTo()), - copiedVertices.get(e.getFrom())); - copiedEdges.put(e, eCopy); - copy.add(eCopy); - } - it = surfaces.values().iterator(); - while (it.hasNext()) { - Surface s = (Surface)it.next(); - copyInnerSurface(s, - copiedEdges, - copiedSurfaces, - copy); - } - } - - /** - * Copies a surface in the inner layers of the copy - * @param s the surface to copy - * @param copiedEdges map of edges and their copies. - * @param copiedSurfaces map of surfaces and their copies. - * @param copy the copy of this space - */ - private void copyInnerSurface(Surface s, - Map<Edge, Edge> copiedEdges, - Map<Surface, Surface> copiedSurfaces, - Space copy) { - if (!copiedSurfaces.keySet().contains(s)) { - List<Edge> newEdges = new LinkedList<Edge>(); - Iterator edgeIt = s.getEdges().iterator(); - while (edgeIt.hasNext()) { - newEdges.add(copiedEdges.get((Edge)edgeIt.next())); - } - Surface newSurface = new Surface(newEdges); - if (s.getExterior() != null) { - Surface exteriorCopy; - if (!copiedSurfaces.keySet().contains(s.getExterior())) { - copyInnerSurface(s.getExterior(), - copiedEdges, - copiedSurfaces, - copy); - } - exteriorCopy = copiedSurfaces.get(s.getExterior()); - exteriorCopy.addHole(newSurface); - } - newSurface.setFrontDomain(copy.getEmpty()); - newSurface.setBackDomain(copy.getEmpty()); - copiedSurfaces.put(s, newSurface); - copy.add(newSurface); - } - } - - /** - * Copies the envelope of this space and returns the - * set of surfaces that is the envelope. The method maintains the - * three copy maps of vertices, edges and surfaces. - * @param copiedVertices map of vertices and their copies. - * @param copiedEdges map of edges and their copies. - * @param copiedSurfaces map of surfaces and their copies. - * @param copy the copy of this space. - * @return the envelope set of surfaces - */ - private Set<Surface> copyEnvelope(Map<Vertex, Vertex> copiedVertices, - Map<Edge, Edge> copiedEdges, - Map<Surface, Surface> copiedSurfaces, - Space copy) { - Iterator it = this.envelope.iterator(); - Set<Surface> envelopeCopy = new HashSet<Surface>(); - while (it.hasNext()) { - Surface s = (Surface)it.next(); - Surface surfaceCopy; - if (copiedSurfaces.keySet().contains(s)) { - surfaceCopy = copiedSurfaces.get(s); - } else { - /* This should only apply to the outer layer */ - surfaceCopy = copyOuterSurface(s, copiedVertices, - copiedEdges, - copiedSurfaces); - - } - envelopeCopy.add(surfaceCopy); - if (s.getFrontDomain() == this) { - surfaceCopy.setFrontDomain(copy); - } - if (s.getBackDomain() == this) { - surfaceCopy.setBackDomain(copy); - } - } - return envelopeCopy; - } - - /** - * Copies a surface in the outer layer of the copy - * @param s the surface to copy - * @param copiedVertices map of vertices and their copies. - * @param copiedEdges map of edges and their copies. - * @param copiedSurfaces map of surfaces and their copies. - * @return the copy of the surface - */ - private Surface copyOuterSurface(Surface s, - Map<Vertex, Vertex> copiedVertices, - Map<Edge, Edge> copiedEdges, - Map<Surface, Surface> copiedSurfaces) { - Surface surfaceCopy; - { - Iterator edgeIt = s.getEdges().iterator(); - List<Edge> edgeCopies = new LinkedList<Edge>(); - while (edgeIt.hasNext()) { - Edge e = (Edge)edgeIt.next(); - if (!copiedVertices.keySet().contains(e.getTo())) { - copiedVertices.put(e.getTo(), e.getTo().copy()); - this.getOwner().add(copiedVertices.get(e.getTo())); - } - if (!copiedVertices.keySet().contains(e.getFrom())) { - copiedVertices.put(e.getFrom(), e.getFrom().copy()); - this.getOwner().add(copiedVertices.get(e.getFrom())); - } - if (!copiedEdges.keySet().contains(e)) { - copiedEdges.put(e, new Edge(copiedVertices.get(e.getFrom()), - copiedVertices.get(e.getTo()))); - } - this.getOwner().add(copiedEdges.get(e)); - edgeCopies.add(copiedEdges.get(e)); - } - surfaceCopy = new Surface(edgeCopies); - this.getOwner().add(surfaceCopy); - surfaceCopy.setFrontDomain(this.getOwner().getEmpty()); - surfaceCopy.setBackDomain(this.getOwner().getEmpty()); - - copiedSurfaces.put(s, surfaceCopy); - } - Iterator it = s.getHoles().iterator(); - while (it.hasNext()) { - Surface hole = (Surface)it.next(); - surfaceCopy.addHole(copyOuterSurface(hole, copiedVertices, copiedEdges, copiedSurfaces)); - } - return surfaceCopy; - } - - /** * @return Returns true if its transparent */ --- 1500,1503 ---- |