def build_orientation(patient_position, column_direction, row_direction, frame_of_reference_uid = None):
    sb = StudyBuilder(patient_position=patient_position, patient_id="smallValuesUInt32", patient_name="smallValuesUInt32", patient_birthdate = "20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position,)
    print "ct"
    ct = sb.build_ct(
        num_voxels=[7, 7, 7],
        voxel_size=[3, 3, 3],
        pixel_representation=0,
        rescale_slope=1,
        rescale_intercept=-1024,
        row_direction=row_direction,
        column_direction=column_direction)
    ct.clear(real_value = -1000)
    ct.add_box(size = [4,4,4], center = [0,0,0], real_value = 0)
    ct.add_box(size = [20,4,4], center = [0,-8,-8], real_value = 0)
    ct.add_box(size = [4,20,4], center = [8,0,-8], real_value = 0)
    ct.add_box(size = [4,4,20], center = [8,8,0], real_value = 0)
    ct.add_sphere(radius = 4, center = [-8,-8,-8], real_value = 0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size = [4,4,4], center = [0,0,0], name='CenterVoxel', interpreted_type='SITE')
    rtstruct.add_box(size = [20,4,4], center = [0,-8,-8], name='x=-8 to 8, y=z=-8', interpreted_type='SITE')
    rtstruct.add_box(size = [4,20,4], center = [8,0,-8], name='y=-8 to 8 x=8, z=-8', interpreted_type='SITE')
    rtstruct.add_box(size = [4,4,20], center = [8,8,0], name='z=-8 to 8, x=y=8', interpreted_type='SITE')
    rtstruct.add_sphere(radius=4, center = [-8,-8,-8], name='x=y=z=-8', interpreted_type='SITE')
    rtstruct.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set = rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle = 0, collimator_angle=30, meterset = 100)
    b1.conform_to_rectangle(4, 4, [0,0])
    b2 = rtplan.build_beam(gantry_angle = 120, meterset = 100)
    b2.conform_to_rectangle(4, 4, [4,4])
    rtplan.build()

    print "rtdose beam 1"
    rtdose1 = sb.build_dose(planbuilder = rtplan, bits = 32)
    rtdose1.dose_grid_scaling = 1
    rtdose1.dose_summation_type = "PLAN"
    rtdose1.beam_number = None
    rtdose1.BitsAllocated = 32
    rtdose1.BitsStored = 32
    rtdose1.HighBit = 31

    rtdose1.add_box(size = [0,0,0], center = [9,  9, -9], stored_value = 65536) #50%
    rtdose1.add_box(size = [0,0,0], center = [-9, 9, -9], stored_value = 65536) #50%
    rtdose1.add_box(size = [0,0,0], center = [9,  -9,-9], stored_value = 65536) #50%
    rtdose1.add_box(size = [0,0,0], center = [-9, -9,-9], stored_value = 65536) #50%
    rtdose1.add_box(size = [0,0,0], center = [0, 0,  -9], stored_value = 65535*2) #100  
    rtdose1.add_box(size = [0,0,0], center = [0, 0,   0], stored_value = 65535*2)  #100

    return sb
def build_orientation(patient_position, row_direction, column_direction, frame_of_reference_uid = None):
    sb = StudyBuilder(patient_position=patient_position, patient_id="OrientationTests", patient_name="Orientation^Tests", patient_birthdate = "20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position,)
    print "ct"
    ct = sb.build_ct(
        num_voxels=[7, 7, 7],
        voxel_size=[4, 4, 4],
        pixel_representation=0,
        rescale_slope=1,
        rescale_intercept=-1024,
        row_direction=row_direction,
        column_direction=column_direction)
    ct.clear(real_value = -1000)
    ct.add_box(size = [4,4,4], center = [0,0,0], real_value = 0)
    ct.add_box(size = [20,4,4], center = [0,-8,-8], real_value = 0)
    ct.add_box(size = [4,20,4], center = [8,0,-8], real_value = 0)
    ct.add_box(size = [4,4,20], center = [8,8,0], real_value = 0)
    ct.add_sphere(radius = 4, center = [-8,-8,-8], real_value = 0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size = [4,4,4], center = [0,0,0], name='CenterVoxel', interpreted_type='SITE')
    rtstruct.add_box(size = [20,4,4], center = [0,-8,-8], name='x=-8 to 8, y=z=-8', interpreted_type='SITE')
    rtstruct.add_box(size = [4,20,4], center = [8,0,-8], name='y=-8 to 8 x=8, z=-8', interpreted_type='SITE')
    rtstruct.add_box(size = [4,4,20], center = [8,8,0], name='z=-8 to 8, x=y=8', interpreted_type='SITE')
    rtstruct.add_sphere(radius=4, center = [-8,-8,-8], name='x=y=z=-8', interpreted_type='SITE')
    rtstruct.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set = rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle = 0, collimator_angle=30, meterset = 100)
    b1.conform_to_rectangle(4, 4, [0,0])
    b2 = rtplan.build_beam(gantry_angle = 120, meterset = 100)
    b2.conform_to_rectangle(4, 4, [4,4])
    rtplan.build()

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

    return sb
