Skip to content

Conversation

@peterhollender
Copy link
Contributor

@peterhollender peterhollender commented Apr 24, 2025

Closes #290
Closes #299

This PR refactors the way SegmentationMethods work and adds a concrete example for transducer tracking in db_dvc. As in #299 , the updated data includes:

an MRI

These can be found in:

db_dvc/subjects/soren/volumes/MRI/MRI.json
db_dvc/subjects/soren/volumes/MRI/MRI_volume.nii

a transducer complete with a registration surface mesh

These can be found in:

db_dvc/transducers/openlifu_2x400/openlifu_2x400.body.stl
db_dvc/transducers/openlifu_2x400/openlifu_2x400.json
db_dvc/transducers/openlifu_2x400/openlifu_2x400.surf.stl

a photoscan and/or photocollection of the same subject who is in the MRI, wearing the same transducer whose registration surface mesh is included in the session

The corresponding photoscans and photocollections were added, and you can see the full list of references/ids in the following files:

db_dvc/subjects/soren/sessions/test session/photoscans/photoscans.json
db_dvc/subjects/soren/sessions/test session/photocollections/photocollections.json

Before merging

  • Do a merge commit of the db_dvc from main and this branch.

Copy link
Contributor

@arhowe00 arhowe00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! I made some changes to simplify the base class and added type annotations, which have been incredibly helpful. I also added tests for Material and additional tests for SegmentationMethod.

I didn't make changes on more substantive questions I had, so I left those as comments.

When you look at these, I'll see if there are any more tests I can add so this integrates with the app

Copy link
Contributor

@arhowe00 arhowe00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional question I noticed when testing things out.

arhowe00 added a commit to OpenwaterHealth/SlicerOpenLIFU that referenced this pull request May 5, 2025
This commit is a wip based on the outcome of Peter's comments regarding
the inheritance. If the 3 layer inheritance is preferred, then you will
have to subclass this.

OpenwaterHealth/OpenLIFU-python#289 (review)
arhowe00 added a commit to OpenwaterHealth/SlicerOpenLIFU that referenced this pull request May 9, 2025
This commit subclasses the `SegmentationMethod` configurer to account
for the unique inheritance structure of `SegmentationMethods`. In brief,
there are three levels of inheritance, but the last two levels are
supposed to be alternative selections. Between the alternative
selections, two of them (`UniformWater` and `UniformTissue`) are
supposed to be the same as `UniformSegmentation` except that
`ref_material` is set as water/tissue and is not intended to be mutable.
The subclassing of the definition form takes all these details into
account.

[See the discussion on GitHub
here.](OpenwaterHealth/OpenLIFU-python#289 (comment))
peterhollender and others added 10 commits May 9, 2025 23:39
This class was redundant and the functionality was ill-defined. Doing a
`git grep` on SlicerOpenLIFU cf446f8aa9793fbb64d1431a5b991d5740fc503e
and HEAD revealed no other uses of `get_materials`.
- Simplify and explicitly ignore pyright errors in seg_method tests
  meant to protect against accidental call errors and misuse.
…t` (#290)

Removes string-based shortcuts to ensure type safety. Adds recursive
construction of Material instances for clean, nested deserialization.
Consolidated `to_dict` implementation by moving it to the top of the
class and simplifying the logic using `__dict__.copy()` with a recursive
override for `materials`.
- Also remove comment
@arhowe00 arhowe00 force-pushed the p/segmethod_cleanup branch from fd8993a to 21d2ba8 Compare May 10, 2025 03:46
peterhollender and others added 5 commits May 9, 2025 23:47
Note: `to_dict` should not discard `ref_material` because it is an
attribute of the class. However, `from_dict` needs to be overridden to
instead account for the overridden constructor which does not use
`ref_material` in the construction of the derived objects
`UniformTissue` and `UniformWater`.
- Also update associated JSON files to include the `ref_material` for
  all `SegmentationMethod`s, even if it is not intended to change.
This commit updates db_dvc by running the script
scripts/standardize_database.py and adding back `ref_material` for
`UniformWater` and `UniformTissue`. Furthermore, the following non-jpg
files were removed from the photocollections/ in db_dvc, as
photocollections should not contain files of the following kind:

```sh
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_2/texture_1001.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_2/texture_1002.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_2/texturedMesh.mtl
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_2/texturedMesh.obj
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_3/texture_1001.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_3/texture_1002.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_3/texturedMesh.mtl
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_3/texturedMesh.obj
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_4/texture_1001.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_4/texture_1002.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_4/texturedMesh.mtl
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_4/texturedMesh.obj
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_5/texture_1001.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_5/texture_1002.exr
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_5/texturedMesh.mtl
db_dvc/subjects/soren/sessions/test session/photocollections/Soren_repeat_5/texturedMesh.obj
```
@arhowe00 arhowe00 force-pushed the p/segmethod_cleanup branch from 21d2ba8 to 89f6a64 Compare May 10, 2025 03:47
@arhowe00 arhowe00 self-requested a review May 10, 2025 03:47
Copy link
Contributor

@arhowe00 arhowe00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I did test this branch in the extension, and the previous issues with using segmentation methods went away.

@arhowe00 arhowe00 merged commit 0e09d41 into main May 10, 2025
9 checks passed
arhowe00 added a commit to OpenwaterHealth/SlicerOpenLIFU that referenced this pull request May 10, 2025
This commit subclasses the `SegmentationMethod` configurer to account
for the unique inheritance structure of `SegmentationMethods`. In brief,
there are three levels of inheritance, but the last two levels are
supposed to be alternative selections. Between the alternative
selections, two of them (`UniformWater` and `UniformTissue`) are
supposed to be the same as `UniformSegmentation` except that
`ref_material` is set as water/tissue and is not intended to be mutable.
The subclassing of the definition form takes all these details into
account.

[See the discussion on GitHub
here.](OpenwaterHealth/OpenLIFU-python#289 (comment))
ebrahimebrahim pushed a commit to OpenwaterHealth/SlicerOpenLIFU that referenced this pull request May 14, 2025
This commit subclasses the `SegmentationMethod` configurer to account
for the unique inheritance structure of `SegmentationMethods`. In brief,
there are three levels of inheritance, but the last two levels are
supposed to be alternative selections. Between the alternative
selections, two of them (`UniformWater` and `UniformTissue`) are
supposed to be the same as `UniformSegmentation` except that
`ref_material` is set as water/tissue and is not intended to be mutable.
The subclassing of the definition form takes all these details into
account.

[See the discussion on GitHub
here.](OpenwaterHealth/OpenLIFU-python#289 (comment))
ebrahimebrahim pushed a commit to OpenwaterHealth/SlicerOpenLIFU that referenced this pull request May 14, 2025
This commit subclasses the `SegmentationMethod` configurer to account
for the unique inheritance structure of `SegmentationMethods`. In brief,
there are three levels of inheritance, but the last two levels are
supposed to be alternative selections. Between the alternative
selections, two of them (`UniformWater` and `UniformTissue`) are
supposed to be the same as `UniformSegmentation` except that
`ref_material` is set as water/tissue and is not intended to be mutable.
The subclassing of the definition form takes all these details into
account.

[See the discussion on GitHub
here.](OpenwaterHealth/OpenLIFU-python#289 (comment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a complete example for transducer tracking Ensure SegmentationMethod Is a proper abstract base class

3 participants