Hi all.
We automatizated the cross section analysis computation for our own centerlines.
The program runs like this:
def obtainDataFromGeometry(segmentationNode, segmentID, branchID, G, centerlinesDict, tableNode,
fileToSaveResults, createFile):
"""
Runs CrossSectionAnalysis and genrates a file with
- Centerline ID
- Centerline branch ID
- Node ID
- Distance
- Diameter
- Area
- Curvature
- RAS coordinates
:segmentationNode: segmentation node where the geometry is
:segmentID: the segment name we want to operate with
:branchID: indicates the coronary branch ('left' or 'right')
:centerlinesDict: a dictionary with key "centerline name" and value list of
nodeIDs of the centerline
:tableNode: 'vtkMRMLTableNode' to save auxiliary results
:fileToSaveResults: path to file where to save results
:createFile: if True, generates a new file to save resutls. If False, appends results to file
:return: creates a file in fileToSaveResults with the metadata
"""
logic = CrossSectionAnalysis.CrossSectionAnalysisLogic()
segmentNodeID = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentID)
# Set lumen surface
logic.setLumenSurface(segmentationNode, segmentNodeID)
# Set table node
logic.setOutputTableNode(tableNode)
# To obtain RAS coordinates in different cols
logic.coordinateSystemColumnSingle = False
# Set centerline node
centerlineNames = list(centerlinesDict.keys()) # utils.getCurveNames(centerlinesPrefix)
if(createFile): # We create a new file
with open(fileToSaveResults, "w") as file:
file.write("CenterlineID,branchID,nodeID,Distance,Diameter(CE),Cross-sectionArea,Curvature,R,A,S\n")
for centerlineID in centerlineNames:
print("Extracting metadata info from " + str(centerlineID) + "...")
# Find nodes
# numberOfValues = tableNode.GetTable().GetColumn(0).GetNumberOfValues()
numberOfValues = len(centerlinesDict[centerlineID])
# If the curve has less than 3 points, cross section analysis crashes
doCrossSection = False
if(numberOfValues > 2):
doCrossSection = True
if (doCrossSection):
# avoids interpolating points
slicer.util.getNode(centerlineID).SetNumberOfPointsPerInterpolatingSegment(1)
logic.setInputCenterlineNode(slicer.util.getNode(centerlineID))
# Run CrossSectionAnalysis
logic.run()
The issue we see few times is the following one:
-
If the scene is created and saved and we use this routine in a new Slicer window where we open the saved scene, the function sometimes freezes extracting radius and other parameters. The function blocks the interface:
-
This problem is not seemed yet when we run the the function in the same Slicer window, but we do not rule out the possibility of happen here too.
Thanks a lot for the help .