|
213 | 213 | "source": [
|
214 | 214 | "#| export\n",
|
215 | 215 | "import pyvista\n",
|
| 216 | + "import vtk\n", |
216 | 217 | "\n",
|
217 |
| - "from diffdrr.drr import DRR" |
| 218 | + "from diffdrr.drr import DRR\n", |
| 219 | + "\n", |
| 220 | + "vtk.vtkLogger.SetStderrVerbosity(vtk.vtkLogger.ConvertToVerbosity(-1))" |
218 | 221 | ]
|
219 | 222 | },
|
220 | 223 | {
|
|
257 | 260 | " method=\"marching_cubes\",\n",
|
258 | 261 | " progress_bar=verbose,\n",
|
259 | 262 | " )\n",
|
260 |
| - " \n", |
| 263 | + "\n", |
261 | 264 | " # Process the mesh\n",
|
262 | 265 | " mesh.extract_largest(inplace=True, progress_bar=verbose)\n",
|
263 | 266 | " mesh.point_data.clear()\n",
|
|
275 | 278 | " mesh.decimate_pro(0.25, inplace=True, progress_bar=verbose)\n",
|
276 | 279 | " mesh.fill_holes(100, inplace=True, progress_bar=verbose)\n",
|
277 | 280 | " mesh.clean(inplace=True, progress_bar=verbose)\n",
|
278 |
| - " \n", |
| 281 | + "\n", |
279 | 282 | " elif method == \"surface_nets\":\n",
|
280 |
| - " grid.point_data[\"values\"] = drr.volume.cpu().numpy().flatten(order=\"F\") > threshold\n", |
| 283 | + " grid.point_data[\"values\"] = (\n", |
| 284 | + " drr.volume.cpu().numpy().flatten(order=\"F\") > threshold\n", |
| 285 | + " )\n", |
281 | 286 | " try:\n",
|
282 | 287 | " mesh = grid.contour_labeled(smoothing=True, progress_bar=verbose)\n",
|
283 | 288 | " except AttributeError as e:\n",
|
284 |
| - " raise AttributeError(f\"{e}, ensure you are using pyvista>=0.43 and vtk>=9.3\")\n", |
| 289 | + " raise AttributeError(\n", |
| 290 | + " f\"{e}, ensure you are using pyvista>=0.43 and vtk>=9.3\"\n", |
| 291 | + " )\n", |
285 | 292 | " mesh.clear_cell_data()\n",
|
286 | 293 | "\n",
|
287 | 294 | " else:\n",
|
288 |
| - " raise ValueError(f\"method must be `marching_cubes` or `surface_nets`, not {method}\")\n", |
289 |
| - " \n", |
| 295 | + " raise ValueError(\n", |
| 296 | + " f\"method must be `marching_cubes` or `surface_nets`, not {method}\"\n", |
| 297 | + " )\n", |
| 298 | + "\n", |
290 | 299 | " return mesh"
|
291 | 300 | ]
|
292 | 301 | },
|
|
298 | 307 | "outputs": [],
|
299 | 308 | "source": [
|
300 | 309 | "#| export\n",
|
301 |
| - "def img_to_mesh(drr: DRR, rotations, translations, parameterization, convention=None, **kwargs):\n", |
| 310 | + "def img_to_mesh(\n", |
| 311 | + " drr: DRR, rotations, translations, parameterization, convention=None, **kwargs\n", |
| 312 | + "):\n", |
302 | 313 | " \"\"\"\n",
|
303 | 314 | " For a given pose (not batched), turn the camera and detector into a mesh.\n",
|
304 | 315 | " Additionally, render the DRR for the pose. Convert into a texture that\n",
|
|
0 commit comments