Visualisation does aspect ratio correctly.

Thu, 19 Dec 2019 23:29:21 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 19 Dec 2019 23:29:21 +0200
changeset 24
f6630036e588
parent 23
64a3f09e5fa7
child 25
1fba916f2b77

Visualisation does aspect ratio correctly.

src/Visualise.jl file | annotate | diff | comparison | revisions
--- a/src/Visualise.jl	Thu Dec 19 21:38:03 2019 +0200
+++ b/src/Visualise.jl	Thu Dec 19 23:29:21 2019 +0200
@@ -82,6 +82,7 @@
     n = length(imgs)
     # Get device dimensions in metres and pixels
     scrw, scrh, pw, ph = GR.inqdspsize()
+    aspect = n > 0 ? Float64(size(imgs[1], 1))/Float64(size(imgs[1], 2)) : 1
     # Scaling to maximums ize window
     sc=0.7
     # Set up window and transformations
@@ -90,20 +91,20 @@
     GR.selntran(1)
     # - First OS window size
     if scrw/n>scrh
-        GR.setwsviewport(0, sc*scrh*n, 0, sc*scrh)
+        GR.setwsviewport(0, sc*scrh*n, 0, sc*scrh*aspect)
     else
-        GR.setwsviewport(0, sc*scrw, 0, sc*scrw/n)
+        GR.setwsviewport(0, sc*scrw, 0, sc*scrw/n*aspect)
     end
     # - Part of normalised window shown
-    GR.setwswindow(0, 1, 0, 1/n);
-    GR.setviewport(0, 1, 0, 1/n); 
-    # Workd coordinates
-    GR.setwindow(0, n, 0, 1)
+    GR.setwswindow(0, 1, 0, 1/n*aspect);
+    GR.setviewport(0, 1, 0, 1/n*aspect); 
+    # World coordinates
+    GR.setwindow(0, n, 0, aspect)
     # Plot images
     for i=1:n
         im = imgs[i]'
         sz = size(im)
-        GR.drawimage(i-1, i, 0, 1, sz[1], sz[2], grayGR.(im))
+        GR.drawimage(i-1, i, 0, aspect, sz[1], sz[2], grayGR.(im))
     end
     if refresh
         GR.updatews()

mercurial