[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Surface.java,1.22,1.23
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-09-20 12:35:05
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8111 Modified Files: Surface.java Log Message: Added front and back domain, and constraints for moveing innersurfaces(still buggy) Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Surface.java 14 Sep 2005 06:47:47 -0000 1.22 --- Surface.java 20 Sep 2005 12:34:52 -0000 1.23 *************** *** 45,48 **** --- 45,54 ---- private boolean isInner; + /** The domain in front of the surface */ + private Domain frontDomain; + + /** The domain behind the surface */ + private Domain backDomain; + /** * Constructor for persistence layer *************** *** 62,65 **** --- 68,73 ---- setEdges(null); setInnerSurfaces(null); + setBackDomain(null); + setFrontDomain(null); } *************** *** 126,130 **** constructor = c; } ! /** * Get the edges --- 134,138 ---- constructor = c; } ! /** * Get the edges *************** *** 262,267 **** --- 270,406 ---- } } + + if (this.isInner) { + Set surfaces = SurfaceFacade.getInstance().findAll(); + Iterator surfIt = surfaces.iterator(); + while (surfIt.hasNext()) { + Surface surf = (Surface)surfIt.next(); + Set inners = surf.getInnerSurfaces(); + if (inners != null) { + Iterator innerIt = inners.iterator(); + while (innerIt.hasNext()) { + Surface innerSurf = (Surface)innerIt.next(); + if (innerSurf.equals(this)) { + if (!containedCheck(this, surf)) { + this.move(-dx, -dy, -dz); + } + } + } + } + } + } + SurfaceFacade.getInstance().update(this); } + + /** + * Checks if a hole is contained in a surface, given that the hole and the + * surface is in the same plane. + * @param hole the hole + * @param surf the surface + * @return boolean indicating werther or not the hole is contained in the plane. + */ + private boolean containedCheck(Surface hole, Surface surf) { + /*this is done by aplying the crossing numbers algorithm on every vertex + *of the hole. Using the edges of the hole as rays we cover two vertecies + *at a time. + */ + List holeEdges = hole.getEdges(); + Iterator holeIt = holeEdges.iterator(); + Edge holeEdge = null; + boolean contained = true; + if (holeIt.hasNext()) { + holeEdge = (Edge)holeIt.next(); + contained = crossingNumbers(holeEdge, surf); + } + while (holeIt.hasNext() && contained) { + holeEdge = (Edge)holeIt.next(); + if (holeIt.hasNext()) { + holeEdge = (Edge)holeIt.next(); + if (!crossingNumbers(holeEdge, surf)) { + contained = false; + } + } + } + return contained; + } + + /** + * The crossing numbers algorithm to check if an edge is contained in an other surface. + * @param edge the edge. + * @param surf the surface. + * @return a boolean werther or not the edge is contained + */ + private boolean crossingNumbers(Edge edge, Surface surf) { + List surfEdges = surf.getEdges(); + Iterator surfIt = surfEdges.iterator(); + Edge holeEdge = edge; + Vertex holeOr = holeEdge.getTo(); + Vertex holeDir = holeEdge.getFrom().minus(holeOr); + holeDir.scale(1 / holeDir.length()); + boolean contained = true; + int crossings = 0; + while (surfIt.hasNext() && contained) { + Edge surfEdge = (Edge)surfIt.next(); + //in order to find intersections we get a parametrizied version of the edges + //the origin point and direction vector for the surface edge + Vertex surfOr = surfEdge.getTo(); + Vertex surfDir = surfEdge.getFrom().minus(surfOr); + surfDir.scale(1 / surfDir.length()); + //formulars for finding intersections taken from http://www.realtimerendering.com/int/#I304 + Vertex dirCross = surfDir.cross(holeDir); + double denominator = dirCross.length() * dirCross.length(); + if (denominator != 0) { + Vertex orSubs = holeOr.minus(surfOr); + double surfDet = orSubs.determinant(holeDir, dirCross); + double holeDet = orSubs.determinant(surfDir, dirCross); + double tSurf = surfDet / denominator; + double tHole = holeDet / denominator; + double epsilon = 0.00001; + //checking if there is an intersection and if it is within the line segments + if ((tSurf > 0) && (tHole > 0) && + (Math.abs((surfOr.getX() + surfDir.getX() * tSurf) - + (holeOr.getX() + holeDir.getX() * tHole)) + < epsilon) && + (Math.abs((surfOr.getY() + surfDir.getY() * tSurf) - + (holeOr.getY() + holeDir.getY() * tHole)) + < epsilon) && + (Math.abs((surfOr.getZ() + surfDir.getZ() * tSurf) - + (holeOr.getZ() + holeDir.getZ() * tHole)) + < epsilon)) { + //the parameters for the "from" point on the edges + double tSurfFrom = 0; + double tHoleFrom = 0; + if (surfDir.getX() != 0) { + tSurfFrom = ((surfEdge.getFrom().getX() - surfOr.getX()) / surfDir.getX()); + } else if (surfDir.getY() != 0) { + tSurfFrom = ((surfEdge.getFrom().getY() - surfOr.getY()) / surfDir.getY()); + } else if (surfDir.getZ() != 0 && holeDir.getZ() != 0) { + tSurfFrom = ((surfEdge.getFrom().getZ() - surfOr.getZ()) / surfDir.getZ()); + } else { + log.warn("outer surface edge has a zero vector direction vector"); + } + if (holeDir.getX() != 0) { + tHoleFrom = ((holeEdge.getFrom().getX() - holeOr.getX()) / holeDir.getX()); + } else if (holeDir.getY() != 0) { + tHoleFrom = ((holeEdge.getFrom().getY() - holeOr.getY()) / holeDir.getY()); + } else if (holeDir.getZ() != 0) { + tHoleFrom = ((holeEdge.getFrom().getZ() - holeOr.getZ()) / holeDir.getZ()); + } else { + log.warn("inner surface edge has a zero vector direction vector"); + } + if (tHoleFrom > tHole) { + contained = false; + } else if (tSurfFrom >= tSurf) { + crossings++; + } + } + } + } + if (crossings % 2 == 0) { + contained = false; + } + return contained; + } /** *************** *** 306,310 **** this.isInner = isInner; } ! /** --- 445,485 ---- this.isInner = isInner; } ! ! /** ! * Get the domain behind the surface ! * @return the backdomain ! * @hibernate.many-to-one ! * column="BACK_DOMAIN_ID" ! * class="net.sourceforge.bprocessor.model.Domain" ! */ ! public Domain getBackDomain() { ! return backDomain; ! } ! ! /** ! * Set the domain behind the surface ! * @param back the domain ! */ ! public void setBackDomain(Domain back) { ! backDomain = back; ! } ! ! /** ! * Get the domain in front of the surface ! * @return the frontdomain ! * @hibernate.many-to-one ! * column="FRONT_DOMAIN_ID" ! * class="net.sourceforge.bprocessor.model.Domain" ! */ ! public Domain getFrontDomain() { ! return frontDomain; ! } ! /** ! * Set the domain in front of the surface ! * @param front the frontdomain ! */ ! public void setFrontDomain(Domain front) { ! frontDomain = front; ! } /** |