Exemplo n.º 1
0
def generate_mr_signed_in_short_range(out_dir, patient_id):
    sb = StudyBuilder(patient_position="HFS",
                      patient_id=patient_id,
                      patients_name="MrSigned^InShortRange",
                      patients_birthdate="20121212")
    ct = sb.build_mr(num_voxels=[48, 64, 10],
                     voxel_size=[4, 3, 4],  # [mm]
                     pixel_representation=get_pixel_representation('signed'))
    ct.clear(stored_value=0)
    ct.add_box(size=[25, 50, 5], center=[0, 0, 0], stored_value=12345, mode='set')

    # Smallest stored value is: 0 (in short range)
    # Largest stored value is: 12345 (in short range).

    mk_fresh_dir(out_dir)
    sb.write(out_dir)
    print out_dir
Exemplo n.º 2
0
def generate_pt_unsigned_not_in_short_range(out_dir, patient_id):
    sb = StudyBuilder(patient_position="HFS",
                      patient_id=patient_id,
                      patients_name="PtUnsigned^NotInShortRange",
                      patients_birthdate="20121212")
    pt = sb.build_pt(num_voxels=[48, 64, 10],
                     voxel_size=[4, 3, 4],  # [mm]
                     pixel_representation=get_pixel_representation('unsigned'),
                     rescale_slope=1)
    pt.clear(stored_value=0)
    pt.add_box(size=[25, 50, 5], center=[0, 0, 0], stored_value=54321, mode='set')

    # Smallest stored value is: 0 (in short range)
    # Largest stored value is: 54321 (greater than 32767).

    mk_fresh_dir(out_dir)
    sb.write(out_dir)
    print out_dir
Exemplo n.º 3
0
def generate_ct_unsigned_rescaled_in_short_range(out_dir, patient_id):
    sb = StudyBuilder(patient_position="HFS",
                      patient_id=patient_id,
                      patients_name="CtUnsigned^InShortRange",
                      patients_birthdate="20121212")
    ct = sb.build_ct(num_voxels=[48, 64, 10],
                     voxel_size=[4, 3, 4],  # [mm]
                     pixel_representation=get_pixel_representation('unsigned'),
                     rescale_slope=1,
                     rescale_intercept=-1024)
    ct.clear(stored_value=0)
    ct.add_box(size=[25, 50, 5], center=[0, 0, 0], stored_value=12345, mode='set')

    # Smallest rescaled value is: 1 * 0 - 1024 = -1024 (in short range)
    # Largest rescaled value is: 1 * 54321 - 1024 = 11321 (in short range).

    mk_fresh_dir(out_dir)
    sb.write(out_dir)
    print out_dir
Exemplo n.º 4
0
        elif series.modality == "RTSTRUCT":
            for structure in series.structures:
                structure = structure.split(",")
                shape = structure[0]
                if shape == 'sphere':
                    name = structure[1]
                    radius = float(structure[2])
                    interpreted_type = structure[3]
                    if len(structure) > 4:
                        center = [float(c) for c in structure[4].lstrip('[').rstrip(']').split(";")]
                    else:
                        center = [0,0,0]
                    rtstruct.add_sphere(name=name, radius=radius, center=center, interpreted_type=interpreted_type)
                elif shape == 'box':
                    name = structure[1]
                    size = structure[2]
                    if size.startswith("[") and size.endswith("]"):
                        size = [float(c) for c in size.lstrip('[').rstrip(']').split(";")]
                    else:
                        size = [float(size),float(size),float(size)]
                    interpreted_type = structure[3]
                    if len(structure) > 4:
                        center = [float(c) for c in structure[4].lstrip('[').rstrip(']').split(";")]
                    else:
                        center = [0,0,0]
                    rtstruct.add_box(name=name, size=size, center=center, interpreted_type=interpreted_type)
                elif shape == "external":
                    rtstruct.add_external_box()
            rtstruct.build()
sb.write(args.outdir)
Exemplo n.º 5
0
        elif series.modality == "RTSTRUCT":
            for structure in series.structures:
                structure = structure.split(",")
                shape = structure[0]
                if shape == 'sphere':
                    name = structure[1]
                    radius = float(structure[2])
                    interpreted_type = structure[3]
                    if len(structure) > 4:
                        center = [float(c) for c in structure[4].lstrip('[').rstrip(']').split(";")]
                    else:
                        center = [0, 0, 0]
                    rtstruct.add_sphere(name=name, radius=radius, center=center, interpreted_type=interpreted_type)
                elif shape == 'box':
                    name = structure[1]
                    size = structure[2]
                    if size.startswith("[") and size.endswith("]"):
                        size = [float(c) for c in size.lstrip('[').rstrip(']').split(";")]
                    else:
                        size = [float(size), float(size), float(size)]
                    interpreted_type = structure[3]
                    if len(structure) > 4:
                        center = [float(c) for c in structure[4].lstrip('[').rstrip(']').split(";")]
                    else:
                        center = [0, 0, 0]
                    rtstruct.add_box(name=name, size=size, center=center, interpreted_type=interpreted_type)
                elif shape == "external":
                    rtstruct.add_external_box()
            rtstruct.build()
