bprocessor-commit Mailing List for B-processor (Page 149)
Status: Pre-Alpha
Brought to you by:
henryml
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(12) |
Jul
(117) |
Aug
(151) |
Sep
(157) |
Oct
(81) |
Nov
(117) |
Dec
(119) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(183) |
Feb
(130) |
Mar
(117) |
Apr
(61) |
May
(82) |
Jun
(45) |
Jul
(149) |
Aug
(173) |
Sep
(199) |
Oct
(165) |
Nov
(107) |
Dec
(137) |
2007 |
Jan
(124) |
Feb
(58) |
Mar
(123) |
Apr
(80) |
May
(130) |
Jun
(64) |
Jul
(31) |
Aug
(42) |
Sep
(114) |
Oct
(167) |
Nov
(239) |
Dec
(200) |
2008 |
Jan
(43) |
Feb
(43) |
Mar
(4) |
Apr
(9) |
May
(5) |
Jun
(1) |
Jul
(3) |
Aug
(3) |
Sep
(13) |
Oct
(9) |
Nov
(12) |
Dec
|
2009 |
Jan
|
Feb
(20) |
Mar
(7) |
Apr
(12) |
May
(34) |
Jun
(72) |
Jul
|
Aug
(3) |
Sep
(31) |
Oct
(2) |
Nov
(8) |
Dec
(4) |
2010 |
Jan
(5) |
Feb
(32) |
Mar
(8) |
Apr
(7) |
May
(36) |
Jun
|
Jul
(11) |
Aug
(15) |
Sep
(7) |
Oct
(2) |
Nov
(13) |
Dec
(80) |
2011 |
Jan
|
Feb
|
Mar
(8) |
Apr
(12) |
May
(32) |
Jun
(9) |
Jul
(5) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
(8) |
2012 |
Jan
|
Feb
|
Mar
(3) |
Apr
(5) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(22) |
Jun
(5) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Michael L. <he...@us...> - 2005-12-05 07:53:56
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9883/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Domain.java Surface.java Project.java Plane.java Log Message: Implemented Surface.extrude(length) Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** Surface.java 28 Nov 2005 22:23:49 -0000 1.50 --- Surface.java 5 Dec 2005 07:53:46 -0000 1.51 *************** *** 11,14 **** --- 11,15 ---- import java.util.HashMap; import java.util.Iterator; + import java.util.LinkedList; import java.util.List; import java.util.Set; *************** *** 183,187 **** vertices.add(e0.getTo()); } else if (edges.size() > 1) { ! Vertex current = getFirtVertex(); if (current != null) { vertices.add(current); --- 184,188 ---- vertices.add(e0.getTo()); } else if (edges.size() > 1) { ! Vertex current = getFirstVertex(); if (current != null) { vertices.add(current); *************** *** 190,193 **** --- 191,197 ---- Edge edge = (Edge) iter.next(); current = edge.otherVertex(current); + if (current == null) { + throw new Error("other vertex null"); + } vertices.add(current); } *************** *** 203,207 **** * @return The first vertex */ ! public Vertex getFirtVertex() { List edges = getEdges(); if (edges.size() == 0) { --- 207,211 ---- * @return The first vertex */ ! public Vertex getFirstVertex() { List edges = getEdges(); if (edges.size() == 0) { *************** *** 401,404 **** --- 405,505 ---- } + /** + * Extrude this surface + * @param delta How much to extrude along the normal + * @return The top in the extruded surface + */ + public Surface extrude(double delta) { + Vertex normal = normal(); + normal.scale(delta / normal.length()); + + List vertices = getVertices(); + Vertex first = (Vertex) vertices.get(0); + Vertex last = (Vertex) vertices.get(vertices.size() - 1); + if (first != last) { + throw new Error("extruding open surface"); + } + + // FIXME getVertices() should not return duplicates + // why is a surface not allways closed? It should be! + + vertices.remove(vertices.size() - 1); + List edges = getEdges(); + + int n = vertices.size(); + + Vertex[] v = new Vertex[n]; + Edge[] e = new Edge[n]; + + + Vertex[] vmap = new Vertex[n]; + Edge[] topmap = new Edge[n]; + Edge[] sidemap = new Edge[n]; + Surface[] facemap = new Surface[n]; + + Surface top = null; + + vertices.toArray(v); + edges.toArray(e); + + for (int i = 0; i < n; i++) { + vmap[i] = v[i].add(normal); + Project.getInstance().intern(vmap[i]); + } + + for (int i = 0; i < n; i++) { + topmap[i] = new Edge("", vmap[i], vmap[(i + 1) % n]); + Project.getInstance().intern(topmap[i]); + } + + for (int i = 0; i < n; i++) { + sidemap[i] = new Edge("", v[i], vmap[i]); + Project.getInstance().intern(sidemap[i]); + } + + for (int i = 0; i < n; i++) { + Edge b = e[i]; + Edge r = sidemap[i]; + Edge l = sidemap[(i + 1) % n]; + Edge t = topmap[i]; + List newEdges = new LinkedList(); + newEdges.add(r); + newEdges.add(t); + newEdges.add(l); + newEdges.add(b); + facemap[i] = new Surface("", newEdges); + Project.getInstance().intern(facemap[i]); + + } + + { + List newEdges = new LinkedList(); + for (int i = 0; i < n; i++) { + newEdges.add(topmap[n - i - 1]); + } + top = new Surface("", newEdges); + Project.getInstance().intern(top); + } + + + // FIXME should return the sides instead of assigning + // spaces here. + + for (int i = 0; i < n; i++) { + if (delta < 0) { + facemap[i].setBackDomain(getBackDomain()); + } else { + facemap[i].setFrontDomain(getFrontDomain()); + } + } + if (delta < 0) { + top.setBackDomain(getBackDomain()); + } else { + top.setFrontDomain(getFrontDomain()); + } + + + return top; + } /** *************** *** 408,418 **** public void addHole(Surface inner) { if (innerSurfaces == null) { ! Set initSet = new HashSet(); ! initSet.add(inner); ! setInnerSurfaces(initSet); ! } else { ! innerSurfaces.add(inner); } inner.setIsInner(true); } --- 509,537 ---- public void addHole(Surface inner) { if (innerSurfaces == null) { ! innerSurfaces = new HashSet(); } + innerSurfaces.add(inner); inner.setIsInner(true); + + Vertex normal = normal(); + Vertex other = inner.normal(); + double dot = normal.dot(other); + Domain front = getFrontDomain(); + Domain back = getBackDomain(); + if (dot > 0) { + if (inner.getFrontDomain() == null) { + inner.setFrontDomain(front); + } + if (inner.getBackDomain() == null) { + inner.setBackDomain(back); + } + } else { + if (inner.getFrontDomain() == null) { + inner.setFrontDomain(back); + } + if (inner.getBackDomain() == null) { + inner.setBackDomain(front); + } + } } *************** *** 515,620 **** } - //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; ! 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 && tSurfFrom >= tSurf) { ! contained = false; ! } else if (tSurfFrom >= tSurf) { ! crossings++; ! } ! } } } ! if (crossings % 2 == 0) { ! contained = false; ! } ! return contained; } --- 634,651 ---- } /** ! * Tests if a surface is a hole in this surface ! * @param hole The surface to test ! * @return True if hole */ ! public boolean surrounds(Surface hole) { ! Iterator iter = hole.getVertices().iterator(); ! while (iter.hasNext()) { ! Vertex current = (Vertex) iter.next(); ! if (!surrounds(current)) { ! return false; } } ! return true; } *************** *** 655,660 **** backDomain.removeSurface(this); } - backDomain = back; } --- 686,694 ---- backDomain.removeSurface(this); } backDomain = back; + if (backDomain != null) { + backDomain.addSurface(this); + } + Project.getInstance().update(this); } *************** *** 678,681 **** --- 712,719 ---- } frontDomain = front; + if (frontDomain != null) { + frontDomain.addSurface(this); + } + Project.getInstance().update(this); } *************** *** 762,766 **** n = normal(); Edge e0 = (Edge) edges.get(0); ! origin = getFirtVertex(); i = e0.otherVertex(origin).minus(origin); i.scale(1 / i.length()); --- 800,804 ---- n = normal(); Edge e0 = (Edge) edges.get(0); ! origin = getFirstVertex(); i = e0.otherVertex(origin).minus(origin); i.scale(1 / i.length()); *************** *** 869,873 **** */ public boolean surrounds(Vertex v) { ! return surrounds(v, 0.00001); } /** --- 907,911 ---- */ public boolean surrounds(Vertex v) { ! return surrounds(v, 0.0000001); } /** Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Edge.java 29 Nov 2005 19:06:51 -0000 1.21 --- Edge.java 5 Dec 2005 07:53:46 -0000 1.22 *************** *** 335,339 **** */ public String toString() { ! return "Edge[id=" + id + ",name=" + name + ",from=" + from + ",to=" + to + "]"; } --- 335,339 ---- */ public String toString() { ! return "Edge[E" + id + " {V" + from.getId() + " -> V" + to.getId() + "}]"; } *************** *** 388,394 **** */ public double[] center() { ! double x = (to.getX() - from.getX()) / 2; ! double y = (to.getY() - from.getY()) / 2; ! double z = (to.getZ() - from.getZ()) / 2; return new double[]{from.getX() + x, from.getY() + y, from.getZ() + z}; } --- 388,394 ---- */ public double[] center() { ! double x = (to.getX() - from.getX()) / 2.0; ! double y = (to.getY() - from.getY()) / 2.0; ! double z = (to.getZ() - from.getZ()) / 2.0; return new double[]{from.getX() + x, from.getY() + y, from.getZ() + z}; } Index: Domain.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Domain.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Domain.java 6 Oct 2005 11:11:07 -0000 1.11 --- Domain.java 5 Dec 2005 07:53:46 -0000 1.12 *************** *** 137,140 **** --- 137,141 ---- s.add(surface); } + Project.getInstance().update(this); } Index: Plane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Plane.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Plane.java 6 Nov 2005 16:25:34 -0000 1.9 --- Plane.java 5 Dec 2005 07:53:46 -0000 1.10 *************** *** 123,126 **** --- 123,127 ---- } Vertex i = new Vertex("intersection"); + // TODO Round off the point to be in the plane i.setX(x0 + t * xd); i.setY(y0 + t * yd); Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Project.java 21 Nov 2005 09:53:41 -0000 1.7 --- Project.java 5 Dec 2005 07:53:46 -0000 1.8 *************** *** 154,157 **** --- 154,158 ---- Notification n = new Notification(Notification.CONSTRUCTION_SPACE_MODIFIED, domain.getId()); Notifier.getInstance().sendNotification(n); + System.out.println("send notification"); } else if (domain instanceof FunctionalSpace) { DatabaseFacade.getInstance().update((FunctionalSpace)domain); |
From: Michael L. <he...@us...> - 2005-12-03 12:27:34
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29323/src/net/sourceforge/bprocessor/gl Modified Files: GLColorMenuActionListener.java GLView.java Log Message: Implemented rules for colors of surfaces: When drawing one side of the surface, the color for the space on the other side is used. Default gray for none, wheat for construction and alice blue for functional. Index: GLView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/GLView.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** GLView.java 23 Nov 2005 19:03:26 -0000 1.26 --- GLView.java 3 Dec 2005 12:27:21 -0000 1.27 *************** *** 103,106 **** --- 103,108 ---- JMenuItem bgItem = new JMenuItem("Background Color"); bgItem.addActionListener(colorMenuListener); + JMenuItem noneItem = new JMenuItem("None Color"); + noneItem.addActionListener(colorMenuListener); JMenuItem defaultItem = new JMenuItem("Default"); defaultItem.addActionListener(colorMenuListener); *************** *** 109,112 **** --- 111,115 ---- colorMenu.add(lineItem); colorMenu.add(bgItem); + colorMenu.add(noneItem); colorMenu.add(defaultItem); Index: GLColorMenuActionListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/GLColorMenuActionListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GLColorMenuActionListener.java 30 Nov 2005 15:45:38 -0000 1.2 --- GLColorMenuActionListener.java 3 Dec 2005 12:27:21 -0000 1.3 *************** *** 61,64 **** --- 61,67 ---- Color newColor = JColorChooser.showDialog(GUI.getInstance(), "Background Color", Color.white); view.setBGColor(newColor.getRGBComponents(null)); + } else if (e.getActionCommand().equals("None Color")) { + Color newColor = JColorChooser.showDialog(GUI.getInstance(), "None Color", Color.white); + view.setNoneColor(newColor.getRGBComponents(null)); } else if (e.getActionCommand().equals("Default")) { view.setBGColor(View.BACKGROUND_COLOR); |
From: Michael L. <he...@us...> - 2005-12-03 12:27:32
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29323/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java View.java Log Message: Implemented rules for colors of surfaces: When drawing one side of the surface, the color for the space on the other side is used. Default gray for none, wheat for construction and alice blue for functional. Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** AbstractView.java 1 Dec 2005 10:10:02 -0000 1.66 --- AbstractView.java 3 Dec 2005 12:27:21 -0000 1.67 *************** *** 65,68 **** --- 65,79 ---- private static final int ALL = 4; + /** The NORMAL side is the side where the normal points to */ + private static final int NORMAL = 0; + + /** The front side is the functional-space side. */ + private static final int FRONT = 1; + + /** The back side the construction-space side. */ + private static final int BACK = 2; + + + /** The width of the window */ protected static double width; *************** *** 94,97 **** --- 105,117 ---- /** The current grid color */ protected static float[] gridColor; + + /** Front color for surfaces */ + protected static float[] frontCcolor = new float[] {0.96f, 0.87f, 0.70f}; + + /** NONE color for surfaces */ + protected static float[] noneColor = new float[] {0.70f, 0.70f, 0.70f}; + + /** Back color for surfaces */ + protected static float[] backColor = new float[] {0.94f, 0.97f, 1.00f}; /** The target */ *************** *** 741,750 **** gl.glCullFace(GL.GL_BACK); ! gl.glColor3fv(FRONT_COLOR); ! drawSurfaces(gld); gl.glCullFace(GL.GL_FRONT); ! gl.glColor3fv(BACK_COLOR); ! drawSurfaces(gld); gl.glDisable(GL.GL_CULL_FACE); --- 761,770 ---- gl.glCullFace(GL.GL_BACK); ! gl.glColor3fv(frontCcolor); ! drawSurfaces(gld, FRONT); gl.glCullFace(GL.GL_FRONT); ! gl.glColor3fv(backColor); ! drawSurfaces(gld, BACK); gl.glDisable(GL.GL_CULL_FACE); *************** *** 761,765 **** gl.glPolygonOffset(1.0f, 1.0f); gl.glColor3fv(SURFACE_COLOR); ! drawSurfaces(gld); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); break; --- 781,785 ---- gl.glPolygonOffset(1.0f, 1.0f); gl.glColor3fv(SURFACE_COLOR); ! drawSurfaces(gld, NORMAL); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); break; *************** *** 871,875 **** Surface s = (Surface)it.next(); pushName(gl, s); ! drawSurface(s); popName(gl); } --- 891,895 ---- Surface s = (Surface)it.next(); pushName(gl, s); ! drawSurface(s, false); popName(gl); } *************** *** 985,989 **** gl.glPolygonStipple(highlight); Surface s = (Surface) o; ! drawSurface(s); gl.glDisable(GL.GL_POLYGON_STIPPLE); } --- 1005,1009 ---- gl.glPolygonStipple(highlight); Surface s = (Surface) o; ! drawSurface(s, false); gl.glDisable(GL.GL_POLYGON_STIPPLE); } *************** *** 993,998 **** * Draw a surface * @param s The surface to draw */ ! private void drawSurface(Surface s) { GLUtesselator tess = glu.gluNewTess(); GLUtesselatorCallback cb = new Callback(); --- 1013,1019 ---- * Draw a surface * @param s The surface to draw + * @param flip Flip the surface */ ! private void drawSurface(Surface s, boolean flip) { GLUtesselator tess = glu.gluNewTess(); GLUtesselatorCallback cb = new Callback(); *************** *** 1013,1022 **** if (norm != null) { norm.scale(1 / norm.length()); ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); } } //drawing the outer contour ! drawContour(s, tess); ! //drawing the inner conturs Set innerSurfaces = s.getInnerSurfaces(); --- 1034,1050 ---- if (norm != null) { norm.scale(1 / norm.length()); ! if (flip) { ! gl.glNormal3d(-norm.getX(), -norm.getY(), -norm.getZ()); ! } else { ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); ! } } } //drawing the outer contour ! if (flip) { ! drawContourReverse(s, tess); ! } else { ! drawContour(s, tess); ! } //drawing the inner conturs Set innerSurfaces = s.getInnerSurfaces(); *************** *** 1056,1059 **** --- 1084,1109 ---- } + /** + * Draw contour of a Surface in reverse + * @param surface The surface + * @param tess The Tesselator + */ + private void drawContourReverse(Surface surface, GLUtesselator tess) { + List vertices = surface.getVertices(); + if (vertices.size() > 0) { + Vertex first = (Vertex) vertices.get(0); + Vertex last = (Vertex) vertices.get(vertices.size() - 1); + if (first == last) { + glu.gluTessBeginContour(tess); + for (int i = vertices.size(); i > 0; i--) { + Vertex current = (Vertex) vertices.get(i - 1); + double[] coords = new double[] {current.getX(), current.getY(), current.getZ()}; + glu.gluTessVertex(tess, coords, new Point(coords[0], coords[1], coords[2])); + } + glu.gluTessEndContour(tess); + } + } + } + /** *************** *** 1124,1134 **** } } ! /** ! * Draw all surfaces * @param gld The GLDrawable */ ! private void drawSurfaces(GLDrawable gld) { ! Set surfaces = Project.getInstance().getSurfaces(); Collection selection = glv.getTool().getSelection(); GL gl = gld.getGL(); --- 1174,1225 ---- } } ! /** ! * Is the surface visible ! * @param surface The surface to test ! * @return True if visible ! */ ! private boolean isVisible(Surface surface) { ! Domain back = surface.getBackDomain(); ! Domain front = surface.getFrontDomain(); ! if ((front instanceof FunctionalSpace) && (back instanceof FunctionalSpace)) { ! return false; ! } ! if ((front instanceof ConstructionSpace) && (back instanceof ConstructionSpace)) { ! return false; ! } ! return true; ! } ! ! /** ! * ! * Get color associated with the space ! * @param space The space ! * @return The color ! */ ! private float[] getSpaceColor(Domain space) { ! if (space == null) { ! return noneColor; ! } else { ! // TODO check if the space space has a color ! if (space instanceof ConstructionSpace) { ! // We are looking at a constructionspace ! return frontCcolor; ! } ! if (space instanceof FunctionalSpace) { ! // We are looking at a constructionspace ! return backColor; ! } ! return noneColor; ! } ! } ! ! /** ! * Draw the surfaces * @param gld The GLDrawable + * @param surfaces The surfaces to draw + * @param side The side of the Surface to draw */ ! private void drawSurfaces(GLDrawable gld, Set surfaces, int side) { Collection selection = glv.getTool().getSelection(); GL gl = gld.getGL(); *************** *** 1137,1167 **** Surface s = (Surface)it.next(); if (!selection.contains(s)) { ! if ((s.getBackDomain() instanceof FunctionalSpace) && ! (s.getFrontDomain() instanceof FunctionalSpace)) { ! //gl.glEnable(GL.GL_POLYGON_STIPPLE); ! //gl.glPolygonStipple(transparency); ! //drawSurface(s); ! //gl.glDisable(GL.GL_POLYGON_STIPPLE); ! } else { ! drawSurface(s); } } ! } ! it = tempSurfaces.iterator(); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! if (!selection.contains(s)) { ! if ((s.getBackDomain() instanceof FunctionalSpace) && ! (s.getFrontDomain() instanceof FunctionalSpace)) { ! //gl.glEnable(GL.GL_POLYGON_STIPPLE); ! //gl.glPolygonStipple(transparency); ! //drawSurface(s); ! //gl.glDisable(GL.GL_POLYGON_STIPPLE); ! } else { ! drawSurface(s); ! } ! } ! } } --- 1228,1269 ---- Surface s = (Surface)it.next(); if (!selection.contains(s)) { ! if (isVisible(s)) { ! if (side == FRONT) { ! // TODO check if a surface has a color assigned to ! // the front and use that. ! ! // Where are drawing the front of the surface, so ! // we should use the color of the Space associated with the ! // back. ! ! Domain back = s.getBackDomain(); ! gl.glColor3fv(getSpaceColor(back)); ! } ! if (side == BACK) { ! // TODO check if a surface has a color assigned to ! // the back and use that. ! ! // Where are drawing the back of the surface, so ! // we should use the color of the Space associated with the ! // front. ! ! Domain front = s.getFrontDomain(); ! gl.glColor3fv(getSpaceColor(front)); ! } ! drawSurface(s, false); } } ! } ! } ! /** ! * Draw all surfaces ! * @param gld The GLDrawable ! * @param side The side of surfaces to draw ! */ ! private void drawSurfaces(GLDrawable gld, int side) { ! Set surfaces = Project.getInstance().getSurfaces(); ! drawSurfaces(gld, surfaces, side); ! drawSurfaces(gld, tempSurfaces, side); } *************** *** 1772,1775 **** --- 1874,1886 ---- /** + * Set the none color + * @param color The color + */ + + public void setNoneColor(float[] color) { + noneColor = color; + } + + /** * Adds a temporary surface to be drawn. * @param s the surface Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** View.java 1 Dec 2005 10:10:02 -0000 1.25 --- View.java 3 Dec 2005 12:27:21 -0000 1.26 *************** *** 58,67 **** public static final float[] SURFACE_COLOR = new float[] {1.0f, 1.0f, 1.0f}; - /** Front color for surfaces */ - public static final float[] FRONT_COLOR = new float[] {0.96f, 0.87f, 0.70f}; - - /** Back color for surfaces */ - public static final float[] BACK_COLOR = new float[] {0.94f, 0.97f, 1.00f}; - /** Used for selected objects */ public static final float[] SELECTED_COLOR = new float[] {1.0f, 0.4f, 1.0f}; --- 58,61 ---- *************** *** 298,301 **** --- 292,301 ---- /** + * Sets the default surface color + * @param color the color + */ + public void setNoneColor(float[] color); + + /** * Adds a temporary surface to be drawn. * @param s the surface |
From: rimestad <rim...@us...> - 2005-12-01 15:57:06
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23150/src/net/sourceforge/bprocessor/gl/tool Modified Files: CameraTool.java Log Message: Removed debug output Index: CameraTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/CameraTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CameraTool.java 1 Dec 2005 10:10:02 -0000 1.1 --- CameraTool.java 1 Dec 2005 15:56:57 -0000 1.2 *************** *** 117,137 **** Vertex sidewards = up.cross(forward); sidewards.scale(1 / sidewards.length()); ! log.info("forward: " + forward.getX() + ", " + forward.getY() + ", " + forward.getZ()); log.info("sideward: " + sidewards.getX() + ", " + sidewards.getY() + ", " + sidewards.getZ()); ! log.info("upwrad: " + up.getX() + ", " + up.getY() + ", " + up.getZ()); double angleX = ((double)(e.getX() - previousPos[0]) / 360) * Math.PI; double angleY = ((double)(e.getY() - previousPos[1]) / 360) * Math.PI; if (e.isShiftDown()) { // roll camera ! Geometry.rotate(angleY, forward.getX(), forward.getY(), forward.getZ(), roll, zero); } else if (e.isAltDown()) { // rotate camera about itself - double turn = 1; - if (roll[2] < 0) { - turn = -1; - } Geometry.rotate(angleX, up.getX(), up.getY(), up.getZ(), center, camera); Geometry.rotate(-angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), --- 117,137 ---- Vertex sidewards = up.cross(forward); sidewards.scale(1 / sidewards.length()); ! /*log.info("forward: " + forward.getX() + ", " + forward.getY() + ", " + forward.getZ()); log.info("sideward: " + sidewards.getX() + ", " + sidewards.getY() + ", " + sidewards.getZ()); ! log.info("upwrad: " + up.getX() + ", " + up.getY() + ", " + up.getZ());*/ double angleX = ((double)(e.getX() - previousPos[0]) / 360) * Math.PI; double angleY = ((double)(e.getY() - previousPos[1]) / 360) * Math.PI; + double turn = 1; + if (roll[2] < 0) { + turn = -1; + } if (e.isShiftDown()) { // roll camera ! Geometry.rotate(turn * (-angleY - angleX) / 2, forward.getX(), forward.getY(), forward.getZ(), roll, zero); } else if (e.isAltDown()) { // rotate camera about itself Geometry.rotate(angleX, up.getX(), up.getY(), up.getZ(), center, camera); Geometry.rotate(-angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), *************** *** 142,148 **** } else { // rotate camera about point of view (or selection if any) ! Geometry.rotate(-angleX, up.getX(), up.getY(), up.getZ(), camera, pivot); ! Geometry.rotate(-angleX, up.getX(), up.getY(), up.getZ(), center, pivot); ! //Geometry.rotate(-angleX, 0, 0, 1, roll, new double[]{0, 0, 0}); Geometry.rotate(angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), camera, pivot); --- 142,148 ---- } else { // rotate camera about point of view (or selection if any) ! Geometry.rotate(-angleX, 0, 0, turn, camera, pivot); ! Geometry.rotate(-angleX, 0, 0, turn, center, pivot); ! Geometry.rotate(-angleX, 0, 0, turn, roll, new double[]{0, 0, 0}); Geometry.rotate(angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), camera, pivot); |
From: rimestad <rim...@us...> - 2005-12-01 10:10:20
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3390/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java PencilTool.java ToolFactory.java Added Files: CameraTool.java Removed Files: RotationTool.java CameraZoomTimer.java CameraMoveTimer.java Log Message: removed the two timers from the system and added a renamed rotationtool to cameratool. Changed camera rotation so that it uses the geometry class from the model package. It is now relatively good rotation and drag in the right directions. The are one question ralated to horizontal rotation either we shall rotate about the z-axis or the up vector, as it is now I use the up vector but that makes rotation a bit wird in some situations. If we choose to use the z-axis we cant rotate if we look from above. --- CameraMoveTimer.java DELETED --- --- NEW FILE: CameraTool.java --- //--------------------------------------------------------------------------------- // $Id: CameraTool.java,v 1.1 2005/12/01 10:10:02 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.view.View3D; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Vertex; //import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.InputEvent; import java.awt.Cursor; import javax.swing.Timer; import org.apache.log4j.Logger; /** * The rotationtool */ public class CameraTool extends AbstractTool { /** Rotation mode */ public static final int ROTATION = 0; /** Roll mode */ public static final int ROLL = 1; /** The logger */ private static Logger log = Logger.getLogger(CameraTool.class); /** The carmera move timer */ private static Timer timer; /** The mouse position last time the mouse was pressed initializes to (0,0) */ private static int[] pressPos = new int[2]; /** The current rotation mode */ protected int mode = ROTATION; /** The cursor for rotation */ private Cursor rotationCursor; /** The cursor for drag */ private Cursor dragCursor; /** * KeyListener for the GL Canvas * @param glv The 3D canvas * @param cursor1 The Mouse cursor for rotation * @param cursor2 The Mouse cursor for drag */ public CameraTool(GLView glv, Cursor cursor1, Cursor cursor2) { super(glv, cursor1); rotationCursor = cursor1; dragCursor = cursor2; } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ protected void moved(MouseEvent e) { if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { mode = ROLL; } else { mode = ROTATION; } } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { View view = glv.getView(); if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { glv.setCursor(dragCursor); double[] center = ((View3D)view).getCenter(); double[] camera = ((View3D)view).getCamera(); Vertex first = view.toPlaneCoords(new double[] {previousPos[0], previousPos[1]}, new Plane((camera[0] - center[0]), (camera[1] - center[1]), (camera[2] - center[2]), 0)); Vertex second = view.toPlaneCoords(new double[] {e.getX(), e.getY()}, new Plane((camera[0] - center[0]), (camera[1] - center[1]), (camera[2] - center[2]), 0)); view.translate(new double[] {first.getX() - second.getX(), first.getY() - second.getY(), first.getZ() - second.getZ()}); } else if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK || e.getButton() == MouseEvent.BUTTON1) { View3D view2 = (View3D) view; double[] pivot = super.selectionCenter(); double[] camera = view2.getCamera(); double[] center = view2.getCenter(); double[] roll = view2.getRoll(); double[] zero = new double[]{0, 0, 0}; Vertex up = new Vertex("", roll[0], roll[1], roll[2]); up.scale(1 / up.length()); double x = center[0] - camera[0]; double y = center[1] - camera[1]; double z = center[2] - camera[2]; Vertex forward = new Vertex("", x, y, z); forward.scale(1 / forward.length()); Vertex sidewards = up.cross(forward); sidewards.scale(1 / sidewards.length()); log.info("forward: " + forward.getX() + ", " + forward.getY() + ", " + forward.getZ()); log.info("sideward: " + sidewards.getX() + ", " + sidewards.getY() + ", " + sidewards.getZ()); log.info("upwrad: " + up.getX() + ", " + up.getY() + ", " + up.getZ()); double angleX = ((double)(e.getX() - previousPos[0]) / 360) * Math.PI; double angleY = ((double)(e.getY() - previousPos[1]) / 360) * Math.PI; if (e.isShiftDown()) { // roll camera Geometry.rotate(angleY, forward.getX(), forward.getY(), forward.getZ(), roll, zero); } else if (e.isAltDown()) { // rotate camera about itself double turn = 1; if (roll[2] < 0) { turn = -1; } Geometry.rotate(angleX, up.getX(), up.getY(), up.getZ(), center, camera); Geometry.rotate(-angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), center, camera); Geometry.rotate(angleX, 0, 0, turn, roll, new double[]{0, 0, 0}); Geometry.rotate(angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), roll, zero); } else { // rotate camera about point of view (or selection if any) Geometry.rotate(-angleX, up.getX(), up.getY(), up.getZ(), camera, pivot); Geometry.rotate(-angleX, up.getX(), up.getY(), up.getZ(), center, pivot); //Geometry.rotate(-angleX, 0, 0, 1, roll, new double[]{0, 0, 0}); Geometry.rotate(angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), camera, pivot); Geometry.rotate(angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), center, pivot); Geometry.rotate(angleY, sidewards.getX(), sidewards.getY(), sidewards.getZ(), roll, zero); } glv.repaint(); } } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { glv.setCursor(rotationCursor); if (e.getButton() == MouseEvent.BUTTON1) { if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { mode = ROLL; } else { mode = ROTATION; } } } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { } } Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ToolFactory.java 29 Nov 2005 19:00:39 -0000 1.16 --- ToolFactory.java 1 Dec 2005 10:10:02 -0000 1.17 *************** *** 50,54 **** /** rotation tool */ ! private RotationTool rotation; /** Tape measure tool */ --- 50,54 ---- /** rotation tool */ ! private CameraTool rotation; /** Tape measure tool */ *************** *** 103,110 **** extrusion = new ExtrusionTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); ! rotation = new RotationTool(glv, rotationCursor, dragCursor); tapeMeasure = new TapeMeasureTool(glv, pencilcursor); - Notifier.getInstance().addListener(select); } --- 103,109 ---- extrusion = new ExtrusionTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); ! rotation = new CameraTool(glv, rotationCursor, dragCursor); tapeMeasure = new TapeMeasureTool(glv, pencilcursor); Notifier.getInstance().addListener(select); } --- CameraZoomTimer.java DELETED --- Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** PencilTool.java 30 Nov 2005 23:04:54 -0000 1.40 --- PencilTool.java 1 Dec 2005 10:10:02 -0000 1.41 *************** *** 18,22 **** import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; - import net.sourceforge.bprocessor.gl.view.View3D; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; --- 18,21 ---- *************** *** 641,708 **** } changed = true; - } else if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) { - View3D view = (View3D) glv.getView(); - double[] pivot = AbstractTool.selectionCenter(); - double[] camera = view.getCamera(); - double[] center = view.getCenter(); - double[] roll = view.getRoll(); - - double angle; - if (e.getKeyCode() == KeyEvent.VK_LEFT) { - angle = Math.PI / 18; - } else { - angle = -Math.PI / 18; - } - if (e.isShiftDown()) { - Geometry.rotate(angle, 0, 0, 1, camera, center); - } else if (e.isAltDown()) { - Geometry.rotate(angle, roll[0], roll[1], roll[2], center, camera); - } else { - Geometry.rotate(angle, 0, 0, 1, camera, pivot); - Geometry.rotate(angle, 0, 0, 1, center, pivot); - Geometry.rotate(angle, 0, 0, 1, roll, new double[]{0, 0, 0}); - } - glv.repaint(); - } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) { - View3D view = (View3D) glv.getView(); - double[] pivot = AbstractTool.selectionCenter(); - double[] camera = view.getCamera(); - double[] center = view.getCenter(); - double[] roll = view.getRoll(); - - double[] zero = new double[]{0, 0, 0}; - double x; - double y; - double z; - - Vertex up = new Vertex("", roll[0], roll[1], roll[2]); - x = center[0] - camera[0]; - y = center[1] - camera[1]; - z = center[2] - camera[2]; - Vertex forward = new Vertex("", x, y, z); - - Vertex sidewards = up.cross(forward); - sidewards.scale(1 / sidewards.length()); - x = sidewards.getX(); - y = sidewards.getY(); - z = sidewards.getZ(); - - double angle; - if (e.getKeyCode() == KeyEvent.VK_UP) { - angle = Math.PI / 18; - } else { - angle = -Math.PI / 18; - } - if (e.isShiftDown()) { - Geometry.rotate(angle, x, y, z, camera, center); - } else if (e.isAltDown()) { - Geometry.rotate(angle, x, y, z, center, camera); - } else { - Geometry.rotate(angle, x, y, z, camera, pivot); - Geometry.rotate(angle, x, y, z, center, pivot); - Geometry.rotate(angle, x, y, z, roll, zero); - } - - glv.repaint(); } else { super.keyPressed(e); --- 640,643 ---- Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** AbstractTool.java 30 Nov 2005 23:04:54 -0000 1.32 --- AbstractTool.java 1 Dec 2005 10:10:02 -0000 1.33 *************** *** 12,15 **** --- 12,16 ---- import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.gl.view.View; + import net.sourceforge.bprocessor.gl.view.View3D; import net.sourceforge.bprocessor.gl.GLView; *************** *** 100,106 **** View v = glv.getView(); if (rotation > 0) { ! v.zoom(1.1); } else { ! v.zoom(0.9); } glv.repaint(false); --- 101,107 ---- View v = glv.getView(); if (rotation > 0) { ! v.zoomout(); } else { ! v.zoomin(); } glv.repaint(false); *************** *** 112,117 **** * @return The center of the selection */ ! public static double[] selectionCenter() { ! double[] center = new double[] {0, 0, 0}; Iterator it = selection.iterator(); if (it.hasNext()) { --- 113,118 ---- * @return The center of the selection */ ! public double[] selectionCenter() { ! double[] center = ((View3D)glv.getView()).getCenter(); Iterator it = selection.iterator(); if (it.hasNext()) { *************** *** 137,151 **** View v = glv.getView(); if (e.getKeyCode() == KeyEvent.VK_UP) { ! v.translateCenter(new double[] {0.0, -1.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { ! v.translateCenter(new double[] {0.0, 1.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { ! v.translateCenter(new double[] {-1.0, 0.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { ! v.translateCenter(new double[] {1.0, 0.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_Z) { ! v.zoom(1.1); } else if (e.getKeyCode() == KeyEvent.VK_X) { ! v.zoom(0.9); } else if (e.getKeyCode() == KeyEvent.VK_Q) { glv.changeTool(Tool.SELECT_TOOL); --- 138,152 ---- View v = glv.getView(); if (e.getKeyCode() == KeyEvent.VK_UP) { ! v.translate(new double[] {0.0, -1.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { ! v.translate(new double[] {0.0, 1.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { ! v.translate(new double[] {-1.0, 0.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { ! v.translate(new double[] {1.0, 0.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_Z) { ! v.zoomout(); } else if (e.getKeyCode() == KeyEvent.VK_X) { ! v.zoomin(); } else if (e.getKeyCode() == KeyEvent.VK_Q) { glv.changeTool(Tool.SELECT_TOOL); --- RotationTool.java DELETED --- |
From: rimestad <rim...@us...> - 2005-12-01 10:10:18
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3390/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java View.java View3D.java Log Message: removed the two timers from the system and added a renamed rotationtool to cameratool. Changed camera rotation so that it uses the geometry class from the model package. It is now relatively good rotation and drag in the right directions. The are one question ralated to horizontal rotation either we shall rotate about the z-axis or the up vector, as it is now I use the up vector but that makes rotation a bit wird in some situations. If we choose to use the z-axis we cant rotate if we look from above. Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** AbstractView.java 30 Nov 2005 23:04:54 -0000 1.65 --- AbstractView.java 1 Dec 2005 10:10:02 -0000 1.66 *************** *** 109,115 **** protected GLUT glut = new GLUT(); - /** The zoomFactor in the parent view */ - protected double zoomFactor = 1.0; - /** The GLView */ protected GLView glv = null; --- 109,112 ---- *************** *** 1234,1238 **** * @param change The change in R+ (is divided with the window height) */ ! public void translateRotationX(double change) { } --- 1231,1235 ---- * @param change The change in R+ (is divided with the window height) */ ! public void rotateVertical(double change) { } *************** *** 1241,1260 **** * @param change The change in R+ (is divided with the window height) */ ! public void translateRotationY(double change) { } /** - * Change the zoom factor of the camera take only R+ - * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom - * @param zoom the zoom factor change - */ - public void zoom(double zoom) { - if (zoom > 0) { - zoom *= getZoomFactor(); - setZoomFactor(zoom); - } - } - - /** * Change view to 3d, XY, XZ, or YZ * @param value One of 3d_VIEW, XY_VIEW, XZ_VIEW, YZ_VIEW --- 1238,1245 ---- * @param change The change in R+ (is divided with the window height) */ ! public void rotateHorizontal(double change) { } /** * Change view to 3d, XY, XZ, or YZ * @param value One of 3d_VIEW, XY_VIEW, XZ_VIEW, YZ_VIEW *************** *** 1262,1281 **** public void changeView(int value) { } - /** - * setter for zoomFactor - * @param z The new zoomFactor - */ - public void setZoomFactor(double z) { - zoomFactor = z; - } - - /** - * getter for zoomFactor - * @return The parent zoomFactor - */ - public double getZoomFactor() { - return zoomFactor; - } - /** * Getter for activeEdge --- 1247,1250 ---- *************** *** 1607,1611 **** * @param mv the move vector */ ! public abstract void translateCenter(double [] mv); /** --- 1576,1580 ---- * @param mv the move vector */ ! public abstract void translate(double [] mv); /** Index: View3D.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View3D.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** View3D.java 24 Nov 2005 10:31:22 -0000 1.23 --- View3D.java 1 Dec 2005 10:10:02 -0000 1.24 *************** *** 89,94 **** double aspect = width / height; ! double near = 1 * getZoomFactor(); ! double far = 1000.0 * getZoomFactor(); focalwidth = 60.0; if (aspect < 1.0) { --- 89,97 ---- double aspect = width / height; ! double length = Math.sqrt((camera[0] - center[0]) * (camera[0] - center[0]) + ! (camera[1] - center[1]) * (camera[1] - center[1]) + ! (camera[2] - center[2]) * (camera[2] - center[2])); ! double near = length / 10; ! double far = length * 100.0; focalwidth = 60.0; if (aspect < 1.0) { *************** *** 102,108 **** gl.glLoadIdentity(); ! glu.gluLookAt(center[0] + (camera[0] - center[0]) * getZoomFactor(), ! center[1] + (camera[1] - center[1]) * getZoomFactor(), ! center[2] + (camera[2] - center[2]) * getZoomFactor(), center[0], center[1], center[2], roll[0], roll[1], roll[2]); --- 105,111 ---- gl.glLoadIdentity(); ! glu.gluLookAt(center[0] + (camera[0] - center[0]), ! center[1] + (camera[1] - center[1]), ! center[2] + (camera[2] - center[2]), center[0], center[1], center[2], roll[0], roll[1], roll[2]); *************** *** 145,159 **** * @param mv the move vector */ ! public void translateCenter(double [] mv) { if (mv.length == 3) { ! double x = modelMatrix[0] * mv[0] - modelMatrix[1] * mv[1] + modelMatrix[2] * mv[2]; ! double y = modelMatrix[4] * mv[0] - modelMatrix[5] * mv[1] + modelMatrix[6] * mv[2]; ! double z = modelMatrix[8] * mv[0] - modelMatrix[9] * mv[1] + modelMatrix[10] * mv[2]; ! center[0] += x * getZoomFactor(); ! center[1] += y * getZoomFactor(); ! center[2] += z * getZoomFactor(); ! camera[0] += x * getZoomFactor(); ! camera[1] += y * getZoomFactor(); ! camera[2] += z * getZoomFactor(); } else { log.error("[translateViewMatrix] Wrong parameter size"); --- 148,159 ---- * @param mv the move vector */ ! public void translate(double [] mv) { if (mv.length == 3) { ! center[0] += mv[0]; ! center[1] += mv[1]; ! center[2] += mv[2]; ! camera[0] += mv[0]; ! camera[1] += mv[1]; ! camera[2] += mv[2]; } else { log.error("[translateViewMatrix] Wrong parameter size"); *************** *** 178,183 **** * @param change The change in R+ (is divided with the window height) */ ! public void translateRotationX(double change) { ! translateRotationX(change, center); } --- 178,183 ---- * @param change The change in R+ (is divided with the window height) */ ! public void rotateVertical(double change) { ! rotateVertical(change, center); } *************** *** 187,191 **** * @param c The point to rotate about */ ! public void translateRotationX(double change, double[] c) { double angle = change / width; rotate(-angle, c, modelMatrix[0], modelMatrix[4], modelMatrix[8]); --- 187,191 ---- * @param c The point to rotate about */ ! public void rotateVertical(double change, double[] c) { double angle = change / width; rotate(-angle, c, modelMatrix[0], modelMatrix[4], modelMatrix[8]); *************** *** 202,208 **** public void rotate(double angle, double[] c, double x, double y, double z) { double rx, ry, rz; ! double dx = (camera[0] - c[0]); ! double dy = (camera[1] - c[1]); ! double dz = (camera[2] - c[2]); double sinx, cosx, siny, sinz, cosy, cosz; --- 202,208 ---- public void rotate(double angle, double[] c, double x, double y, double z) { double rx, ry, rz; ! double dx = (camera[0]); ! double dy = (camera[1]); ! double dz = (camera[2]); double sinx, cosx, siny, sinz, cosy, cosz; *************** *** 232,242 **** rz = dx * rot[6] + dy * rot[7] + dz * rot[8]; ! camera[0] = rx + c[0]; ! camera[1] = ry + c[1]; ! camera[2] = rz + c[2]; ! roll[0] = roll[0] * rot[0] + roll[1] * rot[1] + roll[2] * rot[2]; roll[1] = roll[0] * rot[3] + roll[1] * rot[4] + roll[2] * rot[5]; roll[2] = roll[0] * rot[6] + roll[1] * rot[7] + roll[2] * rot[8]; } --- 232,249 ---- rz = dx * rot[6] + dy * rot[7] + dz * rot[8]; ! camera[0] = rx; ! camera[1] = ry; ! camera[2] = rz; ! if (c != center) { ! //rotate center as well ! center[0] = center[0] * rot[0] + center[1] * rot[1] + center[2] * rot[2]; ! center[1] = center[0] * rot[3] + center[1] * rot[4] + center[2] * rot[5]; ! center[2] = center[0] * rot[6] + center[1] * rot[7] + center[2] * rot[8]; ! } ! /* roll[0] = roll[0] * rot[0] + roll[1] * rot[1] + roll[2] * rot[2]; roll[1] = roll[0] * rot[3] + roll[1] * rot[4] + roll[2] * rot[5]; roll[2] = roll[0] * rot[6] + roll[1] * rot[7] + roll[2] * rot[8]; + */ } *************** *** 280,284 **** * @param c The point to rotate about */ ! public void translateRotationY(double change, double[] c) { double angle = change / height; if (roll[2] < 0) { --- 287,291 ---- * @param c The point to rotate about */ ! public void rotateHorizontal(double change, double[] c) { double angle = change / height; if (roll[2] < 0) { *************** *** 293,298 **** * @param change The change in R+ (is divided with the window height) */ ! public void translateRotationY(double change) { ! translateRotationY(change, center); } --- 300,305 ---- * @param change The change in R+ (is divided with the window height) */ ! public void rotateHorizontal(double change) { ! rotateHorizontal(change, center); } *************** *** 312,316 **** camera[2] = 25.0; roll[0] = .0; ! roll[1] = .1; roll[2] = .0; } --- 319,323 ---- camera[2] = 25.0; roll[0] = .0; ! roll[1] = 1.0; roll[2] = .0; } *************** *** 326,330 **** roll[0] = .0; roll[1] = .0; ! roll[2] = .1; } if (value == View.VIEW_YZ) { --- 333,337 ---- roll[0] = .0; roll[1] = .0; ! roll[2] = 1.0; } if (value == View.VIEW_YZ) { *************** *** 339,343 **** roll[0] = .0; roll[1] = .0; ! roll[2] = .1; } if (value == View.VIEW_3D) { --- 346,350 ---- roll[0] = .0; roll[1] = .0; ! roll[2] = 1.0; } if (value == View.VIEW_3D) { *************** *** 437,443 **** return vertex; } ! } ! log.warn("Too many arguments"); ! return new Vertex(""); } --- 444,451 ---- return vertex; } ! } else { ! log.warn("Too many arguments " + coords.length + ", " + plane.toString()); ! } ! return null; } *************** *** 449,452 **** return new Transformation(glu, modelMatrix, projMatrix, screenport); } ! } --- 457,477 ---- return new Transformation(glu, modelMatrix, projMatrix, screenport); } ! ! /** ! * Function to zoom in ! */ ! public void zoomin() { ! camera[0] -= (camera[0] - center[0]) * 0.1; ! camera[1] -= (camera[1] - center[1]) * 0.1; ! camera[2] -= (camera[2] - center[2]) * 0.1; ! } ! ! /** ! * Function to zoom out ! */ ! public void zoomout() { ! camera[0] += (camera[0] - center[0]) * 0.1; ! camera[1] += (camera[1] - center[1]) * 0.1; ! camera[2] += (camera[2] - center[2]) * 0.1; ! } } Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** View.java 30 Nov 2005 23:04:54 -0000 1.24 --- View.java 1 Dec 2005 10:10:02 -0000 1.25 *************** *** 118,155 **** * @param mv the move vector */ ! public void translateCenter(double[] mv); /** ! * Change the zoom factor of the camera take only R+ ! * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom ! * @param zoom the zoom factor change */ ! public void zoom(double zoom); /** ! * Change the rotation about the x axis. Only usable in 3D ! * @param change The change in R+ (is divided with the window height) */ ! public void translateRotationX(double change); /** ! * Change the rotation about the y axis. Only usable in 3D * @param change The change in R+ (is divided with the window height) */ ! public void translateRotationY(double change); ! /** ! * Change the rotation about the y axis * @param change The change in R+ (is divided with the window height) * @param center The point to rotate about */ ! public void translateRotationY(double change, double[] center); /** ! * Change the rotation about the x axis * @param change The change in R+ (is divided with the window height) * @param center The point to rotate about */ ! public void translateRotationX(double change, double[] center); /** --- 118,158 ---- * @param mv the move vector */ ! public void translate(double[] mv); /** ! * zoom the camera in */ ! public void zoomin(); /** ! * zoom the camera out */ ! public void zoomout(); /** ! * Change the rotation about the x axis. Only usable in 3D * @param change The change in R+ (is divided with the window height) */ ! public void rotateVertical(double change); ! /** ! * Change the rotation about the x axis * @param change The change in R+ (is divided with the window height) * @param center The point to rotate about */ ! public void rotateVertical(double change, double[] center); /** ! * Change the rotation about the y axis. Only usable in 3D ! * @param change The change in R+ (is divided with the window height) ! */ ! public void rotateHorizontal(double change); ! ! /** ! * Change the rotation about the y axis * @param change The change in R+ (is divided with the window height) * @param center The point to rotate about */ ! public void rotateHorizontal(double change, double[] center); /** *************** *** 184,193 **** /** - * getter for zoomFactor - * @return The parent zoomFactor - */ - public double getZoomFactor(); - - /** * Setter for snapVertex * @param v The new snapVertex --- 187,190 ---- |
From: Michael L. <he...@us...> - 2005-11-30 23:05:03
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26883/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java View.java Log Message: Penciltool finds intersection when hitting two edges Catmull-Clark has a corner-rule Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** AbstractView.java 30 Nov 2005 15:43:21 -0000 1.64 --- AbstractView.java 30 Nov 2005 23:04:54 -0000 1.65 *************** *** 1104,1108 **** */ private void drawVertexHit(Vertex v) { - // TODO draw a point gl.glPointSize(7.0f); gl.glBegin(GL.GL_POINTS); --- 1104,1107 ---- *************** *** 1110,1118 **** gl.glEnd(); gl.glPointSize(1.0f); - - //gl.glPushMatrix(); - //gl.glTranslated(v.getX(), v.getY(), v.getZ()); - //glu.gluSphere(ball, 0.5, 8, 8); - //gl.glPopMatrix(); } --- 1109,1112 ---- *************** *** 1417,1425 **** /** * Processes the select buffer ! * @return the ID of the closest hit and -1 if no hit. */ ! private Object processSelect() { ! //Processing hits ! // TODO Find vertices int bufferOffset = 0; int names = 0; --- 1411,1418 ---- /** * Processes the select buffer ! * @return the closest hit and null if no hit. */ ! private List processSelect() { ! List selection = new LinkedList(); int bufferOffset = 0; int names = 0; *************** *** 1475,1479 **** if (Math.abs(vLocal.getZ()) < 0.0000000001) { ! return v; } } --- 1468,1473 ---- if (Math.abs(vLocal.getZ()) < 0.0000000001) { ! selection.add(v); ! return selection; } } *************** *** 1489,1521 **** Vertex from = e.getFrom(); Vertex to = e.getTo(); - if (vertices.contains(from)) { - return from; - } - if (vertices.contains(to)) { - return to; - } // Test if from and to are in the same plane as the closest surface Vertex fromLocal = system.translate(from); Vertex toLocal = system.translate(to); ! if ((Math.abs(fromLocal.getZ()) < 0.0000000001) ! && (Math.abs(toLocal.getZ()) < 0.0000000001)) { ! return e; } } } } if (closest instanceof Edge) { Edge edge = (Edge) closest; if (vertices.contains(edge.getFrom())) { ! return edge.getFrom(); } if (vertices.contains(edge.getTo())) { ! return edge.getTo(); } } if (closest instanceof ClippingPlane) { ClippingPlane cp = (ClippingPlane) closest; } ! return closest; } --- 1483,1535 ---- Vertex from = e.getFrom(); Vertex to = e.getTo(); // Test if from and to are in the same plane as the closest surface Vertex fromLocal = system.translate(from); Vertex toLocal = system.translate(to); ! boolean fromIn = (Math.abs(fromLocal.getZ()) < 0.0000000001); ! boolean toIn = (Math.abs(toLocal.getZ()) < 0.0000000001); ! ! if (fromIn && vertices.contains(from)) { ! selection.add(from); ! return selection; ! } ! ! if (toIn && vertices.contains(to)) { ! selection.add(to); ! return selection; ! } ! if (fromIn && toIn) { ! selection.add(e); } } } + if (!selection.isEmpty()) { + return selection; + } } if (closest instanceof Edge) { Edge edge = (Edge) closest; if (vertices.contains(edge.getFrom())) { ! selection.add(edge.getFrom()); ! return selection; } if (vertices.contains(edge.getTo())) { ! selection.add(edge.getTo()); ! return selection; } + selection.add(edge); + Iterator iter = edges.iterator(); + while (iter.hasNext()) { + Object o = iter.next(); + if (o != edge) { + selection.add(o); + } + } + return selection; } if (closest instanceof ClippingPlane) { ClippingPlane cp = (ClippingPlane) closest; } ! selection.add(closest); ! return selection; } *************** *** 1526,1530 **** * @return The object under the point, null if no object is there */ ! public Object getObjectAtPoint(double x, double y) { int id; this.x = x; --- 1540,1544 ---- * @return The object under the point, null if no object is there */ ! public List getObjectAtPoint(double x, double y) { int id; this.x = x; *************** *** 1537,1543 **** glv.repaint(true); ! Object o = processSelect(); clearNames(); ! return o; } --- 1551,1557 ---- glv.repaint(true); ! List selection = processSelect(); clearNames(); ! return selection; } Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** View.java 30 Nov 2005 15:43:20 -0000 1.23 --- View.java 30 Nov 2005 23:04:54 -0000 1.24 *************** *** 7,10 **** --- 7,12 ---- package net.sourceforge.bprocessor.gl.view; + import java.util.List; + import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; *************** *** 230,234 **** * @return The object under the point, null if no object is there. */ ! public Object getObjectAtPoint(double x, double y); /** --- 232,236 ---- * @return The object under the point, null if no object is there. */ ! public List getObjectAtPoint(double x, double y); /** |
From: Michael L. <he...@us...> - 2005-11-30 23:05:03
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26883/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java PencilTool.java CatmullClark.java Log Message: Penciltool finds intersection when hitting two edges Catmull-Clark has a corner-rule Index: CatmullClark.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/CatmullClark.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CatmullClark.java 30 Nov 2005 08:51:50 -0000 1.2 --- CatmullClark.java 30 Nov 2005 23:04:54 -0000 1.3 *************** *** 307,318 **** /** * Check if this is a crease vertex - this ! * is wrong, there should be a tag. Some * vertices with 2 or 3 edges are not crease. * @param v The vertex ! * @return Crease or not */ boolean crease(Vertex v) { int k = elGet(v).size(); ! return (k < 4); } --- 307,338 ---- /** * Check if this is a crease vertex - this ! * is a temporary solution, there should be a tag. Some * vertices with 2 or 3 edges are not crease. * @param v The vertex ! * @return True if crease */ boolean crease(Vertex v) { int k = elGet(v).size(); ! return (k == 3); ! } ! ! /** ! * Is it a corner? ! * @param v The vertex ! * @return True if corner ! */ ! boolean corner(Vertex v) { ! int k = elGet(v).size(); ! return (k == 2); ! } ! ! /** ! * Is it smooth? ! * @param v The vertex ! * @return True if smooth ! */ ! boolean smooth(Vertex v) { ! int k = elGet(v).size(); ! return (k == 4); } *************** *** 416,420 **** double n = es.size(); double[] values = new double[3]; ! if (n > 3) { List adjacent = facelistGet(v); List pts = new LinkedList(); --- 436,440 ---- double n = es.size(); double[] values = new double[3]; ! if (n == 4) { List adjacent = facelistGet(v); List pts = new LinkedList(); *************** *** 442,456 **** values[1] = q[1] / n + r[1] / n + (n - 2) * p[1] / n; values[2] = q[2] / n + r[2] / n + (n - 2) * p[2] / n; ! } else { ! values[0] = v.getX() * 6; values[1] = v.getY() * 6; values[2] = v.getZ() * 6; Iterator esit = es.iterator(); while (esit.hasNext()) { Edge e = (Edge) esit.next(); Vertex to = e.otherVertex(v); ! if (crease(to)) { values[0] += to.getX(); values[1] += to.getY(); --- 462,476 ---- values[1] = q[1] / n + r[1] / n + (n - 2) * p[1] / n; values[2] = q[2] / n + r[2] / n + (n - 2) * p[2] / n; ! } else if (n == 3) { values[0] = v.getX() * 6; values[1] = v.getY() * 6; values[2] = v.getZ() * 6; + Iterator esit = es.iterator(); while (esit.hasNext()) { Edge e = (Edge) esit.next(); Vertex to = e.otherVertex(v); ! if (!smooth(to)) { values[0] += to.getX(); values[1] += to.getY(); *************** *** 458,465 **** } } - values[0] /= 8.0; values[1] /= 8.0; values[2] /= 8.0; } positions.add(values); --- 478,488 ---- } } values[0] /= 8.0; values[1] /= 8.0; values[2] /= 8.0; + } else { + values[0] = v.getX(); + values[1] = v.getY(); + values[2] = v.getZ(); } positions.add(values); Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** PencilTool.java 24 Nov 2005 13:50:54 -0000 1.39 --- PencilTool.java 30 Nov 2005 23:04:54 -0000 1.40 *************** *** 71,74 **** --- 71,81 ---- /** The wanted length of the previous edge */ private String number = ""; + + /** Edge one */ + private Edge splitE1; + + /** Edge two */ + private Edge splitE2; + /** *************** *** 80,83 **** --- 87,121 ---- super(glv, cursor); } + + /** + * Find the object under the mouse and set target + * @param event The MouseEvent + */ + protected void findPencilTarget(MouseEvent event) { + splitE1 = null; + splitE2 = null; + int x = event.getX(); + int y = event.getY(); + View view = glv.getView(); + List selection = view.getObjectAtPoint(x, y); + if (selection.isEmpty()) { + target = null; + } else { + if (selection.size() > 1) { + Edge e1 = (Edge) selection.get(0); + Edge e2 = (Edge) selection.get(1); + Edge intersect = e1.intersection(e2); + if (intersect == null) { + target = e1; + } else { + target = intersect.getFrom(); + splitE1 = e1; + splitE2 = e2; + } + } else { + target = selection.get(0); + } + } + } /** *************** *** 149,156 **** edges = new ArrayList(); intern(vertex); ! if (target != null) { ! if (target instanceof Edge) { ! Edge edge = (Edge) target; ! edge.split(vertex); } } --- 187,198 ---- edges = new ArrayList(); intern(vertex); ! if (splitE1 != null) { ! if (!splitE1.getConstructor()) { ! splitE1.split(vertex); ! } ! } ! if (splitE2 != null) { ! if (!splitE2.getConstructor()) { ! splitE2.split(vertex); } } *************** *** 162,172 **** // The following lines of code are there to make sure // that a Surface is finished when clicking an edge.. ! if (target != null) { ! if (target instanceof Edge) { intern(vertex); ! Edge edge = (Edge) target; ! edge.split(vertex); } ! } if (vertex.getId() == null) { //log.info("ID was null on " + vertex); --- 204,219 ---- // The following lines of code are there to make sure // that a Surface is finished when clicking an edge.. ! if (splitE1 != null) { ! if (!splitE1.getConstructor()) { intern(vertex); ! splitE1.split(vertex); } ! } ! if (splitE2 != null) { ! if (!splitE2.getConstructor()) { ! intern(vertex); ! splitE2.split(vertex); ! } ! } if (vertex.getId() == null) { //log.info("ID was null on " + vertex); *************** *** 381,384 **** --- 428,432 ---- vertex.setName("current"); current = vertex; + splitE1 = edge; } } else { *************** *** 423,427 **** */ protected void pressed(MouseEvent e) { ! findTarget(e); glv.getView().makeTarget(target); boolean legal = findVertex(e); --- 471,475 ---- */ protected void pressed(MouseEvent e) { ! findPencilTarget(e); glv.getView().makeTarget(target); boolean legal = findVertex(e); *************** *** 435,439 **** */ protected void moved(MouseEvent e) { ! findTarget(e); glv.getView().makeTarget(target); if (target != null) { --- 483,487 ---- */ protected void moved(MouseEvent e) { ! findPencilTarget(e); glv.getView().makeTarget(target); if (target != null) { *************** *** 485,489 **** */ protected void released(MouseEvent e) { ! findTarget(e); glv.getView().makeTarget(target); } --- 533,537 ---- */ protected void released(MouseEvent e) { ! findPencilTarget(e); glv.getView().makeTarget(target); } Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** AbstractTool.java 24 Nov 2005 10:31:22 -0000 1.31 --- AbstractTool.java 30 Nov 2005 23:04:54 -0000 1.32 *************** *** 538,542 **** int y = event.getY(); View view = glv.getView(); ! target = view.getObjectAtPoint(x, y); } } --- 538,547 ---- int y = event.getY(); View view = glv.getView(); ! List selection = view.getObjectAtPoint(x, y); ! if (selection.isEmpty()) { ! target = null; ! } else { ! target = selection.get(0); ! } } } |
From: Nordholt <nor...@us...> - 2005-11-30 15:46:00
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19380 Modified Files: GLColorMenuActionListener.java Log Message: fixed bug when trying to go back to default colors Index: GLColorMenuActionListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/GLColorMenuActionListener.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GLColorMenuActionListener.java 23 Nov 2005 19:02:10 -0000 1.1 --- GLColorMenuActionListener.java 30 Nov 2005 15:45:38 -0000 1.2 *************** *** 63,68 **** } else if (e.getActionCommand().equals("Default")) { view.setBGColor(View.BACKGROUND_COLOR); ! view.setBGColor(View.GRID_COLOR); ! view.setBGColor(View.STD_LINE_COLOR); } --- 63,68 ---- } else if (e.getActionCommand().equals("Default")) { view.setBGColor(View.BACKGROUND_COLOR); ! view.setGridColor(View.GRID_COLOR); ! view.setLineColor(View.STD_LINE_COLOR); } |
From: Nordholt <nor...@us...> - 2005-11-30 15:43:29
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18773 Modified Files: View.java AbstractView.java Log Message: added support for temporary vertices, edges and surfaces to be drawn but not added to the database Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** AbstractView.java 30 Nov 2005 08:51:49 -0000 1.63 --- AbstractView.java 30 Nov 2005 15:43:21 -0000 1.64 *************** *** 176,179 **** --- 176,188 ---- private boolean backLabelSelect = false; + /** Temporary edges. Will be drawn but not put in database */ + private Set tempEdges; + + /** Temporary surfaces. Will be drawn but not put in database */ + private Set tempSurfaces; + + /** Temporary verticies. Will be drawn but not put in database */ + private Set tempVertices; + static { setTransparency(100); *************** *** 239,242 **** --- 248,254 ---- lineColor = STD_LINE_COLOR; gridColor = GRID_COLOR; + tempEdges = new HashSet(); + tempSurfaces = new HashSet(); + tempVertices = new HashSet(); } *************** *** 684,687 **** --- 696,705 ---- drawEdge(e); } + //draw all temporary edges. + Iterator tempEdgeIt = tempEdges.iterator(); + while (tempEdgeIt.hasNext()) { + Edge e = (Edge)tempEdgeIt.next(); + drawEdge(e); + } } *************** *** 701,704 **** --- 719,736 ---- } } + //Draw any temporary vertex not part of an edge + gl.glColor3fv(lineColor); + it = tempVertices.iterator(); + while (it.hasNext()) { + Vertex v = (Vertex)it.next(); + if (v.getEdges().isEmpty()) { + gl.glColor3fv(lineColor); + gl.glPointSize(5.0f); + gl.glBegin(GL.GL_POINTS); + gl.glVertex3d(v.getX(), v.getY(), v.getZ()); + gl.glEnd(); + gl.glPointSize(1.0f); + } + } } *************** *** 1038,1051 **** if (to != null && from != null) { if (e.getConstructor()) { - Vertex minus = to.minus(from); - minus.scale(1 / minus.length()); gl.glEnable(GL.GL_LINE_STIPPLE); gl.glBegin(GL.GL_LINE_STRIP); ! gl.glVertex3d(to.getX() + minus.getX() * 50, ! to.getY() + minus.getY() * 50, ! to.getZ() + minus.getZ() * 50); ! gl.glVertex3d(from.getX() + minus.getX() * -50, ! from.getY() + minus.getY() * -50, ! from.getZ() + minus.getZ() * -50); gl.glEnd(); gl.glDisable(GL.GL_LINE_STIPPLE); --- 1070,1081 ---- if (to != null && from != null) { if (e.getConstructor()) { gl.glEnable(GL.GL_LINE_STIPPLE); gl.glBegin(GL.GL_LINE_STRIP); ! gl.glVertex3d(to.getX(), ! to.getY(), ! to.getZ()); ! gl.glVertex3d(from.getX(), ! from.getY(), ! from.getZ()); gl.glEnd(); gl.glDisable(GL.GL_LINE_STIPPLE); *************** *** 1127,1130 **** --- 1157,1176 ---- } } + + it = tempSurfaces.iterator(); + while (it.hasNext()) { + Surface s = (Surface)it.next(); + if (!selection.contains(s)) { + if ((s.getBackDomain() instanceof FunctionalSpace) && + (s.getFrontDomain() instanceof FunctionalSpace)) { + //gl.glEnable(GL.GL_POLYGON_STIPPLE); + //gl.glPolygonStipple(transparency); + //drawSurface(s); + //gl.glDisable(GL.GL_POLYGON_STIPPLE); + } else { + drawSurface(s); + } + } + } } *************** *** 1741,1743 **** --- 1787,1838 ---- gridColor = color; } + + /** + * Adds a temporary surface to be drawn. + * @param s the surface + */ + public void addTempSurface(Surface s) { + tempSurfaces.add(s); + } + + /** + * Removes a temporary surface + * @param s the surface to remove + */ + public void removeTempSurface(Surface s) { + tempSurfaces.remove(s); + } + + /** + * Adds a temporary edge to be drawn. + * @param e the edge + */ + public void addTempEdge(Edge e) { + tempEdges.add(e); + } + + /** + * Removes a temporary edge + * @param e the edge to remove + */ + public void removeTempEdge(Edge e) { + tempEdges.remove(e); + } + + /** + * Adds a temporary surface to be drawn. + * @param v the vertex + */ + public void addTempVertex(Vertex v) { + tempVertices.add(v); + } + + /** + * Removes a temporary vertex + * @param v the vertex to remove + */ + public void removeTempVertex(Vertex v) { + tempVertices.remove(v); + } + } Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** View.java 23 Nov 2005 19:05:14 -0000 1.22 --- View.java 30 Nov 2005 15:43:20 -0000 1.23 *************** *** 287,299 **** */ public void setBGColor(float[] color); ! /** * Sets the line color * @param color the color. */ public void setLineColor(float[] color); ! /** * Sets the grid color * @param color the color. */ public void setGridColor(float[] color); } --- 287,336 ---- */ public void setBGColor(float[] color); ! /** * Sets the line color * @param color the color. */ public void setLineColor(float[] color); ! /** * Sets the grid color * @param color the color. */ public void setGridColor(float[] color); + + /** + * Adds a temporary surface to be drawn. + * @param s the surface + */ + public void addTempSurface(Surface s); + + /** + * Removes a temporary surface + * @param s the surface to remove + */ + public void removeTempSurface(Surface s); + + /** + * Adds a temporary edge to be drawn. + * @param e the edge + */ + public void addTempEdge(Edge e); + + /** + * Removes a temporary edge + * @param e the edge to remove + */ + public void removeTempEdge(Edge e); + + /** + * Adds a temporary surface to be drawn. + * @param v the vertex + */ + public void addTempVertex(Vertex v); + + /** + * Removes a temporary vertex + * @param v the vertex to remove + */ + public void removeTempVertex(Vertex v); + } |
From: Nordholt <nor...@us...> - 2005-11-30 15:40:09
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17844 Modified Files: TapeMeasureTool.java Log Message: added new temporary construction line, display of length and control from length field Index: TapeMeasureTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/TapeMeasureTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TapeMeasureTool.java 29 Nov 2005 18:59:40 -0000 1.1 --- TapeMeasureTool.java 30 Nov 2005 15:39:59 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- import java.awt.Cursor; import java.awt.event.MouseEvent; + import java.awt.event.KeyEvent; import net.sourceforge.bprocessor.model.Edge; *************** *** 50,53 **** --- 51,57 ---- private Vertex edgeNormal; + /** The current number in the length field */ + private String number; + /** * Constructor *************** *** 69,110 **** if (target instanceof Surface) { Surface targetSurface = (Surface)target; ! glv.getView().makeTarget(target); ! movePlane = targetSurface.plane(); ! Vertex edgeDirection = currentEdge.getTo().minus(currentEdge.getFrom()); ! Vertex surfaceNormal = targetSurface.normal(); ! edgeNormal = edgeDirection.cross(surfaceNormal); ! edgeNormal.scale(1 / edgeNormal.length()); ! double x = e.getX(); ! double y = AbstractView.getHeight() - e.getY(); ! View v = glv.getView(); ! Transformation transformation = v.transformation(); ! Vertex near = new Vertex("near", x, y, 0.0); ! Vertex far = new Vertex("far", x, y, 1.0); ! Edge ray = new Edge("ray", near, far); ! ray = transformation.unProject(ray); ! Vertex intersect = movePlane.intersection(ray); ! Vertex delta = intersect.minus(constructionPoint); ! edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); ! currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); ! constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); } } else { ! edgeNormal.scale(1 / edgeNormal.length()); ! double x = e.getX(); ! double y = AbstractView.getHeight() - e.getY(); ! View v = glv.getView(); ! Transformation transformation = v.transformation(); ! Vertex near = new Vertex("near", x, y, 0.0); ! Vertex far = new Vertex("far", x, y, 1.0); ! Edge ray = new Edge("ray", near, far); ! ray = transformation.unProject(ray); ! Vertex intersect = movePlane.intersection(ray); ! Vertex delta = intersect.minus(constructionPoint); ! edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); ! currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); ! constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); } } } /** --- 73,117 ---- if (target instanceof Surface) { Surface targetSurface = (Surface)target; ! if (currentEdge.getSurfaces().contains(targetSurface)) { ! number = ""; ! glv.getView().makeTarget(target); ! movePlane = targetSurface.plane(); ! Vertex edgeDirection = currentEdge.getTo().minus(currentEdge.getFrom()); ! Vertex surfaceNormal = targetSurface.normal(); ! edgeNormal = edgeDirection.cross(surfaceNormal); ! move(e); ! } } } else { ! move(e); } + } else { + findTarget(e); + glv.getView().makeTarget(target); } } + + /** + * moves the construction line. + * @param e the mouseevent. + */ + private void move(MouseEvent e) { + edgeNormal.scale(1 / edgeNormal.length()); + double x = e.getX(); + double y = AbstractView.getHeight() - e.getY(); + View v = glv.getView(); + Transformation transformation = v.transformation(); + Vertex near = new Vertex("near", x, y, 0.0); + Vertex far = new Vertex("far", x, y, 1.0); + Edge ray = new Edge("ray", near, far); + ray = transformation.unProject(ray); + Vertex intersect = movePlane.intersection(ray); + Vertex delta = intersect.minus(constructionPoint); + edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); + currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); + constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); + number = ""; + glv.setLength(edgeToConstruction.getLength()); + } /** *************** *** 124,129 **** if (target instanceof Edge) { currentEdge = (Edge)target; ! Vertex constructionFrom = createVertex(currentEdge.getFrom().copy()); ! Vertex constructionTo = createVertex(currentEdge.getTo().copy()); currentConstruction = createEdge(constructionFrom, constructionTo); currentConstruction.setConstructor(true); --- 131,149 ---- if (target instanceof Edge) { currentEdge = (Edge)target; ! ! Vertex minus = currentEdge.getTo().minus(currentEdge.getFrom()); ! minus.scale(1 / minus.length()); ! Vertex constructionFrom = createVertex(new double[] {(currentEdge.getFrom().getX() + ! minus.getX() * -50), ! (currentEdge.getFrom().getY() + ! minus.getY() * -50), ! (currentEdge.getFrom().getZ() + ! minus.getZ() * -50)}); ! Vertex constructionTo = createVertex(new double[] {(currentEdge.getTo().getX() + ! minus.getX() * 50), ! (currentEdge.getTo().getY() + ! minus.getY() * 50), ! (currentEdge.getTo().getZ() + ! minus.getZ() * 50)}); currentConstruction = createEdge(constructionFrom, constructionTo); currentConstruction.setConstructor(true); *************** *** 138,146 **** ray = transformation.unProject(ray); Edge intersection = currentEdge.intersection(ray); ! edgePoint = createVertex(intersection.getFrom()); ! constructionPoint = createVertex(edgePoint.copy()); edgeToConstruction = new Edge("lengthEdge", edgePoint, constructionPoint); } } else { currentEdge = null; currentConstruction = null; --- 158,174 ---- ray = transformation.unProject(ray); Edge intersection = currentEdge.intersection(ray); ! edgePoint = intersection.getFrom(); ! constructionPoint = edgePoint.copy(); edgeToConstruction = new Edge("lengthEdge", edgePoint, constructionPoint); + edgeToConstruction.setConstructor(true); + v.addTempEdge(edgeToConstruction); + v.addTempVertex(edgePoint); + v.addTempVertex(constructionPoint); } } else { + View v = glv.getView(); + v.removeTempEdge(edgeToConstruction); + v.removeTempVertex(edgePoint); + v.removeTempVertex(constructionPoint); currentEdge = null; currentConstruction = null; *************** *** 148,152 **** edgeToConstruction = null; removeVertex(edgePoint); ! removeVertex(constructionPoint); } } --- 176,180 ---- edgeToConstruction = null; removeVertex(edgePoint); ! removeVertex(constructionPoint); } } *************** *** 158,161 **** --- 186,260 ---- protected void released(MouseEvent e) { } + + /** + * Invoked when a key has been pressed. + * @param e The KeyEvent + */ + public void keyPressed(KeyEvent e) { + /*a length can only be typed in if some surface is selected + for extrusion, and if the "number"-variable has been initialised + */ + super.keyPressed(e); + if (currentEdge != null && number != null) { + if (e.getKeyCode() == KeyEvent.VK_1) { + number += "1"; + } else if (e.getKeyCode() == KeyEvent.VK_2) { + number += "2"; + } else if (e.getKeyCode() == KeyEvent.VK_3) { + number += "3"; + } else if (e.getKeyCode() == KeyEvent.VK_4) { + number += "4"; + } else if (e.getKeyCode() == KeyEvent.VK_5) { + number += "5"; + } else if (e.getKeyCode() == KeyEvent.VK_6) { + number += "6"; + } else if (e.getKeyCode() == KeyEvent.VK_7) { + number += "7"; + } else if (e.getKeyCode() == KeyEvent.VK_8) { + number += "8"; + } else if (e.getKeyCode() == KeyEvent.VK_9) { + number += "9"; + } else if (e.getKeyCode() == KeyEvent.VK_0) { + number += "0"; + } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + if (!number.equals("")) { + double length = glv.getLength(); + double currentLength = edgeToConstruction.getLength(); + Vertex minus = edgeToConstruction.getTo().minus(edgeToConstruction.getFrom()); + edgeNormal.scale(1 / edgeNormal.length()); + minus.scale(1 / minus.length()); + double delta; + if (minus.dot(edgeNormal) > 0) { + delta = length - currentLength; + } else { + delta = -(length - currentLength); + } + constructionPoint.move(edgeNormal.getX() * delta, + edgeNormal.getY() * delta, + edgeNormal.getZ() * delta); + currentConstruction.move(edgeNormal.getX() * delta, + edgeNormal.getY() * delta, + edgeNormal.getZ() * delta); + glv.repaint(); + } + } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + int length = number.length(); + if (length > 0) { + number = number.substring(0, length - 1); + } + } + if (number.equals("")) { + glv.setLength(0); + } else { + try { + double d = Double.parseDouble(number); + glv.setLength(d / 1000); + } catch (NumberFormatException exp) { + log.warn(exp); + } + } + } + super.keyPressed(e); + } } |
From: Michael L. <he...@us...> - 2005-11-30 08:51:58
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19957/src/net/sourceforge/bprocessor/gl/tool Modified Files: CatmullClark.java Log Message: More catmull-clark stuff Index: CatmullClark.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/CatmullClark.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CatmullClark.java 28 Nov 2005 22:24:51 -0000 1.1 --- CatmullClark.java 30 Nov 2005 08:51:50 -0000 1.2 *************** *** 36,39 **** --- 36,43 ---- private HashMap edgelist; + /** The other edge list */ + + private HashMap el; + /** The face list */ private HashMap facelist; *************** *** 148,151 **** --- 152,187 ---- /** + * Init el + * @param v The vertex + * @return The new el + */ + public List elInit(Vertex v) { + List edges = new LinkedList(); + el.put(v, edges); + return edges; + } + /** + * Get el + * @param v The vertex + * @return The el + */ + public List elGet(Vertex v) { + List edges = (List) el.get(v); + if (edges == null) { + edges = elInit(v); + } + return edges; + } + /** + * Insert edge in el + * @param v The Vertex + * @param e The edge + */ + public void elInsert(Vertex v, Edge e) { + List edges = elGet(v); + edges.add(e); + } + + /** * Init facelist * @param v The Vertex *************** *** 270,273 **** --- 306,322 ---- /** + * Check if this is a crease vertex - this + * is wrong, there should be a tag. Some + * vertices with 2 or 3 edges are not crease. + * @param v The vertex + * @return Crease or not + */ + boolean crease(Vertex v) { + int k = elGet(v).size(); + return (k < 4); + } + + + /** * Run catmullclark subdivsion on faces * @param faces The faces to subdivide *************** *** 277,280 **** --- 326,330 ---- edgelist = new HashMap(); facelist = new HashMap(); + el = new HashMap(); List surfaces = new ArrayList(); HashSet edges = new HashSet(); *************** *** 306,309 **** --- 356,361 ---- edgepoints.add(center); edgemap.put(current, center); + elInsert(current.getFrom(), current); + elInsert(current.getTo(), current); } } *************** *** 341,397 **** Vertex v = (Vertex) iter.next(); List adjacent = edgelistGet(v); ! List pts = new LinkedList(); ! Iterator eit = adjacent.iterator(); ! while (eit.hasNext()) { ! Edge edge = (Edge) eit.next(); ! pts.add(edge.otherVertex(v)); } - double[] values = average(pts); - v.setX(values[0]); - v.setY(values[1]); - v.setZ(values[2]); } } { Iterator iter = vertices.iterator(); while (iter.hasNext()) { Vertex v = (Vertex) iter.next(); ! List es = edgelistGet(v); double n = es.size(); ! List adjacent = facelistGet(v); ! List pts = new LinkedList(); ! Iterator sit = adjacent.iterator(); ! while (sit.hasNext()) { ! pts.add(facemap.get(sit.next())); ! } ! double[] q = average(pts); ! ! double[] r = new double[]{0, 0, 0}; ! Iterator eit = es.iterator(); ! while (eit.hasNext()) { ! Edge edge = (Edge) eit.next(); ! double[] c = edge.center(); ! r[0] += c[0]; ! r[1] += c[1]; ! r[2] += c[2]; ! } ! ! r[0] /= n; ! r[1] /= n; ! r[2] /= n; ! double[] p = new double[3]; ! p[0] = v.getX(); ! p[1] = v.getY(); ! p[2] = v.getZ(); ! double[] values = new double[3]; ! values[0] = q[0] / n + 2 * r[0] / n + (n - 3) * p[0] / n; ! values[1] = q[1] / n + 2 * r[1] / n + (n - 3) * p[1] / n; ! values[2] = q[2] / n + 2 * r[2] / n + (n - 3) * p[2] / n; ! v.setX(values[0]); ! v.setY(values[1]); ! v.setZ(values[2]); } --- 393,476 ---- Vertex v = (Vertex) iter.next(); List adjacent = edgelistGet(v); ! if (adjacent.size() > 3) { ! List pts = new LinkedList(); ! Iterator eit = adjacent.iterator(); ! while (eit.hasNext()) { ! Edge edge = (Edge) eit.next(); ! pts.add(edge.otherVertex(v)); ! } ! double[] values = average(pts); ! v.setX(values[0]); ! v.setY(values[1]); ! v.setZ(values[2]); } } } { Iterator iter = vertices.iterator(); + LinkedList positions = new LinkedList(); + while (iter.hasNext()) { Vertex v = (Vertex) iter.next(); ! List es = elGet(v); double n = es.size(); ! double[] values = new double[3]; ! if (n > 3) { ! List adjacent = facelistGet(v); ! List pts = new LinkedList(); ! Iterator sit = adjacent.iterator(); ! while (sit.hasNext()) { ! pts.add(facemap.get(sit.next())); ! } ! double[] q = average(pts); ! Iterator eit = es.iterator(); ! pts.clear(); ! while (eit.hasNext()) { ! Edge edge = (Edge) eit.next(); ! pts.add(edge.otherVertex(v)); ! } ! double[] r = average(pts); ! double[] p = new double[3]; ! p[0] = v.getX(); ! p[1] = v.getY(); ! p[2] = v.getZ(); ! ! values[0] = q[0] / n + r[0] / n + (n - 2) * p[0] / n; ! values[1] = q[1] / n + r[1] / n + (n - 2) * p[1] / n; ! values[2] = q[2] / n + r[2] / n + (n - 2) * p[2] / n; ! } else { ! ! ! values[0] = v.getX() * 6; ! values[1] = v.getY() * 6; ! values[2] = v.getZ() * 6; ! Iterator esit = es.iterator(); ! while (esit.hasNext()) { ! Edge e = (Edge) esit.next(); ! Vertex to = e.otherVertex(v); ! if (crease(to)) { ! values[0] += to.getX(); ! values[1] += to.getY(); ! values[2] += to.getZ(); ! } ! } ! ! values[0] /= 8.0; ! values[1] /= 8.0; ! values[2] /= 8.0; ! } ! positions.add(values); ! } ! Iterator vit = vertices.iterator(); ! Iterator pit = positions.iterator(); ! while (vit.hasNext()) { ! Vertex v = (Vertex) vit.next(); ! double[] p = (double[]) pit.next(); ! v.setX(p[0]); ! v.setY(p[1]); ! v.setZ(p[2]); } |
From: Michael L. <he...@us...> - 2005-11-30 08:51:57
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19957/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java Log Message: More catmull-clark stuff Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** AbstractView.java 29 Nov 2005 19:02:51 -0000 1.62 --- AbstractView.java 30 Nov 2005 08:51:49 -0000 1.63 *************** *** 25,28 **** --- 25,29 ---- import java.util.HashSet; import java.util.Iterator; + import java.util.LinkedList; import java.util.List; import java.util.Collection; *************** *** 719,724 **** gl.glDisable(GL.GL_CULL_FACE); - - drawSpaces(gld); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); gl.glDisable(GL.GL_LIGHTING); --- 720,723 ---- *************** *** 737,741 **** break; } ! } gl.glColor3fv(SELECTED_COLOR); --- 736,742 ---- break; } ! } ! ! drawSpaces(gld); gl.glColor3fv(SELECTED_COLOR); *************** *** 1129,1132 **** --- 1130,1157 ---- /** + * Collect edges from surface + * @param surface The surface + * @param result The result + */ + void collectEdges(Surface surface, Collection result) { + Iterator iter = surface.getEdges().iterator(); + while (iter.hasNext()) { + result.add(iter.next()); + } + } + + /** + * Collect edges from surfaces + * @param surfaces The surfaces + * @param result The result + */ + void collectEdges(List surfaces, Collection result) { + Iterator iter = surfaces.iterator(); + while (iter.hasNext()) { + collectEdges((Surface) iter.next(), result); + } + } + + /** * Draw the spaces by running the modellor * @param gld The GLDrawable *************** *** 1134,1137 **** --- 1159,1163 ---- private void drawSpaces(GLDrawable gld) { Set spaces = Project.getInstance().getDomains(); + Iterator spaceIter = spaces.iterator(); while (spaceIter.hasNext()) { *************** *** 1140,1148 **** List surfaces = space.getModellor().generate(); if (surfaces != null) { ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! drawSurface(current); ! } } } --- 1166,1188 ---- List surfaces = space.getModellor().generate(); if (surfaces != null) { ! LinkedList edges = new LinkedList(); ! HashSet mark = new HashSet(); ! collectEdges(surfaces, edges); ! gl.glDisable(GL.GL_DEPTH); ! gl.glLineWidth(1.0f); ! gl.glColor3fv(X_AXIS_COLOR); ! Iterator eit = edges.iterator(); ! while (eit.hasNext()) { ! Edge e = (Edge)eit.next(); ! if (!mark.contains(e)) { ! drawEdge(e); ! mark.add(e); ! } ! }; ! // Iterator iter = surfaces.iterator(); ! // while (iter.hasNext()) { ! // Surface current = (Surface) iter.next(); ! // drawSurface(current); ! // } } } |
From: Nordholt <nor...@us...> - 2005-11-29 19:06:59
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30036 Modified Files: Edge.java Log Message: added a field to tell if this is a constructor edge, constructor edges will not be split Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Edge.java 28 Nov 2005 22:23:49 -0000 1.20 --- Edge.java 29 Nov 2005 19:06:51 -0000 1.21 *************** *** 39,42 **** --- 39,45 ---- private Vertex to; + /** Constructor */ + private boolean constructor; + /** * Constructor for persistence layer *************** *** 54,57 **** --- 57,61 ---- setFrom(null); setTo(null); + setConstructor(false); } *************** *** 143,146 **** --- 147,167 ---- /** + * Is the edge a constructor + * @return True if constructor; otherwise false + * @hibernate.property + */ + public boolean getConstructor() { + return constructor; + } + + /** + * Set if the edge is a constructor + * @param c True if constructor; otherwise false + */ + public void setConstructor(boolean c) { + constructor = c; + } + + /** * Return the other vertex than the given one, if the given one is one of them * @param v The vertex *************** *** 290,313 **** * TODO to split this edge by the vertex */ ! ! Vertex from = getFrom(); ! Vertex to = getTo(); ! Edge e1 = new Edge("", from, vertex); ! Project.getInstance().intern(e1); ! Edge e2 = new Edge("", vertex, to); ! Project.getInstance().intern(e2); ! ! ! Set surfaces = getSurfaces(); ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! current.replace(this, e1, e2); } - Project.getInstance().remove(this); } ! ! /** ! * String representation of the object * @return The string */ --- 311,335 ---- * TODO to split this edge by the vertex */ ! if (!constructor) { ! Vertex from = getFrom(); ! Vertex to = getTo(); ! Edge e1 = new Edge("", from, vertex); ! Project.getInstance().intern(e1); ! Edge e2 = new Edge("", vertex, to); ! Project.getInstance().intern(e2); ! ! ! Set surfaces = getSurfaces(); ! Iterator iter = surfaces.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! current.replace(this, e1, e2); ! } ! Project.getInstance().remove(this); } } ! ! /** ! * String representation of the object * @return The string */ |
From: Nordholt <nor...@us...> - 2005-11-29 19:05:33
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29578 Modified Files: PersistenceManager.java Log Message: added constructor field for edge Index: PersistenceManager.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/xml/PersistenceManager.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PersistenceManager.java 30 Oct 2005 15:49:36 -0000 1.11 --- PersistenceManager.java 29 Nov 2005 19:05:26 -0000 1.12 *************** *** 242,246 **** net.sourceforge.bprocessor.model.Edge em = new net.sourceforge.bprocessor.model.Edge(e.getName()); ! Project.getInstance().intern(em); --- 242,248 ---- net.sourceforge.bprocessor.model.Edge em = new net.sourceforge.bprocessor.model.Edge(e.getName()); ! ! em.setConstructor(e.isConstructor()); ! Project.getInstance().intern(em); *************** *** 820,823 **** --- 822,826 ---- ex.setId(counter++); ex.setName(e.getName()); + ex.setConstructor(e.getConstructor()); Map em = (Map)mapper.get(KEY_EDGE); |
From: Nordholt <nor...@us...> - 2005-11-29 19:04:46
|
Update of /cvsroot/bprocessor/model/src/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29351 Modified Files: bprocessor.xsd Log Message: added constructor field for edges Index: bprocessor.xsd =================================================================== RCS file: /cvsroot/bprocessor/model/src/etc/bprocessor.xsd,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** bprocessor.xsd 20 Sep 2005 12:54:01 -0000 1.5 --- bprocessor.xsd 29 Nov 2005 19:04:38 -0000 1.6 *************** *** 86,89 **** --- 86,90 ---- <xsd:element name="vertexfromref" type="xsd:long" maxOccurs="1" minOccurs="0"/> <xsd:element name="vertextoref" type="xsd:long" maxOccurs="1" minOccurs="0"/> + <xsd:element name="constructor" type="xsd:boolean"/> </xsd:sequence> </xsd:complexType> |
From: Nordholt <nor...@us...> - 2005-11-29 19:03:03
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28676 Modified Files: AbstractView.java Log Message: added special drawing of construction lines Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** AbstractView.java 28 Nov 2005 22:24:50 -0000 1.61 --- AbstractView.java 29 Nov 2005 19:02:51 -0000 1.62 *************** *** 1032,1044 **** */ private void drawEdge(Edge e) { Vertex to = e.getTo(); Vertex from = e.getFrom(); if (to != null && from != null) { ! gl.glBegin(GL.GL_LINE_STRIP); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glEnd(); } ! } /** --- 1032,1060 ---- */ private void drawEdge(Edge e) { + Vertex to = e.getTo(); Vertex from = e.getFrom(); if (to != null && from != null) { ! if (e.getConstructor()) { ! Vertex minus = to.minus(from); ! minus.scale(1 / minus.length()); ! gl.glEnable(GL.GL_LINE_STIPPLE); ! gl.glBegin(GL.GL_LINE_STRIP); ! gl.glVertex3d(to.getX() + minus.getX() * 50, ! to.getY() + minus.getY() * 50, ! to.getZ() + minus.getZ() * 50); ! gl.glVertex3d(from.getX() + minus.getX() * -50, ! from.getY() + minus.getY() * -50, ! from.getZ() + minus.getZ() * -50); ! gl.glEnd(); ! gl.glDisable(GL.GL_LINE_STIPPLE); ! } else { ! gl.glBegin(GL.GL_LINE_STRIP); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glEnd(); ! } } ! } /** |
From: Nordholt <nor...@us...> - 2005-11-29 19:01:23
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27782 Modified Files: ToolFactory.java Log Message: added tape measure tool Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ToolFactory.java 22 Nov 2005 13:40:22 -0000 1.15 --- ToolFactory.java 29 Nov 2005 19:00:39 -0000 1.16 *************** *** 50,54 **** /** rotation tool */ ! private RotationTool rotation; /** The previous tool */ --- 50,57 ---- /** rotation tool */ ! private RotationTool rotation; ! ! /** Tape measure tool */ ! private TapeMeasureTool tapeMeasure; /** The previous tool */ *************** *** 68,71 **** --- 71,75 ---- Cursor pencilcursor = Toolkit.getDefaultToolkit().createCustomCursor(pencilimage, new Point(7, 8), "Pencil"); + url = cl.getResource("Bcursorrotcam.gif"); Image rotationImage = Toolkit.getDefaultToolkit().getImage(url); *************** *** 90,93 **** --- 94,100 ---- but = tb.registerAction(new RotationAction(glv)); but.setToolTipText("Rotation"); + but = tb.registerAction(new TapeMeasureAction(glv)); + but.setToolTipText("Tape Measure"); + select = new SpaceTool(glv, null); *************** *** 97,100 **** --- 104,109 ---- clipplane = new ClipplaneTool(glv, pencilcursor); rotation = new RotationTool(glv, rotationCursor, dragCursor); + tapeMeasure = new TapeMeasureTool(glv, pencilcursor); + Notifier.getInstance().addListener(select); *************** *** 112,116 **** return factory; } ! /** * Get the default tool --- 121,125 ---- return factory; } ! /** * Get the default tool *************** *** 157,160 **** --- 166,172 ---- currentTool = rotation; return rotation; + } else if (i == Tool.TAPE_MEASURE_TOOL) { + currentTool = tapeMeasure; + return tapeMeasure; } else { log.error("[get] No such tool " + i); *************** *** 311,315 **** } } ! /** * The clipping action inner class --- 323,327 ---- } } ! /** * The clipping action inner class *************** *** 318,322 **** /** The GLView */ private GLView glv = null; ! /** * Constructor --- 330,334 ---- /** The GLView */ private GLView glv = null; ! /** * Constructor *************** *** 330,334 **** putValue(Action.SMALL_ICON, im); } ! /** * Called when the button is pressed --- 342,347 ---- putValue(Action.SMALL_ICON, im); } ! ! /** * Called when the button is pressed *************** *** 339,341 **** --- 352,384 ---- } } + + + /** + * The tape measure action inner class + */ + class TapeMeasureAction extends AbstractAction { + /** The GLView */ + private GLView glv = null; + + /** + * Constructor + * @param glv TheGLView + */ + TapeMeasureAction(GLView glv) { + this.glv = glv; + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL url = cl.getResource("selecticon.png"); + ImageIcon im = new ImageIcon(url); + putValue(Action.SMALL_ICON, im); + } + + /** + * Called when the button is pressed + * @param e The ActionEvent + */ + public void actionPerformed(ActionEvent e) { + glv.changeTool(Tool.TAPE_MEASURE_TOOL); + } + } + } |
From: Nordholt <nor...@us...> - 2005-11-29 19:01:23
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27930 Modified Files: Tool.java Log Message: added tape measure tool Index: Tool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Tool.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Tool.java 18 Nov 2005 01:27:56 -0000 1.12 --- Tool.java 29 Nov 2005 19:01:12 -0000 1.13 *************** *** 18,21 **** --- 18,23 ---- */ public interface Tool extends MouseListener, MouseMotionListener, KeyListener, MouseWheelListener { + /** The prevoius tool (the tool used before this one) */ + public static final int PREVIOUS_TOOL = -1; /** The select tool */ public static final int SELECT_TOOL = 0; *************** *** 30,35 **** /** The Rotation tool */ public static final int ROTATION_TOOL = 5; ! /** The prevoius tool (the tool used before this one) */ ! public static final int PREVIOUS_TOOL = 6; /** --- 32,38 ---- /** The Rotation tool */ public static final int ROTATION_TOOL = 5; ! /** The Tape Measure tool */ ! public static final int TAPE_MEASURE_TOOL = 6; ! /** |
From: Nordholt <nor...@us...> - 2005-11-29 18:59:52
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27336 Added Files: TapeMeasureTool.java Log Message: tape measure tool, first draft --- NEW FILE: TapeMeasureTool.java --- //--------------------------------------------------------------------------------- // $Id: TapeMeasureTool.java,v 1.1 2005/11/29 18:59:40 nordholt Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.awt.Cursor; import java.awt.event.MouseEvent; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.AbstractView; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.GLView; import org.apache.log4j.Logger; /** * The TapeMeasureTool */ public class TapeMeasureTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(TapeMeasureTool.class); /** The current edge */ private Edge currentEdge; /** The current construction edge */ private Edge currentConstruction; /** The edge point */ private Vertex edgePoint; /** The construction edge point */ private Vertex constructionPoint; /** The the edge between the current edge and the construction edge */ private Edge edgeToConstruction; /** The plane we are moving in */ private Plane movePlane; /** The edge normal */ private Vertex edgeNormal; /** * Constructor * @param glv The GLView * @param cursor The cursor */ public TapeMeasureTool(GLView glv, Cursor cursor) { super(glv, cursor); } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ protected void moved(MouseEvent e) { if (currentEdge != null) { if (movePlane == null) { findTarget(e); if (target instanceof Surface) { Surface targetSurface = (Surface)target; glv.getView().makeTarget(target); movePlane = targetSurface.plane(); Vertex edgeDirection = currentEdge.getTo().minus(currentEdge.getFrom()); Vertex surfaceNormal = targetSurface.normal(); edgeNormal = edgeDirection.cross(surfaceNormal); edgeNormal.scale(1 / edgeNormal.length()); double x = e.getX(); double y = AbstractView.getHeight() - e.getY(); View v = glv.getView(); Transformation transformation = v.transformation(); Vertex near = new Vertex("near", x, y, 0.0); Vertex far = new Vertex("far", x, y, 1.0); Edge ray = new Edge("ray", near, far); ray = transformation.unProject(ray); Vertex intersect = movePlane.intersection(ray); Vertex delta = intersect.minus(constructionPoint); edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); } } else { edgeNormal.scale(1 / edgeNormal.length()); double x = e.getX(); double y = AbstractView.getHeight() - e.getY(); View v = glv.getView(); Transformation transformation = v.transformation(); Vertex near = new Vertex("near", x, y, 0.0); Vertex far = new Vertex("far", x, y, 1.0); Edge ray = new Edge("ray", near, far); ray = transformation.unProject(ray); Vertex intersect = movePlane.intersection(ray); Vertex delta = intersect.minus(constructionPoint); edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); } } } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { findTarget(e); if (currentEdge == null) { if (target instanceof Edge) { currentEdge = (Edge)target; Vertex constructionFrom = createVertex(currentEdge.getFrom().copy()); Vertex constructionTo = createVertex(currentEdge.getTo().copy()); currentConstruction = createEdge(constructionFrom, constructionTo); currentConstruction.setConstructor(true); double x = e.getX(); double y = AbstractView.getHeight() - e.getY(); View v = glv.getView(); Transformation transformation = v.transformation(); Vertex near = new Vertex("near", x, y, 0.0); Vertex far = new Vertex("far", x, y, 1.0); Edge ray = new Edge("ray", near, far); ray = transformation.unProject(ray); Edge intersection = currentEdge.intersection(ray); edgePoint = createVertex(intersection.getFrom()); constructionPoint = createVertex(edgePoint.copy()); edgeToConstruction = new Edge("lengthEdge", edgePoint, constructionPoint); } } else { currentEdge = null; currentConstruction = null; movePlane = null; edgeToConstruction = null; removeVertex(edgePoint); removeVertex(constructionPoint); } } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { } } |
From: Nordholt <nor...@us...> - 2005-11-29 18:52:16
|
Update of /cvsroot/bprocessor/build/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25982 Modified Files: Changelog Log Message: small additions to changelog Index: Changelog =================================================================== RCS file: /cvsroot/bprocessor/build/doc/Changelog,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Changelog 22 Nov 2005 16:16:13 -0000 1.5 --- Changelog 29 Nov 2005 18:52:05 -0000 1.6 *************** *** 20,23 **** --- 20,25 ---- - length input is added for extrusion - guidance lines + - Automatic space assignment when extruding surfaces based on analysis of exsisting space assignments + - Selecting a surface shows labels indicating space assignments for the surface. 2005/09/23: Release M1 |
From: Michael L. <he...@us...> - 2005-11-28 22:25:06
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1777/src/net/sourceforge/bprocessor/gl/tool Modified Files: ExtrusionTool.java SelectTool.java Added Files: CatmullClarkActionListener.java CatmullClark.java Log Message: Catmull Clark subdivision --- NEW FILE: CatmullClark.java --- //--------------------------------------------------------------------------------- // $Id: CatmullClark.java,v 1.1 2005/11/28 22:24:51 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Set; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Modellor; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * CatmullClark subdivision */ public class CatmullClark implements Modellor { /** The space */ private Space space; /** The edge list */ private HashMap edgelist; /** The face list */ private HashMap facelist; /** * Construct! * @param space The Space */ public CatmullClark(Space space) { super(); this.space = space; } /** * Make a copy of the originals * @param originals The originals * @return The copy */ private List copy(Set originals) { List surfaces = new ArrayList(); HashMap edgemap = new HashMap(); HashMap vertexmap = new HashMap(); { Iterator oit = originals.iterator(); while (oit.hasNext()) { Surface surface = (Surface) oit.next(); Iterator vit = surface.getVertices().iterator(); while (vit.hasNext()) { Vertex current = (Vertex) vit.next(); Vertex vertex = current.copy(); vertexmap.put(current, vertex); } } } { Iterator oit = originals.iterator(); while (oit.hasNext()) { Surface surface = (Surface) oit.next(); Iterator vit = surface.getEdges().iterator(); while (vit.hasNext()) { Edge current = (Edge) vit.next(); Vertex from = (Vertex) vertexmap.get(current.getFrom()); Vertex to = (Vertex) vertexmap.get(current.getTo()); Edge edge = new Edge("", from, to); edgemap.put(current, edge); } } } { Iterator oit = originals.iterator(); while (oit.hasNext()) { Surface surface = (Surface) oit.next(); List edges = new ArrayList(); Iterator vit = surface.getEdges().iterator(); while (vit.hasNext()) { Edge current = (Edge) vit.next(); Edge edge = (Edge) edgemap.get(current); edges.add(edge); } surfaces.add(new Surface("", edges)); } } return surfaces; } /** * Find a common vertex * @param e1 Edge 1 * @param e2 Edge 2 * @return A common vertex */ public Vertex common(Edge e1, Edge e2) { if (e2.contains(e1.getFrom())) { return e1.getFrom(); } else { return e1.getTo(); } } /** * Init edgelist * @param v The vertex * @return The new edgelist */ public List edgelistInit(Vertex v) { List edges = new LinkedList(); edgelist.put(v, edges); return edges; } /** * Get edgelist * @param v The vertex * @return The edgelist */ public List edgelistGet(Vertex v) { List edges = (List) edgelist.get(v); if (edges == null) { edges = edgelistInit(v); } return edges; } /** * Insert edge in edgelist * @param v The Vertex * @param e The edge */ public void edgelistInsert(Vertex v, Edge e) { List edges = edgelistGet(v); edges.add(e); } /** * Init facelist * @param v The Vertex * @return The new facelist */ public List facelistInit(Vertex v) { List faces = new LinkedList(); facelist.put(v, faces); return faces; } /** * Get facelist * @param v The vertex * @return The facelist */ public List facelistGet(Vertex v) { List faces = (List) facelist.get(v); if (faces == null) { faces = facelistInit(v); } return faces; } /** * Insert in facelist * @param v The vertex * @param e The face */ public void facelistInsert(Vertex v, Surface e) { List faces = facelistGet(v); faces.add(e); } /** * Create edge * @param from From * @param to To * @return Edge */ public Edge edge(Vertex from, Vertex to) { List fl = edgelistGet(from); List tl = edgelistGet(to); Iterator iter = fl.iterator(); Edge edge = null; while (iter.hasNext()) { Edge current = (Edge) iter.next(); if (current.otherVertex(from) == to) { edge = current; break; } } if (edge == null) { edge = new Edge("", from, to); fl.add(edge); tl.add(edge); } return edge; } /** * Create quad * @param e1 E1 * @param e2 E2 * @param e3 E3 * @param e4 E4 * @return Quad */ public Surface quad(Edge e1, Edge e2, Edge e3, Edge e4) { List edges = new ArrayList(); edges.add(e1); edges.add(e2); edges.add(e3); edges.add(e4); return new Surface("", edges); } /** * Create a quad * @param v1 V1 * @param v2 V2 * @param v3 V3 * @param v4 V4 * @return Quad */ public Surface quad(Vertex v1, Vertex v2, Vertex v3, Vertex v4) { Edge e1 = edge(v1, v2); Edge e2 = edge(v2, v3); Edge e3 = edge(v3, v4); Edge e4 = edge(v4, v1); return quad(e1, e2, e3, e4); } /** * Calculate the average of points * @param pts The points * @return The average */ public double[] average(List pts) { double[] values = new double[]{0, 0, 0}; Iterator iter = pts.iterator(); while (iter.hasNext()) { Vertex current = (Vertex) iter.next(); values[0] += current.getX(); values[1] += current.getY(); values[2] += current.getZ(); } values[0] /= (double) pts.size(); values[1] /= (double) pts.size(); values[2] /= (double) pts.size(); return values; } /** * Generate the faces * @return the faces */ public List generate() { List faces = copy(space.getSurfaces()); return catmullclark(catmullclark(catmullclark(faces))); } /** * Run catmullclark subdivsion on faces * @param faces The faces to subdivide * @return The subdivided mesh */ public List catmullclark(List faces) { edgelist = new HashMap(); facelist = new HashMap(); List surfaces = new ArrayList(); HashSet edges = new HashSet(); HashSet vertices = new HashSet(); List edgepoints = new LinkedList(); HashMap facemap = new HashMap(); HashMap edgemap = new HashMap(); { Iterator iter = faces.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); facemap.put(current, current.center()); edges.addAll(current.getEdges()); Iterator vit = current.getVertices().iterator(); vit.next(); while (vit.hasNext()) { Vertex v = (Vertex) vit.next(); facelistInsert(v, current); vertices.add(v); } } } { Iterator iter = edges.iterator(); while (iter.hasNext()) { Edge current = (Edge) iter.next(); double[] values = current.center(); Vertex center = new Vertex("", values[0], values[1], values[2]); edgepoints.add(center); edgemap.put(current, center); } } { Iterator iter = faces.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); Iterator eit = current.getEdges().iterator(); Edge top = (Edge) eit.next(); Edge right = (Edge) eit.next(); Edge bottom = (Edge) eit.next(); Edge left = (Edge) eit.next(); Vertex topm = (Vertex) edgemap.get(top); Vertex rightm = (Vertex) edgemap.get(right); Vertex bottomm = (Vertex) edgemap.get(bottom); Vertex leftm = (Vertex) edgemap.get(left); Vertex topleft = common(top, left); Vertex topright = common(top, right); Vertex bottomleft = common(bottom, left); Vertex bottomright = common(bottom, right); Vertex m = (Vertex) facemap.get(current); Surface q1 = quad(topleft, topm, m, leftm); Surface q2 = quad(topm, topright, rightm, m); Surface q3 = quad(rightm, bottomright, bottomm, m); Surface q4 = quad(bottomm, bottomleft, leftm, m); surfaces.add(q1); surfaces.add(q2); surfaces.add(q3); surfaces.add(q4); } } { Iterator iter = edgepoints.iterator(); while (iter.hasNext()) { Vertex v = (Vertex) iter.next(); List adjacent = edgelistGet(v); List pts = new LinkedList(); Iterator eit = adjacent.iterator(); while (eit.hasNext()) { Edge edge = (Edge) eit.next(); pts.add(edge.otherVertex(v)); } double[] values = average(pts); v.setX(values[0]); v.setY(values[1]); v.setZ(values[2]); } } { Iterator iter = vertices.iterator(); while (iter.hasNext()) { Vertex v = (Vertex) iter.next(); List es = edgelistGet(v); double n = es.size(); List adjacent = facelistGet(v); List pts = new LinkedList(); Iterator sit = adjacent.iterator(); while (sit.hasNext()) { pts.add(facemap.get(sit.next())); } double[] q = average(pts); double[] r = new double[]{0, 0, 0}; Iterator eit = es.iterator(); while (eit.hasNext()) { Edge edge = (Edge) eit.next(); double[] c = edge.center(); r[0] += c[0]; r[1] += c[1]; r[2] += c[2]; } r[0] /= n; r[1] /= n; r[2] /= n; double[] p = new double[3]; p[0] = v.getX(); p[1] = v.getY(); p[2] = v.getZ(); double[] values = new double[3]; values[0] = q[0] / n + 2 * r[0] / n + (n - 3) * p[0] / n; values[1] = q[1] / n + 2 * r[1] / n + (n - 3) * p[1] / n; values[2] = q[2] / n + 2 * r[2] / n + (n - 3) * p[2] / n; v.setX(values[0]); v.setY(values[1]); v.setZ(values[2]); } } return surfaces; } } Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** SelectTool.java 20 Nov 2005 19:33:52 -0000 1.43 --- SelectTool.java 28 Nov 2005 22:24:50 -0000 1.44 *************** *** 80,84 **** * @param e The MouseEvent object */ ! protected void pressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.getClickCount() >= 2 && target instanceof Surface) { --- 80,94 ---- * @param e The MouseEvent object */ ! protected void pressed(MouseEvent e) { ! ! if (e.getButton() == MouseEvent.BUTTON3) { ! findTarget(e); ! if (target != null) { ! if (target instanceof String) { ! JPopupMenu toolsmenu = toolsmenu((String) target); ! glv.popup(toolsmenu, e.getX(), e.getY()); ! } ! } ! } if (e.getButton() == MouseEvent.BUTTON1) { if (e.getClickCount() >= 2 && target instanceof Surface) { *************** *** 260,263 **** --- 270,307 ---- /** + * Create the toolsmenu + * @param name Space name + * @return The toolsmenu + */ + private JPopupMenu toolsmenu(String name) { + JPopupMenu menu = new JPopupMenu("Tools"); + Space space = null; + Surface surface = null; + Iterator iter = selection.iterator(); + while (iter.hasNext()) { + Object current = iter.next(); + if (current instanceof Surface) { + surface = (Surface) current; + break; + } + } + if (surface != null) { + if (name.equals("back")) { + space = (Space) surface.getBackDomain(); + } + if (name.equals("front")) { + space = (Space) surface.getFrontDomain(); + } + } + if (space != null) { + ActionListener listener = new CatmullClarkActionListener(space); + JMenuItem catmullClarkItem = new JMenuItem("Catmull-Clark"); + catmullClarkItem.addActionListener(listener); + menu.add(catmullClarkItem); + } + return menu; + } + + /** * Sends the notification for select * @param obj The selected object --- NEW FILE: CatmullClarkActionListener.java --- //--------------------------------------------------------------------------------- // $Id: CatmullClarkActionListener.java,v 1.1 2005/11/28 22:24:50 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import net.sourceforge.bprocessor.model.Space; /** * First version of implementation of Catmull-Clark scheme. * Does not handle boundary cases. */ public class CatmullClarkActionListener implements ActionListener { /** The space */ private Space space; /** * Construct * @param space The space */ public CatmullClarkActionListener(Space space) { super(); this.space = space; } /** * Perform action * @param event The ActionEvent */ public void actionPerformed(ActionEvent event) { space.setModellor(new CatmullClark(space)); } } Index: ExtrusionTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrusionTool.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** ExtrusionTool.java 23 Nov 2005 16:51:56 -0000 1.31 --- ExtrusionTool.java 28 Nov 2005 22:24:50 -0000 1.32 *************** *** 153,157 **** while (vertIt.hasNext() && inSide) { Vertex vert = (Vertex)vertIt.next(); ! inSide = surface.surrounds(vert, 1); } } --- 153,157 ---- while (vertIt.hasNext() && inSide) { Vertex vert = (Vertex)vertIt.next(); ! inSide = surface.surrounds(vert, 1.0); } } |
From: Michael L. <he...@us...> - 2005-11-28 22:25:05
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1777/src/net/sourceforge/bprocessor/gl/model Modified Files: ClippingPlane.java Log Message: Catmull Clark subdivision Index: ClippingPlane.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/model/ClippingPlane.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ClippingPlane.java 25 Nov 2005 17:48:08 -0000 1.4 --- ClippingPlane.java 28 Nov 2005 22:24:51 -0000 1.5 *************** *** 66,70 **** // clickable etc. if (origin.getId() == null) { ! Project.getInstance().intern(origin); } return origin; --- 66,70 ---- // clickable etc. if (origin.getId() == null) { ! //Project.getInstance().intern(origin); } return origin; |
From: Michael L. <he...@us...> - 2005-11-28 22:25:03
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1777/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java Log Message: Catmull Clark subdivision Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** AbstractView.java 23 Nov 2005 19:04:38 -0000 1.60 --- AbstractView.java 28 Nov 2005 22:24:50 -0000 1.61 *************** *** 18,21 **** --- 18,22 ---- import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Domain; + import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; *************** *** 718,721 **** --- 719,724 ---- gl.glDisable(GL.GL_CULL_FACE); + + drawSpaces(gld); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); gl.glDisable(GL.GL_LIGHTING); *************** *** 1108,1111 **** --- 1111,1136 ---- } } + + /** + * Draw the spaces by running the modellor + * @param gld The GLDrawable + */ + private void drawSpaces(GLDrawable gld) { + Set spaces = Project.getInstance().getDomains(); + Iterator spaceIter = spaces.iterator(); + while (spaceIter.hasNext()) { + Space space = (Space) spaceIter.next(); + if (space.getModellor() != null) { + List surfaces = space.getModellor().generate(); + if (surfaces != null) { + Iterator iter = surfaces.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + drawSurface(current); + } + } + } + } + } /** |
From: Michael L. <he...@us...> - 2005-11-28 22:24:04
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1534/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Vertex.java Surface.java Space.java Added Files: Modellor.java Log Message: Added ability of geometric objects to be in hashtables without ID Added modellor example Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** Surface.java 23 Nov 2005 16:55:04 -0000 1.49 --- Surface.java 28 Nov 2005 22:23:49 -0000 1.50 *************** *** 892,896 **** */ public int hashCode() { ! return id.hashCode(); } --- 892,900 ---- */ public int hashCode() { ! if (id == null) { ! return super.hashCode(); ! } else { ! return id.hashCode(); ! } } *************** *** 904,911 **** return false; } - Surface s = (Surface)o; ! ! return this.id.equals(s.getId()); } --- 908,918 ---- return false; } Surface s = (Surface)o; ! ! if (id == null || s.getId() == null) { ! return this == s; ! } else { ! return this.id.equals(s.getId()); ! } } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Space.java 6 Nov 2005 16:25:34 -0000 1.5 --- Space.java 28 Nov 2005 22:23:49 -0000 1.6 *************** *** 29,32 **** --- 29,35 ---- /** The elements */ private Set elements; + + /** The modellor */ + private Modellor modellor; /** *************** *** 80,83 **** --- 83,102 ---- this.elements = elements; } + + /** + * Get the modellor + * @return The modellor + */ + public Modellor getModellor() { + return modellor; + } + + /** + * Set the modellor + * @param modellor The modellor + */ + public void setModellor(Modellor modellor) { + this.modellor = modellor; + } /** Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Vertex.java 15 Nov 2005 18:58:30 -0000 1.15 --- Vertex.java 28 Nov 2005 22:23:49 -0000 1.16 *************** *** 355,359 **** */ public int hashCode() { ! return id.hashCode(); } --- 355,363 ---- */ public int hashCode() { ! if (id == null) { ! return super.hashCode(); ! } else { ! return id.hashCode(); ! } } *************** *** 367,374 **** return false; } - Vertex v = (Vertex)o; ! ! return this.id.equals(v.getId()); } --- 371,381 ---- return false; } Vertex v = (Vertex)o; ! ! if (id == null || v.getId() == null) { ! return this == v; ! } else { ! return this.id.equals(v.getId()); ! } } Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Edge.java 18 Nov 2005 16:24:11 -0000 1.19 --- Edge.java 28 Nov 2005 22:23:49 -0000 1.20 *************** *** 191,195 **** */ public int hashCode() { ! return id.hashCode(); } --- 191,199 ---- */ public int hashCode() { ! if (id == null) { ! return super.hashCode(); ! } else { ! return id.hashCode(); ! } } *************** *** 203,210 **** return false; } - Edge e = (Edge)o; ! return this.id.equals(e.getId()); } --- 207,217 ---- return false; } Edge e = (Edge)o; ! if (id == null || e.getId() == null) { ! return this == e; ! } else { ! return this.id.equals(e.getId()); ! } } --- NEW FILE: Modellor.java --- //--------------------------------------------------------------------------------- // $Id: Modellor.java,v 1.1 2005/11/28 22:23:49 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.List; /** * The modellor interface, can generate surfaces from parameters * established at the creation of the Modellor. */ public interface Modellor { /** * Generate a list of surfaces. * @return A list of surfaces */ public List generate(); } |