class_docstr: A regularly-spaced collection of coordinates
  
  This class provides factory methods for generating Pointsets from
  :class:`~nibabel.spatialimages.SpatialImage`\s and generating masks
  from coordinate sets.
class_docstr_tok: ["A","regularly-spaced","collection","of","coordinates","This","class","provides","factory","methods","for","generating","Pointsets","from",":","class",":","`","~nibabel.spatialimages.SpatialImage","`","\\s","and","generating","masks","from","coordinate","sets","."]
code: def to_mask(self, shape=None) -> SpatialImage:
      if shape is None:
          shape = tuple(
              np.max(self.coordinates, axis=0)[: self.dim] + 1
          )
      mask_arr = np.zeros(shape, dtype="bool")
      mask_arr[
          tuple(np.asanyarray(self.coordinates)[:, : self.dim].T)
      ] = True
      return SpatialImage(mask_arr, self.affine)
  
imports: from __future__ import annotations
  import math
  import typing
  from dataclasses import dataclass, replace
  import numpy
  from nibabel.casting import able_int_type
  from nibabel.fileslice import strided_scalar
  from nibabel.spatialimages import SpatialImage
label_desc: Use image node_id 3 for calling the Grid obj's underlying member method code with example usage: obj.to_mask(shape) and returns: SpatialImage