code: def test_threshold_stopping_criterion(rng):
      """This tests that the threshold stopping criterion returns expected
      streamline statuses.
      """
  
      tissue_map = rng.random((4, 4, 4))
  
      ttc = ThresholdStoppingCriterion(
          tissue_map.astype("float32"), 0.5
      )
  
      # Test voxel center
      for ind in ndindex(tissue_map.shape):
          pts = np.array(ind, dtype="float64")
          state = ttc.check_point(pts)
          if tissue_map[ind] > 0.5:
              npt.assert_equal(state, int(StreamlineStatus.TRACKPOINT))
          else:
              npt.assert_equal(state, int(StreamlineStatus.ENDPOINT))
  
      # Test random points in voxel
      inds = [
          [0, 1.4, 2.2],
          [0, 2.3, 2.3],
          [0, 2.2, 1.3],
          [0, 0.9, 2.2],
          [0, 2.8, 1.1],
          [0, 1.1, 3.3],
          [0, 2.1, 1.9],
          [0, 3.1, 3.1],
          [0, 0.1, 0.1],
          [0, 0.9, 0.5],
          [0, 0.9, 0.5],
          [0, 2.9, 0.1],
      ]
      for pts in inds:
          pts = np.array(pts, dtype="float64")
          state = ttc.check_point(pts)
          res = scipy.ndimage.map_coordinates(
              tissue_map,
              np.reshape(pts, (3, 1)),
              order=1,
              mode="nearest",
          )
          if res > 0.5:
              npt.assert_equal(state, int(StreamlineStatus.TRACKPOINT))
          else:
              npt.assert_equal(state, int(StreamlineStatus.ENDPOINT))
  
      # Test outside points
      outside_pts = [
          [100, 100, 100],
          [0, -1, 1],
          [0, 10, 2],
          [0, 0.5, -0.51],
          [0, -0.51, 0.1],
      ]
      for pts in outside_pts:
          pts = np.array(pts, dtype="float64")
          state = ttc.check_point(pts)
          npt.assert_equal(state, int(StreamlineStatus.OUTSIDEIMAGE))
  
file_path: dipy/dipy/tracking/tests/test_stopping_criterion.py
imports: import numpy
  import numpy.testing
  import scipy.ndimage
  from dipy.core.ndindex import ndindex
  from dipy.tracking.stopping_criterion import ActStoppingCriterion, BinaryStoppingCriterion, CmcStoppingCriterion, ThresholdStoppingCriterion, StreamlineStatus
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 2 for calling a global function with example usage: test_threshold_stopping_criterion(rng) without return types