Accessing VolumeNode in loadable

I am currently attempting to implement this Python script 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 but still it remains unclear to me how it is performed here using currentNode.

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, …

1 Like

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?