@@ -23,13 +23,12 @@ def get_min_max_values(image: sitk.Image) -> Tuple[float, float]:
23
23
return filter .GetMinimum (), filter .GetMaximum ()
24
24
25
25
26
- def _path (path : Union [ str , Path ] ) -> Path :
26
+ def _path (path : str | Path ) -> Path :
27
27
if isinstance (path , str ):
28
28
return Path (path )
29
- elif isinstance (path , Path ):
29
+ if isinstance (path , Path ):
30
30
return path
31
- else :
32
- raise ValueError ("Invalid path type." )
31
+ raise ValueError ("Invalid path type." )
33
32
34
33
35
34
# --== class definitions ==--
@@ -261,6 +260,13 @@ def segmentAlgorithmType(self) -> str:
261
260
def segmentAlgorithmType (self , segmentAlgorithmType : str ) -> None :
262
261
self ._data ["SegmentAlgorithmType" ] = segmentAlgorithmType
263
262
263
+ def _triplet_setter (self , key : str , value : Union [Tuple [str , str , str ], Triplet ]):
264
+ if isinstance (value , tuple ):
265
+ value = Triplet .fromTuple (value )
266
+ assert isinstance (value , Triplet )
267
+ self ._data [key ] = value .asdict ()
268
+
269
+
264
270
@property
265
271
def segmentedPropertyCategory (self ) -> Triplet :
266
272
return self ._triplet_factory ("SegmentedPropertyCategoryCodeSequence" )
@@ -269,10 +275,7 @@ def segmentedPropertyCategory(self) -> Triplet:
269
275
def segmentedPropertyCategory (
270
276
self , value : Union [Tuple [str , str , str ], Triplet ]
271
277
) -> None :
272
- if isinstance (value , tuple ):
273
- value = Triplet .fromTuple (value )
274
- assert isinstance (value , Triplet )
275
- self ._data ["SegmentedPropertyCategoryCodeSequence" ] = value .asdict ()
278
+ self ._triplet_setter ("SegmentedPropertyCategoryCodeSequence" , value )
276
279
277
280
@property
278
281
def segmentedPropertyType (self ) -> Triplet :
@@ -282,10 +285,7 @@ def segmentedPropertyType(self) -> Triplet:
282
285
def segmentedPropertyType (
283
286
self , value : Union [Tuple [str , str , str ], Triplet ]
284
287
) -> None :
285
- if isinstance (value , tuple ):
286
- value = Triplet .fromTuple (value )
287
- assert isinstance (value , Triplet )
288
- self ._data ["SegmentedPropertyTypeCodeSequence" ] = value .asdict ()
288
+ self ._triplet_setter ("SegmentedPropertyTypeCodeSequence" , value )
289
289
290
290
@property
291
291
def segmentedPropertyTypeModifier (self ) -> Triplet :
@@ -295,10 +295,7 @@ def segmentedPropertyTypeModifier(self) -> Triplet:
295
295
def segmentedPropertyTypeModifier (
296
296
self , value : Union [Tuple [str , str , str ], Triplet ]
297
297
) -> None :
298
- if isinstance (value , tuple ):
299
- value = Triplet .fromTuple (value )
300
- assert isinstance (value , Triplet )
301
- self ._data ["SegmentedPropertyTypeModifierCodeSequence" ] = value .asdict ()
298
+ self ._triplet_setter ("SegmentedPropertyTypeModifierCodeSequence" , value )
302
299
303
300
@property
304
301
def hasSegmentedPropertyTypeModifier (self ) -> bool :
@@ -310,10 +307,7 @@ def anatomicRegion(self) -> Triplet:
310
307
311
308
@anatomicRegion .setter
312
309
def anatomicRegion (self , value : Union [Tuple [str , str , str ], Triplet ]) -> None :
313
- if isinstance (value , tuple ):
314
- value = Triplet .fromTuple (value )
315
- assert isinstance (value , Triplet )
316
- self ._data ["AnatomicRegionSequence" ] = value .asdict ()
310
+ self ._triplet_setter ("AnatomicRegionSequence" , value )
317
311
318
312
@property
319
313
def hasAnatomicRegion (self ) -> bool :
@@ -327,10 +321,7 @@ def anatomicRegionModifier(self) -> Triplet:
327
321
def anatomicRegionModifier (
328
322
self , value : Union [Tuple [str , str , str ], Triplet ]
329
323
) -> None :
330
- if isinstance (value , tuple ):
331
- value = Triplet .fromTuple (value )
332
- assert isinstance (value , Triplet )
333
- self ._data ["AnatomicRegionModifierSequence" ] = value .asdict ()
324
+ self ._triplet_setter ("AnatomicRegionModifierSequence" , value )
334
325
335
326
@property
336
327
def hasAnatomicRegionModifier (self ) -> bool :
0 commit comments