Exemple #3
0
if not os.path.exists(args.outdir):
    os.makedirs(args.outdir)
for study in args.studies:
    sb = StudyBuilder()
    for series in study:
        if series.center.__class__ is str:
            series.center = [float(b) for b in series.center.lstrip('[').rstrip(']').split(";")]
        if series.modality == "CT":
            if 'PatientPosition' not in sb.current_study:
                parser.error("Patient position must be specified when writing CT images!")
            ib = sb.build_ct(num_voxels=num_voxels, voxel_size=voxel_size, center=np.array(series.center))
        elif series.modality == "RTDOSE":
            ib = sb.build_dose(num_voxels=num_voxels, voxel_size=voxel_size, center=np.array(series.center))
        elif series.modality == "RTPLAN":
            isocenter = [float(b) for b in series.isocenter.lstrip('[').rstrip(']').split(";")]
            rp = sb.build_static_plan(nominal_beam_energy=series.nominal_energy, isocenter = isocenter)
        elif series.modality == "RTSTRUCT":
            rtstruct = sb.build_structure_set()
        else:
            assert "Unknown modality"

        for value in series.values:
            value = value.split(",")
            if len(value) == 1 and (value[0][0].isdigit() or value[0][0] == '-'):
                ib.clear(float(value[0]))
            else:
                shape = value[0]
                if shape == "sphere":
                    val = float(value[1])
                    radius = float(value[2])
                    if len(value) > 3:
