Hello! I am new to python and VTK so please have patience
I have an actor and I would like to rotate it about a line I drew using vtkLineSource(). I chose my start and end points and I drew the line. Now what I thought is (please correct me if I am wrong) that I should make an axis on the line and then apply the vtkTransformWXYZ() to rotate about the axis. It does not work, it gives a weird rotation about the chosen point, but not the one I desire.
I also tried defining the axis on the middle of the line I drew and apply the rotation on it, but when I try, it rotates about the global coordinates, and not the local. I also tried to give as input the point, but again, the rotation is very weird.
Is there a way to define the line as an axis and rotate the actor about it? So far I tried like in the following examples: https://lorensen.github.io/VTKExamples/site/Python/PolyData/RotationAroundLine/ and https://lorensen.github.io/VTKExamples/site/Python/Rendering/Rotations/ but my actor always rotates in a weird way.
Could anyone help/point me in the right direction please?
Here is the part of my code where I am trying to rotate the actor…
###################### create line to rotate about and display it
lineStart = [16.8879, -106.476, -782.449]
lineFinish = [-17.827, -92.2757, lineStart[2]]
lineMiddle = [(lineStart[0]+lineFinish[0])/2, (lineStart[1]+lineFinish[1])/2, lineStart[2]]
lineSource = vtk.vtkLineSource()
lineSource.SetPoint1(lineStart)
lineSource.SetPoint2(lineFinish)
lineSource.Update()
mapperLine = vtk.vtkPolyDataMapper()
mapperLine.SetInputConnection(lineSource.GetOutputPort())
actorLine = vtk.vtkActor()
actorLine.SetMapper(mapperLine)
actorLine.GetProperty().SetLineWidth(4)
actorLine.GetProperty().SetColor(1,0,0)
ren.AddActor(actorLine)
############# rotate about the line
modelMapper = vtk.vtkPolyDataMapper()
modelMapper.SetInputData(cleanFilter.GetOutput())
modelActor = vtk.vtkActor()
modelActor.SetMapper(modelMapper)
modelAxesSource = vtk.vtkAxes()
modelAxesSource.SetScaleFactor(100)
modelAxesSource.SetOrigin(lineMiddle)
modelAxesMapper = vtk.vtkPolyDataMapper()
modelAxesMapper.SetInputConnection(modelAxesSource.GetOutputPort())
modelAxes = vtk.vtkActor()
modelAxes.SetMapper(modelAxesMapper)
ren.AddActor(modelAxes)
modelAxes.VisibilityOn()
##this did not work
# modelActor.SetOrientation(lineMiddle)
# modelActor.RotateZ(45)
# ren.AddActor(modelActor)
transform = vtk.vtkTransform()
transform.RotateWXYZ(45, lineMiddle)
transformFilter = vtk.vtkTransformPolyDataFilter()
transformFilter.SetTransform(transform)
transformFilter.SetInputConnection(cleanFilter.GetOutputPort())
transformFilter.Update()
NewMapper = vtk.vtkPolyDataMapper()
NewMapper.SetInputConnection(transformFilter.GetOutputPort())
actorRotated = vtk.vtkActor()
actorRotated.SetMapper(NewMapper)
ren.AddActor(actorRotated)
Thanks in advance,
Diana