Exemple #1
0
 def pov_export(self, export_path, export_name):
     if not os.path.exists(export_path):
         os.makedirs(export_path)
     filename = export_name + '.pov'
     fullname = export_path + '/' + filename
     print(self.scene.camera.pos)
     povexport.export(canvas=self.scene, filename=fullname, shadowless=1)
Exemple #2
0
def cinematic_thread(svc, POVdump=None, ACCEL=ACCEL, DT=DT):
    log.info("Cinematic thread started")
    the_world = svc.the_world
    scene = the_world.scene
    picked = None
    frames=-1
    while 1:
        frames += 1
        rate(ACCEL/DT)
        svc.cinematic_lock.acquire()
        try:
            if scene.kb.keys:
                k = scene.kb.getkey()
                if k == "Q":
                    #send event
                    return
            if scene.mouse.events:
                ev = scene.mouse.getevent()
                if ev.release == "left":
                    if picked:
                        the_world.speeds[picked.num]=((scene.mouse.pos-picked.PV)/DT).astuple()
                        the_world.cinematic_change = 1
                        picked = None
                    else:
                        o = ev.pick
                        if ev.shift and o:
                            if hasattr(o,"id"):
                                svc.node_shift_click(o.id)
                        elif ev.ctrl and o:
                            if hasattr(o,"id"):
                                svc.node_ctrl_click(o.id)
                        else:
                            if hasattr(o, "action"):
                                o.action()
                if ev.drag == "left":
                    if ev.pick and ev.pick.pickable:
                        picked = ev.pick

    
            if picked:
                picked.PV = picked.pos
                picked.pos=scene.mouse.pos
                picked.V = vector()
                the_world.coords[picked.num]=picked.pos.astuple()
                the_world.speeds[picked.num]=(0.0,0.0,0.0)
                the_world.cinematic_change = 1

            the_world.update(DT)
            the_world.update_edges()                
            if POVdump is not None:
                fname = POVdump % frames
                povexport.export(filename=fname, display=scene, include_list=['colors.inc'])
                
        except:
            log.exception("FRAME=%i: Catched exception in the cinematic thread!" % frames)
            
        svc.cinematic_lock.release()
scene.title = "Superhopf-3D"
#scene.autoscale = False       # automatic scaling (default)
scene.userspin = True        # the user can rotate the scene
scene.userzoom = True        # user can zoom in and out of the scene.
scene.fullscreen = False
#scene.autocenter = True

#--- Creation des points dans l'espace
listOfPts = initPts( xmin, xmax, ymin, ymax, npts )
num_image = 1

while t<tmax:
    rate(500)
    one_step( listOfPts, a, sig, dt )

    t = t + dt
    print t

    # export vers POV
    if doPov:
        if num_image % 10 == 0:
	
	    outputRep = "/home/mestivier/Progs/SuperHopf/vPython/PovOutput"
            outputBasename = "sh%010i.pov" % num_image
    
            filename = os.path.join( outputRep, outputBasename )
            povexport.export( filename = filename )
            print filename
        num_image = num_image + 1

Exemple #4
0
scene.center = vector(0,0.5,0)
scene.forward = vector(-.3,0,-1)
gslabel = label(pos=vector(1.5,2,0), text='VPython', color=color.blue, align='left', box=0, line=0)
box(pos=vector(-2,0,0), size=vector(.3,2.5,2.5), pov_texture='T_Wood24')
box(pos=vector(.25,-1.4,0), size=vector(4.8,.3,2.5), pov_texture='T_Wood24')
cylinder(pos=vector(-2,2,1.25), radius=0.7, axis=vector(0,0,-2.5), color=color.red)
ball = sphere(pos=vector(2,1,0), radius=0.5, color=color.cyan)
ptr = arrow(pos=vector(0,0,2), axis=vector(2,0,0), color=color.yellow)
cone(pos=vector(-2,0,0), radius=1, length=3, color=color.green, opacity=0.3)
ring(pos=vector(.2,0,0), radius=.6, axis=vector(1,0,0), thickness=0.12, color=color.gray(0.4))
ellipsoid(pos=vector(-.3,2,0), color=color.orange, size=vector(.3,1.5,1.5))
pyramid(pos=vector(.3,2,0), color=vector(0,0.5,.25), size=vector(0.8,1.2,1.2))
spring = helix(pos=vector(2,-1.25,0), radius=0.3, axis=vector(0,1.8,0),
        color=color.orange, thickness=.1)
