def TransformFeatures(self, features):
    # We assume that the lasers are not padded, and all points are real.
    if ('points_padding' in features.lasers and
        features.lasers.points_padding is not None):
      raise ValueError('FilterNLZPoints preprocessor does not support '
                       'padded lasers.')

    # The 3rd feature in the laser is 1.0 for points in a no-label-zone
    # and -1. for normal points.
    is_not_nlz = tf.not_equal(features.lasers.points_feature[:, 2], 1.0)
    features.lasers.points_xyz = tf.boolean_mask(features.lasers.points_xyz,
                                                 is_not_nlz)
    features.lasers.points_feature = tf.boolean_mask(
        features.lasers.points_feature, is_not_nlz)
    return features
def _GetFilteredBoundingBoxData(kitti_data):
    """Given a single batch element of data, process it for writing.

  Args:
    kitti_data: A NestedMap of KITTI input generator returned data with a batch
      size of 1.

  Returns:
    A NestedMap of all the output data we need to write per bounding box
    cropped pointclouds.
  """
    points = kitti_data.lasers.points_xyz
    points_feature = kitti_data.lasers.points_feature
    bboxes_3d = kitti_data.labels.bboxes_3d
    bboxes_3d_mask = kitti_data.labels.bboxes_3d_mask
    bboxes_3d = tf.boolean_mask(bboxes_3d, bboxes_3d_mask)

    if 'points_padding' in kitti_data.lasers:
        points_validity_mask = tf.cast(kitti_data.lasers.points_padding - 1,
                                       tf.bool)
        points = tf.boolean_mask(points, points_validity_mask)
        points_feature = tf.boolean_mask(points_feature, points_validity_mask)

    points_in_bboxes_mask = geometry.IsWithinBBox3D(points, bboxes_3d)

    output_map = py_utils.NestedMap()
    # Points and features contain the whole pointcloud, which we will use
    # per box boolean masks later in _ToTFExampleProto to subselect data per box.
    output_map.points = points
    output_map.points_feature = points_feature
    output_map.points_in_bboxes_mask = points_in_bboxes_mask

    output_map.source_id = kitti_data.labels.source_id

    # Add additional data
    output_keys = [
        'bboxes_3d',
        'labels',
        'texts',
        'occlusion',
        'difficulties',
        'truncation',
    ]
    for key in output_keys:
        output_map[key] = tf.boolean_mask(kitti_data.labels[key],
                                          kitti_data.labels.bboxes_3d_mask)
    return output_map