[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Command.java, 1.82, 1.83
Status: Pre-Alpha
Brought to you by:
henryml
From: Sebastian G. <sg...@us...> - 2010-05-19 15:45:50
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv15006/src/net/sourceforge/bprocessor/model Modified Files: Command.java Log Message: Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** Command.java 25 Feb 2010 14:43:48 -0000 1.82 --- Command.java 19 May 2010 15:45:39 -0000 1.83 *************** *** 18,22 **** import java.util.Set; - /** * Command --- 18,21 ---- *************** *** 29,32 **** --- 28,32 ---- public Command() { parameters = new ParameterBlock(); + // Comment } *************** *** 130,134 **** ! /** * --- 130,134 ---- ! /** * *************** *** 137,141 **** public static class PropertyCommand extends Command { private Geometric target; ! /** * --- 137,141 ---- public static class PropertyCommand extends Command { private Geometric target; ! /** * *************** *** 146,150 **** parameters.put("name", ""); } ! /** * {@inheritDoc} --- 146,150 ---- parameters.put("name", ""); } ! /** * {@inheritDoc} *************** *** 161,165 **** } } ! } /** --- 161,165 ---- } } ! } /** *************** *** 1637,1653 **** boolean working = true; while (working) { ! search: ! for (Edge current : edges) { ! working = false; ! if (!mark.contains(current)) { ! if (current.contains(to)) { ! ordered.addLast(current); ! mark.add(current); ! to = current.otherVertex(to); ! working = true; ! break search; } } - } } } --- 1637,1653 ---- boolean working = true; while (working) { ! search: ! for (Edge current : edges) { ! working = false; ! if (!mark.contains(current)) { ! if (current.contains(to)) { ! ordered.addLast(current); ! mark.add(current); ! to = current.otherVertex(to); ! working = true; ! break search; ! } } } } } *************** *** 1656,1672 **** boolean working = true; while (working) { ! search: ! for (Edge current : edges) { ! working = false; ! if (!mark.contains(current)) { ! if (current.contains(from)) { ! ordered.addFirst(current); ! mark.add(current); ! from = current.otherVertex(from); ! working = true; ! break search; } } - } } } --- 1656,1672 ---- boolean working = true; while (working) { ! search: ! for (Edge current : edges) { ! working = false; ! if (!mark.contains(current)) { ! if (current.contains(from)) { ! ordered.addFirst(current); ! mark.add(current); ! from = current.otherVertex(from); ! working = true; ! break search; ! } } } } } *************** *** 1964,1968 **** } ! /** * Layer */ --- 1964,2353 ---- } ! ! ! /** new command start ........................................................................................ ! * ! */ ! public static class Hyperbolicparaboloid extends Command { ! private Space net; ! ! /** ! * Constructs a frame command ! * @param net Space ! */ ! public Hyperbolicparaboloid(Space net) { ! this.net = net; ! parameters.put("height", 1.0); ! parameters.put("subdivisions", 5); ! ! parameters.put("HP name", "Hyperbolic Paraboloid"); ! } ! ! /** ! * {@inheritDoc} ! */ ! public String title() { ! return "Hyperbolicparaboloid"; ! } ! ! // not used... ! private List<Edge> simplify(List<Edge> edges) { ! if (edges.size() > 3) { ! List<Edge> result = new LinkedList(); ! List<Vertex> vertices = Offset.vertices(edges); ! LinkedList<Vertex> live = new LinkedList(); ! { ! int n = vertices.size(); ! Vertex previous = vertices.get(n - 1); ! Vertex current = vertices.get(0); ! Vertex next = null; ! for (int i = 0; i < n; i++) { ! next = vertices.get((i + 1) % n); ! Vertex u = current.minus(previous); ! Vertex v = next.minus(current); ! Vertex cross = u.cross(v); ! if (!cross.isZero()) { ! live.add(current); ! } ! previous = current; ! current = next; ! } ! } ! Vertex previous = live.getLast(); ! for (Vertex current : live) { ! result.add(new Edge(previous, current)); ! previous = current; ! } ! return result; ! } else { ! return edges; ! } ! } ! ! ! /** {@inheritDoc} */ ! @Override ! public void evaluate() { ! double height = parameters.getDouble("height"); ! int subdiv = parameters.getInteger("subdivisions"); ! String HPname = (String) parameters.get("HP name"); ! List<Surface> surfaces = new ArrayList(net.getSurfaces()); ! if (surfaces.size()==1) { ! Surface surface = surfaces.get(0); ! List<Vertex> vertices = surface.getVertices(); //returns vertices in order. ! if (vertices.size()==4) { ! List<Vertex> nVertices = new LinkedList(); ! for (Vertex current : vertices) { ! nVertices.add(current.copy()); ! } ! double trans = height/2; ! for (Vertex current : nVertices) { ! current.z = current.z + trans; ! trans = -trans; ! } ! Space result = Space.createUnion(HPname); ! ! Vertex[] dir = new Vertex[3]; ! Vertex[][] HPvertices = new Vertex[subdiv][subdiv]; ! // add grid points ! for (int u = 0; u < subdiv; u++) { ! for (int v = 0; v < subdiv; v++) { ! double vFactor = ((double) v)/(subdiv-1); ! double uFactor = ((double) u)/(subdiv-1); ! dir[0] = nVertices.get(1).minus(nVertices.get(0)).scale(uFactor).add(nVertices.get(0)); ! dir[1] = nVertices.get(2).minus(nVertices.get(3)).scale(uFactor).add(nVertices.get(3)); ! dir[2] = dir[1].minus(dir[0]).scale(vFactor).add(dir[0]); ! HPvertices[u][v] = dir[2]; ! result.add(HPvertices[u][v]); ! } ! } ! // add edges ! for (int u = 0; u < subdiv; u++) { ! for (int v = 0; v < subdiv; v++) { ! if (u>0) {result.add(new Edge(HPvertices[u][v],HPvertices[u-1][v]));} ! if (v>0) {result.add(new Edge(HPvertices[u][v],HPvertices[u][v-1]));} ! } ! } ! //add surfaces ! for (int u = 1; u < subdiv; u++) { ! for (int v = 1; v < subdiv; v++) { ! List<Edge> edges = new LinkedList(); ! edges.add(new Edge(HPvertices[u-1][v-1],HPvertices[u][v-1])); ! edges.add(new Edge(HPvertices[u][v-1],HPvertices[u][v])); ! edges.add(new Edge(HPvertices[u][v],HPvertices[u-1][v])); ! edges.add(new Edge(HPvertices[u-1][v],HPvertices[u-1][v-1])); ! result.add(new Surface(edges)); ! } ! } ! net.getOwner().add(result); ! } ! } ! } ! } ! ! /** new command end ......................................................................................... ! * ! * /** new command start ........................................................................................ ! * ! */ ! public static class UniformNonrationalBSpline extends Command { ! private Space net; ! ! /** ! * Constructs a frame command ! * @param net Space ! */ ! public UniformNonrationalBSpline(Space net) { ! this.net = net; ! parameters.put("subdivisions", 5.0); ! parameters.put("UNRBSname", "Unifrom Nonrational BSpline"); ! } ! ! /** ! * {@inheritDoc} ! */ ! public String title() { ! return "Unifrom Nonrational BSpline"; ! } ! ! //bring edges in order ! public static List<Edge> order(List<Edge> edges) { ! LinkedList<Edge> ordered = new LinkedList(); ! if (edges.size() > 0) { ! Edge first = edges.get(0); ! ordered.add(first); ! edges.remove(0); ! while (edges.size()>0) { ! for (int i = 0; i < edges.size(); i++) { ! search: ! if (edges.get(i).contains(ordered.get(ordered.size()-1).to)) { ! //check direction ! if (!edges.get(i).from.equals(ordered.get(ordered.size()-1).to)) { ! Vertex temp = edges.get(i).to; ! edges.get(i).to = edges.get(i).from; ! edges.get(i).from = temp; ! } ! //add at end of Linked list ! ordered.add(edges.get(i)); ! edges.remove(i); ! break search; ! } else if (edges.get(i).contains(ordered.get(0).from)) { ! //check direction ! if (!edges.get(i).to.equals(ordered.get(ordered.size()-1).from)) { ! Vertex temp = edges.get(i).to; ! edges.get(i).to = edges.get(i).from; ! edges.get(i).from = temp; ! } ! // add at beginning of Linked List ! ordered.add(0, edges.get(i)); ! edges.remove(i); ! break search; ! } ! } ! } ! } ! return ordered; ! } ! ! public Vertex unrbsCalc(List<Vertex> gConst, double t) { ! Vertex blend = new Vertex(0,0,0); ! if (gConst.size()==4) { ! double[] tempCalc = new double[4]; ! tempCalc[0] = ((1-t)*(1-t)*(1-t))/6; ! tempCalc[1] = (3*t*t*t-6*t*t+4)/6; ! tempCalc[2] = (-3*t*t*t+3*t*t+3*t+1)/6; ! tempCalc[3] = (t*t*t)/6; ! for (int i=0; i<=3; i++) { ! blend.x = blend.x + tempCalc[i]*gConst.get(i).x; ! blend.y = blend.y + tempCalc[i]*gConst.get(i).y; ! blend.z = blend.z + tempCalc[i]*gConst.get(i).z; ! } ! System.out.println(blend.x); ! } ! return blend; ! } ! ! /** {@inheritDoc} */ ! @Override ! public void evaluate() { ! String UNRBSname = (String) parameters.get("UNRBSname"); ! double subdiv = parameters.getDouble("subdivisions"); ! ! List<Vertex> vertices = new ArrayList(net.getVertices()); ! List<Edge> edges = new ArrayList(net.getEdges()); ! List<Vertex> orderPoints = new ArrayList(); ! List<Vertex> curvePoints = new LinkedList(); ! if (vertices.size()>=3) { ! LinkedList<Edge> nEdges = new LinkedList(); ! nEdges = (LinkedList) order(edges); ! // write into List ! for (int i=0; i<nEdges.size(); i++) { ! orderPoints.add(nEdges.get(i).from); ! } ! orderPoints.add(nEdges.get(nEdges.size()-1).to); ! // make Spline go through endpoints ! for (int i=0; i<=2; i++) { ! orderPoints.add(orderPoints.get(orderPoints.size()-1)); ! orderPoints.add(0,orderPoints.get(0)); ! } ! ! // create space object to draw new elements ! Space result = Space.createUnion(UNRBSname); ! ! // calculate Uniform Nonrational Spline Curve ! for (int i=3; i<= orderPoints.size()-2; i++) { ! for (int t=0; t<subdiv; t++) { ! curvePoints.add(unrbsCalc(orderPoints.subList(i-3, i+1),t/subdiv)); ! } ! } ! // draw Spline Curve ! for (int i=1;i<curvePoints.size()-1;i++) { ! result.add(new Edge(curvePoints.get(i-1),curvePoints.get(i))); ! } ! ! ! net.getOwner().add(result); ! } ! } ! } ! ! /** new command end ......................................................................................... ! * ! /** new command start ........................................................................................ ! * ! */ ! public static class NonuniformNonrationalBSpline extends Command { ! private Space net; ! ! /** ! * Constructs a frame command ! * @param net Space ! */ ! public NonuniformNonrationalBSpline(Space net) { ! this.net = net; ! parameters.put("subdivisions", 5.0); ! parameters.put("UNRBSname", "Nonunifrom Nonrational BSpline"); ! double val = 0; ! for (int i=0; i<net.getVertices().size()+4; i++) { ! if ((i>=4) && (i<=net.getVertices().size())) { ! val++; ! } ! parameters.put("knot value " + i, val); ! } ! } ! ! /** ! * {@inheritDoc} ! */ ! public String title() { ! return "Nonunifrom Nonrational BSpline"; ! } ! ! //bring edges in order ! public static List<Edge> order(List<Edge> edges) { ! LinkedList<Edge> ordered = new LinkedList(); ! if (edges.size() > 0) { ! Edge first = edges.get(0); ! ordered.add(first); ! edges.remove(0); ! while (edges.size()>0) { ! for (int i = 0; i < edges.size(); i++) { ! search: ! if (edges.get(i).contains(ordered.get(ordered.size()-1).to)) { ! //check direction ! if (!edges.get(i).from.equals(ordered.get(ordered.size()-1).to)) { ! Vertex temp = edges.get(i).to; ! edges.get(i).to = edges.get(i).from; ! edges.get(i).from = temp; ! } ! //add at end of Linked list ! ordered.add(edges.get(i)); ! edges.remove(i); ! break search; ! } else if (edges.get(i).contains(ordered.get(0).from)) { ! //check direction ! if (!edges.get(i).to.equals(ordered.get(ordered.size()-1).from)) { ! Vertex temp = edges.get(i).to; ! edges.get(i).to = edges.get(i).from; ! edges.get(i).from = temp; ! } ! // add at beginning of Linked List ! ordered.add(0, edges.get(i)); ! edges.remove(i); ! break search; ! } ! } ! } ! } ! return ordered; ! } ! ! private Vertex nunrbsCalc(List<Vertex> gConst, List<Double> t, double cT) { ! // gConst Control Points P(i), P(i+1), P(i+2), P(i+3) ! // t relevant knot values t(i), t(i+1). t(i+2), t(i+3) ! // cT current t, t(i)<=cT<t(i+1) ! Vertex blend = new Vertex(0, 0, 0); ! if ((gConst.size() == 4) && (t.size() == 4)) { ! double[] tempCalc = new double[4]; ! if ((cT >= t.get(0)) && (cT < t.get(1))) { ! tempCalc[0] = 1; ! } else { ! tempCalc[0] = 0; ! } ! ! tempCalc[1] = ((cT - t.get(0)) / (t.get(1) - t.get(0))) * tempCalc[0]; ! tempCalc[1] = tempCalc[1] + ((t.get(2) - cT) / (t.get(2) - t.get(1))) * cT; ! ! ! } ! return blend; ! } ! ! /** {@inheritDoc} */ ! @Override ! public void evaluate() { ! String zUNRBSname = (String) parameters.get("UNRBSname"); ! double subdiv = parameters.getDouble("subdivisions"); ! ! List<Vertex> vertices = new ArrayList(net.getVertices()); ! List<Edge> edges = new ArrayList(net.getEdges()); ! List<Vertex> orderPoints = new ArrayList(); ! List<Vertex> curvePoints = new LinkedList(); ! if (vertices.size() >= 3) { ! LinkedList<Edge> nEdges = new LinkedList(); ! nEdges = (LinkedList) order(edges); ! // write into List ! for (int i = 0; i < nEdges.size(); i++) { ! orderPoints.add(nEdges.get(i).from); ! } ! orderPoints.add(nEdges.get(nEdges.size() - 1).to); ! // make Spline go through endpoints ! for (int i = 0; i <= 2; i++) { ! orderPoints.add(orderPoints.get(orderPoints.size() - 1)); ! orderPoints.add(0, orderPoints.get(0)); ! } ! ! // create space object to draw new elements ! Space result = Space.createUnion(zUNRBSname); ! ! // calculate Uniform Nonrational Spline Curve ! for (int i = 3; i <= orderPoints.size() - 2; i++) { ! for (int t = 0; t < subdiv; t++) { ! //curvePoints.add(nunrbsCalc(orderPoints.subList(i-3, i+1),t/subdiv)); ! } ! } ! // draw Spline Curve ! for (int i = 1; i < curvePoints.size() - 1; i++) { ! result.add(new Edge(curvePoints.get(i - 1), curvePoints.get(i))); ! } ! ! net.getOwner().add(result); ! } ! } ! } ! ! /** new command end ! * ! * * Layer */ |