Thankyou for the respons!
For the normalvectors I ended up using this script to just calculate the normals i needed from point to point manually. Ignore the variable referencepoints that is for something specific in my case. This creates a csv. file with the points and normals.
import slicer
import csv
import qt
import numpy as np
refpoints_name = qt.QInputDialog.getText(None, "String Input", "Enter name of referencepoints:")
centerline_name = qt.QInputDialog.getText(None, "String Input", "Enter name of centerline:")
curveNode = slicer.util.getNode(centerline_name)
curveNode.GetMeasurement("curvature mean").SetEnabled(True)
#normals = slicer.util.arrayFromMarkupsCurveData(curveNode, "Tangents", True)
#positions = slicer.util.arrayFromMarkupsCurvePoints(curveNode, True)
positions = slicer.util.arrayFromMarkupsControlPoints(curveNode)
normals = []
for i in range(len(positions)-1):
normal = positions[i+1] - positions[i]
normal = normal / np.linalg.norm(normal)
normals.append(normal)
ref_points = slicer.util.getNode(refpoints_name)
ref_points_only = slicer.util.arrayFromMarkupsControlPoints(ref_points)
directory_dialog = qt.QFileDialog()
directory_dialog.setFileMode(qt.QFileDialog.Directory)
directory_dialog.setWindowTitle("Select folder to save the csv file")
directory_dialog.exec_()
selected_directory = directory_dialog.selectedFiles()[0]
print("Selected directory:", selected_directory)
file_name = qt.QInputDialog.getText(None, "File Name Input", "Enter a file name:")
file_path = selected_directory + "/" + file_name + ".csv"
print("Selected file path:", file_path)
with open(file_path, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['X', 'Y', 'Z'])
for pos in ref_points_only:
writer.writerow([pos[0], pos[1], pos[2]])
writer.writerow(['X', 'Y', 'Z', 'Normal_X', 'Normal_Y', 'Normal_Z'])
for i in range(len(positions)-1):
writer.writerow([positions[i][0], positions[i][1], positions[i][2], normals[i][0], normals[i][1], normals[i][2]])
print("Data saved to:", file_path)
For the plotting i was using matplotlib, but have also good succes with open3d, but it is not applicable with newer versions of python.
import matplotlib.pyplot as plt
# Create a 3D figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot the centerline points
ax.scatter(centerline_points[:, 0], centerline_points[:, 1], centerline_points[:, 2])
# Plot the normal vectors
ax.quiver(centerline_points[:, 0], centerline_points[:, 1], centerline_points[:, 2],
centerline_points[:, 3], centerline_points[:, 4], centerline_points[:, 5],
length=0.1, normalize=True, color='r')
ax.set_box_aspect([np.ptp(centerline_points[:, 0]), np.ptp(centerline_points[:, 1]), np.ptp(centerline_points[:, 2])])
# Set labels for the axes
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
# Show the plot
plt.show()