Exemple #4
0
def build_orientation(patient_position,
                      column_direction,
                      row_direction,
                      frame_of_reference_uid=None):
    sb = StudyBuilder(patient_position=patient_position,
                      patient_id="doseSmallVoxelsOutsideImageData",
                      patient_name="doseSmallVoxelsOutsideImageData",
                      patient_birthdate="20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position, )
    print "ct"
    ct = sb.build_ct(num_voxels=[7, 7, 7],
                     voxel_size=[4, 4, 4],
                     pixel_representation=0,
                     rescale_slope=1,
                     rescale_intercept=-1024,
                     row_direction=row_direction,
                     column_direction=column_direction)
    ct.clear(real_value=-1000)
    ct.add_box(size=[4, 4, 4], center=[0, 0, 0], real_value=0)
    ct.add_box(size=[20, 4, 4], center=[0, -8, -8], real_value=0)
    ct.add_box(size=[4, 20, 4], center=[8, 0, -8], real_value=0)
    ct.add_box(size=[4, 4, 20], center=[8, 8, 0], real_value=0)
    ct.add_sphere(radius=4, center=[-8, -8, -8], real_value=0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size=[4, 4, 4],
                     center=[0, 0, 0],
                     name='CenterVoxel',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[20, 4, 4],
                     center=[0, -8, -8],
                     name='x=-8 to 8, y=z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 20, 4],
                     center=[8, 0, -8],
                     name='y=-8 to 8 x=8, z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 4, 20],
                     center=[8, 8, 0],
                     name='z=-8 to 8, x=y=8',
                     interpreted_type='SITE')
    rtstruct.add_sphere(radius=4,
                        center=[-8, -8, -8],
                        name='x=y=z=-8',
                        interpreted_type='SITE')
    rtstruct.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set=rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle=0, collimator_angle=30, meterset=100)
    b1.conform_to_rectangle(4, 4, [0, 0])

    b2 = rtplan.build_beam(gantry_angle=120, meterset=100)
    b2.conform_to_rectangle(4, 4, [4, 4])

    b3 = rtplan.build_beam(gantry_angle=120, meterset=100)
    b3.conform_to_rectangle(4, 4, [4, 4])

    b4 = rtplan.build_beam(gantry_angle=120, meterset=100)
    b4.conform_to_rectangle(4, 4, [4, 4])

    rtplan.build()

    print "rtdose beam 1"
    rtdose1 = sb.build_dose(planbuilder=None,
                            num_voxels=[31, 31, 31],
                            voxel_size=[1, 1, 1],
                            row_direction=row_direction,
                            column_direction=column_direction)
    rtdose1.dose_grid_scaling = 0.5
    rtdose1.dose_summation_type = "BEAM"
    rtdose1.beam_number = 1

    rtdose1.add_box(size=[1, 1, 1], center=[0, 14, 0], stored_value=200)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 12, 0], stored_value=180)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 10, 0], stored_value=160)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 8, 0], stored_value=140)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 6, 0], stored_value=120)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 4, 0], stored_value=110)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 2, 0], stored_value=105)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 0, 0], stored_value=100)

    rtdose1.add_box(size=[1, 1, 1], center=[0, -14, 0], stored_value=200)
    rtdose1.add_box(size=[1, 1, 1], center=[0, -12, 0], stored_value=180)
    rtdose1.add_box(size=[1, 1, 1], center=[0, -10, 0], stored_value=160)
    rtdose1.add_box(size=[1, 1, 1], center=[0, -8, 0], stored_value=140)
    rtdose1.add_box(size=[1, 1, 1], center=[0, -6, 0], stored_value=120)
    rtdose1.add_box(size=[1, 1, 1], center=[0, -4, 0], stored_value=110)
    rtdose1.add_box(size=[1, 1, 1], center=[0, -2, 0], stored_value=105)
    rtdose1.add_box(size=[1, 1, 1], center=[0, 0, 0], stored_value=100)

    ############# second beam
    print "rtdose beam 2"
    rtdose2 = sb.build_dose(planbuilder=None,
                            num_voxels=[31, 31, 31],
                            voxel_size=[1, 1, 1],
                            row_direction=row_direction,
                            column_direction=column_direction)
    rtdose2.dose_grid_scaling = 0.5
    rtdose2.dose_summation_type = "BEAM"
    rtdose2.beam_number = 2

    rtdose2.add_box(size=[1, 1, 1], center=[14, 0, 0], stored_value=200)
    rtdose2.add_box(size=[1, 1, 1], center=[12, 0, 0], stored_value=180)
    rtdose2.add_box(size=[1, 1, 1], center=[10, 0, 0], stored_value=160)
    rtdose2.add_box(size=[1, 1, 1], center=[8, 0, 0], stored_value=140)
    rtdose2.add_box(size=[1, 1, 1], center=[6, 0, 0], stored_value=120)
    rtdose2.add_box(size=[1, 1, 1], center=[4, 0, 0], stored_value=110)
    rtdose2.add_box(size=[1, 1, 1], center=[2, 0, 0], stored_value=105)
    rtdose2.add_box(size=[1, 1, 1], center=[0, 0, 0], stored_value=100)

    rtdose2.add_box(size=[1, 1, 1], center=[-14, 0, 0], stored_value=200)
    rtdose2.add_box(size=[1, 1, 1], center=[-12, 0, 0], stored_value=180)
    rtdose2.add_box(size=[1, 1, 1], center=[-10, 0, 0], stored_value=160)
    rtdose2.add_box(size=[1, 1, 1], center=[-8, 0, 0], stored_value=140)
    rtdose2.add_box(size=[1, 1, 1], center=[-6, 0, 0], stored_value=120)
    rtdose2.add_box(size=[1, 1, 1], center=[-4, 0, 0], stored_value=110)
    rtdose2.add_box(size=[1, 1, 1], center=[-2, 0, 0], stored_value=105)
    rtdose2.add_box(size=[1, 1, 1], center=[0, 0, 0], stored_value=100)

    ############# third beam
    print "rtdose beam 3"
    rtdose3 = sb.build_dose(planbuilder=None,
                            num_voxels=[31, 31, 31],
                            voxel_size=[1, 1, 1],
                            row_direction=row_direction,
                            column_direction=column_direction)
    rtdose3.dose_grid_scaling = 0.5
    rtdose3.dose_summation_type = "BEAM"
    rtdose3.beam_number = 3

    rtdose3.add_box(size=[1, 1, 1], center=[14, 0, -12], stored_value=200)
    rtdose3.add_box(size=[1, 1, 1], center=[12, 0, -12], stored_value=180)
    rtdose3.add_box(size=[1, 1, 1], center=[10, 0, -12], stored_value=160)
    rtdose3.add_box(size=[1, 1, 1], center=[8, 0, -12], stored_value=140)
    rtdose3.add_box(size=[1, 1, 1], center=[6, 0, -12], stored_value=120)
    rtdose3.add_box(size=[1, 1, 1], center=[4, 0, -12], stored_value=110)
    rtdose3.add_box(size=[1, 1, 1], center=[2, 0, -12], stored_value=105)
    rtdose3.add_box(size=[1, 1, 1], center=[0, 0, -12], stored_value=100)

    rtdose3.add_box(size=[1, 1, 1], center=[-14, 0, -12], stored_value=200)
    rtdose3.add_box(size=[1, 1, 1], center=[-12, 0, -12], stored_value=180)
    rtdose3.add_box(size=[1, 1, 1], center=[-10, 0, -12], stored_value=160)
    rtdose3.add_box(size=[1, 1, 1], center=[-8, 0, -12], stored_value=140)
    rtdose3.add_box(size=[1, 1, 1], center=[-6, 0, -12], stored_value=120)
    rtdose3.add_box(size=[1, 1, 1], center=[-4, 0, -12], stored_value=110)
    rtdose3.add_box(size=[1, 1, 1], center=[-2, 0, -12], stored_value=105)
    rtdose3.add_box(size=[1, 1, 1], center=[0, 0, -12], stored_value=100)

    ############# fourth beam
    print "rtdose beam 4"
    rtdose4 = sb.build_dose(planbuilder=None,
                            num_voxels=[31, 31, 31],
                            voxel_size=[1, 1, 1],
                            row_direction=row_direction,
                            column_direction=column_direction)
    rtdose4.dose_grid_scaling = 0.5
    rtdose4.dose_summation_type = "BEAM"
    rtdose4.beam_number = 4

    rtdose4.add_box(size=[1, 1, 1], center=[14, 0, 12], stored_value=200)
    rtdose4.add_box(size=[1, 1, 1], center=[12, 0, 12], stored_value=180)
    rtdose4.add_box(size=[1, 1, 1], center=[10, 0, 12], stored_value=160)
    rtdose4.add_box(size=[1, 1, 1], center=[8, 0, 12], stored_value=140)
    rtdose4.add_box(size=[1, 1, 1], center=[6, 0, 12], stored_value=120)
    rtdose4.add_box(size=[1, 1, 1], center=[4, 0, 12], stored_value=110)
    rtdose4.add_box(size=[1, 1, 1], center=[2, 0, 12], stored_value=105)
    rtdose4.add_box(size=[1, 1, 1], center=[0, 0, 12], stored_value=100)

    rtdose4.add_box(size=[1, 1, 1], center=[-14, 0, 12], stored_value=200)
    rtdose4.add_box(size=[1, 1, 1], center=[-12, 0, 12], stored_value=180)
    rtdose4.add_box(size=[1, 1, 1], center=[-10, 0, 12], stored_value=160)
    rtdose4.add_box(size=[1, 1, 1], center=[-8, 0, 12], stored_value=140)
    rtdose4.add_box(size=[1, 1, 1], center=[-6, 0, 12], stored_value=120)
    rtdose4.add_box(size=[1, 1, 1], center=[-4, 0, 12], stored_value=110)
    rtdose4.add_box(size=[1, 1, 1], center=[-2, 0, 12], stored_value=105)
    rtdose4.add_box(size=[1, 1, 1], center=[0, 0, 12], stored_value=100)

    ############# second plan
    print "rtdose plan dose"
    rtdosePlan = sb.build_dose(planbuilder=None,
                               num_voxels=[31, 31, 31],
                               voxel_size=[1, 1, 1],
                               row_direction=row_direction,
                               column_direction=column_direction)
    rtdosePlan.dose_grid_scaling = 0.5
    rtdosePlan.dose_summation_type = "PLAN"
    rtdosePlan.beam_number = None

    rtdosePlan.pixel_array = numpy.add(rtdose2.pixel_array,
                                       rtdose1.pixel_array)
    rtdosePlan.pixel_array = numpy.add(rtdose3.pixel_array,
                                       rtdosePlan.pixel_array)
    rtdosePlan.pixel_array = numpy.add(rtdose4.pixel_array,
                                       rtdosePlan.pixel_array)

    return sb
