Class: RTKIT::ControlPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/rtkit/control_point.rb

Overview

Contains DICOM data and methods related to a ControlPoint.

Notes

The first control point in a given beam defines the intial setup, and contains all applicable parameters. The rest of the control points contains the parameters which change at any control point.

Relations

  • A Beam has many ControlPoints.

  • A ControlPoint has many Collimators.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, cum_meterset, beam) ⇒ ControlPoint

Creates a new ControlPoint instance.

Parameters

  • index – Integer. The control point index.

  • meterset – The control point’s cumulative meterset weight.

  • beam – The Beam instance that this ControlPoint belongs to.

  • options – A hash of parameters.

Options

  • :type – String. Beam type. Defaults to ‘STATIC’.

  • :delivery_type – String. Treatment delivery type. Defaults to ‘TREATMENT’.

  • :description – String. Beam description. Defaults to the ‘name’ attribute.

  • :rad_type – String. Radiation type. Defaults to ‘PHOTON’.

  • :sad – Float. Source-axis distance. Defaults to 1000.0.

  • :unit – String. The primary dosimeter unit. Defaults to ‘MU’.

Raises:

  • (ArgumentError)


114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rtkit/control_point.rb', line 114

def initialize(index, cum_meterset, beam)
  raise ArgumentError, "Invalid argument 'beam'. Expected Beam, got #{beam.class}." unless beam.is_a?(Beam)
  # Set values:
  @collimators = Array.new
  @associated_collimators = Hash.new
  self.index = index
  self.cum_meterset = cum_meterset
  # Set references:
  @beam = beam
  # Register ourselves with the Beam:
  @beam.add_control_point(self)
end

Instance Attribute Details

#beamObject (readonly)

The Beam that the ControlPoint is defined in.



20
21
22
# File 'lib/rtkit/control_point.rb', line 20

def beam
  @beam
end

#collimator_angleObject

Collimator (beam limiting device) angle (float).



22
23
24
# File 'lib/rtkit/control_point.rb', line 22

def collimator_angle
  @collimator_angle
end

#collimator_directionObject

Collimator (beam limiting device) rotation direction (string).



24
25
26
# File 'lib/rtkit/control_point.rb', line 24

def collimator_direction
  @collimator_direction
end

#collimatorsObject (readonly)

An array containing the ControlPoint’s collimators.



26
27
28
# File 'lib/rtkit/control_point.rb', line 26

def collimators
  @collimators
end

#cum_metersetObject

Cumulative meterset weight (float).



28
29
30
# File 'lib/rtkit/control_point.rb', line 28

def cum_meterset
  @cum_meterset
end

#energyObject

Nominal beam energy (float).



30
31
32
# File 'lib/rtkit/control_point.rb', line 30

def energy
  @energy
end

#gantry_angleObject

Gantry angle (float).



32
33
34
# File 'lib/rtkit/control_point.rb', line 32

def gantry_angle
  @gantry_angle
end

#gantry_directionObject

Gantry rotation direction (string).



34
35
36
# File 'lib/rtkit/control_point.rb', line 34

def gantry_direction
  @gantry_direction
end

#indexObject

Control point index (integer).



36
37
38
# File 'lib/rtkit/control_point.rb', line 36

def index
  @index
end

#isoObject

Isosenter position (a coordinate triplet of positions x, y, z).



38
39
40
# File 'lib/rtkit/control_point.rb', line 38

def iso
  @iso
end

#pedestal_angleObject

Pedestal angle (float).



40
41
42
# File 'lib/rtkit/control_point.rb', line 40

def pedestal_angle
  @pedestal_angle
end

#pedestal_directionObject

Pedestal rotation direction (string).



42
43
44
# File 'lib/rtkit/control_point.rb', line 42

def pedestal_direction
  @pedestal_direction
end

#ssdObject

Source to surface distance (float).



44
45
46
# File 'lib/rtkit/control_point.rb', line 44

def ssd
  @ssd
end

#table_top_angleObject

Table top angle (float).



46
47
48
# File 'lib/rtkit/control_point.rb', line 46

def table_top_angle
  @table_top_angle
end

#table_top_directionObject

Table top rotation direction (string).



48
49
50
# File 'lib/rtkit/control_point.rb', line 48

def table_top_direction
  @table_top_direction
end

#table_top_lateralObject

Table top lateral position (float).



50
51
52
# File 'lib/rtkit/control_point.rb', line 50

def table_top_lateral
  @table_top_lateral
end

#table_top_longitudinalObject

Table top longitudinal position (float).



52
53
54
# File 'lib/rtkit/control_point.rb', line 52

def table_top_longitudinal
  @table_top_longitudinal
end

#table_top_verticalObject

Table top vertical position (float).



54
55
56
# File 'lib/rtkit/control_point.rb', line 54

def table_top_vertical
  @table_top_vertical
end

Class Method Details

