Prechádzať zdrojové kódy

Nonlinear remapping to make it possible to ignore boring beginning and end

Andreas Völker 5 rokov pred
rodič
commit
7ef4189153

BIN
colormap.png


+ 4 - 0
src/de/andreasvoelker/BlochFrame.java

@@ -12,6 +12,10 @@ public class BlochFrame extends GLCanvas {
     final BlochRenderer renderer;
     final Animator animator;
 
+    public void setNonlinearity(float v) {
+        renderer.setNonlinearity(v);
+    }
+
 
     class MyMouseMotionListener implements MouseMotionListener {
         int prevX, prevY;

+ 22 - 1
src/de/andreasvoelker/BlochRenderer.java

@@ -20,6 +20,27 @@ public class BlochRenderer implements GLEventListener {
     private float pitch = 0;
     private float yaw = 0;
 
+    public float getNonlinearity() {
+        return nonlinearity;
+    }
+
+    public void setNonlinearity(float nonlinearity) {
+        this.nonlinearity = nonlinearity;
+    }
+
+    private float nonlinearRemap(float x){
+        // from (Mathematica):
+        // f[x_] := a + b*x + c*x^2 + d*x^3
+        // Solve[{f[0] == 0, f[1] == 1, f[1/2] == 1/2, f'[1/2] == s}, {a, b, c,
+        //  d}]
+        float xx = x*x;
+        float xxx = xx*x;
+        return (3-2*nonlinearity)*x+6*(nonlinearity-1)*xx-4*(nonlinearity-1)*xxx;
+
+    }
+
+    private float nonlinearity = 1.0f;
+
     public float getRadius() {
         return radius;
     }
@@ -85,7 +106,7 @@ public class BlochRenderer implements GLEventListener {
             gl.glBegin(GL2.GL_LINE_STRIP);
             for (int i = 0; i != blochSphere.getSize(); i++) {
                 gl.glVertex3f(blochSphere.pre[i], blochSphere.pim[i], blochSphere.f[i]);
-                gl.glTexCoord1f((factor*blochSphere.t[i]-t0));
+                gl.glTexCoord1f(nonlinearRemap(factor*(blochSphere.t[i]-t0)));
             }
             gl.glEnd();
         }

+ 11 - 3
src/de/andreasvoelker/MainWindows.java

@@ -8,6 +8,7 @@ import java.io.*;
 public class MainWindows extends JFrame {
     final JButton button;
     final BlochFrame blochFrame;
+    final JSlider nonlinearRemapping;
 
     MainWindows(){
         super("BlochRender");
@@ -26,10 +27,17 @@ public class MainWindows extends JFrame {
 
 
         setLayout(new MigLayout("fill"));
+        nonlinearRemapping = new JSlider();
+        nonlinearRemapping.setMinimum(0);
+        nonlinearRemapping.setMajorTickSpacing(200);
+        nonlinearRemapping.setValue(20);
+        nonlinearRemapping.addChangeListener(e -> blochFrame.setNonlinearity((float)(nonlinearRemapping.getValue())/20.0f));
 
-        add(blochFrame, "grow, span 1 2");
-        add(button, "wrap");
-        add(label);
+        add(blochFrame, "grow, span 1 3");
+        add(button, "wrap, span 2");
+        add(new JLabel("Nonlinear remapping"));
+        add(nonlinearRemapping, "wrap");
+        add(label, "span 2");
         this.pack();
 
     }