qurit/rt-utils

Return ROI names of geometric type

mffield opened this issue · 0 comments

Hello,
In using the package I tended to call get_roi_names() to obtain a list of structures that I would like to retrieve a mask for, then retrieved the masks with the function get_roi_mask_by_name(). However, it ran into problems when there are different geometric types in the RTSTRUCT, especially the 'POINT' geometries. Generally if all of the contours are described as 'CLOSED_PLANAR' then the process works fine. But some datasets have these POINT ROIs and it is not always clear that they are from the name. So my proposal is to have another optional argument to get_roi_names() to specify the geometries we want to return. Default behaviour is the original version of listing all names. To get all CLOSED_PLANAR structures only we would call rtstruct_ds.get_roi_names('CLOSED_PLANAR') where rtstruct_ds is the rtstruct object from this repository. Here is the modified function below in rtstruct.py.

def get_roi_names(self, geometry = 'ALL') -> List[str]:
        """
        Returns a list of the names of all ROI within the RTStruct
        Optional argument to return only ROI of specific geometric type. E.g. CLOSED_PLANAR, POINT
        """
        
        if not self.ds.StructureSetROISequence:
            return []
        
        if geometry == 'ALL':
            return [
                structure_roi.ROIName for structure_roi in self.ds.StructureSetROISequence
            ]
        
        return [
                self.ds.StructureSetROISequence[i].ROIName 
                for i in range(0,len(self.ds.ROIContourSequence)) 
                if self.ds.ROIContourSequence[i].ContourSequence[0].ContourGeometricType==geometry
            ]

Let me know if this is useful to incorporate, it certainly is for my work as I had to do this check separately outside this package.

Best wishes,
Matt