Empty volumes for labellayer and foregroundlayer


I am new to using VTK,

I am getting background layer just fine with the right HU values. However, when I pull out labellayer from slicelogic and use the function getvolume. It is always nullptr. On my screen I can see there are segmentations.

Here is my code so far,

  QStringList theList;
  QString text;
  int* ijk = new int[0, 0, 0];
  double* xyz;
  std::map<QString, vtkMRMLSliceLayerLogic*> layerLogic;
  vtkMRMLVolumeNode* volumeNode;
  vtkImageData* imageData;
  vtkMRMLSliceNode* sliceNode;
  vtkMRMLCrosshairNode* crossHair;
  qDebug() << "Updating current logic";
  crossHair = vtkMRMLCrosshairNode::SafeDownCast(

  if (crossHair) sliceNode = crossHair->GetCursorPositionXYZ(xyz);

  if (sliceNode == nullptr) return theList;
  vtkSlicerApplicationLogic* appLogic = vtkSlicerApplicationLogic::SafeDownCast(
  if (appLogic == nullptr) return theList;
  d->sliceLogic = vtkMRMLSliceLogic::SafeDownCast(
  if (d->sliceLogic == nullptr) return theList;

  layerLogic["B"] = vtkMRMLSliceLayerLogic::SafeDownCast(d->sliceLogic->GetBackgroundLayer());
  layerLogic["F"] = vtkMRMLSliceLayerLogic::SafeDownCast(d->sliceLogic->GetForegroundLayer());
  layerLogic["L"] = vtkMRMLSliceLayerLogic::SafeDownCast(d->sliceLogic->GetLabelLayer());

  int i = 0;
  for (auto& layer : layerLogic) {
    text = "";
    if (layer.second == nullptr) {
      qDebug() << layer.first << " has is empty";
    qDebug() << "Get volume: ";
    volumeNode = vtkMRMLVolumeNode::SafeDownCast(

After this I print which layers have no volume.

Thanks if anyone can help