Example #1
0
    def loadFiducialsXml(self, volumeNode, fileName):
        """ Load from disk a list of fiducials for a particular volume node
        :param volumeNode: Volume (scalar node)
        :param fileName: full path of the file to load the fiducials where
        """
        with open(fileName, "r") as f:
            xml = f.read()

        self.currentGeometryTopologyData = gtd.GeometryTopologyData.from_xml(
            xml)
        for point in self.currentGeometryTopologyData.points:
            # Activate the current fiducials list based on the type list
            typesList = self.getTypesListFromXmlPoint(point)
            fidListNode = self.setActiveFiducialsListNode(
                volumeNode, typesList)
            # Check if the coordinate system is RAS (and make the corresponding transform otherwise)
            if self.currentGeometryTopologyData.coordinate_system == self.currentGeometryTopologyData.LPS:
                coord = Util.lps_to_ras(point.coordinate)
            elif self.currentGeometryTopologyData.coordinate_system == self.currentGeometryTopologyData.IJK:
                coord = Util.ijk_to_ras(volumeNode, point.coordinate)
            else:
                # Try default mode (RAS)
                coord = point.coordinate
            # Add the fiducial
            fidListNode.AddFiducial(coord[0], coord[1], coord[2],
                                    self.getMarkupLabel(typesList))
Example #2
0
    def loadFiducialsXml(self, volumeNode, fileName):
        """ Load from disk a list of fiducials for a particular volume node
        :param volumeNode: Volume (scalar node)
        :param fileName: full path of the file to load the fiducials where
        """
        with open(fileName, "r") as f:
            xml = f.read()

        self.currentGeometryTopologyData = GTD.GeometryTopologyData.from_xml(
            xml)
        for point in self.currentGeometryTopologyData.points:
            subtype = point.chest_type
            if subtype in self.params.mainTypes.keys():
                # Main type. The subtype will be "Any"
                mainType = subtype
                subtype = 0
            else:
                mainType = self.params.getMainTypeForSubtype(subtype)
            # Activate the current fiducials list based on the main type
            fidListNode = self.setActiveFiducialsListNode(
                volumeNode, mainType, subtype, point.feature_type)
            # Check if the coordinate system is RAS (and make the corresponding transform otherwise)
            if self.currentGeometryTopologyData.coordinate_system == self.currentGeometryTopologyData.LPS:
                coord = Util.lps_to_ras(point.coordinate)
            elif self.currentGeometryTopologyData.coordinate_system == self.currentGeometryTopologyData.IJK:
                coord = Util.ijk_to_ras(volumeNode, point.coordinate)
            else:
                # Try default mode (RAS)
                coord = point.coordinate
            # Add the fiducial
            fidListNode.AddFiducial(
                coord[0], coord[1], coord[2],
                self.getMarkupLabel(mainType, subtype, point.feature_type))
    def loadFiducials(self, volumeNode, fileName):
        """ Load from disk a list of fiducials for a particular volume node
        :param volumeNode: Volume (scalar node)
        :param fileName: full path of the file to load the fiducials where
        """
        with open(fileName, "r") as f:
            xml = f.read()

        geom = GTD.GeometryTopologyData.from_xml(xml)
        for point in geom.points:
            subtype = point.chest_type
            if subtype in self.params.mainTypes.keys():
                # Main type. The subtype will be "Any"
                mainType = subtype
                subtype = 0
            else:
                mainType = self.params.getMainTypeForSubtype(subtype)
            # Activate the current fiducials list based on the main type
            fidList = self.setActiveFiducialsListNode(volumeNode, mainType, subtype, point.feature_type)
            # Check if the coordinate system is RAS (and make the corresponding transform otherwise)
            if geom.coordinate_system == geom.LPS:
                coord = Util.lps_to_ras(point.coordinate)
            elif geom.coordinate_system == geom.IJK:
                coord = Util.ijk_to_ras(volumeNode, point.coordinate)
            else:
                # Try default mode (RAS)
                coord = point.coordinate
            # Add the fiducial
            fidList.AddFiducial(coord[0], coord[1], coord[2], self.getMarkupLabel(mainType, subtype, point.feature_type))
Example #4
0
wrong_points = []
wrong_cases = set()
for file_name in xmls:
    if Util.get_file_extension(file_name) != ".xml":
        continue
    # Open volume
    volFile = "{0}/{1}.nhdr".format(vols_dir, file_name.replace("_parenchymaTraining.xml", ""))
    v = slicer.util.loadVolume(volFile, returnNode=True)[1]
    # print(volFile)
    dims = v.GetImageData().GetDimensions()
    p = path.join(xmls_dir, file_name)
    with open(p, "r+b") as f:
        xml = f.read()
        geom = gtd.GeometryTopologyData.from_xml(xml)
        for point in geom.points:
            ras = Util.lps_to_ras(point.coordinate)
            ijk = Util.ras_to_ijk(v, ras)
            for i in range(3):
                if ijk[i] < 0 or ijk[i] >= dims[i]:
                    # Flip just the second coord
                    # point.coordinate[1] = -point.coordinate[1]
                    wrong_points.append((file_name, point.coordinate, ijk))
                    wrong_cases.add(file_name)
        # if file_name in wrong_cases:
        #     print("Added " + file_name)
                # ras = point.coordinate
                # point.coordinate = Util.ras_to_lps(ras)

## Change sign
# for case in wrong_cases:
#     p = path.join(xmls_dir, case)
Example #5
0
wrong_points = []
wrong_cases = set()
for file_name in xmls:
    if Util.get_file_extension(file_name) != ".xml":
        continue
    # Open volume
    volFile = "{0}/{1}.nhdr".format(vols_dir, file_name.replace("_parenchymaTraining.xml", ""))
    v = slicer.util.loadVolume(volFile, returnNode=True)[1]
    # print(volFile)
    dims = v.GetImageData().GetDimensions()
    p = path.join(xmls_dir, file_name)
    with open(p, "r+b") as f:
        xml = f.read()
        geom = gtd.GeometryTopologyData.from_xml(xml)
        for point in geom.points:
            ras = Util.lps_to_ras(point.coordinate)
            ijk = Util.ras_to_ijk(v, ras)
            for i in range(3):
                if ijk[i] < 0 or ijk[i] >= dims[i]:
                    # Flip just the second coord
                    # point.coordinate[1] = -point.coordinate[1]
                    wrong_points.append((file_name, point.coordinate, ijk))
                    wrong_cases.add(file_name)
        # if file_name in wrong_cases:
        #     print("Added " + file_name)
                # ras = point.coordinate
                # point.coordinate = Util.ras_to_lps(ras)

## Change sign
# for case in wrong_cases:
#     p = path.join(xmls_dir, case)