Exemple #5
0
            ib = sb.build_pt(
                num_voxels=num_voxels,
                voxel_size=voxel_size,
                pixel_representation=pixel_representations[series.pixel_representation],
                rescale_slope=series.rescale_slope,
                center=np.array(series.center))
        elif series.modality == "RTDOSE":
            ib = sb.build_dose(
                num_voxels=num_voxels,
                voxel_size=voxel_size,
                center=np.array(series.center))
        elif series.modality == "RTPLAN":
            isocenter = [float(b) for b in series.isocenter.lstrip('[').rstrip(']').split(";")]
            rp = sb.build_static_plan(nominal_beam_energy=series.nominal_energy,
                                      isocenter=isocenter,
                                      mlc_direction=series.mlc_direction,
                                      sad=series.sad)
        elif series.modality == "RTSTRUCT":
            rtstruct = sb.build_structure_set()
        else:
            assert "Unknown modality"

        for value in series.values:
            value = value.split(",")
            if len(value) == 1 and (value[0][0].isdigit() or value[0][0] == '-'):
                ib.clear(float(value[0]))
            else:
                shape = value[0]
                if shape == "sphere":
                    val = float(value[1])
                    radius = float(value[2])
Exemple #6
0
def build_orientation(patient_position,
                      row_direction,
                      column_direction,
                      frame_of_reference_uid=None):
    sb = StudyBuilder(patient_position=patient_position,
                      patient_id="OrientationTests",
                      patient_name="Orientation^Tests",
                      patient_birthdate="20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position, )
    print "ct"
    ct = sb.build_ct(num_voxels=[7, 7, 7],
                     voxel_size=[4, 4, 4],
                     pixel_representation=0,
                     rescale_slope=1,
                     rescale_intercept=-1024,
                     row_direction=row_direction,
                     column_direction=column_direction)
    ct.clear(real_value=-1000)
    ct.add_box(size=[4, 4, 4], center=[0, 0, 0], real_value=0)
    ct.add_box(size=[20, 4, 4], center=[0, -8, -8], real_value=0)
    ct.add_box(size=[4, 20, 4], center=[8, 0, -8], real_value=0)
    ct.add_box(size=[4, 4, 20], center=[8, 8, 0], real_value=0)
    ct.add_sphere(radius=4, center=[-8, -8, -8], real_value=0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size=[4, 4, 4],
                     center=[0, 0, 0],
                     name='CenterVoxel',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[20, 4, 4],
                     center=[0, -8, -8],
                     name='x=-8 to 8, y=z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 20, 4],
                     center=[8, 0, -8],
                     name='y=-8 to 8 x=8, z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 4, 20],
                     center=[8, 8, 0],
                     name='z=-8 to 8, x=y=8',
                     interpreted_type='SITE')
    rtstruct.add_sphere(radius=4,
                        center=[-8, -8, -8],
                        name='x=y=z=-8',
                        interpreted_type='SITE')
    rtstruct.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set=rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle=0, collimator_angle=30, meterset=100)
    b1.conform_to_rectangle(4, 4, [0, 0])
    b2 = rtplan.build_beam(gantry_angle=120, meterset=100)
    b2.conform_to_rectangle(4, 4, [4, 4])
    rtplan.build()

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

    return sb
