Class: RTKIT::Collimator

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

Overview

Contains DICOM data and methods related to a RT Beam Limiting Device item, defined in a Beam.

Relations

  • A Beam has many Collimators.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, num_pairs, beam, options = {}) ⇒ Collimator

Creates a new Collimator instance.

Parameters

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

  • num_pairs – Integer. The Number of Leaf/Jaw Pairs.

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

  • options – A hash of parameters.

Options

  • :boundaries – Array/String. The Leaf Position Boundaries (300A,00BE). Defaults to nil.

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rtkit/collimator.rb', line 55

def initialize(type, num_pairs, beam, options={})
  raise ArgumentError, "Invalid argument 'beam'. Expected Beam, got #{beam.class}." unless beam.is_a?(Beam)
  # Set values:
  self.type = type
  self.num_pairs = num_pairs
  self.boundaries = options[:boundaries]
  # Set references:
  @beam = beam
  # Register ourselves with the Beam:
  @beam.add_collimator(self)
end

Instance Attribute Details

#beamObject (readonly)

The Beam that the CollimatorSetup is defined for.



13
14
15
# File 'lib/rtkit/collimator.rb', line 13

def beam
  @beam
end

#boundariesObject

Collimator boundaries (for multi leaf collimators only: the number of boundaries equals the number of leaves + 1).



15
16
17
# File 'lib/rtkit/collimator.rb', line 15

def boundaries
  @boundaries
end

#num_pairsObject

The number of Leaf/Jaw (Collimator) Pairs.



17
18
19
# File 'lib/rtkit/collimator.rb', line 17

def num_pairs
  @num_pairs
end

#typeObject

Collimator type.



19
20
21
# File 'lib/rtkit/collimator.rb', line 19

def type
  @type
end

Class Method Details

.create_from_item(coll_item, beam) ⇒ Object

Creates a new Collimator instance from the RT Beam Limiting Device item of the RTPlan file. Returns the Collimator instance.

Parameters

  • coll_item – The patient setup item from the DObject of a RTPlan file.

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

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rtkit/collimator.rb', line 29

def self.create_from_item(coll_item, beam)
  raise ArgumentError, "Invalid argument 'coll_item'. Expected DICOM::Item, got #{coll_item.class}." unless coll_item.is_a?(DICOM::Item)
  raise ArgumentError, "Invalid argument 'beam'. Expected Beam, got #{beam.class}." unless beam.is_a?(Beam)
  options = Hash.new
  # Values from the Beam Limiting Device Type Item:
  type = coll_item.value(COLL_TYPE)
  num_pairs = coll_item.value(NR_COLLIMATORS)
  boundaries = coll_item.value(COLL_BOUNDARIES)
  # Create the Collimator instance:
  c = self.new(type, num_pairs, beam, :boundaries => boundaries)
  return c
end

Instance Method Details

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

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



69
70
71
72
73
# File 'lib/rtkit/collimator.rb', line 69

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

#hashObject

Generates a Fixnum hash value for this instance.



79
80
81
# File 'lib/rtkit/collimator.rb', line 79

def hash
  state.hash
end

#to_collimatorObject

Returns self.



131
132
133
# File 'lib/rtkit/collimator.rb', line 131

def to_collimator
  self
end

#to_itemObject

Creates and returns a Beam Limiting Device Sequence Item from the attributes of the Collimator.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rtkit/collimator.rb', line 86

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