| 85 | |
| 86 | |
| 87 | class CartesianQuantizer(Quantizer): |
| 88 | def __init__(self, image_meta_path: str, quant_step: List[float]): |
| 89 | self.quant_step = torch.tensor(quant_step, dtype=torch.float) |
| 90 | |
| 91 | def __call__(self, pc): |
| 92 | # Converts to polar coordinates and quantizes with different step size for each coordinate |
| 93 | # pc: (N, 3) point cloud with Cartesian coordinates (X, Y, Z) |
| 94 | pc = pc[...,:3] |
| 95 | quantized_pc = pc / self.quant_step |
| 96 | |
| 97 | # quantized_pc, ndx = ME.utils.sparse_quantize(pc, quantization_size=self.quant_step, return_index=True) |
| 98 | # Return quantized coordinates and index of selected elements |
| 99 | return quantized_pc |
| 100 | |
| 101 | def dequantize(self, coords): |
| 102 | # Dequantize coords and return as (N, 3) tensor of floats |
| 103 | # Use coords of the voxel center |
| 104 | pc = coords * self.quant_step |
| 105 | return pc |
| 106 | |
| 107 | |
| 108 | if __name__ == "__main__": |