Commit cefadbb2 authored by hinzmann's avatar hinzmann

added size UI

parent f7fcfdb6
package de.jtem.halfedgetools.plugin.data.visualizer;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import de.jreality.geometry.BoundingBoxUtility;
import de.jreality.geometry.TTFLineSetFactory;
import de.jreality.math.Matrix;
......@@ -9,6 +20,7 @@ import de.jreality.scene.Appearance;
import de.jreality.scene.IndexedLineSet;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.shader.CommonAttributes;
import de.jreality.ui.LayoutFactory;
import de.jreality.util.Rectangle3D;
import de.jreality.util.SceneGraphUtility;
import de.jtem.halfedge.Edge;
......@@ -30,17 +42,83 @@ import de.jtem.halfedgetools.plugin.image.ImageHook;
import de.jtem.jrworkspace.plugin.Controller;
import de.jtem.jrworkspace.plugin.PluginInfo;
public class LabelVisualizer extends DataVisualizerPlugin {
public class LabelVisualizer extends DataVisualizerPlugin implements ChangeListener {
private HalfedgeInterface
hif = null;
private JPanel
panel = new JPanel();
private SpinnerNumberModel
sizeModel = new SpinnerNumberModel(0.03, 0.0, 100, 0.1);
private JSpinner
sizeSpinner = new JSpinner(sizeModel);
private LabelVisualization
activeVisualization = null;
public LabelVisualizer() {
panel.setLayout(new GridBagLayout());
GridBagConstraints lc = LayoutFactory.createLeftConstraint();
GridBagConstraints rc = LayoutFactory.createRightConstraint();
panel.add(new JLabel("Font size"), lc);
sizeSpinner.setPreferredSize(new Dimension(100, 32));
panel.add(sizeSpinner, rc);
sizeSpinner.addChangeListener(this);
}
@Override
public boolean canRead(Adapter<?> a, NodeType type) {
return true;
}
@Override
public PluginInfo getPluginInfo() {
PluginInfo info = super.getPluginInfo();
info.icon = ImageHook.getIcon("font.png");
return info;
}
@Override
public String getName() {
return "Labels";
}
@Override
public DataVisualization createVisualization(HalfedgeLayer layer, NodeType type, Adapter<?> source) {
return new LabelVisualization(layer, source, this, type);
}
@Override
public void stateChanged(ChangeEvent e) {
activeVisualization.setFontSize(sizeModel.getNumber().doubleValue());
activeVisualization.update();
}
@Override
public JPanel connectUserInterfaceFor(DataVisualization visualization) {
activeVisualization = (LabelVisualization) visualization;
sizeModel.setValue(activeVisualization.getFontSize());
return panel;
}
@Override
public void install(Controller c) throws Exception {
super.install(c);
hif = c.getPlugin(HalfedgeInterface.class);
}
private class LabelVisualization extends AbstractDataVisualization {
private SceneGraphComponent visualizationRoot = new SceneGraphComponent("Label visualization root");
private TTFLineSetFactory
ttfLineSetFactory = new TTFLineSetFactory();
private double
fontSize = 0.03;
public LabelVisualization(
HalfedgeLayer layer,
......@@ -52,6 +130,16 @@ public class LabelVisualizer extends DataVisualizerPlugin {
visualizationRoot.setName("Label for " + source.toString());
ttfLineSetFactory.setTTFFont(LabelVisualizer.class.getResource("Raleway-Thin.ttf").getPath());
ttfLineSetFactory.setSingleLineFont(false);
ttfLineSetFactory.setSize(fontSize);
}
public double getFontSize() {
return fontSize;
}
public void setFontSize(double fontSize) {
this.fontSize = fontSize;
ttfLineSetFactory.setSize(fontSize);
}
@Override
......@@ -60,14 +148,12 @@ public class LabelVisualizer extends DataVisualizerPlugin {
AdapterSet a = hif.getAdapters();
visualizationRoot.removeAllChildren();
ttfLineSetFactory.setSize(0.03);
switch (getType()) {
case Vertex: {
int numDigits = (int) Math.ceil(Math.log10(getLayer().get().numVertices()));
for (Vertex<?, ?, ?> v : getLayer().get().getVertices()) {
String label = getSource().get(v, a).toString();
SceneGraphComponent sgc = new SceneGraphComponent("V" + String.format("%0"+numDigits+"d",v.getIndex()));
IndexedLineSet labelLineSet = ttfLineSetFactory.getIndexLineSet(label);
sgc.setGeometry(labelLineSet);
......@@ -89,7 +175,7 @@ public class LabelVisualizer extends DataVisualizerPlugin {
int numDigits = (int) Math.ceil(Math.log10(getLayer().get().numEdges()));
for (Edge<?, ?, ?> e : getLayer().get().getEdges()) {
String label = getSource().get(e, a).toString();
SceneGraphComponent sgc = new SceneGraphComponent("E" + String.format("%0"+numDigits+"d",e.getIndex()));
sgc.setGeometry(ttfLineSetFactory.getIndexLineSet(label));
Rectangle3D labelBoundingBox = BoundingBoxUtility.calculateBoundingBox(ttfLineSetFactory.getIndexLineSet(label));
......@@ -102,7 +188,7 @@ public class LabelVisualizer extends DataVisualizerPlugin {
double[] edgeCenter = a.getD(BaryCenter3d.class, e);
double[] faceCenter = a.getD(BaryCenter3d.class, e.getLeftFace());
Rn.linearCombination(edgeCenter, 0.95, edgeCenter, 0.05, faceCenter);
Matrix M = getTransformationMatrix(localCoordinateSystem, edgeCenter);
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, anchorPoint)).getMatrix());
M.assignTo(sgc);
......@@ -134,7 +220,7 @@ public class LabelVisualizer extends DataVisualizerPlugin {
Appearance app = ttfLineSetFactory.getStandardAppearance();
app.setAttribute(CommonAttributes.EDGE_DRAW, true);
visualizationRoot.setAppearance(app);
getLayer().addTemporaryGeometry(visualizationRoot);
}
......@@ -169,7 +255,7 @@ public class LabelVisualizer extends DataVisualizerPlugin {
return anchorPoint;
}
private double[][] getFaceCoordinateSystem(Face<?,?,?> f, AdapterSet as) {
double[] upDirection = new double[]{0,0,1};
double[][] faceCoordinateSystem = new double[3][3];
......@@ -196,32 +282,4 @@ public class LabelVisualizer extends DataVisualizerPlugin {
}
@Override
public boolean canRead(Adapter<?> a, NodeType type) {
return true;
}
@Override
public PluginInfo getPluginInfo() {
PluginInfo info = super.getPluginInfo();
info.icon = ImageHook.getIcon("font.png");
return info;
}
@Override
public String getName() {
return "Labels";
}
@Override
public DataVisualization createVisualization(HalfedgeLayer layer, NodeType type, Adapter<?> source) {
return new LabelVisualization(layer, source, this, type);
}
@Override
public void install(Controller c) throws Exception {
super.install(c);
hif = c.getPlugin(HalfedgeInterface.class);
}
}
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