Page 1 of 2
Structure of .ctgr files
Posted: Thu Oct 24, 2019 6:56 am
by lucapegolotti
Hello,
I would like to use the files generated by SimVascular's segmentation feature in a project that I am developing, but I am struggling to understand the structure of the .ctgr format.
The files that I have been able to generate by following
https://simvascular.github.io/docsModelGuide.html or
https://www.youtube.com/watch?v=mNclY0T4ek8 are intelligible to me. They have the following xml structure:
Code: Select all
<contourgroup ..>
<timestep ..>
<lofting_parameters ..>
<contour ..>
list of control and contour points
</contour>
<contour ..>
list of control and contour points
</contour>
</lofting_parameters>
</timestep>
</contourgroup>
The segmentation data in the tutorial (
https://simvascular.github.io/docsQuickGuide.html), instead, is structured as follows:
Code: Select all
<path ..>
<timestep ..>
<path_element ..>
<control_points>
...
</control_points>
<path_points>
...
</path_points>
</path_element>
</timestep>
</path>
My questions are: 1) which method has been used to generate the sample .ctgr in the tutorial? 2) it seems that the contours are not split into different xml entries in that case, but I am curious to know how SimVascular manages to correctly render them. In other words, how can one retrieve the contours from the second version of the .ctgr?
Best,
Luca
Re: Structure of .ctgr files
Posted: Thu Oct 24, 2019 7:48 pm
by davep
Hi Luca,
The
.ctgr file contains data defining the set of curves (contours) used to segment a region of an image plane. If you look in the
Segmentations/aorta.ctgr file for the Demo Project example you will see elements labeled
<contour id="0" to
<contour id="39" that define the data for each the 40 contours created for the
aorta segmentation. The
<contour_points> element under each
<contour id> element contains the 3D coordinates for the contour.
The
.pth file contains data for the path that defines the center of a region of an image plane. If you look in the
Paths/aorta.pth file for the Demo Project you will see a single
<path_element id="0" element. The
<path_points> element contain the 3D coordinates of the curve fit through the path control points under the
<control_points> element.
I have written a couple of Python scripts that read in and display SV segmentation .
ctgr files (
https://github.com/ktbolt/cardiovascula ... ontours.py) and SV path .
pth files (
https://github.com/ktbolt/cardiovascula ... v-paths.py). Have a look at them to see how to read data from the SV XML files.
Cheers,
Dave
Re: Structure of .ctgr files
Posted: Thu Oct 24, 2019 11:30 pm
by lucapegolotti
Hi Dave,
Thank you so much for your reply. As I think you noticed, I have by accident interpreted the .pth file as a .ctgr.
Anyways, the scripts you sent me will be of great help.
Thanks!
Luca
Re: Structure of .ctgr files
Posted: Wed Apr 29, 2020 5:04 am
by rudolf.hellmuth
Hi David,
I am trying to use these pieces of code to make a python script that inflates/shrinks the contours along the path. This is for artificially applying aneurysms and stenoses. As inputs I give a path.pth, a contour_group.ctgr, and a table of 'position along path' and 'cross-sectional area' (or 'approximate diameter' or 'relative thicken ratio'); and as output I would get a new_contour_group.ctrg. I want to scale the contours on the respective cross-sectional planes.
I have a question regarding the control_points though: Do I have to care about them when I do my up and down scaling? The number of control_points change according to the contour.type. I suppose these are the handling points for the contour segments on the GUI. Will I crash the GUI, if I don't a position these points correctly? If that's the case, could you please give me hints of how I should do that?
Thanks,
Rudolf
Re: Structure of .ctgr files
Posted: Wed Apr 29, 2020 11:40 am
by davep
Hi Rudolf,
The contour control points are used to parameterize the contours. For a circle contour they are the circle center and a point on the circle. For the other contour types they are used to scale the contour, it is not clear to me (yet) how this is done.
So you will need to scale both the control points and contour points. If you don't scale the control points then SV will not be able to create a lofted surface from the contours.
Cheers,
Dave
Re: Structure of .ctgr files
Posted: Fri May 01, 2020 8:40 am
by rudolf.hellmuth
Thanks for the hint, Dave. This is gonna be more difficult, since I must modify both control_points and contour_points. Could you please point me out in the source code, where one information generates the other? I suppose, I also have to care about the truncation of the last digit of the float numbers printed on the .ctgr file, haven't I?
I have just been able to clone the contourgroup, scale the new one, and save the .ctgr file. I haven't scaled the control_points yet. I will do the cross-section scaling after I can be sure that I can load this onto SimVascular, and it lofts without crashing.
Cheers,
Rudolf
Re: Structure of .ctgr files
Posted: Fri May 01, 2020 10:07 am
by davep
Hi Rudolf,
It seems that the relationship between control points and contour points is different depending on the contour type (circle, level set, etc.). Let me do some tests, have a look in the source code, and I'll get back to you.
Cheers,
Dave
Re: Structure of .ctgr files
Posted: Fri May 01, 2020 3:51 pm
by davep
Hi Rudolf,
I did some tests modifying the contour files and here's what I found
Code: Select all
The first control point is the contour center.
- Circle
+ have two control points
+ control points are determined by the contour points
- Level Set
+ have two control points
+ control points are determined by the contour points
+ to scale contour need to just scale contour points
- Polygon
+ have N control points
+ control points are not determined by the contour points
+ when displaying the first two control points seem to be computed from the contour points
+ to scale contour need to scale control and contour points
- Spline
+ have N control points
+ control points are not determined by the contour points
+ when displaying the first two control points seem to be computed from the contour points
+ to scale contour need to scale control and contour points
- don't need to scale the first two control points
- Threshold
+ have two control points
+ control points are determined by the contour points
+ to scale contour need to just scale contour points
I've written a Python script to test these ideas, to scale contours and write a new .ctgr file. I can read in the scaled contour file into SV with no problems. Have a look here
https://github.com/ktbolt/cardiovascula ... tgr/python.
Cheers,
Dave
Re: Structure of .ctgr files
Posted: Tue May 05, 2020 4:13 am
by rudolf.hellmuth
Hi Dave,
Thanks a million for your help. I wasn't expecting you writing more code, that was very kind of you. I was writing it a bit different, more object-oriented. You can see my draft attached, if you wish. I tested the output on SimVascular, and it worked fine.
I've got now another question, how would you do to change contour types? I would like to change some of them to ellipses, but it would be cool to transform them them back and forth into different types, like it is possible on SimVascular.
My ultimate goal is to apply (map) the vessel diameters obtained from x-ray projections (angiograms) onto the 3-D reconstruction obtained from CT image. CT show artefacts near metallic parts (e.g., stents), but angiograms don't. I want to heal the 3-D reconstruction with the angiogram data, by cure-fitting elliptical contours, or splinePoly contours with elliptical shape.
Thanks,
Rudolf
Re: Structure of .ctgr files
Posted: Tue May 05, 2020 10:36 am
by davep
Hi Rudolf,
I coded this to make sure I understood how it works and to have an example that other users might find useful. At some point I will create a SimVascular repository of useful Python and C++ programs. Perhaps I can include your most excellent code when you are finished?
Changing the contour type between a circle and ellipse should not be too difficult. The control points for a circle are its center and a boundary point, for an ellipse they are its center and two points on its boundary (major and minor axes).
The circle/ellipse
contour_points are generated using a local (
u,
v) coordinate system defined by the contour
path_point
Code: Select all
<path_point id="0">
<pos x="-2.24526097931416" y="-2.03248293794249" z="13.538274999999999" />
<tangent x="0.460083289910039" y="0.400117476272235" z="-0.792609217412397" /> # tangent to path
<rotation x="0" y="0.892702844860054" z="0.450645793033471" /> # normal to path
</path_point>
where
u = rotation and
v = rotation x tangent. You can then generate the
contour_points data from this. SV creates the contour points for a circle using the
CreateContourPoints() method in
SimVascular/Code/Source/sv3/Segmentation/sv3_CircleContour.cxx.
I am in the process of implementing an SV Python API that will make manipulating SV data much easier. I think I will complete this in a month or so. Stay tuned!
Cheers,
Dave