Commit 44ff5bdd authored by hinzmann's avatar hinzmann

-new EdgeNormal Adapter

-AlongEdgePostion is also working if there is no incident face
-Zup does not work in this case yet -> TODO: fix this problem
parent 792985b2
......@@ -20,6 +20,7 @@ import de.jtem.halfedgetools.adapter.generic.BaryCenter4dAdapter;
import de.jtem.halfedgetools.adapter.generic.BaryCenterAdapter;
import de.jtem.halfedgetools.adapter.generic.EdgeLengthAdapter;
import de.jtem.halfedgetools.adapter.generic.EdgeLengthTexAdapter;
import de.jtem.halfedgetools.adapter.generic.EdgeNormalAdapter;
import de.jtem.halfedgetools.adapter.generic.EdgeVectorAdapter;
import de.jtem.halfedgetools.adapter.generic.FaceAreaAdapter;
import de.jtem.halfedgetools.adapter.generic.IndexLabelAdapter;
......@@ -483,6 +484,7 @@ public class AdapterSet extends TreeSet<Adapter<?>> {
aSet.add(new EdgeLengthAdapter());
aSet.add(new EdgeLengthTexAdapter());
aSet.add(new IndexLabelAdapter());
aSet.add(new EdgeNormalAdapter());
return aSet;
}
......
package de.jtem.halfedgetools.adapter.generic;
import de.jreality.math.Rn;
import de.jtem.halfedge.Edge;
import de.jtem.halfedge.Face;
import de.jtem.halfedge.Node;
import de.jtem.halfedge.Vertex;
import de.jtem.halfedgetools.adapter.AbstractAdapter;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.type.EdgeNormal;
import de.jtem.halfedgetools.adapter.type.Normal;
import de.jtem.halfedgetools.adapter.type.VectorField;
import de.jtem.halfedgetools.adapter.type.generic.EdgeVector;
@EdgeNormal
@VectorField
public class EdgeNormalAdapter extends AbstractAdapter<double[]> {
public EdgeNormalAdapter() {
super(double[].class, true, false);
}
public EdgeNormalAdapter(Class<? extends double[]> typeClass, boolean getter, boolean setter) {
super(typeClass, getter, setter);
}
@Override
public double getPriority() {
return -1;
}
@Override
public <
V extends Vertex<V, E, F>,
E extends Edge<V, E, F>,
F extends Face<V, E, F>
> double[] getE(E e, AdapterSet a) {
double[] normal = new double[3];
if (e.getLeftFace() != null) {
normal = a.getD(Normal.class, e.getLeftFace());
return normal;
}
else if (e.getPreviousEdge()!= null && e.getNextEdge() != null) {
double[] edgeVector = a.getD(EdgeVector.class, e);
double[] prevEdgeVector = a.getD(EdgeVector.class, e.getPreviousEdge());
double[] nextEdgeVector = a.getD(EdgeVector.class, e.getNextEdge());
if (e.getPreviousEdge().equals(e.getNextEdge())){
//TODO
}
double[] n1 = Rn.crossProduct(null, edgeVector, Rn.negate(prevEdgeVector,prevEdgeVector));
Rn.add(normal, normal, n1);
if (e.getNextEdge() == null) {
return Rn.normalize(normal, normal);
}
double[] n2 = Rn.crossProduct(null, nextEdgeVector, Rn.negate(edgeVector,edgeVector));
Rn.add(normal, normal, n2);
return Rn.times(normal, 1.0 / 2.0, normal);
}
// else if (e.getRightFace() != null) {
// normal = a.getD(Normal.class, e.getRightFace());
// return normal;
// }
return normal;
}
@Override
public <N extends Node<?, ?, ?>> boolean canAccept(Class<N> nodeClass) {
return true;
}
@Override
public String toString() {
return "EdgeNormals";
}
}
package de.jtem.halfedgetools.adapter.type;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EdgeNormal {
}
......@@ -10,6 +10,7 @@ import de.jreality.util.Rectangle3D;
import de.jtem.halfedge.Edge;
import de.jtem.halfedge.Face;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.type.EdgeNormal;
import de.jtem.halfedgetools.adapter.type.Normal;
import de.jtem.halfedgetools.adapter.type.generic.BaryCenter3d;
import de.jtem.halfedgetools.adapter.type.generic.EdgeVector;
......@@ -29,13 +30,16 @@ public class AlongEdgeLabelPosition extends ZUpLabelPosition {
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();
// Face<?,?,?> face = e.getLeftFace();
double marginFactor = getMarginFactor();
if(face == null) {
face = e.getRightFace();
}
// if(face == null) {
// face = e.getRightFace();
// }
double[] faceNormal = (face == null)?new double[]{0,0,1}:as.getD(Normal.class, face);
// double[] faceNormal = (face == null)?new double[]{0,0,1}:as.getD(Normal.class, face);
// double[] faceNormal = (face == null)?as.getD(EdgeNormal.class, e):as.getD(Normal.class, face);
double[] faceNormal = as.getD(EdgeNormal.class, e);
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)
......
......@@ -6,8 +6,10 @@ import de.jreality.math.Rn;
import de.jreality.util.Rectangle3D;
import de.jtem.halfedge.Edge;
import de.jtem.halfedge.Face;
import de.jtem.halfedge.Node;
import de.jtem.halfedge.Vertex;
import de.jtem.halfedgetools.adapter.AdapterSet;
import de.jtem.halfedgetools.adapter.type.EdgeNormal;
import de.jtem.halfedgetools.adapter.type.Normal;
import de.jtem.halfedgetools.adapter.type.generic.BaryCenter3d;
import de.jtem.halfedgetools.adapter.type.generic.EdgeVector;
......@@ -50,6 +52,7 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
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
double[] edgeCenter = as.getD(BaryCenter3d.class, e);
Face<?,?,?> face = e.getLeftFace();
double marginFactor = getMarginFactor(); //get the absolute marginFactor for this LabelPosition which will be used to translate the label away from the edge to make it fit better
......@@ -58,17 +61,22 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
face = e.getRightFace();
marginFactor *= -1.0; //in this case negate the factor in order to still place the label on the correct side of the edge
}
double[] faceCenter = null;
double[][] localCoordinateSystem = null;
double[] marginVector = null;
if(face == null) { //if right face is also null, return
return null; //TODO find a solution for the case that the edge has no incident faces!!
localCoordinateSystem = getLocalCoordinateSystem(e,as); //TODO find a solution for the case that the edge has no incident faces!!
marginVector = localCoordinateSystem[2]; //TODO
}else{
localCoordinateSystem = getLocalCoordinateSystem(face,as);
faceCenter = as.getD(BaryCenter3d.class, face);
marginVector = Rn.subtract(null, faceCenter, edgeCenter); //vector from edgeCenter to faceCenter
}
double[][] localCoordinateSystem = getFacesCoordinateSystem(face,as);
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); //vector from edgeCenter to faceCenter
// 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
......@@ -96,7 +104,7 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
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);
double[][] localCoordinateSystem = getLocalCoordinateSystem(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]));
......@@ -114,7 +122,7 @@ public class ZUpLabelPosition extends AbstractLabelPosition {
/**
* Calculates a 3-dim coordinate system as double[][] on the basis of a given face.
* @param f the face for which the coordinate system is calculated
* @param node the face for which the coordinate system is calculated
* @param as the adapterset
* @return facesCoordinateSystem where
* facesCoordinateSystem[2] is the normal of the face
......@@ -123,10 +131,13 @@ 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.
*/
protected double[][] getFacesCoordinateSystem(Face<?,?,?> f, AdapterSet as) {
protected double[][] getLocalCoordinateSystem(Node<?,?,?> node, 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
facesCoordinateSystem[2] = as.getD(Normal.class, node); //the faces normal
if(facesCoordinateSystem[2] == null) {
facesCoordinateSystem[2] = as.getD(EdgeNormal.class, node);
}
facesCoordinateSystem[1] = Rn.projectOntoComplement(null, upDirection, facesCoordinateSystem[2]); // projection of the upDirection onto the normals complement
if(Rn.euclideanNorm(facesCoordinateSystem[1]) < 1E-6){ //if the normal is almost the same as updirection -> facesCoordinateSystem[1] almost zero
facesCoordinateSystem[1] = Rn.projectOntoComplement(null, new double[]{0, 1,0}, facesCoordinateSystem[2]); //then choose {0, 1,0} as alternate upDirection for projecting
......
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