Exemple #7
0
print ct.pixel_array.max(), ct.pixel_array.min()

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

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])
Exemple #8
0
def build_orientation(patient_position,
                      column_direction,
                      row_direction,
                      frame_of_reference_uid=None):
    sb = StudyBuilder(patient_position=patient_position,
                      patient_id="doseDifferentMax",
                      patient_name="doseDifferentMax",
                      patient_birthdate="20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position, )
    print "ct"
    ct = sb.build_ct(num_voxels=[7, 7, 7],
                     voxel_size=[4, 4, 4],
                     pixel_representation=0,
                     rescale_slope=1,
                     rescale_intercept=-1024,
                     row_direction=row_direction,
                     column_direction=column_direction)
    ct.clear(real_value=-1000)
    ct.add_box(size=[4, 4, 4], center=[0, 0, 0], real_value=0)
    ct.add_box(size=[20, 4, 4], center=[0, -8, -8], real_value=0)
    ct.add_box(size=[4, 20, 4], center=[8, 0, -8], real_value=0)
    ct.add_box(size=[4, 4, 20], center=[8, 8, 0], real_value=0)
    ct.add_sphere(radius=4, center=[-8, -8, -8], real_value=0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size=[4, 4, 4],
                     center=[0, 0, 0],
                     name='CenterVoxel',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[20, 4, 4],
                     center=[0, -8, -8],
                     name='x=-8 to 8, y=z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 20, 4],
                     center=[8, 0, -8],
                     name='y=-8 to 8 x=8, z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 4, 20],
                     center=[8, 8, 0],
                     name='z=-8 to 8, x=y=8',
                     interpreted_type='SITE')
    rtstruct.add_sphere(radius=4,
                        center=[-8, -8, -8],
                        name='x=y=z=-8',
                        interpreted_type='SITE')
    rtstruct.build()

    print "rtstruct 2 not connected to the plan"
    rtstruct2 = sb.build_structure_set(ct)
    rtstruct2.add_external_box()
    rtstruct2.add_sphere(radius=4,
                         center=[0, 0, 0],
                         name='center sphere',
                         interpreted_type='SITE')
    rtstruct2.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set=rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle=0, collimator_angle=30, meterset=100)
    b1.conform_to_rectangle(4, 4, [0, 0])
    b2 = rtplan.build_beam(gantry_angle=120, meterset=100)
    b2.conform_to_rectangle(4, 4, [4, 4])
    rtplan.build()

    print "rtdose beam 1"
    rtdose1 = sb.build_dose(planbuilder=None,
                            num_voxels=[7, 9, 5],
                            voxel_size=[3, 1, 1],
                            row_direction=row_direction,
                            column_direction=column_direction)
    rtdose1.dose_grid_scaling = 0.01
    rtdose1.dose_summation_type = "BEAM"
    rtdose1.beam_number = 1

    rtdose1.add_box(size=[3, 1, 1], center=[0, -3, 0], stored_value=100)
    rtdose1.add_box(size=[3, 1, 1], center=[0, -2, 0], stored_value=91)
    rtdose1.add_box(size=[3, 1, 1], center=[0, -1, 0], stored_value=81)
    rtdose1.add_box(size=[3, 1, 1], center=[0, 0, 0], stored_value=71)
    rtdose1.add_box(size=[3, 1, 1], center=[0, 1, 0], stored_value=61)
    rtdose1.add_box(size=[3, 1, 1], center=[0, 2, 0], stored_value=51)
    rtdose1.add_box(size=[3, 1, 1], center=[0, 3, 0], stored_value=0)

    ############# second beam
    print "rtdose beam 2"
    rtdose2 = sb.build_dose(planbuilder=None,
                            num_voxels=[7, 9, 5],
                            voxel_size=[3, 1, 1],
                            row_direction=row_direction,
                            column_direction=column_direction)
    rtdose2.dose_grid_scaling = 0.01
    rtdose2.dose_summation_type = "BEAM"
    rtdose2.beam_number = 2

    rtdose2.add_box(size=[3, 1, 1], center=[-9, 0, 0], stored_value=100)
    rtdose2.add_box(size=[3, 1, 1], center=[-6, 0, 0], stored_value=91)
    rtdose2.add_box(size=[3, 1, 1], center=[-3, 0, 0], stored_value=81)
    rtdose2.add_box(size=[3, 1, 1], center=[0, 0, 0], stored_value=71)
    rtdose2.add_box(size=[3, 1, 1], center=[3, 0, 0], stored_value=61)
    rtdose2.add_box(size=[3, 1, 1], center=[6, 0, 0], stored_value=51)
    rtdose2.add_box(size=[3, 1, 1], center=[9, 0, 0], stored_value=0)

    ############# second plan
    print "rtdose plan dose"
    rtdosePlan = sb.build_dose(planbuilder=None,
                               num_voxels=[7, 9, 5],
                               voxel_size=[3, 1, 1],
                               row_direction=row_direction,
                               column_direction=column_direction)
    rtdosePlan.dose_grid_scaling = 0.01
    rtdosePlan.dose_summation_type = "PLAN"
    rtdosePlan.beam_number = None

    rtdosePlan.pixel_array = numpy.add(rtdose2.pixel_array,
                                       rtdose1.pixel_array)

    return sb
