Change axis labels of slice view and 3D view


I’m trying to rename axis labels from medical I, P, A etc to XYZ. I’ve tried to do that in qMyAppMainWindow:

  std::vector<std::string> axesNames({"-X", "X", "-Y", "Y", "-Z", "Z"});

  for (int j = 0; j < this->LayoutManager->threeDViewCount(); j++)
    for (int i = 0; i < axesNames.size(); i++)
          i, axesNames[i].c_str());

  for (const QString& sliceViewName : this->LayoutManager->sliceViewNames())
    for (int i = 0; i < axesNames.size(); i++)
          ->SetAxisLabel(i, axesNames[i].c_str());

and in my custom module but apparently after I have set labels some other module reset it to default values by calling vtkMRMLAbstractViewNode::CopyContent()

I think I need to make a decision either to put the code above to vtkSlicerModuleLogic::OnMRMLSceneNodeAdded(...) of my module or to control the module loading order (though I don’t know how to do that yet).

In vtkSlicerModuleLogic::OnMRMLSceneNodeAdded(vtkMRMLNode* node) I process the newly added node and if it is a slice or 3D view then I change its labels. But I think that changing labels of already existind nodes every time new node is added is not the best way.

Probably someone has a better solution?

Probably you also need to change the axes names in the default view node, similarly to how it is done here.

1 Like

Thank you for the useful info!

I have found that disabling DataProbe module ( --disable-modules DataProbe) solves my problem with resetting axes labels.

@lassoan in the link you gave there is a comment:
# Replace orientation presets in all existing slice nodes and in the default slice node

It is the second time I encounter default node and I can’t understand what it is and what it is aimed to? Especially why default nodes are some kind of a separate nodes as in the example we append them to the list:

sliceNodes = slicer.util.getNodesByClass("vtkMRMLSliceNode")

Thus slicer.util.getNodesByClass("vtkMRMLSliceNode") doesn’t include defaul nodes…

The MRML scene can store an instance of each MRML class, the default node. When you create a new node or reset a node then the default node will be used to set its properties. See some more information in the API documentation.

1 Like

As I understood the default node serves as some kind of a template and the scene may create new nodes of that class with the properties set from that template?

One more thing:
let’s suppose that slicer was launched with the dault layout (single 3D view and three slices). Will that default vtkMRMLSliceNode be one of that three slices or it will be the forth slice node and it is hidden?

The default slice node is used to initialize all slice nodes. The values are also used when the nodes are reset (e.g., when the scene is closed).

1 Like