import time
import vtk

cnt = 1
fname = '/home/andre/tiffs/out'

def frame_write(fname, count, MainVTKWindow):
    pass
    #print 'ok'
    #global cnt
    #w2i = vtk.vtkWindowToImageFilter()
    #writer = vtk.vtkTIFFWriter()
    #w2i.SetInput(MainVTKWindow.GetRenderWindow())
    #w2i.Update()
    #writer.SetInputConnection(w2i.GetOutputPort())
    ##prompt_user_input()
    ##save_name = raw_input("Save file as ... :")
    #writer.SetFileName("%s%04d.tif" %(fname,count))
    ##remove_prompt_user_input()
    #writer.Write()
    #print 'saved main window to %s%04d.tif sucessfully' %(fname,count)


def animate(MainVTKWindow):
    global cnt
    MainVTKWindow.widget.Render()
    print MainVTKWindow.ListOfObjects
    #clip the scalp off    
    for i in range (55):
        MainVTKWindow.ListOfObjects[-1].planes1.SetBounds((-300, -2.43569, -1.44856, 219.683-i*4, -17.8669, 250.052))
        MainVTKWindow.widget.Render()
        frame_write(fname, cnt, MainVTKWindow.ren)
        cnt += 1
        #time.sleep(0.0)
        #frame write here

    #rotate 75 degrees
    for i in range(60):
        MainVTKWindow.ren.GetActiveCamera().Azimuth(1)
        MainVTKWindow.widget.Render()
        frame_write(fname, cnt, MainVTKWindow.ren)
        cnt += 1

    ##rotate up a few degrees
    #for i in range(40):
    #    MainVTKWindow.ren.GetActiveCamera().Elevation(1)
    #    MainVTKWindow.widget.Render()
    #    #MainVTKWindow.Views_page.OnVPCaptureButton('null_arg')
    
    #sweep out the left cortex    
    for i in range (27):
        MainVTKWindow.ListOfObjects[-3].planes1.SetBounds((-175.987, -89.0735,-1.44856+i*8, 227.83,-17.8669, 170.052))
        MainVTKWindow.widget.Render()    
        frame_write(fname, cnt, MainVTKWindow.ren)
        cnt += 1    

    #zoom in a bit
    for i in range(10):
        MainVTKWindow.ren.GetActiveCamera().Zoom(1.05)    
        MainVTKWindow.widget.Render()
        frame_write(fname, cnt, MainVTKWindow.ren)
        cnt += 1
    
    #sweep out the right gray matter to reveal white
    for i in range (55):
        MainVTKWindow.ListOfObjects[-2].planes1.SetBounds((-89.0735, 0.0, -1.44856+i*4, 227.83,-17.8669, 170.052))
        MainVTKWindow.widget.Render()    
        frame_write(fname, cnt, MainVTKWindow.ren)
        cnt += 1
    MainVTKWindow.Views_page.OnVPCaptureButton('null_arg')

    #time.sleep(3)
    #reset
    MainVTKWindow.ListOfObjects[-1].planes1.SetBounds((-300.987, -2.43569, -1.44856, 219.683, -17.8669, 250.052))
    MainVTKWindow.widget.Render()