angle = 0
da = .01

trail = curve(color=color.magenta, radius= .02)
trail.append(vector(1,0,0))
trail.append(vector(1,0,2))
trail.append(vector(2,0,2))

while angle < 3*pi/4:
  ptr.rotate(angle=da, axis=vector(0,0,1), origin=ptr.pos)
  trail.append(ptr.pos+ptr.axis)
  angle += da

inclist = ['colors.inc', 'stones.inc', 'woods.inc', 'metals.inc']
scene.pause('Adjust the camera, then click to export to POV-ray.')
povexport.export(canvas=scene, filename='VPobjects.pov', include_list=inclist)
Exemple #5
0
def main():

    # TEST
    #HT = '300'
    #WD = '450'
    #finFrame = '30'

    # PRODUCTION Rotate Video Parameters
    HT = '1200'
    WD = '1800'
    finFrame = '120'

    # parse the command line options
    args = vt.parseCMD() 
    fileName = args.fileNames[0]
    outType = args.output
 
    # check if images already exist in current directory.  If not, create them.
    if glob.glob('*png*') == []:

        # get cell lengths
        cellDims, excDims = vt.getCellDimensions(fileName)
        L = float(cellDims[0])
        Ly = float(cellDims[1])
        Lz = float(cellDims[2])
        if len(excDims) > 0:
            ay = float(excDims[0])
            az = float(excDims[1])
        else:
            ay, az = None, None

        # Load the configurations from disk	
        numFrames,wl = vt.loadPIMCPaths(fileName)
        print 'Number of frames: ',numFrames
        
        paths = []
        for t in range(numFrames):
            paths.append(vt.Path(wl[t],Ly,Lz))

        # choose frame number from (g)ce-wl file.
        numFrame = 0

        # time slice info.
        M = paths[numFrame].numTimeSlices
        dM = 1.0*L/(1.0*(M-1))
        
        # ----- This is where you define cell characteristics -----------------
        scene = vis.display(title='World Lines!!',x=0, y=0, 
                width=800, height=844,
                center=(0,0,0), background=(1.0,1.0,1.0))
        scene.autoscale = 0
        
        # Set up excluded volume
        if len(excDims)>0:
            excVol = vis.box(pos=(0,0,0), length=L, 
                    height=ay, width=az, opacity=0.7)

        # Set up cell walls
        cellWalls = vis.box(pos=(0,0,0), length=L, 
                height=Ly, width=Lz, opacity=0.05)

        # The boundary of the simulation box in space-time -- 1D
        #ymax = -0.5*L + (M-1)*dM
        #line = [(-0.5*L,-0.5*L,0),(0.5*L,-0.5*L,0),(0.5*L,ymax,0),
        #        (-0.5*L,ymax,0),(-0.5*L,-0.5*L,0)]
        #vis.curve(pos=line,radius=0.20,color=(0.5,0.5,0.5))

        # ---------------------------------------------------------------------

        wl = vt.WLFrame(paths[numFrame], L, Ly, Lz)
        
        # define povray file names
        povFileName = 'wlview.pov'
        iniFileName =  povFileName[:-4]+'.ini'
        
        pov.export(scene, povFileName)

        # -- generate single image with povray --------------------------------
        if outType == 'single':
            command = ('povray', povFileName, 'Height='+HT,'Width='+WD)
            subprocess.check_call(command)

        # -- generate multiple images, same image but rotating about origin ---
        if outType == 'rotate':
            vt.writeINIfile(povFileName,HT,WD,finFrame)

            command = ('povray', iniFileName)
            subprocess.check_call(command)

        # -- generate images showing evolving worldlines ----------------------
        if outType == 'bins':
            # UPDATE THIS!
            '''n = 1
            for p in paths[1:]:
                #		visual.rate(1)
                wl.update(p)
                vt.getScreenShot(n)
                n += 1
            '''
  
    
    # ---- generate video from series of images -------------------------------
    if outType != 'single':
        # check for Mencoder, the video processing utility.
        vt.findMencoder()
        
        # set up bash commands to run mencoder
        command = ('mencoder', 'mf://*.png', '-mf', 'type=png:w=800:h=600:fps=1',
               '-ovc', 'lavc', '-lavcopts', 'vcodec=mpeg4', '-oac', 'copy',
               '-o', 'animatedStuff.avi')

        print "\n\nabout to execute:\n%s\n\n" % ' '.join(command)
        subprocess.check_call(command)

        print "\n The movie was written to 'animatedStuff.avi'"

 
    # try to close visual python window
    try:
        import wx
        wx.Exit()
    except:
        pass
            #            right = scene.forward.cross(scene.up).norm() # unit vector to the right
            #            newforward = vector(scene.forward)
            #            newforward = rotate(newforward, angle=0.05, axis=right)
            #            newforward = rotate(newforward, angle=0.05, axis=scene.up)
            #            scene.forward = newforward
            for dt in cosas:
                dt.visible = False
                del dt
            for i in range(len(pos)):
                ttt = theta[i] * 180.0 / math.pi
                rod = cylinder(pos=tuple(pos[i]), axis=tuple(dis[i]), radius=0.1)
                rod.color = colorAngle(ttt)
                cosas.append(rod)
            count += 1

            povexport.export(display=scene, filename=dir + "images/image" + putzeros(count) + ".pov")

        if viewHistogram:
            angulos = []
            for ang in theta:
                angulos.append(ang * 180.0 / math.pi)
                angulos.append(180.0 - ang * 180.0 / math.pi)
            [x, y] = histogram(0.0, 180.0, angulos, bins)
            ax.clear()
            ax.bar(x, y)
            ax.plot(x1, y1, "r-")
            draw()

    # print count
    #            if i < len(cosas):
    #                cosas[i].pos=tuple(pos[i])
