Commit 72277d76 authored by Alina Hinzmann's avatar Alina Hinzmann

implemented possibility to now flip both horizontically and vertically,

marginFactor as paramter
TODO: fix problem with marginFactor-Spinner and remove Flip-booleans
from methodparameters
parent d447bb58
......@@ -9,26 +9,38 @@ import de.jtem.halfedge.Vertex;
import de.jtem.halfedgetools.adapter.AdapterSet;
public abstract class AbstractLabelPosition implements LabelPosition {
protected double marginFactor = 1.0;
public double getMarginFactor(){
return marginFactor*getDefaultMargin();
}
public void setMarginFactor(double marginFactor){
this.marginFactor = marginFactor/getDefaultMargin();
}
public abstract double getDefaultMargin();
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Node<?, ?, ?> n, AdapterSet as, boolean labelFlip) {
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Node<?, ?, ?> n, AdapterSet as, boolean horizontalFlip, boolean verticalFlip) {
if(Vertex.class.isAssignableFrom(n.getClass())) {
return getTransformationMatrix(labelBoundingBox, (Vertex<?,?,?>)n, as, labelFlip);
return getTransformationMatrix(labelBoundingBox, (Vertex<?,?,?>)n, as, horizontalFlip, verticalFlip);
} else if(Edge.class.isAssignableFrom(n.getClass())) {
return getTransformationMatrix(labelBoundingBox, (Edge<?,?,?>)n, as, labelFlip);
return getTransformationMatrix(labelBoundingBox, (Edge<?,?,?>)n, as, horizontalFlip, verticalFlip);
} else if(Face.class.isAssignableFrom(n.getClass())) {
return getTransformationMatrix(labelBoundingBox, (Face<?,?,?>)n, as, labelFlip);
return getTransformationMatrix(labelBoundingBox, (Face<?,?,?>)n, as, horizontalFlip, verticalFlip);
}
return null;
}
@Override
public abstract Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Vertex<?, ?, ?> v, AdapterSet as, boolean labelFlip);
public abstract Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Vertex<?, ?, ?> v, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
@Override
public abstract Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean labelFlip);
public abstract Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
@Override
public abstract Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Face<?, ?, ?> f, AdapterSet as, boolean labelFlip);
public abstract Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Face<?, ?, ?> f, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
}
......@@ -26,11 +26,11 @@ public class AlongEdgeLabelPosition extends ZUpLabelPosition {
}
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean labelFlip) {
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean horizontalFlip, boolean verticalFlip) {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] edgeVector = as.getD(EdgeVector.class, e); //get edge as vector
Face<?,?,?> face = e.getLeftFace();
double marginFactor = 0.03;
double marginFactor = getMarginFactor();
if(face == null) {
face = e.getRightFace();
}
......@@ -57,12 +57,18 @@ public class AlongEdgeLabelPosition extends ZUpLabelPosition {
Matrix M = getTransformationMatrix(edgeCoordinateSystem, edgeCenter); //puts together the coord-vectors to a matrix which will be the transformation of x-axis -> edgeCoordinateSystem[0], y-axis -> edgeCoordinateSystem[1], z-axis -> edgeCoordinateSystem[2] and the translation by edgeCenter
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, anchorPoint)).getMatrix());
if(labelFlip){
if(horizontalFlip || verticalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().translate(labelbbCenter).getMatrix());
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix());
if(horizontalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix());
}
if(verticalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateX(Math.PI).getMatrix());
}
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, labelbbCenter)).getMatrix());
}
return M;
//TEST: the following did not work... but thought it should do the same
......@@ -98,5 +104,11 @@ public class AlongEdgeLabelPosition extends ZUpLabelPosition {
// return M;
}
@Override
public double getDefaultMargin() {
return 0.03;
}
}
......@@ -9,12 +9,14 @@ import de.jtem.halfedge.Vertex;
import de.jtem.halfedgetools.adapter.AdapterSet;
public interface LabelPosition {
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Node<?,?,?> n, AdapterSet as, boolean labelFlip);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Vertex<?,?,?> v, AdapterSet as, boolean labelFlip);
public void setMarginFactor(double marginFactor);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Node<?,?,?> n, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Vertex<?,?,?> v, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean labelFlip);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Face<?,?,?> f, AdapterSet as, boolean labelFlip);
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Face<?,?,?> f, AdapterSet as, boolean horizontalFlip, boolean verticalFlip);
}
......@@ -68,18 +68,21 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
private SpinnerNumberModel
decimalsModel = new SpinnerNumberModel(3.0, 0.0, 100.0, 1.0),
fontSizeModel = new SpinnerNumberModel(0.05, 0.0, 100, 0.01);
fontSizeModel = new SpinnerNumberModel(0.05, 0.0, 100, 0.01),
marginFactorModel = new SpinnerNumberModel(0.03, -1, 1, 0.01); //TODO Problem:Startwert des Sliders setzen
private JSpinner
decimalsSpinner = new JSpinner(decimalsModel),
sizeSpinner = new JSpinner(fontSizeModel);
sizeSpinner = new JSpinner(fontSizeModel),
marginFactorSpinner = new JSpinner(marginFactorModel);
private JTextField
prefixTextField = new JTextField(); //a textfield allowing to set a prefix to all labels of a visualization
private JCheckBox
flipLabelChecker = new JCheckBox("Flip direction"); //gives the possibility to flip the labels (if normals are in the "wrong" direction for it)
//do this by rotating the label-lineset 180degree around its bb-center-axis (z axis resp. earlier y-axis)
horizontalFlipChecker = new JCheckBox("Flip horizontally"), //gives the possibility to flip the labels (if normals are in the "wrong" direction for it), do this by rotating the label-lineset 180degree around its bb-center-axis (z axis resp. earlier y-axis)
verticalFlipChecker = new JCheckBox("Flip vertically");
private ColorChooseJButton
labelColorButton = new ColorChooseJButton(true); //cool color button, true = showing colors to choose in new window
......@@ -112,14 +115,21 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
optionsPanel.add(prefixTextField, rc);
prefixTextField.addActionListener(this);
optionsPanel.add(flipLabelChecker, rc);
flipLabelChecker.addActionListener(this);
optionsPanel.add(horizontalFlipChecker, lc);
horizontalFlipChecker.addActionListener(this);
optionsPanel.add(verticalFlipChecker, rc);
verticalFlipChecker.addActionListener(this);
optionsPanel.add(new JLabel("Font size"), lc);
// sizeSpinner.setPreferredSize(new Dimension(100, 32));
optionsPanel.add(sizeSpinner, rc);
sizeSpinner.addChangeListener(this);
optionsPanel.add(new JLabel("Margin"), lc);
optionsPanel.add(marginFactorSpinner, rc);
marginFactorSpinner.addChangeListener(this);
// lc.gridwidth = 2;
labelColorButton.setColor(Color.BLACK); //set the initial color to black
optionsPanel.add(new JLabel("Color"), lc);
......@@ -158,7 +168,8 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
// vis.decimals = decimalsModel.getNumber().intValue();
// vis.prefix = prefixTextField.getText();
vis.setFontSize(fontSizeModel.getNumber().doubleValue()); //stay with the fontsize previously chosen
vis.labelFlip = flipLabelChecker.isSelected(); //if labels were flipped in the previous visualization than go on with doing so
vis.setMarginFactor(marginFactorModel.getNumber().doubleValue());
vis.horizontalFlip = horizontalFlipChecker.isSelected(); //if labels were flipped in the previous visualization than go on with doing so
// vis.setColor(getLabelColor());
// vis.update();
......@@ -209,8 +220,10 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
activeVisualization.setLabelPosition((LabelPosition) labelPositionCombo.getSelectedItem());
activeVisualization.setDecimals(decimalsModel.getNumber().intValue());
activeVisualization.setPrefix(prefixTextField.getText());
activeVisualization.setLabelFlipped(flipLabelChecker.isSelected());
activeVisualization.setFlippedHorizontally(horizontalFlipChecker.isSelected());
activeVisualization.setFlippedVertically(verticalFlipChecker.isSelected());
activeVisualization.setFontSize(fontSizeModel.getNumber().doubleValue());
activeVisualization.setMarginFactor(marginFactorModel.getNumber().doubleValue());
activeVisualization.setColor(getLabelColor());
activeVisualization.update();
}
......@@ -225,8 +238,10 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
labelPositionCombo.setSelectedItem(activeVisualization.getLabelPosition());
decimalsModel.setValue(activeVisualization.getDecimals());
prefixTextField.setText(activeVisualization.getPrefix());
flipLabelChecker.setSelected(activeVisualization.isLabelFlipped());
horizontalFlipChecker.setSelected(activeVisualization.isFlippedHorizontally());
verticalFlipChecker.setSelected(activeVisualization.isFlippedVertically());
fontSizeModel.setValue(activeVisualization.getFontSize());
marginFactorModel.setValue(activeVisualization.getMarginFactor());
labelColorButton.setColor(activeVisualization.getColor());
listenersDisabled = false;
return optionsPanel;
......@@ -422,13 +437,15 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
prefix = new String(); //a possible prefix for all labels
private boolean
labelFlip; //labels are flipped if true (to make them readable both from in- and outside of the corresponding geometry)
horizontalFlip, //labels are flipped horizontally if true (to make them readable both from in- and outside of the corresponding geometry)
verticalFlip; //labels are flipped vertically
private Appearance
labelAppearance = null;
private double
fontSize = 0.05; // font size of the label resp. the lineset
fontSize = 0.05, //font size of the label resp. the lineset
marginFactor = 0.03; //absolute factor moving the Label away from its corresponding edge
private Color
color = Color.BLACK;
......@@ -468,7 +485,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
for(Node<?,?,?> node : labelFactory.getNodes()) { //go through all these nodes which shall be labelled with the data
Object data = getSource().get(node, a); //getSource() gives the Data-Adapter for which the visualization by labels was chosen, .get(v, a) gets its value for the vertex v - this is what the label shall show
Label label = labelFactory.createNodeLabel(node, data); //creates the label for the node with its data
Matrix M = labelPosition.getTransformationMatrix(label.getBoundingBox(), node, a, labelFlip); //now work out where to place it by getting the needed transformations from the trafoMatrix of labelPosition
Matrix M = labelPosition.getTransformationMatrix(label.getBoundingBox(), node, a, horizontalFlip, verticalFlip); //now work out where to place it by getting the needed transformations from the trafoMatrix of labelPosition
SceneGraphComponent labelComponent = label.getLabelComponent();
M.assignTo(labelComponent); //and assign this trafo to the SGC
SceneGraphUtility.addChildNode(visualizationRoot, labelComponent);
......@@ -529,12 +546,20 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
this.prefix = prefix;
}
public boolean isLabelFlipped() {
return labelFlip;
public boolean isFlippedHorizontally() {
return horizontalFlip;
}
public void setLabelFlipped(boolean labelFlip) {
this.labelFlip = labelFlip;
public void setFlippedHorizontally(boolean horizontalFlip) {
this.horizontalFlip = horizontalFlip;
}
public boolean isFlippedVertically() {
return verticalFlip;
}
public void setFlippedVertically(boolean verticalFlip) {
this.verticalFlip = verticalFlip;
}
public double getFontSize() {
......@@ -546,6 +571,15 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
ttfLineSetFactory.setSize(fontSize);
}
public double getMarginFactor() {
return marginFactor;
}
public void setMarginFactor(double marginFactor) {
this.marginFactor = marginFactor;
labelPosition.setMarginFactor(marginFactor);
}
public Color getColor() {
return color;
}
......
......@@ -18,13 +18,12 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
private double[]
upDirection = new double[]{0,0,1};
public String toString(){
return "z-axis up";
}
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Vertex<?,?,?> v, AdapterSet as, boolean labelFlip) {
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Vertex<?,?,?> v, AdapterSet as, boolean horizontalFlip, boolean verticalFlip) {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] center = as.getD(Position3d.class, v);
double[] normal = as.getD(Normal.class, v);
......@@ -32,23 +31,26 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
.translate(center) //translate the label to the vertex position
.rotateFromTo(upDirection, normal) //new double[]{0, 0,1}, normal) //rotate the updirection to the vertexnormal
.getMatrix();
if(labelFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix()); //if the label shall be flipped: rotate it 180degree around central axis of its boundingbox (since translated in the origin this is the y-axis)
}
if(horizontalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix()); //if the label shall be flipped horizontally: rotate it 180degree around central axis of its boundingbox (since translated in the origin this is the y-axis)
}
if(verticalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateX(Math.PI).getMatrix()); //if the label shall be flipped vertically: rotate it 180degree around the x-axis (since translated in the origin)
}
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, labelbbCenter)).getMatrix()); //translate the labels center to the origin
return M;
}
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean labelFlip) {
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean horizontalFlip, boolean verticalFlip) {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] edgeVector = as.getD(EdgeVector.class, e); //get edge as vector
Face<?,?,?> face = e.getLeftFace();
double offset = 0.05;
double marginFactor = getMarginFactor();
if(face == null) {
face = e.getRightFace();
offset *= -1.0;
marginFactor *= -1.0;
}
if(face == null) {
return null;
......@@ -59,26 +61,37 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
double[] edgeCenter = as.getD(BaryCenter3d.class, e);
double[] faceCenter = as.getD(BaryCenter3d.class, face);
Rn.linearCombination(edgeCenter, 0.95, edgeCenter, offset, faceCenter);
double[] marginVector = Rn.subtract(null, faceCenter, edgeCenter);
Rn.normalize(marginVector,marginVector);
Rn.add(edgeCenter, edgeCenter, Rn.times(null, marginFactor, marginVector)); //add a bit margin by "translating" edgeCenter
// Rn.linearCombination(edgeCenter, 0.95, edgeCenter, marginFactor, faceCenter); //add a bit margin by shifting edgeCenter to faceCenter by marginFactor
Matrix M = getTransformationMatrix(localCoordinateSystem, edgeCenter);
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, anchorPoint)).getMatrix());
if(labelFlip){
if(horizontalFlip || verticalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().translate(labelbbCenter).getMatrix());
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix());
if(horizontalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix());
}
if(verticalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateX(Math.PI).getMatrix());
}
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, labelbbCenter)).getMatrix());
}
return M;
}
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Face<?, ?, ?> f, AdapterSet as, boolean labelFlip) {
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Face<?, ?, ?> f, AdapterSet as, boolean horizontalFlip, boolean verticalFlip) {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] center = as.getD(BaryCenter3d.class, f);
double[][] localCoordinateSystem = getFacesCoordinateSystem(f,as);
Matrix M = getTransformationMatrix(localCoordinateSystem, center);
if(labelFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix()); //if the label shall be flipped: rotate it 180degree around central axis of its boundingbox (since translated in the origin this is the y-axis)
if(horizontalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix()); //if the label shall be flipped horizontally: rotate it 180degree around central axis of its boundingbox (since translated in the origin this is the y-axis)
}
if(verticalFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateX(Math.PI).getMatrix()); //if the label shall be flipped vertically: rotate it 180degree around the x-axis (since translated in the origin)
}
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, labelbbCenter)).getMatrix());
return M;
......@@ -153,5 +166,10 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
return anchorPoint;
}
@Override
public double getDefaultMargin() {
return 0.05;
}
}
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