Binary Operations¶
Morphological Operations¶
fdtdx.constraints.binary_transform.dilate_jax(image, kernel)
¶
Performs morphological dilation on a binary image using JAX.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Array
|
Binary input array to be dilated. |
required |
kernel
|
Array
|
Binary kernel defining the dilation shape. |
required |
Returns:
Type | Description |
---|---|
Array
|
Dilated binary array. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.erode_jax(image, kernel)
¶
Performs morphological erosion on a binary image using JAX.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Array
|
Binary input array to be eroded. |
required |
kernel
|
Array
|
Binary kernel defining the erosion shape. |
required |
Returns:
Type | Description |
---|---|
Array
|
Eroded binary array. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.seperated_3d_dilation(arr_3d, kernel_xy, kernel_yz, kernel_xz, reduction_arr)
¶
Performs separated 3D dilation along each axis plane.
Applies 2D dilation kernels separately in the XY, YZ, and XZ planes to approximate 3D dilation while being more computationally efficient. The result is masked by the reduction array after each operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr_3d
|
Array
|
3D binary array to be dilated. |
required |
kernel_xy
|
Array
|
2D kernel for XY plane dilation. |
required |
kernel_yz
|
Array
|
2D kernel for YZ plane dilation. |
required |
kernel_xz
|
Array
|
2D kernel for XZ plane dilation. |
required |
reduction_arr
|
Array
|
Binary mask to constrain dilation results. |
required |
Returns:
Type | Description |
---|---|
Array
|
Dilated 3D binary array. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.binary_median_filter(arr_3d, kernel_sizes, padding_cfg)
¶
Applies a binary median filter to a 3D array.
Implements a median filter for binary data by using convolution and thresholding. The filter is applied separately along each axis using the specified kernel sizes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr_3d
|
Array
|
3D binary input array. |
required |
kernel_sizes
|
tuple[int, int, int]
|
Tuple of (kx, ky, kz) specifying filter size in each dimension. |
required |
padding_cfg
|
PaddingConfig
|
Configuration for padding the input array. |
required |
Returns:
Type | Description |
---|---|
Array
|
Filtered binary array. |
Source code in src/fdtdx/constraints/binary_transform.py
Connectivity Analysis¶
fdtdx.constraints.binary_transform.compute_polymer_connection(matrix, connected_slice=None)
¶
Computes a mask of polymer regions connected to specified points.
Uses iterative dilation to identify polymer regions (ones in the matrix) that are connected either to the bottom layer or to specified points in connected_slice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Array
|
Binary array where 1 represents polymer and 0 represents air. |
required |
connected_slice
|
tuple[int | None, int | None, int | None] | None
|
Optional tuple of indices specifying starting points for the connection computation. If None, uses bottom layer. |
None
|
Returns:
Type | Description |
---|---|
Array
|
Boolean array marking connected polymer regions. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.compute_air_connection(matrix)
¶
Computes a mask of air regions connected to the boundaries.
Uses iterative dilation to identify air regions (zeros in the matrix) that are connected to the simulation boundaries. This is used to ensure proper ventilation in the structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Array
|
Binary array where 1 represents polymer and 0 represents air. |
required |
Returns:
Type | Description |
---|---|
Array
|
Boolean array marking air regions connected to boundaries. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.connect_slice(lower_slice, middle_slice, upper_slice, upper_save_points)
¶
Connects polymer regions between adjacent slices.
Attempts to connect disconnected polymer regions between three adjacent z-slices by modifying the middle and upper slices while preserving specified connection points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower_slice
|
Array
|
Binary array representing the lower z-slice. |
required |
middle_slice
|
Array
|
Binary array representing the middle z-slice to be optimized. |
required |
upper_slice
|
Array
|
Binary array representing the upper z-slice to be optimized. |
required |
upper_save_points
|
Array
|
Boolean mask of points in upper slice that must remain connected. |
required |
Returns:
Type | Description |
---|---|
tuple[Array, Array]
|
Tuple of (modified_middle_slice, modified_upper_slice) with connected regions. |
Source code in src/fdtdx/constraints/binary_transform.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
Structure Optimization¶
fdtdx.constraints.binary_transform.remove_floating_polymer(matrix)
¶
Removes polymer regions that are not connected to the substrate.
Uses flood-fill algorithm to identify polymer regions connected to the bottom layer and removes any floating polymer regions that are not connected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Array
|
Binary array where 1 represents polymer and 0 represents air. Shape is (x, y, z) representing the 3D grid. |
required |
Returns:
Type | Description |
---|---|
Array
|
Modified binary array with floating polymer regions removed. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.remove_polymer_non_connected_to_x_max_middle(matrix)
¶
Removes polymer regions not connected to the middle of the x-max boundary.
Uses flood-fill algorithm starting from the middle point of the x-max boundary to identify connected polymer regions and removes unconnected regions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Array
|
Binary array where 1 represents polymer and 0 represents air. Shape is (x, y, z) representing the 3D grid. |
required |
Returns:
Type | Description |
---|---|
Array
|
Modified binary array with unconnected polymer regions removed. |
Source code in src/fdtdx/constraints/binary_transform.py
fdtdx.constraints.binary_transform.connect_holes_and_structures(matrix)
¶
Connects disconnected polymer structures and air holes in the matrix.
Performs a two-pass algorithm: 1. Connects disconnected polymer structures by adding polymer material 2. Connects disconnected air regions by removing polymer material
This ensures both structural integrity and proper air ventilation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Array
|
Binary array where 1 represents polymer and 0 represents air. Shape is (x, y, z) representing the 3D grid. |
required |
Returns:
Type | Description |
---|---|
Array
|
Modified binary array with connected structures and holes. |