Skip to content

Commit

Permalink
GUI: re-scale vector quantities to unity so that big values render OK
Browse files Browse the repository at this point in the history
(Thanks Mykola Dvornik)
  • Loading branch information
barnex committed Jan 28, 2015
1 parent 31a5771 commit 3bfde19
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions draw/colorscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func ColorMap(min, max, value float32, colormap ...color.RGBA) color.RGBA {

// get two neighboring colors
i := int(index)
if i < 0 {
i = 0
}
if i >= len(colormap)-1 {
i = len(colormap) - 2
}
c1 := colormap[i]
c2 := colormap[i+1]

Expand Down
34 changes: 34 additions & 0 deletions engine/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/mumax/3/draw"
"image"
"image/jpeg"
"math"
"net/http"
"sync"
)
Expand Down Expand Up @@ -110,6 +111,9 @@ func (ren *render) render() {
d := ren.imgBuf
comp := ren.comp
quant := ren.quant
if comp == "" {
normalize(d)
}
if comp != "" && quant.NComp() > 1 { // ... if one has been selected by gui
d = d.Comp(compstr[comp])
}
Expand All @@ -123,3 +127,33 @@ func (ren *render) render() {
}

var compstr = map[string]int{"x": 0, "y": 1, "z": 2}

func normalize(f *data.Slice) {
a := f.Vectors()
maxnorm := 0.
for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {

x, y, z := a[0][i][j][k], a[1][i][j][k], a[2][i][j][k]
norm := math.Sqrt(float64(x*x + y*y + z*z))
if norm > maxnorm {
maxnorm = norm
}

}
}
}
factor := float32(1 / maxnorm)

for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {
a[0][i][j][k] *= factor
a[1][i][j][k] *= factor
a[2][i][j][k] *= factor

}
}
}
}

0 comments on commit 3bfde19

Please sign in to comment.