Exemple #9
0
def build_orientation(patient_position,
                      column_direction,
                      row_direction,
                      frame_of_reference_uid=None):
    sb = StudyBuilder(patient_position=patient_position,
                      patient_id="OrientationTests",
                      patient_name="Orientation^Tests",
                      patient_birthdate="20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position, )
    print "ct"
    ct = sb.build_ct(num_voxels=[7, 7, 7],
                     voxel_size=[4, 4, 4],
                     pixel_representation=0,
                     rescale_slope=1,
                     rescale_intercept=-1024,
                     row_direction=row_direction,
                     column_direction=column_direction)
    ct.clear(real_value=-1000)
    ct.add_box(size=[4, 4, 4], center=[0, 0, 0], real_value=0)
    ct.add_box(size=[20, 4, 4], center=[0, -8, -8], real_value=0)
    ct.add_box(size=[4, 20, 4], center=[8, 0, -8], real_value=0)
    ct.add_box(size=[4, 4, 20], center=[8, 8, 0], real_value=0)
    ct.add_sphere(radius=4, center=[-8, -8, -8], real_value=0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size=[4, 4, 4],
                     center=[0, 0, 0],
                     name='CenterVoxel',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[20, 4, 4],
                     center=[0, -8, -8],
                     name='x=-8 to 8, y=z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 20, 4],
                     center=[8, 0, -8],
                     name='y=-8 to 8 x=8, z=-8',
                     interpreted_type='SITE')
    rtstruct.add_box(size=[4, 4, 20],
                     center=[8, 8, 0],
                     name='z=-8 to 8, x=y=8',
                     interpreted_type='SITE')
    rtstruct.add_sphere(radius=4,
                        center=[-8, -8, -8],
                        name='x=y=z=-8',
                        interpreted_type='SITE')
    rtstruct.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set=rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle=0, collimator_angle=30, meterset=100)
    b1.conform_to_rectangle(4, 4, [0, 0])
    b2 = rtplan.build_beam(gantry_angle=120, meterset=100)
    b2.conform_to_rectangle(4, 4, [4, 4])
    rtplan.build()

    print "rtdose beam 1"
    rtdose1 = sb.build_dose(planbuilder=rtplan)
    rtdose1.dose_grid_scaling = 1
    rtdose1.dose_summation_type = "BEAM"
    rtdose1.beam_number = 1

    rtdose1.add_box(size=[4, 4, 4], center=[0, -12, 0],
                    stored_value=65535)  #100%
    rtdose1.add_box(size=[4, 4, 4], center=[0, -8, 0],
                    stored_value=39321)  #60%
    rtdose1.add_box(size=[4, 4, 4], center=[0, -4, 0],
                    stored_value=38665)  #59%
    rtdose1.add_box(size=[4, 4, 4], center=[0, 0, 0], stored_value=32767)  #50%
    rtdose1.add_box(size=[4, 4, 4], center=[0, 4, 0], stored_value=32112)  #49%
    rtdose1.add_box(size=[4, 4, 4], center=[0, 8, 0], stored_value=15728)  #24%
    rtdose1.add_box(size=[4, 4, 4], center=[0, 12, 0], stored_value=0)  #0%

    ############# second beam
    print "rtdose beam 2"
    rtdose2 = sb.build_dose(planbuilder=rtplan)
    rtdose2.dose_grid_scaling = 1
    rtdose2.dose_summation_type = "BEAM"
    rtdose2.beam_number = 2

    rtdose2.add_box(size=[4, 4, 4], center=[-12, 0, 0],
                    stored_value=65535)  # 100%
    rtdose2.add_box(size=[4, 4, 4], center=[-8, 0, 0],
                    stored_value=62259)  # 95%
    rtdose2.add_box(size=[4, 4, 4], center=[-4, 0, 0],
                    stored_value=61602)  # 94%
    rtdose2.add_box(size=[4, 4, 4], center=[0, 0, 0],
                    stored_value=32767)  # 50%
    rtdose2.add_box(size=[4, 4, 4], center=[4, 0, 0],
                    stored_value=52428)  # 80%
    rtdose2.add_box(size=[4, 4, 4], center=[8, 0, 0],
                    stored_value=51772)  # 79%
    rtdose2.add_box(size=[4, 4, 4], center=[12, 0, 0],
                    stored_value=15728)  # 24%

    ############# second plan
    print "rtdose plan dose"
    rtdosePlan = sb.build_dose(planbuilder=rtplan)
    rtdosePlan.dose_grid_scaling = 1
    rtdosePlan.dose_summation_type = "PLAN"
    rtdosePlan.beam_number = None

    rtdosePlan.pixel_array = numpy.add(rtdose2.pixel_array,
                                       rtdose1.pixel_array)

    return sb
