[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.77, 1.78 Surface.java,
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-03-27 17:18:21
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22370/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Surface.java Geometry.java CoordinateSystem.java Log Message: played a bit around with space assignment after contour extrusion... not perfect yet but on its way... Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.146 retrieving revision 1.147 diff -C2 -d -r1.146 -r1.147 *** Surface.java 26 Mar 2007 10:48:22 -0000 1.146 --- Surface.java 27 Mar 2007 17:18:11 -0000 1.147 *************** *** 90,93 **** --- 90,96 ---- previous = current; } + if (e1 == null || e2 == null) { + return PARALLEL; + } Vertex common = Edge.commonVertex(e1, e2); Vertex from = e1.otherVertex(common); Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.77 retrieving revision 1.78 diff -C2 -d -r1.77 -r1.78 *** Edge.java 22 Mar 2007 14:37:26 -0000 1.77 --- Edge.java 27 Mar 2007 17:18:11 -0000 1.78 *************** *** 1000,1004 **** surfaceedges.add(sideMap.get(e.getTo())); surfaceedges.add(e); ! extrusion.add(new Surface(surfaceedges)); } --- 1000,1055 ---- surfaceedges.add(sideMap.get(e.getTo())); surfaceedges.add(e); ! Surface side = new Surface(surfaceedges); ! List<Surface> surfs = Geometry.neighbourAroundEdge(side, e); ! if (surfs != null) { ! CoordinateSystem cs = side.coordinateSystem(); ! log.info("Side coord " + cs); ! //for front domain ! Surface inside = surfs.get(0); ! int dir1 = inside.direction(cs); ! int dir2 = side.direction(cs); ! if (dir1 == Surface.PARALLEL) { ! if (cs.translate(e.getFrom().add(inside.normal())).getY() < 0) { ! if (dir2 == Surface.LEFT) { ! side.setFrontDomain(inside.getBackDomain()); ! } else { ! side.setBackDomain(inside.getBackDomain()); ! } ! } else { ! if (dir2 == Surface.LEFT) { ! side.setFrontDomain(inside.getFrontDomain()); ! } else { ! side.setBackDomain(inside.getFrontDomain()); ! } ! } ! } else if (dir1 == dir2) { ! side.setFrontDomain(inside.getFrontDomain()); ! } else { ! side.setFrontDomain(inside.getBackDomain()); ! } ! //for back domain ! Surface outside = surfs.get(surfs.size() - 1); ! dir1 = outside.direction(cs); ! if (dir1 == Surface.PARALLEL) { ! /*if (cs.translate(e.getFrom().add(outside.normal())).getY() < 0) { ! if (dir2 == Surface.RIGHT) { ! side.setBackDomain(outside.getBackDomain()); ! } else { ! side.setFrontDomain(outside.getBackDomain()); ! } ! } else { ! if (dir2 == Surface.RIGHT) { ! side.setBackDomain(outside.getFrontDomain()); ! } else { ! side.setFrontDomain(outside.getFrontDomain()); ! } ! }*/ ! } else if (dir1 == dir2) { ! side.setBackDomain(outside.getBackDomain()); ! } else { ! side.setBackDomain(outside.getFrontDomain()); ! } ! } ! extrusion.add(side); } Index: Geometry.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** Geometry.java 23 Mar 2007 15:27:18 -0000 1.46 --- Geometry.java 27 Mar 2007 17:18:11 -0000 1.47 *************** *** 10,17 **** --- 10,21 ---- import java.util.ArrayList; import java.util.Collection; + import java.util.Collections; + import java.util.Comparator; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; + import java.util.Map; import java.util.Set; *************** *** 379,383 **** return Math.asin(tmp.getZ()); } ! /** * Insert a Constructor into model --- 383,413 ---- return Math.asin(tmp.getZ()); } ! ! /** ! * finds the angle between the x-axis of the coordinate system and ! * the given vertex in radian. ! * @param vertex The vertex to find the angle to ! * @param coordinateSystem - the coordinatesystem to find it in ! * @return the resulting angle ! */ ! public static double findAngle(Vertex vertex, CoordinateSystem coordinateSystem) { ! Vertex projVertex = coordinateSystem.project(vertex); ! Vertex vector = projVertex.minus(coordinateSystem.getOrigin()); ! vector.normalize(); ! Vertex xAxis = coordinateSystem.getI().copy(); ! double cosAngle = xAxis.dot(vector); ! if (cosAngle > 1 && cosAngle < 1.001) { ! cosAngle = 1; ! } else if (cosAngle < -1 && cosAngle > -1.001) { ! cosAngle = -1; ! } ! double angle = Math.acos(cosAngle); ! Vertex translated = coordinateSystem.translate(vertex); ! if (translated.getY() < 0) { ! angle = 2 * Math.PI - angle; ! } ! return angle; ! } ! /** * Insert a Constructor into model *************** *** 474,477 **** --- 504,596 ---- } + + /** + * Finds and sort the neighborsurfaces after angle + * @param from the surface to find neighbours for. + * @param edge the shared edge + * @return the neighbour surface ordered after angle to from. + */ + public static List<Surface> neighbourAroundEdge(Surface from, Edge edge) { + //Building a coordinate system: + Vertex n = edge.getDirection(); + n.normalize(); + + Vertex j = from.normal(); + if (j == null) { + return null; + } + Vertex sharedVertex = edge.getFrom(); + Vertex adjacentVertex = Geometry.findNonparallelVertex(from, edge); + if (adjacentVertex == null) { + return null; + } + + Plane p = new Plane(n.getX(), n.getY(), n.getZ(), sharedVertex); + Vertex projVertex = p.project(adjacentVertex); + Vertex i = projVertex.minus(sharedVertex); + i.normalize(); + CoordinateSystem cs = new CoordinateSystem(i, j , n, sharedVertex); + log.info(cs); + //Project.getInstance().getActiveSpace().add(cs); + List<Surface> neighbours = new LinkedList<Surface>(edge.getSurfaces()); + Map<Surface, Double> surToAngle = new HashMap<Surface, Double>(); + //make pre calculations finding all angles to surfaces and filling map + for (Surface s : edge.getSurfaces()) { + if (s != from) { + Vertex notShared = findNonparallelVertex(s, edge); + if (notShared != null) { + double angle = Geometry.findAngle(notShared, cs); + surToAngle.put(s, angle); + } + } + } + log.info(surToAngle); + Collections.sort(neighbours, new SurfaceComparator(surToAngle)); + return neighbours; + } + + /** + * Private comparator class for use in neighborOnEdge method + * @author Rimestad + */ + private static final class SurfaceComparator implements Comparator<Surface> { + private Map<Surface, Double> surToAngle; + /** + * @param preComps precomputations of the angles to the different surfaces + */ + public SurfaceComparator(Map<Surface, Double> preComps) { + super(); + surToAngle = preComps; + } + + /** + * {@inheritDoc} + */ + public int compare(Surface o1, Surface o2) { + return surToAngle.get(o1).compareTo(surToAngle.get(o2)); + } + } + + /** + * Find the next vertex in a surface that is not on the given edge (the line i generates that is) + * @param in The Surface to look for vertexes in + * @param to The edge containing the vertexes generating the line (have to be a edge in in) + * @return The found vertex if any + */ + public static Vertex findNonparallelVertex(Surface in, Edge to) { + Set<Vertex> vertexes = in.collect(); + Vertex adjacentVertex = null; + for (Vertex v : vertexes) { + if (v != to.getFrom() && v != to.getTo()) { + if (to.getDirection().dot(v.minus(to.getFrom())) > 0.0001) { + // the found vertex v were not on the same line as sharedEdge + adjacentVertex = v; + break; + } + } + } + return adjacentVertex; + } + /** * Display info on the log Index: CoordinateSystem.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/CoordinateSystem.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** CoordinateSystem.java 23 Mar 2007 15:27:18 -0000 1.47 --- CoordinateSystem.java 27 Mar 2007 17:18:11 -0000 1.48 *************** *** 137,141 **** /** ! * Constructor secure that they all are orthogonal to each other and normalized * @param i The i vector * @param j The j vector --- 137,141 ---- /** ! * Constructor taking all three axis (normalize and secure orthogonality yourself) * @param i The i vector * @param j The j vector |