Exemple #7
0
r = ring(frame=f,
         radius=1,
         thickness=0.2,
         color=color.red,
         pov_texture='T_Wood20')

b = box(pos=(0, 0, -3),
        size=(1.0, 0.5, 0.25),
        color=color.magenta,
        frame=f,
        pov_texture='T_Wood19')

x = arange(0, 4, 0.4)
helix = curve(x=x,
              y=0.5 * sin(2 * x),
              z=2 + 0.5 * cos(2 * x),
              radius=0.1,
              color=color.magenta,
              frame=f,
              pov_texture='T_Wood3')

inclist = ['colors.inc', 'stones.inc', 'woods.inc', 'metals.inc']

scene.mouse.getclick()  ## position camera somewhere, then click
print(povexport.version())
print("Begin exporting pov file")
povexport.export(filename="woodexample.pov",
                 display=scene,
                 include_list=inclist)
print("Export finished")
Exemple #8
0
def cinematic_thread(svc, POVdump=None, ACCEL=ACCEL, DT=DT):
    log.info("Cinematic thread started")
    the_world = svc.the_world
    scene = the_world.scene
    picked = None
    frames = -1
    while 1:
        frames += 1
        rate(ACCEL / DT)
        svc.cinematic_lock.acquire()
        try:
            if scene.kb.keys:
                k = scene.kb.getkey()
                if k == "Q":
                    #send event
                    return
            if scene.mouse.events:
                ev = scene.mouse.getevent()
                if ev.release == "left":
                    if picked:
                        the_world.speeds[picked.num] = (
                            (scene.mouse.pos - picked.PV) / DT).astuple()
                        the_world.cinematic_change = 1
                        picked = None
                    else:
                        o = ev.pick
                        if ev.shift and o:
                            if hasattr(o, "id"):
                                svc.node_shift_click(o.id)
                        elif ev.ctrl and o:
                            if hasattr(o, "id"):
                                svc.node_ctrl_click(o.id)
                        else:
                            if hasattr(o, "action"):
                                o.action()
                if ev.drag == "left":
                    if ev.pick and ev.pick.pickable:
                        picked = ev.pick

            if picked:
                picked.PV = picked.pos
                picked.pos = scene.mouse.pos
                picked.V = vector()
                the_world.coords[picked.num] = picked.pos.astuple()
                the_world.speeds[picked.num] = (0.0, 0.0, 0.0)
                the_world.cinematic_change = 1

            the_world.update(DT)
            the_world.update_edges()
            if POVdump is not None:
                fname = POVdump % frames
                povexport.export(filename=fname,
                                 display=scene,
                                 include_list=['colors.inc'])

        except:
            log.exception(
                "FRAME=%i: Catched exception in the cinematic thread!" %
                frames)

        svc.cinematic_lock.release()
       elif s=="r":
       	     ballslice=ballslice+1
	     if ballslice>=len(data[pathNum][0]):
	     	ballslice=len(data[pathNum][0])-1
       elif s=="l":
       	     ballslice=ballslice-1
	     if ballslice<0:
	     	ballslice=0
       elif s=="b":
             mybox.visible=0
       elif s=="B":
             mybox.visible=1
       elif s=="C":
             scene.center=loc
       elif s=="p":
	       povexport.export(filename="export.pov")
       
       print ballslice
       print len(data[pathNum][0])
       ball1.visible=0
       ball2.visible=0
       ball3.visible=0
       ball4.visible=0
       ball5.visible=0
       ball6.visible=0
       ball7.visible=0
       ball8.visible=0
       ball1 = sphere (pos=(data[pathNum,0,ballslice]), radius=0.1, color=color.red)
       ball2 = sphere (pos=(data[pathNum,1,ballslice]), radius=0.1, color=color.red)
       ball3 = sphere (pos=(data[pathNum,2,ballslice]), radius=0.1, color=color.red)
       ball4 = sphere (pos=(data[pathNum,3,ballslice]), radius=0.1, color=color.red)
    # ---Gestion des entrées clavier
    #   n = next
    #   p = previous
    #   f = first
    #   l = last
    elif SCENE.kb.keys:
        ENTRY = SCENE.kb.getkey()
        if ENTRY == "n":
            NO_SIMUL = NO_SIMUL + 1
            TPS = NEWTIME
        elif ENTRY == "p":
            NO_SIMUL = NO_SIMUL - 1
            TPS = NEWTIME
        elif ENTRY == "f":
            NO_SIMUL = 1
            TPS = NEWTIME
        elif ENTRY == "l":
            NO_SIMUL = NB_SIMUL
            TPS = NEWTIME
        else:
            print "Les seules entrées valables sont n pour avancer et p pour reculer"
            TPS = NEWTIME

    # Export POV
    NO_SIMUL_BIS = NO_SIMUL - 1
    BASENAME = "simulation%3.3i.pov" % (NO_SIMUL_BIS)
    FILENAME = os.path.join(POV_OUTPUT, BASENAME)
    povexport.export(filename=FILENAME)
    print FILENAME
