/
chain_4_collinear.py
160 lines (128 loc) · 3.71 KB
/
chain_4_collinear.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import openvoronoi as ovd
import ovdvtk
import time
import vtk
import datetime
import math
import random
import os
import sys
import pickle
import gzip
if __name__ == "__main__":
#w=2500
#h=1500
#w=1920
#h=1080
w=1024
h=1024
myscreen = ovdvtk.VTKScreen(width=w, height=h)
ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version() )
w2if = vtk.vtkWindowToImageFilter()
w2if.SetInput(myscreen.renWin)
lwr = vtk.vtkPNGWriter()
lwr.SetInput( w2if.GetOutput() )
#w2if.Modified()
#lwr.SetFileName("tux1.png")
scale=1
myscreen.render()
random.seed(42)
far = 1
camPos = far
zmult = 3
# camPos/float(1000)
myscreen.camera.SetPosition(0, -camPos/float(1000), zmult*camPos)
myscreen.camera.SetClippingRange(-(zmult+1)*camPos,(zmult+1)*camPos)
myscreen.camera.SetFocalPoint(0.0, 0, 0)
vd = ovd.VoronoiDiagram(far,120)
print ovd.version()
# for vtk visualization
vod = ovdvtk.VD(myscreen,vd,float(scale), textscale=0.01, vertexradius=0.003)
vod.drawFarCircle()
vod.textScale = 0.002
vod.vertexRadius = 0.0031
vod.drawVertices=0
vod.drawVertexIndex=1
vod.drawGenerators=0
vod.offsetEdges = 1
vd.setEdgeOffset(0.01)
linesegs = 1 # switch to turn on/off line-segments
segs = []
#ovd.Point(1,1)
#eps=0.9
p1=ovd.Point(-0.1,-0.1)
p2=ovd.Point(0.0,0.0)
p3=ovd.Point(0.1,0.1)
p4=ovd.Point(0.2,0.3)
#p4=ovd.Point(0.6,0.6)
#p5=ovd.Point(-0.6,0.3)
pts = [p1,p2,p3,p4]
#t_after = time.time()
#print ".done in {0:.3f} s.".format( t_after-t_before )
times=[]
id_list = []
m=0
t_before = time.time()
for p in pts:
id_list.append( vd.addVertexSite( p ) )
#print m," added vertex", seg_id[0]
m=m+1
t_after = time.time()
times.append( t_after-t_before )
#exit()
#print " ",2*Nmax," point-sites sites took {0:.3f}".format(times[0])," seconds, {0:.2f}".format( 1e6*float( times[0] )/(float(2*Nmax)*float(math.log10(2*Nmax))) ) ,"us/n*log(n)"
print "all point sites inserted. "
vd.check()
#nsegs = Nmax
#nsegs = 5 #Nmax
#n=1
t_before = time.time()
#vd.debug_on()
vd.addLineSite( id_list[0], id_list[1])
vd.check()
vd.debug_on()
vd.addLineSite( id_list[2], id_list[1])
vd.check()
vd.addLineSite( id_list[2], id_list[3] )
vd.check()
t_after = time.time()
line_time = t_after-t_before
if line_time < 1e-3:
line_time = 1
times.append( line_time )
#s = id_list[nsegs]
#vd.debug_on()
#vd.addLineSite( s[0], s[1], 10)
#seg = id_list[nsegs]
#vd.addLineSite(seg[0],seg[1],10)
# 1 identify start/endvert
# 2 add line-segment edges/sites to graph
# 3 identify seed-vertex
# 4 create delete-tree
# 5 create new vertices
# 6 add startpoint pos separator
# 7 add startoiubt neg separator
# 8 add end-point pos separator
# 9 add end-point neg separator
# 10 add new edges
# 11 delete delete-tree edges
# 12 reset status
vod.setVDText2(times)
err = vd.getStat()
#print err
print "got errorstats for ",len(err)," points"
if len(err)>1:
minerr = min(err)
maxerr = max(err)
print "min error= ",minerr
print "max error= ",maxerr
print "num vertices: ",vd.numVertices()
print "num SPLIT vertices: ",vd.numSplitVertices()
calctime = t_after-t_before
vod.setAll()
print "PYTHON All DONE."
myscreen.render()
#w2if.Modified()
#lwr.SetFileName("{0}.png".format(Nmax))
#lwr.Write()
myscreen.iren.Start()