.create_from_item(cp_item, beam) ⇒ Object

Creates a new control point instance from a Control Point Sequence Item (from an RTPlan file). Returns the ControlPoint instance.

Parameters

  • cp_item – An item from the Control Point Sequence in the DObject of a RTPlan file.

  • beam – The Beam instance that this ControlPoint belongs to.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rtkit/control_point.rb', line 64

def self.create_from_item(cp_item, beam)
  raise ArgumentError, "Invalid argument 'cp_item'. Expected DICOM::Item, got #{cp_item.class}." unless cp_item.is_a?(DICOM::Item)
  raise ArgumentError, "Invalid argument 'beam'. Expected Beam, got #{beam.class}." unless beam.is_a?(Beam)
  # Values from the Structure Set ROI Sequence Item:
  index = cp_item.value(CONTROL_POINT_INDEX)
  cum_meterset = cp_item.value(CUM_METERSET_WEIGHT)
  # Create the Beam instance:
  cp = self.new(index, cum_meterset, beam)
  # Set optional values:
  cp.collimator_angle = cp_item.value(COLL_ANGLE)
  cp.collimator_direction = cp_item.value(COLL_DIRECTION)
  cp.energy = cp_item.value(BEAM_ENERGY)
  cp.gantry_angle = cp_item.value(GANTRY_ANGLE)
  cp.gantry_direction = cp_item.value(GANTRY_DIRECTION)
  cp.iso = cp_item.value(ISO_POS)
  cp.pedestal_angle = cp_item.value(PEDESTAL_ANGLE)
  cp.pedestal_direction = cp_item.value(PEDESTAL_DIRECTION)
  cp.ssd = cp_item.value(SSD).to_f if cp_item.exists?(SSD)
  cp.table_top_angle = cp_item.value(TABLE_TOP_ANGLE)
  cp.table_top_direction = cp_item.value(TABLE_TOP_DIRECTION)
  cp.table_top_lateral = cp_item.value(TABLE_TOP_LATERAL)
  cp.table_top_vertical = cp_item.value(TABLE_TOP_VERTICAL)
  cp.table_top_longitudinal = cp_item.value(TABLE_TOP_LONGITUDINAL)
  # Iterate the beam limiting device position items and create Collimator instances:
  if cp_item.exists?(COLL_POS_SQ)
    cp_item[COLL_POS_SQ].each do |coll_item|
      CollimatorSetup.create_from_item(coll_item, cp)
    end
  end
  return cp
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Returns true if the argument is an instance with attributes equal to self.



129
130
131
132
133
# File 'lib/rtkit/control_point.rb', line 129

def ==(other)
  if other.respond_to?(:to_control_point)
    other.send(:state) == state
  end
end

#add_collimator(coll) ⇒ Object

Adds a CollimatorSetup instance to this ControlPoint.

Raises:

  • (ArgumentError)


139
140
141
142
143
# File 'lib/rtkit/control_point.rb', line 139

def add_collimator(coll)
  raise ArgumentError, "Invalid argument 'coll'. Expected CollimatorSetup, got #{coll.class}." unless coll.is_a?(CollimatorSetup)
  @collimators << coll unless @associated_collimators[coll.type]
  @associated_collimators[coll.type] = coll
end

#collimator(*args) ⇒ Object

Returns the CollimatorSetup instance mathcing the specified device type string (if an argument is used). If a specified type doesn’t match, nil is returned. If no argument is passed, the first CollimatorSetup instance associated with the ControlPoint is returned.

Parameters

  • type – String. The RT Beam Limiting Device Type value.

Raises:

  • (ArgumentError)


153
154
155
156
157
158
159
160
161
# File 'lib/rtkit/control_point.rb', line 153

def collimator(*args)
  raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length)
  if args.length == 1
    return @associated_collimators[args.first && args.first.to_s]
  else
    # No argument used, therefore we return the first CollimatorSetup instance:
    return @collimators.first
  end
end

#hashObject

Generates a Fixnum hash value for this instance.



226
227
228
# File 'lib/rtkit/control_point.rb', line 226

def hash
  state.hash
end

#to_control_pointObject

Returns self.



333
334
335
# File 'lib/rtkit/control_point.rb', line 333

def to_control_point
  self
end

#to_itemObject

Creates and returns a Control Point Sequence Item from the attributes of the ControlPoint.



339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/rtkit/control_point.rb', line 339

def to_item
  item = DICOM::Item.new
  item.add(DICOM::Element.new(ROI_COLOR, @color))
  s = DICOM::Sequence.new(CONTOUR_SQ)
  item.add(s)
  item.add(DICOM::Element.new(REF_ROI_NUMBER, @number.to_s))
  # Add Contour items to the Contour Sequence (one or several items per Slice):
  @slices.each do |slice|
    slice.contours.each do |contour|
      s.add_item(contour.to_item)
    end
  end
  return item
end