# Getting output of a widget as ImageData

**URL:** https://discourse.vtk.org/t/getting-output-of-a-widget-as-imagedata/13638
**Category:** Web
**Created:** [March 27, 2024, 8:15am UTC](https://discourse.vtk.org/t/getting-output-of-a-widget-as-imagedata/13638 "2024-03-27T08:15:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yippiez](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yippiez/32/8636_2.png) [@yippiez](https://discourse.vtk.org/u/yippiez)
#### Post date: [March 27, 2024, 8:15am UTC](https://discourse.vtk.org/t/getting-output-of-a-widget-as-imagedata/13638/1 "2024-03-27T08:15:10Z")

</div>

Hello, when using the [ImageCroppingWidget](https://kitware.github.io/vtk-js/api/Widgets_Widgets3D_ImageCroppingWidget.html) (example [here](https://kitware.github.io/vtk-js/examples/ImageCroppingWidget.html)) is it possible to get the [ImageData](https://kitware.github.io/vtk-js/api/Common_DataModel_ImageData.html) of the object?

It is hinted [here](https://discourse.vtk.org/t/how-do-i-save-the-widgets/9014/2) that the underlying volume from widgets are possible to save as `ImageData` using `vtkXMLImageDataWriter`, and thats exactly what i am trying to do.

Setting [vtkVolume](https://kitware.github.io/vtk-js/api/Rendering_Core_Volume.html#getVolumes) as the input yields an error since the `vtkVolume` class doesn’t have the `getExtent` function ([source](https://github.com/Kitware/vtk-js/blob/cebd291431ec8be98782f5ddd0e42cc310e19bcf/Sources/IO/XML/XMLImageDataWriter/index.js#L23))

```javascript
const writer = vtkXMLImageDataWriter.newInstance();
writer.setFormat(vtkXMLWriter.FormatTypes.ASCII);
// writer.setCompression(true);
const data = writer.write(vtkVolume);

```

I have tried getting the ImageData object from the mapper itself but i couldn’t find a function to get the output data from the mapper in the documentation of the [VolumeMapper](https://kitware.github.io/vtk-js/api/Rendering_Core_VolumeMapper.html#getBlendMode), [AbstractMapper](https://kitware.github.io/vtk-js/api/Rendering_Core_AbstractMapper.html#Source) or [Mapper](https://kitware.github.io/vtk-js/api/Rendering_Core_Mapper.html#getArrayAccessMode). I have also tried to find a function that crop widget itself but as far as i can tell the cropwidget usess the VolumeMapper to do the actual cropping while itself is just providing a interface for the input slice planes.

My questions are

- Is there a straightforward way to get the output data from Volume, VolumeMapper or WidgetStates?
- If so could they be combined with other widgets to get a single ImageData?
- If not is there a way to get the ImageData from the `model` instead of the `publicAPI` using the `get` function?
- If not is the recommended method to get cropping parameters from the widget and apply it to `ImageCropFilter` in the background, essantialy recomputing the cropping operation?

Thanks

---

<div class="post-metadata">

### Author: ![yippiez](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yippiez/32/8636_2.png) [@yippiez](https://discourse.vtk.org/u/yippiez)
#### Post date: [March 29, 2024, 9:44am UTC](https://discourse.vtk.org/t/getting-output-of-a-widget-as-imagedata/13638/2 "2024-03-29T09:44:56Z")

</div>

For anyone else with the same issue, i went with `"geting cropping parameters from the widget and apply it to ImageCropFilte in the background"` everything works as expected and computation overhead seems to be minimal.

Here is the code to update the filter:

```javascript
let cropFilter = ...
...
cropFilter.setCroppingPlanes(widget.getWidgetState().getCroppingPlanes().getPlanes());
cropFilter.update();

```
