Lua and sequences

  • Hi,


    I use a Lua RetrieveResultConverter to adapt archived RT data from Helax TMS to newer treatment planning without modifying the archived data.
    Now I run into a problem in sequences:
    Some sequences like '(300a,00b6)-BeamLimitingDeviceSequence' are of unknown length.
    I did not succeed with Lua functions like
    'bldmax=#Data.ExposureSequence[ex].BeamLimitingDeviceSequence' or
    'bldmax=table.getn(Data.ExposureSequence[ex].BeamLimitingDeviceSequence)'
    because of type 'userdata'.
    To point out the problem I used this Lua function as RetrieveResultConverter for RTIMAGE from our linac

    Code
    function rrc0() writedicom(Data,Data.SOPInstanceUID..'-before') if Data.Modality=='RTIMAGE' then print('RTImage from',Data.RadiationMachineName) ex=0 while Data.ExposureSequence and Data.ExposureSequence[ex] and Data.ExposureSequence[ex].BeamLimitingDeviceSequence do print(' Exposure #',ex,' Frame=',Data.ExposureSequence[ex].ReferencedFrameNumber) bld=0 while Data.ExposureSequence[ex].BeamLimitingDeviceSequence and Data.ExposureSequence[ex].BeamLimitingDeviceSequence[bld] and Data.ExposureSequence[ex].BeamLimitingDeviceSequence[bld].RTBeamLimitingDeviceType do print(' BeamLimitingDevice #',bld,'=',Data.ExposureSequence[ex].BeamLimitingDeviceSequence[bld].RTBeamLimitingDeviceType) bld=bld+1 end -- BeamLimitingDeviceSequence ex=ex+1 end -- ExposureSequence end writedicom(Data,Data.SOPInstanceUID..'-after')end


    There is no explicit modification of 'Data' in the lua function, but the dump of the dicom file saved at the end of the function shows additional empty sequence elements:


    If the receiving system is another conquest, I can't see these empty elements in the header dump of the gui, but they are sent over the network and Masterplan chokes on RTPLANs containing such sequence elements reporting parsing errors.
    Access to the not existing 'Data.ExposureSequence[1]' in line 7 of the function doesn't give result 'nil' but generates an empty sequence element as I further tested. It is not possible to destroy the empty element after the loop by 'Data.ExposureSequence[ex]=nil' after line 18.


    What is the recomended way to parse sequences without this result?


    Gerald

  • Hi Gerald,


    is see this is an issue. To read data without creating empty sequence try this kind of test, i.e., use direct array access:


    if Data[ExposureSequence.' .. ex .. '.BeamLimitingDeviceSequence' ] ~= nil then



    Marcel

  • Hi Marcel,


    probably it's not the right syntax I used.
    I tried
    print(Data['ExposureSequence']) -> userdata:... may be, this really exists
    print(Data['ExposureSequence.0.BeamLimitingDeviceSequence.0.RTBeamLimitingDeviceType']) -> userdata:... I expected 'MLCX' in the example above
    print(Data['ExposureSequence.1']) -> userdata:... this sequence element doesn't exist, I expected 'nil'
    print(Data['ExposureSequence.5.BeamLimitingDeviceSequence']) -> userdata:...


    There are no more empty sequence elements in Data but also no information about existing and non-existing elements.
    Please correct me.


    Gerald

  • In 1 4.16e (just released), there is an # (length) operator implemented:


    print('------ test read/write Data --------')
    Data.PatientName = Data.PatientID
    Data.ReferencedStudySequence = {}
    print(#Data.ReferencedStudySequence); -- prints 0
    print('This is a sequence: ', Data.ReferencedStudySequence);
    Data.ReferencedStudySequence[0].StudyInstanceUID = Data.StudyInstanceUID
    Data.ReferencedStudySequence.StudyInstanceUID = Data.StudyInstanceUID
    Data.ReferencedStudySequence[1].StudyInstanceUID = Data.StudyInstanceUID
    print(#Data.ReferencedStudySequence); -- prints 2
    print('This is a sequence item: ', Data.ReferencedStudySequence[0].StudyInstanceUID);


    Marcel

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!