Exemple #11
0
               radius=2.5,
               color=color.yellow)
cone001.rotate(axis=khat, angle=-pi / 5.0)

a = arrow(pos=(0, 0, 0), axis=ihat * 3, color=color.cyan, frame=f)

s = sphere(pos=ihat * 3, radius=0.1, color=color.green)
r = ring(frame=f, radius=1, thickness=0.2, color=color.red)

b = box(pos=(0, 0, -3), size=(1.0, 0.5, 0.25), color=color.magenta, frame=f)

x = arange(0, 4, 0.4)
helix = curve(x=x,
              y=0.5 * sin(2 * x),
              z=2 + 0.5 * cos(2 * x),
              radius=0.1,
              color=color.magenta,
              frame=f)

inclist = ['colors.inc', 'stones.inc', 'woods.inc', 'metals.inc']

scene.mouse.getclick()  ## position camera somewhere, then click

import time
start = time.time()
print(povexport.version())
print("Begin exporting pov file")
povexport.export(display=scene, include_list=inclist)
print("Export finished")
##print(time.time() - start)
Exemple #12
0
axis2=vector(0,1.5,0)
axis3=vector(-2,0,0.6)
axis4=vector(0,-1.5,0)

current=0.25
Iarrow1=arrow(pos=corner, axis=axis1, shaft=Ishaft)
Iarrow2=arrow(pos=Iarrow1.pos+Iarrow1.axis, axis=axis2, shaft=Ishaft)
Iarrow3=arrow(pos=Iarrow2.pos+Iarrow2.axis, axis=axis3, shaft=Ishaft)
Iarrow4=arrow(pos=Iarrow3.pos+Iarrow3.axis, axis=axis4, shaft=Ishaft)

force1=current*cross(axis1,Bdirect)
force2=current*cross(axis2,Bdirect)
force3=current*cross(axis3,Bdirect)
force4=current*cross(axis4,Bdirect)

fshaft=0.75
farrow1=arrow(pos=Iarrow1.pos+axis1/2, axis=force1, color=color.red)
farrow2=arrow(pos=Iarrow2.pos+axis2/2, axis=force2, color=color.red)
farrow3=arrow(pos=Iarrow3.pos+axis3/2, axis=force3, color=color.red)
farrow4=arrow(pos=Iarrow4.pos+axis4/2, axis=force4, color=color.red)

tarrow=arrow(pos=vector(0,0,0), axis=cross(axis1,force2)*3, color=color.yellow)

import time
counter=0

while 1:
	scene.mouse.getclick()  ## position camera somewhere, then click
	povexport.export(filename="%1.0_loopTorque.pov" %counter, display=scene)
	print "Export finished"
	counter=counter+1
Exemple #13
0
def main():

    # TEST
    #HT = '300'
    #WD = '450'
    #finFrame = '30'

    # PRODUCTION Rotate Video Parameters
    HT = '1200'
    WD = '1800'
    finFrame = '120'

    # parse the command line options
    args = vt.parseCMD()
    fileName = args.fileNames[0]
    outType = args.output

    # check if images already exist in current directory.  If not, create them.
    if glob.glob('*png*') == []:

        # get cell lengths
        cellDims, excDims = vt.getCellDimensions(fileName)
        L = float(cellDims[0])
        Ly = float(cellDims[1])
        Lz = float(cellDims[2])
        if len(excDims) > 0:
            ay = float(excDims[0])
            az = float(excDims[1])
        else:
            ay, az = None, None

        # Load the configurations from disk
        numFrames, wl = vt.loadPIMCPaths(fileName)
        print 'Number of frames: ', numFrames

        paths = []
        for t in range(numFrames):
            paths.append(vt.Path(wl[t], Ly, Lz))

        # choose frame number from (g)ce-wl file.
        numFrame = 0

        # time slice info.
        M = paths[numFrame].numTimeSlices
        dM = 1.0 * L / (1.0 * (M - 1))

        # ----- This is where you define cell characteristics -----------------
        scene = vis.display(title='World Lines!!',
                            x=0,
                            y=0,
                            width=800,
                            height=844,
                            center=(0, 0, 0),
                            background=(1.0, 1.0, 1.0))
        scene.autoscale = 0

        # Set up excluded volume
        if len(excDims) > 0:
            excVol = vis.box(pos=(0, 0, 0),
                             length=L,
                             height=ay,
                             width=az,
                             opacity=0.7)

        # Set up cell walls
        cellWalls = vis.box(pos=(0, 0, 0),
                            length=L,
                            height=Ly,
                            width=Lz,
                            opacity=0.05)

        # The boundary of the simulation box in space-time -- 1D
        #ymax = -0.5*L + (M-1)*dM
        #line = [(-0.5*L,-0.5*L,0),(0.5*L,-0.5*L,0),(0.5*L,ymax,0),
        #        (-0.5*L,ymax,0),(-0.5*L,-0.5*L,0)]
        #vis.curve(pos=line,radius=0.20,color=(0.5,0.5,0.5))

        # ---------------------------------------------------------------------

        wl = vt.WLFrame(paths[numFrame], L, Ly, Lz)

        # define povray file names
        povFileName = 'wlview.pov'
        iniFileName = povFileName[:-4] + '.ini'

        pov.export(scene, povFileName)

        # -- generate single image with povray --------------------------------
        if outType == 'single':
            command = ('povray', povFileName, 'Height=' + HT, 'Width=' + WD)
            subprocess.check_call(command)

        # -- generate multiple images, same image but rotating about origin ---
        if outType == 'rotate':
            vt.writeINIfile(povFileName, HT, WD, finFrame)

            command = ('povray', iniFileName)
            subprocess.check_call(command)

        # -- generate images showing evolving worldlines ----------------------
        if outType == 'bins':
            # UPDATE THIS!
            '''n = 1
            for p in paths[1:]:
                #		visual.rate(1)
                wl.update(p)
                vt.getScreenShot(n)
                n += 1
            '''

    # ---- generate video from series of images -------------------------------
    if outType != 'single':
        # check for Mencoder, the video processing utility.
        vt.findMencoder()

        # set up bash commands to run mencoder
        command = ('mencoder', 'mf://*.png', '-mf',
                   'type=png:w=800:h=600:fps=1', '-ovc', 'lavc', '-lavcopts',
                   'vcodec=mpeg4', '-oac', 'copy', '-o', 'animatedStuff.avi')

        print "\n\nabout to execute:\n%s\n\n" % ' '.join(command)
        subprocess.check_call(command)

        print "\n The movie was written to 'animatedStuff.avi'"

    # try to close visual python window
    try:
        import wx
        wx.Exit()
    except:
        pass