Commit 41f911ec authored by Thilo Rörig's avatar Thilo Rörig
Browse files

added n-gon to PrimitivesGenerator, added selection to vectorfield

visualizer, modified clipping, synchronized bb calculation, 
parent e26e7869
......@@ -151,6 +151,9 @@ public class HalfedgeLayer implements ActionListener {
private ActionTool
actionTool = new ActionTool("PrimaryAction");
private double[]
clippingOrigin = new double[]{0,0,0};
private HalfedgeLayer() {
layerRoot.addChild(geometryRoot);
......@@ -555,22 +558,24 @@ public class HalfedgeLayer implements ActionListener {
}
protected void updateBoundingBox() {
boundingBoxRoot.setGeometry(null);
if (boundingBoxRoot.getChildNodes().contains(pivotRoot)) {
boundingBoxRoot.removeChild(pivotRoot);
synchronized(boundingBoxRoot) {
boundingBoxRoot.setGeometry(null);
if (boundingBoxRoot.getChildNodes().contains(pivotRoot)) {
boundingBoxRoot.removeChild(pivotRoot);
}
Rectangle3D bbox = BoundingBoxUtility.calculateBoundingBox(layerRoot);
if (euclideanNormSquared(bbox.getExtent()) == 0)
return;
BoundingBoxUtility.removeZeroExtends(bbox);
IndexedFaceSet ifs = IndexedFaceSetUtility.representAsSceneGraph(bbox);
ifs.setName("Bounding Box");
boundingBoxRoot.setGeometry(ifs);
MatrixBuilder mb = MatrixBuilder.euclidean();
mb.translate(bbox.getMinX(), bbox.getMinY(), bbox.getMaxZ());
mb.scale(bbox.getMaxExtent() / 20);
mb.assignTo(pivotRoot);
boundingBoxRoot.addChild(pivotRoot);
}
Rectangle3D bbox = BoundingBoxUtility.calculateBoundingBox(layerRoot);
if (euclideanNormSquared(bbox.getExtent()) == 0)
return;
BoundingBoxUtility.removeZeroExtends(bbox);
IndexedFaceSet ifs = IndexedFaceSetUtility.representAsSceneGraph(bbox);
ifs.setName("Bounding Box");
boundingBoxRoot.setGeometry(ifs);
MatrixBuilder mb = MatrixBuilder.euclidean();
mb.translate(bbox.getMinX(), bbox.getMinY(), bbox.getMaxZ());
mb.scale(bbox.getMaxExtent() / 20);
mb.assignTo(pivotRoot);
boundingBoxRoot.addChild(pivotRoot);
}
@Override
......@@ -985,6 +990,10 @@ public class HalfedgeLayer implements ActionListener {
clippingScale = new double[]{x,y,z};
updateClipping();
}
public void setClippingOrigin(double x, double y, double z) {
clippingOrigin = new double[]{x,y,z};
}
public void setEnableClipping(boolean clip) {
clippingEnabled = clip;
......@@ -995,13 +1004,13 @@ public class HalfedgeLayer implements ActionListener {
Rectangle3D bb = BoundingBoxUtility.calculateBoundingBox(layerRoot);
clippingRoot.removeAllChildren();
if(clippingEnabled) {
clippingRoot.addChild(createClippingBox(bb, clippingScale));
clippingRoot.addChild(createClippingBox(bb, clippingScale, clippingOrigin));
}
}
private SceneGraphComponent createClippingBox(Rectangle3D bb, double[] cs) {
private SceneGraphComponent createClippingBox(Rectangle3D bb, double[] cs, double[] origin) {
SceneGraphComponent clipBox = new SceneGraphComponent("Clipping Box");
MatrixBuilder.euclidean().translate(bb.getCenter()).assignTo(clipBox);
double[] extent = bb.getExtent();
double x = cs[0];
double y = cs[1];
......@@ -1009,11 +1018,13 @@ public class HalfedgeLayer implements ActionListener {
switch (clippingMode) {
case REL:
MatrixBuilder.euclidean().translate(bb.getCenter()).assignTo(clipBox);
x *= extent[0]/2;
y *= extent[1]/2;
z *= extent[2]/2;
break;
case ABS:
MatrixBuilder.euclidean().translate(origin).assignTo(clipBox);
break;
}
......@@ -1047,6 +1058,10 @@ public class HalfedgeLayer implements ActionListener {
public double[] getClippingScale() {
return clippingScale;
}
public double[] getClippingOrigin() {
return clippingOrigin;
}
public boolean isClippingEnabled() {
return clippingEnabled;
......
......@@ -37,6 +37,7 @@ public class PrimitivesGenerator extends AlgorithmDialogPlugin implements ItemLi
private JRadioButton
triangleButton = new JRadioButton("Triangle"),
ngonButton = new JRadioButton("n-gon"),
cubeButton = new JRadioButton("Cube"),
openCubeButton = new JRadioButton("Open Cube"),
cylinderButton = new JRadioButton("Cylinder"),
......@@ -47,11 +48,13 @@ public class PrimitivesGenerator extends AlgorithmDialogPlugin implements ItemLi
cylinderParametersPanel = new ShrinkPanel("Cyclinder parameters");
private SpinnerNumberModel
ngonSize = new SpinnerNumberModel(5,3,Integer.MAX_VALUE, 1),
circlePoints = new SpinnerNumberModel(15, 3, 100, 1),
heightPoints = new SpinnerNumberModel(15, 2, 100, 1),
aspectRatio = new SpinnerNumberModel(1.0, 0.0001, 10000, 0.1);
private JSpinner
ngonSpinner = new JSpinner(ngonSize),
circleSpinner = new JSpinner(circlePoints),
heightSpinner = new JSpinner(heightPoints),
ratioSpinner = new JSpinner(aspectRatio);
......@@ -74,6 +77,7 @@ public class PrimitivesGenerator extends AlgorithmDialogPlugin implements ItemLi
triangleButton.setSelected(true);
primitivesGroup.add(triangleButton);
primitivesGroup.add(ngonButton);
primitivesGroup.add(openCubeButton);
primitivesGroup.add(cubeButton);
primitivesGroup.add(cylinderButton);
......@@ -91,6 +95,8 @@ public class PrimitivesGenerator extends AlgorithmDialogPlugin implements ItemLi
cylinderParametersPanel.setShrinked(false);
panel.add(triangleButton,gbc2);
panel.add(ngonButton,gbc2);
panel.add(ngonSpinner,gbc2);
panel.add(cubeButton,gbc2);
panel.add(openCubeButton, gbc2);
panel.add(cylinderButton,gbc2);
......@@ -118,6 +124,9 @@ public class PrimitivesGenerator extends AlgorithmDialogPlugin implements ItemLi
if(triangleButton.isSelected()) {
ifs = Primitives.regularPolygon(3);
}
if(ngonButton.isSelected()) {
ifs = Primitives.regularPolygon(ngonSize.getNumber().intValue());
}
if(cubeButton.isSelected()) {
ifs = Primitives.cube();
}
......
......@@ -17,6 +17,7 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
......@@ -45,17 +46,21 @@ import de.jtem.halfedge.Vertex;
import de.jtem.halfedgetools.adapter.Adapter;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.type.generic.BaryCenter3d;
import de.jtem.halfedgetools.plugin.HalfedgeInterface;
import de.jtem.halfedgetools.plugin.HalfedgeLayer;
import de.jtem.halfedgetools.plugin.data.AbstractDataVisualization;
import de.jtem.halfedgetools.plugin.data.DataVisualization;
import de.jtem.halfedgetools.plugin.data.DataVisualizer;
import de.jtem.halfedgetools.plugin.data.DataVisualizerPlugin;
import de.jtem.halfedgetools.plugin.image.ImageHook;
import de.jtem.halfedgetools.selection.Selection;
import de.jtem.halfedgetools.selection.SelectionListener;
import de.jtem.halfedgetools.util.GeometryUtility;
import de.jtem.jrworkspace.plugin.Controller;
import de.jtem.jrworkspace.plugin.PluginInfo;
public class VectorFieldVisualizer extends DataVisualizerPlugin implements
ActionListener, ChangeListener {
ActionListener, ChangeListener, SelectionListener {
private SpinnerNumberModel
scaleModel = new SpinnerNumberModel(1.0, -100.0, 100.0, 0.1),
......@@ -67,7 +72,8 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
directedChecker = new JCheckBox("Directed"),
tubesChecker = new JCheckBox("Tubes"),
normalizedChecker = new JCheckBox("Normalized"),
centeredChecker = new JCheckBox("Centered");
centeredChecker = new JCheckBox("Centered"),
selectionChecker = new JCheckBox("Selected");
private JPanel
optionsPanel = new JPanel();
......@@ -86,6 +92,9 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
private VectorFieldVisualization actVis = null;
private boolean listenersDisabled = false;
private List<VectorFieldVisualization>
visualizationList = new ArrayList<>();
public VectorFieldVisualizer() {
initOptionPanel();
......@@ -122,6 +131,8 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
colorChooser.setSelectedIndex(8);
cl.gridwidth = 2;
optionsPanel.add(colorChooser, cl);
optionsPanel.add(selectionChecker, cr);
selectionChecker.addActionListener(this);
colorChooser.addActionListener(this);
checkTubesEnabled();
......@@ -165,8 +176,13 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
vis.normalized = normalizedChecker.isSelected();
vis.centered = centeredChecker.isSelected();
vis.color = colors[colorChooser.getSelectedIndex()];
if(selectionChecker.isSelected()) {
vis.selection = layer.getSelection();
} else {
vis.selection = null;
}
layer.addTemporaryGeometry(vis.vectorsComponent);
visualizationList.add(vis);
return vis;
}
......@@ -174,6 +190,7 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
public void disposeVisualization(DataVisualization vis) {
VectorFieldVisualization vfVis = (VectorFieldVisualization) vis;
vis.getLayer().removeTemporaryGeometry(vfVis.vectorsComponent);
visualizationList.remove(vis);
}
@Override
......@@ -197,6 +214,11 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
actVis.normalized = normalizedChecker.isSelected();
actVis.centered = centeredChecker.isSelected();
actVis.color = colors[colorChooser.getSelectedIndex()];
if(selectionChecker.isSelected()) {
actVis.selection = actVis.getLayer().getSelection();
} else {
actVis.selection = null;
}
actVis.update();
}
......@@ -212,6 +234,8 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
normalized = true, centered = true;
private Color color = Color.BLACK;
private Selection selection = null;
public VectorFieldVisualization(HalfedgeLayer layer, Adapter<?> source,
DataVisualizer visualizer, NodeType type) {
super(layer, source, visualizer, type);
......@@ -255,13 +279,25 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
List<? extends Node> nodes = null;
switch (getType()) {
case Vertex:
nodes = hds.getVertices();
if(selection == null) {
nodes = hds.getVertices();
} else {
nodes = new LinkedList<Vertex<?,?,?> >(selection.getVertices());
}
break;
case Edge:
nodes = hds.getEdges();
if(selection == null) {
nodes = hds.getEdges();
} else {
nodes = new LinkedList<Edge<?,?,?> >(selection.getEdges());
}
break;
default:
nodes = hds.getFaces();
if(selection == null) {
nodes = hds.getFaces();
} else {
nodes = new LinkedList<Face<?,?,?> >(selection.getFaces());
}
break;
}
......@@ -621,4 +657,18 @@ public class VectorFieldVisualizer extends DataVisualizerPlugin implements
return optionsPanel;
}
@Override
public void selectionChanged(Selection s, HalfedgeInterface hif) {
if (listenersDisabled) return;
for (VectorFieldVisualization v : visualizationList) {
v.update();
}
}
@Override
public void install(Controller c) throws Exception {
super.install(c);
c.getPlugin(HalfedgeInterface.class).addSelectionListener(this);
}
}
......@@ -41,11 +41,18 @@ public class LayerActionsWidget extends JPanel implements ActionListener, Change
private SpinnerNumberModel
xSizeModel = new SpinnerNumberModel(0.5, 0.0, 1.0, 0.1),
ySizeModel = new SpinnerNumberModel(0.5, 0.0, 1.0, 0.1),
zSizeModel = new SpinnerNumberModel(0.5, 0.0, 1.0, 0.1);
zSizeModel = new SpinnerNumberModel(0.5, 0.0, 1.0, 0.1),
xOriginModel = new SpinnerNumberModel(0.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0),
yOriginModel = new SpinnerNumberModel(0.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0),
zOriginModel = new SpinnerNumberModel(0.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0);
private JSpinner
xSizeSpinner = new JSpinner(xSizeModel),
ySizeSpinner = new JSpinner(ySizeModel),
zSizeSpinner = new JSpinner(zSizeModel);
zSizeSpinner = new JSpinner(zSizeModel),
xOriginSpinner = new JSpinner(xOriginModel),
yOriginSpinner = new JSpinner(yOriginModel),
zOriginSpinner = new JSpinner(zOriginModel);
public LayerActionsWidget() {
setLayout(new GridBagLayout());
......@@ -68,6 +75,25 @@ public class LayerActionsWidget extends JPanel implements ActionListener, Change
xSizeSpinner.addChangeListener(this);
ySizeSpinner.addChangeListener(this);
zSizeSpinner.addChangeListener(this);
add(new JLabel("Origin"),lc);
add(new JLabel("x"),lc);
add(xOriginSpinner,lc);
add(new JLabel("y"),lc);
add(yOriginSpinner,lc);
add(new JLabel("z"),lc);
add(zOriginSpinner,rc);
xOriginSpinner.setPreferredSize(new Dimension(50,20));
yOriginSpinner.setPreferredSize(new Dimension(50,20));
zOriginSpinner.setPreferredSize(new Dimension(50,20));
clippingBox.addActionListener(this);
xOriginSpinner.addChangeListener(this);
yOriginSpinner.addChangeListener(this);
zOriginSpinner.addChangeListener(this);
xOriginSpinner.setEnabled(false);
yOriginSpinner.setEnabled(false);
zOriginSpinner.setEnabled(false);
scaleGroup.add(relativeButton);
scaleGroup.add(absoluteButton);
relativeButton.setSelected(true);
......@@ -98,6 +124,10 @@ public class LayerActionsWidget extends JPanel implements ActionListener, Change
zSizeModel.setMaximum(1.0);
zSizeModel.setStepSize(.05);
} else if(absoluteButton.isSelected()) {
xOriginSpinner.setEnabled(absoluteButton.isSelected());
yOriginSpinner.setEnabled(absoluteButton.isSelected());
zOriginSpinner.setEnabled(absoluteButton.isSelected());
Rectangle3D bb = BoundingBoxUtility.calculateBoundingBox(layer.getGeometryRoot());
Rectangle3D bbGeometry = BoundingBoxUtility.calculateBoundingBox(layer.getGeometry());
double[] extent = bb.getExtent();
......@@ -113,16 +143,25 @@ public class LayerActionsWidget extends JPanel implements ActionListener, Change
zSizeModel.setValue(2.0*gExtent[1]);
zSizeModel.setMaximum(Double.MAX_VALUE);
zSizeModel.setStepSize(extent[1]*0.05);
xOriginModel.setStepSize(extent[0]*0.05);
yOriginModel.setStepSize(extent[1]*0.05);
zOriginModel.setStepSize(extent[1]*0.05);
}
}
@Override
public void stateChanged(ChangeEvent e) {
if(e.getSource() == xSizeSpinner || e.getSource() == ySizeSpinner || e.getSource() == zSizeSpinner) {
if(e.getSource() == xSizeSpinner || e.getSource() == ySizeSpinner || e.getSource() == zSizeSpinner ||
e.getSource() == xOriginSpinner || e.getSource() == yOriginSpinner || e.getSource() == zOriginSpinner) {
double x = xSizeModel.getNumber().doubleValue();
double y = ySizeModel.getNumber().doubleValue();
double z = zSizeModel.getNumber().doubleValue();
layer.setClippingScale(x,y,z);
double ox = xOriginModel.getNumber().doubleValue();
double oy = yOriginModel.getNumber().doubleValue();
double oz = zOriginModel.getNumber().doubleValue();
layer.setClippingScale(x,y,z);
layer.setClippingOrigin(ox,oy,oz);
}
}
......@@ -143,6 +182,10 @@ public class LayerActionsWidget extends JPanel implements ActionListener, Change
xSizeModel.setValue(scale[0]);
ySizeModel.setValue(scale[1]);
zSizeModel.setValue(scale[2]);
double[] origin = layer.getClippingOrigin();
xOriginModel.setValue(origin[0]);
yOriginModel.setValue(origin[1]);
zOriginModel.setValue(origin[2]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment