# Accessing VolumeNode in loadable

**URL:** https://discourse.slicer.org/t/accessing-volumenode-in-loadable/25580
**Category:** Development
**Tags:** loadable-module
**Created:** [October 6, 2022, 3:51pm UTC](https://discourse.slicer.org/t/accessing-volumenode-in-loadable/25580 "2022-10-06T15:51:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@leo](https://discourse.slicer.org/u/leo)
#### Post date: [October 6, 2022, 3:51pm UTC](https://discourse.slicer.org/t/accessing-volumenode-in-loadable/25580/1 "2022-10-06T15:51:04Z")

</div>

I am currently attempting to implement this [Python script](https://discourse.slicer.org/t/tracking-cursor-movements-to-access-voxel-values/24568/7) in a loadable module in order to acces voxels. My attempts until node ended always with my custom module breaking. My understanding right now is that the way I try to acces the MRMLVolumeNode might by the issue.  
` vtkMRMLVolumeNode* inputVolumeNode;`  
`vtkWeakPointer<vtkMRMLCrosshairNode> crosshairNode;`  
`vtkGeneralTransform* transform_ras_to_volume_ras;`  
`double ras[4] = { 0,0,0 };`  
`vtkMRMLScene* scene;`  
`double ijk_point[4] = { 0, 0, 0, 1 };`  
`vtkMRMLVolumeNode* volumeNode = vtkMRMLVolumeNode::SafeDownCast(scene->GetFirstNodeByName("MRHead"));`  
as my program seems to be breaking at this last step.  
I have had a look a different ways to acces the data like in this case using vtkImageData to acces [voxels](https://discourse.slicer.org/t/access-image-pixel-values-in-loadable/904) but still it remains unclear to me how it is performed here using currentNode.

---

<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: [October 6, 2022, 7:12pm UTC](https://discourse.slicer.org/t/accessing-volumenode-in-loadable/25580/2 "2022-10-06T19:12:49Z")

</div>

Do you have a node by the name `MRHead` in the scene?

What is your overall goal?

Would you like to use C++ to do some expensive computations? If yes, then you don’t need to mess with crosshairs and with getting a node from scene in C++, etc. Just write the computation code in C++ and call that from Python. The Python code would take care of everything (getting the current volume node, cursor position, etc.) except the lengthy computation. Or, you can compute quickly in Python, by operating on arrays and not on individual voxels, or using libraries, such as VTK, ITK, numpy, …

---

<div class="post-metadata">

### Author: ![leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@leo](https://discourse.slicer.org/u/leo)
#### Post date: [October 10, 2022, 3:46pm UTC](https://discourse.slicer.org/t/accessing-volumenode-in-loadable/25580/3 "2022-10-10T15:46:56Z")

</div>

Thankyou, for your reply. Indeed I have a Volume by the name of MRHead in the scene. I would need to get the voxel values at the mouse positions since I need to perform computation based on their Gray scale values and this would need to happen in a fast running loop. Have you got any recommendations for resources or different paths to take?
