| 1 |
from opencamlib import ocl, pyocl, camvtk |
| 2 |
import math |
| 3 |
|
| 4 |
if __name__ == "__main__": |
| 5 |
print(ocl.version()) # print out git version tag |
| 6 |
|
| 7 |
# set up VTK visualization |
| 8 |
myscreen = camvtk.VTKScreen() |
| 9 |
myscreen.setAmbient(20,20,20) |
| 10 |
myscreen.camera.SetPosition(4, 4, 3) |
| 11 |
myscreen.camera.SetFocalPoint(0.6, 0.6, 0) |
| 12 |
myscreen.setAmbient(1,1,1) |
| 13 |
|
| 14 |
#camvtk.drawArrows(myscreen) |
| 15 |
|
| 16 |
# three corners of a triangle |
| 17 |
a = ocl.Point(1,0,-0.000010) |
| 18 |
b = ocl.Point(0,1,+0.0) |
| 19 |
c = ocl.Point(0.001,0,+0.3001) |
| 20 |
#c = ocl.Point(0,0,0.3) |
| 21 |
t = ocl.Triangle(a,b,c) |
| 22 |
|
| 23 |
# draw the triangle with VTK |
| 24 |
myscreen.addActor( camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))); |
| 25 |
myscreen.addActor( camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))); |
| 26 |
myscreen.addActor( camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))); |
| 27 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) |
| 28 |
myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) |
| 29 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) |
| 30 |
|
| 31 |
# Define a cutter |
| 32 |
angle = math.pi/8 |
| 33 |
length = 5.0 |
| 34 |
#c1 = ocl.BullCutter(0.5,0.1, length) |
| 35 |
#c1 = ocl.CylCutter(0.5, length) |
| 36 |
#c1 = ocl.BallCutter(0.5, length) |
| 37 |
c1 = ocl.ConeCutter(0.5,angle, length) |
| 38 |
cutter = c1 |
| 39 |
cutter = c1.offsetCutter(0.1) |
| 40 |
|
| 41 |
print(cutter) |
| 42 |
|
| 43 |
|
| 44 |
# grid parameters |
| 45 |
minx=-0.7 |
| 46 |
dx=0.03 |
| 47 |
maxx=1.7 |
| 48 |
miny=-0.7 |
| 49 |
dy=0.03 |
| 50 |
maxy=1.7 |
| 51 |
z=-0.5 |
| 52 |
# generate list of CL-poins at height z |
| 53 |
clpoints=[] |
| 54 |
# we calculate cutter-locations for this grid of XY points |
| 55 |
clpoints = pyocl.CLPointGrid(minx,dx,maxx,miny,dy,maxy,z) |
| 56 |
|
| 57 |
# loop through the cl-points |
| 58 |
n=0 |
| 59 |
print(len(clpoints), "cl-points to evaluate") |
| 60 |
for cl in clpoints: |
| 61 |
cutter.vertexDrop(cl,t) |
| 62 |
cutter.edgeDrop(cl,t) |
| 63 |
cutter.facetDrop(cl,t) |
| 64 |
n=n+1 |
| 65 |
print("drop-cutter done.") |
| 66 |
# cl has now been updated so it is a valid cutter-location point |
| 67 |
# drop-cutter only updates the z-coordinate of cl, x/y are not changed. |
| 68 |
|
| 69 |
print("rendering...",) |
| 70 |
# render all the points |
| 71 |
camvtk.drawCLPointCloud(myscreen, clpoints) |
| 72 |
camvtk.drawCCPoints(myscreen, clpoints) |
| 73 |
print("done." ) |
| 74 |
|
| 75 |
tx = camvtk.Text() |
| 76 |
tx.SetPos( (myscreen.width-200, myscreen.height-130) ) |
| 77 |
tx.SetText("opencamlib\ndrop-cutter") |
| 78 |
myscreen.addActor( tx ) |
| 79 |
|
| 80 |
#w2if = vtk.vtkWindowToImageFilter() |
| 81 |
#w2if.SetInput(myscreen.renWin) |
| 82 |
#lwr = vtk.vtkPNGWriter() |
| 83 |
#lwr.SetInput( w2if.GetOutput() ) |
| 84 |
#w2if.Modified() |
| 85 |
|
| 86 |
|
| 87 |
# animate by rotating the camera |
| 88 |
""" |
| 89 |
for n in range(1,90): |
| 90 |
tx.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) |
| 91 |
myscreen.camera.Azimuth( 4 ) |
| 92 |
#time.sleep(0.01) |
| 93 |
myscreen.render() |
| 94 |
lwr.SetFileName("frames/ball_all"+ ('%05d' % n)+".png") |
| 95 |
w2if.Modified() |
| 96 |
#lwr.Write() # write screenshot to file |
| 97 |
""" |
| 98 |
myscreen.render() |
| 99 |
myscreen.iren.Start() |
| 100 |
raw_input("Press Enter to terminate") |
| 101 |
|