File: TestExtractEdges.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; 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: 178; javascript: 165; objc: 153; tcl: 59
file content (97 lines) | stat: -rwxr-xr-x 2,788 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import (
    reference,
    vtkIdList
)
from vtkmodules.vtkCommonDataModel import vtkQuadric
from vtkmodules.vtkFiltersCore import (
    vtkExecutionTimer,
    vtkExtractEdges,
    vtkPointDataToCellData,
)
from vtkmodules.vtkImagingHybrid import vtkSampleFunction
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
)
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2

# Test edge extraction with cell data, and with original
# point numbering preserved.
#
# Due to issues rendering lots of lines, this test has been
# modified to perform procedural comparison of results.
res = 10
error = 0

# Test edge extraction for arbitrary datasets
#
# Quadric definition
quadric = vtkQuadric()
quadric.SetCoefficients([.5,1,.2,0,.1,0,0,.2,0,0])
sample = vtkSampleFunction()
sample.SetSampleDimensions(res,res,res)
sample.SetImplicitFunction(quadric)
sample.ComputeNormalsOff()
sample.Update()

# Create some cell data
pd2cd = vtkPointDataToCellData()
pd2cd.SetInputConnection(sample.GetOutputPort())
pd2cd.PassPointDataOn()
pd2cd.Update()

# Now extract the edges
extract = vtkExtractEdges()
extract.SetInputConnection(pd2cd.GetOutputPort())
extract.UseAllPointsOn()

timer = vtkExecutionTimer()
timer.SetFilter(extract)
extract.Update()
ET = timer.GetElapsedWallClockTime()
print ("vtkExtractEdges:", ET)

# Now compare attribute values of extracted points and edges with
# the input dataset.
if extract.GetOutput().GetNumberOfPoints() != 1000:
    print("Wrong number of points. Expected 1000 but got {0}.".format(extract.GetOutput().GetNumberOfPoints()))
    error = 1

numEdges = extract.GetOutput().GetNumberOfCells()
if numEdges != 2700:
    print("Wrong number of edges. Expected 2700 but got {0}.".format(numEdges))
    error = 1

qScalars = sample.GetOutput().GetPointData().GetScalars()
eScalars = extract.GetOutput().GetPointData().GetScalars()

# Compare selected attribute values with input dataset attributes.
edgeNum = 0
ePts = vtkIdList()
edges = extract.GetOutput().GetLines()
eIter = edges.NewIterator()
while not eIter.IsDoneWithTraversal():
    eIter.GetCurrentCell(ePts)
    v0 = ePts.GetId(0)
    v1 = ePts.GetId(1)
    s0 = eScalars.GetTuple1(v0)
    s1 = eScalars.GetTuple1(v1)
    q0 = qScalars.GetTuple1(v0)
    q1 = qScalars.GetTuple1(v1)
    if s0 != q0 or s1 != q1:
        error = 1
        print("Error in edge number: ", edgeNum)
    edgeNum += 1
    eIter.GoToNextCell()

# Return test results. If the assert is not true, then different results were
# generated by vtkStaticPointLocator and vtkPointLocator.
assert error == 0

# --- end of script --