# VTK - Template --{{0}}-- This document defines some basic macros for applying [VTKjs](https://kitware.github.io/vtk-js/examples/) in [LiaScript](https://LiaScript.github.io), to make VTK programs in Markdown executeable and editable. __Try it on LiaScript:__ https://liascript.github.io/course/?https://raw.githubusercontent.com/liaTemplates/vtk/master/README.md __See the project on Github:__ https://github.com/liaTemplates/vtk --{{1}}-- There are three ways to use this template. The easiest way is to use the `import` statement and the url of the raw text-file of the master branch or any other branch or version. But you can also copy the required functionionality directly into the header of your Markdown document, see therefor the [last slide](#5). And of course, you could also clone this project and change it, as you wish. {{1}} 1. Load the macros via `import: https://raw.githubusercontent.com/liaTemplates/vtk/master/README.md` 2. Copy the definitions into your Project 3. Clone this repository on GitHub ## `VTK.eval` --{{0}}-- Simply attach the macro `VTK.eval` to your Markdown code-block to make it executable and editable. This macro requires only one parameter, the id of the div, that is inserted to be the target for the viewer. You will have to use this id in your script again, see line 1. ```js var view = document.getElementById("view_cone"); var fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance({ rootContainer: view, containerStyle: { height: '100%', overflow: 'hidden' }, background: [0, 0, 0] }); var actor = vtk.Rendering.Core.vtkActor.newInstance(); var mapper = vtk.Rendering.Core.vtkMapper.newInstance(); var cone = vtk.Filters.Sources.vtkConeSource.newInstance(); actor.setMapper(mapper); mapper.setInputConnection(cone.getOutputPort()); var renderer = fullScreenRenderer.getRenderer(); renderer.addActor(actor); renderer.resetCamera(); var renderWindow = fullScreenRenderer.getRenderWindow(); renderWindow.render(); ``` @VTK.eval(view_cone) ## `VTK.run` --{{0}}-- If you only want to execute your VTK script, you can use the macro `VTK.run` with the block notation. Simply add it to the head of the of the code-block together with the id of target div. ```js @VTK.run(view_cone_2) var view = document.getElementById("view_cone_2"); var fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance({ rootContainer: view, containerStyle: { height: '100%', overflow: 'hidden' }, background: [0, 0, 0] }); var actor = vtk.Rendering.Core.vtkActor.newInstance(); var mapper = vtk.Rendering.Core.vtkMapper.newInstance(); var cone = vtk.Filters.Sources.vtkConeSource.newInstance(); actor.setMapper(mapper); mapper.setInputConnection(cone.getOutputPort()); var renderer = fullScreenRenderer.getRenderer(); renderer.addActor(actor); renderer.resetCamera(); var renderWindow = fullScreenRenderer.getRenderWindow(); renderWindow.render(); ``` ## `VTK.load` > __Note:__ This might take a while, to load and render the vti data set within the browser. @VTK.load(https://data.kitware.com/api/v1/file/58e665158d777f16d095fc2e/download) ## `VTK.loadIframe` @VTK.loadIframe(https://kitware.github.io/vtk-js-datasets/data/vti/head-binary-zlib.vti) ## Implementation ``` html script: https://unpkg.com/vtk.js @VTK.eval
@end @VTK.run
@end @VTK.loadIframe @end @VTK.load: @VTK._load_(@uid,`@0`) @VTK._load_
@end ```