Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw lines with Python VTK

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian detailed introduction of "how to use Python VTK to draw lines", the content is detailed, the steps are clear, the details are handled properly, I hope this "how to use Python VTK to draw lines" article can help you solve your doubts, following the editor's ideas slowly in depth, together to learn new knowledge.

Introduction of main functions:

Vtk.vtkPoints () is a class used in VTK to define a point, and a point set can be inserted using points.InsertPoint (index, x, y, z). In the function, the first parameter is the sequence number of the point, followed by the coordinates of the three parameters.

Vtk.vtkLineSource () defines the class of the line in VTK, and through SetPoints (points), enter the point through which the line passes.

Vtk.vtkParametricSpline () defines the class of the curve in VTK, and through SetPoints (points), enter the point through which the curve passes.

Vtk.vtkParametricFunctionSource () curve interpolation fitting function, you can fit the set of input points into a curve. There are many ways to generate. We can take a brief look at the introduction of the VTK official documentation.

S\ CALAR_NONE-Scalars are not generated (default).

SCALAR_U-The scalar is set to the u-value.

SCALAR_V-The scalar is set to the v-value.

SCALAR_U0-The scalar is set to 1 if u = (u_max-u_min) / 2 = u_avg, 0 otherwise.

SCALAR_V0-The scalar is set to 1 if v = (v_max-v_min) / 2 = v_avg, 0 otherwise.

SCALAR_U0V0-The scalar is set to 1 if u = = u_avg, 2 if v = = v_avg, 3 if u = u_avg & v = v_avg, 0 otherwise.

SCALAR_MODULUS-The scalar is set to (sqrt (uu+vv)), this is measured relative to.

SCALAR_PHASE-The scalar is set to (atan2 (vjure u)) (in degrees, 0 to 360), this is measured relative to (upright avg pencyclavg).

SCALAR_QUADRANT-The scalar is set to 1, 2, 3 or 4. Depending upon the quadrant of the point.

SCALAR_X-The scalar is set to the x-value.

SCALAR_Y-The scalar is set to the y-value.

SCALAR_Z-The scalar is set to the z-value.

SCALAR_DISTANCE-The scalar is set to (sqrt (xx+yy+z*z)) I.e. Distance from the origin.

SCALAR_USER_DEFINED-The scalar is set to the value returned from EvaluateScalar ().

Actor.GetProperty (). SetColor () line color configuration

Actor.GetProperty (). SetLineWidth () line width configuration

Fit curve code:

Import vtkpoints = vtk.vtkPoints () # define a point tool points.InsertPoint (0,329,338,45) # you can insert a point using InsertPoint # Note: points.InsertPoint (a, b, c, d) # where a represents the sequence number of the point The three-dimensional coordinates of the point points.InsertPoint (1,328,319,46) points.InsertPoint (2,300,329) 96) # define curve tool # fit the first few points into a curve spline = vtk.vtkParametricSpline () spline.SetPoints (points) splineSource = vtk.vtkParametricFunctionSource () splineSource.SetParametricFunction (spline) splineSource.Update () splineMapper = vtk.vtkPolyDataMapper () splineMapper.SetInputConnection (splineSource.GetOutputPort ()) splineActor = vtk.vtkActor () splineActor.SetMapper (splineMapper) # set line color splineActor.GetProperty (). SetColor (0.3800, 0.7000) 0.1600) # set line width splineActor.GetProperty () .SetLineWidth (5) ren1 = vtk.vtkRenderer () renWin = vtk.vtkRenderWindow () renWin.AddRenderer (ren1) iren = vtk.vtkRenderWindowInteractor () iren.SetRenderWindow (renWin) ren1.AddActor (splineActor) ren1.SetBackground (1,1,1) renWin.SetSize (250,250) renWin.Render () iren.Start ()

Draw a line code

Import vtkpoints = vtk.vtkPoints () # define a point tool points.InsertPoint (0,329,338,45) # you can insert a point using InsertPoint # Note: points.InsertPoint (a, b, c, d) # where a represents the sequence number of the point Points.InsertPoint (1,328,319,46) points.InsertPoint (2,300,329,96) # define a straight line tool lineSource = vtk.vtkLineSource () lineSource.SetPoints (points) lineSource.Update () lineMapper = vtk.vtkPolyDataMapper () lineMapper.SetInputConnection (lineSource.GetOutputPort ()) splineActor = vtk.vtkActor () splineActor.SetMapper (lineMapper) # set line color splineActor.GetProperty (). SetColor (0.3800, 0.7000) 0.1600) # set line width splineActor.GetProperty () .SetLineWidth (5) ren1 = vtk.vtkRenderer () renWin = vtk.vtkRenderWindow () renWin.AddRenderer (ren1) iren = vtk.vtkRenderWindowInteractor () iren.SetRenderWindow (renWin) ren1.AddActor (splineActor) ren1.SetBackground (1,1,1) renWin.SetSize (250,250) renWin.Render () iren.Start ()

Read here, this article "how to use Python VTK to draw lines" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report