# Presentation: 524020

## Using the Volume Rendering Plugin

- Accessed via **Define Datamode ---> Plugins ---> Render [new]**

**Range of values to render**

**Histogram of values in underlay dataset**

**Maximum voxel opacity**

**Menu to control scripting (control rendering from a file)**

**Render new image immediately when a control is changed**

**Accumulate a history of rendered images (can later save to an animation)**

**Open color overlay controls**

**Sub-brick to display**

**Name of underlay dataset**

**Pick new underlay dataset**

**Range of values in underlay**

**Change mapping from values in dataset to brightness in image **

**Mapping from values to opacity **

**Cutout parts of 3D volume.**

**Control viewing angles**

**Detailed instructions**

**Force a new image to be rendered**

**Reload values from the dataset**

**Close all rendering windows**

**Show 2D crosshairs**

**Select incremental mode for angle changes **

**Compute many images in a row**

## Volume rendering concepts:
Goal is to create a 2D image consisting of pixels
Each 2D pixel is obtained from data looking down line of sight into 3D volume:

- Goal is to create a 2D image consisting of pixels
- Each 2D pixel is obtained from data looking down line of sight into 3D volume:

- Each 3D voxel contains one numerical value
- Voxel value determines the brightness (or color) of that voxel --- if it is visible
- Voxel value determines the _opacity_ of that voxel:
- Opacity = 0  Transparent (brightness does not contribute to image)
- Opacity = 1  Opaque (nothing behind it along the line will be seen)
- Intermediate values are translucent:
- 	Opacity = 0.5  50% of voxel brightness is added to pixel; voxels farther down the line will contribute to other 50% of pixel result

- If we looked directly from the subject’s right to left, all the data along the white line would contribute to one image pixel

## 3D viewing angles:
	Roll      =   angle about I-S axis
	Pitch    =   angle about L-R axis (after roll rotation)
	Yaw     =   angle about A-P axis (after roll and pitch)
Rendering is CPU and memory intensive --- a fast computer is very desirable
Utility program 3dIntracranial can be used to strip the scalp off of a T1-weighted anatomical volume.  In some cases, this may need to be done with the orig dataset, which may then be written out in Talairach coordinates. 
For example:
		3dIntracranial -anat anat+tlrc -prefix astrip
AFNI can now render datasets that are stored with an arbitrary orientation and voxel size
Datasets are internally re-oriented (see 3dresample) to axial slice order, so that cut directions make sense.  This may take a few seconds, depending on the computer.
Note that axial slice order is the standard for ‘warped’ datasets written out to disk in +acpc or +tlrc coordinates.
The Overlay dataset may also be resampled, so that its grid spacing matches that of the Underlay dataset.

- 	Roll      =   angle about I-S axis
- 	Pitch    =   angle about L-R axis (after roll rotation)
- 	Yaw     =   angle about A-P axis (after roll and pitch)
- Rendering is CPU and memory intensive --- a fast computer is very desirable
- Utility program _**3dIntracranial**_ can be used to strip the scalp off of a T1-weighted anatomical volume.  In some cases, this may need to be done with the **orig** dataset, which may then be written out in Talairach coordinates.
- For example:
- 		**3dIntracranial -anat anat+tlrc -prefix astrip**
- AFNI can now render datasets that are stored with an arbitrary orientation and voxel size
- Datasets are internally re-oriented (see** 3dresample**) to axial slice order, so that cut directions make sense.  This may take a few seconds, depending on the computer.
- Note that axial slice order is the standard for ‘warped’ datasets written out to disk in **+acpc** or **+tlrc** coordinates.
- The Overlay dataset may also be resampled, so that its grid spacing matches that of the Underlay dataset.

## In Talairach view, open the rendering plugin, and choose astrip+tlrc as the underlay dataset
Plugin will load the voxel values, build the histogram, and then be ready to render
Press Draw to make your first image
Press Accumulate, then DynaDraw, then Roll  a few times
Will generate renderings from different angles (i.e., lines of sight)
If DynaDraw is off, then you must press Draw to get a new rendering
 Accumulate on  rendered images are saved, and can be reviewed by using the image viewer slider
This slider does not move you through slices, as it does in the 2D image viewing windows
It just moves you backward and forward in the history of saved rendered images
If you turn Accumulate off, then creating the next rendered image will erase the history
By default, the plugin’s controls (‘widgets’) do not change as you move around in the rendering history
Selecting ScriptLoad widgets will make the widgets display the settings they had when the currently displayed image was rendered

