[Bprocessor-commit] bprocessor/src/net/sourceforge/bprocessor/packages/physics PhysicsNet.java, 1.
Status: Pre-Alpha
Brought to you by:
henryml
From: Sebastian G. <sg...@us...> - 2012-03-06 09:28:15
|
Update of /cvsroot/bprocessor/bprocessor/src/net/sourceforge/bprocessor/packages/physics In directory vz-cvs-4.sog:/tmp/cvs-serv15606/src/net/sourceforge/bprocessor/packages/physics Modified Files: PhysicsNet.java PhysicsPackage.java Log Message: hanging chain tool - change weight and change restlength / selection implemented tool to aligh normals when faces are planar Index: PhysicsPackage.java =================================================================== RCS file: /cvsroot/bprocessor/bprocessor/src/net/sourceforge/bprocessor/packages/physics/PhysicsPackage.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PhysicsPackage.java 21 Dec 2011 05:31:53 -0000 1.10 --- PhysicsPackage.java 6 Mar 2012 09:28:13 -0000 1.11 *************** *** 40,64 **** import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.plugin.NetCommand; import net.sourceforge.bprocessor.packages.skeleton.*; ! /* ! * To Do ! * Michael: ! * parameters additional parameters should be saved when added, change function , the display of the value is not automatically updated. ! * Plugin Parameters and Selection Parameters: they should not be displayed in the same panel. Rather split the existing panel. So there can be a selection and a tool running at the same time and all information is visible. ! * Sliders, Checkboxes, etc. for the plugin controls ! * A plugin button should be able to run a tool with a selection / mouse interaction. ! * ! * Modify new net while simulation is running, i.e. corner property, etc. ! * Planarity and regularity of panels, add bending stiffness! ! * Rectangularity needs improvement, bending stiffness! ! * Add parameters to b-net and save them! - see above, Michael, add and save parameters to original net ! * Subdivision ! * Selection => parameter changes to vertices and edges, not only global ! * Volume calculation and inflation force ! * Auto-detect corners of net (vertices that are only connected to 2 edges) ! * time settings and parameters ! */ public class PhysicsPackage { --- 40,48 ---- import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.plugin.NetCommand; + import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.packages.skeleton.*; ! public class PhysicsPackage { *************** *** 143,147 **** --- 127,136 ---- return factor; } + private DoubleValue selectionDistance = new DoubleValue(3); + public DoubleValue getSelectionDistance() { + return selectionDistance; + } + public void initialize(Space net) { *************** *** 177,180 **** --- 166,170 ---- pN = new PhysicsNet(cNet, gravity.getValue(), springConstant.getValue(), cDamp.getValue(), pDamp.getValue(), mass.getValue(), restLengthFactor.getValue()); pN.toolFactor = factor.getValue(); + pN.selectionDistance = selectionDistance.getValue(); panel = new ControlPanel(this,cNet,pN,edges); *************** *** 208,211 **** --- 198,202 ---- //tool Factor pN.toolFactor = factor.getValue(); + pN.selectionDistance = selectionDistance.getValue(); //track changes of bNet and modify Physics Net accordingly *************** *** 221,224 **** --- 212,216 ---- } } + //update edges Collection<Edge> bEdges = net.getEdges(); *************** *** 277,286 **** protected void moved(MouseEvent event) { findTarget(event); if (target instanceof Geometric) { ! if (target instanceof Surface) { ! editor.getView().makeTarget(target); } ! if (target instanceof Edge) { ! editor.getView().makeTarget(target); } } --- 269,282 ---- protected void moved(MouseEvent event) { findTarget(event); + Selection.primary().clear(); if (target instanceof Geometric) { ! if (target instanceof Vertex) { ! //editor.getView().makeTarget(target); ! Vertex bV = (Vertex) target; ! pN.extendSelectionFromVertex(bV, pN.selectionDistance); } ! if (target instanceof Surface) { ! Surface bS = (Surface) target; ! pN.extendSelectionFromVertex(bS, pN.selectionDistance); } } *************** *** 289,293 **** @Override protected void pressed(MouseEvent event) { ! findTarget(event); if (target instanceof Geometric) { if (target instanceof Surface) { --- 285,298 ---- @Override protected void pressed(MouseEvent event) { ! Iterator it = Selection.primary().iterator(); ! while (it.hasNext()) { ! Geometric g = (Geometric)it.next(); ! if (g instanceof Edge) { ! Edge bE = (Edge)g; ! double bDist = bE.center().distance(pN.sOrigin); ! pN.scaleRestLengthFactor(bE,1+(((pN.selectionDistance-bDist)/pN.selectionDistance)*pN.toolFactor/4)); ! } ! } ! /* if (target instanceof Geometric) { if (target instanceof Surface) { *************** *** 305,308 **** --- 310,314 ---- } } + */ } *************** *** 315,319 **** --- 321,327 ---- public static class physicsChangeWeightTool extends AbstractTool { + //import net.sourceforge.bprocessor.packages.physics.*; PhysicsNet pN; //Physics Net = Simulation Object + public physicsChangeWeightTool() { // TODO Auto-generated constructor stub *************** *** 333,339 **** protected void moved(MouseEvent event) { findTarget(event); if (target instanceof Geometric) { if (target instanceof Vertex) { ! editor.getView().makeTarget(target); } } --- 341,354 ---- protected void moved(MouseEvent event) { findTarget(event); + Selection.primary().clear(); if (target instanceof Geometric) { if (target instanceof Vertex) { ! //editor.getView().makeTarget(target); ! Vertex bV = (Vertex) target; ! pN.extendSelectionFromVertex(bV, pN.selectionDistance); ! } ! if (target instanceof Surface) { ! Surface bS = (Surface) target; ! pN.extendSelectionFromVertex(bS, pN.selectionDistance); } } *************** *** 342,354 **** @Override protected void pressed(MouseEvent event) { ! findTarget(event); ! if (target instanceof Geometric) { ! if (target instanceof Vertex) { ! editor.getView().makeTarget(target); ! Vertex bV = (Vertex) target; ! pN.scaleParticleMass(bV,1+(pN.toolFactor/4)); } } ! } --- 357,371 ---- @Override protected void pressed(MouseEvent event) { ! ! Iterator it = Selection.primary().iterator(); ! while (it.hasNext()) { ! Geometric g = (Geometric)it.next(); ! if (g instanceof Vertex) { ! Vertex bV = (Vertex)g; ! double bDist = bV.distance(pN.sOrigin); ! pN.scaleParticleMass(bV,1+(((pN.selectionDistance-bDist)/pN.selectionDistance)*pN.toolFactor)); } } ! //pN.scaleParticleMass(bV,1+(pN.toolFactor/4)); } *************** *** 358,361 **** --- 375,381 ---- } + + + } *************** *** 458,515 **** content.add(buttonRow); } - { - // add tool buttons - Box buttonRow = Box.createHorizontalBox(); - { - buttonRow.add(Box.createHorizontalStrut(5)); - JButton toolBtnA = new JButton(new SkeletonAction("p-spring.png") { - public void actionPerformed(ActionEvent e) { - Editor.instance().changeTool(toolSprings); - } - }); - toolBtnA.setMargin(new Insets(1, 1, 1, 1)); - toolBtnA.setMaximumSize(toolBtnA.getMinimumSize()); - buttonRow.add(toolBtnA); - } - { - buttonRow.add(Box.createHorizontalStrut(5)); - JButton toolBtnB = new JButton(new SkeletonAction("p-weight.png") { - public void actionPerformed(ActionEvent e) { - Editor.instance().changeTool(toolWeights); - } - }); - toolBtnB.setMargin(new Insets(1, 1, 1, 1)); - toolBtnB.setMaximumSize(toolBtnB.getMinimumSize()); - buttonRow.add(toolBtnB); - } ! buttonRow.add(Box.createHorizontalGlue()); ! content.add(buttonRow); ! } //add sliders { ! SliderControl control = new SliderControl(0.0001, 0.1, skeleton.getTimeStep(), this); ! Label labelled = new Label("Calc Time Step [s]", control); content.add(labelled.row()); } { ! SliderControl control = new SliderControl(-1, 1, skeleton.getFactor(), this); ! Label labelled = new Label("Tool Setting", control); content.add(labelled.row()); } { ! SliderControl control = new SliderControl(-9.81, 9.81, skeleton.getGravity(), this); ! Label labelled = new Label("Gravity [m/s2]", control); content.add(labelled.row()); } { ! SliderControl control = new SliderControl(0, 30, skeleton.getMass(), this); ! Label labelled = new Label("Particle Mass [kg]", control); content.add(labelled.row()); } { ! SliderControl control = new SliderControl(0, 50, skeleton.getPDamp(), this); ! Label labelled = new Label("Particle Damping [N sec/m]", control); content.add(labelled.row()); } --- 478,537 ---- content.add(buttonRow); } ! //add sliders { ! SliderControl control = new SliderControl(-9.81, 9.81, skeleton.getGravity(), this); ! Label labelled = new Label("Gravity [m/s2]", control); content.add(labelled.row()); } { ! SliderControl control = new SliderControl(0, 100, skeleton.getEqualConstant(), this); ! Label labelled = new Label("Equal Edges Spring Constant ec [N/m]", control); ! content.add(labelled.row()); ! } ! /*{ ! SliderControl control = new SliderControl(0, 50, skeleton.getEqualDamping(), this); ! Label labelled = new Label("Equal Edges Damping [N sec/m]", control); ! content.add(labelled.row()); ! }*/ ! { ! SliderControl control = new SliderControl(0, 100, skeleton.getRectConstant(), this); ! Label labelled = new Label("Equal Diagonals Spring Constant rc [N/m]", control); content.add(labelled.row()); } + /*{ + SliderControl control = new SliderControl(0, 50, skeleton.getRectDamping(), this); + Label labelled = new Label("Equal Diagonals Damping [N sec/m]", control); + content.add(labelled.row()); + }*/ { ! SliderControl control = new SliderControl(0, 100, skeleton.getPlaneConstant(), this); ! Label labelled = new Label("Planarity Spring Constant pc [N/m]", control); content.add(labelled.row()); } + /*{ + SliderControl control = new SliderControl(0, 50, skeleton.getPlaneDamping(), this); + Label labelled = new Label("Planarity Damping [N sec/m]", control); + content.add(labelled.row()); + }*/ { ! SliderControl control = new SliderControl(0, 1000, skeleton.getVolume(), this); ! Label labelled = new Label("Volume [m3]", control); content.add(labelled.row()); } + // add spacing { ! Box spacing = Box.createHorizontalBox(); ! { ! spacing.add(Box.createHorizontalStrut(15)); ! spacing.add(Box.createVerticalStrut(15)); ! } ! content.add(spacing); ! } ! { ! SliderControl control = new SliderControl(0, 30, skeleton.getMass(), this); ! Label labelled = new Label("Particle Mass [kg]", control); content.add(labelled.row()); } *************** *** 529,565 **** content.add(labelled.row()); } { ! SliderControl control = new SliderControl(0, 100, skeleton.getEqualConstant(), this); ! Label labelled = new Label("Equal Edges Spring Constant ec [N/m]", control); ! content.add(labelled.row()); } - /*{ - SliderControl control = new SliderControl(0, 50, skeleton.getEqualDamping(), this); - Label labelled = new Label("Equal Edges Damping [N sec/m]", control); - content.add(labelled.row()); - }*/ { ! SliderControl control = new SliderControl(0, 100, skeleton.getRectConstant(), this); ! Label labelled = new Label("Equal Diagonals Spring Constant rc [N/m]", control); content.add(labelled.row()); } - /*{ - SliderControl control = new SliderControl(0, 50, skeleton.getRectDamping(), this); - Label labelled = new Label("Equal Diagonals Damping [N sec/m]", control); - content.add(labelled.row()); - }*/ { ! SliderControl control = new SliderControl(0, 100, skeleton.getPlaneConstant(), this); ! Label labelled = new Label("Planarity Spring Constant pc [N/m]", control); content.add(labelled.row()); } ! /*{ ! SliderControl control = new SliderControl(0, 50, skeleton.getPlaneDamping(), this); ! Label labelled = new Label("Planarity Damping [N sec/m]", control); content.add(labelled.row()); ! }*/ { ! SliderControl control = new SliderControl(0, 1000, skeleton.getVolume(), this); ! Label labelled = new Label("Volume [m3]", control); content.add(labelled.row()); } --- 551,621 ---- content.add(labelled.row()); } + // add spacing { ! Box spacing = Box.createHorizontalBox(); ! { ! spacing.add(Box.createHorizontalStrut(15)); ! spacing.add(Box.createVerticalStrut(15)); ! } ! content.add(spacing); } { ! SliderControl control = new SliderControl(0.0001, 0.1, skeleton.getTimeStep(), this); ! Label labelled = new Label("Calc Time Step [s]", control); content.add(labelled.row()); } { ! SliderControl control = new SliderControl(0, 50, skeleton.getPDamp(), this); ! Label labelled = new Label("Particle Damping [N sec/m]", control); content.add(labelled.row()); } ! ! // add spacing ! { ! Box spacing = Box.createHorizontalBox(); ! { ! spacing.add(Box.createHorizontalStrut(15)); ! spacing.add(Box.createVerticalStrut(15)); ! } ! content.add(spacing); ! } ! ! // add tool buttons ! { ! Box buttonRow = Box.createHorizontalBox(); ! { ! buttonRow.add(Box.createHorizontalStrut(5)); ! JButton toolBtnA = new JButton(new SkeletonAction("p-spring.png") { ! public void actionPerformed(ActionEvent e) { ! Editor.instance().changeTool(toolSprings); ! } ! }); ! toolBtnA.setMargin(new Insets(1, 1, 1, 1)); ! toolBtnA.setMaximumSize(toolBtnA.getMinimumSize()); ! buttonRow.add(toolBtnA); ! } ! { ! buttonRow.add(Box.createHorizontalStrut(5)); ! JButton toolBtnB = new JButton(new SkeletonAction("p-weight.png") { ! public void actionPerformed(ActionEvent e) { ! Editor.instance().changeTool(toolWeights); ! } ! }); ! toolBtnB.setMargin(new Insets(1, 1, 1, 1)); ! toolBtnB.setMaximumSize(toolBtnB.getMinimumSize()); ! buttonRow.add(toolBtnB); ! } ! ! buttonRow.add(Box.createHorizontalGlue()); ! content.add(buttonRow); ! } ! { ! SliderControl control = new SliderControl(-1, 1, skeleton.getFactor(), this); ! Label labelled = new Label("Tool Setting", control); content.add(labelled.row()); ! } { ! SliderControl control = new SliderControl(0.0001, 500, skeleton.getSelectionDistance(), this); ! Label labelled = new Label("Extend Selection Distance", control); content.add(labelled.row()); } Index: PhysicsNet.java =================================================================== RCS file: /cvsroot/bprocessor/bprocessor/src/net/sourceforge/bprocessor/packages/physics/PhysicsNet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PhysicsNet.java 5 Jun 2011 19:57:14 -0000 1.3 --- PhysicsNet.java 6 Mar 2012 09:28:13 -0000 1.4 *************** *** 5,8 **** --- 5,9 ---- import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.ParameterBlock; + import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Vertex; *************** *** 20,23 **** --- 21,26 ---- boolean solid = false; double toolFactor = 0.0; + double selectionDistance = 4; + Vertex sOrigin = new Vertex(0,0,0); //selection Center / Origin HashMap<Vertex,PhysicsParticle> particles = new HashMap(); HashMap<Edge,PhysicsSpring> springs = new HashMap(); *************** *** 257,259 **** --- 260,301 ---- return v; } + + public void extendSelectionFromVertex(Vertex bV,double dist) { + Collection<Surface> tSurfaces= bV.getSurfaces(); + sOrigin = bV; + for (Surface s : tSurfaces) { + Selection.primary().add(s); + extendSelectionFromSurface(s,sOrigin, dist); + } + } + + public void extendSelectionFromVertex(Surface bS,double dist) { + Selection.primary().add(bS); + sOrigin = bS.center(); + extendSelectionFromSurface(bS,sOrigin, dist); + } + + public void extendSelectionFromSurface(Surface bS, Vertex origin, double dist) { + Collection<Vertex> tVertices = bS.getVertices(); + for (Vertex bV : tVertices) { + Collection<Surface> tSurfaces= bV.getSurfaces(); + for (Surface s : tSurfaces) { + if (Selection.primary().contains(s)==false) { + Collection<Vertex> sVertices = s.getVertices(); + Boolean allIn = true; + for (Vertex v : tVertices) { + if (Math.abs(origin.distance(v))>dist) { + allIn = false; + } + } + if (allIn==true) { + Selection.primary().add(s); + Selection.primary().addAll(s.getVertices()); + Selection.primary().addAll(s.getEdges()); + extendSelectionFromSurface(s,origin, dist); + } + } + } + } + } } \ No newline at end of file |