Class: RTP::ControlPoint

Inherits:
Record
  • Object
show all
Defined in:
lib/rtp-connect/control_point.rb

Overview

Note:

Relations:

  • Parent: Field

  • Children: none

The ControlPoint class.

Instance Attribute Summary collapse

Attributes inherited from Record

#crc, #keyword

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#encode, #get_parent, #to_record

Constructor Details

#initialize(parent) ⇒ ControlPoint

Creates a new ControlPoint.

Parameters:

  • parent (Record)

    a record which is used to determine the proper parent of this instance



109
110
111
112
113
114
115
116
117
118
# File 'lib/rtp-connect/control_point.rb', line 109

def initialize(parent)
  # Child:
  @mlc_shape = nil
  # Parent relation (may get more than one type of record here):
  @parent = get_parent(parent.to_record, Field)
  @parent.add_control_point(self)
  @keyword = 'CONTROL_PT_DEF'
  @mlc_lp_a = Array.new(100)
  @mlc_lp_b = Array.new(100)
end

Instance Attribute Details

#collimator_angleObject

Returns the value of attribute collimator_angle.



29
30
31
# File 'lib/rtp-connect/control_point.rb', line 29

def collimator_angle
  @collimator_angle
end

#collimator_dirObject

Returns the value of attribute collimator_dir.



30
31
32
# File 'lib/rtp-connect/control_point.rb', line 30

def collimator_dir
  @collimator_dir
end

#collimator_x1Object

Returns the value of attribute collimator_x1.



33
34
35
# File 'lib/rtp-connect/control_point.rb', line 33

def collimator_x1
  @collimator_x1
end

#collimator_x2Object

Returns the value of attribute collimator_x2.



34
35
36
# File 'lib/rtp-connect/control_point.rb', line 34

def collimator_x2
  @collimator_x2
end

#collimator_y1Object

Returns the value of attribute collimator_y1.



37
38
39
# File 'lib/rtp-connect/control_point.rb', line 37

def collimator_y1
  @collimator_y1
end

#collimator_y2Object

Returns the value of attribute collimator_y2.



38
39
40
# File 'lib/rtp-connect/control_point.rb', line 38

def collimator_y2
  @collimator_y2
end

#control_pt_numberObject

Returns the value of attribute control_pt_number.



19
20
21
# File 'lib/rtp-connect/control_point.rb', line 19

def control_pt_number
  @control_pt_number
end

#couch_angleObject

Returns the value of attribute couch_angle.



42
43
44
# File 'lib/rtp-connect/control_point.rb', line 42

def couch_angle
  @couch_angle
end

#couch_dirObject

Returns the value of attribute couch_dir.



43
44
45
# File 'lib/rtp-connect/control_point.rb', line 43

def couch_dir
  @couch_dir
end

#couch_lateralObject

Returns the value of attribute couch_lateral.



40
41
42
# File 'lib/rtp-connect/control_point.rb', line 40

def couch_lateral
  @couch_lateral
end

#couch_longitudinalObject

Returns the value of attribute couch_longitudinal.



41
42
43
# File 'lib/rtp-connect/control_point.rb', line 41

def couch_longitudinal
  @couch_longitudinal
end

#couch_ped_dirObject

Returns the value of attribute couch_ped_dir.



45
46
47
# File 'lib/rtp-connect/control_point.rb', line 45

def couch_ped_dir
  @couch_ped_dir
end

#couch_pedestalObject

Returns the value of attribute couch_pedestal.



44
45
46
# File 'lib/rtp-connect/control_point.rb', line 44

def couch_pedestal
  @couch_pedestal
end

#couch_verticalObject

Returns the value of attribute couch_vertical.



39
40
41
# File 'lib/rtp-connect/control_point.rb', line 39

def couch_vertical
  @couch_vertical
end

#doserateObject

Returns the value of attribute doserate.



24
25
26
# File 'lib/rtp-connect/control_point.rb', line 24

def doserate
  @doserate
end

#energyObject

Returns the value of attribute energy.



23
24
25
# File 'lib/rtp-connect/control_point.rb', line 23

def energy
  @energy
end

#field_idObject

Returns the value of attribute field_id.



15
16
17
# File 'lib/rtp-connect/control_point.rb', line 15

def field_id
  @field_id
end

#field_xObject

Returns the value of attribute field_x.



32
33
34
# File 'lib/rtp-connect/control_point.rb', line 32

def field_x
  @field_x
end

#field_x_modeObject

Returns the value of attribute field_x_mode.



31
32
33
# File 'lib/rtp-connect/control_point.rb', line 31

