Skip to content
Michael Martinez edited this page Mar 9, 2019 · 9 revisions

How To Access Viewer Data

The root, globally named reference for all Papaya viewer instances is papayaContainers. This array contains one item per viewer instance (as more than one Papaya viewer instance can be created on a page). If you only have a single instance on a page, you can access it like so:

var myContainer = papayaContainers[0];

The class structure of every Papaya viewer instance is as follows:

So to access the base volume of your viewer, you can use:

var vol = papayaContainers[0].viewer.screenVolumes[0].volume;

For example, to find the image dimensions of the viewer, you can use:

var dims = papayaContainers[0].viewer.screenVolumes[0].volume.header.imageDimensions;
console.log(dims.xDim + " " + dims.yDim + " " + dims.zDim);

API Methods

The following functions are added as a convenience for dynamically interacting with Papaya.

/* Reset a viewer.
 * {Number} index index of the Papaya container to reset (0 for a single viewer)
 * {Array} params array of parameters (optional)
 */
papaya.Container.resetViewer(index[, params])
/* Removes an overlay image.
 * {Number} index index of the Papaya container to reset (0 for a single viewer)
 * {Number} imageIndex index of the image to remove (>= 1 for overlays)
 */
papaya.Container.removeImage(index, imageIndex)
/* Adds an overlay image.
 * {Number} index index of the Papaya container to reset (0 for a single viewer)
 * {String} imageRef the image url or file reference
 * {Object} imageParams an associative array specifying image parameters (optional)
 */
papaya.Container.addImage(index, imageRef[, imageParams])

/* Example */
papaya.Container.addImage(index, "data/myImage.nii.gz", {{"myImage.nii.gz" : { <some params> }}})
/* Hides an image.
 * {Number} index index of the Papaya container to reset (0 for a single viewer)
 * {Number} imageIndex index of the image to hide (0 for base image, >0 for overlays)
 */
papaya.Container.hideImage(index, imageIndex)
/* Shows an image.
 * {Number} index index of the Papaya container to reset (0 for a single viewer)
 * {Number} imageIndex index of the image to show (0 for base image, >0 for overlays)
 */
papaya.Container.showImage(index, imageIndex)
/* Dynamically add a viewer.
 * {String} id the HTML id of the element in which to add a Papaya container
 * {Array} params array of parameters (optional)
 * {Function} callback (optional)
 */
papaya.Container.addViewer(id, params, callback)
/* Starts Papaya.  Typically called in the window load() event, if for whatever 
 * reason a Papaya container is generated dynamically after the page loads, you 
 * should call this function.
 */
papaya.Container.startPapaya()
Clone this wiki locally