Public
Edited
Jul 3, 2023
Fork of Hello vtk.js
1 fork
11 stars
Insert cell
Insert cell
elevationMap(elevation_data, image)
Insert cell
function elevationMap(
elevation_data,
image,
opts = {
xSpacing: 0.01568,
ySpacing: 0.01568,
zScaling: 0.06666
}
) {
// In Observable, we really don't want the fullScreenRenderer that nearly all the examples are using
// this version forces it into a container
const fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance(
{
rootContainer: document.createElement("div"),
containerStyle: { width: `${width}px`, height: "600px" }
}
);

const vtkActor = vtk.Rendering.Core.vtkActor,
vtkElevationReader = vtk.IO.Misc.vtkElevationReader,
vtkMapper = vtk.Rendering.Core.vtkMapper,
vtkTexture = vtk.Rendering.Core.vtkTexture;

// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------

const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();

// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------

const reader = vtkElevationReader.newInstance(opts);
const mapper = vtkMapper.newInstance();
const actor = vtkActor.newInstance();

mapper.setInputConnection(reader.getOutputPort());
actor.setMapper(mapper);

renderer.addActor(actor);
renderer.resetCamera();
renderWindow.render();

// Apply Texture
if (image) {
const texture = vtkTexture.newInstance();
texture.setInterpolate(true);
texture.setImage(image);
actor.addTexture(texture);
renderWindow.render();
}

// Download elevation and render when ready
const elevation_url = "data:text/csv;" + d3.csvFormatRows(elevation_data);
reader.setUrl(elevation_url).then(() => {
renderer.resetCamera();
renderWindow.render();
});

return Object.assign(html`${fullScreenRenderer.getContainer()}`, {
value: fullScreenRenderer
});
}
Insert cell
vtk = import("https://cdn.skypack.dev/vtk.js?min").then(() => window.vtk)
Insert cell
__BASE_PATH__ = "https://kitware.github.io/vtk-js"
Insert cell
Insert cell
image = d3.image(`${__BASE_PATH__}/data/elevation/dem.jpg`, {
crossOrigin: "anonymous"
})
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more