Provides a system for patient-specific cardiovascular modeling and simulation.
-
François de Kermenguy
- Posts: 13
- Joined: Sat Oct 02, 2021 12:08 am
Post
by François de Kermenguy » Fri Mar 22, 2024 10:00 am
Hello
,
I'm trying to use the
PythonAPI to manually create SV files.
I managed to do it for path (
path = sv.pathplanning.Path()) with the following code:
Code: Select all
path_serie = sv.pathplanning.Series()
path_serie.set_name("{}".format(roi_name))
path_serie.set_path(path, 0)
path_serie.set_path_id(1)
path_serie.write(os.path.join(output_path, "{}_path.pth".format(roi_name)))
However, I can't do it for my contour (
sv.segmentation.Contour()) because the
sv.segmentation.Series() class doesn't have equivalent methods such as
set_name, set_segmentation, set_segmentation_id ... (but it does have a write() method. In this case, how can I write my segmentation in a .ctgr file?
Thanks a lot!
fdekerm
-
David Parker
- Posts: 1705
- Joined: Tue Aug 23, 2005 2:43 pm
Post
by David Parker » Fri Mar 22, 2024 10:47 am
Hello fdekerm,
The Python API
segmentation module is not fully functional like the
pathplanning module because of certain SV implementation issues.
You will need to use
xml.etree.ElementTree to create a .ctgr file. For example
Code: Select all
import xml.etree.ElementTree as et
from xml.dom import minidom
contour_group = et.Element("contourgroup")
contour_group.set("path_name", "path")
contour_group.set("path_id", "1")
contour_group.set("reslice_size", "5")
contour_group.set("point_2D_display_size", "")
contour_group.set("point_size", "")
time_step = et.SubElement(contour_group, "timestep")
time_step.set("id", "0")
lofting_parameters = et.SubElement(time_step, "lofting_parameters")
lofting_parameters.set("method", "nurbs")
with open("contour.ctgr", "w") as file:
file.write(str(xmlstr.decode('UTF-8')))
There is also an exampled of reading in a .ctgr file and modifying it here
https://github.com/ktbolt/cardiovascula ... tgr/python.
Cheers,
Dave