Exemplo n.º 1
0
    def add_lightfield(self, beam, weight):
        x,y,z = self.mgrid()
        bld = modules.getblds(beam.BeamLimitingDeviceSequence)
        gantry_angle = None
        gantry_pitch_angle = 0
        isocenter = [0,0,0]
        beam_limiting_device_angle = Decimal(0)
        table_top = TableTop()
        table_top_ecc = TableTopEcc()
        patient_position = 'HFS'
        patient_support_angle = 0
        if hasattr(beam, 'SourceAxisDistance'):
            sad = beam.SourceAxisDistance
        else:
            sad = 1000
        for cp in beam.ControlPointSequence:
            if hasattr(cp, 'BeamLimitingDevicePositionSequence') and cp.BeamLimitingDevicePositionSequence != None:
                bldp = modules.getblds(cp.BeamLimitingDevicePositionSequence)
            gantry_angle = getattr(cp, 'GantryAngle', gantry_angle)
            gantry_pitch_angle = getattr(cp, 'GantryPitchAngle', gantry_angle)
            beam_limiting_device_angle = getattr(cp, 'BeamLimitingDeviceAngle', beam_limiting_device_angle)
            patient_support_angle = getattr(cp, 'PatientSupportAngle', patient_support_angle)
            isocenter = getattr(cp, 'IsocenterPosition', isocenter)
            table_top_ecc.Ls = getattr(cp, 'TableTopEccentricAxisDistance', table_top_ecc.Ls)
            table_top_ecc.theta_e = getattr(cp, 'TableTopEccentricAngle', table_top_ecc.theta_e)
            table_top.psi_t = getattr(cp, 'TableTopPitchAngle', table_top.psi_t)
            table_top.phi_t = getattr(cp, 'TableTopRollAngle', table_top.phi_t)
            table_top.Tx = getattr(cp, 'TableTopLateralPosition', table_top.Tx)
            table_top.Ty = getattr(cp, 'TableTopLongitudinalPosition', table_top.Ty)
            table_top.Tz = getattr(cp, 'TableTopVerticalPosition', table_top.Tz)
            patient_position = getattr(cp, 'PatientPosition', patient_position)

            table_top = TableTop()
            Mdb = modules.get_dicom_to_bld_coordinate_transform(gantry_angle, gantry_pitch_angle, beam_limiting_device_angle,
                                                                patient_support_angle, patient_position,
                                                                table_top, table_top_ecc, sad, isocenter)
            coords = np.array([x.ravel(),
                               y.ravel(),
                               z.ravel(),
                               np.ones(x.shape).ravel()]).reshape((4,1,1,np.prod(x.shape)))
            c = Mdb * coords
            # Negation here since everything is at z < 0 in the b system, and that rotates by 180 degrees
            c2 = -np.array([float(beam.SourceAxisDistance)*c[0,:]/c[2,:], float(beam.SourceAxisDistance)*c[1,:]/c[2,:]]).squeeze()
            nleaves = len(bld['MLCX'].LeafPositionBoundaries)-1
            for i in range(nleaves):
                self.pixel_array.ravel()[(c2[0,:] >= max(float(bldp['ASYMX'].LeafJawPositions[0]),
                                              float(bldp['MLCX'].LeafJawPositions[i])))
                               * (c2[0,:] <= min(float(bldp['ASYMX'].LeafJawPositions[1]),
                                                 float(bldp['MLCX'].LeafJawPositions[i + nleaves])))
                               * (c2[1,:] > max(float(bldp['ASYMY'].LeafJawPositions[0]),
                                                 float(bld['MLCX'].LeafPositionBoundaries[i])))
                               * (c2[1,:] <= min(float(bldp['ASYMY'].LeafJawPositions[1]),
                                                 float(bld['MLCX'].LeafPositionBoundaries[i+1])))] += 1