def field_x_mode
  @field_x_mode
end

#field_yObject

Returns the value of attribute field_y.



36
37
38
# File 'lib/rtp-connect/control_point.rb', line 36

def field_y
  @field_y
end

#field_y_modeObject

Returns the value of attribute field_y_mode.



35
36
37
# File 'lib/rtp-connect/control_point.rb', line 35

def field_y_mode
  @field_y_mode
end

#gantry_angleObject

Returns the value of attribute gantry_angle.



27
28
29
# File 'lib/rtp-connect/control_point.rb', line 27

def gantry_angle
  @gantry_angle
end

#gantry_dirObject

Returns the value of attribute gantry_dir.



28
29
30
# File 'lib/rtp-connect/control_point.rb', line 28

def gantry_dir
  @gantry_dir
end

#mlc_leavesObject

Returns the value of attribute mlc_leaves.



17
18
19
# File 'lib/rtp-connect/control_point.rb', line 17

def mlc_leaves
  @mlc_leaves
end

#mlc_lp_aObject

Note: This attribute contains an array of all MLC LP A values (leaves 1..100).



47
48
49
# File 'lib/rtp-connect/control_point.rb', line 47

def mlc_lp_a
  @mlc_lp_a
end

#mlc_lp_bObject

Note: This attribute contains an array of all MLC LP B values (leaves 1..100).



49
50
51
# File 'lib/rtp-connect/control_point.rb', line 49

def mlc_lp_b
  @mlc_lp_b
end

#mlc_shapeObject (readonly)

The MLC shape record (if any) that belongs to this ControlPoint.



14
15
16
# File 'lib/rtp-connect/control_point.rb', line 14

def mlc_shape
  @mlc_shape
end

#mlc_typeObject

Returns the value of attribute mlc_type.



16
17
18
# File 'lib/rtp-connect/control_point.rb', line 16

def mlc_type
  @mlc_type
end

#monitor_unitsObject

Returns the value of attribute monitor_units.



21
22
23
# File 'lib/rtp-connect/control_point.rb', line 21

def monitor_units
  @monitor_units
end

#mu_conventionObject

Returns the value of attribute mu_convention.



20
21
22
# File 'lib/rtp-connect/control_point.rb', line 20

def mu_convention
  @mu_convention
end

#parentObject (readonly)

The Record which this instance belongs to.



12
13
14
# File 'lib/rtp-connect/control_point.rb', line 12

def parent
  @parent
end

#scale_conventionObject

Returns the value of attribute scale_convention.



26
27
28
# File 'lib/rtp-connect/control_point.rb', line 26

def scale_convention
  @scale_convention
end

#ssdObject

Returns the value of attribute ssd.



25
26
27
# File 'lib/rtp-connect/control_point.rb', line 25

def ssd
  @ssd
end

#total_control_pointsObject

Returns the value of attribute total_control_points.



18
19
20
# File 'lib/rtp-connect/control_point.rb', line 18

def total_control_points
  @total_control_points
end

#wedge_positionObject

Returns the value of attribute wedge_position.



22
23
24
# File 'lib/rtp-connect/control_point.rb', line 22

def wedge_position
  @wedge_position
end

Class Method Details

.load(string, parent) ⇒ ControlPoint

Creates a new ControlPoint by parsing a RTPConnect string line.