sb.write(args.outdir)
Exemplo n.º 6
0
rtstruct = sb.build_structure_set()
rtstruct.add_external_box()
sph = rtstruct.add_sphere(radius=70,
                          center=[-50, 0, -100],
                          name='Sph-Organ',
                          interpreted_type='CAVITY')
sph2 = rtstruct.add_sphere(radius=25,
                           center=[0, 0, 0],
                           name='Sph-PTV',
                           interpreted_type='PTV')

rtplan = sb.build_static_plan()
b1 = rtplan.build_beam(gantry_angle=180, collimator_angle=15, meterset=100)
b1.conform_to_rectangle(1, 1, [0, 0])

rtplan.build(finalize_mlc=False)

modules.conform_mlc_to_roi(b1.rtbeam, sph.roi_contour, sb.current_study)
modules.conform_mlc_to_roi(b1.rtbeam, sph2.roi_contour, sb.current_study)
b1.finalize_mlc()

sb.write(tmpdir)
print tmpdir

import plotting as p

p.plot_cp(rtplan.datasets[0].Beams[0], rtplan.datasets[0].Beams[0].CPs[0])
p.plot_roi_in_cp(rtplan.datasets[0].Beams[0],
                 rtplan.datasets[0].Beams[0].CPs[0], sph.roi_contour,
                 sb.current_study)
pp.axis('image')
Exemplo n.º 7
0
ct.add_sphere(radius = 25, center = [0,0,0], real_value = -1000, mode = 'set')
print ct.pixel_array.max(),ct.pixel_array.min()
ct.add_box(size = [25,50,25], center = [0,0,0], stored_value = 300, mode = 'add')
print ct.pixel_array.max(),ct.pixel_array.min()

assert sb.seriesbuilders['CT'] == [ct]

rtstruct = sb.build_structure_set()
rtstruct.add_external_box()
rtstruct.add_sphere(radius = 25, center = [0,0,0], name='Sph-PTV', interpreted_type='PTV')
rtstruct.add_box(size = [25,50,25], center = [0,0,0], name='Box-Organ', interpreted_type='CAVITY')

rtplan = sb.build_static_plan()
b1 = rtplan.build_beam(gantry_angle = 0, meterset = 100)
b1.conform_to_circle(25, [0,0])
b2 = rtplan.build_beam(gantry_angle = 120, meterset = 91)
b2.conform_to_rectangle(25, 50, [0,0])
b3 = rtplan.build_beam(gantry_angle = 240, meterset = 71)
b3.conform_to_rectangle(50, 25, [50,-50])
assert rtplan.beam_builders == [b1,b2,b3]

rtplan.build()

rtdose = sb.build_dose()
for beam in rtplan.beam_builders:
    rtdose.add_lightfield(beam.rtbeam, beam.meterset)


sb.write(tmpdir)
print tmpdir
print ct.pixel_array.max(),ct.pixel_array.min()
ct.add_sphere(radius = 25, center = [0,0,0], real_value = -1000, mode = 'set')
print ct.pixel_array.max(),ct.pixel_array.min()
ct.add_box(size = [25,50,25], center = [0,0,0], stored_value = 300, mode = 'add')
print ct.pixel_array.max(),ct.pixel_array.min()

assert sb.seriesbuilders['CT'] == [ct]

rtstruct = sb.build_structure_set()
rtstruct.add_external_box()
rtstruct.add_sphere(radius = 25, center = [0,0,0], name='Sph-PTV', interpreted_type='PTV')
rtstruct.add_box(size = [25,50,25], center = [0,0,0], name='Box-Organ', interpreted_type='CAVITY')

rtplan = sb.build_static_plan()
b1 = rtplan.build_beam(gantry_angle = 0, meterset = 100)
b1.conform_to_circle(25, [0,0])
b2 = rtplan.build_beam(gantry_angle = 120, meterset = 91)
b2.conform_to_rectangle(25, 50, [0,0])
b3 = rtplan.build_beam(gantry_angle = 240, meterset = 71)
b3.conform_to_rectangle(50, 25, [50,-50])
assert rtplan.beam_builders == [b1,b2,b3]

rtplan.build()

rtdose = sb.build_dose()
for beam in rtplan.beam_builders:
    rtdose.add_lightfield(beam.rtbeam, beam.meterset)


sb.write("/tmp/studybuilder")