Commit 792985b2 authored by hinzmann's avatar hinzmann

implemented adjustable offset (default = 0) in direction of normal

parent 347f3d53
......@@ -10,7 +10,9 @@ import de.jtem.halfedgetools.adapter.AdapterSet;
public abstract class AbstractLabelPosition implements LabelPosition {
protected double marginFactor = 1.0;
protected double
marginFactor = 1.0,
offset = 0.0;
/**
* Gives the converted absolute margin factor.
......@@ -28,6 +30,16 @@ public abstract class AbstractLabelPosition implements LabelPosition {
*/
public abstract double getDefaultMargin();
public double getOffset(){
return offset;
}
public void setOffset(double offset){
this.offset = offset;
}
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Node<?, ?, ?> n, AdapterSet as, boolean horizontalFlip, boolean verticalFlip) {
if(Vertex.class.isAssignableFrom(n.getClass())) {
......
......@@ -49,6 +49,10 @@ public class AlongEdgeLabelPosition extends ZUpLabelPosition {
// Rn.linearCombination(edgeCenter, 0.95, edgeCenter, 0.05, faceCenter);
Rn.add(edgeCenter, edgeCenter, Rn.times(null, marginFactor, edgeCoordinateSystem[1])); //add a bit margin by "translating" edgeCenter
//for offsetting the label, move the edgeCenter with factor offset in direction of the facenormal
Rn.add(edgeCenter, edgeCenter, Rn.times(null, offset, faceNormal));
double[] anchorPoint = new double[3];
anchorPoint[0] = labelBoundingBox.getCenter()[0]; //take the x-coord of the center as x-coordinate for the anchorpoint
anchorPoint[1] = labelBoundingBox.getMinY(); //and choose minY as y-coordinate
......
......@@ -12,6 +12,8 @@ public interface LabelPosition {
public void setMarginFactor(double marginFactor);
public void setOffset(double offset);
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);
......
......@@ -69,13 +69,14 @@ 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),
marginFactorModel = new SpinnerNumberModel(1, -10, 10, 0.1); ////factor moving the Label away from its corresponding edge, here 1 as default value in order to have one GUI-element for different LabelPosition classes, but in computation of the matrixTrafo this will be converted to an absolute value using standard-margin (getDefaultMargin()) of the current LabelPosition-class
marginFactorModel = new SpinnerNumberModel(1, -10, 10, 0.1), ////factor moving the Label away from its corresponding edge, here 1 as default value in order to have one GUI-element for different LabelPosition classes, but in computation of the matrixTrafo this will be converted to an absolute value using standard-margin (getDefaultMargin()) of the current LabelPosition-class
offsetModel = new SpinnerNumberModel(0.0, -5, 5, 0.01);
private JSpinner
decimalsSpinner = new JSpinner(decimalsModel),
sizeSpinner = new JSpinner(fontSizeModel),
marginFactorSpinner = new JSpinner(marginFactorModel);
marginFactorSpinner = new JSpinner(marginFactorModel),
offsetSpinner = new JSpinner(offsetModel);
private JTextField
prefixTextField = new JTextField(); //a textfield allowing to set a prefix to all labels of a visualization
......@@ -131,6 +132,10 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
optionsPanel.add(marginFactorSpinner, rc);
marginFactorSpinner.addChangeListener(this);
optionsPanel.add(new JLabel("Offset"), lc);
optionsPanel.add(offsetSpinner, rc);
offsetSpinner.addChangeListener(this);
// lc.gridwidth = 2;
labelColorButton.setColor(Color.BLACK); //set the initial color to black
optionsPanel.add(new JLabel("Color"), lc);
......@@ -225,6 +230,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
activeVisualization.setFlippedVertically(verticalFlipChecker.isSelected());
activeVisualization.setFontSize(fontSizeModel.getNumber().doubleValue());
activeVisualization.setMarginFactor(marginFactorModel.getNumber().doubleValue());
activeVisualization.setOffset(offsetModel.getNumber().doubleValue());
activeVisualization.setColor(getLabelColor());
activeVisualization.update();
}
......@@ -243,6 +249,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
verticalFlipChecker.setSelected(activeVisualization.isFlippedVertically());
fontSizeModel.setValue(activeVisualization.getFontSize());
marginFactorModel.setValue(activeVisualization.getMarginFactor());
offsetModel.setValue(activeVisualization.getOffset());
labelColorButton.setColor(activeVisualization.getColor());
listenersDisabled = false;
return optionsPanel;
......@@ -446,8 +453,9 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
private double
fontSize = 0.05, //font size of the label resp. the lineset
marginFactor = 1; //factor moving the Label away from its corresponding edge, here 1 as default value but in computation of the matrixTrafo this will be converted to an absolute value using standard-margin (getDefaultMargin()) of the current LabelPosition-class
marginFactor = 1.0, //factor moving the Label away from its corresponding edge, here 1 as default value but in computation of the matrixTrafo this will be converted to an absolute value using standard-margin (getDefaultMargin()) of the current LabelPosition-class
offset = 0.0;
private Color
color = Color.BLACK;
......@@ -580,6 +588,15 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
this.marginFactor = marginFactor;
labelPosition.setMarginFactor(marginFactor);
}
public double getOffset() {
return offset;
}
public void setOffset(double offset) {
this.offset = offset;
labelPosition.setOffset(offset);
}
public Color getColor() {
return color;
......
......@@ -27,6 +27,10 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] center = as.getD(Position3d.class, v);
double[] normal = as.getD(Normal.class, v);
//for offsetting the label, move the center with factor offset in direction of the normal
Rn.add(center, center, Rn.times(null, offset, normal));
Matrix M = MatrixBuilder.euclidean() //generate the trafo-matrix, done/to read from bottom to top
.translate(center) //translate the label to the vertex position
.rotateFromTo(upDirection, normal) //new double[]{0, 0,1}, normal) //rotate the updirection to the vertexnormal
......@@ -60,15 +64,19 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
double[][] localCoordinateSystem = getFacesCoordinateSystem(face,as);
double[] anchorPoint = getAnchorPoint(edgeVector, localCoordinateSystem, labelBoundingBox);
double[] anchorPoint = getAnchorPoint(edgeVector, localCoordinateSystem, labelBoundingBox); //find out which point of the label shall be used as anchorpoint for placing it
double[] edgeCenter = as.getD(BaryCenter3d.class, e);
double[] faceCenter = as.getD(BaryCenter3d.class, face);
double[] marginVector = Rn.subtract(null, faceCenter, edgeCenter);
double[] marginVector = Rn.subtract(null, faceCenter, edgeCenter); //vector from edgeCenter to faceCenter
Rn.normalize(marginVector,marginVector);
//for moving the label a bit apart from its edge, move the edgeCenter with factor marginFactor towards faceCenter
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
//for offsetting the label, move the edgeCenter with factor offset in direction of the facenormal
Rn.add(edgeCenter, edgeCenter, Rn.times(null, offset, localCoordinateSystem[2]));
Matrix M = getTransformationMatrix(localCoordinateSystem, edgeCenter);
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, anchorPoint)).getMatrix());
if(horizontalFlip || verticalFlip){
......@@ -89,6 +97,10 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] center = as.getD(BaryCenter3d.class, f);
double[][] localCoordinateSystem = getFacesCoordinateSystem(f,as);
//for offsetting the label, move the center with factor offset in direction of the facenormal
Rn.add(center, center, Rn.times(null, offset, localCoordinateSystem[2]));
Matrix M = getTransformationMatrix(localCoordinateSystem, center);
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)
......
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