ConstantPad3d

https://pytorch.org/docs/stable/generated/torch.nn.ConstantPad3d.html

constant_pad3d_demo.py
import svetoviz_webgpu as sv

# 1. Prepare 3D MRI volume
input_volume = torch.from_numpy(np.stack(slices)).unsqueeze(0).unsqueeze(0)

# 2. Define ConstantPad3d
# Pads 3 voxels across all dimensions with value -1.0
pad3d = nn.ConstantPad3d(padding=3, value=-1.0)

def terminal_callback(buffer, message, images, files):
    output = pad3d(input_volume)

    buffer.send_system_message(f"Input Voxel Grid: {input_volume.shape[2:]}")
    buffer.send_system_message(f"Padded Voxel Grid: {output.shape[2:]}")
    buffer.send_system_message("Volumetric constant-insertion applied (Value: -1.0)")

# 3. Start the interactive session
sv.pytorch_web(module=pad3d, terminal_callback=terminal_callback)
Volumetric Constant Shell
ConstantPad3d volumetric visualization
This operation extends the volumetric grid by adding layers of the specified constant value across all six faces. It is commonly used to standardize volume sizes before feeding them into 3D U-Nets.