I have a csv file with the columns ‘label’, ‘start’ and ‘end’. Where ‘start’ and ‘end’ are coordinates for a line. How can I in Python from this csv file create markups lines which corresponds to the ‘start’ and ‘end’ values and display them in Slicer. Furthermore, how can I change the color of each line?
Thank you, I have solved this now. A new problem has arised, The csv file that I have is large with over 10000 rows (which should result in 10000 lines), I used the function “AddControlPointWorld” in order to make a markups line, however with this large amount of data the script gets really slow, is there any other faster way to create markups lines from a large csv file?
If you need to add more than a few dozens of points then do all that in a batch using StartModify/EndModify. If you show thousands of points then you may also consider disabling interactive picking and label display.
These are all demonstrated in this test:
However, if you don’t need labels and interaction then markups is not the right way to render the points. Instead, you can show them as glyphs in a model node. You can create a 3D model using a few lines of Python code (add your points into points of a polydata and turn the points into glyphs using vtkGlyph3D) - probably ChatGPT can write the code for you but if you get stuck then let us know.
Reading and writing point coordinates in a text file is also very slow. You can read/write the file about 100x faster if you write into a binary format (e.g., PLY or VTK). It is sufficient to write out just the points, Slicer will read it as a VTK polydata, and you can easily apply the glyph filter in Slicer.
I have managed to display a smaller amount of points (about 100) with both of the methods you have given me. But I still have the same problem.
Maybe I need to formulate my question a bit more detailed. I want to divide these 10000 points into groups of two, this since I want these groups to be displayed with different colors, so for example if I should do it with the first methods you presented to me, then I would assume that “numberOfNodes” would be 5000 and “numberOfControlPoints” would be 2, and then I could change the color of each node. The problem then is that it takes a really long time to execute the script and to create these nodes (the same would happen if i would make 5000 glyphs).
So my question now is if it is possible to display these data points and be able to individually change properties of each point (or in groups of two), so that at the end i will display these points with different colors?
Thank you, I managed to reduce the number of markup nodes to about 50 so everything worked fine.
Furthermore, I have a csv file which represents a vascular tree where each row in the file is a branch, which has an id and start and end coordinates for that branch. I wish to display this tree in the viewer. The tree consists of about 2000 branches. What is the best way to display this tree? I tried creating markup lines, however it seems that 3Dslicer has a hard time creating 2000 different markups lines. (Note, it is important to represent the branches as lines and not just nodes).