- Plugin will load the voxel values, build the histogram, and then be ready to render
- Press _**Draw**_ to make your first image
- Press _**Accumulate**_, then _**DynaDraw**_, then _**Roll**__ ___ a few times
- Will generate renderings from different angles (i.e., lines of sight)
- If _**DynaDraw**_ is off, then you must press _**Draw**_ to get a new rendering
** **_**Accumulate**_ on  rendered images are saved, and can be reviewed by using the image viewer slider
- This slider _does not_ move you through slices, as it does in the 2D image viewing windows
- It just moves you backward and forward in the history of saved rendered images
- If you turn _**Accumulate**_ off, then creating the next rendered image will erase the history
- By default, the plugin’s controls (‘widgets’) do not change as you move around in the rendering history
- Selecting _**Script**__****__**Load widgets**_ will make the widgets display the settings they had when the currently displayed image was rendered

## Controlling the mappings from voxel value to brightness and opacity:

- Probably want to make white matter be fully white.
- 	Drag #3 Brightness handle up to top, over to white matter value
- Probably want to reduce Opacity to 0 for all low intensity voxels.
- 	Drag #2 Opacity handle to bottom, over to histogram trough value
- Then press _**Draw**_ to force a re-rendering

**Values below “Bot” are equivalent to “Bot”**

**Values above “Top” are equivalent to “Top”**

**Gray and White matter peaks for this SPGR dataset**

**Crv ******** curve between handles**

**# ******** changes number of handles**

**Line ******** restore straight line map**

**‘****Handles’ that let you change the shape of the mapping functions**

**Horizontal axes correspond to voxel values between “Bot” and “Top”**

## Cutouts are for removing parts of the volume so you can see the parts you want:

- Each cutout specifies a sub-volume in space that will be removed from the dataset before rendering (done by setting voxel opacity to zero inside the cutout)
- Multiple cutouts can be combined in two different ways:
-  _**OR**_  all voxels in all cutouts will be removed
-  _**AND**_  only voxels that are in every cutout sub-volume will be removed
-  _**Must Do**_ can be used to force the removal of cutout voxels even if _**AND**_ is active
-  _**OR**_ is equivalent to _**Must Do**_ for all cutouts

**How to combine cutouts**

**Number of cutouts**

**Type of cutout**

**Cutout parameter**

**Force cutout when AND is on**

**Obtain parameter from current AFNI crosshair location**

**Types of cutouts available**

## Most cutout types are controlled by a single numerical parameter determining the position of the cutout
 Right of ’x’ means to cut out all voxels to the right of the given x-coordinates (-x is Right, +x is Left)
Similarly, can cutout everything Anterior to, Posterior to, or Superior to, Inferior to, or Left of a given coordinate position
 Behind..., Below..., Front..., Above... cut out 45o diagonally slanted half-spaces, with respect to the listed planes:

	For example, Above AS-PI is above a plane 
	that slants from the Anterior-Superior front
	of the brain downwards to the Posterior-
	Inferior back of the brain -- that is, halfway
	between a coronal and axial slice

 TT Ellipsoid cuts out the region outside an ellipsoid                           with the same proportions as the Talairach-Tournoux                             Atlas brain

			      This is fun, but not much use  

** **_**Right of**_ ’x’ means to cut out all voxels to the right of the given x-coordinates (-x is Right, +x is Left)
- Similarly, can cutout everything Anterior to, Posterior to, or Superior to, Inferior to, or Left of a given coordinate position
-  _**Behind...**_, _**Below...**_, _**Front...**_, _**Above...**_ cut out 45o diagonally slanted half-spaces, with respect to the listed planes:
- 	For example, _**Above AS-PI**_ is above a plane
- 	that slants from the Anterior-Superior front
- 	of the brain downwards to the Posterior-
- 	Inferior back of the brain -- that is, halfway
- 	between a coronal and axial slice
-  _**TT Ellipsoid**_ cuts out the region outside an ellipsoid                           with the same proportions as the Talairach-Tournoux                             Atlas brain
- 			      This is fun, but not much use

## Cutout type Expr > 0 defines the region to be removed by a general mathematical expression, rather than a single parameter
The expression uses the same syntax as 3dcalc
Variables that can be used are ‘x’, ‘y’, and ‘z’, corresponding to spatial coordinates in the dataset
When using Automate (infra), variable ‘t’ can also be used
The (x, y, z) locations where the expression evaluates to a positive number will be cut out
Example: rendering a slab tilted at an arbitrary angle between coronal (xz-plane) and axial (xy-plane):

- The expression uses the same syntax as _**3dcalc**_
- Variables that can be used are ‘x’, ‘y’, and ‘z’, corresponding to spatial coordinates in the dataset
- When using _**Automate**_ (infra), variable ‘t’ can also be used
- The (x, y, z) locations where the expression evaluates to a positive number will be cut out
- Example: rendering a slab tilted at an arbitrary angle between coronal (xz-plane) and axial (xy-plane):

**width w**

**(y,z)=s*(sin(a),cos(a))****  Slab is parallel to this line            ****s**** = distance along line**

