Display Dicom data just received by websocket connection

node->CreateDefaultDisplayNodes() does return “vtkMRMLScalarVolumeNode::CreateDefaultDisplayNodes failed: scene is invalid” as well if I don’t do a set scene.

But the maybe it’s connected to my issue about loading dicom. With a regular 4.10.2 slicer i’m not able to load a dicom series. It result in one black slice. Sample nrrd are working.

I can load a Dicom serie using the add Data function. But i can’t load it using the DCM database , i see the series in the database, i can check metadata, but i cant examine them (button does nothing) and i can’t load them either.

Are there errors in the log?

No, here is a log when i add a Dicom to DB and tried to examine it and load it :

Session start time …: 2019-07-02 10:14:13

Slicer version …: 4.11.0-2019-05-21 (revision a3fce80) linux-amd64 - not installed release

Operating system …: Linux / 4.15.0-54-generic / #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 - 64-bit

Memory …: 7772 MB physical, 976 MB virtual

CPU …: GenuineIntel Intel® Core™ i5-8500 CPU @ 3.00GHz, 6 cores, 6 logical processors

VTK configuration …: OpenGL2 rendering, Sequential threading

Developer mode enabled …: yes

Prefer executable CLI …: yes

Additional module paths …: /home/raphaelbahegne/Dev/Repo/SiStream-Debug-Build/lib/Slicer-4.11/qt-scripted-modules, /home/raphaelbahegne/Dev/Repo/SiStream-Debug-Build/lib/Slicer-4.11/qt-loadable-modules, /home/raphaelbahegne/Dev/Repo/SiStream-Debug-Build/lib/Slicer-4.11/cli-modules

Scripted subject hierarchy plugin registered: Annotations

Scripted subject hierarchy plugin registered: SegmentEditor

Scripted subject hierarchy plugin registered: SegmentStatistics

Switch to module: “Welcome”

Switch to module: “DICOM”

TagCacheDatabase adding table

New patient inserted: 1

New patient inserted as : 1

Need to insert new study: “”

Study Added

Need to insert new series: “”

Series Added

“DICOM indexer has successfully processed 30 files [0.46s]”

Imported a DICOM directory, checking for extensions

Imported a DICOM directory, checking for extensions

A “restore default” in application setting solved my problem. I don’t know what caused thoses troubles.

I’m back to creating nodes.

Ok, i fixed my problem here part of my code if someone want to do same :slight_smile:

long int  val_long, width, height;
for (int sliceNum=0; sliceNum<dcmImageList.count(); sliceNum++)
    DcmDataset *dataSet = dcmImageList[sliceNum].getDataset();
    if(  dataSet != nullptr )
        vtkNew<vtkMRMLScalarVolumeNode> dicomNode;
        width = val_long;
        height = val_long;

        if (sliceNum==0) {
            imageData->SetDimensions(width, height, dcmImageList.count());

        const unsigned short *dicom_buf;
        dataSet->findAndGetUint16Array(DCM_PixelData, dicom_buf);

        E_TransferSyntax xfer = dataSet->getOriginalXfer();
        dataSet->chooseRepresentation(xfer, nullptr);
        DicomImage *di = new DicomImage(dataSet, xfer, 0);

        memcpy(imageData->GetScalarPointer(0,0,sliceNum), di->getOutputData(16), di->getOutputDataSize());
        std::cout << "-------------------empty image--------------------------------" << std::endl;

//this->GetMRMLScene()->AddNewNodeByClass("vtkMRMLScalarVolumeNode", "dicomNode");

(Some dicom infos are hardcoded at the moment)

Few observations :

  • if i use AddNewNodeByClass instead of AddNode it throw “scene invalid” and it does not work
  • CreateDisplayDefaultNodes throw a warning :

Warning: In /home/raphaelbahegne/Dev/Slicer/Libs/MRML/Core/vtkMRMLSubjectHierarchyNode.cxx, line 718
vtkSubjectHierarchyItem (0x562fd3c5c650): FindChildByID: Item cache does not contain requested ID 140486651064064
HasItemAttribute: Failed to find subject hierarchy item by ID 140486651064064

But the image is displayed properly.

this->GetMRMLScene()->AddNewNodeByClass("vtkMRMLScalarVolumeNode", "dicomNode") creates a new node by the name “dicomnode”. The new node has nothing to do with the other node that you created previously. That previously created node is not added to the scene, that’s why you got the error that the scene was invalid.

You can use to use scene->AddNewNodeByClass(...) instead of vtkNew<...> node; scene->AddNode(node). AddNewNodeByClass is simpler (just one method calls instead of two) and it creates the new node with default properties stored in the scene (for volume nodes there is not much to customize but for display or storage nodes the user may have set some non-default values).

Most likely this warning is a false alarm. Do you use latest master version of Slicer?

It got the src and built slicer just 2 month ago, so it’s 4.11.0

Thanks a lot it becomes clearer, and clearer.

Ok i used AddNewNodeByClass but it gives me a vtkMrmlNode not a Scalar volume one.

So it did a cast :

vtkMRMLScalarVolumeNode dicomNode = (vtkMRMLScalarVolumeNode)scene->AddNewNodeByClass(“vtkMRMLScalarVolumeNode”, “dicomNode”);

But it seem a little bit brutal, is there a cleaner way ?

You can use vtkMRMLScalarVolumeNode::SafeDownCast to retrieve a more specific pointer.