File: clipPointSet.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,992 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 185; javascript: 165; objc: 153; tcl: 59
file content (34 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkCommonDataModel import (
    vtkPlane,
    vtkPointSet
)
from vtkmodules.vtkFiltersGeneral import vtkTableBasedClipDataSet

# Create a sphere source
sphere_source = vtkSphereSource()
sphere_source.SetRadius(1.0)
sphere_source.SetThetaResolution(30)
sphere_source.SetPhiResolution(30)
sphere_source.Update()

# Convert PolyData to PointSet
poly = sphere_source.GetOutput()
pointset = vtkPointSet()
pointset.SetPoints(poly.GetPoints())

# Define a clipping plane
plane = vtkPlane()
plane.SetOrigin(0.0, 0.0, 0.0)  # Pass through the origin
plane.SetNormal(1.0, 0.0, 0.0)  # Clip along the X-axis

# Use vtkTableBasedClipDataSet to clip the point set
clipper = vtkTableBasedClipDataSet()
clipper.SetInputData(pointset)
clipper.SetClipFunction(plane)
clipper.SetInsideOut(False)  # Keep points on the positive side of the plane
clipper.Update()
output = clipper.GetOutput()

assert(output.GetNumberOfPoints() == 422)
assert(output.GetNumberOfCells() == 0)