I want to draw a line by connecting some scattered points which I have clicked in the view.
I can get each points RAS position, but it seems can not display the final line in Slicer, below is my code for drawing line, could someone share some guidance?
#coding----
def drawPolyLine(points):
#points is the list which contains each points pos,likes [(0.0,1.0),(1.0,2.0)],just one slice in the view.
polyLine = vtk.vtkPolyLineSource()
for i, (x, y) in enumerate(points):
polyLine.SetPoint(i, x, y, 0)
polyLine.SetNumberOfPoints(len(points))
polyLine.SetClosed(True)
polyLine.Update()
polyData = polyLine.GetOutput()
return showPolyData(polyData)
def showPolyData(polyData):
model = slicer.vtkMRMLModelNode()
if isinstance(polyData, vtk.vtkAlgorithmOutput):
model.SetPolyDataConnection(polyData)
elif isinstance(polyData, vtk.vtkPolyData):
# print("type and polyData={},{}".format(type(polyData),polyData))
model.SetAndObservePolyData(polyData)
else:
raise Exception('input error!')
model.SetScene(slicer.mrmlScene)
modelDisplay = slicer.vtkMRMLModelDisplayNode()
modelDisplay.SetOpacity(1.0)
modelDisplay.SetColor([1, 1, 0])
modelDisplay.SetSliceIntersectionVisibility(True) # Show in slice view
modelDisplay.SetVisibility(True) # Hide in 3D view
modelDisplay.SetScene(slicer.mrmlScene)
slicer.mrmlScene.AddNode(modelDisplay)
slicer.mrmlScene.AddNode(model)
transform = slicer.vtkMRMLLinearTransformNode()
slicer.mrmlScene.AddNode(transform)
model.SetAndObserveDisplayNodeID(modelDisplay.GetID())
model.SetAndObserveTransformNodeID(transform.GetID())
return model
You can use MarkupsToModel extension to create curves from markup fiducial or model points. It supports linear and various smooth interpolating and approximating methods.
I have tried MarkupsToModel,it really can draw the straight line by clicking scattered pointes.
Just have one issue:if I want to delete the total polydata,I should switch to Models then select corresponding model to delete it,correct?
I have implemented a simple module,which can draw some scattered points,then connect neighboring points with a straight line, used a polydata to show these lines at last,likes below screenshot:
Since I want to setAndobserve this polydata in Slicer,the issue: this Polydata can not be displayed,since the area is 0,likes below screenshot:
If you set the output to be a closed surface instead of a line then you’ll get the surface area. Both sides of the surface will be included in the computation, so you probably want to divide the reported surface area by 2.
It can create curves with clicking points,one issue is:the curve is convex hull,can we change it to false?
since we found some points can not be seen,pls see below screenshots:
Do you need a line/curve connecting points? If yes, then set ModelType to Curve and probably enable TubeLoop as well.
If you want to reconstruct a surface from a sparse set of points then Delaunay triangulation is used. You can tune DelaunayAlpha parameter to control how much concavity is allowed in the reconstructed surface (if alpha is set to 0 then the result will be a convex hull).