Exemplo n.º 2
0
 def add_lightfield(self, beam, weight):
     x,y,z = self.mgrid()
     coords = (np.array([x.ravel(), y.ravel(), z.ravel(), np.ones(x.shape).ravel()]).reshape((4,1,1,np.prod(x.shape))))
     bld = modules.getblds(beam.BeamLimitingDeviceSequence)
     mlcdir, jawdir1, jawdir2 = modules.get_mlc_and_jaw_directions(bld)
     mlcidx = (0,1) if mlcdir == "MLCX" else (1,0)
     
     def add_lightfield_for_cp(cp, gantry_angle, gantry_pitch_angle, beam_limiting_device_angle,
                               patient_support_angle, patient_position,
                               table_top, table_top_ecc, sad, isocenter, bldp):
         Mdb = modules.get_dicom_to_bld_coordinate_transform(gantry_angle, gantry_pitch_angle, beam_limiting_device_angle,
                                                             patient_support_angle, patient_position,
                                                             table_top, table_top_ecc, sad, isocenter)
         c = Mdb * coords
         # Negation here since everything is at z < 0 in the b system, and that rotates by 180 degrees
         c2 = -np.array([float(beam.SourceAxisDistance)*c[0,:]/c[2,:],
                         float(beam.SourceAxisDistance)*c[1,:]/c[2,:]]).squeeze()
         nleaves = len(bld[mlcdir].LeafPositionBoundaries)-1
         for i in range(nleaves):
             self.pixel_array.ravel()[
                 (c2[0,:] >= float(bldp['ASYMX'].LeafJawPositions[0])) *
                 (c2[0,:] <  float(bldp['ASYMX'].LeafJawPositions[1])) *
                 (c2[1,:] >= float(bldp['ASYMY'].LeafJawPositions[0])) *
                 (c2[1,:] <  float(bldp['ASYMY'].LeafJawPositions[1])) *
                 (c2[mlcidx[0],:] >= float(bldp[mlcdir].LeafJawPositions[i])) *
                 (c2[mlcidx[0],:] <  float(bldp[mlcdir].LeafJawPositions[i + nleaves])) *
                 (c2[mlcidx[1],:] >= float(bld[mlcdir].LeafPositionBoundaries[i])) *
                 (c2[mlcidx[1],:] <  float(bld[mlcdir].LeafPositionBoundaries[i+1]))
             ] += 1
     do_for_all_cps(beam, self.current_study['PatientPosition'], add_lightfield_for_cp)
Exemplo n.º 3
0
 def add_lightfield(self, beam, weight):
     x,y,z = self.mgrid()
     coords = (np.array([x.ravel(), y.ravel(), z.ravel(), np.ones(x.shape).ravel()]).reshape((4,1,1,np.prod(x.shape))))
     bld = modules.getblds(beam.BeamLimitingDeviceSequence)
     
     def add_lightfield_for_cp(cp, gantry_angle, gantry_pitch_angle, beam_limiting_device_angle,
                               patient_support_angle, patient_position,
                               table_top, table_top_ecc, sad, isocenter, bldp):
         Mdb = modules.get_dicom_to_bld_coordinate_transform(gantry_angle, gantry_pitch_angle, beam_limiting_device_angle,
                                                             patient_support_angle, patient_position,
                                                             table_top, table_top_ecc, sad, isocenter)
         c = Mdb * coords
         # Negation here since everything is at z < 0 in the b system, and that rotates by 180 degrees
         c2 = -np.array([float(beam.SourceAxisDistance)*c[0,:]/c[2,:], float(beam.SourceAxisDistance)*c[1,:]/c[2,:]]).squeeze()
         nleaves = len(bld['MLCX'].LeafPositionBoundaries)-1
         for i in range(nleaves):
             self.pixel_array.ravel()[(c2[0,:] >= max(float(bldp['ASYMX'].LeafJawPositions[0]),
                                       float(bldp['MLCX'].LeafJawPositions[i])))
                                    * (c2[0,:] <= min(float(bldp['ASYMX'].LeafJawPositions[1]),
                                       float(bldp['MLCX'].LeafJawPositions[i + nleaves])))
                                    * (c2[1,:] > max(float(bldp['ASYMY'].LeafJawPositions[0]),
                                       float(bld['MLCX'].LeafPositionBoundaries[i])))
                                    * (c2[1,:] <= min(float(bldp['ASYMY'].LeafJawPositions[1]),
                                       float(bld['MLCX'].LeafPositionBoundaries[i+1])))] += 1
     do_for_all_cps(beam, self.current_study['PatientPosition'], add_lightfield_for_cp)
Exemplo n.º 4
0
def plot_cp(beam, cp):
    plot_leaves(
        modules.getblds(beam.BLDs)['MLCX'].LeafPositionBoundaries,
        modules.getblds(cp.BLDPositions)['MLCX'].LeafJawPositions)
Exemplo n.º 5
0
def plot_cp(beam, cp):
    plot_leaves(modules.getblds(beam.BLDs)['MLCX'].LeafPositionBoundaries,
                modules.getblds(cp.BLDPositions)['MLCX'].LeafJawPositions)