Commit a410cb30 authored by Alina Hinzmann's avatar Alina Hinzmann

new class for alignment of labels along the edges, inherits from

ZUpLabelPosition since only positioning of labels on edges changes
parent a5912a7b
/**
*
*/
package de.jtem.halfedgetools.plugin.data.visualizer;
import de.jreality.math.Matrix;
import de.jreality.math.MatrixBuilder;
import de.jreality.math.Rn;
import de.jreality.util.Rectangle3D;
import de.jtem.halfedge.Edge;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.type.Normal;
import de.jtem.halfedgetools.adapter.type.generic.BaryCenter3d;
import de.jtem.halfedgetools.adapter.type.generic.EdgeVector;
import de.jtem.halfedgetools.adapter.type.generic.Position3d;
/**
* @author hinzmann
*
*/
public class AlongEdgeLabelPosition extends ZUpLabelPosition {
@Override
public String toString(){
return "along Edge";
}
@Override
public Matrix getTransformationMatrix(Rectangle3D labelBoundingBox, Edge<?, ?, ?> e, AdapterSet as, boolean labelFlip) {
double[] labelbbCenter = labelBoundingBox.getCenter();
double[] edgeVector = as.getD(EdgeVector.class, e); //get edge as vector
double[] faceNormal = as.getD(Normal.class, e.getLeftFace());
double[][] edgeCoordinateSystem = new double[3][3];
edgeCoordinateSystem[2] = faceNormal; //the faces normal (will become labels z-direction by making a matrix out of these vectors)
edgeCoordinateSystem[1] = Rn.crossProduct(null, faceNormal, edgeVector); //vector orthogonal both to the edge and the faces normal, i.e. the vector orthogonal to the edge and lying in the face (will get labels y-direction)
Rn.normalize(edgeCoordinateSystem[1], edgeCoordinateSystem[1]); //normalize it
edgeCoordinateSystem[0] = edgeVector; //the edge (will become labels x-direction)
Rn.normalize(edgeCoordinateSystem[0], edgeCoordinateSystem[0]); //normalize it
double[] edgeCenter = as.getD(BaryCenter3d.class, e);
// double[] faceCenter = as.getD(BaryCenter3d.class, e.getLeftFace());
// Rn.linearCombination(edgeCenter, 0.95, edgeCenter, 0.05, faceCenter);
double marginFactor = 0.03;
Rn.add(edgeCenter, edgeCenter, Rn.times(null, marginFactor, edgeCoordinateSystem[1])); //add a bit margin by "translating" edgeCenter
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
anchorPoint[2] = labelBoundingBox.getMinZ(); //and we always take the min in z-direction, such that a 3D-label-boundingbox would stick out to the geometry's outside
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){
M.multiplyOnRight(MatrixBuilder.euclidean().translate(labelbbCenter).getMatrix());
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(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
// double[] edgeVector = as.getD(EdgeVector.class, e); //get edge as vector
// double[] normedEdgeVector = Rn.normalize(null, edgeVector);
// double[] faceNormal = as.getD(Normal.class, e.getLeftFace());
// double[] orthogToEdge = Rn.crossProduct(null, faceNormal, edgeVector);
// Rn.normalize(orthogToEdge, orthogToEdge);
//
// double[] edgeCenter = as.getD(BaryCenter3d.class, e);
//// double[] faceCenter = as.getD(BaryCenter3d.class, e.getLeftFace());
//// Rn.linearCombination(edgeCenter, 0.95, edgeCenter, 0.05, faceCenter);
// double marginFactor = 0.03;
// Rn.add(edgeCenter, edgeCenter, Rn.times(null, marginFactor, orthogToEdge)); //add a bit margin by "translating" edgeCenter
//
// 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
// anchorPoint[2] = labelBoundingBox.getMinZ(); //and we always take the min in z-direction, such that a 3D-label-boundingbox would stick out to the geometry's outside
//
// Matrix M = MatrixBuilder.euclidean() //generate the trafo-matrix, done/to read from bottom to top
// .translate(edgeCenter) //translate the label to the vertex position
// .rotateFromTo(new double[]{1,0,0}, normedEdgeVector)
// .rotateFromTo(new double[]{0,1,0}, orthogToEdge)
// .rotateFromTo(new double[]{0,0,1}, faceNormal) //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)
// }
// M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, anchorPoint)).getMatrix()); //translate the labels center to the origin
//
// return M;
}
}
......@@ -91,6 +91,8 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
public LabelVisualizer() {
ZUpLabelPosition zUpLabelPosition = new ZUpLabelPosition();
labelPositions.add(zUpLabelPosition);
AlongEdgeLabelPosition alongEdgeLabelPosition = new AlongEdgeLabelPosition();
labelPositions.add(alongEdgeLabelPosition);
labelPositionCombo = new JComboBox<>(labelPositions.toArray(new LabelPosition[0]));
// labelPositionCombo.addItem(zUpLabelPosition);
......
......@@ -20,7 +20,7 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
public String toString(){
return "Z up";
return "z-axis up";
}
@Override
......@@ -86,7 +86,7 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
*
* If the normal is almost the same as updirection and therefore facesCoordinateSystem[1] almost zero, then {0, 1,0} is projected as alternate upDirection.
*/
private double[][] getFacesCoordinateSystem(Face<?,?,?> f, AdapterSet as) {
protected double[][] getFacesCoordinateSystem(Face<?,?,?> f, AdapterSet as) {
// double[] upDirection = new double[]{0,0,1};
double[][] facesCoordinateSystem = new double[3][3];
facesCoordinateSystem[2] = as.getD(Normal.class, f); //the faces normal
......@@ -106,7 +106,7 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
* @param basePoint the targetpoint the label will be translated to
* @return the transformation matrix
*/
private Matrix getTransformationMatrix(double[][] faceCoordinateSystem, double[]basePoint) {
protected Matrix getTransformationMatrix(double[][] faceCoordinateSystem, double[]basePoint) {
Matrix matrix = new Matrix(
faceCoordinateSystem[0][0], faceCoordinateSystem[1][0], faceCoordinateSystem[2][0], basePoint[0],
faceCoordinateSystem[0][1], faceCoordinateSystem[1][1], faceCoordinateSystem[2][1], basePoint[1],
......
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