ct = sb.build_ct(num_voxels = [48,64,48], voxel_size = [4,3,4], rescale_slope = 1, rescale_intercept = -1024)
ct.clear(real_value = 0)
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)

Exemple #11
0
def build_orientation(patient_position, column_direction, row_direction, frame_of_reference_uid = None):
    sb = StudyBuilder(patient_position=patient_position, patient_id="OrientationTests", patient_name="Orientation^Tests", patient_birthdate = "20121212")
    if frame_of_reference_uid != None:
        sb.current_study['FrameOfReferenceUID'] = frame_of_reference_uid

    print "building %s..." % (patient_position,)
    print "ct"
    ct = sb.build_ct(
        num_voxels=[7, 7, 7],
        voxel_size=[4, 4, 4],
        pixel_representation=0,
        rescale_slope=1,
        rescale_intercept=-1024,
        row_direction=row_direction,
        column_direction=column_direction)
    ct.clear(real_value = -1000)
    ct.add_box(size = [4,4,4], center = [0,0,0], real_value = 0)
    ct.add_box(size = [20,4,4], center = [0,-8,-8], real_value = 0)
    ct.add_box(size = [4,20,4], center = [8,0,-8], real_value = 0)
    ct.add_box(size = [4,4,20], center = [8,8,0], real_value = 0)
    ct.add_sphere(radius = 4, center = [-8,-8,-8], real_value = 0)

    print "rtstruct"
    rtstruct = sb.build_structure_set(ct)
    rtstruct.add_external_box()
    rtstruct.add_box(size = [4,4,4], center = [0,0,0], name='CenterVoxel', interpreted_type='SITE')
    rtstruct.add_box(size = [20,4,4], center = [0,-8,-8], name='x=-8 to 8, y=z=-8', interpreted_type='SITE')
    rtstruct.add_box(size = [4,20,4], center = [8,0,-8], name='y=-8 to 8 x=8, z=-8', interpreted_type='SITE')
    rtstruct.add_box(size = [4,4,20], center = [8,8,0], name='z=-8 to 8, x=y=8', interpreted_type='SITE')
    rtstruct.add_sphere(radius=4, center = [-8,-8,-8], name='x=y=z=-8', interpreted_type='SITE')
    rtstruct.build()

    print "rtplan"
    rtplan = sb.build_static_plan(structure_set = rtstruct, sad=20)
    b1 = rtplan.build_beam(gantry_angle = 0, collimator_angle=30, meterset = 100)
    b1.conform_to_rectangle(4, 4, [0,0])
    b2 = rtplan.build_beam(gantry_angle = 120, meterset = 100)
    b2.conform_to_rectangle(4, 4, [4,4])
    rtplan.build()

    print "rtdose beam 1"
    rtdose1 = sb.build_dose(planbuilder = rtplan)
    rtdose1.dose_grid_scaling = 1
    rtdose1.dose_summation_type = "BEAM"
    rtdose1.beam_number = 1

    rtdose1.add_box(size = [4,4,4], center = [0,-12, 0], stored_value = 65535) #100%
    rtdose1.add_box(size = [4,4,4], center = [0, -8, 0], stored_value = 39321) #60%
    rtdose1.add_box(size = [4,4,4], center = [0, -4, 0], stored_value = 38665) #59%
    rtdose1.add_box(size = [4,4,4], center = [0,  0, 0], stored_value = 32767) #50%
    rtdose1.add_box(size = [4,4,4], center = [0,  4, 0], stored_value = 32112) #49%
    rtdose1.add_box(size = [4,4,4], center = [0,  8, 0], stored_value = 15728) #24%
    rtdose1.add_box(size = [4,4,4], center = [0, 12, 0], stored_value = 0)     #0%

    ############# second beam
    print "rtdose beam 2"
    rtdose2 = sb.build_dose(planbuilder = rtplan)
    rtdose2.dose_grid_scaling = 1
    rtdose2.dose_summation_type = "BEAM"
    rtdose2.beam_number = 2

    rtdose2.add_box(size = [4,4,4], center = [-12,0, 0], stored_value = 65535) # 100%
    rtdose2.add_box(size = [4,4,4], center = [-8, 0, 0], stored_value = 62259) # 95%
    rtdose2.add_box(size = [4,4,4], center = [-4, 0, 0], stored_value = 61602) # 94%
    rtdose2.add_box(size = [4,4,4], center = [0,  0, 0], stored_value = 32767) # 50%
    rtdose2.add_box(size = [4,4,4], center = [4,  0, 0], stored_value = 52428) # 80%
    rtdose2.add_box(size = [4,4,4], center = [8,  0, 0], stored_value = 51772) # 79%
    rtdose2.add_box(size = [4,4,4], center = [12, 0, 0], stored_value = 15728) # 24%

    ############# second plan
    print "rtdose plan dose"
    rtdosePlan = sb.build_dose(planbuilder = rtplan)
    rtdosePlan.dose_grid_scaling = 1
    rtdosePlan.dose_summation_type = "PLAN"
    rtdosePlan.beam_number = None

    rtdosePlan.pixel_array = numpy.add(rtdose2.pixel_array, rtdose1.pixel_array)

    return sb
