class_docstr: Render SDFs using the CPU.
class_docstr_tok: ["Render","SDFs","using","the","CPU","."]
code: def render_to_texture(self, data, texture, offset, size):
      sdf = (data / 255).astype(np.float32)  # from ubyte -> float
      h, w = sdf.shape
      tex_w, tex_h = size
      _calc_distance_field(sdf, w, h, 32)
      # This tweaking gets us a result more similar to the GPU SDFs,
      # for which the text rendering code was optimized
      sdf = 2 * sdf - 1.0
      sdf = np.sign(sdf) * np.abs(sdf) ** 0.75 / 2.0 + 0.5
      # Downsample using NumPy (because we can't guarantee SciPy)
      xp = (np.arange(w) + 0.5) / float(w)
      x = (np.arange(tex_w) + 0.5) / float(tex_w)
      bitmap = np.array([np.interp(x, xp, ss) for ss in sdf])
      xp = (np.arange(h) + 0.5) / float(h)
      x = (np.arange(tex_h) + 0.5) / float(tex_h)
      bitmap = np.array([np.interp(x, xp, ss) for ss in bitmap.T]).T
      assert bitmap.shape[::-1] == size
      # convert to uint8
      bitmap = (bitmap * 255).astype(np.uint8)
      # convert single channel to RGB by repeating
      bitmap = np.tile(bitmap[..., np.newaxis], (1, 1, 3))
      texture[
          offset[1] : offset[1] + size[1],
          offset[0] : offset[0] + size[0],
          :,
      ] = bitmap
  
imports: from __future__ import division
  import numpy
  from copy import deepcopy
  import sys
  from ._sdf_gpu import SDFRendererGPU
  from ._sdf_cpu import _calc_distance_field
  from ...gloo import TextureAtlas, IndexBuffer, VertexBuffer
  from ...gloo import context
  from ...gloo.wrappers import _check_valid
  from ...util.fonts import _load_glyph
  from ..transforms import STTransform
  from ...color import ColorArray
  from ..visual import Visual
  from ...io import load_spatial_filters
label_desc: Use image node_id 1 for calling the SDFRendererCPU obj's underlying member method code with example usage: obj.render_to_texture(data, texture, offset, size) without return types