# Independent zoom along different axes

**URL:** <https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263>\
**Category:** Development\
**Created:** [August 18, 2021, 10:45pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263 "2021-08-18T22:45:49Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 18, 2021, 10:45pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/1 "2021-08-18T22:45:50Z")

</div>

Hi,

I’m working on Slicer CAT where I need to display different 3D data (the data represent the geological objects) in XYZ domain where X, Y axes - has the meaning of geographic coordinates (meters) and Z - is the depth (zero is the ocean water level) or time (meters or milliseconds). Right handed coordinate system: X-to the east, Y-to the north, Z-out of the Earth.

I need to provide ability to zoom Z-axis independently from X and Y. That leads that the scales along X,Y will differ from Z-axis.

Maybe Slicer already has such opportunity? If not maybe you have some recommendations/links and especially should I implement it in Slicer core library via Slicer-github pull request or only in my Slicer CAT?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 18, 2021, 11:03pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/2 "2021-08-18T23:03:40Z")

</div>

Yes, all of that should be pretty doable. You could have a look at SlicerAstro, which also adapted a lot of things to deal with different coordinate meanings so I’d think a lot of the hooks that @Davide_Punzo added will be of use to you.

> **[GitHub - Punzo/SlicerAstro: Astronomy (HI) extension for 3DSlicer...](https://github.com/Punzo/SlicerAstro)**
>
> Astronomy (HI) extension for 3DSlicer (https://www.slicer.org/) - GitHub - Punzo/SlicerAstro: Astronomy (HI) extension for 3DSlicer (https://www.slicer.org/)

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 18, 2021, 11:07pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/3 "2021-08-18T23:07:23Z")

</div>

Thank you,

Is there precompiled bindary of Slicer Astro for Windows?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 18, 2021, 11:12pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/4 "2021-08-18T23:12:45Z")

</div>

In general, yes, you can just install the extension.

