Class: RTKIT::Frame
- Inherits:
-
Object
- Object
- RTKIT::Frame
- Defined in:
- lib/rtkit/frame.rb
Overview
Contains the DICOM data and methods related to a Frame of Reference.
Relations
-
A Frame of Reference belongs to a Patient.
-
A Frame of Reference can have many ImageSeries.
Instance Attribute Summary collapse
-
#image_series ⇒ Object
readonly
An array of ImageSeries belonging to this Frame.
-
#indicator ⇒ Object
readonly
The Position Reference Indicator (an optional annotation indicating the anatomical reference location).
-
#patient ⇒ Object
readonly
The Patient which this Frame of Reference belongs to.
-
#rois ⇒ Object
readonly
An array of ROI instances belonging to this Frame.
-
#uid ⇒ Object
readonly
The Frame of Reference UID.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns true if the argument is an instance with attributes equal to self.
-
#add_image(image) ⇒ Object
Adds an Image to this Frame.
-
#add_roi(roi) ⇒ Object
Adds a ROI to this Frame.
-
#add_series(series) ⇒ Object
Adds an ImageSeries to this Frame.
-
#hash ⇒ Object
Generates a Fixnum hash value for this instance.
-
#image(*args) ⇒ Object
Returns the Image instance mathcing the specified SOP Instance UID (if an argument is used).
-
#initialize(uid, patient, options = {}) ⇒ Frame
constructor
Creates a new Frame instance.
-
#roi(name_or_number) ⇒ Object
Returns a ROI that matches the specified number or name.
-
#series(*args) ⇒ Object
Returns the ImageSeries instance mathcing the specified Series Instance UID (if an argument is used).
-
#to_frame ⇒ Object
Returns self.
Constructor Details
#initialize(uid, patient, options = {}) ⇒ Frame
Creates a new Frame instance. The Frame of Reference UID tag value uniquely identifies the Frame.
Parameters
-
uid
– The Frame of Reference UID string. -
patient
– The Patient instance that this Frame belongs to. -
options
– A hash of parameters.
Options
-
:indicator
– The Position Reference Indicator string.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rtkit/frame.rb', line 35 def initialize(uid, patient, ={}) raise ArgumentError, "Invalid argument 'uid'. Expected String, got #{uid.class}." unless uid.is_a?(String) raise ArgumentError, "Invalid argument 'patient'. Expected Patient, got #{patient.class}." unless patient.is_a?(Patient) raise ArgumentError, "Invalid option :indicator. Expected String, got #{indicator.class}." if [:indicator] && ![:indicator].is_a?(String) @associated_series = Hash.new @associated_instance_uids = Hash.new @image_series = Array.new @rois = Array.new @uid = uid @patient = patient @indicator = [:indicator] # Register ourselves with the patient and its dataset: @patient.add_frame(self) @patient.dataset.add_frame(self) end |
Instance Attribute Details
#image_series ⇒ Object (readonly)
An array of ImageSeries belonging to this Frame.
13 14 15 |
# File 'lib/rtkit/frame.rb', line 13 def image_series @image_series end |
#indicator ⇒ Object (readonly)
The Position Reference Indicator (an optional annotation indicating the anatomical reference location).
15 16 17 |
# File 'lib/rtkit/frame.rb', line 15 def indicator @indicator end |
#patient ⇒ Object (readonly)
The Patient which this Frame of Reference belongs to.
17 18 19 |
# File 'lib/rtkit/frame.rb', line 17 def patient @patient end |
#rois ⇒ Object (readonly)
An array of ROI instances belonging to this Frame.
19 20 21 |
# File 'lib/rtkit/frame.rb', line 19 def rois @rois end |
#uid ⇒ Object (readonly)
The Frame of Reference UID.
21 22 23 |
# File 'lib/rtkit/frame.rb', line 21 def uid @uid end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true if the argument is an instance with attributes equal to self.
53 54 55 56 57 |
# File 'lib/rtkit/frame.rb', line 53 def ==(other) if other.respond_to?(:to_frame) other.send(:state) == state end end |
#add_image(image) ⇒ Object
Adds an Image to this Frame.
63 64 65 66 67 68 69 |
# File 'lib/rtkit/frame.rb', line 63 def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) #@images << image @associated_instance_uids[image.uid] = image # If the ImageSeries of an added Image is not connected to this Frame yet, do so: add_series(image.series) unless series(image.series.uid) end |
#add_roi(roi) ⇒ Object
Adds a ROI to this Frame.
73 74 75 76 |
# File 'lib/rtkit/frame.rb', line 73 def add_roi(roi) raise ArgumentError, "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi.is_a?(ROI) @rois << roi unless @rois.include?(roi) end |
#add_series(series) ⇒ Object
Adds an ImageSeries to this Frame.
80 81 82 83 84 |
# File 'lib/rtkit/frame.rb', line 80 def add_series(series) raise ArgumentError, "Invalid argument 'series' Expected ImageSeries or DoseVolume, got #{series.class}." unless [ImageSeries, DoseVolume].include?(series.class) @image_series << series @associated_series[series.uid] = series end |
#hash ⇒ Object
Generates a Fixnum hash value for this instance.
88 89 90 |
# File 'lib/rtkit/frame.rb', line 88 def hash state.hash end |
#image(*args) ⇒ Object
Returns the Image instance mathcing the specified SOP Instance UID (if an argument is used). If a specified UID doesn’t match, nil is returned. If no argument is passed, the first Image of the first ImageSeries instance associated with the Frame is returned.
Parameters
-
uid
– String. The value of the Series Instance UID element.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rtkit/frame.rb', line 100 def image(*args) raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length) if args.length == 1 raise ArgumentError, "Expected String (or nil), got #{args.first.class}." unless [String, NilClass].include?(args.first.class) return @associated_instance_uids[args.first] else # No argument used, therefore we return the first Image of the first ImageSeries instance: return @image_series.first.image end end |
#roi(name_or_number) ⇒ Object
Returns a ROI that matches the specified number or name. Returns nil if no match is found.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rtkit/frame.rb', line 114 def roi(name_or_number) raise ArgumentError, "Invalid argument 'name_or_number'. Expected String or Integer, got #{name_or_number.class}." unless [String, Integer, Fixnum].include?(name_or_number.class) if name_or_number.is_a?(String) @rois.each do |r| return r if r.name == name_or_number end else @rois.each do |r| return r if r.number == name_or_number end end return nil end |
#series(*args) ⇒ Object
Returns the ImageSeries instance mathcing the specified Series Instance UID (if an argument is used). If a specified UID doesn’t match, nil is returned. If no argument is passed, the first Series instance associated with the Frame is returned.
Parameters
-
uid
– String. The value of the Series Instance UID element.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rtkit/frame.rb', line 136 def series(*args) raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length) if args.length == 1 raise ArgumentError, "Expected String (or nil), got #{args.first.class}." unless [String, NilClass].include?(args.first.class) return @associated_series[args.first] else # No argument used, therefore we return the first Study instance: return @image_series.first end end |
#to_frame ⇒ Object
Returns self.
149 150 151 |
# File 'lib/rtkit/frame.rb', line 149 def to_frame self end |