module RTP

Copyright 2011-2020 Christoffer Lervag

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Constants

CRC_SEED

The seed value used in the RTPConnect implementation of the CCITT algorithm.

CRC_TABLE

The table & values used in the RTPConnect implementation of the CCITT algorithm.

PARSE_METHOD

Pairs of RTPConnect keywords and parse method names.

VERSION

The RTPConnect library version string.

Public Class Methods

leaf_boundaries(nr_leaves) click to toggle source

Gives an array of MLC leaf position boundaries for a given type of MLC, specified by its number of leaves at one side.

@param [Fixnum] nr_leaves the number of leaves (in one leaf bank) @return [Array<Fixnum>] the leaf boundary positions @raise [ArgumentError] if an unsupported MLC (nr of leaves) is given

# File lib/rtp-connect/methods.rb, line 16
def leaf_boundaries(nr_leaves)
  case nr_leaves
  when 29
    leaf_boundaries_odd(29)
  when 40
    leaf_boundaries_even(40)
  when 41
    leaf_boundaries_odd(41)
  when 60
    leaf_boundaries_varian_60
  when 80
    leaf_boundaries_even(80)
  else
    raise ArgumentError, "Unsupported number of leaves: #{nr_leaves}"
  end
end
leaf_boundaries_even(nr_leaves) click to toggle source

Gives an array of MLC leaf position boundaries for ordinary even numbered multi leaf collimators.

@param [Fixnum] nr_leaves the number of leaves (in one leaf bank) @return [Array<Fixnum>] the leaf boundary positions

# File lib/rtp-connect/methods.rb, line 39
def leaf_boundaries_even(nr_leaves)
  Array.new(nr_leaves+1) {|i| (i * 400 / nr_leaves.to_f - 200).to_i}
end
leaf_boundaries_odd(nr_leaves) click to toggle source

Gives an array of MLC leaf position boundaries for ordinary odd numbered multi leaf collimators.

@param [Fixnum] nr_leaves the number of leaves (in one leaf bank) @return [Array<Fixnum>] the leaf boundary positions

# File lib/rtp-connect/methods.rb, line 49
def leaf_boundaries_odd(nr_leaves)
  Array.new(nr_leaves-1) {|i| (10 * (i - (0.5 * nr_leaves - 1))).to_i}.unshift(-200).push(200)
end
leaf_boundaries_varian_60() click to toggle source

Gives an array of MLC leaf position boundaries for the Varian 120 leaf MLC (60 leaves on each bank).

@return [Array<Fixnum>] the leaf boundary positions

# File lib/rtp-connect/methods.rb, line 57
def leaf_boundaries_varian_60
  Array.new(10) {|i| (i * 10 - 200).to_i}
      .concat(Array.new(41) {|i| (i * 5 - 100).to_i})
      .concat(Array.new(10) {|i| (i * 10 + 110).to_i})
end
verify(line, options={}) click to toggle source

Computes the CRC checksum of the given line and verifies that this value corresponds with the checksum given at the end of the line.

@param [String] line a single line string from an RTPConnect ascii file @param [Hash] options the options to use for verifying the RTP record @option options [Boolean] :ignore_crc if true, the verification method will return true even if the checksum is invalid @return [Boolean] true @raise [ArgumentError] if an invalid line/record is given or the string contains an invalid checksum

# File lib/rtp-connect/methods.rb, line 72
def verify(line, options={})
  last_comma_pos = line.rindex(',')
  raise ArgumentError, "Invalid line encountered; No comma present in the string: #{line}" unless last_comma_pos
  string_to_check = line[0..last_comma_pos]
  string_remaining = line[(last_comma_pos+1)..-1]
  raise ArgumentError, "Invalid line encountered; Valid checksum missing at end of string: #{string_remaining}" unless string_remaining.length >= 3
  checksum_extracted = string_remaining.value.to_i
  checksum_computed = string_to_check.checksum
  raise ArgumentError, "Invalid line encountered: Specified checksum #{checksum_extracted} deviates from the computed checksum #{checksum_computed}." if checksum_extracted != checksum_computed && !options[:ignore_crc]
  return true
end