()
| 303 | } |
| 304 | |
| 305 | func (tg *TensorGrid) Render() { |
| 306 | if tg.Tensor == nil || tg.Tensor.Len() == 0 { |
| 307 | return |
| 308 | } |
| 309 | tg.EnsureColorMap() |
| 310 | tg.UpdateRange() |
| 311 | |
| 312 | pc := &tg.Scene.PaintContext |
| 313 | |
| 314 | pos := tg.Geom.Pos.Content |
| 315 | sz := tg.Geom.Size.Actual.Content |
| 316 | // sz.SetSubScalar(tg.Disp.BotRtSpace.Dots) |
| 317 | |
| 318 | pc.FillBox(pos, sz, tg.Styles.Background) |
| 319 | |
| 320 | tsr := tg.Tensor |
| 321 | |
| 322 | if tg.Display.Image { |
| 323 | ysz := tsr.DimSize(0) |
| 324 | xsz := tsr.DimSize(1) |
| 325 | nclr := 1 |
| 326 | outclr := false // outer dimension is color |
| 327 | if tsr.NumDims() == 3 { |
| 328 | if tsr.DimSize(0) == 3 || tsr.DimSize(0) == 4 { |
| 329 | outclr = true |
| 330 | ysz = tsr.DimSize(1) |
| 331 | xsz = tsr.DimSize(2) |
| 332 | nclr = tsr.DimSize(0) |
| 333 | } else { |
| 334 | nclr = tsr.DimSize(2) |
| 335 | } |
| 336 | } |
| 337 | tsz := math32.Vec2(float32(xsz), float32(ysz)) |
| 338 | gsz := sz.Div(tsz) |
| 339 | for y := 0; y < ysz; y++ { |
| 340 | for x := 0; x < xsz; x++ { |
| 341 | ey := y |
| 342 | if !tg.Display.TopZero { |
| 343 | ey = (ysz - 1) - y |
| 344 | } |
| 345 | switch { |
| 346 | case outclr: |
| 347 | var r, g, b, a float64 |
| 348 | a = 1 |
| 349 | r = tg.Display.Range.ClipNormValue(tsr.Float([]int{0, y, x})) |
| 350 | g = tg.Display.Range.ClipNormValue(tsr.Float([]int{1, y, x})) |
| 351 | b = tg.Display.Range.ClipNormValue(tsr.Float([]int{2, y, x})) |
| 352 | if nclr > 3 { |
| 353 | a = tg.Display.Range.ClipNormValue(tsr.Float([]int{3, y, x})) |
| 354 | } |
| 355 | cr := math32.Vec2(float32(x), float32(ey)) |
| 356 | pr := pos.Add(cr.Mul(gsz)) |
| 357 | pc.StrokeStyle.Color = colors.Uniform(colors.FromFloat64(r, g, b, a)) |
| 358 | pc.FillBox(pr, gsz, pc.StrokeStyle.Color) |
| 359 | case nclr > 1: |
| 360 | var r, g, b, a float64 |
| 361 | a = 1 |
| 362 | r = tg.Display.Range.ClipNormValue(tsr.Float([]int{y, x, 0})) |
nothing calls this directly
no test coverage detected