[https://www.slicer.org/wiki/Documentation/4.10/Extensions/SlicerAstro](https://www.slicer.org/wiki/Documentation/4.10/Extensions/SlicerAstro)

But it looks like there may be a [build issue on windows](https://slicer.cdash.org/viewBuildError.php?buildid=2364700) currently. Looks like mac and linux are working.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 19, 2021, 12:18am UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/5 "2021-08-19T00:18:18Z")

</div>

I’m trying to build Slicer Astro but there are some things…

My slicer cat (named Colada) is in `C:/C` and the build folder `C:/C/d`.  
Slicer Astro is in `C:/A` and the build folder `C:/A/d`.

Then I do (using IDE though the commands should be similar):

```auto
cd C:/A/d
cmake .. -DSlicer_DIR=C:/C/d/Slicer-build
cmake --build .

```

Then I can see that only `SlicerAstroWelcome` module is built. Can’t understand why…

How to add this extension to my Slicer CAT? Do I need to add all the path to Slicer Astro’s built modules (via `Edit-\>Application Settings-\>Modules-\>add)?

If I try to execute `C:\A\d\SlicerWithSlicerAstro.exe` in cmd I get:

```auto
PS C:\A\d> ./SlicerWithSlicerAstro.exe
error: File specified using --launcher-additional-settings argument does NOT exist ! [C:/A/d/AdditionalLauncherSettings.ini]
Usage
  Colada [options]

Options
  --launcher-help Display help
  --launcher-version Show launcher version information
  --launcher-verbose Verbose mode
  --launch Specify the application to launch
  --launcher-detach Launcher will NOT wait for the application to finish
  --launcher-no-splash Hide launcher splash
  --launcher-timeout Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
  --launcher-load-environment Specify the saved environment to load.
  --launcher-dump-environment Launcher will print environment variables to be set, then exit
  --launcher-show-set-environment-commands Launcher will print commands suitable for setting the parent environment (i.e. using 'eval' in a POSIX shell), then exit
  --launcher-additional-settings Additional settings file to consider
  --launcher-additional-settings-exclude-groups Comma separated list of settings groups that should NOT be overwritten by values in User and Additional settings. For example: General,Application,ExtraApplicationToLaunch
  --launcher-ignore-user-additional-settings Ignore additional user settings
  --launcher-generate-exec-wrapper-script Generate executable wrapper script allowing to set the environment
  --launcher-generate-template Generate an example of setting file
  --VisualStudioProject Open Visual Studio Slicer project with Slicer's DLL paths set up
  --cmd Start cmd
  --designer Start Qt designer using Slicer plugins
  --VisualStudio Open Visual Studio with Slicer's DLL paths set up
PS C:\A\d>

```

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 19, 2021, 11:53am UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/6 "2021-08-19T11:53:24Z")

</div>

I just saw that slicer astro is unix only

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 20, 2021, 2:33pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/7 "2021-08-20T14:33:03Z")

</div>

I have installed Slicer Astro on Ubuntu, definately there are some useful features.  
But I can’t find a way to make independent zooming along chosen axis…  
Perhaps I postpone this task for a while and try get a little experience of writing/modifying Slcier’s widgets that are on the scene (on the picture, I think they are called `qMRMLwidgets`)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/f/ef88e3897a5e5ea72f7bb9e6581ab26c48350d01.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 20, 2021, 3:39pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/8 "2021-08-20T15:39:03Z")

</div>

This question has come up before and I think setting slice field of view manually worked acceptably for that use case. However, it would be a much cleaner solution to simply apply a transform to the volume that scales it down along an axis.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 20, 2021, 3:45pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/9 "2021-08-20T15:45:30Z")

</div>

> [@lassoan](#):
>
> However, it would be a much cleaner solution to simply apply a transform to the volume that scales it down along an axis.

I’m afraid that I need to work in XYZ coordinate system and all the data (not only volumes, but everything that is on scene) must be hard linked to axes… But thank you, I’m going to take some time to investigate the problem

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 20, 2021, 5:02pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/10 "2021-08-20T17:02:00Z")

</div>

Could ypu please give a hint how to acieve widgets from the scene and add widgets there (widgets are shown on the picture)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/1/a1cc123e855dc8852ba9474c57100760fd92e2e5.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 20, 2021, 5:42pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/11 "2021-08-20T17:42:58Z")

</div>

> [@keri](#):
>
> I’m afraid that I need to work in XYZ coordinate system and all the data (not only volumes, but everything that is on scene) must be hard linked to axes…

You can apply linear transforms to all node types, not just volumes. Also, you can unregister default measurements in markups nodes and register your own custom measurements that take into account the changed scale when reporting length/area/volume values.

> [@keri](#):
>
> Could ypu please give a hint how to acieve widgets from the scene and add widgets there (widgets are shown on the picture)

There should be examples for this in the script repository, but the idea is that you l get widgets via the layout manager and then manipulate child widgets using standard Qt API.

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [August 20, 2021, 11:56pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/12 "2021-08-20T23:56:12Z")

</div>

Hi,

In SlicerAstro there isn’t s feature to zoom just one axis. However you could easily add in Python some widgets (e.g. sliders) in the slide pop up menu on which you could modify the field of view of the slice (i.e. you modify the attributes of the MRML slice object associated to the slice widget). Modifying the mouse zooming interaction is more complicated.

In general, regarding a full coordinates customization, you may have a look at the custom classes in the AstroVolumes module (the MRMLDM classes and the widgets, something like SlicerAstroController etc…) and few tweaks in Python (SlicerAstroDataProde module). The implementation is mainly in C++ and somewhat tricky if you don’t have a full picture of Slicer infrastructure.

Cheers,  
Davide.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 21, 2021, 4:41pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/13 "2021-08-21T16:41:44Z")

</div>

Thank you, I have found example how to customize 3d view and slice widgets [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#customize-widgets-in-view-controller-bars).

@Davide_Punzo thank you for explanation. Step by step I’m getting known with Slicer philosophy. Probably a little later I will come back to this task and reread this topic. I guess that should help me

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [August 22, 2021, 3:02pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/14 "2021-08-22T15:02:10Z")

</div>

It seems that I can set [transform to the vtkCamera](https://discourse.vtk.org/t/scaling-a-rendering-scene/173/4?u=kerim). And I tested with VTK 9.0.1 it works.

```cpp
  vtkNew<vtkTransform> transform;
  transform->Scale(2, 1, 1);

  renderer->GetActiveCamera()->SetModelTransformMatrix(transform->GetMatrix());

```

Though there are some problems that is connected with `vtkCubeAxesActor`.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/0/00b3c26df9bc6275bd4060e7159e5ec15a960198.png)

P.S. as I have previously created [topic dedicated to adding vtkCubeAxesActor to the Slicer’s scene](https://discourse.slicer.org/t/add-an-actor-vtkcubeaxesactor-to-the-scene-in-c/19294), I think I should discuss the mentionned problem there.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [September 1, 2021, 7:51pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/15 "2021-09-01T19:51:39Z")

</div>

I’m trying to set transfrom on camera but it seems that this only affect on 3D view:

```python
# Getting camera from 3D view
layoutManager = slicer.app.layoutManager()
view = layoutManager.threeDWidget(0).threeDView()
threeDViewNode = view.mrmlViewNode()
cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDViewNode)

# Getting camera
renderWindow = view.renderWindow()
renderers = renderWindow.GetRenderers()
renderer = renderers.GetItemAsObject(0)
camera = cameraNode.GetCamera()

# Create `transform` object and set scales for it
transform = vtk.vtkTransform()
transform.Scale(2, 1, 1)

# Apply transform to the camera
camera.SetModelTransformMatrix(transform.GetMatrix())

```

With this I get scaled 3D view but none of the Slice view is affected by scale. It seems that there is no camera on Slice view.

I understand that I can apply transform directly on volume but in this case coordinates of my object will be broken. I need to keep the original coordinates of object untouched…

What can I do to apply independently scale axes in slice view? I don’t fully understand yet how what are slice-views represented in sense of VTK objects, but probably I could set fake camera on them?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 2, 2021, 11:41pm UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/16 "2021-09-02T23:41:08Z")

</div>

You can change the aspect ratio of slice views by simply setting the desired field of view in the slice node.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [September 3, 2021, 12:45am UTC](https://discourse.slicer.org/t/independent-zoom-along-different-axes/19263/17 "2021-09-03T00:45:51Z")

</div>

Thank you very much!

With this I see how to solve my issue with zooming. At least I think so 🙂