**(y,z)=s*(cos(a),-sin(a))**** Slab is perpendicular to this line**

**z**

**a**

**y**

## The set of points within the slab is described by the inequality
			y  cos(a) - z  sin(a) -s <  1/2w
	for angle=a, slab center offset=s, and slab width=w.  To render a slanted coronal slab 30 mm thick, tilted posteriorly from the vertical of 25o, we would use this for the cutout expression:

		     abs(y*cosd(25)-z*sind(25)-20)-15

	where the sind() and cosd() functions take arguments in degrees, and where the offset has been set to 20 mm (you will have to alter this offset to get the exact position you want)

By using Automate and setting the angle (25 above) and/or the offset (20 above) to depend on ‘t’, we can make a sequence of images where the slab rotates downwards and/or moves backwards

- 			*y ** cos(a) - z ** sin(a) -s** <  1/2w*
- 	for angle=*a*, slab center offset=*s*, and slab width=*w*.  To render a slanted coronal slab 30 mm thick, tilted posteriorly from the vertical of 25o, we would use this for the cutout expression:
- 		     **abs(y*cosd(25)-z*sind(25)-20)-15**
- 	where the **sind()** and **cosd()** functions take arguments in degrees, and where the offset has been set to 20 mm (you will have to alter this offset to get the exact position you want)
- By using _**Automate**_ and setting the angle (25 above) and/or the offset (20 above) to depend on ‘t’, we can make a sequence of images where the slab rotates downwards and/or moves backwards

##  Automate lets you create a large number of renderings at once
Note that most (but not all) number entry boxes have slightly raised borders:

- Note that most (but not all) number entry boxes have slightly raised borders:

- Such boxes can use an expression with the variable ‘t’ when _**Automate**_ is used:
- Turn _**Automate**_ on
- Enter some small number in the _**Frames**_ control (say 5)
- Enter _**70+5*t**_ in the _**Roll**_ control, then press _**Compute**_
- The dataset will be rendered with the variable ‘t’ set to 0, 1, 2, 3, 4 in turn
- That is, t will run from 0 to one less than the number of Frames, and all the raised-border boxes that use expressions with ‘t’ will be evaluated prior to each frame being rendered
- In this example, this will result in a sequence of views of the dataset from different roll angles 70o, 75o, 80o, 85o, 90o
- Can also use ‘t’ in cutout parameters to make cutouts depend on ‘time’
- 2 cutouts, _**Left of**_=**10+3*t** and _**Right of**_=**-10+3*t** will produce a 20 mm thick slice that slides leftwards as t increases
- Can use ‘t’ in more than one raised-border box simultaneously to make complex animations (e.g., _**Roll**_ and _**Cutouts**_ together)
- Put cursor in raised-border box and press _**Enter**_ to have box reset to last numerical value used by _**Automate**_

**With raised border**

**Without raised border**

## Color overlays (e.g., of functional activation maps)
Press the [Overlay] button to open up the panel that controls how functional overlays are generated:

- Press the **[**_**Overlay**_**]** button to open up the panel that controls how functional overlays are generated:

- Controls are similar to _**Define Function**_ for overlaying color on 2D image viewer windows
- Will only discuss differences from 2D overlay control panel

**Determines colors for above-threshold voxels**

**Select ShowThru mode and corresponding percentage**

**Shows current overlay dataset**

**Voxels below threshold will not be colored**

**Sub-bricks for color and thresholding**

**Opacity of colored voxels**

**Show regions from Talairach Atlas**

**Turn overlay coloring on**

**Apply cutouts to overlay**

**‘****Clean up’ small blobs of above-threshold voxels (as in 3dclust)**

##  Color Opacity lets you select the opacity of colored voxels (those that are above the threshold)
Opacity of overlaid voxels is different from the opacity it would have from the underlay dataset at that location
Usually want this to be high (0.5 or above)
Tow special values on this menu:
 Underlay means that the colored voxel’s opacity will be determined by the opacity that it would have from the underlay image
 ShowThru means that colored voxels show through underlay voxels (the ‘glass brain’ effect), no matter how opaque the underlay is
Takes some practice to become accustomed to this type of image
But can be a very useful way to see lots of activation at once:

- Opacity of overlaid voxels is different from the opacity it would have from the underlay dataset at that location
- Usually want this to be high (0.5 or above)
- Tow special values on this menu:
** **_**Underlay**_ means that the colored voxel’s opacity will be determined by the opacity that it would have from the underlay image
** **_**ShowThru**_ means that colored voxels show through underlay voxels (the ‘glass brain’ effect), no matter how opaque the underlay is
- Takes some practice to become accustomed to this type of image
- But can be a very useful way to see lots of activation at once:

- Seeing this animated is especially useful (but hard to publish)