Exemple #12
0
    os.makedirs(args.outdir)
for study in args.studies:
    sb = StudyBuilder()
    for series in study:
        if series.center.__class__ is str:
            series.center = [float(b) for b in series.center.lstrip('[').rstrip(']').split(";")]
        if series.modality == "CT":
            if 'PatientPosition' not in sb.current_study:
                parser.error("Patient position must be specified when writing CT images!")
            ib = sb.build_ct(num_voxels=num_voxels, voxel_size=voxel_size, center=np.array(series.center))
        elif series.modality == "RTDOSE":
            ib = sb.build_dose(num_voxels=num_voxels, voxel_size=voxel_size, center=np.array(series.center))
        elif series.modality == "RTPLAN":
            isocenter = [float(b) for b in series.isocenter.lstrip('[').rstrip(']').split(";")]
            rp = sb.build_static_plan(nominal_beam_energy = series.nominal_energy,
                                      isocenter = isocenter,
                                      mlc_direction = series.mlc_direction,
                                      sad = series.sad)
        elif series.modality == "RTSTRUCT":
            rtstruct = sb.build_structure_set()
        else:
            assert "Unknown modality"

        for value in series.values:
            value = value.split(",")
            if len(value) == 1 and (value[0][0].isdigit() or value[0][0] == '-'):
                ib.clear(float(value[0]))
            else:
                shape = value[0]
                if shape == "sphere":
                    val = float(value[1])
                    radius = float(value[2])