# Can the API returned from the onCreated prop be used to manipulate a second volume generated at a time after the initial volume?

**URL:** https://discourse.vtk.org/t/can-the-api-returned-from-the-oncreated-prop-be-used-to-manipulate-a-second-volume-generated-at-a-time-after-the-initial-volume/6603
**Category:** Web
**Created:** [September 10, 2021, 2:52pm UTC](https://discourse.vtk.org/t/can-the-api-returned-from-the-oncreated-prop-be-used-to-manipulate-a-second-volume-generated-at-a-time-after-the-initial-volume/6603 "2021-09-10T14:52:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shanebenlolo](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@shanebenlolo](https://discourse.vtk.org/u/shanebenlolo)
#### Post date: [September 10, 2021, 2:52pm UTC](https://discourse.vtk.org/t/can-the-api-returned-from-the-oncreated-prop-be-used-to-manipulate-a-second-volume-generated-at-a-time-after-the-initial-volume/6603/1 "2021-09-10T14:52:57Z")

</div>

Hello,

I am working on the OHIF viewer to extend the functionality provided by the VTK extension. The current feature I am working on now is adding fusion. At this point, I have successfully brought in a second volume for fusion, but now I am trying to manipulate that layer using VTK’s native methods, by utilizing the API that is provided on the creation of the View2D / View3D components.

Here is a code snippet of the API I am referring to:

```auto
const mergeProps = (propsFromState, propsFromDispatch, ownProps) => {
  const { afterCreation } = propsFromState;

  const props = {
    ...propsFromState,
    ...propsFromDispatch,
    ...ownProps,
    /**
     * Our component sets up the underlying dom element on "componentDidMount"
     * for use with VTK.
     *
     * The onCreated prop passes back an Object containing many of the internal
     * components of the VTK scene. We can grab a reference to these here, to
     * make playing with VTK's native methods easier.
     *
     * A similar approach is taken with the Cornerstone extension.
     */
    onCreated: api => {
      // Store the API details for later
      //setViewportSpecificData({ vtkApi: api });

      if (afterCreation && typeof afterCreation === 'function') {
        afterCreation(api);
      }
    },
  };
  return props;
};

```

the full code can be found here [Viewers/ConnectedVTKViewport.js at master · OHIF/Viewers · GitHub](https://github.com/OHIF/Viewers/blob/master/extensions/vtk/src/ConnectedVTKViewport.js)

My problem is that when I initialize the View2D / View3D components, they do not have 2 volumes, only the initial CT scan. It is not until a user picks a corresponding PET scan to perform fusion with that a second volume is generated. Therefore, the API provided to me is not aware of the second volume and I cannot use it to implement VTK’s native methods.

Am I able to simply push my second volume into the `volumes` array within the API? Or does the API need to be aware of any volumes it will be manipulating upon instantiation? Thanks for any help you can offer.

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [September 23, 2021, 4:34pm UTC](https://discourse.vtk.org/t/can-the-api-returned-from-the-oncreated-prop-be-used-to-manipulate-a-second-volume-generated-at-a-time-after-the-initial-volume/6603/2 "2021-09-23T16:34:51Z")

</div>

Hi, this appears to be an OHIF-specific question. I’d first see if there is an API to tell OHIF that you’ve updated the `volumes` array in order to render your second volume.
