# How to get a ROI to fit volume in the Volume Rendering module with python?

**URL:** <https://discourse.slicer.org/t/how-to-get-a-roi-to-fit-volume-in-the-volume-rendering-module-with-python/18793>\
**Category:** Support\
**Tags:** python\
**Created:** [July 19, 2021, 12:06am UTC](https://discourse.slicer.org/t/how-to-get-a-roi-to-fit-volume-in-the-volume-rendering-module-with-python/18793 "2021-07-19T00:06:26Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [July 25, 2021, 12:14pm UTC](https://discourse.slicer.org/t/how-to-get-a-roi-to-fit-volume-in-the-volume-rendering-module-with-python/18793/7 "2021-07-25T12:14:28Z")

</div>

> [@jumbojing](#):
>
> > [@Juicy](#):
> >
> > ````auto
> > > # Create a new ROI
> > roiNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLAnnotationROINode")
> > # Make new parameter node in order to use the crop volume module programmatically
> > crop_module = slicer.vtkMRMLCropVolumeParametersNode()
> > # Add parameter node to the scene
> > slicer.mrmlScene.AddNode(crop_module)
> > # Set the volume as the input volume in the crop volume module
> > crop_module.SetInputVolumeNodeID(volumeNode.GetID())
> > # Set output volume as the same volume to overwrite original volume (only needed if you actually want to crop the volume)
> > crop_module.SetOutputVolumeNodeID(volumeNode.GetID())
> > # Set the input ROI
> > crop_module.SetROINodeID(roiNode.GetID())
> > # Use the Fit ROI to Volume function of the crop volume module
> > slicer.modules.cropvolume.logic().FitROIToInputVolume(crop_module)
> > > ```
> > 
> > ````

```auto
roiNode.SetName("ROI")
roiNode.SetXYZ(PP)
roiNode.SetRadiusXYZ(50, 50, 50)

```

我是这样定义ROI大小的…

---

_[View the full topic](https://discourse.slicer.org/t/how-to-get-a-roi-to-fit-volume-in-the-volume-rendering-module-with-python/18793)._