Parameters:

  • string (#to_s)

    the control point definition record string line

  • parent (Record)

    a record which is used to determine the proper parent of this instance

Returns:

Raises:

  • (ArgumentError)

    if given a string containing an invalid number of elements



58
59
60
61
62
63
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
95
96
97
98
99
100
101
102
103
# File 'lib/rtp-connect/control_point.rb', line 58

def self.load(string, parent)
  # Get the quote-less values:
  values = string.to_s.values
  low_limit = 233
  high_limit = 233
  raise ArgumentError, "Invalid argument 'string': Expected at least #{low_limit} elements, got #{values.length}." if values.length < low_limit
  RTP.logger.warn "The number of elements (#{values.length}) for this ControlPoint record exceeds the known number of data items for this record (#{high_limit}). This may indicate an invalid record or that the RTP format has recently been expanded with new items." if values.length > high_limit
  cp = self.new(parent)
  # Assign the values to attributes:
  cp.keyword = values[0]
  cp.field_id = values[1]
  cp.mlc_type = values[2]
  cp.mlc_leaves = values[3]
  cp.total_control_points = values[4]
  cp.control_pt_number = values[5]
  cp.mu_convention = values[6]
  cp.monitor_units = values[7]
  cp.wedge_position = values[8]
  cp.energy = values[9]
  cp.doserate = values[10]
  cp.ssd = values[11]
  cp.scale_convention = values[12]
  cp.gantry_angle = values[13]
  cp.gantry_dir = values[14]
  cp.collimator_angle = values[15]
  cp.collimator_dir = values[16]
  cp.field_x_mode = values[17]
  cp.field_x = values[18]
  cp.collimator_x1 = values[19]
  cp.collimator_x2 = values[20]
  cp.field_y_mode = values[21]
  cp.field_y = values[22]
  cp.collimator_y1 = values[23]
  cp.collimator_y2 = values[24]
  cp.couch_vertical = values[25]
  cp.couch_lateral = values[26]
  cp.couch_longitudinal = values[27]
  cp.couch_angle = values[28]
  cp.couch_dir = values[29]
  cp.couch_pedestal = values[30]
  cp.couch_ped_dir = values[31]
  cp.mlc_lp_a = [*values[32..131]]
  cp.mlc_lp_b = [*values[132..231]]
  cp.crc = values[-1]
  return cp
end

Instance Method Details

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

Checks for equality.

Other and self are considered equivalent if they are of compatible types and their attributes are equivalent.

Parameters:

  • other

    an object to be compared with self.

Returns:

  • (Boolean)

    true if self and other are considered equivalent



128
129
130
131
132
# File 'lib/rtp-connect/control_point.rb', line 128

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

#childrenArray

As of now, gives an empty array. However, by definition, this record may have an mlc shape record as child, but this is not implemented yet.

Returns:

  • (Array)

    an emtpy array



141
142
143
144
# File 'lib/rtp-connect/control_point.rb', line 141

def children
  #return [@mlc_shape]
  return Array.new
end

#hashFixnum

Note:

Two objects with the same attributes will have the same hash code.

Computes a hash code for this object.

Returns:

  • (Fixnum)

    the object’s hash code



152
153
154
# File 'lib/rtp-connect/control_point.rb', line 152

def hash
  state.hash
end

#indexFixnum

Gives the index of this ControlPoint (i.e. its index among the control points belonging to the parent Field).

Returns:

  • (Fixnum)

    the control point’s index



161
162
163
# File 'lib/rtp-connect/control_point.rb', line 161

def index
  @parent.control_points.index(self)
end

#keyword=(value) ⇒ Object

Note:

Since only a specific string is accepted, this is more of an argument check than a traditional setter method

Sets the keyword attribute.

Parameters:

  • value (#to_s)

    the new attribute value

Raises:

  • (ArgumentError)

    if given an unexpected keyword



264
265
266
267
268
# File 'lib/rtp-connect/control_point.rb', line 264

def keyword=(value)
  value = value.to_s.upcase
  raise ArgumentError, "Invalid keyword. Expected 'CONTROL_PT_DEF', got #{value}." unless value == "CONTROL_PT_DEF"
  @keyword = value
end

#to_control_pointControlPoint

Returns self.

Returns:



213
214
215
# File 'lib/rtp-connect/control_point.rb', line 213

def to_control_point
  self
end

#to_sString Also known as: to_str

Encodes the ControlPoint object + any hiearchy of child objects, to a properly formatted RTPConnect ascii string.

Returns:

  • (String)

    an RTP string with a single or multiple lines/records



222
223
224
225
226
227
228
229
230
# File 'lib/rtp-connect/control_point.rb', line 222

def to_s
  str = encode
  if children
    children.each do |child|
      str += child.to_s
    end
  end
  return str
end

#valuesArray<String> Also known as: state

Note:

The CRC is not considered part of the actual values and is excluded.

Collects the values (attributes) of this instance.

Returns:

  • (Array<String>)

    an array of attributes (in the same order as they appear in the RTP string)



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/rtp-connect/control_point.rb', line 170

def values
  return [
    @keyword,
    @field_id,
    @mlc_type,
    @mlc_leaves,
    @total_control_points,
    @control_pt_number,
    @mu_convention,
    @monitor_units,
    @wedge_position,
    @energy,
    @doserate,
    @ssd,
    @scale_convention,
    @gantry_angle,
    @gantry_dir,
    @collimator_angle,
    @collimator_dir,
    @field_x_mode,
    @field_x,
    @collimator_x1,
    @collimator_x2,
    @field_y_mode,
    @field_y,
    @collimator_y1,
    @collimator_y2,
    @couch_vertical,
    @couch_lateral,
    @couch_longitudinal,
    @couch_angle,
    @couch_dir,
    @couch_pedestal,
    @couch_ped_dir,
    *@mlc_lp_a,
    *@mlc_lp_b
  ]
end