Changes between Version 3 and Version 4 of Examples/Brain


Ignore:
Timestamp:
04/11/17 12:37:34 (7 years ago)
Author:
Herwig Zilken
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Examples/Brain

    v3 v4  
    5656   dset[i, : , :]=v
    5757
    58 
    5958print "success"
    6059fout.close()
    61 
    6260}}}
    6361
    6462== Creating XDMF Files
    65 !ParaView needs proper XDMF files to be able to read the data from a hdf5 file. We generated two xdfm files by hand. One for the fullsize dataset, and one for loading a spatial subsampled version via a hyperslab.
    66 
    67 The xdmf file for the fullsize dataset is quite simple an defines just the uniform rectilinear grid with one attribute. It is a very good practize to normalize the spatial extend of the grid by setting the grid spacing accordingly. We decided that the grid should have the extend "1.0" in the direction on its largest axis.
    68 So the grid spacing is 1.0/31076=3.21792e-5 for the Y- and Z-axis. The X-axis is the direction of the slice cutting, therefore it's grid spacing is larger by a factor of 40, resulting in 40*3.21792e-5=1.2872e-3.
     63!ParaView needs proper XDMF files to be able to read the data from a hdf5 file. We generated two xdfm files by hand. One for the fullsize dataset, and one to be able to load a spatial subsampled version via a hyperslab.
     64
     65The xdmf file for the fullsize dataset is quite simple an defines just the uniform rectilinear grid with one attribute. It is a very good practise to normalize the spatial extend of the grid by setting the grid spacing accordingly. We decided that the grid should have the extend "1.0" in the direction on its largest axis.
     66So the grid spacing is 1.0/31076=3.21792e-5 for the Y- and Z-axis. The X-axis is the direction where the slices are cut. Therefore it's grid spacing is larger by a factor of 40, resulting in 40*3.21792e-5=1.2872e-3.
     67The origin of the grid was set to its center.
    6968
    7069'''Fullsize Version:'''
     
    9594}}}
    9695
    97 As the dataset is relatively large (200 GB), we decided to generate a second xdmf file which only reads a subsampled version of the data (every 4th pixel in Y- and Z-direction, 12.5 GB). This can be done via the "hyperslab" construct and adds a little bit more complexity to the description. Please note that the grid spacing has to be adapted to the subsampled grid size accordingly.
     96As the dataset is relatively large (200 GB), we decided to generate a second xdmf file which only reads a subsampled version of the data (every 4th pixel in Y- and Z-direction, 12.5 GB). This is conventiant because the loading time is much shorter and the handling of the data is more fluent. The subsampling can be done via the "hyperslab" construct in the xdmf file and adds a little bit more complexity to the description. Please note that the grid spacing has to be adapted to the subsampled grid size accordingly.
    9897
    9998'''Subsampled Version:'''
     
    129128</Domain>
    130129</Xdmf>
    131 
    132130}}}
    133131
     
    139137
    140138== Generating the movie with a Python script
     139In the next sections the resulting Python script is shown step by step.
     140=== Preliminary Steps
     141First of all one has to import paraview.simple and open a view of the correct size (e.g. 1920x1080=fullHD or 3840x2160=4K).
     142{{{
     143#!python
     144#### import the simple module from the paraview
     145from paraview.simple import *
     146
     147Connect() #connect to build in paraview
     148#also possible to connect to pvserver, e.g. pv.Connect('localhost')
     149
     150paraview.simple._DisableFirstRenderCameraReset()
     151
     152# get active view
     153renderView = CreateRenderView('RenderView')
     154renderView.UseOffscreenRendering = 1
     155renderView.ViewSize = [1920*2, 1080*2]
     156}}}
     157
     158=== Loading the Data
     159The data is loaded and then visualized with the [http://www.ospray.org/ OSPRay] volume renderer:
     160{{{
     161#!python
     162vervet = XDMFReader(FileNames=['/homeb/zam/zilken/JURECA/projekte/hdf5_inm_converter/Vervet_Sehrinde_rightHem_direction/data/vervet_hyperslab.xdmf'])
     163vervet.PointArrayStatus = ['PLI']
     164vervet.GridStatus = ['Brain']
     165print "loading vervet data"
     166vervetDisplay = Show(vervet, renderView)
     167vervetDisplay.VolumeRenderingMode = 'OSPRay Based'
     168vervetDisplay.SetRepresentationType('Volume')
     169vervetDisplay.ColorArrayName = ['POINTS', '']
     170vervetDisplay.OSPRayScaleArray = 'PLI'
     171vervetDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
     172vervetDisplay.SelectOrientationVectors = 'None'
     173vervetDisplay.ScaleFactor = 0.09998712839442306
     174vervetDisplay.SelectScaleArray = 'PLI'
     175}}}
     176
     177=== Camera Animation: Path-based
     178To orbit around the data (rotate the data), the camera can be animated in orbit mode. The CameraTrack and the AnimationScene are used in conjunction with two keyframes to render 100 images:
     179{{{
     180#!python
     181cameraAnimationCue1 = GetCameraTrack(view=renderView)
     182animationScene = GetAnimationScene()
     183
     184# create first keyframe
     185# Note: this one keyframe stores all orbit camera position in PositionPathPoints
     186keyFrame5157 = CameraKeyFrame()
     187keyFrame5157.Position = [0.0, 0.0, 1.488]
     188keyFrame5157.ViewUp = [-1.0, 0.0, 0.0]
     189keyFrame5157.ParallelScale = 0.6825949417738006
     190keyFrame5157.PositionPathPoints = [0.0, 0.0, 1.488, 0.0, 1.1563931906479727, 0.9364287418821582, 0.0, 1.455483629891903, -0.30937259593682587, 0.0, 0.6755378636124458, -1.3258177079922915, 0.0, -0.6052241248967907, -1.3593556409721905, 0.0, -1.437297629518134, -0.3851227391125512, 0.0, -1.2038172876299222, 0.8746244554111999]
     191keyFrame5157.FocalPathPoints = [0.0, 0.0, 0.0]
     192keyFrame5157.ClosedPositionPath = 1
     193
     194# create last keyframe
     195keyFrame5158 = CameraKeyFrame()
     196keyFrame5158.KeyTime = 1.0
     197keyFrame5158.Position = [0.0, 0.0, 1.488]
     198keyFrame5158.ViewUp = [-1.0, 0.0, 0.0]
     199keyFrame5158.ParallelScale = 0.6825949417738006
     200
     201# initialize the animation track
     202cameraAnimationCue1.Mode = 'Path-based'
     203cameraAnimationCue1.KeyFrames = [keyFrame5157, keyFrame5158]
     204
     205numFrames = 100
     206imageNum = 0
     207animationScene.NumberOfFrames = numFrames
     208animationScene.GoToFirst()
     209for i in range(numFrames):
     210  print ("orbit state: rendering image %04d" % (imageNum))
     211  WriteImage("image_%04d.png" % (imageNum))
     212  imageNum = imageNum + 1
     213  animationScene.GoToNext()
     214}}}
     215
     216=== Camera Animation: Interpolate Camera
     217For whatever reason !ParaView offers a second option for camera animation, called "interpolate camera".
     218In this mode, the Position-, !FocalPoint- and !ViewUp-vectors of a given number of keyframes are interpolated.
     219This way a camera flight consisting of 2, 3 or more keyframes can be animated. Here is an example for 3 keyframes.
     220{{{
     221#!python
     222# create key frame 1
     223keyFrame1 = CameraKeyFrame()
     224keyFrame1.KeyTime = 0.0
     225keyFrame1.Position = [0.0, 0.0,  1.488]
     226keyFrame1.FocalPoint = [0.0, 0.0, 0.0]
     227keyFrame1.ViewUp = [-1.0, 0.0, 0.0]
     228keyFrame1.ParallelScale = 0.8516115354228021
     229# create key frame 2
     230keyFrame2 = CameraKeyFrame()
     231keyFrame2.KeyTime = 0.14
     232keyFrame2.Position = [-0.28, -0.495, 1.375]
     233keyFrame2.FocalPoint = [-0.00016, -0.0003, -4.22e-5]
     234keyFrame2.ViewUp = [-0.981, 0.0255, -0.193]
     235keyFrame2.ParallelScale = 0.8516115354228021
     236# create key frame 2
     237keyFrame3.KeyTime = 1.0
     238keyFrame3.Position = [-0.0237, -0.092, 0.1564]
     239keyFrame3.FocalPoint = [-0.000116651539708215, -0.000439441275715884, -9.75944360306001e-05]
     240keyFrame3.ViewUp = [-0.98677511491576, -0.0207684556984332, -0.160759272923493]
     241keyFrame3.ParallelScale = 0.8516115354228021
     242
     243cameraAnimationCue1.KeyFrames = [keyFrame1, keyFrame2, keyFrame3]
     244cameraAnimationCue1.Mode = 'Interpolate Camera'
     245numFrames = 200
     246animationScene.NumberOfFrames = numFrames
     247
     248animationScene.GoToFirst()
     249imageNum = 0
     250
     251for i in range(numFrames):
     252  print ("rendering image %04d" % (imageNum))
     253  WriteImage("picture_%04d.png" % (imageNum))
     254  imageNum = imageNum + 1
     255  animationScene.GoToNext()
     256}}}