id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
22,900
dicom/rtkit
lib/rtkit/data_set.rb
RTKIT.DataSet.add
def add(dcm) id = dcm.value(PATIENTS_ID) p = patient(id) if p p.add(dcm) else add_patient(Patient.load(dcm, self)) end end
ruby
def add(dcm) id = dcm.value(PATIENTS_ID) p = patient(id) if p p.add(dcm) else add_patient(Patient.load(dcm, self)) end end
[ "def", "add", "(", "dcm", ")", "id", "=", "dcm", ".", "value", "(", "PATIENTS_ID", ")", "p", "=", "patient", "(", "id", ")", "if", "p", "p", ".", "add", "(", "dcm", ")", "else", "add_patient", "(", "Patient", ".", "load", "(", "dcm", ",", "self", ")", ")", "end", "end" ]
Adds a DICOM object to the dataset, by adding it to an existing Patient, or creating a new Patient. @note To ensure a correct relationship between objects of different modality, please add DICOM objects in the specific order: images, structs, plans, doses, rtimages. Alternatively, use the class method DataSet.load(objects), which handles this automatically. @param [DICOM::DObject] dcm a DICOM object to be added to this data set
[ "Adds", "a", "DICOM", "object", "to", "the", "dataset", "by", "adding", "it", "to", "an", "existing", "Patient", "or", "creating", "a", "new", "Patient", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/data_set.rb#L140-L148
22,901
dicom/rtkit
lib/rtkit/data_set.rb
RTKIT.DataSet.add_frame
def add_frame(frame) raise ArgumentError, "Invalid argument 'frame'. Expected Frame, got #{frame.class}." unless frame.is_a?(Frame) # Do not add it again if the frame already belongs to this instance: @frames << frame unless @associated_frames[frame.uid] @associated_frames[frame.uid] = frame end
ruby
def add_frame(frame) raise ArgumentError, "Invalid argument 'frame'. Expected Frame, got #{frame.class}." unless frame.is_a?(Frame) # Do not add it again if the frame already belongs to this instance: @frames << frame unless @associated_frames[frame.uid] @associated_frames[frame.uid] = frame end
[ "def", "add_frame", "(", "frame", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'frame'. Expected Frame, got #{frame.class}.\"", "unless", "frame", ".", "is_a?", "(", "Frame", ")", "# Do not add it again if the frame already belongs to this instance:", "@frames", "<<", "frame", "unless", "@associated_frames", "[", "frame", ".", "uid", "]", "@associated_frames", "[", "frame", ".", "uid", "]", "=", "frame", "end" ]
Adds a Frame to this DataSet. @param [Frame] frame a Frame object to be added to this data set
[ "Adds", "a", "Frame", "to", "this", "DataSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/data_set.rb#L154-L159
22,902
dicom/rtkit
lib/rtkit/data_set.rb
RTKIT.DataSet.add_patient
def add_patient(patient) raise ArgumentError, "Invalid argument 'patient'. Expected Patient, got #{patient.class}." unless patient.is_a?(Patient) # Do not add it again if the patient already belongs to this instance: @patients << patient unless @associated_patients[patient.id] @associated_patients[patient.id] = patient end
ruby
def add_patient(patient) raise ArgumentError, "Invalid argument 'patient'. Expected Patient, got #{patient.class}." unless patient.is_a?(Patient) # Do not add it again if the patient already belongs to this instance: @patients << patient unless @associated_patients[patient.id] @associated_patients[patient.id] = patient end
[ "def", "add_patient", "(", "patient", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'patient'. Expected Patient, got #{patient.class}.\"", "unless", "patient", ".", "is_a?", "(", "Patient", ")", "# Do not add it again if the patient already belongs to this instance:", "@patients", "<<", "patient", "unless", "@associated_patients", "[", "patient", ".", "id", "]", "@associated_patients", "[", "patient", ".", "id", "]", "=", "patient", "end" ]
Adds a Patient to this DataSet. @param [Patient] patient a Patient object to be added to this data set
[ "Adds", "a", "Patient", "to", "this", "DataSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/data_set.rb#L165-L170
22,903
dicom/rtkit
lib/rtkit/data_set.rb
RTKIT.DataSet.print
def print @patients.each do |p| puts p.name p.studies.each do |st| puts " #{st.uid}" st.series.each do |se| puts " #{se.modality}" if se.respond_to?(:images) && se.images puts " (#{se.images.length} images)" end end end end end
ruby
def print @patients.each do |p| puts p.name p.studies.each do |st| puts " #{st.uid}" st.series.each do |se| puts " #{se.modality}" if se.respond_to?(:images) && se.images puts " (#{se.images.length} images)" end end end end end
[ "def", "print", "@patients", ".", "each", "do", "|", "p", "|", "puts", "p", ".", "name", "p", ".", "studies", ".", "each", "do", "|", "st", "|", "puts", "\" #{st.uid}\"", "st", ".", "series", ".", "each", "do", "|", "se", "|", "puts", "\" #{se.modality}\"", "if", "se", ".", "respond_to?", "(", ":images", ")", "&&", "se", ".", "images", "puts", "\" (#{se.images.length} images)\"", "end", "end", "end", "end", "end" ]
Prints the nested structure of patient - study - series - images that have been loaded in the DataSet instance.
[ "Prints", "the", "nested", "structure", "of", "patient", "-", "study", "-", "series", "-", "images", "that", "have", "been", "loaded", "in", "the", "DataSet", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/data_set.rb#L223-L236
22,904
dicom/rtkit
lib/rtkit/data_set.rb
RTKIT.DataSet.print_rt
def print_rt @patients.each do |p| puts p.name p.studies.each do |st| puts " Study (UID: #{st.uid})" st.image_series.each do |is| puts " #{is.modality} (#{is.images.length} images - UID: #{is.uid})" is.structs.each do |struct| puts " StructureSet (#{struct.rois.length} ROIs - UID: #{struct.uid})" struct.plans.each do |plan| puts " RTPlan (#{plan.beams.length} beams - UID: #{plan.uid})" plan.rt_doses.each do |rt_dose| puts " RTDose (#{rt_dose.volumes.length} volumes - UID: #{rt_dose.uid})" end plan.rt_images.each do |rt_image| puts " RTImage (#{rt_image.images.length} images - UID: #{rt_image.uid})" end end end end end end end
ruby
def print_rt @patients.each do |p| puts p.name p.studies.each do |st| puts " Study (UID: #{st.uid})" st.image_series.each do |is| puts " #{is.modality} (#{is.images.length} images - UID: #{is.uid})" is.structs.each do |struct| puts " StructureSet (#{struct.rois.length} ROIs - UID: #{struct.uid})" struct.plans.each do |plan| puts " RTPlan (#{plan.beams.length} beams - UID: #{plan.uid})" plan.rt_doses.each do |rt_dose| puts " RTDose (#{rt_dose.volumes.length} volumes - UID: #{rt_dose.uid})" end plan.rt_images.each do |rt_image| puts " RTImage (#{rt_image.images.length} images - UID: #{rt_image.uid})" end end end end end end end
[ "def", "print_rt", "@patients", ".", "each", "do", "|", "p", "|", "puts", "p", ".", "name", "p", ".", "studies", ".", "each", "do", "|", "st", "|", "puts", "\" Study (UID: #{st.uid})\"", "st", ".", "image_series", ".", "each", "do", "|", "is", "|", "puts", "\" #{is.modality} (#{is.images.length} images - UID: #{is.uid})\"", "is", ".", "structs", ".", "each", "do", "|", "struct", "|", "puts", "\" StructureSet (#{struct.rois.length} ROIs - UID: #{struct.uid})\"", "struct", ".", "plans", ".", "each", "do", "|", "plan", "|", "puts", "\" RTPlan (#{plan.beams.length} beams - UID: #{plan.uid})\"", "plan", ".", "rt_doses", ".", "each", "do", "|", "rt_dose", "|", "puts", "\" RTDose (#{rt_dose.volumes.length} volumes - UID: #{rt_dose.uid})\"", "end", "plan", ".", "rt_images", ".", "each", "do", "|", "rt_image", "|", "puts", "\" RTImage (#{rt_image.images.length} images - UID: #{rt_image.uid})\"", "end", "end", "end", "end", "end", "end", "end" ]
Prints the nested structure of the DataSet from a radiotherapy point of view, where the various series beneath the patient-study level is presented in a hiearchy of image series, structure set, rt plan, rt dose and rt image, in accordance with the object hiearchy used by RTKIT.
[ "Prints", "the", "nested", "structure", "of", "the", "DataSet", "from", "a", "radiotherapy", "point", "of", "view", "where", "the", "various", "series", "beneath", "the", "patient", "-", "study", "level", "is", "presented", "in", "a", "hiearchy", "of", "image", "series", "structure", "set", "rt", "plan", "rt", "dose", "and", "rt", "image", "in", "accordance", "with", "the", "object", "hiearchy", "used", "by", "RTKIT", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/data_set.rb#L243-L265
22,905
jlong/radius
lib/radius/context.rb
Radius.Context.stack
def stack(name, attributes, block) previous = @tag_binding_stack.last previous_locals = previous.nil? ? globals : previous.locals locals = DelegatingOpenStruct.new(previous_locals) binding = TagBinding.new(self, locals, name, attributes, block) @tag_binding_stack.push(binding) result = yield(binding) @tag_binding_stack.pop result end
ruby
def stack(name, attributes, block) previous = @tag_binding_stack.last previous_locals = previous.nil? ? globals : previous.locals locals = DelegatingOpenStruct.new(previous_locals) binding = TagBinding.new(self, locals, name, attributes, block) @tag_binding_stack.push(binding) result = yield(binding) @tag_binding_stack.pop result end
[ "def", "stack", "(", "name", ",", "attributes", ",", "block", ")", "previous", "=", "@tag_binding_stack", ".", "last", "previous_locals", "=", "previous", ".", "nil?", "?", "globals", ":", "previous", ".", "locals", "locals", "=", "DelegatingOpenStruct", ".", "new", "(", "previous_locals", ")", "binding", "=", "TagBinding", ".", "new", "(", "self", ",", "locals", ",", "name", ",", "attributes", ",", "block", ")", "@tag_binding_stack", ".", "push", "(", "binding", ")", "result", "=", "yield", "(", "binding", ")", "@tag_binding_stack", ".", "pop", "result", "end" ]
A convienence method for managing the various parts of the tag binding stack.
[ "A", "convienence", "method", "for", "managing", "the", "various", "parts", "of", "the", "tag", "binding", "stack", "." ]
e7b4eab374c6a15e105524ccd663767b8bc91e5b
https://github.com/jlong/radius/blob/e7b4eab374c6a15e105524ccd663767b8bc91e5b/lib/radius/context.rb#L95-L104
22,906
jlong/radius
lib/radius/context.rb
Radius.Context.numeric_specificity
def numeric_specificity(tag_name, nesting_parts) nesting_parts = nesting_parts.dup name_parts = tag_name.split(':') specificity = 0 value = 1 if nesting_parts.last == name_parts.last while nesting_parts.size > 0 if nesting_parts.last == name_parts.last specificity += value name_parts.pop end nesting_parts.pop value *= 0.1 end specificity = 0 if (name_parts.size > 0) end specificity end
ruby
def numeric_specificity(tag_name, nesting_parts) nesting_parts = nesting_parts.dup name_parts = tag_name.split(':') specificity = 0 value = 1 if nesting_parts.last == name_parts.last while nesting_parts.size > 0 if nesting_parts.last == name_parts.last specificity += value name_parts.pop end nesting_parts.pop value *= 0.1 end specificity = 0 if (name_parts.size > 0) end specificity end
[ "def", "numeric_specificity", "(", "tag_name", ",", "nesting_parts", ")", "nesting_parts", "=", "nesting_parts", ".", "dup", "name_parts", "=", "tag_name", ".", "split", "(", "':'", ")", "specificity", "=", "0", "value", "=", "1", "if", "nesting_parts", ".", "last", "==", "name_parts", ".", "last", "while", "nesting_parts", ".", "size", ">", "0", "if", "nesting_parts", ".", "last", "==", "name_parts", ".", "last", "specificity", "+=", "value", "name_parts", ".", "pop", "end", "nesting_parts", ".", "pop", "value", "*=", "0.1", "end", "specificity", "=", "0", "if", "(", "name_parts", ".", "size", ">", "0", ")", "end", "specificity", "end" ]
Returns the specificity for +tag_name+ at nesting defined by +nesting_parts+ as a number.
[ "Returns", "the", "specificity", "for", "+", "tag_name", "+", "at", "nesting", "defined", "by", "+", "nesting_parts", "+", "as", "a", "number", "." ]
e7b4eab374c6a15e105524ccd663767b8bc91e5b
https://github.com/jlong/radius/blob/e7b4eab374c6a15e105524ccd663767b8bc91e5b/lib/radius/context.rb#L128-L145
22,907
dicom/rtkit
lib/rtkit/coordinate.rb
RTKIT.Coordinate.translate
def translate(x, y, z) @x += x.to_f @y += y.to_f @z += z.to_f end
ruby
def translate(x, y, z) @x += x.to_f @y += y.to_f @z += z.to_f end
[ "def", "translate", "(", "x", ",", "y", ",", "z", ")", "@x", "+=", "x", ".", "to_f", "@y", "+=", "y", ".", "to_f", "@z", "+=", "z", ".", "to_f", "end" ]
Moves the coordinate according to the given offset vector. @param [Float] x the offset along the x axis (in units of mm) @param [Float] y the offset along the y axis (in units of mm) @param [Float] z the offset along the z axis (in units of mm)
[ "Moves", "the", "coordinate", "according", "to", "the", "given", "offset", "vector", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/coordinate.rb#L85-L89
22,908
celluloid/dcell
lib/dcell/resource_manager.rb
DCell.ResourceManager.register
def register(id, &block) ref = __get id return ref.__getobj__ if ref && ref.weakref_alive? item = block.call return nil unless item __register id, item end
ruby
def register(id, &block) ref = __get id return ref.__getobj__ if ref && ref.weakref_alive? item = block.call return nil unless item __register id, item end
[ "def", "register", "(", "id", ",", "&", "block", ")", "ref", "=", "__get", "id", "return", "ref", ".", "__getobj__", "if", "ref", "&&", "ref", ".", "weakref_alive?", "item", "=", "block", ".", "call", "return", "nil", "unless", "item", "__register", "id", ",", "item", "end" ]
Register an item inside the cache if it does not yet exist If the item is not found inside the cache the block attached should return a valid reference
[ "Register", "an", "item", "inside", "the", "cache", "if", "it", "does", "not", "yet", "exist", "If", "the", "item", "is", "not", "found", "inside", "the", "cache", "the", "block", "attached", "should", "return", "a", "valid", "reference" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/resource_manager.rb#L44-L50
22,909
celluloid/dcell
lib/dcell/resource_manager.rb
DCell.ResourceManager.each
def each @lock.synchronize do @items.each do |id, ref| begin yield id, ref.__getobj__ rescue WeakRef::RefError end end end end
ruby
def each @lock.synchronize do @items.each do |id, ref| begin yield id, ref.__getobj__ rescue WeakRef::RefError end end end end
[ "def", "each", "@lock", ".", "synchronize", "do", "@items", ".", "each", "do", "|", "id", ",", "ref", "|", "begin", "yield", "id", ",", "ref", ".", "__getobj__", "rescue", "WeakRef", "::", "RefError", "end", "end", "end", "end" ]
Iterates over registered and alive items
[ "Iterates", "over", "registered", "and", "alive", "items" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/resource_manager.rb#L53-L62
22,910
celluloid/dcell
lib/dcell/resource_manager.rb
DCell.ResourceManager.clear
def clear @lock.synchronize do if block_given? @items.each do |id, ref| begin yield id, ref.__getobj__ rescue WeakRef::RefError end end end @items.clear end end
ruby
def clear @lock.synchronize do if block_given? @items.each do |id, ref| begin yield id, ref.__getobj__ rescue WeakRef::RefError end end end @items.clear end end
[ "def", "clear", "@lock", ".", "synchronize", "do", "if", "block_given?", "@items", ".", "each", "do", "|", "id", ",", "ref", "|", "begin", "yield", "id", ",", "ref", ".", "__getobj__", "rescue", "WeakRef", "::", "RefError", "end", "end", "end", "@items", ".", "clear", "end", "end" ]
Clears all items from the cache If block is given, iterates over the cached items
[ "Clears", "all", "items", "from", "the", "cache", "If", "block", "is", "given", "iterates", "over", "the", "cached", "items" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/resource_manager.rb#L66-L78
22,911
celluloid/dcell
lib/dcell/resource_manager.rb
DCell.ResourceManager.find
def find(id) @lock.synchronize do begin ref = @items[id] return unless ref ref.__getobj__ rescue WeakRef::RefError # :nocov: @items.delete id nil # :nocov: end end end
ruby
def find(id) @lock.synchronize do begin ref = @items[id] return unless ref ref.__getobj__ rescue WeakRef::RefError # :nocov: @items.delete id nil # :nocov: end end end
[ "def", "find", "(", "id", ")", "@lock", ".", "synchronize", "do", "begin", "ref", "=", "@items", "[", "id", "]", "return", "unless", "ref", "ref", ".", "__getobj__", "rescue", "WeakRef", "::", "RefError", "# :nocov:", "@items", ".", "delete", "id", "nil", "# :nocov:", "end", "end", "end" ]
Finds an item by its ID
[ "Finds", "an", "item", "by", "its", "ID" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/resource_manager.rb#L81-L94
22,912
dicom/rtkit
lib/rtkit/drr/attenuation.rb
RTKIT.Attenuation.vector_attenuation
def vector_attenuation(h_units, lengths) raise ArgumentError, "Incosistent arguments. Expected both NArrays to have the same length, go #{h_units.length} and #{lengths.length}" if h_units.length != lengths.length # Note that the lengths are converted to units of cm in the calculation. # The exponential gives transmission: To get attenuation we subtract from one: 1 - Math.exp(-(attenuation_coefficients(h_units) * 0.1 * lengths).sum) end
ruby
def vector_attenuation(h_units, lengths) raise ArgumentError, "Incosistent arguments. Expected both NArrays to have the same length, go #{h_units.length} and #{lengths.length}" if h_units.length != lengths.length # Note that the lengths are converted to units of cm in the calculation. # The exponential gives transmission: To get attenuation we subtract from one: 1 - Math.exp(-(attenuation_coefficients(h_units) * 0.1 * lengths).sum) end
[ "def", "vector_attenuation", "(", "h_units", ",", "lengths", ")", "raise", "ArgumentError", ",", "\"Incosistent arguments. Expected both NArrays to have the same length, go #{h_units.length} and #{lengths.length}\"", "if", "h_units", ".", "length", "!=", "lengths", ".", "length", "# Note that the lengths are converted to units of cm in the calculation.", "# The exponential gives transmission: To get attenuation we subtract from one:", "1", "-", "Math", ".", "exp", "(", "-", "(", "attenuation_coefficients", "(", "h_units", ")", "*", "0.1", "*", "lengths", ")", ".", "sum", ")", "end" ]
Calculates the attentuation for a vector pair of hounsfield units and lengths. @param [NArray<Integer>] h_units a vector of Hounsfield units @param [NArray<Float>] lengths a vector of lengths (in units of mm) @return [Float] the calculated attenuation of a ray through the given medium
[ "Calculates", "the", "attentuation", "for", "a", "vector", "pair", "of", "hounsfield", "units", "and", "lengths", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/attenuation.rb#L118-L123
22,913
dicom/rtkit
lib/rtkit/drr/attenuation.rb
RTKIT.Attenuation.determine_coefficient
def determine_coefficient # Array of photon energies (in units of MeV). @energies = [ 0.001, 0.0015, 0.002, 0.003, 0.004, 0.005, 0.006, 0.008, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.08, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1.0, 1.25, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 15.0, 20.0 ] # Array of mass attenuation coefficients for the above energies, for liquid water (in units of cm^2/g): @att_coeffs = [ 4078, 1376, 617.3, 192.9, 82.78, 42.58, 24.64, 10.37, 5.329, 1.673, 0.8096, 0.3756, 0.2683, 0.2269, 0.2059, 0.1837, 0.1707, 0.1505, 0.137, 0.1186, 0.1061, 0.09687, 0.08956, 0.07865, 0.07072, 0.06323, 0.05754, 0.04942, 0.03969, 0.03403, 0.03031, 0.0277, 0.02429, 0.02219, 0.01941, 0.01813 ] # Determine the coefficient: if @energy >= 20.0 # When the energy is above 20, we use the coefficient for 20 MeV: @ac_water = @att_coeffs.last else if i = @energies.index(@energy) # When it exactly matches one of the listed energies, use its corresponding coefficient: @ac_water = @att_coeffs[i] else # When the given energy is between two of the listed values, interpolate: i_after = @energies.index {|x| x > @energy} if i_after e_high = @energies[i_after] e_low = @energies[i_after - 1] ac_high = @att_coeffs[i_after] ac_low = @att_coeffs[i_after - 1] @ac_water = (ac_high - ac_low ) / (e_high - e_low) * (@energy - e_low) else raise "Unexpected behaviour with index in the energy interpolation logic." end end end end
ruby
def determine_coefficient # Array of photon energies (in units of MeV). @energies = [ 0.001, 0.0015, 0.002, 0.003, 0.004, 0.005, 0.006, 0.008, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.08, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1.0, 1.25, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 15.0, 20.0 ] # Array of mass attenuation coefficients for the above energies, for liquid water (in units of cm^2/g): @att_coeffs = [ 4078, 1376, 617.3, 192.9, 82.78, 42.58, 24.64, 10.37, 5.329, 1.673, 0.8096, 0.3756, 0.2683, 0.2269, 0.2059, 0.1837, 0.1707, 0.1505, 0.137, 0.1186, 0.1061, 0.09687, 0.08956, 0.07865, 0.07072, 0.06323, 0.05754, 0.04942, 0.03969, 0.03403, 0.03031, 0.0277, 0.02429, 0.02219, 0.01941, 0.01813 ] # Determine the coefficient: if @energy >= 20.0 # When the energy is above 20, we use the coefficient for 20 MeV: @ac_water = @att_coeffs.last else if i = @energies.index(@energy) # When it exactly matches one of the listed energies, use its corresponding coefficient: @ac_water = @att_coeffs[i] else # When the given energy is between two of the listed values, interpolate: i_after = @energies.index {|x| x > @energy} if i_after e_high = @energies[i_after] e_low = @energies[i_after - 1] ac_high = @att_coeffs[i_after] ac_low = @att_coeffs[i_after - 1] @ac_water = (ac_high - ac_low ) / (e_high - e_low) * (@energy - e_low) else raise "Unexpected behaviour with index in the energy interpolation logic." end end end end
[ "def", "determine_coefficient", "# Array of photon energies (in units of MeV).", "@energies", "=", "[", "0.001", ",", "0.0015", ",", "0.002", ",", "0.003", ",", "0.004", ",", "0.005", ",", "0.006", ",", "0.008", ",", "0.01", ",", "0.015", ",", "0.02", ",", "0.03", ",", "0.04", ",", "0.05", ",", "0.06", ",", "0.08", ",", "0.1", ",", "0.15", ",", "0.2", ",", "0.3", ",", "0.4", ",", "0.5", ",", "0.6", ",", "0.8", ",", "1.0", ",", "1.25", ",", "1.5", ",", "2.0", ",", "3.0", ",", "4.0", ",", "5.0", ",", "6.0", ",", "8.0", ",", "10.0", ",", "15.0", ",", "20.0", "]", "# Array of mass attenuation coefficients for the above energies, for liquid water (in units of cm^2/g):", "@att_coeffs", "=", "[", "4078", ",", "1376", ",", "617.3", ",", "192.9", ",", "82.78", ",", "42.58", ",", "24.64", ",", "10.37", ",", "5.329", ",", "1.673", ",", "0.8096", ",", "0.3756", ",", "0.2683", ",", "0.2269", ",", "0.2059", ",", "0.1837", ",", "0.1707", ",", "0.1505", ",", "0.137", ",", "0.1186", ",", "0.1061", ",", "0.09687", ",", "0.08956", ",", "0.07865", ",", "0.07072", ",", "0.06323", ",", "0.05754", ",", "0.04942", ",", "0.03969", ",", "0.03403", ",", "0.03031", ",", "0.0277", ",", "0.02429", ",", "0.02219", ",", "0.01941", ",", "0.01813", "]", "# Determine the coefficient:", "if", "@energy", ">=", "20.0", "# When the energy is above 20, we use the coefficient for 20 MeV:", "@ac_water", "=", "@att_coeffs", ".", "last", "else", "if", "i", "=", "@energies", ".", "index", "(", "@energy", ")", "# When it exactly matches one of the listed energies, use its corresponding coefficient:", "@ac_water", "=", "@att_coeffs", "[", "i", "]", "else", "# When the given energy is between two of the listed values, interpolate:", "i_after", "=", "@energies", ".", "index", "{", "|", "x", "|", "x", ">", "@energy", "}", "if", "i_after", "e_high", "=", "@energies", "[", "i_after", "]", "e_low", "=", "@energies", "[", "i_after", "-", "1", "]", "ac_high", "=", "@att_coeffs", "[", "i_after", "]", "ac_low", "=", "@att_coeffs", "[", "i_after", "-", "1", "]", "@ac_water", "=", "(", "ac_high", "-", "ac_low", ")", "/", "(", "e_high", "-", "e_low", ")", "*", "(", "@energy", "-", "e_low", ")", "else", "raise", "\"Unexpected behaviour with index in the energy interpolation logic.\"", "end", "end", "end", "end" ]
Determines the attenuation coefficient to use, based on the given energy.
[ "Determines", "the", "attenuation", "coefficient", "to", "use", "based", "on", "the", "given", "energy", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/attenuation.rb#L131-L232
22,914
zmoazeni/harvested
lib/harvest/user.rb
Harvest.User.timezone=
def timezone=(timezone) tz = timezone.to_s.downcase case tz when 'cst', 'cdt' then self.timezone = 'america/chicago' when 'est', 'edt' then self.timezone = 'america/new_york' when 'mst', 'mdt' then self.timezone = 'america/denver' when 'pst', 'pdt' then self.timezone = 'america/los_angeles' else if Harvest::Timezones::MAPPING[tz] self["timezone"] = Harvest::Timezones::MAPPING[tz] else self["timezone"] = timezone end end end
ruby
def timezone=(timezone) tz = timezone.to_s.downcase case tz when 'cst', 'cdt' then self.timezone = 'america/chicago' when 'est', 'edt' then self.timezone = 'america/new_york' when 'mst', 'mdt' then self.timezone = 'america/denver' when 'pst', 'pdt' then self.timezone = 'america/los_angeles' else if Harvest::Timezones::MAPPING[tz] self["timezone"] = Harvest::Timezones::MAPPING[tz] else self["timezone"] = timezone end end end
[ "def", "timezone", "=", "(", "timezone", ")", "tz", "=", "timezone", ".", "to_s", ".", "downcase", "case", "tz", "when", "'cst'", ",", "'cdt'", "then", "self", ".", "timezone", "=", "'america/chicago'", "when", "'est'", ",", "'edt'", "then", "self", ".", "timezone", "=", "'america/new_york'", "when", "'mst'", ",", "'mdt'", "then", "self", ".", "timezone", "=", "'america/denver'", "when", "'pst'", ",", "'pdt'", "then", "self", ".", "timezone", "=", "'america/los_angeles'", "else", "if", "Harvest", "::", "Timezones", "::", "MAPPING", "[", "tz", "]", "self", "[", "\"timezone\"", "]", "=", "Harvest", "::", "Timezones", "::", "MAPPING", "[", "tz", "]", "else", "self", "[", "\"timezone\"", "]", "=", "timezone", "end", "end", "end" ]
Sets the timezone for the user. This can be done in a variety of ways. == Examples user.timezone = :cst # the easiest way. CST, EST, MST, and PST are supported user.timezone = 'america/chicago' # a little more verbose user.timezone = 'Central Time (US & Canada)' # the most explicit way
[ "Sets", "the", "timezone", "for", "the", "user", ".", "This", "can", "be", "done", "in", "a", "variety", "of", "ways", "." ]
33d26049651fde6adf651d5c8aff8fff97156210
https://github.com/zmoazeni/harvested/blob/33d26049651fde6adf651d5c8aff8fff97156210/lib/harvest/user.rb#L42-L56
22,915
dicom/rtkit
lib/rtkit/dose.rb
RTKIT.Dose.bed
def bed(d, alpha_beta) # FIXME: Perhaps better to use number of fractions instead of fraction dose?! raise ArgumentError, "A positive alpha_beta factor is required (got: #{alpha_beta})." unless alpha_beta.to_f > 0.0 @value * (1 + d.to_f/alpha_beta.to_f) end
ruby
def bed(d, alpha_beta) # FIXME: Perhaps better to use number of fractions instead of fraction dose?! raise ArgumentError, "A positive alpha_beta factor is required (got: #{alpha_beta})." unless alpha_beta.to_f > 0.0 @value * (1 + d.to_f/alpha_beta.to_f) end
[ "def", "bed", "(", "d", ",", "alpha_beta", ")", "# FIXME: Perhaps better to use number of fractions instead of fraction dose?!", "raise", "ArgumentError", ",", "\"A positive alpha_beta factor is required (got: #{alpha_beta}).\"", "unless", "alpha_beta", ".", "to_f", ">", "0.0", "@value", "*", "(", "1", "+", "d", ".", "to_f", "/", "alpha_beta", ".", "to_f", ")", "end" ]
Calculates the biologically equivalent dose, BED. This is the theoretical limit of the equivalent dose delivered in small fractions, i.e. when complete repair takes place. @param [#to_f] d fraction dose @param [#to_f] alpha_beta the alpha/beta tissue factor to be used @return [Float] the biologically equivalent dose
[ "Calculates", "the", "biologically", "equivalent", "dose", "BED", ".", "This", "is", "the", "theoretical", "limit", "of", "the", "equivalent", "dose", "delivered", "in", "small", "fractions", "i", ".", "e", ".", "when", "complete", "repair", "takes", "place", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/dose.rb#L59-L63
22,916
dicom/rtkit
lib/rtkit/drr/ray.rb
RTKIT.Ray.trace
def trace # Set up instance varibles which depends on the initial conditions. # Delta positions determines whether the ray's travel is positive # or negative in the three directions. delta_x = @p1.x < @p2.x ? 1 : -1 delta_y = @p1.y < @p2.y ? 1 : -1 delta_z = @p1.z < @p2.z ? 1 : -1 # Delta indices determines whether the ray's voxel space indices increments # in a positive or negative fashion as it travels through the voxel space. # Note that for rays travelling perpendicular on a particular axis, the # delta value of that axis will be undefined (zero). @delta_i = @p1.x == @p2.x ? 0 : delta_x @delta_j = @p1.y == @p2.y ? 0 : delta_y @delta_k = @p1.z == @p2.z ? 0 : delta_z # These variables describe how much the alpha fraction changes (in a # given axis) when we follow the ray through one voxel (across two planes). # This value is high if the ray is perpendicular on the axis (angle high, or close to 90 degrees), # and low if the angle is parallell with the axis (angle low, or close to 0 degrees). @delta_ax = @vs.delta_x / (@p2.x - @p1.x).abs @delta_ay = @vs.delta_y / (@p2.y - @p1.y).abs @delta_az = @vs.delta_z / (@p2.z - @p1.z).abs # Determines the ray length (from p1 to p2). @length = Math.sqrt((@[email protected])**2 + (@[email protected])**2 + (@[email protected])**2) # Perform the ray tracing: # Number of voxels: nx, ny, nz # Number of planes: nx+1, ny+1, nz+1 # Voxel indices: 0..(nx-1), etc. # Plane indices: 0..nx, etc. intersection_with_voxel_space # Perform the ray trace only if the ray's intersection with the # voxel space is between the ray's start and end points: if @alpha_max > 0 && @alpha_min < 1 min_and_max_indices number_of_planes axf, ayf, azf = first_intersection_point_in_voxel_space # If we didn't get any intersection points, there's no need to proceed with the ray trace: if [axf, ayf, azf].any? # Initialize the starting alpha values: initialize_alphas(axf, ayf, azf) @i, @j, @k = indices_first_intersection(axf, ayf, azf) # Initiate the ray tracing if we got valid starting coordinates: if @i && @j && @k # Calculate the first move: update # Next interactions: # To avoid float impresision issues we choose to round here before # doing the comparison. How many decimals should we choose to round to? # Perhaps there is a more prinipal way than the chosen solution? alpha_max_rounded = @alpha_max.round(8) while @ac.round(8) < alpha_max_rounded do update end end end end end
ruby
def trace # Set up instance varibles which depends on the initial conditions. # Delta positions determines whether the ray's travel is positive # or negative in the three directions. delta_x = @p1.x < @p2.x ? 1 : -1 delta_y = @p1.y < @p2.y ? 1 : -1 delta_z = @p1.z < @p2.z ? 1 : -1 # Delta indices determines whether the ray's voxel space indices increments # in a positive or negative fashion as it travels through the voxel space. # Note that for rays travelling perpendicular on a particular axis, the # delta value of that axis will be undefined (zero). @delta_i = @p1.x == @p2.x ? 0 : delta_x @delta_j = @p1.y == @p2.y ? 0 : delta_y @delta_k = @p1.z == @p2.z ? 0 : delta_z # These variables describe how much the alpha fraction changes (in a # given axis) when we follow the ray through one voxel (across two planes). # This value is high if the ray is perpendicular on the axis (angle high, or close to 90 degrees), # and low if the angle is parallell with the axis (angle low, or close to 0 degrees). @delta_ax = @vs.delta_x / (@p2.x - @p1.x).abs @delta_ay = @vs.delta_y / (@p2.y - @p1.y).abs @delta_az = @vs.delta_z / (@p2.z - @p1.z).abs # Determines the ray length (from p1 to p2). @length = Math.sqrt((@[email protected])**2 + (@[email protected])**2 + (@[email protected])**2) # Perform the ray tracing: # Number of voxels: nx, ny, nz # Number of planes: nx+1, ny+1, nz+1 # Voxel indices: 0..(nx-1), etc. # Plane indices: 0..nx, etc. intersection_with_voxel_space # Perform the ray trace only if the ray's intersection with the # voxel space is between the ray's start and end points: if @alpha_max > 0 && @alpha_min < 1 min_and_max_indices number_of_planes axf, ayf, azf = first_intersection_point_in_voxel_space # If we didn't get any intersection points, there's no need to proceed with the ray trace: if [axf, ayf, azf].any? # Initialize the starting alpha values: initialize_alphas(axf, ayf, azf) @i, @j, @k = indices_first_intersection(axf, ayf, azf) # Initiate the ray tracing if we got valid starting coordinates: if @i && @j && @k # Calculate the first move: update # Next interactions: # To avoid float impresision issues we choose to round here before # doing the comparison. How many decimals should we choose to round to? # Perhaps there is a more prinipal way than the chosen solution? alpha_max_rounded = @alpha_max.round(8) while @ac.round(8) < alpha_max_rounded do update end end end end end
[ "def", "trace", "# Set up instance varibles which depends on the initial conditions.", "# Delta positions determines whether the ray's travel is positive", "# or negative in the three directions.", "delta_x", "=", "@p1", ".", "x", "<", "@p2", ".", "x", "?", "1", ":", "-", "1", "delta_y", "=", "@p1", ".", "y", "<", "@p2", ".", "y", "?", "1", ":", "-", "1", "delta_z", "=", "@p1", ".", "z", "<", "@p2", ".", "z", "?", "1", ":", "-", "1", "# Delta indices determines whether the ray's voxel space indices increments", "# in a positive or negative fashion as it travels through the voxel space.", "# Note that for rays travelling perpendicular on a particular axis, the", "# delta value of that axis will be undefined (zero).", "@delta_i", "=", "@p1", ".", "x", "==", "@p2", ".", "x", "?", "0", ":", "delta_x", "@delta_j", "=", "@p1", ".", "y", "==", "@p2", ".", "y", "?", "0", ":", "delta_y", "@delta_k", "=", "@p1", ".", "z", "==", "@p2", ".", "z", "?", "0", ":", "delta_z", "# These variables describe how much the alpha fraction changes (in a", "# given axis) when we follow the ray through one voxel (across two planes).", "# This value is high if the ray is perpendicular on the axis (angle high, or close to 90 degrees),", "# and low if the angle is parallell with the axis (angle low, or close to 0 degrees).", "@delta_ax", "=", "@vs", ".", "delta_x", "/", "(", "@p2", ".", "x", "-", "@p1", ".", "x", ")", ".", "abs", "@delta_ay", "=", "@vs", ".", "delta_y", "/", "(", "@p2", ".", "y", "-", "@p1", ".", "y", ")", ".", "abs", "@delta_az", "=", "@vs", ".", "delta_z", "/", "(", "@p2", ".", "z", "-", "@p1", ".", "z", ")", ".", "abs", "# Determines the ray length (from p1 to p2).", "@length", "=", "Math", ".", "sqrt", "(", "(", "@p2", ".", "x", "-", "@p1", ".", "x", ")", "**", "2", "+", "(", "@p2", ".", "y", "-", "@p1", ".", "y", ")", "**", "2", "+", "(", "@p2", ".", "z", "-", "@p1", ".", "x", ")", "**", "2", ")", "# Perform the ray tracing:", "# Number of voxels: nx, ny, nz", "# Number of planes: nx+1, ny+1, nz+1", "# Voxel indices: 0..(nx-1), etc.", "# Plane indices: 0..nx, etc.", "intersection_with_voxel_space", "# Perform the ray trace only if the ray's intersection with the", "# voxel space is between the ray's start and end points:", "if", "@alpha_max", ">", "0", "&&", "@alpha_min", "<", "1", "min_and_max_indices", "number_of_planes", "axf", ",", "ayf", ",", "azf", "=", "first_intersection_point_in_voxel_space", "# If we didn't get any intersection points, there's no need to proceed with the ray trace:", "if", "[", "axf", ",", "ayf", ",", "azf", "]", ".", "any?", "# Initialize the starting alpha values:", "initialize_alphas", "(", "axf", ",", "ayf", ",", "azf", ")", "@i", ",", "@j", ",", "@k", "=", "indices_first_intersection", "(", "axf", ",", "ayf", ",", "azf", ")", "# Initiate the ray tracing if we got valid starting coordinates:", "if", "@i", "&&", "@j", "&&", "@k", "# Calculate the first move:", "update", "# Next interactions:", "# To avoid float impresision issues we choose to round here before", "# doing the comparison. How many decimals should we choose to round to?", "# Perhaps there is a more prinipal way than the chosen solution?", "alpha_max_rounded", "=", "@alpha_max", ".", "round", "(", "8", ")", "while", "@ac", ".", "round", "(", "8", ")", "<", "alpha_max_rounded", "do", "update", "end", "end", "end", "end", "end" ]
Performs ray tracing, where the ray's possible intersection of the associated voxel space is investigated for the ray's movement from its source coordinate to its target coordinate. The resulting density experienced by the ray through the voxel space is stored in the 'd' attribute. The indices of the voxel space intersected by the ray is stored in the 'indices' attribute (if the 'path' option has been set).
[ "Performs", "ray", "tracing", "where", "the", "ray", "s", "possible", "intersection", "of", "the", "associated", "voxel", "space", "is", "investigated", "for", "the", "ray", "s", "movement", "from", "its", "source", "coordinate", "to", "its", "target", "coordinate", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/ray.rb#L306-L361
22,917
dicom/rtkit
lib/rtkit/drr/ray.rb
RTKIT.Ray.alpha_min
def alpha_min(fractions) fractions.compact.collect { |a| a >= 0 ? a : nil}.compact.min end
ruby
def alpha_min(fractions) fractions.compact.collect { |a| a >= 0 ? a : nil}.compact.min end
[ "def", "alpha_min", "(", "fractions", ")", "fractions", ".", "compact", ".", "collect", "{", "|", "a", "|", "a", ">=", "0", "?", "a", ":", "nil", "}", ".", "compact", ".", "min", "end" ]
Gives the minimum value among the directional fractions given, taking into account that some of them may be nil, negative, or even -INFINITY, and thus needs to be excluded before extracting the valid minimum value. @param [Array<Float, NilClass>] fractions a collection of alpha values @return [Float] the minimum value among the valid alphas
[ "Gives", "the", "minimum", "value", "among", "the", "directional", "fractions", "given", "taking", "into", "account", "that", "some", "of", "them", "may", "be", "nil", "negative", "or", "even", "-", "INFINITY", "and", "thus", "needs", "to", "be", "excluded", "before", "extracting", "the", "valid", "minimum", "value", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/ray.rb#L374-L376
22,918
dicom/rtkit
lib/rtkit/drr/ray.rb
RTKIT.Ray.first_intersection_point_in_voxel_space
def first_intersection_point_in_voxel_space a_x_min = ax(@i_min) a_y_min = ay(@j_min) a_z_min = az(@k_min) a_x_max = ax(@i_max) a_y_max = ay(@j_max) a_z_max = az(@k_max) alpha_x = alpha_min_first_intersection([a_x_min, a_x_max]) alpha_y = alpha_min_first_intersection([a_y_min, a_y_max]) alpha_z = alpha_min_first_intersection([a_z_min, a_z_max]) return alpha_x, alpha_y, alpha_z end
ruby
def first_intersection_point_in_voxel_space a_x_min = ax(@i_min) a_y_min = ay(@j_min) a_z_min = az(@k_min) a_x_max = ax(@i_max) a_y_max = ay(@j_max) a_z_max = az(@k_max) alpha_x = alpha_min_first_intersection([a_x_min, a_x_max]) alpha_y = alpha_min_first_intersection([a_y_min, a_y_max]) alpha_z = alpha_min_first_intersection([a_z_min, a_z_max]) return alpha_x, alpha_y, alpha_z end
[ "def", "first_intersection_point_in_voxel_space", "a_x_min", "=", "ax", "(", "@i_min", ")", "a_y_min", "=", "ay", "(", "@j_min", ")", "a_z_min", "=", "az", "(", "@k_min", ")", "a_x_max", "=", "ax", "(", "@i_max", ")", "a_y_max", "=", "ay", "(", "@j_max", ")", "a_z_max", "=", "az", "(", "@k_max", ")", "alpha_x", "=", "alpha_min_first_intersection", "(", "[", "a_x_min", ",", "a_x_max", "]", ")", "alpha_y", "=", "alpha_min_first_intersection", "(", "[", "a_y_min", ",", "a_y_max", "]", ")", "alpha_z", "=", "alpha_min_first_intersection", "(", "[", "a_z_min", ",", "a_z_max", "]", ")", "return", "alpha_x", ",", "alpha_y", ",", "alpha_z", "end" ]
Determines the alpha values for the first intersection after the ray has entered the voxel space. @return [Array<Float>] directional x, y and z alpha values
[ "Determines", "the", "alpha", "values", "for", "the", "first", "intersection", "after", "the", "ray", "has", "entered", "the", "voxel", "space", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/ray.rb#L403-L414
22,919
dicom/rtkit
lib/rtkit/drr/ray.rb
RTKIT.Ray.indices_first_intersection
def indices_first_intersection(axf, ayf, azf) i, j, k = nil, nil, nil # In cases of perpendicular ray travel, one or two arguments may be # -INFINITY, which must be excluded when searching for the minimum value: af_min = alpha_min([axf, ayf, azf]) sorted_real_alpha_values([axf, ayf, azf]).each do |a| alpha_mean = (a + @alpha_min) * 0.5 i0 = phi_x(alpha_mean) j0 = phi_y(alpha_mean) k0 = phi_z(alpha_mean) if indices_within_voxel_space(i0, j0, k0) i, j, k = i0, j0, k0 break end end return i, j, k end
ruby
def indices_first_intersection(axf, ayf, azf) i, j, k = nil, nil, nil # In cases of perpendicular ray travel, one or two arguments may be # -INFINITY, which must be excluded when searching for the minimum value: af_min = alpha_min([axf, ayf, azf]) sorted_real_alpha_values([axf, ayf, azf]).each do |a| alpha_mean = (a + @alpha_min) * 0.5 i0 = phi_x(alpha_mean) j0 = phi_y(alpha_mean) k0 = phi_z(alpha_mean) if indices_within_voxel_space(i0, j0, k0) i, j, k = i0, j0, k0 break end end return i, j, k end
[ "def", "indices_first_intersection", "(", "axf", ",", "ayf", ",", "azf", ")", "i", ",", "j", ",", "k", "=", "nil", ",", "nil", ",", "nil", "# In cases of perpendicular ray travel, one or two arguments may be", "# -INFINITY, which must be excluded when searching for the minimum value:", "af_min", "=", "alpha_min", "(", "[", "axf", ",", "ayf", ",", "azf", "]", ")", "sorted_real_alpha_values", "(", "[", "axf", ",", "ayf", ",", "azf", "]", ")", ".", "each", "do", "|", "a", "|", "alpha_mean", "=", "(", "a", "+", "@alpha_min", ")", "*", "0.5", "i0", "=", "phi_x", "(", "alpha_mean", ")", "j0", "=", "phi_y", "(", "alpha_mean", ")", "k0", "=", "phi_z", "(", "alpha_mean", ")", "if", "indices_within_voxel_space", "(", "i0", ",", "j0", ",", "k0", ")", "i", ",", "j", ",", "k", "=", "i0", ",", "j0", ",", "k0", "break", "end", "end", "return", "i", ",", "j", ",", "k", "end" ]
Determines the voxel indices of the first intersection. @param [Float] axf a directional x alpha value for the ray's first intersection in voxel space @param [Float] ayf a directional y alpha value for the ray's first intersection in voxel space @param [Float] azf a directional z alpha value for the ray's first intersection in voxel space @return [Array<Integer>] voxel indices i, j and k of the first intersection
[ "Determines", "the", "voxel", "indices", "of", "the", "first", "intersection", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/ray.rb#L423-L439
22,920
dicom/rtkit
lib/rtkit/drr/ray.rb
RTKIT.Ray.indices_within_voxel_space
def indices_within_voxel_space(i, j, k) if [i, j, k].min >= 0 if i < @vs.nx && j < @vs.nz && k < @vs.nz true else false end else false end end
ruby
def indices_within_voxel_space(i, j, k) if [i, j, k].min >= 0 if i < @vs.nx && j < @vs.nz && k < @vs.nz true else false end else false end end
[ "def", "indices_within_voxel_space", "(", "i", ",", "j", ",", "k", ")", "if", "[", "i", ",", "j", ",", "k", "]", ".", "min", ">=", "0", "if", "i", "<", "@vs", ".", "nx", "&&", "j", "<", "@vs", ".", "nz", "&&", "k", "<", "@vs", ".", "nz", "true", "else", "false", "end", "else", "false", "end", "end" ]
Checks whether the given voxel indices describe an index that is within the associated voxel space. @param [Integer] i the first volume index (column) @param [Integer] j the second volume index (row) @param [Integer] k the third volume index (slice) @return [Boolean] true if within, and false if not
[ "Checks", "whether", "the", "given", "voxel", "indices", "describe", "an", "index", "that", "is", "within", "the", "associated", "voxel", "space", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/ray.rb#L449-L459
22,921
dicom/rtkit
lib/rtkit/drr/ray.rb
RTKIT.Ray.sorted_real_alpha_values
def sorted_real_alpha_values(fractions) fractions.compact.collect { |a| a >= 0 && a.finite? ? a : nil}.compact.sort end
ruby
def sorted_real_alpha_values(fractions) fractions.compact.collect { |a| a >= 0 && a.finite? ? a : nil}.compact.sort end
[ "def", "sorted_real_alpha_values", "(", "fractions", ")", "fractions", ".", "compact", ".", "collect", "{", "|", "a", "|", "a", ">=", "0", "&&", "a", ".", "finite?", "?", "a", ":", "nil", "}", ".", "compact", ".", "sort", "end" ]
Gives a sorted array of the directional fractions given, taking into account that some of them may be nil, negative, or even -INFINITY, and thus needs to be excluded before sorting. @param [Array<Float, NilClass>] fractions a collection of alpha values @return [Array<Float>] sorted (valid) alpha values
[ "Gives", "a", "sorted", "array", "of", "the", "directional", "fractions", "given", "taking", "into", "account", "that", "some", "of", "them", "may", "be", "nil", "negative", "or", "even", "-", "INFINITY", "and", "thus", "needs", "to", "be", "excluded", "before", "sorting", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/ray.rb#L621-L623
22,922
jlong/radius
lib/radius/parser.rb
Radius.Parser.parse
def parse(string) @stack = [ ParseContainerTag.new { |t| Utility.array_to_s(t.contents) } ] tokenize(string) stack_up @stack.last.to_s end
ruby
def parse(string) @stack = [ ParseContainerTag.new { |t| Utility.array_to_s(t.contents) } ] tokenize(string) stack_up @stack.last.to_s end
[ "def", "parse", "(", "string", ")", "@stack", "=", "[", "ParseContainerTag", ".", "new", "{", "|", "t", "|", "Utility", ".", "array_to_s", "(", "t", ".", "contents", ")", "}", "]", "tokenize", "(", "string", ")", "stack_up", "@stack", ".", "last", ".", "to_s", "end" ]
Creates a new parser object initialized with a Context. Parses string for tags, expands them, and returns the result.
[ "Creates", "a", "new", "parser", "object", "initialized", "with", "a", "Context", ".", "Parses", "string", "for", "tags", "expands", "them", "and", "returns", "the", "result", "." ]
e7b4eab374c6a15e105524ccd663767b8bc91e5b
https://github.com/jlong/radius/blob/e7b4eab374c6a15e105524ccd663767b8bc91e5b/lib/radius/parser.rb#L30-L35
22,923
dicom/rtkit
lib/rtkit/series.rb
RTKIT.Series.add_attributes_to_dcm
def add_attributes_to_dcm(dcm) # Series level: dcm.add_element(SOP_CLASS, @class_uid) dcm.add_element(SERIES_UID, @series_uid) dcm.add_element(SERIES_NUMBER, '1') # Study level: dcm.add_element(STUDY_DATE, @study.date) dcm.add_element(STUDY_TIME, @study.time) dcm.add_element(STUDY_UID, @study.study_uid) dcm.add_element(STUDY_ID, @study.id) # Add frame level tags if a relevant frame exists: if @study.iseries && @study.iseries.frame dcm.add_element(PATIENT_ORIENTATION, '') dcm.add_element(FRAME_OF_REF, @study.iseries.frame.uid) dcm.add_element(POS_REF_INDICATOR, '') end # Patient level: dcm.add_element(PATIENTS_NAME, @study.patient.name) dcm.add_element(PATIENTS_ID, @study.patient.id) dcm.add_element(BIRTH_DATE, @study.patient.birth_date) dcm.add_element(SEX, @study.patient.sex) end
ruby
def add_attributes_to_dcm(dcm) # Series level: dcm.add_element(SOP_CLASS, @class_uid) dcm.add_element(SERIES_UID, @series_uid) dcm.add_element(SERIES_NUMBER, '1') # Study level: dcm.add_element(STUDY_DATE, @study.date) dcm.add_element(STUDY_TIME, @study.time) dcm.add_element(STUDY_UID, @study.study_uid) dcm.add_element(STUDY_ID, @study.id) # Add frame level tags if a relevant frame exists: if @study.iseries && @study.iseries.frame dcm.add_element(PATIENT_ORIENTATION, '') dcm.add_element(FRAME_OF_REF, @study.iseries.frame.uid) dcm.add_element(POS_REF_INDICATOR, '') end # Patient level: dcm.add_element(PATIENTS_NAME, @study.patient.name) dcm.add_element(PATIENTS_ID, @study.patient.id) dcm.add_element(BIRTH_DATE, @study.patient.birth_date) dcm.add_element(SEX, @study.patient.sex) end
[ "def", "add_attributes_to_dcm", "(", "dcm", ")", "# Series level:", "dcm", ".", "add_element", "(", "SOP_CLASS", ",", "@class_uid", ")", "dcm", ".", "add_element", "(", "SERIES_UID", ",", "@series_uid", ")", "dcm", ".", "add_element", "(", "SERIES_NUMBER", ",", "'1'", ")", "# Study level:", "dcm", ".", "add_element", "(", "STUDY_DATE", ",", "@study", ".", "date", ")", "dcm", ".", "add_element", "(", "STUDY_TIME", ",", "@study", ".", "time", ")", "dcm", ".", "add_element", "(", "STUDY_UID", ",", "@study", ".", "study_uid", ")", "dcm", ".", "add_element", "(", "STUDY_ID", ",", "@study", ".", "id", ")", "# Add frame level tags if a relevant frame exists:", "if", "@study", ".", "iseries", "&&", "@study", ".", "iseries", ".", "frame", "dcm", ".", "add_element", "(", "PATIENT_ORIENTATION", ",", "''", ")", "dcm", ".", "add_element", "(", "FRAME_OF_REF", ",", "@study", ".", "iseries", ".", "frame", ".", "uid", ")", "dcm", ".", "add_element", "(", "POS_REF_INDICATOR", ",", "''", ")", "end", "# Patient level:", "dcm", ".", "add_element", "(", "PATIENTS_NAME", ",", "@study", ".", "patient", ".", "name", ")", "dcm", ".", "add_element", "(", "PATIENTS_ID", ",", "@study", ".", "patient", ".", "id", ")", "dcm", ".", "add_element", "(", "BIRTH_DATE", ",", "@study", ".", "patient", ".", "birth_date", ")", "dcm", ".", "add_element", "(", "SEX", ",", "@study", ".", "patient", ".", "sex", ")", "end" ]
Creates a new Series instance. The Series Instance UID string is used to uniquely identify a Series. @param [String] series_uid the Series Instance UID string @param [String] modality the modality string of the series (e.g. 'CT', 'RTSTRUCT') @param [Study] study the Study instance which this Series belongs to @param [Hash] options the options to use for creating the Series @option options [String] :class_uid the SOP class UID (DICOM tag '0008,0016') @option options [String] :date the series date (DICOM tag '0008,0021') @option options [String] :description the series description (DICOM tag '0008,103E') @option options [String] :time the series time (DICOM tag '0008,0031') Inserts general series, study and patient level attributes from this instance, as well as from the related study, patient and frame instances to a DICOM object. @param [DICOM::DObject] dcm a DICOM object typically belonging to an image instance of this series @return [DICOM::DObject] a DICOM object with the relevant attributes added
[ "Creates", "a", "new", "Series", "instance", ".", "The", "Series", "Instance", "UID", "string", "is", "used", "to", "uniquely", "identify", "a", "Series", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/series.rb#L62-L83
22,924
dicom/rtkit
lib/rtkit/staple.rb
RTKIT.Staple.solve
def solve set_parameters # Vectors holding the values used for calculating the weights: a = NArray.float(@n) b = NArray.float(@n) # Set an initial estimate for the probabilities of true segmentation: @n.times do |i| @weights_current[i] = @decisions[i, true].mean end # Proceed iteratively until we have converged to a local optimum: k = 0 while k < max_iterations do # Copy weights: @weights_previous = @weights_current.dup # E-step: Estimation of the conditional expectation of the complete data log likelihood function. # Deriving the estimator for the unobserved true segmentation (T). @n.times do |i| voxel_decisions = @decisions[i, true] # Find the rater-indices for this voxel where the raters' decisions equals 1 and 0: positive_indices, negative_indices = (voxel_decisions.eq 1).where2 # Determine ai: # Multiply by corresponding sensitivity (or 1 - sensitivity): a_decision1_factor = (positive_indices.length == 0 ? 1 : @p[positive_indices].prod) a_decision0_factor = (negative_indices.length == 0 ? 1 : (1 - @p[negative_indices]).prod) a[i] = @weights_previous[i] * a_decision1_factor * a_decision0_factor # Determine bi: # Multiply by corresponding specificity (or 1 - specificity): b_decision0_factor = (negative_indices.length == 0 ? 1 : @q[negative_indices].prod) b_decision1_factor = (positive_indices.length == 0 ? 1 : (1 - @q[positive_indices]).prod) b[i] = @weights_previous[i] * b_decision0_factor * b_decision1_factor # Determine Wi: (take care not to divide by zero) if a[i] > 0 or b[i] > 0 @weights_current[i] = a[i] / (a[i] + b[i]) else @weights_current[i] = 0 end end # M-step: Estimation of the performance parameters by maximization. # Finding the values of the expert performance level parameters that maximize the conditional expectation # of the complete data log likelihood function (phi - p,q). @r.times do |j| voxel_decisions = @decisions[true, j] # Find the voxel-indices for this rater where the rater's decisions equals 1 and 0: positive_indices, negative_indices = (voxel_decisions.eq 1).where2 # Determine sensitivity: # Sum the weights for the indices where the rater's decision equals 1: sum_positive = (positive_indices.length == 0 ? 0 : @weights_current[positive_indices].sum) @p[j] = sum_positive / @weights_current.sum # Determine specificity: # Sum the weights for the indices where the rater's decision equals 0: sum_negative = (negative_indices.length == 0 ? 0 : (1 - @weights_current[negative_indices]).sum) @q[j] = sum_negative / (1 - @weights_current).sum end # Bump our iteration index: k += 1 # Abort if we have reached the local optimum: (there is no change in the sum of weights) if @weights_current.sum - @weights_previous.sum == 0 #puts "Iteration aborted as optimum solution was found!" if @verbose #logger.info("Iteration aborted as optimum solution was found!") break end end # Set the true segmentation: @true_segmentation_vector = @weights_current.round # Set the weights attribute: @weights = @weights_current # As this vector doesn't make much sense to the user, it must be converted to a volume. If volume reduction has # previously been performed, this must be taken into account when transforming it to a volume: construct_segmentation_volume # Construct a BinVolume instance for the true segmentation and add it as a master volume to the BinMatcher instance. update_bin_matcher # Set the phi variable: @phi[0, true] = @p @phi[1, true] = @q end
ruby
def solve set_parameters # Vectors holding the values used for calculating the weights: a = NArray.float(@n) b = NArray.float(@n) # Set an initial estimate for the probabilities of true segmentation: @n.times do |i| @weights_current[i] = @decisions[i, true].mean end # Proceed iteratively until we have converged to a local optimum: k = 0 while k < max_iterations do # Copy weights: @weights_previous = @weights_current.dup # E-step: Estimation of the conditional expectation of the complete data log likelihood function. # Deriving the estimator for the unobserved true segmentation (T). @n.times do |i| voxel_decisions = @decisions[i, true] # Find the rater-indices for this voxel where the raters' decisions equals 1 and 0: positive_indices, negative_indices = (voxel_decisions.eq 1).where2 # Determine ai: # Multiply by corresponding sensitivity (or 1 - sensitivity): a_decision1_factor = (positive_indices.length == 0 ? 1 : @p[positive_indices].prod) a_decision0_factor = (negative_indices.length == 0 ? 1 : (1 - @p[negative_indices]).prod) a[i] = @weights_previous[i] * a_decision1_factor * a_decision0_factor # Determine bi: # Multiply by corresponding specificity (or 1 - specificity): b_decision0_factor = (negative_indices.length == 0 ? 1 : @q[negative_indices].prod) b_decision1_factor = (positive_indices.length == 0 ? 1 : (1 - @q[positive_indices]).prod) b[i] = @weights_previous[i] * b_decision0_factor * b_decision1_factor # Determine Wi: (take care not to divide by zero) if a[i] > 0 or b[i] > 0 @weights_current[i] = a[i] / (a[i] + b[i]) else @weights_current[i] = 0 end end # M-step: Estimation of the performance parameters by maximization. # Finding the values of the expert performance level parameters that maximize the conditional expectation # of the complete data log likelihood function (phi - p,q). @r.times do |j| voxel_decisions = @decisions[true, j] # Find the voxel-indices for this rater where the rater's decisions equals 1 and 0: positive_indices, negative_indices = (voxel_decisions.eq 1).where2 # Determine sensitivity: # Sum the weights for the indices where the rater's decision equals 1: sum_positive = (positive_indices.length == 0 ? 0 : @weights_current[positive_indices].sum) @p[j] = sum_positive / @weights_current.sum # Determine specificity: # Sum the weights for the indices where the rater's decision equals 0: sum_negative = (negative_indices.length == 0 ? 0 : (1 - @weights_current[negative_indices]).sum) @q[j] = sum_negative / (1 - @weights_current).sum end # Bump our iteration index: k += 1 # Abort if we have reached the local optimum: (there is no change in the sum of weights) if @weights_current.sum - @weights_previous.sum == 0 #puts "Iteration aborted as optimum solution was found!" if @verbose #logger.info("Iteration aborted as optimum solution was found!") break end end # Set the true segmentation: @true_segmentation_vector = @weights_current.round # Set the weights attribute: @weights = @weights_current # As this vector doesn't make much sense to the user, it must be converted to a volume. If volume reduction has # previously been performed, this must be taken into account when transforming it to a volume: construct_segmentation_volume # Construct a BinVolume instance for the true segmentation and add it as a master volume to the BinMatcher instance. update_bin_matcher # Set the phi variable: @phi[0, true] = @p @phi[1, true] = @q end
[ "def", "solve", "set_parameters", "# Vectors holding the values used for calculating the weights:", "a", "=", "NArray", ".", "float", "(", "@n", ")", "b", "=", "NArray", ".", "float", "(", "@n", ")", "# Set an initial estimate for the probabilities of true segmentation:", "@n", ".", "times", "do", "|", "i", "|", "@weights_current", "[", "i", "]", "=", "@decisions", "[", "i", ",", "true", "]", ".", "mean", "end", "# Proceed iteratively until we have converged to a local optimum:", "k", "=", "0", "while", "k", "<", "max_iterations", "do", "# Copy weights:", "@weights_previous", "=", "@weights_current", ".", "dup", "# E-step: Estimation of the conditional expectation of the complete data log likelihood function.", "# Deriving the estimator for the unobserved true segmentation (T).", "@n", ".", "times", "do", "|", "i", "|", "voxel_decisions", "=", "@decisions", "[", "i", ",", "true", "]", "# Find the rater-indices for this voxel where the raters' decisions equals 1 and 0:", "positive_indices", ",", "negative_indices", "=", "(", "voxel_decisions", ".", "eq", "1", ")", ".", "where2", "# Determine ai:", "# Multiply by corresponding sensitivity (or 1 - sensitivity):", "a_decision1_factor", "=", "(", "positive_indices", ".", "length", "==", "0", "?", "1", ":", "@p", "[", "positive_indices", "]", ".", "prod", ")", "a_decision0_factor", "=", "(", "negative_indices", ".", "length", "==", "0", "?", "1", ":", "(", "1", "-", "@p", "[", "negative_indices", "]", ")", ".", "prod", ")", "a", "[", "i", "]", "=", "@weights_previous", "[", "i", "]", "*", "a_decision1_factor", "*", "a_decision0_factor", "# Determine bi:", "# Multiply by corresponding specificity (or 1 - specificity):", "b_decision0_factor", "=", "(", "negative_indices", ".", "length", "==", "0", "?", "1", ":", "@q", "[", "negative_indices", "]", ".", "prod", ")", "b_decision1_factor", "=", "(", "positive_indices", ".", "length", "==", "0", "?", "1", ":", "(", "1", "-", "@q", "[", "positive_indices", "]", ")", ".", "prod", ")", "b", "[", "i", "]", "=", "@weights_previous", "[", "i", "]", "*", "b_decision0_factor", "*", "b_decision1_factor", "# Determine Wi: (take care not to divide by zero)", "if", "a", "[", "i", "]", ">", "0", "or", "b", "[", "i", "]", ">", "0", "@weights_current", "[", "i", "]", "=", "a", "[", "i", "]", "/", "(", "a", "[", "i", "]", "+", "b", "[", "i", "]", ")", "else", "@weights_current", "[", "i", "]", "=", "0", "end", "end", "# M-step: Estimation of the performance parameters by maximization.", "# Finding the values of the expert performance level parameters that maximize the conditional expectation", "# of the complete data log likelihood function (phi - p,q).", "@r", ".", "times", "do", "|", "j", "|", "voxel_decisions", "=", "@decisions", "[", "true", ",", "j", "]", "# Find the voxel-indices for this rater where the rater's decisions equals 1 and 0:", "positive_indices", ",", "negative_indices", "=", "(", "voxel_decisions", ".", "eq", "1", ")", ".", "where2", "# Determine sensitivity:", "# Sum the weights for the indices where the rater's decision equals 1:", "sum_positive", "=", "(", "positive_indices", ".", "length", "==", "0", "?", "0", ":", "@weights_current", "[", "positive_indices", "]", ".", "sum", ")", "@p", "[", "j", "]", "=", "sum_positive", "/", "@weights_current", ".", "sum", "# Determine specificity:", "# Sum the weights for the indices where the rater's decision equals 0:", "sum_negative", "=", "(", "negative_indices", ".", "length", "==", "0", "?", "0", ":", "(", "1", "-", "@weights_current", "[", "negative_indices", "]", ")", ".", "sum", ")", "@q", "[", "j", "]", "=", "sum_negative", "/", "(", "1", "-", "@weights_current", ")", ".", "sum", "end", "# Bump our iteration index:", "k", "+=", "1", "# Abort if we have reached the local optimum: (there is no change in the sum of weights)", "if", "@weights_current", ".", "sum", "-", "@weights_previous", ".", "sum", "==", "0", "#puts \"Iteration aborted as optimum solution was found!\" if @verbose", "#logger.info(\"Iteration aborted as optimum solution was found!\")", "break", "end", "end", "# Set the true segmentation:", "@true_segmentation_vector", "=", "@weights_current", ".", "round", "# Set the weights attribute:", "@weights", "=", "@weights_current", "# As this vector doesn't make much sense to the user, it must be converted to a volume. If volume reduction has", "# previously been performed, this must be taken into account when transforming it to a volume:", "construct_segmentation_volume", "# Construct a BinVolume instance for the true segmentation and add it as a master volume to the BinMatcher instance.", "update_bin_matcher", "# Set the phi variable:", "@phi", "[", "0", ",", "true", "]", "=", "@p", "@phi", "[", "1", ",", "true", "]", "=", "@q", "end" ]
Applies the STAPLE algorithm to the dataset to determine the true hidden segmentation as well as scoring the various segmentations.
[ "Applies", "the", "STAPLE", "algorithm", "to", "the", "dataset", "to", "determine", "the", "true", "hidden", "segmentation", "as", "well", "as", "scoring", "the", "various", "segmentations", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/staple.rb#L141-L215
22,925
dicom/rtkit
lib/rtkit/staple.rb
RTKIT.Staple.construct_segmentation_volume
def construct_segmentation_volume if @volumes.first.shape == @original_volumes.first.shape # Just reshape the vector (and ensure that it remains byte type): @true_segmentation = @true_segmentation_vector.reshape(*@original_volumes.first.shape).to_type(1) else # Need to take into account exactly which indices (slices, columns, rows) have been removed. # To achieve a correct reconstruction, we will use the information on the original volume indices of our # current volume, and apply it for each dimension. @true_segmentation = NArray.byte(*@original_volumes.first.shape) true_segmentation_in_reduced_volume = @true_segmentation_vector.reshape(*@volumes.first.shape) @true_segmentation[*@original_indices] = true_segmentation_in_reduced_volume end end
ruby
def construct_segmentation_volume if @volumes.first.shape == @original_volumes.first.shape # Just reshape the vector (and ensure that it remains byte type): @true_segmentation = @true_segmentation_vector.reshape(*@original_volumes.first.shape).to_type(1) else # Need to take into account exactly which indices (slices, columns, rows) have been removed. # To achieve a correct reconstruction, we will use the information on the original volume indices of our # current volume, and apply it for each dimension. @true_segmentation = NArray.byte(*@original_volumes.first.shape) true_segmentation_in_reduced_volume = @true_segmentation_vector.reshape(*@volumes.first.shape) @true_segmentation[*@original_indices] = true_segmentation_in_reduced_volume end end
[ "def", "construct_segmentation_volume", "if", "@volumes", ".", "first", ".", "shape", "==", "@original_volumes", ".", "first", ".", "shape", "# Just reshape the vector (and ensure that it remains byte type):", "@true_segmentation", "=", "@true_segmentation_vector", ".", "reshape", "(", "@original_volumes", ".", "first", ".", "shape", ")", ".", "to_type", "(", "1", ")", "else", "# Need to take into account exactly which indices (slices, columns, rows) have been removed.", "# To achieve a correct reconstruction, we will use the information on the original volume indices of our", "# current volume, and apply it for each dimension.", "@true_segmentation", "=", "NArray", ".", "byte", "(", "@original_volumes", ".", "first", ".", "shape", ")", "true_segmentation_in_reduced_volume", "=", "@true_segmentation_vector", ".", "reshape", "(", "@volumes", ".", "first", ".", "shape", ")", "@true_segmentation", "[", "@original_indices", "]", "=", "true_segmentation_in_reduced_volume", "end", "end" ]
Reshapes the true segmentation vector to a volume which is comparable with the input volumes for the Staple instance. If volume reduction has been peformed, this must be taken into account.
[ "Reshapes", "the", "true", "segmentation", "vector", "to", "a", "volume", "which", "is", "comparable", "with", "the", "input", "volumes", "for", "the", "Staple", "instance", ".", "If", "volume", "reduction", "has", "been", "peformed", "this", "must", "be", "taken", "into", "account", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/staple.rb#L233-L245
22,926
dicom/rtkit
lib/rtkit/staple.rb
RTKIT.Staple.set_parameters
def set_parameters # Convert the volumes to vectors: @vectors = Array.new @volumes.each {|volume| @vectors << volume.flatten} verify_equal_vector_lengths # Number of voxels: @n = @vectors.first.length # Number of raters: @r = @vectors.length # Decisions array: @decisions = NArray.int(@n, @r) # Sensitivity vector: (Def: true positive fraction, or relative frequency of Dij = 1 when Ti = 1) # (If a rater includes all the voxels that are included in the true segmentation, his score is 1.0 on this parameter) @p = NArray.float(@r) # Specificity vector: (Def: true negative fraction, or relative frequency of Dij = 0 when Ti = 0) # (If a rater has avoided to specify any voxels that are not specified in the true segmentation, his score is 1.0 on this parameter) @q = NArray.float(@r) # Set initial parameter values: (p0, q0) - when combined, called: phi0 @p.fill!(0.99999) @q.fill!(0.99999) # Combined scoring parameter: @phi = NArray.float(2, @r) # Fill the decisions matrix: @vectors.each_with_index do |decision, j| @decisions[true, j] = decision end # Indicator vector of the true (hidden) segmentation: @true_segmentation = NArray.byte(@n) # The estimate of the probability that the true segmentation at each voxel is Ti = 1: f(Ti=1) @weights_previous = NArray.float(@n) # Using the notation commom for EM algorithms and refering to this as the weight variable: @weights_current = NArray.float(@n) end
ruby
def set_parameters # Convert the volumes to vectors: @vectors = Array.new @volumes.each {|volume| @vectors << volume.flatten} verify_equal_vector_lengths # Number of voxels: @n = @vectors.first.length # Number of raters: @r = @vectors.length # Decisions array: @decisions = NArray.int(@n, @r) # Sensitivity vector: (Def: true positive fraction, or relative frequency of Dij = 1 when Ti = 1) # (If a rater includes all the voxels that are included in the true segmentation, his score is 1.0 on this parameter) @p = NArray.float(@r) # Specificity vector: (Def: true negative fraction, or relative frequency of Dij = 0 when Ti = 0) # (If a rater has avoided to specify any voxels that are not specified in the true segmentation, his score is 1.0 on this parameter) @q = NArray.float(@r) # Set initial parameter values: (p0, q0) - when combined, called: phi0 @p.fill!(0.99999) @q.fill!(0.99999) # Combined scoring parameter: @phi = NArray.float(2, @r) # Fill the decisions matrix: @vectors.each_with_index do |decision, j| @decisions[true, j] = decision end # Indicator vector of the true (hidden) segmentation: @true_segmentation = NArray.byte(@n) # The estimate of the probability that the true segmentation at each voxel is Ti = 1: f(Ti=1) @weights_previous = NArray.float(@n) # Using the notation commom for EM algorithms and refering to this as the weight variable: @weights_current = NArray.float(@n) end
[ "def", "set_parameters", "# Convert the volumes to vectors:", "@vectors", "=", "Array", ".", "new", "@volumes", ".", "each", "{", "|", "volume", "|", "@vectors", "<<", "volume", ".", "flatten", "}", "verify_equal_vector_lengths", "# Number of voxels:", "@n", "=", "@vectors", ".", "first", ".", "length", "# Number of raters:", "@r", "=", "@vectors", ".", "length", "# Decisions array:", "@decisions", "=", "NArray", ".", "int", "(", "@n", ",", "@r", ")", "# Sensitivity vector: (Def: true positive fraction, or relative frequency of Dij = 1 when Ti = 1)", "# (If a rater includes all the voxels that are included in the true segmentation, his score is 1.0 on this parameter)", "@p", "=", "NArray", ".", "float", "(", "@r", ")", "# Specificity vector: (Def: true negative fraction, or relative frequency of Dij = 0 when Ti = 0)", "# (If a rater has avoided to specify any voxels that are not specified in the true segmentation, his score is 1.0 on this parameter)", "@q", "=", "NArray", ".", "float", "(", "@r", ")", "# Set initial parameter values: (p0, q0) - when combined, called: phi0", "@p", ".", "fill!", "(", "0.99999", ")", "@q", ".", "fill!", "(", "0.99999", ")", "# Combined scoring parameter:", "@phi", "=", "NArray", ".", "float", "(", "2", ",", "@r", ")", "# Fill the decisions matrix:", "@vectors", ".", "each_with_index", "do", "|", "decision", ",", "j", "|", "@decisions", "[", "true", ",", "j", "]", "=", "decision", "end", "# Indicator vector of the true (hidden) segmentation:", "@true_segmentation", "=", "NArray", ".", "byte", "(", "@n", ")", "# The estimate of the probability that the true segmentation at each voxel is Ti = 1: f(Ti=1)", "@weights_previous", "=", "NArray", ".", "float", "(", "@n", ")", "# Using the notation commom for EM algorithms and refering to this as the weight variable:", "@weights_current", "=", "NArray", ".", "float", "(", "@n", ")", "end" ]
Sets the instance attributes used by the STAPLE algorithm.
[ "Sets", "the", "instance", "attributes", "used", "by", "the", "STAPLE", "algorithm", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/staple.rb#L249-L281
22,927
dicom/rtkit
lib/rtkit/staple.rb
RTKIT.Staple.verify_equal_vector_lengths
def verify_equal_vector_lengths vector_lengths = @vectors.collect{|vector| vector.length} raise IndexError, "Unexpected behaviour: The vectors going into the STAPLE analysis have different lengths." unless vector_lengths.uniq.length == 1 end
ruby
def verify_equal_vector_lengths vector_lengths = @vectors.collect{|vector| vector.length} raise IndexError, "Unexpected behaviour: The vectors going into the STAPLE analysis have different lengths." unless vector_lengths.uniq.length == 1 end
[ "def", "verify_equal_vector_lengths", "vector_lengths", "=", "@vectors", ".", "collect", "{", "|", "vector", "|", "vector", ".", "length", "}", "raise", "IndexError", ",", "\"Unexpected behaviour: The vectors going into the STAPLE analysis have different lengths.\"", "unless", "vector_lengths", ".", "uniq", ".", "length", "==", "1", "end" ]
Ensures that the number of voxels are the same for all segmentation vectors going into the STAPLE analysis. raise [IndexError] if the vectors to be compared in the STAPLE analysis are of different lengths
[ "Ensures", "that", "the", "number", "of", "voxels", "are", "the", "same", "for", "all", "segmentation", "vectors", "going", "into", "the", "STAPLE", "analysis", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/staple.rb#L320-L323
22,928
dicom/rtkit
lib/rtkit/study.rb
RTKIT.Study.add
def add(dcm) raise ArgumentError, "Invalid argument 'dcm'. Expected DObject, got #{dcm.class}." unless dcm.is_a?(DICOM::DObject) existing_series = @associated_series[dcm.value(SERIES_UID)] if existing_series existing_series.add(dcm) else # New series (series subclass depends on modality): case dcm.value(MODALITY) when *IMAGE_SERIES # Create the ImageSeries: s = ImageSeries.load(dcm, self) when 'RTSTRUCT' s = StructureSet.load(dcm, self) when 'RTPLAN' s = Plan.load(dcm, self) when 'RTDOSE' s = RTDose.load(dcm, self) when 'RTIMAGE' s = RTImage.load(dcm, self) when 'CR' s = CRSeries.load(dcm, self) else raise ArgumentError, "Unexpected (unsupported) modality (#{dcm.value(MODALITY)})in Study#add()" end # Add the newly created series to this study: add_series(s) end end
ruby
def add(dcm) raise ArgumentError, "Invalid argument 'dcm'. Expected DObject, got #{dcm.class}." unless dcm.is_a?(DICOM::DObject) existing_series = @associated_series[dcm.value(SERIES_UID)] if existing_series existing_series.add(dcm) else # New series (series subclass depends on modality): case dcm.value(MODALITY) when *IMAGE_SERIES # Create the ImageSeries: s = ImageSeries.load(dcm, self) when 'RTSTRUCT' s = StructureSet.load(dcm, self) when 'RTPLAN' s = Plan.load(dcm, self) when 'RTDOSE' s = RTDose.load(dcm, self) when 'RTIMAGE' s = RTImage.load(dcm, self) when 'CR' s = CRSeries.load(dcm, self) else raise ArgumentError, "Unexpected (unsupported) modality (#{dcm.value(MODALITY)})in Study#add()" end # Add the newly created series to this study: add_series(s) end end
[ "def", "add", "(", "dcm", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'dcm'. Expected DObject, got #{dcm.class}.\"", "unless", "dcm", ".", "is_a?", "(", "DICOM", "::", "DObject", ")", "existing_series", "=", "@associated_series", "[", "dcm", ".", "value", "(", "SERIES_UID", ")", "]", "if", "existing_series", "existing_series", ".", "add", "(", "dcm", ")", "else", "# New series (series subclass depends on modality):", "case", "dcm", ".", "value", "(", "MODALITY", ")", "when", "IMAGE_SERIES", "# Create the ImageSeries:", "s", "=", "ImageSeries", ".", "load", "(", "dcm", ",", "self", ")", "when", "'RTSTRUCT'", "s", "=", "StructureSet", ".", "load", "(", "dcm", ",", "self", ")", "when", "'RTPLAN'", "s", "=", "Plan", ".", "load", "(", "dcm", ",", "self", ")", "when", "'RTDOSE'", "s", "=", "RTDose", ".", "load", "(", "dcm", ",", "self", ")", "when", "'RTIMAGE'", "s", "=", "RTImage", ".", "load", "(", "dcm", ",", "self", ")", "when", "'CR'", "s", "=", "CRSeries", ".", "load", "(", "dcm", ",", "self", ")", "else", "raise", "ArgumentError", ",", "\"Unexpected (unsupported) modality (#{dcm.value(MODALITY)})in Study#add()\"", "end", "# Add the newly created series to this study:", "add_series", "(", "s", ")", "end", "end" ]
Creates a new Study instance. The Study Instance UID string is used to uniquely identify a study. @param [String] study_uid the Study Instance UID string @param [Patient] patient the Patient instance which this Study is associated with @param [Hash] options the options to use for creating the study @option options [String] :date the study date (DICOM tag '0008,0020') @option options [String] :description the study description (DICOM tag '0008,1030') @option options [String] :id the study ID (DICOM tag '0020,0010') @option options [String] :time the study time (DICOM tag '0008,0030') Registers a DICOM object to the study, and processes it to either create (and reference) a new series instance linked to this study, or registering it with an existing series. @param [DICOM::DObject] dcm a DICOM object
[ "Creates", "a", "new", "Study", "instance", ".", "The", "Study", "Instance", "UID", "string", "is", "used", "to", "uniquely", "identify", "a", "study", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/study.rb#L92-L119
22,929
dicom/rtkit
lib/rtkit/study.rb
RTKIT.Study.add_series
def add_series(series) raise ArgumentError, "Invalid argument 'series'. Expected Series, got #{series.class}." unless series.is_a?(Series) # Do not add it again if the series already belongs to this instance: @series << series unless @associated_series[series.uid] @image_series << series if series.is_a?(ImageSeries) && !@associated_series[series.uid] @associated_series[series.uid] = series @associated_iseries[series.uid] = series if series.is_a?(ImageSeries) end
ruby
def add_series(series) raise ArgumentError, "Invalid argument 'series'. Expected Series, got #{series.class}." unless series.is_a?(Series) # Do not add it again if the series already belongs to this instance: @series << series unless @associated_series[series.uid] @image_series << series if series.is_a?(ImageSeries) && !@associated_series[series.uid] @associated_series[series.uid] = series @associated_iseries[series.uid] = series if series.is_a?(ImageSeries) end
[ "def", "add_series", "(", "series", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'series'. Expected Series, got #{series.class}.\"", "unless", "series", ".", "is_a?", "(", "Series", ")", "# Do not add it again if the series already belongs to this instance:", "@series", "<<", "series", "unless", "@associated_series", "[", "series", ".", "uid", "]", "@image_series", "<<", "series", "if", "series", ".", "is_a?", "(", "ImageSeries", ")", "&&", "!", "@associated_series", "[", "series", ".", "uid", "]", "@associated_series", "[", "series", ".", "uid", "]", "=", "series", "@associated_iseries", "[", "series", ".", "uid", "]", "=", "series", "if", "series", ".", "is_a?", "(", "ImageSeries", ")", "end" ]
Adds a Series to this Study. @param [Series] series a series instance to be associated with this study
[ "Adds", "a", "Series", "to", "this", "Study", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/study.rb#L141-L148
22,930
dicom/rtkit
lib/rtkit/selection.rb
RTKIT.Selection.shift
def shift(delta_col, delta_row) raise ArgumentError, "Invalid argument 'delta_col'. Expected Integer, got #{delta_col.class}." unless delta_col.is_a?(Integer) raise ArgumentError, "Invalid argument 'delta_row'. Expected Integer, got #{delta_row.class}." unless delta_row.is_a?(Integer) new_columns = @indices.collect {|index| index % @bin_image.columns + delta_col} new_rows = @indices.collect {|index| index / @bin_image.columns + delta_row} # Set new indices: @indices = Array.new(new_rows.length) {|i| new_columns[i] + new_rows[i] * @bin_image.columns} end
ruby
def shift(delta_col, delta_row) raise ArgumentError, "Invalid argument 'delta_col'. Expected Integer, got #{delta_col.class}." unless delta_col.is_a?(Integer) raise ArgumentError, "Invalid argument 'delta_row'. Expected Integer, got #{delta_row.class}." unless delta_row.is_a?(Integer) new_columns = @indices.collect {|index| index % @bin_image.columns + delta_col} new_rows = @indices.collect {|index| index / @bin_image.columns + delta_row} # Set new indices: @indices = Array.new(new_rows.length) {|i| new_columns[i] + new_rows[i] * @bin_image.columns} end
[ "def", "shift", "(", "delta_col", ",", "delta_row", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'delta_col'. Expected Integer, got #{delta_col.class}.\"", "unless", "delta_col", ".", "is_a?", "(", "Integer", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'delta_row'. Expected Integer, got #{delta_row.class}.\"", "unless", "delta_row", ".", "is_a?", "(", "Integer", ")", "new_columns", "=", "@indices", ".", "collect", "{", "|", "index", "|", "index", "%", "@bin_image", ".", "columns", "+", "delta_col", "}", "new_rows", "=", "@indices", ".", "collect", "{", "|", "index", "|", "index", "/", "@bin_image", ".", "columns", "+", "delta_row", "}", "# Set new indices:", "@indices", "=", "Array", ".", "new", "(", "new_rows", ".", "length", ")", "{", "|", "i", "|", "new_columns", "[", "i", "]", "+", "new_rows", "[", "i", "]", "*", "@bin_image", ".", "columns", "}", "end" ]
Shifts the indices of this selection by the specified number of columns and rows. Positive arguments increment the column and row indices. @note No out of bounds check is performed for indices that are shifted past the image boundary! @param [Integer] delta_col the desired column shift @param [Integer] delta_row the desired row shift @return [Array] the shifted indices
[ "Shifts", "the", "indices", "of", "this", "selection", "by", "the", "specified", "number", "of", "columns", "and", "rows", ".", "Positive", "arguments", "increment", "the", "column", "and", "row", "indices", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/selection.rb#L117-L124
22,931
dicom/rtkit
lib/rtkit/selection.rb
RTKIT.Selection.shift_columns
def shift_columns(delta) raise ArgumentError, "Invalid argument 'delta'. Expected Integer, got #{delta.class}." unless delta.is_a?(Integer) new_columns = @indices.collect {|index| index % @bin_image.columns + delta} new_rows = rows # Set new indices: @indices = Array.new(new_columns.length) {|i| new_columns[i] + new_rows[i] * @bin_image.columns} end
ruby
def shift_columns(delta) raise ArgumentError, "Invalid argument 'delta'. Expected Integer, got #{delta.class}." unless delta.is_a?(Integer) new_columns = @indices.collect {|index| index % @bin_image.columns + delta} new_rows = rows # Set new indices: @indices = Array.new(new_columns.length) {|i| new_columns[i] + new_rows[i] * @bin_image.columns} end
[ "def", "shift_columns", "(", "delta", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'delta'. Expected Integer, got #{delta.class}.\"", "unless", "delta", ".", "is_a?", "(", "Integer", ")", "new_columns", "=", "@indices", ".", "collect", "{", "|", "index", "|", "index", "%", "@bin_image", ".", "columns", "+", "delta", "}", "new_rows", "=", "rows", "# Set new indices:", "@indices", "=", "Array", ".", "new", "(", "new_columns", ".", "length", ")", "{", "|", "i", "|", "new_columns", "[", "i", "]", "+", "new_rows", "[", "i", "]", "*", "@bin_image", ".", "columns", "}", "end" ]
Shifts the indices of this selection by the specified number of columns. A positive argument increment the column indices. @note No out of bounds check is performed for indices that are shifted past the image boundary. @param [Integer] delta the desired column shift @return [Array] the shifted indices
[ "Shifts", "the", "indices", "of", "this", "selection", "by", "the", "specified", "number", "of", "columns", ".", "A", "positive", "argument", "increment", "the", "column", "indices", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/selection.rb#L160-L166
22,932
celluloid/dcell
lib/dcell/node_manager.rb
DCell.NodeManager.each
def each Directory.each do |id| remote = NodeCache.register id next unless remote yield remote end end
ruby
def each Directory.each do |id| remote = NodeCache.register id next unless remote yield remote end end
[ "def", "each", "Directory", ".", "each", "do", "|", "id", "|", "remote", "=", "NodeCache", ".", "register", "id", "next", "unless", "remote", "yield", "remote", "end", "end" ]
Iterate across all available nodes
[ "Iterate", "across", "all", "available", "nodes" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/node_manager.rb#L51-L57
22,933
dicom/rtkit
lib/rtkit/cr_series.rb
RTKIT.CRSeries.add_image
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) @images << image @associated_images[image.uid] = image end
ruby
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) @images << image @associated_images[image.uid] = image end
[ "def", "add_image", "(", "image", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected Image, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "Image", ")", "@images", "<<", "image", "@associated_images", "[", "image", ".", "uid", "]", "=", "image", "end" ]
Adds an Image to this CRSeries. @param [Image] image an image instance to be associated with this series
[ "Adds", "an", "Image", "to", "this", "CRSeries", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/cr_series.rb#L94-L98
22,934
celluloid/dcell
lib/dcell.rb
DCell.ClassMethods.find
def find(actor) Directory.each_with_object([]) do |id, actors| next if id == DCell.id node = Directory[id] next unless node next unless node.actors.include? actor ractor = get_remote_actor actor, id actors << ractor if ractor end end
ruby
def find(actor) Directory.each_with_object([]) do |id, actors| next if id == DCell.id node = Directory[id] next unless node next unless node.actors.include? actor ractor = get_remote_actor actor, id actors << ractor if ractor end end
[ "def", "find", "(", "actor", ")", "Directory", ".", "each_with_object", "(", "[", "]", ")", "do", "|", "id", ",", "actors", "|", "next", "if", "id", "==", "DCell", ".", "id", "node", "=", "Directory", "[", "id", "]", "next", "unless", "node", "next", "unless", "node", ".", "actors", ".", "include?", "actor", "ractor", "=", "get_remote_actor", "actor", ",", "id", "actors", "<<", "ractor", "if", "ractor", "end", "end" ]
Returns actors from multiple nodes
[ "Returns", "actors", "from", "multiple", "nodes" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell.rb#L100-L109
22,935
celluloid/dcell
lib/dcell.rb
DCell.ClassMethods.run!
def run! Directory[id].actors = local_actors Directory[id].pubkey = crypto ? crypto_keys[:pubkey] : nil DCell::SupervisionGroup.run! end
ruby
def run! Directory[id].actors = local_actors Directory[id].pubkey = crypto ? crypto_keys[:pubkey] : nil DCell::SupervisionGroup.run! end
[ "def", "run!", "Directory", "[", "id", "]", ".", "actors", "=", "local_actors", "Directory", "[", "id", "]", ".", "pubkey", "=", "crypto", "?", "crypto_keys", "[", ":pubkey", "]", ":", "nil", "DCell", "::", "SupervisionGroup", ".", "run!", "end" ]
Run the DCell application in the background
[ "Run", "the", "DCell", "application", "in", "the", "background" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell.rb#L113-L117
22,936
celluloid/dcell
lib/dcell.rb
DCell.ClassMethods.generate_node_id
def generate_node_id # a little bit more creative if @registry.respond_to? :unique @registry.unique else digest = Digest::SHA512.new seed = ::Socket.gethostname + rand.to_s + Time.now.to_s + SecureRandom.hex digest.update(seed).to_s end end
ruby
def generate_node_id # a little bit more creative if @registry.respond_to? :unique @registry.unique else digest = Digest::SHA512.new seed = ::Socket.gethostname + rand.to_s + Time.now.to_s + SecureRandom.hex digest.update(seed).to_s end end
[ "def", "generate_node_id", "# a little bit more creative", "if", "@registry", ".", "respond_to?", ":unique", "@registry", ".", "unique", "else", "digest", "=", "Digest", "::", "SHA512", ".", "new", "seed", "=", "::", "Socket", ".", "gethostname", "+", "rand", ".", "to_s", "+", "Time", ".", "now", ".", "to_s", "+", "SecureRandom", ".", "hex", "digest", ".", "update", "(", "seed", ")", ".", "to_s", "end", "end" ]
Attempt to generate a unique node ID for this machine
[ "Attempt", "to", "generate", "a", "unique", "node", "ID", "for", "this", "machine" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell.rb#L165-L174
22,937
celluloid/dcell
lib/dcell/node.rb
DCell.Node.find
def find(name) request = Message::Find.new(Thread.mailbox, name) methods = send_request request return nil if methods.is_a? NilClass rsocket # open relay pipe to avoid race conditions actor = DCell::ActorProxy.create.new self, name, methods add_actor actor end
ruby
def find(name) request = Message::Find.new(Thread.mailbox, name) methods = send_request request return nil if methods.is_a? NilClass rsocket # open relay pipe to avoid race conditions actor = DCell::ActorProxy.create.new self, name, methods add_actor actor end
[ "def", "find", "(", "name", ")", "request", "=", "Message", "::", "Find", ".", "new", "(", "Thread", ".", "mailbox", ",", "name", ")", "methods", "=", "send_request", "request", "return", "nil", "if", "methods", ".", "is_a?", "NilClass", "rsocket", "# open relay pipe to avoid race conditions", "actor", "=", "DCell", "::", "ActorProxy", ".", "create", ".", "new", "self", ",", "name", ",", "methods", "add_actor", "actor", "end" ]
Find an call registered with a given name on this node
[ "Find", "an", "call", "registered", "with", "a", "given", "name", "on", "this", "node" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/node.rb#L60-L67
22,938
celluloid/dcell
lib/dcell/node.rb
DCell.Node.actors
def actors request = Message::List.new(Thread.mailbox) list = send_request request list.map!(&:to_sym) end
ruby
def actors request = Message::List.new(Thread.mailbox) list = send_request request list.map!(&:to_sym) end
[ "def", "actors", "request", "=", "Message", "::", "List", ".", "new", "(", "Thread", ".", "mailbox", ")", "list", "=", "send_request", "request", "list", ".", "map!", "(", ":to_sym", ")", "end" ]
List all registered actors on this node
[ "List", "all", "registered", "actors", "on", "this", "node" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/node.rb#L71-L75
22,939
celluloid/dcell
lib/dcell/node.rb
DCell.Node.ping
def ping(timeout=nil) request = Message::Ping.new(Thread.mailbox) send_request request, :request, timeout end
ruby
def ping(timeout=nil) request = Message::Ping.new(Thread.mailbox) send_request request, :request, timeout end
[ "def", "ping", "(", "timeout", "=", "nil", ")", "request", "=", "Message", "::", "Ping", ".", "new", "(", "Thread", ".", "mailbox", ")", "send_request", "request", ",", ":request", ",", "timeout", "end" ]
Send a ping message with a given timeout
[ "Send", "a", "ping", "message", "with", "a", "given", "timeout" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/node.rb#L79-L82
22,940
celluloid/dcell
lib/dcell/node.rb
DCell.Node.shutdown
def shutdown transition :shutdown kill_actors close_comm NodeCache.delete @id MailboxManager.delete Thread.mailbox instance_variables.each { |iv| remove_instance_variable iv } end
ruby
def shutdown transition :shutdown kill_actors close_comm NodeCache.delete @id MailboxManager.delete Thread.mailbox instance_variables.each { |iv| remove_instance_variable iv } end
[ "def", "shutdown", "transition", ":shutdown", "kill_actors", "close_comm", "NodeCache", ".", "delete", "@id", "MailboxManager", ".", "delete", "Thread", ".", "mailbox", "instance_variables", ".", "each", "{", "|", "iv", "|", "remove_instance_variable", "iv", "}", "end" ]
Graceful termination of the node
[ "Graceful", "termination", "of", "the", "node" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/node.rb#L110-L117
22,941
dicom/rtkit
lib/rtkit/slice.rb
RTKIT.Slice.add_contour
def add_contour(contour) raise ArgumentError, "Invalid argument 'contour'. Expected Contour, got #{contour.class}." unless contour.is_a?(Contour) @contours << contour unless @contours.include?(contour) end
ruby
def add_contour(contour) raise ArgumentError, "Invalid argument 'contour'. Expected Contour, got #{contour.class}." unless contour.is_a?(Contour) @contours << contour unless @contours.include?(contour) end
[ "def", "add_contour", "(", "contour", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'contour'. Expected Contour, got #{contour.class}.\"", "unless", "contour", ".", "is_a?", "(", "Contour", ")", "@contours", "<<", "contour", "unless", "@contours", ".", "include?", "(", "contour", ")", "end" ]
Adds a Contour instance to this Slice. @param [Contour] contour a contour instance to be associated with this slice
[ "Adds", "a", "Contour", "instance", "to", "this", "Slice", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/slice.rb#L83-L86
22,942
dicom/rtkit
lib/rtkit/slice.rb
RTKIT.Slice.bin_image
def bin_image(source_image=@image) raise "Referenced ROI Slice Image is missing from the dataset. Unable to construct image." unless @image bin_img = BinImage.new(NArray.byte(source_image.columns, source_image.rows), source_image) # Delineate and fill for each contour, then create the final image: @contours.each_with_index do |contour, i| x, y, z = contour.coords bin_img.add(source_image.binary_image(x, y, z)) end return bin_img end
ruby
def bin_image(source_image=@image) raise "Referenced ROI Slice Image is missing from the dataset. Unable to construct image." unless @image bin_img = BinImage.new(NArray.byte(source_image.columns, source_image.rows), source_image) # Delineate and fill for each contour, then create the final image: @contours.each_with_index do |contour, i| x, y, z = contour.coords bin_img.add(source_image.binary_image(x, y, z)) end return bin_img end
[ "def", "bin_image", "(", "source_image", "=", "@image", ")", "raise", "\"Referenced ROI Slice Image is missing from the dataset. Unable to construct image.\"", "unless", "@image", "bin_img", "=", "BinImage", ".", "new", "(", "NArray", ".", "byte", "(", "source_image", ".", "columns", ",", "source_image", ".", "rows", ")", ",", "source_image", ")", "# Delineate and fill for each contour, then create the final image:", "@contours", ".", "each_with_index", "do", "|", "contour", ",", "i", "|", "x", ",", "y", ",", "z", "=", "contour", ".", "coords", "bin_img", ".", "add", "(", "source_image", ".", "binary_image", "(", "x", ",", "y", ",", "z", ")", ")", "end", "return", "bin_img", "end" ]
Creates a binary segmented image, from the contours defined for this slice, applied to the referenced Image instance. @param [Image] source_image the image on which the binary image will be applied (defaults to the referenced (anatomical) image, but may be e.g. a dose image) @return [BinImage] the derived binary image instance (with dimensions equal to that of the source image)
[ "Creates", "a", "binary", "segmented", "image", "from", "the", "contours", "defined", "for", "this", "slice", "applied", "to", "the", "referenced", "Image", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/slice.rb#L131-L140
22,943
dicom/rtkit
lib/rtkit/slice.rb
RTKIT.Slice.plane
def plane # Such a change is only possible if the Slice instance has a Contour with at least three Coordinates: raise "This Slice does not contain a Contour. Plane determination is not possible." if @contours.length == 0 raise "This Slice does not contain a Contour with at least 3 Coordinates. Plane determination is not possible." if @contours.first.coordinates.length < 3 # Get three coordinates from our Contour: contour = @contours.first num_coords = contour.coordinates.length c1 = contour.coordinates.first c2 = contour.coordinates[num_coords / 3] c3 = contour.coordinates[2 * num_coords / 3] return Plane.calculate(c1, c2, c3) end
ruby
def plane # Such a change is only possible if the Slice instance has a Contour with at least three Coordinates: raise "This Slice does not contain a Contour. Plane determination is not possible." if @contours.length == 0 raise "This Slice does not contain a Contour with at least 3 Coordinates. Plane determination is not possible." if @contours.first.coordinates.length < 3 # Get three coordinates from our Contour: contour = @contours.first num_coords = contour.coordinates.length c1 = contour.coordinates.first c2 = contour.coordinates[num_coords / 3] c3 = contour.coordinates[2 * num_coords / 3] return Plane.calculate(c1, c2, c3) end
[ "def", "plane", "# Such a change is only possible if the Slice instance has a Contour with at least three Coordinates:", "raise", "\"This Slice does not contain a Contour. Plane determination is not possible.\"", "if", "@contours", ".", "length", "==", "0", "raise", "\"This Slice does not contain a Contour with at least 3 Coordinates. Plane determination is not possible.\"", "if", "@contours", ".", "first", ".", "coordinates", ".", "length", "<", "3", "# Get three coordinates from our Contour:", "contour", "=", "@contours", ".", "first", "num_coords", "=", "contour", ".", "coordinates", ".", "length", "c1", "=", "contour", ".", "coordinates", ".", "first", "c2", "=", "contour", ".", "coordinates", "[", "num_coords", "/", "3", "]", "c3", "=", "contour", ".", "coordinates", "[", "2", "*", "num_coords", "/", "3", "]", "return", "Plane", ".", "calculate", "(", "c1", ",", "c2", ",", "c3", ")", "end" ]
Gives a Plane corresponding to this Slice geometry. The plane is calculated from coordinates belonging to this instance. @return [Plane] the derived plane @raise [RuntimeError] unless the required number of coordinates are present (at least 3)
[ "Gives", "a", "Plane", "corresponding", "to", "this", "Slice", "geometry", ".", "The", "plane", "is", "calculated", "from", "coordinates", "belonging", "to", "this", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/slice.rb#L166-L177
22,944
dicom/rtkit
lib/rtkit/structure.rb
RTKIT.Structure.ss_item
def ss_item item = DICOM::Item.new item.add(DICOM::Element.new(ROI_NUMBER, @number.to_s)) item.add(DICOM::Element.new(REF_FRAME_OF_REF, @frame.uid)) item.add(DICOM::Element.new(ROI_NAME, @name)) item.add(DICOM::Element.new(ROI_ALGORITHM, @algorithm)) return item end
ruby
def ss_item item = DICOM::Item.new item.add(DICOM::Element.new(ROI_NUMBER, @number.to_s)) item.add(DICOM::Element.new(REF_FRAME_OF_REF, @frame.uid)) item.add(DICOM::Element.new(ROI_NAME, @name)) item.add(DICOM::Element.new(ROI_ALGORITHM, @algorithm)) return item end
[ "def", "ss_item", "item", "=", "DICOM", "::", "Item", ".", "new", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "ROI_NUMBER", ",", "@number", ".", "to_s", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "REF_FRAME_OF_REF", ",", "@frame", ".", "uid", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "ROI_NAME", ",", "@name", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "ROI_ALGORITHM", ",", "@algorithm", ")", ")", "return", "item", "end" ]
Creates a Structure Set ROI Sequence Item from the attributes of the Structure instance. @return [DICOM::Item] a structure set ROI sequence item
[ "Creates", "a", "Structure", "Set", "ROI", "Sequence", "Item", "from", "the", "attributes", "of", "the", "Structure", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure.rb#L268-L275
22,945
dicom/rtkit
lib/rtkit/patient.rb
RTKIT.Patient.add
def add(dcm) s = study(dcm.value(STUDY_UID)) if s s.add(dcm) else add_study(Study.load(dcm, self)) end end
ruby
def add(dcm) s = study(dcm.value(STUDY_UID)) if s s.add(dcm) else add_study(Study.load(dcm, self)) end end
[ "def", "add", "(", "dcm", ")", "s", "=", "study", "(", "dcm", ".", "value", "(", "STUDY_UID", ")", ")", "if", "s", "s", ".", "add", "(", "dcm", ")", "else", "add_study", "(", "Study", ".", "load", "(", "dcm", ",", "self", ")", ")", "end", "end" ]
Registers a DICOM object to the patient, by adding it to an existing Study, or creating a new Study. @param [DICOM::DObject] dcm a DICOM object
[ "Registers", "a", "DICOM", "object", "to", "the", "patient", "by", "adding", "it", "to", "an", "existing", "Study", "or", "creating", "a", "new", "Study", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/patient.rb#L99-L106
22,946
dicom/rtkit
lib/rtkit/patient.rb
RTKIT.Patient.add_study
def add_study(study) raise ArgumentError, "Invalid argument 'study'. Expected Study, got #{study.class}." unless study.is_a?(Study) # Do not add it again if the study already belongs to this instance: @studies << study unless @associated_studies[study.uid] @associated_studies[study.uid] = study end
ruby
def add_study(study) raise ArgumentError, "Invalid argument 'study'. Expected Study, got #{study.class}." unless study.is_a?(Study) # Do not add it again if the study already belongs to this instance: @studies << study unless @associated_studies[study.uid] @associated_studies[study.uid] = study end
[ "def", "add_study", "(", "study", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'study'. Expected Study, got #{study.class}.\"", "unless", "study", ".", "is_a?", "(", "Study", ")", "# Do not add it again if the study already belongs to this instance:", "@studies", "<<", "study", "unless", "@associated_studies", "[", "study", ".", "uid", "]", "@associated_studies", "[", "study", ".", "uid", "]", "=", "study", "end" ]
Adds a Study to this Patient. @param [Study] study a study instance to be associated with this patient
[ "Adds", "a", "Study", "to", "this", "Patient", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/patient.rb#L123-L128
22,947
slagyr/limelight
ruby/lib/limelight/prop.rb
Limelight.Prop.play_sound
def play_sound(filename) path = Java::limelight.Context.fs.path_to(scene.path, filename) @peer.play_sound(path) end
ruby
def play_sound(filename) path = Java::limelight.Context.fs.path_to(scene.path, filename) @peer.play_sound(path) end
[ "def", "play_sound", "(", "filename", ")", "path", "=", "Java", "::", "limelight", ".", "Context", ".", "fs", ".", "path_to", "(", "scene", ".", "path", ",", "filename", ")", "@peer", ".", "play_sound", "(", "path", ")", "end" ]
Plays a sound on the computers audio output. The parameter is the filename of a .au sound file. This filename should relative to the root directory of the current Production, or an absolute path.
[ "Plays", "a", "sound", "on", "the", "computers", "audio", "output", ".", "The", "parameter", "is", "the", "filename", "of", "a", ".", "au", "sound", "file", ".", "This", "filename", "should", "relative", "to", "the", "root", "directory", "of", "the", "current", "Production", "or", "an", "absolute", "path", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/prop.rb#L260-L263
22,948
slagyr/limelight
ruby/lib/limelight/scene.rb
Limelight.Scene.open_production
def open_production(production_path) Thread.new { Java::limelight.Context.instance.studio.open(production_path) } end
ruby
def open_production(production_path) Thread.new { Java::limelight.Context.instance.studio.open(production_path) } end
[ "def", "open_production", "(", "production_path", ")", "Thread", ".", "new", "{", "Java", "::", "limelight", ".", "Context", ".", "instance", ".", "studio", ".", "open", "(", "production_path", ")", "}", "end" ]
Creates a new Producer to open the specified Production.
[ "Creates", "a", "new", "Producer", "to", "open", "the", "specified", "Production", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/scene.rb#L96-L98
22,949
slagyr/limelight
ruby/lib/limelight/scene.rb
Limelight.Scene.find_by_id
def find_by_id(id) peer_result = @peer.find(id.to_s) peer_result.nil? ? nil : peer_result.proxy end
ruby
def find_by_id(id) peer_result = @peer.find(id.to_s) peer_result.nil? ? nil : peer_result.proxy end
[ "def", "find_by_id", "(", "id", ")", "peer_result", "=", "@peer", ".", "find", "(", "id", ".", "to_s", ")", "peer_result", ".", "nil?", "?", "nil", ":", "peer_result", ".", "proxy", "end" ]
Returns a Prop with the specified id. Returns nil id the Prop doesn't exist in the Scene.
[ "Returns", "a", "Prop", "with", "the", "specified", "id", ".", "Returns", "nil", "id", "the", "Prop", "doesn", "t", "exist", "in", "the", "Scene", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/scene.rb#L109-L112
22,950
dicom/rtkit
lib/rtkit/collimator_setup.rb
RTKIT.CollimatorSetup.to_item
def to_item item = DICOM::Item.new item.add(DICOM::Element.new(COLL_TYPE, @type)) item.add(DICOM::Element.new(COLL_POS, positions_string)) return item end
ruby
def to_item item = DICOM::Item.new item.add(DICOM::Element.new(COLL_TYPE, @type)) item.add(DICOM::Element.new(COLL_POS, positions_string)) return item end
[ "def", "to_item", "item", "=", "DICOM", "::", "Item", ".", "new", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "COLL_TYPE", ",", "@type", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "COLL_POS", ",", "positions_string", ")", ")", "return", "item", "end" ]
Creates a Beam Limiting Device Position Sequence Item from the attributes of the CollimatorSetup. @return [DICOM::Item] the created DICOM item
[ "Creates", "a", "Beam", "Limiting", "Device", "Position", "Sequence", "Item", "from", "the", "attributes", "of", "the", "CollimatorSetup", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/collimator_setup.rb#L113-L118
22,951
dicom/rtkit
lib/rtkit/roi.rb
RTKIT.ROI.add_slice
def add_slice(slice) raise ArgumentError, "Invalid argument 'slice'. Expected Slice, got #{slice.class}." unless slice.is_a?(Slice) @slices << slice unless @associated_instance_uids[slice.uid] @associated_instance_uids[slice.uid] = slice end
ruby
def add_slice(slice) raise ArgumentError, "Invalid argument 'slice'. Expected Slice, got #{slice.class}." unless slice.is_a?(Slice) @slices << slice unless @associated_instance_uids[slice.uid] @associated_instance_uids[slice.uid] = slice end
[ "def", "add_slice", "(", "slice", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'slice'. Expected Slice, got #{slice.class}.\"", "unless", "slice", ".", "is_a?", "(", "Slice", ")", "@slices", "<<", "slice", "unless", "@associated_instance_uids", "[", "slice", ".", "uid", "]", "@associated_instance_uids", "[", "slice", ".", "uid", "]", "=", "slice", "end" ]
Adds a Slice instance to this ROI. @param [Slice] slice a slice instance to be associated with this ROI
[ "Adds", "a", "Slice", "instance", "to", "this", "ROI", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/roi.rb#L65-L69
22,952
dicom/rtkit
lib/rtkit/roi.rb
RTKIT.ROI.create_slices
def create_slices(contour_sequence) raise ArgumentError, "Invalid argument 'contour_sequence'. Expected DICOM::Sequence, got #{contour_sequence.class}." unless contour_sequence.is_a?(DICOM::Sequence) # Sort the contours by slices: slice_collection = Hash.new contour_sequence.each do |slice_contour_item| sop_uid = slice_contour_item[CONTOUR_IMAGE_SQ][0].value(REF_SOP_UID) slice_collection[sop_uid] = Array.new unless slice_collection[sop_uid] slice_collection[sop_uid] << slice_contour_item end # Create slices: slice_collection.each_pair do |sop_uid, items| Slice.create_from_items(sop_uid, items, self) end end
ruby
def create_slices(contour_sequence) raise ArgumentError, "Invalid argument 'contour_sequence'. Expected DICOM::Sequence, got #{contour_sequence.class}." unless contour_sequence.is_a?(DICOM::Sequence) # Sort the contours by slices: slice_collection = Hash.new contour_sequence.each do |slice_contour_item| sop_uid = slice_contour_item[CONTOUR_IMAGE_SQ][0].value(REF_SOP_UID) slice_collection[sop_uid] = Array.new unless slice_collection[sop_uid] slice_collection[sop_uid] << slice_contour_item end # Create slices: slice_collection.each_pair do |sop_uid, items| Slice.create_from_items(sop_uid, items, self) end end
[ "def", "create_slices", "(", "contour_sequence", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'contour_sequence'. Expected DICOM::Sequence, got #{contour_sequence.class}.\"", "unless", "contour_sequence", ".", "is_a?", "(", "DICOM", "::", "Sequence", ")", "# Sort the contours by slices:", "slice_collection", "=", "Hash", ".", "new", "contour_sequence", ".", "each", "do", "|", "slice_contour_item", "|", "sop_uid", "=", "slice_contour_item", "[", "CONTOUR_IMAGE_SQ", "]", "[", "0", "]", ".", "value", "(", "REF_SOP_UID", ")", "slice_collection", "[", "sop_uid", "]", "=", "Array", ".", "new", "unless", "slice_collection", "[", "sop_uid", "]", "slice_collection", "[", "sop_uid", "]", "<<", "slice_contour_item", "end", "# Create slices:", "slice_collection", ".", "each_pair", "do", "|", "sop_uid", ",", "items", "|", "Slice", ".", "create_from_items", "(", "sop_uid", ",", "items", ",", "self", ")", "end", "end" ]
Creates Slice instances from the contour sequence items of the contour sequence, and connects these slices to this ROI instance. @param [DICOM::Sequence] contour_sequence a Contour Sequence
[ "Creates", "Slice", "instances", "from", "the", "contour", "sequence", "items", "of", "the", "contour", "sequence", "and", "connects", "these", "slices", "to", "this", "ROI", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/roi.rb#L143-L156
22,953
dicom/rtkit
lib/rtkit/roi.rb
RTKIT.ROI.distribution
def distribution([email protected]_dose.sum) raise ArgumentError, "Invalid argument 'dose_volume'. Expected DoseVolume, got #{dose_volume.class}." unless dose_volume.is_a?(DoseVolume) raise ArgumentError, "Invalid argument 'dose_volume'. The specified DoseVolume does not belong to this ROI's StructureSet." unless dose_volume.dose_series.plan.struct == @struct # Extract a binary volume from the ROI, based on the dose data: bin_vol = bin_volume(dose_volume) # Create a DoseDistribution from the BinVolume: dose_distribution = DoseDistribution.create(bin_vol) return dose_distribution end
ruby
def distribution([email protected]_dose.sum) raise ArgumentError, "Invalid argument 'dose_volume'. Expected DoseVolume, got #{dose_volume.class}." unless dose_volume.is_a?(DoseVolume) raise ArgumentError, "Invalid argument 'dose_volume'. The specified DoseVolume does not belong to this ROI's StructureSet." unless dose_volume.dose_series.plan.struct == @struct # Extract a binary volume from the ROI, based on the dose data: bin_vol = bin_volume(dose_volume) # Create a DoseDistribution from the BinVolume: dose_distribution = DoseDistribution.create(bin_vol) return dose_distribution end
[ "def", "distribution", "(", "dose_volume", "=", "@struct", ".", "plan", ".", "rt_dose", ".", "sum", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'dose_volume'. Expected DoseVolume, got #{dose_volume.class}.\"", "unless", "dose_volume", ".", "is_a?", "(", "DoseVolume", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'dose_volume'. The specified DoseVolume does not belong to this ROI's StructureSet.\"", "unless", "dose_volume", ".", "dose_series", ".", "plan", ".", "struct", "==", "@struct", "# Extract a binary volume from the ROI, based on the dose data:", "bin_vol", "=", "bin_volume", "(", "dose_volume", ")", "# Create a DoseDistribution from the BinVolume:", "dose_distribution", "=", "DoseDistribution", ".", "create", "(", "bin_vol", ")", "return", "dose_distribution", "end" ]
Creates a DoseDistribution based on the delineation by this ROI in the specified RTDose series. @param [DoseVolume] dose_volume the dose volume to extract the dose distribution from (defaults to the sum of the dose volumes of the first RTDose of the first plan of the parent StructureSet) @raise [ArgumentError] if given a dose volume who's plan does not belong to this ROI's structure set
[ "Creates", "a", "DoseDistribution", "based", "on", "the", "delineation", "by", "this", "ROI", "in", "the", "specified", "RTDose", "series", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/roi.rb#L164-L172
22,954
dicom/rtkit
lib/rtkit/roi.rb
RTKIT.ROI.translate
def translate(x, y, z) @slices.each do |s| s.translate(x, y, z) end end
ruby
def translate(x, y, z) @slices.each do |s| s.translate(x, y, z) end end
[ "def", "translate", "(", "x", ",", "y", ",", "z", ")", "@slices", ".", "each", "do", "|", "s", "|", "s", ".", "translate", "(", "x", ",", "y", ",", "z", ")", "end", "end" ]
Moves the ROI by applying the given offset vector to its coordinates. @param [Float] x the offset along the x axis (in units of mm) @param [Float] y the offset along the y axis (in units of mm) @param [Float] z the offset along the z axis (in units of mm)
[ "Moves", "the", "ROI", "by", "applying", "the", "given", "offset", "vector", "to", "its", "coordinates", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/roi.rb#L314-L318
22,955
slagyr/limelight
ruby/lib/limelight/pen.rb
Limelight.Pen.smooth=
def smooth=(value) hint = value ? java.awt.RenderingHints::VALUE_ANTIALIAS_ON : java.awt.RenderingHints::VALUE_ANTIALIAS_OFF @context.setRenderingHint(java.awt.RenderingHints::KEY_ANTIALIASING, hint) end
ruby
def smooth=(value) hint = value ? java.awt.RenderingHints::VALUE_ANTIALIAS_ON : java.awt.RenderingHints::VALUE_ANTIALIAS_OFF @context.setRenderingHint(java.awt.RenderingHints::KEY_ANTIALIASING, hint) end
[ "def", "smooth", "=", "(", "value", ")", "hint", "=", "value", "?", "java", ".", "awt", ".", "RenderingHints", "::", "VALUE_ANTIALIAS_ON", ":", "java", ".", "awt", ".", "RenderingHints", "::", "VALUE_ANTIALIAS_OFF", "@context", ".", "setRenderingHint", "(", "java", ".", "awt", ".", "RenderingHints", "::", "KEY_ANTIALIASING", ",", "hint", ")", "end" ]
Specifies whether the pen will use anti-aliasing to draw smooth shapes or not. Shapes will appear pixilated when smooth is set to false.
[ "Specifies", "whether", "the", "pen", "will", "use", "anti", "-", "aliasing", "to", "draw", "smooth", "shapes", "or", "not", ".", "Shapes", "will", "appear", "pixilated", "when", "smooth", "is", "set", "to", "false", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/pen.rb#L45-L48
22,956
slagyr/limelight
ruby/lib/limelight/pen.rb
Limelight.Pen.fill_oval
def fill_oval(x, y, width, height) @context.fillOval(x, y, width, height) end
ruby
def fill_oval(x, y, width, height) @context.fillOval(x, y, width, height) end
[ "def", "fill_oval", "(", "x", ",", "y", ",", "width", ",", "height", ")", "@context", ".", "fillOval", "(", "x", ",", "y", ",", "width", ",", "height", ")", "end" ]
Fills an oval specified by the bounding rectangle. See draw_oval.
[ "Fills", "an", "oval", "specified", "by", "the", "bounding", "rectangle", ".", "See", "draw_oval", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/pen.rb#L77-L79
22,957
dicom/rtkit
lib/rtkit/image.rb
RTKIT.Image.draw_lines
def draw_lines(column_indices, row_indices, image, value) raise ArgumentError, "Invalid argument 'column_indices'. Expected Array, got #{column_indices.class}." unless column_indices.is_a?(Array) raise ArgumentError, "Invalid argument 'row_indices'. Expected Array, got #{row_indices.class}." unless row_indices.is_a?(Array) raise ArgumentError, "Invalid arguments. Expected Arrays of equal length, got #{column_indices.length}, #{row_indices.length}." unless column_indices.length == row_indices.length raise ArgumentError, "Invalid argument 'image'. Expected NArray, got #{image.class}." unless image.is_a?(NArray) raise ArgumentError, "Invalid number of dimensions for argument 'image'. Expected 2, got #{image.shape.length}." unless image.shape.length == 2 raise ArgumentError, "Invalid argument 'value'. Expected Integer, got #{value.class}." unless value.is_a?(Integer) column_indices.each_index do |i| image = draw_line(column_indices[i-1], column_indices[i], row_indices[i-1], row_indices[i], image, value) end return image end
ruby
def draw_lines(column_indices, row_indices, image, value) raise ArgumentError, "Invalid argument 'column_indices'. Expected Array, got #{column_indices.class}." unless column_indices.is_a?(Array) raise ArgumentError, "Invalid argument 'row_indices'. Expected Array, got #{row_indices.class}." unless row_indices.is_a?(Array) raise ArgumentError, "Invalid arguments. Expected Arrays of equal length, got #{column_indices.length}, #{row_indices.length}." unless column_indices.length == row_indices.length raise ArgumentError, "Invalid argument 'image'. Expected NArray, got #{image.class}." unless image.is_a?(NArray) raise ArgumentError, "Invalid number of dimensions for argument 'image'. Expected 2, got #{image.shape.length}." unless image.shape.length == 2 raise ArgumentError, "Invalid argument 'value'. Expected Integer, got #{value.class}." unless value.is_a?(Integer) column_indices.each_index do |i| image = draw_line(column_indices[i-1], column_indices[i], row_indices[i-1], row_indices[i], image, value) end return image end
[ "def", "draw_lines", "(", "column_indices", ",", "row_indices", ",", "image", ",", "value", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'column_indices'. Expected Array, got #{column_indices.class}.\"", "unless", "column_indices", ".", "is_a?", "(", "Array", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'row_indices'. Expected Array, got #{row_indices.class}.\"", "unless", "row_indices", ".", "is_a?", "(", "Array", ")", "raise", "ArgumentError", ",", "\"Invalid arguments. Expected Arrays of equal length, got #{column_indices.length}, #{row_indices.length}.\"", "unless", "column_indices", ".", "length", "==", "row_indices", ".", "length", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected NArray, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "NArray", ")", "raise", "ArgumentError", ",", "\"Invalid number of dimensions for argument 'image'. Expected 2, got #{image.shape.length}.\"", "unless", "image", ".", "shape", ".", "length", "==", "2", "raise", "ArgumentError", ",", "\"Invalid argument 'value'. Expected Integer, got #{value.class}.\"", "unless", "value", ".", "is_a?", "(", "Integer", ")", "column_indices", ".", "each_index", "do", "|", "i", "|", "image", "=", "draw_line", "(", "column_indices", "[", "i", "-", "1", "]", ",", "column_indices", "[", "i", "]", ",", "row_indices", "[", "i", "-", "1", "]", ",", "row_indices", "[", "i", "]", ",", "image", ",", "value", ")", "end", "return", "image", "end" ]
Fills the provided pixel array with lines of a specified value, based on two vectors of column and row indices. @param [Array] column_indices an array (vector) of pixel column indices @param [Array] row_indices an array (vector) of pixel row indices @param [NArray] image a two-dimensional numerical pixel array @param [Integer] value the value used for marking pixel lines @raise if there are any discrepancies among the provided image parameters @return [NArray] a pixel array marked with lines
[ "Fills", "the", "provided", "pixel", "array", "with", "lines", "of", "a", "specified", "value", "based", "on", "two", "vectors", "of", "column", "and", "row", "indices", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image.rb#L175-L186
22,958
dicom/rtkit
lib/rtkit/image.rb
RTKIT.Image.extract_pixels
def extract_pixels(x_coords, y_coords, z_coords) # FIXME: This method (along with some other methods in this class, doesn't # actually work for a pure Image instance. This should probably be # refactored (mix-in module instead more appropriate?) # Get image indices (nearest neighbour): column_indices, row_indices = coordinates_to_indices(x_coords, y_coords, z_coords) # Convert from vector indices to array indices: indices = indices_specific_to_general(column_indices, row_indices) # Use the determined image indices to extract corresponding pixel values: return @narray[indices].to_a.flatten end
ruby
def extract_pixels(x_coords, y_coords, z_coords) # FIXME: This method (along with some other methods in this class, doesn't # actually work for a pure Image instance. This should probably be # refactored (mix-in module instead more appropriate?) # Get image indices (nearest neighbour): column_indices, row_indices = coordinates_to_indices(x_coords, y_coords, z_coords) # Convert from vector indices to array indices: indices = indices_specific_to_general(column_indices, row_indices) # Use the determined image indices to extract corresponding pixel values: return @narray[indices].to_a.flatten end
[ "def", "extract_pixels", "(", "x_coords", ",", "y_coords", ",", "z_coords", ")", "# FIXME: This method (along with some other methods in this class, doesn't", "# actually work for a pure Image instance. This should probably be", "# refactored (mix-in module instead more appropriate?)", "# Get image indices (nearest neighbour):", "column_indices", ",", "row_indices", "=", "coordinates_to_indices", "(", "x_coords", ",", "y_coords", ",", "z_coords", ")", "# Convert from vector indices to array indices:", "indices", "=", "indices_specific_to_general", "(", "column_indices", ",", "row_indices", ")", "# Use the determined image indices to extract corresponding pixel values:", "return", "@narray", "[", "indices", "]", ".", "to_a", ".", "flatten", "end" ]
Extracts pixels based on cartesian coordinate arrays. @note No interpolation is performed in the case of a given coordinate being located between pixel indices. In these cases a basic nearest neighbour algorithm is used. @param [NArray] x_coords a numerical array (vector) of pixel x coordinates @param [NArray] y_coords a numerical array (vector) of pixel y coordinates @param [NArray] z_coords a numerical array (vector) of pixel z coordinates @return [Array] the matched pixel values
[ "Extracts", "pixels", "based", "on", "cartesian", "coordinate", "arrays", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image.rb#L199-L209
22,959
dicom/rtkit
lib/rtkit/image.rb
RTKIT.Image.flood_fill
def flood_fill(col, row, image, fill_value) # If the given starting point is out of bounds, put it at the array boundary: col = col > image.shape[0] ? -1 : col row = row > image.shape[1] ? -1 : row existing_value = image[col, row] queue = Array.new queue.push([col, row]) until queue.empty? col, row = queue.shift if image[col, row] == existing_value west_col, west_row = ff_find_border(col, row, existing_value, :west, image) east_col, east_row = ff_find_border(col, row, existing_value, :east, image) # Fill the line between the two border pixels (i.e. not touching the border pixels): image[west_col..east_col, row] = fill_value q = west_col while q <= east_col [:north, :south].each do |direction| same_col, next_row = ff_neighbour(q, row, direction) begin queue.push([q, next_row]) if image[q, next_row] == existing_value rescue # Out of bounds. Do nothing. end end q, same_row = ff_neighbour(q, row, :east) end end end return image end
ruby
def flood_fill(col, row, image, fill_value) # If the given starting point is out of bounds, put it at the array boundary: col = col > image.shape[0] ? -1 : col row = row > image.shape[1] ? -1 : row existing_value = image[col, row] queue = Array.new queue.push([col, row]) until queue.empty? col, row = queue.shift if image[col, row] == existing_value west_col, west_row = ff_find_border(col, row, existing_value, :west, image) east_col, east_row = ff_find_border(col, row, existing_value, :east, image) # Fill the line between the two border pixels (i.e. not touching the border pixels): image[west_col..east_col, row] = fill_value q = west_col while q <= east_col [:north, :south].each do |direction| same_col, next_row = ff_neighbour(q, row, direction) begin queue.push([q, next_row]) if image[q, next_row] == existing_value rescue # Out of bounds. Do nothing. end end q, same_row = ff_neighbour(q, row, :east) end end end return image end
[ "def", "flood_fill", "(", "col", ",", "row", ",", "image", ",", "fill_value", ")", "# If the given starting point is out of bounds, put it at the array boundary:", "col", "=", "col", ">", "image", ".", "shape", "[", "0", "]", "?", "-", "1", ":", "col", "row", "=", "row", ">", "image", ".", "shape", "[", "1", "]", "?", "-", "1", ":", "row", "existing_value", "=", "image", "[", "col", ",", "row", "]", "queue", "=", "Array", ".", "new", "queue", ".", "push", "(", "[", "col", ",", "row", "]", ")", "until", "queue", ".", "empty?", "col", ",", "row", "=", "queue", ".", "shift", "if", "image", "[", "col", ",", "row", "]", "==", "existing_value", "west_col", ",", "west_row", "=", "ff_find_border", "(", "col", ",", "row", ",", "existing_value", ",", ":west", ",", "image", ")", "east_col", ",", "east_row", "=", "ff_find_border", "(", "col", ",", "row", ",", "existing_value", ",", ":east", ",", "image", ")", "# Fill the line between the two border pixels (i.e. not touching the border pixels):", "image", "[", "west_col", "..", "east_col", ",", "row", "]", "=", "fill_value", "q", "=", "west_col", "while", "q", "<=", "east_col", "[", ":north", ",", ":south", "]", ".", "each", "do", "|", "direction", "|", "same_col", ",", "next_row", "=", "ff_neighbour", "(", "q", ",", "row", ",", "direction", ")", "begin", "queue", ".", "push", "(", "[", "q", ",", "next_row", "]", ")", "if", "image", "[", "q", ",", "next_row", "]", "==", "existing_value", "rescue", "# Out of bounds. Do nothing.", "end", "end", "q", ",", "same_row", "=", "ff_neighbour", "(", "q", ",", "row", ",", ":east", ")", "end", "end", "end", "return", "image", "end" ]
Replaces all pixels of a specific value that are contained by pixels of a different value. Uses an iterative, queue based flood fill algorithm. It seems that a recursive method is not suited for Ruby, due to its limited stack space (which is known to be a problem in general for scripting languages). @param [Integer] col the starting column index @param [Integer] row the starting row index @param [NArray] image a two-dimensional numerical pixel array @param [Integer] fill_value the value used for marking pixels @return [NArray] a marked pixel array
[ "Replaces", "all", "pixels", "of", "a", "specific", "value", "that", "are", "contained", "by", "pixels", "of", "a", "different", "value", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image.rb#L224-L253
22,960
dicom/rtkit
lib/rtkit/image.rb
RTKIT.Image.print_img
def print_img(narr=@narray) puts "Image dimensions: #{@columns}*#{@rows}" narr.shape[0].times do |i| puts narr[true, i].to_a.to_s end end
ruby
def print_img(narr=@narray) puts "Image dimensions: #{@columns}*#{@rows}" narr.shape[0].times do |i| puts narr[true, i].to_a.to_s end end
[ "def", "print_img", "(", "narr", "=", "@narray", ")", "puts", "\"Image dimensions: #{@columns}*#{@rows}\"", "narr", ".", "shape", "[", "0", "]", ".", "times", "do", "|", "i", "|", "puts", "narr", "[", "true", ",", "i", "]", ".", "to_a", ".", "to_s", "end", "end" ]
A convenience method for printing image information. @deprecated NB! This has been used only for debugging, and will soon be removed. @param [NArray] narr a numerical array
[ "A", "convenience", "method", "for", "printing", "image", "information", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image.rb#L368-L373
22,961
dicom/rtkit
lib/rtkit/image.rb
RTKIT.Image.create_general_dicom_image_scaffold
def create_general_dicom_image_scaffold # Some tags are created/updated only if no DICOM object already exists: unless @dcm @dcm = DICOM::DObject.new # Group 0008: @dcm.add_element(SPECIFIC_CHARACTER_SET, 'ISO_IR 100') @dcm.add_element(IMAGE_TYPE, 'DERIVED\SECONDARY\DRR') @dcm.add_element(ACCESSION_NUMBER, '') @dcm.add_element(MODALITY, @series.modality) @dcm.add_element(CONVERSION_TYPE, 'SYN') # or WSD? @dcm.add_element(MANUFACTURER, 'RTKIT') @dcm.add_element(TIMEZONE_OFFSET_FROM_UTC, Time.now.strftime('%z')) @dcm.add_element(MANUFACTURERS_MODEL_NAME, "RTKIT_#{VERSION}") # Group 0018: @dcm.add_element(SOFTWARE_VERSION, "RTKIT_#{VERSION}") # Group 0020: # FIXME: We're missing Instance Number (0020,0013) at the moment. # Group 0028: @dcm.add_element(SAMPLES_PER_PIXEL, '1') @dcm.add_element(PHOTOMETRIC_INTERPRETATION, 'MONOCHROME2') @dcm.add_element(BITS_ALLOCATED, 16) @dcm.add_element(BITS_STORED, 16) @dcm.add_element(HIGH_BIT, 15) @dcm.add_element(PIXEL_REPRESENTATION, 0) @dcm.add_element(WINDOW_CENTER, '2048') @dcm.add_element(WINDOW_WIDTH, '4096') end end
ruby
def create_general_dicom_image_scaffold # Some tags are created/updated only if no DICOM object already exists: unless @dcm @dcm = DICOM::DObject.new # Group 0008: @dcm.add_element(SPECIFIC_CHARACTER_SET, 'ISO_IR 100') @dcm.add_element(IMAGE_TYPE, 'DERIVED\SECONDARY\DRR') @dcm.add_element(ACCESSION_NUMBER, '') @dcm.add_element(MODALITY, @series.modality) @dcm.add_element(CONVERSION_TYPE, 'SYN') # or WSD? @dcm.add_element(MANUFACTURER, 'RTKIT') @dcm.add_element(TIMEZONE_OFFSET_FROM_UTC, Time.now.strftime('%z')) @dcm.add_element(MANUFACTURERS_MODEL_NAME, "RTKIT_#{VERSION}") # Group 0018: @dcm.add_element(SOFTWARE_VERSION, "RTKIT_#{VERSION}") # Group 0020: # FIXME: We're missing Instance Number (0020,0013) at the moment. # Group 0028: @dcm.add_element(SAMPLES_PER_PIXEL, '1') @dcm.add_element(PHOTOMETRIC_INTERPRETATION, 'MONOCHROME2') @dcm.add_element(BITS_ALLOCATED, 16) @dcm.add_element(BITS_STORED, 16) @dcm.add_element(HIGH_BIT, 15) @dcm.add_element(PIXEL_REPRESENTATION, 0) @dcm.add_element(WINDOW_CENTER, '2048') @dcm.add_element(WINDOW_WIDTH, '4096') end end
[ "def", "create_general_dicom_image_scaffold", "# Some tags are created/updated only if no DICOM object already exists:", "unless", "@dcm", "@dcm", "=", "DICOM", "::", "DObject", ".", "new", "# Group 0008:", "@dcm", ".", "add_element", "(", "SPECIFIC_CHARACTER_SET", ",", "'ISO_IR 100'", ")", "@dcm", ".", "add_element", "(", "IMAGE_TYPE", ",", "'DERIVED\\SECONDARY\\DRR'", ")", "@dcm", ".", "add_element", "(", "ACCESSION_NUMBER", ",", "''", ")", "@dcm", ".", "add_element", "(", "MODALITY", ",", "@series", ".", "modality", ")", "@dcm", ".", "add_element", "(", "CONVERSION_TYPE", ",", "'SYN'", ")", "# or WSD?", "@dcm", ".", "add_element", "(", "MANUFACTURER", ",", "'RTKIT'", ")", "@dcm", ".", "add_element", "(", "TIMEZONE_OFFSET_FROM_UTC", ",", "Time", ".", "now", ".", "strftime", "(", "'%z'", ")", ")", "@dcm", ".", "add_element", "(", "MANUFACTURERS_MODEL_NAME", ",", "\"RTKIT_#{VERSION}\"", ")", "# Group 0018:", "@dcm", ".", "add_element", "(", "SOFTWARE_VERSION", ",", "\"RTKIT_#{VERSION}\"", ")", "# Group 0020:", "# FIXME: We're missing Instance Number (0020,0013) at the moment.", "# Group 0028:", "@dcm", ".", "add_element", "(", "SAMPLES_PER_PIXEL", ",", "'1'", ")", "@dcm", ".", "add_element", "(", "PHOTOMETRIC_INTERPRETATION", ",", "'MONOCHROME2'", ")", "@dcm", ".", "add_element", "(", "BITS_ALLOCATED", ",", "16", ")", "@dcm", ".", "add_element", "(", "BITS_STORED", ",", "16", ")", "@dcm", ".", "add_element", "(", "HIGH_BIT", ",", "15", ")", "@dcm", ".", "add_element", "(", "PIXEL_REPRESENTATION", ",", "0", ")", "@dcm", ".", "add_element", "(", "WINDOW_CENTER", ",", "'2048'", ")", "@dcm", ".", "add_element", "(", "WINDOW_WIDTH", ",", "'4096'", ")", "end", "end" ]
Creates a new DICOM object with a set of basic attributes needed for a valid DICOM image file.
[ "Creates", "a", "new", "DICOM", "object", "with", "a", "set", "of", "basic", "attributes", "needed", "for", "a", "valid", "DICOM", "image", "file", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image.rb#L500-L527
22,962
dicom/rtkit
lib/rtkit/image.rb
RTKIT.Image.update_dicom_image
def update_dicom_image # General image attributes: @dcm.add_element(IMAGE_DATE, @date) @dcm.add_element(IMAGE_TIME, @time) @dcm.add_element(SOP_UID, @uid) @dcm.add_element(COLUMNS, @columns) @dcm.add_element(ROWS, @rows) # Pixel data: @dcm.pixels = @narray # Higher level tags (patient, study, frame, series): # (Groups 0008, 0010 & 0020) @series.add_attributes_to_dcm(dcm) end
ruby
def update_dicom_image # General image attributes: @dcm.add_element(IMAGE_DATE, @date) @dcm.add_element(IMAGE_TIME, @time) @dcm.add_element(SOP_UID, @uid) @dcm.add_element(COLUMNS, @columns) @dcm.add_element(ROWS, @rows) # Pixel data: @dcm.pixels = @narray # Higher level tags (patient, study, frame, series): # (Groups 0008, 0010 & 0020) @series.add_attributes_to_dcm(dcm) end
[ "def", "update_dicom_image", "# General image attributes:", "@dcm", ".", "add_element", "(", "IMAGE_DATE", ",", "@date", ")", "@dcm", ".", "add_element", "(", "IMAGE_TIME", ",", "@time", ")", "@dcm", ".", "add_element", "(", "SOP_UID", ",", "@uid", ")", "@dcm", ".", "add_element", "(", "COLUMNS", ",", "@columns", ")", "@dcm", ".", "add_element", "(", "ROWS", ",", "@rows", ")", "# Pixel data:", "@dcm", ".", "pixels", "=", "@narray", "# Higher level tags (patient, study, frame, series):", "# (Groups 0008, 0010 & 0020)", "@series", ".", "add_attributes_to_dcm", "(", "dcm", ")", "end" ]
Creates a new DICOM object with a set of basic attributes needed for a valid DICOM file of slice type image modality.
[ "Creates", "a", "new", "DICOM", "object", "with", "a", "set", "of", "basic", "attributes", "needed", "for", "a", "valid", "DICOM", "file", "of", "slice", "type", "image", "modality", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image.rb#L641-L653
22,963
dicom/rtkit
lib/rtkit/rt_dose.rb
RTKIT.RTDose.add_volume
def add_volume(volume) raise ArgumentError, "Invalid argument 'volume'. Expected DoseVolume, got #{volume.class}." unless volume.is_a?(DoseVolume) @volumes << volume unless @associated_volumes[volume.uid] @associated_volumes[volume.uid] = volume end
ruby
def add_volume(volume) raise ArgumentError, "Invalid argument 'volume'. Expected DoseVolume, got #{volume.class}." unless volume.is_a?(DoseVolume) @volumes << volume unless @associated_volumes[volume.uid] @associated_volumes[volume.uid] = volume end
[ "def", "add_volume", "(", "volume", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'volume'. Expected DoseVolume, got #{volume.class}.\"", "unless", "volume", ".", "is_a?", "(", "DoseVolume", ")", "@volumes", "<<", "volume", "unless", "@associated_volumes", "[", "volume", ".", "uid", "]", "@associated_volumes", "[", "volume", ".", "uid", "]", "=", "volume", "end" ]
Adds a DoseVolume instance to this RTDose series. @param [DoseVolume] volume a dose volume instance to be associated with this RTDose
[ "Adds", "a", "DoseVolume", "instance", "to", "this", "RTDose", "series", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/rt_dose.rb#L141-L145
22,964
dicom/rtkit
lib/rtkit/plan.rb
RTKIT.Plan.add_beam
def add_beam(beam) raise ArgumentError, "Invalid argument 'beam'. Expected Beam, got #{beam.class}." unless beam.is_a?(Beam) @beams << beam unless @beams.include?(beam) end
ruby
def add_beam(beam) raise ArgumentError, "Invalid argument 'beam'. Expected Beam, got #{beam.class}." unless beam.is_a?(Beam) @beams << beam unless @beams.include?(beam) end
[ "def", "add_beam", "(", "beam", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'beam'. Expected Beam, got #{beam.class}.\"", "unless", "beam", ".", "is_a?", "(", "Beam", ")", "@beams", "<<", "beam", "unless", "@beams", ".", "include?", "(", "beam", ")", "end" ]
Adds a Beam to this Plan. @param [Beam] beam a beam instance to be associated with this plan
[ "Adds", "a", "Beam", "to", "this", "Plan", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/plan.rb#L167-L170
22,965
dicom/rtkit
lib/rtkit/plan.rb
RTKIT.Plan.add_rt_dose
def add_rt_dose(rt_dose) raise ArgumentError, "Invalid argument 'rt_dose'. Expected RTDose, got #{rt_dose.class}." unless rt_dose.is_a?(RTDose) @rt_doses << rt_dose unless @associated_rt_doses[rt_dose.uid] @associated_rt_doses[rt_dose.uid] = rt_dose end
ruby
def add_rt_dose(rt_dose) raise ArgumentError, "Invalid argument 'rt_dose'. Expected RTDose, got #{rt_dose.class}." unless rt_dose.is_a?(RTDose) @rt_doses << rt_dose unless @associated_rt_doses[rt_dose.uid] @associated_rt_doses[rt_dose.uid] = rt_dose end
[ "def", "add_rt_dose", "(", "rt_dose", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'rt_dose'. Expected RTDose, got #{rt_dose.class}.\"", "unless", "rt_dose", ".", "is_a?", "(", "RTDose", ")", "@rt_doses", "<<", "rt_dose", "unless", "@associated_rt_doses", "[", "rt_dose", ".", "uid", "]", "@associated_rt_doses", "[", "rt_dose", ".", "uid", "]", "=", "rt_dose", "end" ]
Adds a RTDose series to this Plan. @param [RTDose] rt_dose an RTDose instance to be associated with this plan
[ "Adds", "a", "RTDose", "series", "to", "this", "Plan", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/plan.rb#L176-L180
22,966
dicom/rtkit
lib/rtkit/plan.rb
RTKIT.Plan.add_rt_image
def add_rt_image(rt_image) raise ArgumentError, "Invalid argument 'rt_image'. Expected RTImage, got #{rt_image.class}." unless rt_image.is_a?(RTImage) @rt_images << rt_image unless @rt_images.include?(rt_image) end
ruby
def add_rt_image(rt_image) raise ArgumentError, "Invalid argument 'rt_image'. Expected RTImage, got #{rt_image.class}." unless rt_image.is_a?(RTImage) @rt_images << rt_image unless @rt_images.include?(rt_image) end
[ "def", "add_rt_image", "(", "rt_image", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'rt_image'. Expected RTImage, got #{rt_image.class}.\"", "unless", "rt_image", ".", "is_a?", "(", "RTImage", ")", "@rt_images", "<<", "rt_image", "unless", "@rt_images", ".", "include?", "(", "rt_image", ")", "end" ]
Adds a RTImage Series to this Plan. @param [RTImage] rt_image an RTImage instance to be associated with this plan
[ "Adds", "a", "RTImage", "Series", "to", "this", "Plan", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/plan.rb#L186-L189
22,967
dicom/rtkit
lib/rtkit/beam.rb
RTKIT.Beam.add_collimator
def add_collimator(coll) raise ArgumentError, "Invalid argument 'coll'. Expected Collimator, got #{coll.class}." unless coll.is_a?(Collimator) @collimators << coll unless @associated_collimators[coll.type] @associated_collimators[coll.type] = coll end
ruby
def add_collimator(coll) raise ArgumentError, "Invalid argument 'coll'. Expected Collimator, got #{coll.class}." unless coll.is_a?(Collimator) @collimators << coll unless @associated_collimators[coll.type] @associated_collimators[coll.type] = coll end
[ "def", "add_collimator", "(", "coll", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'coll'. Expected Collimator, got #{coll.class}.\"", "unless", "coll", ".", "is_a?", "(", "Collimator", ")", "@collimators", "<<", "coll", "unless", "@associated_collimators", "[", "coll", ".", "type", "]", "@associated_collimators", "[", "coll", ".", "type", "]", "=", "coll", "end" ]
Adds a Collimator instance to this Beam. @param [Collimator] coll a collimator instance to be associated with this beam
[ "Adds", "a", "Collimator", "instance", "to", "this", "Beam", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/beam.rb#L136-L140
22,968
dicom/rtkit
lib/rtkit/beam.rb
RTKIT.Beam.add_control_point
def add_control_point(cp) raise ArgumentError, "Invalid argument 'cp'. Expected ControlPoint, got #{cp.class}." unless cp.is_a?(ControlPoint) @control_points << cp unless @associated_control_points[cp] @associated_control_points[cp] = true end
ruby
def add_control_point(cp) raise ArgumentError, "Invalid argument 'cp'. Expected ControlPoint, got #{cp.class}." unless cp.is_a?(ControlPoint) @control_points << cp unless @associated_control_points[cp] @associated_control_points[cp] = true end
[ "def", "add_control_point", "(", "cp", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'cp'. Expected ControlPoint, got #{cp.class}.\"", "unless", "cp", ".", "is_a?", "(", "ControlPoint", ")", "@control_points", "<<", "cp", "unless", "@associated_control_points", "[", "cp", "]", "@associated_control_points", "[", "cp", "]", "=", "true", "end" ]
Adds a ControlPoint instance to this Beam. @param [ControlPoint] cp a control point instance to be associated with this beam
[ "Adds", "a", "ControlPoint", "instance", "to", "this", "Beam", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/beam.rb#L146-L150
22,969
dicom/rtkit
lib/rtkit/beam.rb
RTKIT.Beam.beam_item
def beam_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
ruby
def beam_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
[ "def", "beam_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" ]
Creates a Beam Sequence Item from the attributes of the Beam instance. @return [DICOM::Item] a beam sequence item
[ "Creates", "a", "Beam", "Sequence", "Item", "from", "the", "attributes", "of", "the", "Beam", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/beam.rb#L156-L169
22,970
dicom/rtkit
lib/rtkit/beam.rb
RTKIT.Beam.control_point
def control_point(*args) raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length) if args.length == 1 raise ArgumentError, "Invalid argument 'index'. Expected Integer (or nil), got #{args.first.class}." unless [Integer, NilClass].include?(args.first.class) return @associated_control_points[args.first] else # No argument used, therefore we return the first instance: return @control_points.first end end
ruby
def control_point(*args) raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length) if args.length == 1 raise ArgumentError, "Invalid argument 'index'. Expected Integer (or nil), got #{args.first.class}." unless [Integer, NilClass].include?(args.first.class) return @associated_control_points[args.first] else # No argument used, therefore we return the first instance: return @control_points.first end end
[ "def", "control_point", "(", "*", "args", ")", "raise", "ArgumentError", ",", "\"Expected one or none arguments, got #{args.length}.\"", "unless", "[", "0", ",", "1", "]", ".", "include?", "(", "args", ".", "length", ")", "if", "args", ".", "length", "==", "1", "raise", "ArgumentError", ",", "\"Invalid argument 'index'. Expected Integer (or nil), got #{args.first.class}.\"", "unless", "[", "Integer", ",", "NilClass", "]", ".", "include?", "(", "args", ".", "first", ".", "class", ")", "return", "@associated_control_points", "[", "args", ".", "first", "]", "else", "# No argument used, therefore we return the first instance:", "return", "@control_points", ".", "first", "end", "end" ]
Gives the ControlPoint instance mathcing the specified index. @overload control_point(index) @param [String] index the control_point index @return [ControlPoint, NilClass] the matched control_point (or nil if no control_point is matched) @overload control_point @return [ControlPoint, NilClass] the first control_point of this instance (or nil if no child control points exists)
[ "Gives", "the", "ControlPoint", "instance", "mathcing", "the", "specified", "index", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/beam.rb#L197-L206
22,971
dicom/rtkit
lib/rtkit/beam.rb
RTKIT.Beam.ref_beam_item
def ref_beam_item item = DICOM::Item.new item.add(DICOM::Element.new(OBS_NUMBER, @number.to_s)) item.add(DICOM::Element.new(REF_ROI_NUMBER, @number.to_s)) item.add(DICOM::Element.new(ROI_TYPE, @type)) item.add(DICOM::Element.new(ROI_INTERPRETER, @interpreter)) return item end
ruby
def ref_beam_item item = DICOM::Item.new item.add(DICOM::Element.new(OBS_NUMBER, @number.to_s)) item.add(DICOM::Element.new(REF_ROI_NUMBER, @number.to_s)) item.add(DICOM::Element.new(ROI_TYPE, @type)) item.add(DICOM::Element.new(ROI_INTERPRETER, @interpreter)) return item end
[ "def", "ref_beam_item", "item", "=", "DICOM", "::", "Item", ".", "new", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "OBS_NUMBER", ",", "@number", ".", "to_s", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "REF_ROI_NUMBER", ",", "@number", ".", "to_s", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "ROI_TYPE", ",", "@type", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "ROI_INTERPRETER", ",", "@interpreter", ")", ")", "return", "item", "end" ]
Creates a Referenced Beam Sequence Item from the attributes of the Beam instance. @return [DICOM::Item] a referenced beam sequence item
[ "Creates", "a", "Referenced", "Beam", "Sequence", "Item", "from", "the", "attributes", "of", "the", "Beam", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/beam.rb#L339-L346
22,972
dicom/rtkit
lib/rtkit/mixins/image_parent.rb
RTKIT.ImageParent.to_voxel_space
def to_voxel_space raise "This image series has no associated images. Unable to create a VoxelSpace." unless @images.length > 0 img = @images.first # Create the voxel space: vs = VoxelSpace.create(img.columns, img.rows, @images.length, img.col_spacing, img.row_spacing, slice_spacing, Coordinate.new(img.pos_x, img.pos_y, img.pos_slice)) # Fill it with pixel values: @images.each_with_index do |image, i| vs[true, true, i] = image.narray end vs end
ruby
def to_voxel_space raise "This image series has no associated images. Unable to create a VoxelSpace." unless @images.length > 0 img = @images.first # Create the voxel space: vs = VoxelSpace.create(img.columns, img.rows, @images.length, img.col_spacing, img.row_spacing, slice_spacing, Coordinate.new(img.pos_x, img.pos_y, img.pos_slice)) # Fill it with pixel values: @images.each_with_index do |image, i| vs[true, true, i] = image.narray end vs end
[ "def", "to_voxel_space", "raise", "\"This image series has no associated images. Unable to create a VoxelSpace.\"", "unless", "@images", ".", "length", ">", "0", "img", "=", "@images", ".", "first", "# Create the voxel space:", "vs", "=", "VoxelSpace", ".", "create", "(", "img", ".", "columns", ",", "img", ".", "rows", ",", "@images", ".", "length", ",", "img", ".", "col_spacing", ",", "img", ".", "row_spacing", ",", "slice_spacing", ",", "Coordinate", ".", "new", "(", "img", ".", "pos_x", ",", "img", ".", "pos_y", ",", "img", ".", "pos_slice", ")", ")", "# Fill it with pixel values:", "@images", ".", "each_with_index", "do", "|", "image", ",", "i", "|", "vs", "[", "true", ",", "true", ",", "i", "]", "=", "image", ".", "narray", "end", "vs", "end" ]
Creates a VoxelSpace instance from the image instances belonging to this image series. @return [VoxelSpace] the created VoxelSpace instance
[ "Creates", "a", "VoxelSpace", "instance", "from", "the", "image", "instances", "belonging", "to", "this", "image", "series", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/mixins/image_parent.rb#L36-L46
22,973
dicom/rtkit
lib/rtkit/mixins/image_parent.rb
RTKIT.ImageParent.update_image_position
def update_image_position(image, new_pos) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) # Remove old position key: @image_positions.delete(image.pos_slice) # Add the new position: @image_positions[new_pos] = image end
ruby
def update_image_position(image, new_pos) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) # Remove old position key: @image_positions.delete(image.pos_slice) # Add the new position: @image_positions[new_pos] = image end
[ "def", "update_image_position", "(", "image", ",", "new_pos", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected Image, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "Image", ")", "# Remove old position key:", "@image_positions", ".", "delete", "(", "image", ".", "pos_slice", ")", "# Add the new position:", "@image_positions", "[", "new_pos", "]", "=", "image", "end" ]
Updates the position that is registered for the image instance for this series. @param [Image] image an instance belonging to this image series @param [Float] new_pos a new slice position to be associated with the image instance
[ "Updates", "the", "position", "that", "is", "registered", "for", "the", "image", "instance", "for", "this", "series", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/mixins/image_parent.rb#L53-L59
22,974
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.add_plan
def add_plan(plan) raise ArgumentError, "Invalid argument 'plan'. Expected Plan, got #{plan.class}." unless plan.is_a?(Plan) @plans << plan unless @associated_plans[plan.uid] @associated_plans[plan.uid] = plan end
ruby
def add_plan(plan) raise ArgumentError, "Invalid argument 'plan'. Expected Plan, got #{plan.class}." unless plan.is_a?(Plan) @plans << plan unless @associated_plans[plan.uid] @associated_plans[plan.uid] = plan end
[ "def", "add_plan", "(", "plan", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'plan'. Expected Plan, got #{plan.class}.\"", "unless", "plan", ".", "is_a?", "(", "Plan", ")", "@plans", "<<", "plan", "unless", "@associated_plans", "[", "plan", ".", "uid", "]", "@associated_plans", "[", "plan", ".", "uid", "]", "=", "plan", "end" ]
Adds a Plan Series to this StructureSet. @param [Plan] plan a plan instance to be associated with this structure set
[ "Adds", "a", "Plan", "Series", "to", "this", "StructureSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L152-L156
22,975
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.add_poi
def add_poi(poi) raise ArgumentError, "Invalid argument 'poi'. Expected POI, got #{poi.class}." unless poi.is_a?(POI) @structures << poi unless @structures.include?(poi) end
ruby
def add_poi(poi) raise ArgumentError, "Invalid argument 'poi'. Expected POI, got #{poi.class}." unless poi.is_a?(POI) @structures << poi unless @structures.include?(poi) end
[ "def", "add_poi", "(", "poi", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'poi'. Expected POI, got #{poi.class}.\"", "unless", "poi", ".", "is_a?", "(", "POI", ")", "@structures", "<<", "poi", "unless", "@structures", ".", "include?", "(", "poi", ")", "end" ]
Adds a POI instance to this StructureSet. @param [POI] poi a poi instance to be associated with this structure set
[ "Adds", "a", "POI", "instance", "to", "this", "StructureSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L162-L165
22,976
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.add_structure
def add_structure(structure) raise ArgumentError, "Invalid argument 'structure'. Expected ROI/POI, got #{structure.class}." unless structure.respond_to?(:to_roi) or structure.respond_to?(:to_poi) @structures << structure unless @structures.include?(structure) end
ruby
def add_structure(structure) raise ArgumentError, "Invalid argument 'structure'. Expected ROI/POI, got #{structure.class}." unless structure.respond_to?(:to_roi) or structure.respond_to?(:to_poi) @structures << structure unless @structures.include?(structure) end
[ "def", "add_structure", "(", "structure", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'structure'. Expected ROI/POI, got #{structure.class}.\"", "unless", "structure", ".", "respond_to?", "(", ":to_roi", ")", "or", "structure", ".", "respond_to?", "(", ":to_poi", ")", "@structures", "<<", "structure", "unless", "@structures", ".", "include?", "(", "structure", ")", "end" ]
Adds a Structure instance to this StructureSet. @param [ROI, POI] structure a Structure to be associated with this StructureSet
[ "Adds", "a", "Structure", "instance", "to", "this", "StructureSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L171-L174
22,977
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.add_roi
def add_roi(roi) raise ArgumentError, "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi.is_a?(ROI) @structures << roi unless @structures.include?(roi) end
ruby
def add_roi(roi) raise ArgumentError, "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi.is_a?(ROI) @structures << roi unless @structures.include?(roi) end
[ "def", "add_roi", "(", "roi", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'roi'. Expected ROI, got #{roi.class}.\"", "unless", "roi", ".", "is_a?", "(", "ROI", ")", "@structures", "<<", "roi", "unless", "@structures", ".", "include?", "(", "roi", ")", "end" ]
Adds a ROI instance to this StructureSet. @param [ROI] roi a roi instance to be associated with this structure set
[ "Adds", "a", "ROI", "instance", "to", "this", "StructureSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L180-L183
22,978
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.create_roi
def create_roi(frame, options={}) raise ArgumentError, "Expected Frame, got #{frame.class}." unless frame.is_a?(Frame) # Set values: algorithm = options[:algorithm] || 'Automatic' name = options[:name] || 'RTKIT-VOLUME' interpreter = options[:interpreter] || 'RTKIT' type = options[:type] || 'CONTROL' if options[:number] raise ArgumentError, "Expected Integer, got #{options[:number].class} for the option :number." unless options[:number].is_a?(Integer) raise ArgumentError, "The specified ROI Number (#{options[:roi_number]}) is already used by one of the existing ROIs (#{roi_numbers})." if structure_numbers.include?(options[:number]) number = options[:number] else number = (structure_numbers.max ? structure_numbers.max + 1 : 1) end # Create ROI: roi = ROI.new(name, number, frame, self, :algorithm => algorithm, :name => name, :number => number, :interpreter => interpreter, :type => type) return roi end
ruby
def create_roi(frame, options={}) raise ArgumentError, "Expected Frame, got #{frame.class}." unless frame.is_a?(Frame) # Set values: algorithm = options[:algorithm] || 'Automatic' name = options[:name] || 'RTKIT-VOLUME' interpreter = options[:interpreter] || 'RTKIT' type = options[:type] || 'CONTROL' if options[:number] raise ArgumentError, "Expected Integer, got #{options[:number].class} for the option :number." unless options[:number].is_a?(Integer) raise ArgumentError, "The specified ROI Number (#{options[:roi_number]}) is already used by one of the existing ROIs (#{roi_numbers})." if structure_numbers.include?(options[:number]) number = options[:number] else number = (structure_numbers.max ? structure_numbers.max + 1 : 1) end # Create ROI: roi = ROI.new(name, number, frame, self, :algorithm => algorithm, :name => name, :number => number, :interpreter => interpreter, :type => type) return roi end
[ "def", "create_roi", "(", "frame", ",", "options", "=", "{", "}", ")", "raise", "ArgumentError", ",", "\"Expected Frame, got #{frame.class}.\"", "unless", "frame", ".", "is_a?", "(", "Frame", ")", "# Set values:", "algorithm", "=", "options", "[", ":algorithm", "]", "||", "'Automatic'", "name", "=", "options", "[", ":name", "]", "||", "'RTKIT-VOLUME'", "interpreter", "=", "options", "[", ":interpreter", "]", "||", "'RTKIT'", "type", "=", "options", "[", ":type", "]", "||", "'CONTROL'", "if", "options", "[", ":number", "]", "raise", "ArgumentError", ",", "\"Expected Integer, got #{options[:number].class} for the option :number.\"", "unless", "options", "[", ":number", "]", ".", "is_a?", "(", "Integer", ")", "raise", "ArgumentError", ",", "\"The specified ROI Number (#{options[:roi_number]}) is already used by one of the existing ROIs (#{roi_numbers}).\"", "if", "structure_numbers", ".", "include?", "(", "options", "[", ":number", "]", ")", "number", "=", "options", "[", ":number", "]", "else", "number", "=", "(", "structure_numbers", ".", "max", "?", "structure_numbers", ".", "max", "+", "1", ":", "1", ")", "end", "# Create ROI:", "roi", "=", "ROI", ".", "new", "(", "name", ",", "number", ",", "frame", ",", "self", ",", ":algorithm", "=>", "algorithm", ",", ":name", "=>", "name", ",", ":number", "=>", "number", ",", ":interpreter", "=>", "interpreter", ",", ":type", "=>", "type", ")", "return", "roi", "end" ]
Creates a ROI belonging to this StructureSet. @note The ROI is created without any Slice instances (these must be added after the ROI creation). @param [Frame] frame the Frame which the ROI is to be associated with @param [Hash] options the options to use for creating the ROI @option options [String] :algorithm the ROI generation algorithm (defaults to 'Automatic') @option options [String] :interpreter the ROI interpreter (defaults to 'RTKIT') @option options [String] :name the ROI name (defaults to 'RTKIT-VOLUME') @option options [String] :number the ROI number (defaults to the first available ROI number in the structure set) @option options [String] :type the ROI interpreted type (defaults to 'CONTROL')
[ "Creates", "a", "ROI", "belonging", "to", "this", "StructureSet", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L198-L215
22,979
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.remove_structure
def remove_structure(instance_or_number) raise ArgumentError, "Invalid argument 'instance_or_number'. Expected a ROI Instance or an Integer (ROI Number). Got #{instance_or_number.class}." unless [ROI, Integer].include?(instance_or_number.class) s_instance = instance_or_number if instance_or_number.is_a?(Integer) s_instance = structure(instance_or_number) end index = @structures.index(s_instance) if index @structures.delete_at(index) s_instance.remove_references end end
ruby
def remove_structure(instance_or_number) raise ArgumentError, "Invalid argument 'instance_or_number'. Expected a ROI Instance or an Integer (ROI Number). Got #{instance_or_number.class}." unless [ROI, Integer].include?(instance_or_number.class) s_instance = instance_or_number if instance_or_number.is_a?(Integer) s_instance = structure(instance_or_number) end index = @structures.index(s_instance) if index @structures.delete_at(index) s_instance.remove_references end end
[ "def", "remove_structure", "(", "instance_or_number", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'instance_or_number'. Expected a ROI Instance or an Integer (ROI Number). Got #{instance_or_number.class}.\"", "unless", "[", "ROI", ",", "Integer", "]", ".", "include?", "(", "instance_or_number", ".", "class", ")", "s_instance", "=", "instance_or_number", "if", "instance_or_number", ".", "is_a?", "(", "Integer", ")", "s_instance", "=", "structure", "(", "instance_or_number", ")", "end", "index", "=", "@structures", ".", "index", "(", "s_instance", ")", "if", "index", "@structures", ".", "delete_at", "(", "index", ")", "s_instance", ".", "remove_references", "end", "end" ]
Removes a ROI or POI from the structure set. @param [ROI, POI, Integer] instance_or_number the ROI/POI instance or its identifying number
[ "Removes", "a", "ROI", "or", "POI", "from", "the", "structure", "set", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L268-L279
22,980
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.structure_names
def structure_names names = Array.new @structures.each do |s| names << s.name end return names end
ruby
def structure_names names = Array.new @structures.each do |s| names << s.name end return names end
[ "def", "structure_names", "names", "=", "Array", ".", "new", "@structures", ".", "each", "do", "|", "s", "|", "names", "<<", "s", ".", "name", "end", "return", "names", "end" ]
Gives the names of the structure set's associated structures. @return [Array<String>] the names of the associated structures
[ "Gives", "the", "names", "of", "the", "structure", "set", "s", "associated", "structures", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L321-L327
22,981
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.structure_numbers
def structure_numbers numbers = Array.new @structures.each do |s| numbers << s.number end return numbers end
ruby
def structure_numbers numbers = Array.new @structures.each do |s| numbers << s.number end return numbers end
[ "def", "structure_numbers", "numbers", "=", "Array", ".", "new", "@structures", ".", "each", "do", "|", "s", "|", "numbers", "<<", "s", ".", "number", "end", "return", "numbers", "end" ]
Gives the numbers of the structure set's associated structures. @return [Array<Integer>] the numbers of the associated structures
[ "Gives", "the", "numbers", "of", "the", "structure", "set", "s", "associated", "structures", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L333-L339
22,982
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.to_dcm
def to_dcm # Use the original DICOM object as a starting point (keeping all non-sequence elements): #@dcm[REF_FRAME_OF_REF_SQ].delete_children @dcm[STRUCTURE_SET_ROI_SQ].delete_children @dcm[ROI_CONTOUR_SQ].delete_children @dcm[RT_ROI_OBS_SQ].delete_children # Create DICOM @rois.each do |roi| @dcm[STRUCTURE_SET_ROI_SQ].add_item(roi.ss_item) @dcm[ROI_CONTOUR_SQ].add_item(roi.contour_item) @dcm[RT_ROI_OBS_SQ].add_item(roi.obs_item) end return @dcm end
ruby
def to_dcm # Use the original DICOM object as a starting point (keeping all non-sequence elements): #@dcm[REF_FRAME_OF_REF_SQ].delete_children @dcm[STRUCTURE_SET_ROI_SQ].delete_children @dcm[ROI_CONTOUR_SQ].delete_children @dcm[RT_ROI_OBS_SQ].delete_children # Create DICOM @rois.each do |roi| @dcm[STRUCTURE_SET_ROI_SQ].add_item(roi.ss_item) @dcm[ROI_CONTOUR_SQ].add_item(roi.contour_item) @dcm[RT_ROI_OBS_SQ].add_item(roi.obs_item) end return @dcm end
[ "def", "to_dcm", "# Use the original DICOM object as a starting point (keeping all non-sequence elements):", "#@dcm[REF_FRAME_OF_REF_SQ].delete_children", "@dcm", "[", "STRUCTURE_SET_ROI_SQ", "]", ".", "delete_children", "@dcm", "[", "ROI_CONTOUR_SQ", "]", ".", "delete_children", "@dcm", "[", "RT_ROI_OBS_SQ", "]", ".", "delete_children", "# Create DICOM", "@rois", ".", "each", "do", "|", "roi", "|", "@dcm", "[", "STRUCTURE_SET_ROI_SQ", "]", ".", "add_item", "(", "roi", ".", "ss_item", ")", "@dcm", "[", "ROI_CONTOUR_SQ", "]", ".", "add_item", "(", "roi", ".", "contour_item", ")", "@dcm", "[", "RT_ROI_OBS_SQ", "]", ".", "add_item", "(", "roi", ".", "obs_item", ")", "end", "return", "@dcm", "end" ]
Converts the structure set instance to a DICOM object. @note This method uses the original DICOM object of the structure set, and updates it with attributes from the structure set instance. @return [DICOM::DObject] the processed DICOM object
[ "Converts", "the", "structure", "set", "instance", "to", "a", "DICOM", "object", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L390-L403
22,983
dicom/rtkit
lib/rtkit/structure_set.rb
RTKIT.StructureSet.load_structures
def load_structures if @dcm[STRUCTURE_SET_ROI_SQ] && @dcm[ROI_CONTOUR_SQ] && @dcm[RT_ROI_OBS_SQ] # Load the information in a nested hash: item_group = Hash.new @dcm[STRUCTURE_SET_ROI_SQ].each do |roi_item| item_group[roi_item.value(ROI_NUMBER)] = {:roi => roi_item} end @dcm[ROI_CONTOUR_SQ].each do |contour_item| item_group[contour_item.value(REF_ROI_NUMBER)][:contour] = contour_item end @dcm[RT_ROI_OBS_SQ].each do |rt_item| item_group[rt_item.value(REF_ROI_NUMBER)][:rt] = rt_item end # Create a ROI instance for each set of items: item_group.each_value do |roi_items| Structure.create_from_items(roi_items[:roi], roi_items[:contour], roi_items[:rt], self) end else RTKIT.logger.warn "The structure set contained one or more empty ROI sequences. No ROIs extracted." end end
ruby
def load_structures if @dcm[STRUCTURE_SET_ROI_SQ] && @dcm[ROI_CONTOUR_SQ] && @dcm[RT_ROI_OBS_SQ] # Load the information in a nested hash: item_group = Hash.new @dcm[STRUCTURE_SET_ROI_SQ].each do |roi_item| item_group[roi_item.value(ROI_NUMBER)] = {:roi => roi_item} end @dcm[ROI_CONTOUR_SQ].each do |contour_item| item_group[contour_item.value(REF_ROI_NUMBER)][:contour] = contour_item end @dcm[RT_ROI_OBS_SQ].each do |rt_item| item_group[rt_item.value(REF_ROI_NUMBER)][:rt] = rt_item end # Create a ROI instance for each set of items: item_group.each_value do |roi_items| Structure.create_from_items(roi_items[:roi], roi_items[:contour], roi_items[:rt], self) end else RTKIT.logger.warn "The structure set contained one or more empty ROI sequences. No ROIs extracted." end end
[ "def", "load_structures", "if", "@dcm", "[", "STRUCTURE_SET_ROI_SQ", "]", "&&", "@dcm", "[", "ROI_CONTOUR_SQ", "]", "&&", "@dcm", "[", "RT_ROI_OBS_SQ", "]", "# Load the information in a nested hash:", "item_group", "=", "Hash", ".", "new", "@dcm", "[", "STRUCTURE_SET_ROI_SQ", "]", ".", "each", "do", "|", "roi_item", "|", "item_group", "[", "roi_item", ".", "value", "(", "ROI_NUMBER", ")", "]", "=", "{", ":roi", "=>", "roi_item", "}", "end", "@dcm", "[", "ROI_CONTOUR_SQ", "]", ".", "each", "do", "|", "contour_item", "|", "item_group", "[", "contour_item", ".", "value", "(", "REF_ROI_NUMBER", ")", "]", "[", ":contour", "]", "=", "contour_item", "end", "@dcm", "[", "RT_ROI_OBS_SQ", "]", ".", "each", "do", "|", "rt_item", "|", "item_group", "[", "rt_item", ".", "value", "(", "REF_ROI_NUMBER", ")", "]", "[", ":rt", "]", "=", "rt_item", "end", "# Create a ROI instance for each set of items:", "item_group", ".", "each_value", "do", "|", "roi_items", "|", "Structure", ".", "create_from_items", "(", "roi_items", "[", ":roi", "]", ",", "roi_items", "[", ":contour", "]", ",", "roi_items", "[", ":rt", "]", ",", "self", ")", "end", "else", "RTKIT", ".", "logger", ".", "warn", "\"The structure set contained one or more empty ROI sequences. No ROIs extracted.\"", "end", "end" ]
Loads the ROI Items contained in the structure set and creates ROI and POI instances, which are referenced to this structure set.
[ "Loads", "the", "ROI", "Items", "contained", "in", "the", "structure", "set", "and", "creates", "ROI", "and", "POI", "instances", "which", "are", "referenced", "to", "this", "structure", "set", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/structure_set.rb#L475-L495
22,984
dicom/rtkit
lib/rtkit/frame.rb
RTKIT.Frame.add_image
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(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
ruby
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(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
[ "def", "add_image", "(", "image", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected Image, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "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" ]
Adds an Image to this Frame. @param [Image] image an image instance to be associated with this frame
[ "Adds", "an", "Image", "to", "this", "Frame", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/frame.rb#L67-L72
22,985
dicom/rtkit
lib/rtkit/frame.rb
RTKIT.Frame.add_series
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
ruby
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
[ "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" ]
Adds an ImageSeries to this Frame. @param [ImageSeries, DoseVolume] series an image series instance to be associated with this frame
[ "Adds", "an", "ImageSeries", "to", "this", "Frame", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/frame.rb#L87-L91
22,986
dicom/rtkit
lib/rtkit/contour.rb
RTKIT.Contour.add_coordinate
def add_coordinate(coordinate) raise ArgumentError, "Invalid argument 'coordinate'. Expected Coordinate, got #{coordinate.class}." unless coordinate.is_a?(Coordinate) @coordinates << coordinate unless @coordinates.include?(coordinate) end
ruby
def add_coordinate(coordinate) raise ArgumentError, "Invalid argument 'coordinate'. Expected Coordinate, got #{coordinate.class}." unless coordinate.is_a?(Coordinate) @coordinates << coordinate unless @coordinates.include?(coordinate) end
[ "def", "add_coordinate", "(", "coordinate", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'coordinate'. Expected Coordinate, got #{coordinate.class}.\"", "unless", "coordinate", ".", "is_a?", "(", "Coordinate", ")", "@coordinates", "<<", "coordinate", "unless", "@coordinates", ".", "include?", "(", "coordinate", ")", "end" ]
Adds a Coordinate instance to this Contour. @param [Coordinate] coordinate a coordinate instance to be associated with this contour
[ "Adds", "a", "Coordinate", "instance", "to", "this", "Contour", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/contour.rb#L114-L117
22,987
dicom/rtkit
lib/rtkit/contour.rb
RTKIT.Contour.coords
def coords x, y, z = Array.new, Array.new, Array.new @coordinates.each do |coord| x << coord.x y << coord.y z << coord.z end return x, y, z end
ruby
def coords x, y, z = Array.new, Array.new, Array.new @coordinates.each do |coord| x << coord.x y << coord.y z << coord.z end return x, y, z end
[ "def", "coords", "x", ",", "y", ",", "z", "=", "Array", ".", "new", ",", "Array", ".", "new", ",", "Array", ".", "new", "@coordinates", ".", "each", "do", "|", "coord", "|", "x", "<<", "coord", ".", "x", "y", "<<", "coord", ".", "y", "z", "<<", "coord", ".", "z", "end", "return", "x", ",", "y", ",", "z", "end" ]
Extracts and transposes all coordinates of this contour, such that the coordinates are given in arrays of x, y and z coordinates. @return [Array] the coordinates of this contour, converted to x, y and z arrays
[ "Extracts", "and", "transposes", "all", "coordinates", "of", "this", "contour", "such", "that", "the", "coordinates", "are", "given", "in", "arrays", "of", "x", "y", "and", "z", "coordinates", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/contour.rb#L134-L142
22,988
dicom/rtkit
lib/rtkit/contour.rb
RTKIT.Contour.create_coordinates
def create_coordinates(contour_data) raise ArgumentError, "Invalid argument 'contour_data'. Expected String (or nil), got #{contour_data.class}." unless [String, NilClass].include?(contour_data.class) if contour_data && contour_data != "" # Split the number strings, sperated by a '\', into an array: string_values = contour_data.split("\\") size = string_values.length/3 # Extract every third value of the string array as x, y, and z, respectively, and collect them as floats instead of strings: x = string_values.values_at(*(Array.new(size){|i| i*3 })).collect{|val| val.to_f} y = string_values.values_at(*(Array.new(size){|i| i*3+1})).collect{|val| val.to_f} z = string_values.values_at(*(Array.new(size){|i| i*3+2})).collect{|val| val.to_f} x.each_index do |i| Coordinate.new(x[i], y[i], z[i], self) end end end
ruby
def create_coordinates(contour_data) raise ArgumentError, "Invalid argument 'contour_data'. Expected String (or nil), got #{contour_data.class}." unless [String, NilClass].include?(contour_data.class) if contour_data && contour_data != "" # Split the number strings, sperated by a '\', into an array: string_values = contour_data.split("\\") size = string_values.length/3 # Extract every third value of the string array as x, y, and z, respectively, and collect them as floats instead of strings: x = string_values.values_at(*(Array.new(size){|i| i*3 })).collect{|val| val.to_f} y = string_values.values_at(*(Array.new(size){|i| i*3+1})).collect{|val| val.to_f} z = string_values.values_at(*(Array.new(size){|i| i*3+2})).collect{|val| val.to_f} x.each_index do |i| Coordinate.new(x[i], y[i], z[i], self) end end end
[ "def", "create_coordinates", "(", "contour_data", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'contour_data'. Expected String (or nil), got #{contour_data.class}.\"", "unless", "[", "String", ",", "NilClass", "]", ".", "include?", "(", "contour_data", ".", "class", ")", "if", "contour_data", "&&", "contour_data", "!=", "\"\"", "# Split the number strings, sperated by a '\\', into an array:", "string_values", "=", "contour_data", ".", "split", "(", "\"\\\\\"", ")", "size", "=", "string_values", ".", "length", "/", "3", "# Extract every third value of the string array as x, y, and z, respectively, and collect them as floats instead of strings:", "x", "=", "string_values", ".", "values_at", "(", "(", "Array", ".", "new", "(", "size", ")", "{", "|", "i", "|", "i", "3", "}", ")", ")", ".", "collect", "{", "|", "val", "|", "val", ".", "to_f", "}", "y", "=", "string_values", ".", "values_at", "(", "(", "Array", ".", "new", "(", "size", ")", "{", "|", "i", "|", "i", "3", "+", "1", "}", ")", ")", ".", "collect", "{", "|", "val", "|", "val", ".", "to_f", "}", "z", "=", "string_values", ".", "values_at", "(", "(", "Array", ".", "new", "(", "size", ")", "{", "|", "i", "|", "i", "3", "+", "2", "}", ")", ")", ".", "collect", "{", "|", "val", "|", "val", ".", "to_f", "}", "x", ".", "each_index", "do", "|", "i", "|", "Coordinate", ".", "new", "(", "x", "[", "i", "]", ",", "y", "[", "i", "]", ",", "z", "[", "i", "]", ",", "self", ")", "end", "end", "end" ]
Creates and connects Coordinate instances with this Contour instance by processing the value of the Contour Data element value. @param [String, NilClass] contour_data a string containing x,y,z coordinate triplets separated by '\'
[ "Creates", "and", "connects", "Coordinate", "instances", "with", "this", "Contour", "instance", "by", "processing", "the", "value", "of", "the", "Contour", "Data", "element", "value", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/contour.rb#L149-L163
22,989
dicom/rtkit
lib/rtkit/contour.rb
RTKIT.Contour.to_item
def to_item # FIXME: We need to decide on how to principally handle the situation when an image series has not been # loaded, and how to set up the ROI slices. A possible solution is to create Image instances if they hasn't been loaded. item = DICOM::Item.new item.add(DICOM::Sequence.new(CONTOUR_IMAGE_SQ)) item[CONTOUR_IMAGE_SQ].add_item item[CONTOUR_IMAGE_SQ][0].add(DICOM::Element.new(REF_SOP_CLASS_UID, @slice.image ? @slice.image.series.class_uid : '1.2.840.10008.5.1.4.1.1.2')) # Deafult to CT if image ref. doesn't exist. item[CONTOUR_IMAGE_SQ][0].add(DICOM::Element.new(REF_SOP_UID, @slice.uid)) item.add(DICOM::Element.new(CONTOUR_GEO_TYPE, @type)) item.add(DICOM::Element.new(NR_CONTOUR_POINTS, @coordinates.length.to_s)) item.add(DICOM::Element.new(CONTOUR_NUMBER, @number.to_s)) item.add(DICOM::Element.new(CONTOUR_DATA, contour_data)) return item end
ruby
def to_item # FIXME: We need to decide on how to principally handle the situation when an image series has not been # loaded, and how to set up the ROI slices. A possible solution is to create Image instances if they hasn't been loaded. item = DICOM::Item.new item.add(DICOM::Sequence.new(CONTOUR_IMAGE_SQ)) item[CONTOUR_IMAGE_SQ].add_item item[CONTOUR_IMAGE_SQ][0].add(DICOM::Element.new(REF_SOP_CLASS_UID, @slice.image ? @slice.image.series.class_uid : '1.2.840.10008.5.1.4.1.1.2')) # Deafult to CT if image ref. doesn't exist. item[CONTOUR_IMAGE_SQ][0].add(DICOM::Element.new(REF_SOP_UID, @slice.uid)) item.add(DICOM::Element.new(CONTOUR_GEO_TYPE, @type)) item.add(DICOM::Element.new(NR_CONTOUR_POINTS, @coordinates.length.to_s)) item.add(DICOM::Element.new(CONTOUR_NUMBER, @number.to_s)) item.add(DICOM::Element.new(CONTOUR_DATA, contour_data)) return item end
[ "def", "to_item", "# FIXME: We need to decide on how to principally handle the situation when an image series has not been", "# loaded, and how to set up the ROI slices. A possible solution is to create Image instances if they hasn't been loaded.", "item", "=", "DICOM", "::", "Item", ".", "new", "item", ".", "add", "(", "DICOM", "::", "Sequence", ".", "new", "(", "CONTOUR_IMAGE_SQ", ")", ")", "item", "[", "CONTOUR_IMAGE_SQ", "]", ".", "add_item", "item", "[", "CONTOUR_IMAGE_SQ", "]", "[", "0", "]", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "REF_SOP_CLASS_UID", ",", "@slice", ".", "image", "?", "@slice", ".", "image", ".", "series", ".", "class_uid", ":", "'1.2.840.10008.5.1.4.1.1.2'", ")", ")", "# Deafult to CT if image ref. doesn't exist.", "item", "[", "CONTOUR_IMAGE_SQ", "]", "[", "0", "]", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "REF_SOP_UID", ",", "@slice", ".", "uid", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "CONTOUR_GEO_TYPE", ",", "@type", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "NR_CONTOUR_POINTS", ",", "@coordinates", ".", "length", ".", "to_s", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "CONTOUR_NUMBER", ",", "@number", ".", "to_s", ")", ")", "item", ".", "add", "(", "DICOM", "::", "Element", ".", "new", "(", "CONTOUR_DATA", ",", "contour_data", ")", ")", "return", "item", "end" ]
Creates a Contour Sequence Item from the attributes of the Contour. @return [DICOM::Item] the created DICOM item
[ "Creates", "a", "Contour", "Sequence", "Item", "from", "the", "attributes", "of", "the", "Contour", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/contour.rb#L187-L200
22,990
dicom/rtkit
lib/rtkit/contour.rb
RTKIT.Contour.translate
def translate(x, y, z) @coordinates.each do |c| c.translate(x, y, z) end end
ruby
def translate(x, y, z) @coordinates.each do |c| c.translate(x, y, z) end end
[ "def", "translate", "(", "x", ",", "y", ",", "z", ")", "@coordinates", ".", "each", "do", "|", "c", "|", "c", ".", "translate", "(", "x", ",", "y", ",", "z", ")", "end", "end" ]
Moves the coordinates of this contour according to the given offset vector. @param [Float] x the offset along the x axis (in units of mm) @param [Float] y the offset along the y axis (in units of mm) @param [Float] z the offset along the z axis (in units of mm)
[ "Moves", "the", "coordinates", "of", "this", "contour", "according", "to", "the", "given", "offset", "vector", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/contour.rb#L209-L213
22,991
celluloid/dcell
lib/dcell/server.rb
DCell.MessageHandler.handle_message
def handle_message(message) begin message = decode_message message rescue InvalidMessageError => ex Logger.crash("couldn't decode message", ex) return end begin message.dispatch rescue => ex Logger.crash("message dispatch failed", ex) end end
ruby
def handle_message(message) begin message = decode_message message rescue InvalidMessageError => ex Logger.crash("couldn't decode message", ex) return end begin message.dispatch rescue => ex Logger.crash("message dispatch failed", ex) end end
[ "def", "handle_message", "(", "message", ")", "begin", "message", "=", "decode_message", "message", "rescue", "InvalidMessageError", "=>", "ex", "Logger", ".", "crash", "(", "\"couldn't decode message\"", ",", "ex", ")", "return", "end", "begin", "message", ".", "dispatch", "rescue", "=>", "ex", "Logger", ".", "crash", "(", "\"message dispatch failed\"", ",", "ex", ")", "end", "end" ]
Handle incoming messages
[ "Handle", "incoming", "messages" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/server.rb#L8-L21
22,992
celluloid/dcell
lib/dcell/server.rb
DCell.MessageHandler.decode_message
def decode_message(message) begin msg = MessagePack.unpack(message, symbolize_keys: true) rescue => ex raise InvalidMessageError, "couldn't unpack message: #{ex}" end begin klass = Utils.full_const_get msg[:type] o = klass.new(*msg[:args]) o.id = msg[:id] if o.respond_to?(:id=) && msg[:id] o rescue => ex raise InvalidMessageError, "invalid message: #{ex}" end end
ruby
def decode_message(message) begin msg = MessagePack.unpack(message, symbolize_keys: true) rescue => ex raise InvalidMessageError, "couldn't unpack message: #{ex}" end begin klass = Utils.full_const_get msg[:type] o = klass.new(*msg[:args]) o.id = msg[:id] if o.respond_to?(:id=) && msg[:id] o rescue => ex raise InvalidMessageError, "invalid message: #{ex}" end end
[ "def", "decode_message", "(", "message", ")", "begin", "msg", "=", "MessagePack", ".", "unpack", "(", "message", ",", "symbolize_keys", ":", "true", ")", "rescue", "=>", "ex", "raise", "InvalidMessageError", ",", "\"couldn't unpack message: #{ex}\"", "end", "begin", "klass", "=", "Utils", ".", "full_const_get", "msg", "[", ":type", "]", "o", "=", "klass", ".", "new", "(", "msg", "[", ":args", "]", ")", "o", ".", "id", "=", "msg", "[", ":id", "]", "if", "o", ".", "respond_to?", "(", ":id=", ")", "&&", "msg", "[", ":id", "]", "o", "rescue", "=>", "ex", "raise", "InvalidMessageError", ",", "\"invalid message: #{ex}\"", "end", "end" ]
Decode incoming messages
[ "Decode", "incoming", "messages" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/server.rb#L24-L38
22,993
celluloid/dcell
lib/dcell/server.rb
DCell.Server.run
def run while true message = @socket.read_multipart if @socket.is_a? Celluloid::ZMQ::RouterSocket message = message[1] else message = message[0] end handle_message message end end
ruby
def run while true message = @socket.read_multipart if @socket.is_a? Celluloid::ZMQ::RouterSocket message = message[1] else message = message[0] end handle_message message end end
[ "def", "run", "while", "true", "message", "=", "@socket", ".", "read_multipart", "if", "@socket", ".", "is_a?", "Celluloid", "::", "ZMQ", "::", "RouterSocket", "message", "=", "message", "[", "1", "]", "else", "message", "=", "message", "[", "0", "]", "end", "handle_message", "message", "end", "end" ]
Wait for incoming 0MQ messages
[ "Wait", "for", "incoming", "0MQ", "messages" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/server.rb#L80-L90
22,994
jlong/radius
lib/radius/parser/scanner.rb
Radius.Scanner.operate
def operate(prefix, data) data = Radius::OrdString.new data @nodes = [''] re = scanner_regex(prefix) if md = re.match(data) remainder = '' while md start_tag, attributes, self_enclosed, end_tag = $1, $2, $3, $4 flavor = self_enclosed == '/' ? :self : (start_tag ? :open : :close) # save the part before the current match as a string node @nodes << md.pre_match # save the tag that was found as a tag hash node @nodes << {:prefix=>prefix, :name=>(start_tag || end_tag), :flavor => flavor, :attrs => parse_attributes(attributes)} # remember the part after the current match remainder = md.post_match # see if we find another tag in the remaining string md = re.match(md.post_match) end # add the last remaining string after the last tag that was found as a string node @nodes << remainder else @nodes << data end return @nodes end
ruby
def operate(prefix, data) data = Radius::OrdString.new data @nodes = [''] re = scanner_regex(prefix) if md = re.match(data) remainder = '' while md start_tag, attributes, self_enclosed, end_tag = $1, $2, $3, $4 flavor = self_enclosed == '/' ? :self : (start_tag ? :open : :close) # save the part before the current match as a string node @nodes << md.pre_match # save the tag that was found as a tag hash node @nodes << {:prefix=>prefix, :name=>(start_tag || end_tag), :flavor => flavor, :attrs => parse_attributes(attributes)} # remember the part after the current match remainder = md.post_match # see if we find another tag in the remaining string md = re.match(md.post_match) end # add the last remaining string after the last tag that was found as a string node @nodes << remainder else @nodes << data end return @nodes end
[ "def", "operate", "(", "prefix", ",", "data", ")", "data", "=", "Radius", "::", "OrdString", ".", "new", "data", "@nodes", "=", "[", "''", "]", "re", "=", "scanner_regex", "(", "prefix", ")", "if", "md", "=", "re", ".", "match", "(", "data", ")", "remainder", "=", "''", "while", "md", "start_tag", ",", "attributes", ",", "self_enclosed", ",", "end_tag", "=", "$1", ",", "$2", ",", "$3", ",", "$4", "flavor", "=", "self_enclosed", "==", "'/'", "?", ":self", ":", "(", "start_tag", "?", ":open", ":", ":close", ")", "# save the part before the current match as a string node", "@nodes", "<<", "md", ".", "pre_match", "# save the tag that was found as a tag hash node", "@nodes", "<<", "{", ":prefix", "=>", "prefix", ",", ":name", "=>", "(", "start_tag", "||", "end_tag", ")", ",", ":flavor", "=>", "flavor", ",", ":attrs", "=>", "parse_attributes", "(", "attributes", ")", "}", "# remember the part after the current match", "remainder", "=", "md", ".", "post_match", "# see if we find another tag in the remaining string", "md", "=", "re", ".", "match", "(", "md", ".", "post_match", ")", "end", "# add the last remaining string after the last tag that was found as a string node", "@nodes", "<<", "remainder", "else", "@nodes", "<<", "data", "end", "return", "@nodes", "end" ]
Parses a given string and returns an array of nodes. The nodes consist of strings and hashes that describe a Radius tag that was found.
[ "Parses", "a", "given", "string", "and", "returns", "an", "array", "of", "nodes", ".", "The", "nodes", "consist", "of", "strings", "and", "hashes", "that", "describe", "a", "Radius", "tag", "that", "was", "found", "." ]
e7b4eab374c6a15e105524ccd663767b8bc91e5b
https://github.com/jlong/radius/blob/e7b4eab374c6a15e105524ccd663767b8bc91e5b/lib/radius/parser/scanner.rb#L12-L44
22,995
slagyr/limelight
ruby/lib/limelight/theater.rb
Limelight.Theater.add_stage
def add_stage(name, options = {}) stage = build_stage(name, options).proxy @peer.add(stage.peer) return stage end
ruby
def add_stage(name, options = {}) stage = build_stage(name, options).proxy @peer.add(stage.peer) return stage end
[ "def", "add_stage", "(", "name", ",", "options", "=", "{", "}", ")", "stage", "=", "build_stage", "(", "name", ",", "options", ")", ".", "proxy", "@peer", ".", "add", "(", "stage", ".", "peer", ")", "return", "stage", "end" ]
Adds a Stage to the Theater. Raises an exception is the name of the Stage is duplicated.
[ "Adds", "a", "Stage", "to", "the", "Theater", ".", "Raises", "an", "exception", "is", "the", "name", "of", "the", "Stage", "is", "duplicated", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/theater.rb#L52-L56
22,996
dicom/rtkit
lib/rtkit/bin_matcher.rb
RTKIT.BinMatcher.fill_blanks
def fill_blanks if @volumes.length > 0 # Register all unique images referenced by the various volumes: images = Set.new # Include the master volume (if it is present): [@volumes, @master].flatten.compact.each do |volume| volume.bin_images.each do |bin_image| images << bin_image.image unless images.include?(bin_image.image) end end # Check if any of the volumes have images missing, and if so, create empty images: images.each do |image| [@volumes, @master].flatten.compact.each do |volume| match = false volume.bin_images.each do |bin_image| match = true if bin_image.image == image end unless match # Create BinImage: bin_img = BinImage.new(NArray.byte(image.columns, image.rows), image) volume.add(bin_img) end end end end end
ruby
def fill_blanks if @volumes.length > 0 # Register all unique images referenced by the various volumes: images = Set.new # Include the master volume (if it is present): [@volumes, @master].flatten.compact.each do |volume| volume.bin_images.each do |bin_image| images << bin_image.image unless images.include?(bin_image.image) end end # Check if any of the volumes have images missing, and if so, create empty images: images.each do |image| [@volumes, @master].flatten.compact.each do |volume| match = false volume.bin_images.each do |bin_image| match = true if bin_image.image == image end unless match # Create BinImage: bin_img = BinImage.new(NArray.byte(image.columns, image.rows), image) volume.add(bin_img) end end end end end
[ "def", "fill_blanks", "if", "@volumes", ".", "length", ">", "0", "# Register all unique images referenced by the various volumes:", "images", "=", "Set", ".", "new", "# Include the master volume (if it is present):", "[", "@volumes", ",", "@master", "]", ".", "flatten", ".", "compact", ".", "each", "do", "|", "volume", "|", "volume", ".", "bin_images", ".", "each", "do", "|", "bin_image", "|", "images", "<<", "bin_image", ".", "image", "unless", "images", ".", "include?", "(", "bin_image", ".", "image", ")", "end", "end", "# Check if any of the volumes have images missing, and if so, create empty images:", "images", ".", "each", "do", "|", "image", "|", "[", "@volumes", ",", "@master", "]", ".", "flatten", ".", "compact", ".", "each", "do", "|", "volume", "|", "match", "=", "false", "volume", ".", "bin_images", ".", "each", "do", "|", "bin_image", "|", "match", "=", "true", "if", "bin_image", ".", "image", "==", "image", "end", "unless", "match", "# Create BinImage:", "bin_img", "=", "BinImage", ".", "new", "(", "NArray", ".", "byte", "(", "image", ".", "columns", ",", "image", ".", "rows", ")", ",", "image", ")", "volume", ".", "add", "(", "bin_img", ")", "end", "end", "end", "end", "end" ]
Ensures that a valid comparison between volumes can be done, by making sure that every volume has a BinImage for any image that is referenced among the BinVolumes. If some BinVolumes are missing one or more BinImages, empty BinImages will be created for these BinVolumes. @note The master volume (if present) is also processed by this method.
[ "Ensures", "that", "a", "valid", "comparison", "between", "volumes", "can", "be", "done", "by", "making", "sure", "that", "every", "volume", "has", "a", "BinImage", "for", "any", "image", "that", "is", "referenced", "among", "the", "BinVolumes", ".", "If", "some", "BinVolumes", "are", "missing", "one", "or", "more", "BinImages", "empty", "BinImages", "will", "be", "created", "for", "these", "BinVolumes", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_matcher.rb#L79-L104
22,997
dicom/rtkit
lib/rtkit/dose_volume.rb
RTKIT.DoseVolume.add_image
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) @images << image unless @associated_images[image.uid] @associated_images[image.uid] = image @image_positions[image.pos_slice.round(2)] = image end
ruby
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) @images << image unless @associated_images[image.uid] @associated_images[image.uid] = image @image_positions[image.pos_slice.round(2)] = image end
[ "def", "add_image", "(", "image", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected Image, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "Image", ")", "@images", "<<", "image", "unless", "@associated_images", "[", "image", ".", "uid", "]", "@associated_images", "[", "image", ".", "uid", "]", "=", "image", "@image_positions", "[", "image", ".", "pos_slice", ".", "round", "(", "2", ")", "]", "=", "image", "end" ]
Adds an Image to this Volume. @param [Image] image an image instance to be associated with this dose volume
[ "Adds", "an", "Image", "to", "this", "Volume", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/dose_volume.rb#L138-L143
22,998
dicom/rtkit
lib/rtkit/dose_volume.rb
RTKIT.DoseVolume.image_by_slice_pos
def image_by_slice_pos(pos) # Step 1: Try for an (exact) match: image = @image_positions[pos.round(2)] # Step 2: If no match, try to search for a close match: # (A close match is defined as the given slice position being within 1/3 of the # slice distance from an existing image instance in the series) if !image && @images.length > 1 proximity = @images.collect{|img| (img.pos_slice - pos).abs} if proximity.min < slice_spacing / 3.0 index = proximity.index(proximity.min) image = @images[index] end end return image end
ruby
def image_by_slice_pos(pos) # Step 1: Try for an (exact) match: image = @image_positions[pos.round(2)] # Step 2: If no match, try to search for a close match: # (A close match is defined as the given slice position being within 1/3 of the # slice distance from an existing image instance in the series) if !image && @images.length > 1 proximity = @images.collect{|img| (img.pos_slice - pos).abs} if proximity.min < slice_spacing / 3.0 index = proximity.index(proximity.min) image = @images[index] end end return image end
[ "def", "image_by_slice_pos", "(", "pos", ")", "# Step 1: Try for an (exact) match:", "image", "=", "@image_positions", "[", "pos", ".", "round", "(", "2", ")", "]", "# Step 2: If no match, try to search for a close match:", "# (A close match is defined as the given slice position being within 1/3 of the", "# slice distance from an existing image instance in the series)", "if", "!", "image", "&&", "@images", ".", "length", ">", "1", "proximity", "=", "@images", ".", "collect", "{", "|", "img", "|", "(", "img", ".", "pos_slice", "-", "pos", ")", ".", "abs", "}", "if", "proximity", ".", "min", "<", "slice_spacing", "/", "3.0", "index", "=", "proximity", ".", "index", "(", "proximity", ".", "min", ")", "image", "=", "@images", "[", "index", "]", "end", "end", "return", "image", "end" ]
Returns an image instance matched by the given slice position. @param [Float] pos image slice position @return [Image, NilClass] the matched image (or nil if no image is matched)
[ "Returns", "an", "image", "instance", "matched", "by", "the", "given", "slice", "position", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/dose_volume.rb#L288-L302
22,999
dradis/dradis-plugins
lib/dradis/plugins/settings.rb
Dradis::Plugins.Settings.dirty_or_db_setting_or_default
def dirty_or_db_setting_or_default(key) if @dirty_options.key?(key) @dirty_options[key] elsif Configuration.exists?(name: namespaced_key(key)) db_setting(key) else @default_options[key] end end
ruby
def dirty_or_db_setting_or_default(key) if @dirty_options.key?(key) @dirty_options[key] elsif Configuration.exists?(name: namespaced_key(key)) db_setting(key) else @default_options[key] end end
[ "def", "dirty_or_db_setting_or_default", "(", "key", ")", "if", "@dirty_options", ".", "key?", "(", "key", ")", "@dirty_options", "[", "key", "]", "elsif", "Configuration", ".", "exists?", "(", "name", ":", "namespaced_key", "(", "key", ")", ")", "db_setting", "(", "key", ")", "else", "@default_options", "[", "key", "]", "end", "end" ]
This method looks up in the configuration repository DB to see if the user has provided a value for the given setting. If not, the default value is returned.
[ "This", "method", "looks", "up", "in", "the", "configuration", "repository", "DB", "to", "see", "if", "the", "user", "has", "provided", "a", "value", "for", "the", "given", "setting", ".", "If", "not", "the", "default", "value", "is", "returned", "." ]
570367ba16e42dae3f3065a6b72c544dd780ca36
https://github.com/dradis/dradis-plugins/blob/570367ba16e42dae3f3065a6b72c544dd780ca36/lib/dradis/plugins/settings.rb#L76-L84