MCPcopy Create free account
hub / github.com/cogentcore/core / Render

Method Render

tensor/tensorcore/tensorgrid.go:305–413  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

303}
304
305func (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}))

Callers

nothing calls this directly

Calls 15

EnsureColorMapMethod · 0.95
UpdateRangeMethod · 0.95
ColorMethod · 0.95
Vec2Function · 0.92
UniformFunction · 0.92
FromFloat64Function · 0.92
Projection2DShapeFunction · 0.92
Projection2DValueFunction · 0.92
FillBoxMethod · 0.80
LenMethod · 0.65
DimSizeMethod · 0.65
NumDimsMethod · 0.65

Tested by

no test coverage detected