• VTK OrientationMarker 方向 三维坐标系 相机坐标轴 自定义坐标轴


    本文 以 Python 语言开发

    我们在做三维软件开发时,经常会用到相机坐标轴,来指示当前空间位置;

    坐标轴效果:

    相机方向坐标轴

     Cube 正方体坐标轴

     自定义坐标轴:

    Code:

    Axes
    1. def main():
    2. colors = vtkNamedColors()
    3. # create a Sphere
    4. sphereSource = vtkSphereSource()
    5. sphereSource.SetCenter(0.0, 0.0, 0.0)
    6. sphereSource.SetRadius(0.5)
    7. # create a mapper
    8. sphereMapper = vtkPolyDataMapper()
    9. sphereMapper.SetInputConnection(sphereSource.GetOutputPort())
    10. # create an actor
    11. sphereActor = vtkActor()
    12. sphereActor.SetMapper(sphereMapper)
    13. # a renderer and render window
    14. renderer = vtkRenderer()
    15. renderWindow = vtkRenderWindow()
    16. renderWindow.SetWindowName('Axes')
    17. renderWindow.AddRenderer(renderer)
    18. # an interactor
    19. renderWindowInteractor = vtkRenderWindowInteractor()
    20. renderWindowInteractor.SetRenderWindow(renderWindow)
    21. # add the actors to the scene
    22. renderer.AddActor(sphereActor)
    23. renderer.SetBackground(colors.GetColor3d('SlateGray'))
    24. transform = vtkTransform()
    25. transform.Translate(1.0, 0.0, 0.0)
    26. axes = vtkAxesActor()
    27. # The axes are positioned with a user transform
    28. axes.SetUserTransform(transform)
    29. # properties of the axes labels can be set as follows
    30. # this sets the x axis label to red
    31. axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(colors.GetColor3d('Red'));
    32. # the actual text of the axis label can be changed:
    33. axes.SetXAxisLabelText('test')
    34. renderer.AddActor(axes)
    35. renderer.GetActiveCamera().Azimuth(50)
    36. renderer.GetActiveCamera().Elevation(-30)
    37. renderer.ResetCamera()
    38. renderWindow.SetWindowName('Axes')
    39. renderWindow.Render()
    40. # begin mouse interaction
    41. renderWindowInteractor.Start()
    42. if __name__ == '__main__':
    43. main()
    CameraOrientationWidget
    1. def main():
    2. colors = vtkNamedColors()
    3. renderer = vtkRenderer()
    4. ren_win = vtkRenderWindow()
    5. interactor = vtkRenderWindowInteractor()
    6. sphere_source = vtkSphereSource()
    7. sphere_source.SetRadius(10.0)
    8. mapper = vtkPolyDataMapper()
    9. mapper.SetInputConnection(sphere_source.GetOutputPort())
    10. actor = vtkActor()
    11. actor.GetProperty().SetColor(colors.GetColor3d('Beige'))
    12. actor.SetMapper(mapper)
    13. renderer.AddActor(actor)
    14. renderer.SetBackground(colors.GetColor3d('DimGray'))
    15. ren_win.AddRenderer(renderer)
    16. ren_win.SetSize(600, 600)
    17. ren_win.SetWindowName('CameraOrientationWidget')
    18. # Important: The interactor must be set prior to enabling the widget.
    19. interactor.SetRenderWindow(ren_win)
    20. cam_orient_manipulator = vtkCameraOrientationWidget()
    21. cam_orient_manipulator.SetParentRenderer(renderer)
    22. # Enable the widget.
    23. cam_orient_manipulator.On()
    24. ren_win.Render()
    25. interactor.Initialize()
    26. interactor.Start()
    27. if __name__ == "__main__":
    28. main()
    OrientationMarkerWidget
    1. colors = vtkNamedColors()
    2. # create a rendering window and renderer
    3. ren = vtkRenderer()
    4. ren_win = vtkRenderWindow()
    5. ren_win.AddRenderer(ren)
    6. ren_win.SetWindowName('OrientationMarkerWidget')
    7. # create a renderwindowinteractor
    8. iren = vtkRenderWindowInteractor()
    9. iren.SetRenderWindow(ren_win)
    10. cube = vtkCubeSource()
    11. cube.SetXLength(200)
    12. cube.SetYLength(200)
    13. cube.SetZLength(200)
    14. cube.Update()
    15. cm = vtkPolyDataMapper()
    16. cm.SetInputConnection(cube.GetOutputPort())
    17. ca = vtkActor()
    18. ca.SetMapper(cm)
    19. ca.GetProperty().SetColor(colors.GetColor3d("BurlyWood"))
    20. ca.GetProperty().EdgeVisibilityOn()
    21. ca.GetProperty().SetEdgeColor(colors.GetColor3d("Red"))
    22. # assign actor to the renderer
    23. ren.AddActor(ca)
    24. ren.SetBackground(colors.GetColor3d('CornflowerBlue'))
    25. axes_actor = vtkAnnotatedCubeActor()
    26. axes_actor.SetXPlusFaceText('L')
    27. axes_actor.SetXMinusFaceText('R')
    28. axes_actor.SetYMinusFaceText('I')
    29. axes_actor.SetYPlusFaceText('S')
    30. axes_actor.SetZMinusFaceText('P')
    31. axes_actor.SetZPlusFaceText('A')
    32. axes_actor.GetTextEdgesProperty().SetColor(colors.GetColor3d("Yellow"))
    33. axes_actor.GetTextEdgesProperty().SetLineWidth(2)
    34. axes_actor.GetCubeProperty().SetColor(colors.GetColor3d("Blue"))
    35. axes = vtkOrientationMarkerWidget()
    36. axes.SetOrientationMarker(axes_actor)
    37. axes.SetInteractor(iren)
    38. axes.EnabledOn()
    39. axes.InteractiveOn()
    40. ren.ResetCamera()
    41. # enable user interface interactor
    42. iren.Initialize()
    43. ren_win.Render()
    44. ren.GetActiveCamera().Azimuth(45)
    45. ren.GetActiveCamera().Elevation(30)
    46. ren_win.Render()
    47. iren.Start()
    custom OrientationMarker
    1. colors = vtkNamedColors()
    2. reader = vtkXMLPolyDataReader()
    3. reader.SetFileName("./Human.vtp")
    4. icon_mapper = vtkDataSetMapper()
    5. icon_mapper.SetInputConnection(reader.GetOutputPort())
    6. icon_actor = vtkActor()
    7. icon_actor.SetMapper(icon_mapper)
    8. icon_actor.GetProperty().SetColor(colors.GetColor3d('Silver'))
    9. # Set up the renderer, window, and interactor
    10. renderer = vtkRenderer()
    11. renderer.SetBackground(colors.GetColor3d('SlateGray'))
    12. ren_win = vtkRenderWindow()
    13. ren_win.AddRenderer(renderer)
    14. ren_win.SetSize(400, 400)
    15. ren_win.SetWindowName('OrientationMarkerWidget1')
    16. iren = vtkRenderWindowInteractor()
    17. iren.SetRenderWindow(ren_win)
    18. rgb = [0.0, 0.0, 0.0]
    19. colors.GetColorRGB('Wheat', rgb)
    20. # Set up the widget
    21. widget = vtkOrientationMarkerWidget()
    22. widget.SetOrientationMarker(icon_actor)
    23. widget.SetInteractor(iren)
    24. widget.SetViewport(0.0, 0.0, 0.3, 0.3)
    25. widget.SetOutlineColor(*rgb)
    26. widget.SetEnabled(1)
    27. widget.InteractiveOn()
    28. # Create a superquadric
    29. superquadric_source = vtkSuperquadricSource()
    30. superquadric_source.SetPhiRoundness(.001)
    31. superquadric_source.SetThetaRoundness(.04)
    32. # Create a mapper and actor
    33. superquadric_mapper = vtkPolyDataMapper()
    34. superquadric_mapper.SetInputConnection(superquadric_source.GetOutputPort())
    35. superquadric_actor = vtkActor()
    36. superquadric_actor.SetMapper(superquadric_mapper)
    37. superquadric_actor.GetProperty().SetInterpolationToFlat()
    38. superquadric_actor.GetProperty().SetDiffuseColor(colors.GetColor3d('Carrot'))
    39. superquadric_actor.GetProperty().SetSpecularColor(colors.GetColor3d('White'))
    40. superquadric_actor.GetProperty().SetDiffuse(0.6)
    41. superquadric_actor.GetProperty().SetSpecular(0.5)
    42. superquadric_actor.GetProperty().SetSpecularPower(5.0)
    43. renderer.AddActor(superquadric_actor)
    44. renderer.ResetCamera()
    45. ren_win.Render()
    46. iren.Initialize()
    47. iren.Start()

  • 相关阅读:
    ARM64 SMP多核启动详解1(spin_table)
    记录一次部署Hugo主题lotusdocs到Github Pages实践
    C语言 数据在内存中的存储
    Ubuntu1804安装rabbitmq服务
    观点|周鸿祎:大模型真正的竞争在于使其与用户场景相结合
    pytest(二)框架实现一些前后置(固件,夹具)的处理,常用三种
    <单链表及模拟实现>——《Data Structure in C Train》
    适合骑车时候戴的耳机怎么选,列举五款在骑行佩戴的耳机推荐
    Flink CDC-2.3版本概述
    [ CTF ]【天格】战队WriteUp-2022年第二届“长城杯”网络安全大赛
  • 原文地址:https://blog.csdn.net/q610098308/article/details/134074535