MCPcopy Create free account
hub / github.com/Kitware/VTK / Circle

Class Circle

IO/XML/Testing/Python/TestXMLHyperTreeGrid.py:48–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46TARGET_LEVEL = 4
47
48class Circle:
49 _center = [0.5, 0.]
50 _rayon = 1.
51 _rayon2 = _rayon*_rayon
52
53 def test(self, x, y, z):
54 d2 = (x - self._center[0])**2 + (y - self._center[1])**2
55 if d2 > self._rayon2:
56 return -1
57 return 1
58
59 def value(self, geoCursor):
60 bounds = range(6)
61 geoCursor.GetBounds( bounds )
62 return self.test(
63 bounds[0]+(bounds[1]-bounds[0])/2,
64 bounds[2]+(bounds[3]-bounds[2])/2,
65 bounds[4]+(bounds[5]-bounds[4])/2)
66
67 def shouldRefine(self, geoCursor):
68 if geoCursor.GetLevel() >= TARGET_LEVEL:
69 return False
70 bounds = range(6)
71 geoCursor.GetBounds( bounds )
72 v0 = self.test(bounds[0],bounds[2],bounds[4])
73 v1 = self.test(bounds[1],bounds[2],bounds[4])
74 if v0 == v1:
75 v2 = self.test(bounds[0],bounds[3],bounds[4])
76 if v0 == v2:
77 v3 = self.test(bounds[1],bounds[3],bounds[4])
78 if v0 == v3:
79 return False
80 return True
81
82 def handleNode(self, geoCursor, levelArray, scalarArray):
83 # Add value in fields
84 idx = geoCursor.GetGlobalNodeIndex()
85 scalarArray.InsertTuple1(idx, self.value(geoCursor))
86 levelArray.InsertTuple1(idx, geoCursor.GetLevel())
87
88 if geoCursor.IsLeaf():
89 if self.shouldRefine(geoCursor):
90 geoCursor.SubdivideLeaf()
91 self.handleNode(geoCursor, levelArray, scalarArray)
92 else:
93 for ichild in range( geoCursor.GetNumberOfChildren() ):
94 geoCursor.ToChild(ichild)
95 self.handleNode(geoCursor, levelArray, scalarArray)
96 geoCursor.ToParent()
97
98#--------------------------------
99

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected