[slicer-users] Automated rendering using VolumeRendering Module

Thomas Ballinger tomb at bwh.harvard.edu
Wed Jun 23 12:00:29 EDT 2010


In case anyone else has the issue, Slicer.tk.tk.eval('update') works great
for forcing an update in a script.
Thanks Steven (and everyone),
Tom Ballinger

On Tue, Jun 22, 2010 at 7:28 AM, Steve Pieper <pieper at bwh.harvard.edu>wrote:

> Hi Yanling, Alex -
>
> Can you look at this and see if there is any reason volume rendering
> wouldn't be rendering correctly?
>
> Tom, the one idea I have is for you to add this call before calling
> SlicerSaveLargeImage:
>
>  Slicer.tk.tk.eval('update')
>
> I'd be curious if that changes anything.
>
> -Steve
>
>
> -------- Original Message --------
> Subject:        Re: [slicer-users] Automated rendering using
> VolumeRendering
> Module
> Date:   Mon, 21 Jun 2010 10:40:25 -0400
> From:   Thomas Ballinger <tomb at bwh.harvard.edu>
> To:     Steve Pieper <pieper at bwh.harvard.edu>
>
>
>
> Steve,
> I've attached the full thing that I import, but what I think are the
> relevant sections are below, the really relevant parts in bold.  This
> was mostly written before I'd explored the API so much, so I ended up
> doing a long of math that wasn't necessary.
>
> scene = Slicer.slicer.MRMLScene
> cam = scene.GetNodeByID('vtkMRMLCameraNode1')
> appli = Slicer.slicer.ApplicationGUI
> slicesgui = appli.GetSlicesGUI()
> firstslicegui = slicesgui.GetNthSliceGUI(0)
> firstslicelogic = firstslicegui.GetLogic()
> camera = cam.GetCamera()
>
> final = tempfile.mkdtemp()
> currentPictureNumber = 0
>
> *def saveDisplay():
>     global currentPictureNumber
>     filename = final+'/'+str(currentPictureNumber)+'.png'
>     Slicer.tk.tk.eval('SlicerSaveLargeImage %s 1'%filename)
>     currentPictureNumber = currentPictureNumber + 1*
>
> def exportMovie(moviename,r=30,q=8):
> """Uses ffmpeg to make a movie from the images taken so far"""
>
>
> a=subprocess.Popen(['/projects/schiz/ra/tomb/ffmpeg/ffmpeg/ffmpeg','-i',final+'/%d.png','-qmax',str(q),'-r','-y',str(r),moviename])
>     os.waitpid(a.pid,0)
>     os.system('nautilus '+os.path.abspath(os.path.dirname(moviename))+' &')
>
> def checkMovie():
> """Uses eog to view your image files"""
>     os.system('eog '+final+'/* &')
>
> def saveRotatePics(theta,phi,howManyFrames=0,save=True,timeDelay=0):
> # This is physics spherical coordinates, not wikipedia ones
>     if not howManyFrames:
>         save=False
>         howManyFrames = 2
>     theta = float(theta)
>     phi = float(phi)
>     theta = theta * (2 * math.pi) / 360
>     phi = phi*(2 * math.pi) / 360
>     (startx,starty,startz) = camera.GetPosition()
>     r = math.sqrt(startx**2+starty**2+startz**2)
>     startTheta = math.atan2(starty,startx)
>     startPhi = math.acos(startz/r)
>     dTheta = theta / (howManyFrames - 1)
>     dPhi = phi / (howManyFrames - 1)
>     for i in range(howManyFrames):
>         theta = startTheta + dTheta*i
>         phi = startPhi + dPhi*i
>         x = r * math.sin(phi) * math.cos(theta)
>         y = r * math.sin(phi) * math.sin(theta)
>         z = r * math.cos(phi)
>         cam.SetPosition(x,y,z)
>         if save:
> *            camera.Modified()
>             appli.GetActiveRenderWindowInteractor().Render()
>             appli.UpdateMain3DViewers()
>             saveDisplay()
> *
> def saveZoomAndPanPics(r,u,f,howFar,howManyFrames=0,save=True,timeDelay=0):
>     howManyFrames = int(howManyFrames)
>     if not howManyFrames:
>         save=False
>         howManyFrames = 2
>     r = float(r)
>     u = float(u)
>     f = float(f)
>     (startfx,startfy,startfz) = camera.GetFocalPoint()
>     (startpx,startpy,startpz) = camera.GetPosition()
>     distFromFocalPoint =
> math.sqrt((startpx-startfx)**2+(startpy-startfy)**2+(startpz-startfz)**2)
>     if howFar >= distFromFocalPoint:
>         return False
>     (upx,upy,upz) = camera.GetViewUp()
>     cameraToFocalPoint = [startfx-startpx,startfy-startpy,startfz-startpz]
>     norm = numpy.linalg.norm(cameraToFocalPoint)
>     (fdx,fdy,fdz) = cameraToFocalPoint/norm
>     (rightx,righty,rightz) = numpy.cross([upx,upy,upz],[fdx,fdy,fdz])
>     dx = (r*rightx+u*upx+f*fdx)/(howManyFrames-1)
>     dy = (r*righty+u*upy+f*fdy)/(howManyFrames-1)
>     dz = (r*rightz+u*upz+f*fdz)/(howManyFrames-1)
>     zdx = (howFar*fdx)/(howManyFrames-1)
>     zdy = (howFar*fdy)/(howManyFrames-1)
>     zdz = (howFar*fdz)/(howManyFrames-1)
>     for i in range(howManyFrames):
>         camera.SetFocalPoint(startfx+dx*i,startfy+dy*i,startfz+dz*i)
>
>
> camera.SetPosition(startpx+(dx+zdx)*i,startpy+(dy+zdy)*i,startpz+(dz+zdz)*i)
>         if save:
> *            camera.Modified()
>             appli.GetActiveRenderWindowInteractor().Render()
>             appli.UpdateMain3DViewers()
>             saveDisplay()
>
> *
> On Fri, Jun 18, 2010 at 3:36 PM, Steve Pieper <pieper at bwh.harvard.edu
> <mailto:pieper at bwh.harvard.edu>> wrote:
>
>    Hi Thomas -
>
>    Can you send the scripts you are using so we can have a look?
>
>    -Steve
>
>
>    On Jun/18/10 11:20 AM, Thomas Ballinger wrote:
>
>        I've been using Slicer to create short videos of sometimes complex
>        scenes.  Of particular use has been the tcl script
>        "SlicerSaveEachRender", but in order to get smoother rotations,
>        pans and
>        zooms I've been using python bindings to rotate the camera and
>        call the
>        tcl script SlicerSaveLargeImage repeatedly.  I've been calling
>        ApplicationGUI.UpdateMain3DViewers() to update the scene before
>        saving
>        the picture, which seems like overkill, but has been working
>        fine for
>        ordinary models.  However, VolumeRendering models don't seem to get
>        updated this way.  Setting camera.Modified() will update the
>        view once
>        my script stops, but not for each camera move.
>
>        What can I call to update a rendered model after changing the
>        camera so
>        I can save the new rendered image?
>
>        Thanks,
>
>        Thomas Ballinger
>
>
>
>        _______________________________________________
>        slicer-users mailing list
>        slicer-users at bwh.harvard.edu <mailto:slicer-users at bwh.harvard.edu>
>
>        http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>        To unsubscribe: send email to
>        slicer-users-request at massmail.spl.harvard.edu
>        <mailto:slicer-users-request at massmail.spl.harvard.edu> with
>        unsubscribe as the subject
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://massmail.spl.harvard.edu/pipermail/slicer-users/attachments/20100623/eeee4c8b/attachment.html>


More information about the slicer-users mailing list