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
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
celluloid/dcell
lib/dcell/directory.rb
DCell.Directory.find
def find(id) return nil unless id meta = DCell.registry.get_node(id) DirectoryMeta.new(id, meta) end
ruby
def find(id) return nil unless id meta = DCell.registry.get_node(id) DirectoryMeta.new(id, meta) end
[ "def", "find", "(", "id", ")", "return", "nil", "unless", "id", "meta", "=", "DCell", ".", "registry", ".", "get_node", "(", "id", ")", "DirectoryMeta", ".", "new", "(", "id", ",", "meta", ")", "end" ]
Get the address for a particular Node ID
[ "Get", "the", "address", "for", "a", "particular", "Node", "ID" ]
a8fecfae220cb2c20d3761bc27880e4133aba498
https://github.com/celluloid/dcell/blob/a8fecfae220cb2c20d3761bc27880e4133aba498/lib/dcell/directory.rb#L67-L71
train
dicom/rtkit
lib/rtkit/control_point.rb
RTKIT.ControlPoint.add_collimator
def add_collimator(coll) raise ArgumentError, "Invalid argument 'coll'. Expected CollimatorSetup, got #{coll.class}." unless coll.is_a?(CollimatorSetup) @collimators << coll unless @associated_collimators[coll.type] @associated_collimators[coll.type] = coll end
ruby
def add_collimator(coll) raise ArgumentError, "Invalid argument 'coll'. Expected CollimatorSetup, got #{coll.class}." unless coll.is_a?(CollimatorSetup) @collimators << coll unless @associated_collimators[coll.type] @associated_collimators[coll.type] = coll end
[ "def", "add_collimator", "(", "coll", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'coll'. Expected CollimatorSetup, got #{coll.class}.\"", "unless", "coll", ".", "is_a?", "(", "CollimatorSetup", ")", "@collimators", "<<", "coll", "unless", "@associated_collimators", "[", "coll", ".", "type", "]", "@associated_collimators", "[", "coll", ".", "type", "]", "=", "coll", "end" ]
Adds a CollimatorSetup instance to this ControlPoint. @param [CollimatorSetup] coll a collimator setup instance to be associated with this control point
[ "Adds", "a", "CollimatorSetup", "instance", "to", "this", "ControlPoint", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/control_point.rb#L132-L136
train
dicom/rtkit
lib/rtkit/projection_image.rb
RTKIT.ProjectionImage.load_pixel_data
def load_pixel_data(dcm) raise ArgumentError, "Invalid argument 'dcm'. Expected DObject, got #{dcm.class}." unless dcm.is_a?(DICOM::DObject) raise ArgumentError, "Invalid argument 'dcm'. Expected modality 'RTIMAGE', got #{dcm.value(MODALITY)}." unless dcm.value(MODALITY) == 'RTIMAGE' # Set attributes common for all image modalities, i.e. CT, MR, RTDOSE & RTIMAGE: @dcm = dcm @narray = dcm.narray @date = dcm.value(IMAGE_DATE) @time = dcm.value(IMAGE_TIME) @columns = dcm.value(COLUMNS) @rows = dcm.value(ROWS) # Some difference in where we pick our values depending on if we have an # RTIMAGE or another type (e.g. CR): if @series.modality == 'RTIMAGE' image_position = dcm.value(RT_IMAGE_POSITION).split("\\") raise "Invalid DICOM image: 2 basckslash-separated values expected for RT Image Position (Patient), got: #{image_position}" unless image_position.length == 2 @pos_x = image_position[0].to_f @pos_y = image_position[1].to_f spacing = dcm.value(IMAGE_PLANE_SPACING).split("\\") raise "Invalid DICOM image: 2 basckslash-separated values expected for Image Plane Pixel Spacing, got: #{spacing}" unless spacing.length == 2 @col_spacing = spacing[1].to_f @row_spacing = spacing[0].to_f else image_position = dcm.value(IMAGE_POSITION).split("\\") raise "Invalid DICOM image: 3 basckslash-separated values expected for Image Position (Patient), got: #{image_position}" unless image_position.length == 3 @pos_x = image_position[0].to_f @pos_y = image_position[1].to_f spacing = dcm.value(SPACING).split("\\") raise "Invalid DICOM image: 2 basckslash-separated values expected for Pixel Spacing, got: #{spacing}" unless spacing.length == 2 @col_spacing = spacing[1].to_f @row_spacing = spacing[0].to_f end end
ruby
def load_pixel_data(dcm) raise ArgumentError, "Invalid argument 'dcm'. Expected DObject, got #{dcm.class}." unless dcm.is_a?(DICOM::DObject) raise ArgumentError, "Invalid argument 'dcm'. Expected modality 'RTIMAGE', got #{dcm.value(MODALITY)}." unless dcm.value(MODALITY) == 'RTIMAGE' # Set attributes common for all image modalities, i.e. CT, MR, RTDOSE & RTIMAGE: @dcm = dcm @narray = dcm.narray @date = dcm.value(IMAGE_DATE) @time = dcm.value(IMAGE_TIME) @columns = dcm.value(COLUMNS) @rows = dcm.value(ROWS) # Some difference in where we pick our values depending on if we have an # RTIMAGE or another type (e.g. CR): if @series.modality == 'RTIMAGE' image_position = dcm.value(RT_IMAGE_POSITION).split("\\") raise "Invalid DICOM image: 2 basckslash-separated values expected for RT Image Position (Patient), got: #{image_position}" unless image_position.length == 2 @pos_x = image_position[0].to_f @pos_y = image_position[1].to_f spacing = dcm.value(IMAGE_PLANE_SPACING).split("\\") raise "Invalid DICOM image: 2 basckslash-separated values expected for Image Plane Pixel Spacing, got: #{spacing}" unless spacing.length == 2 @col_spacing = spacing[1].to_f @row_spacing = spacing[0].to_f else image_position = dcm.value(IMAGE_POSITION).split("\\") raise "Invalid DICOM image: 3 basckslash-separated values expected for Image Position (Patient), got: #{image_position}" unless image_position.length == 3 @pos_x = image_position[0].to_f @pos_y = image_position[1].to_f spacing = dcm.value(SPACING).split("\\") raise "Invalid DICOM image: 2 basckslash-separated values expected for Pixel Spacing, got: #{spacing}" unless spacing.length == 2 @col_spacing = spacing[1].to_f @row_spacing = spacing[0].to_f end end
[ "def", "load_pixel_data", "(", "dcm", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'dcm'. Expected DObject, got #{dcm.class}.\"", "unless", "dcm", ".", "is_a?", "(", "DICOM", "::", "DObject", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'dcm'. Expected modality 'RTIMAGE', got #{dcm.value(MODALITY)}.\"", "unless", "dcm", ".", "value", "(", "MODALITY", ")", "==", "'RTIMAGE'", "@dcm", "=", "dcm", "@narray", "=", "dcm", ".", "narray", "@date", "=", "dcm", ".", "value", "(", "IMAGE_DATE", ")", "@time", "=", "dcm", ".", "value", "(", "IMAGE_TIME", ")", "@columns", "=", "dcm", ".", "value", "(", "COLUMNS", ")", "@rows", "=", "dcm", ".", "value", "(", "ROWS", ")", "if", "@series", ".", "modality", "==", "'RTIMAGE'", "image_position", "=", "dcm", ".", "value", "(", "RT_IMAGE_POSITION", ")", ".", "split", "(", "\"\\\\\"", ")", "raise", "\"Invalid DICOM image: 2 basckslash-separated values expected for RT Image Position (Patient), got: #{image_position}\"", "unless", "image_position", ".", "length", "==", "2", "@pos_x", "=", "image_position", "[", "0", "]", ".", "to_f", "@pos_y", "=", "image_position", "[", "1", "]", ".", "to_f", "spacing", "=", "dcm", ".", "value", "(", "IMAGE_PLANE_SPACING", ")", ".", "split", "(", "\"\\\\\"", ")", "raise", "\"Invalid DICOM image: 2 basckslash-separated values expected for Image Plane Pixel Spacing, got: #{spacing}\"", "unless", "spacing", ".", "length", "==", "2", "@col_spacing", "=", "spacing", "[", "1", "]", ".", "to_f", "@row_spacing", "=", "spacing", "[", "0", "]", ".", "to_f", "else", "image_position", "=", "dcm", ".", "value", "(", "IMAGE_POSITION", ")", ".", "split", "(", "\"\\\\\"", ")", "raise", "\"Invalid DICOM image: 3 basckslash-separated values expected for Image Position (Patient), got: #{image_position}\"", "unless", "image_position", ".", "length", "==", "3", "@pos_x", "=", "image_position", "[", "0", "]", ".", "to_f", "@pos_y", "=", "image_position", "[", "1", "]", ".", "to_f", "spacing", "=", "dcm", ".", "value", "(", "SPACING", ")", ".", "split", "(", "\"\\\\\"", ")", "raise", "\"Invalid DICOM image: 2 basckslash-separated values expected for Pixel Spacing, got: #{spacing}\"", "unless", "spacing", ".", "length", "==", "2", "@col_spacing", "=", "spacing", "[", "1", "]", ".", "to_f", "@row_spacing", "=", "spacing", "[", "0", "]", ".", "to_f", "end", "end" ]
Transfers the pixel data, as well as the related image properties and the DObject instance itself, to the image instance. @param [DICOM::DObject] dcm an instance of a DICOM object @raise [ArgumentError] if the given dicom object doesn't have a projection image type modality
[ "Transfers", "the", "pixel", "data", "as", "well", "as", "the", "related", "image", "properties", "and", "the", "DObject", "instance", "itself", "to", "the", "image", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/projection_image.rb#L71-L102
train
dicom/rtkit
lib/rtkit/projection_image.rb
RTKIT.ProjectionImage.create_projection_image_dicom_scaffold
def create_projection_image_dicom_scaffold # Some tags are created/updated only if no DICOM object already exists: unless @dcm # Setup general image attributes: create_general_dicom_image_scaffold # Group 3002: @dcm.add_element(RT_IMAGE_LABEL, @beam.description) @dcm.add_element(RT_IMAGE_NAME, @beam.name) @dcm.add_element(RT_IMAGE_DESCRIPTION, @beam.plan.name) # Note: If support for image plane type 'NON_NORMAL' is added at some # point, the RT Image Orientation tag (3002,0010) has to be added as well. @dcm.add_element(RT_IMAGE_PLANE, 'NORMAL') @dcm.add_element(X_RAY_IMAGE_RECEPTOR_TRANSLATION, '') @dcm.add_element(X_RAY_IMAGE_RECEPTOR_ANGLE, '') @dcm.add_element(RADIATION_MACHINE_NAME, @beam.machine) @dcm.add_element(RADIATION_MACHINE_SAD, @beam.sad) @dcm.add_element(RADIATION_MACHINE_SSD, @beam.sad) @dcm.add_element(RT_IMAGE_SID, @beam.sad) # FIXME: Add Exposure sequence as well (with Jaw and MLC position information) # Group 300A: @dcm.add_element(DOSIMETER_UNIT, @beam.unit) @dcm.add_element(GANTRY_ANGLE, @beam.control_points[0].gantry_angle) @dcm.add_element(COLL_ANGLE, @beam.control_points[0].collimator_angle) @dcm.add_element(PEDESTAL_ANGLE, @beam.control_points[0].pedestal_angle) @dcm.add_element(TABLE_TOP_ANGLE, @beam.control_points[0].table_top_angle) @dcm.add_element(ISO_POS, @beam.control_points[0].iso.to_s) @dcm.add_element(GANTRY_PITCH_ANGLE, '0.0') # Group 300C: s = @dcm.add_sequence(REF_PLAN_SQ) i = s.add_item i.add_element(REF_SOP_CLASS_UID, @beam.plan.class_uid) i.add_element(REF_SOP_UID, @beam.plan.sop_uid) @dcm.add_element(REF_BEAM_NUMBER, @beam.number) end end
ruby
def create_projection_image_dicom_scaffold # Some tags are created/updated only if no DICOM object already exists: unless @dcm # Setup general image attributes: create_general_dicom_image_scaffold # Group 3002: @dcm.add_element(RT_IMAGE_LABEL, @beam.description) @dcm.add_element(RT_IMAGE_NAME, @beam.name) @dcm.add_element(RT_IMAGE_DESCRIPTION, @beam.plan.name) # Note: If support for image plane type 'NON_NORMAL' is added at some # point, the RT Image Orientation tag (3002,0010) has to be added as well. @dcm.add_element(RT_IMAGE_PLANE, 'NORMAL') @dcm.add_element(X_RAY_IMAGE_RECEPTOR_TRANSLATION, '') @dcm.add_element(X_RAY_IMAGE_RECEPTOR_ANGLE, '') @dcm.add_element(RADIATION_MACHINE_NAME, @beam.machine) @dcm.add_element(RADIATION_MACHINE_SAD, @beam.sad) @dcm.add_element(RADIATION_MACHINE_SSD, @beam.sad) @dcm.add_element(RT_IMAGE_SID, @beam.sad) # FIXME: Add Exposure sequence as well (with Jaw and MLC position information) # Group 300A: @dcm.add_element(DOSIMETER_UNIT, @beam.unit) @dcm.add_element(GANTRY_ANGLE, @beam.control_points[0].gantry_angle) @dcm.add_element(COLL_ANGLE, @beam.control_points[0].collimator_angle) @dcm.add_element(PEDESTAL_ANGLE, @beam.control_points[0].pedestal_angle) @dcm.add_element(TABLE_TOP_ANGLE, @beam.control_points[0].table_top_angle) @dcm.add_element(ISO_POS, @beam.control_points[0].iso.to_s) @dcm.add_element(GANTRY_PITCH_ANGLE, '0.0') # Group 300C: s = @dcm.add_sequence(REF_PLAN_SQ) i = s.add_item i.add_element(REF_SOP_CLASS_UID, @beam.plan.class_uid) i.add_element(REF_SOP_UID, @beam.plan.sop_uid) @dcm.add_element(REF_BEAM_NUMBER, @beam.number) end end
[ "def", "create_projection_image_dicom_scaffold", "unless", "@dcm", "create_general_dicom_image_scaffold", "@dcm", ".", "add_element", "(", "RT_IMAGE_LABEL", ",", "@beam", ".", "description", ")", "@dcm", ".", "add_element", "(", "RT_IMAGE_NAME", ",", "@beam", ".", "name", ")", "@dcm", ".", "add_element", "(", "RT_IMAGE_DESCRIPTION", ",", "@beam", ".", "plan", ".", "name", ")", "@dcm", ".", "add_element", "(", "RT_IMAGE_PLANE", ",", "'NORMAL'", ")", "@dcm", ".", "add_element", "(", "X_RAY_IMAGE_RECEPTOR_TRANSLATION", ",", "''", ")", "@dcm", ".", "add_element", "(", "X_RAY_IMAGE_RECEPTOR_ANGLE", ",", "''", ")", "@dcm", ".", "add_element", "(", "RADIATION_MACHINE_NAME", ",", "@beam", ".", "machine", ")", "@dcm", ".", "add_element", "(", "RADIATION_MACHINE_SAD", ",", "@beam", ".", "sad", ")", "@dcm", ".", "add_element", "(", "RADIATION_MACHINE_SSD", ",", "@beam", ".", "sad", ")", "@dcm", ".", "add_element", "(", "RT_IMAGE_SID", ",", "@beam", ".", "sad", ")", "@dcm", ".", "add_element", "(", "DOSIMETER_UNIT", ",", "@beam", ".", "unit", ")", "@dcm", ".", "add_element", "(", "GANTRY_ANGLE", ",", "@beam", ".", "control_points", "[", "0", "]", ".", "gantry_angle", ")", "@dcm", ".", "add_element", "(", "COLL_ANGLE", ",", "@beam", ".", "control_points", "[", "0", "]", ".", "collimator_angle", ")", "@dcm", ".", "add_element", "(", "PEDESTAL_ANGLE", ",", "@beam", ".", "control_points", "[", "0", "]", ".", "pedestal_angle", ")", "@dcm", ".", "add_element", "(", "TABLE_TOP_ANGLE", ",", "@beam", ".", "control_points", "[", "0", "]", ".", "table_top_angle", ")", "@dcm", ".", "add_element", "(", "ISO_POS", ",", "@beam", ".", "control_points", "[", "0", "]", ".", "iso", ".", "to_s", ")", "@dcm", ".", "add_element", "(", "GANTRY_PITCH_ANGLE", ",", "'0.0'", ")", "s", "=", "@dcm", ".", "add_sequence", "(", "REF_PLAN_SQ", ")", "i", "=", "s", ".", "add_item", "i", ".", "add_element", "(", "REF_SOP_CLASS_UID", ",", "@beam", ".", "plan", ".", "class_uid", ")", "i", ".", "add_element", "(", "REF_SOP_UID", ",", "@beam", ".", "plan", ".", "sop_uid", ")", "@dcm", ".", "add_element", "(", "REF_BEAM_NUMBER", ",", "@beam", ".", "number", ")", "end", "end" ]
Creates a new DICOM object with a set of basic attributes needed for a valid DICOM file of modality RTIMAGE.
[ "Creates", "a", "new", "DICOM", "object", "with", "a", "set", "of", "basic", "attributes", "needed", "for", "a", "valid", "DICOM", "file", "of", "modality", "RTIMAGE", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/projection_image.rb#L152-L186
train
dicom/rtkit
lib/rtkit/dose_distribution.rb
RTKIT.DoseDistribution.d
def d(percent) raise RangeError, "Argument 'percent' must be in the range [0-100]." if percent.to_f < 0 or percent.to_f > 100 d_index = ((@doses.length - 1) * (1 - percent.to_f * 0.01)).round return @doses[d_index] end
ruby
def d(percent) raise RangeError, "Argument 'percent' must be in the range [0-100]." if percent.to_f < 0 or percent.to_f > 100 d_index = ((@doses.length - 1) * (1 - percent.to_f * 0.01)).round return @doses[d_index] end
[ "def", "d", "(", "percent", ")", "raise", "RangeError", ",", "\"Argument 'percent' must be in the range [0-100].\"", "if", "percent", ".", "to_f", "<", "0", "or", "percent", ".", "to_f", ">", "100", "d_index", "=", "(", "(", "@doses", ".", "length", "-", "1", ")", "*", "(", "1", "-", "percent", ".", "to_f", "*", "0.01", ")", ")", ".", "round", "return", "@doses", "[", "d_index", "]", "end" ]
Calculates the dose that at least the specified percentage of the volume receives. @param [#to_f] percent a percentage (number in the range 0-100) @return [Float] the corresponding dose (in units of Gy) @example Calculate the near minimum dose (e.g. up to 2 % of the volume receives a dose less than this): near_min = ptv_distribution.d(98) @example Calculate the near maximum dose (e.g. at most 2 % of the volume receives a dose higher than this): near_max = ptv_distribution.d(2)
[ "Calculates", "the", "dose", "that", "at", "least", "the", "specified", "percentage", "of", "the", "volume", "receives", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/dose_distribution.rb#L80-L84
train
dicom/rtkit
lib/rtkit/dose_distribution.rb
RTKIT.DoseDistribution.v
def v(dose) raise RangeError, "Argument 'dose' cannot be negative." if dose.to_f < 0 # How many dose values are higher than the threshold? num_above = (@doses.ge dose.to_f).where.length # Divide by total number of elements and convert to percentage: return num_above / @doses.length.to_f * 100 end
ruby
def v(dose) raise RangeError, "Argument 'dose' cannot be negative." if dose.to_f < 0 # How many dose values are higher than the threshold? num_above = (@doses.ge dose.to_f).where.length # Divide by total number of elements and convert to percentage: return num_above / @doses.length.to_f * 100 end
[ "def", "v", "(", "dose", ")", "raise", "RangeError", ",", "\"Argument 'dose' cannot be negative.\"", "if", "dose", ".", "to_f", "<", "0", "num_above", "=", "(", "@doses", ".", "ge", "dose", ".", "to_f", ")", ".", "where", ".", "length", "return", "num_above", "/", "@doses", ".", "length", ".", "to_f", "*", "100", "end" ]
Calculates the percentage of the volume that receives a dose higher than or equal to the specified dose. @param [#to_f] dose the dose threshold value to apply to the dose distribution (in units of Gy) @return [Float] the corresponding percentage @example Calculate the low dose spread (e.g. the percentage of the lung that receives a dose higher than 5 Gy): coverage_low = lung_distribution.v(5) @example Calculate the high dose spread (e.g. the percentage of the lung that receives a dose higher than 20 Gy): coverage_high = lung_distribution.v(20)
[ "Calculates", "the", "percentage", "of", "the", "volume", "that", "receives", "a", "dose", "higher", "than", "or", "equal", "to", "the", "specified", "dose", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/dose_distribution.rb#L203-L209
train
slagyr/limelight
ruby/lib/limelight/stage.rb
Limelight.Stage.size=
def size=(*values) values = values[0] if values.size == 1 && values[0].is_a?(Array) @peer.set_size_styles(values[0], values[1]) end
ruby
def size=(*values) values = values[0] if values.size == 1 && values[0].is_a?(Array) @peer.set_size_styles(values[0], values[1]) end
[ "def", "size", "=", "(", "*", "values", ")", "values", "=", "values", "[", "0", "]", "if", "values", ".", "size", "==", "1", "&&", "values", "[", "0", "]", ".", "is_a?", "(", "Array", ")", "@peer", ".", "set_size_styles", "(", "values", "[", "0", "]", ",", "values", "[", "1", "]", ")", "end" ]
Sets the width and height styles of the Stage. state.size = [100, 200] state.size = ["50%", "100%"] # consuming 50% of the width and 100% of the height of the screen
[ "Sets", "the", "width", "and", "height", "styles", "of", "the", "Stage", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/stage.rb#L76-L79
train
slagyr/limelight
ruby/lib/limelight/stage.rb
Limelight.Stage.location=
def location=(*values) values = values[0] if values.size == 1 && values[0].is_a?(Array) @peer.set_location_styles(values[0], values[1]) end
ruby
def location=(*values) values = values[0] if values.size == 1 && values[0].is_a?(Array) @peer.set_location_styles(values[0], values[1]) end
[ "def", "location", "=", "(", "*", "values", ")", "values", "=", "values", "[", "0", "]", "if", "values", ".", "size", "==", "1", "&&", "values", "[", "0", "]", ".", "is_a?", "(", "Array", ")", "@peer", ".", "set_location_styles", "(", "values", "[", "0", "]", ",", "values", "[", "1", "]", ")", "end" ]
Sets the location styles of the Stage. stage.location = [500, 200]
[ "Sets", "the", "location", "styles", "of", "the", "Stage", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/stage.rb#L93-L96
train
slagyr/limelight
ruby/lib/limelight/stage.rb
Limelight.Stage.alert
def alert(message) Thread.new do begin Java::limelight.Context.instance.studio.utilities_production.alert(message) rescue StandardError => e puts "Error on alert: #{e}" end end end
ruby
def alert(message) Thread.new do begin Java::limelight.Context.instance.studio.utilities_production.alert(message) rescue StandardError => e puts "Error on alert: #{e}" end end end
[ "def", "alert", "(", "message", ")", "Thread", ".", "new", "do", "begin", "Java", "::", "limelight", ".", "Context", ".", "instance", ".", "studio", ".", "utilities_production", ".", "alert", "(", "message", ")", "rescue", "StandardError", "=>", "e", "puts", "\"Error on alert: #{e}\"", "end", "end", "end" ]
Pops up a simple modal dialog with the provided message.
[ "Pops", "up", "a", "simple", "modal", "dialog", "with", "the", "provided", "message", "." ]
2e8db684771587422d55a9329e895481e9b56a26
https://github.com/slagyr/limelight/blob/2e8db684771587422d55a9329e895481e9b56a26/ruby/lib/limelight/stage.rb#L234-L242
train
dicom/rtkit
lib/rtkit/image_series.rb
RTKIT.ImageSeries.add_image
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) @images << image unless @frame.image(image.uid) @slices[image.uid] = image.pos_slice @image_positions[image.pos_slice.round(2)] = image @sop_uids[image.pos_slice] = image.uid # The link between image uid and image instance is kept in the Frame, instead of the ImageSeries: @frame.add_image(image) unless @frame.image(image.uid) end
ruby
def add_image(image) raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image) @images << image unless @frame.image(image.uid) @slices[image.uid] = image.pos_slice @image_positions[image.pos_slice.round(2)] = image @sop_uids[image.pos_slice] = image.uid # The link between image uid and image instance is kept in the Frame, instead of the ImageSeries: @frame.add_image(image) unless @frame.image(image.uid) end
[ "def", "add_image", "(", "image", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected Image, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "Image", ")", "@images", "<<", "image", "unless", "@frame", ".", "image", "(", "image", ".", "uid", ")", "@slices", "[", "image", ".", "uid", "]", "=", "image", ".", "pos_slice", "@image_positions", "[", "image", ".", "pos_slice", ".", "round", "(", "2", ")", "]", "=", "image", "@sop_uids", "[", "image", ".", "pos_slice", "]", "=", "image", ".", "uid", "@frame", ".", "add_image", "(", "image", ")", "unless", "@frame", ".", "image", "(", "image", ".", "uid", ")", "end" ]
Adds an Image to this ImageSeries. @param [Image] image an image instance to be associated with this image series
[ "Adds", "an", "Image", "to", "this", "ImageSeries", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image_series.rb#L119-L127
train
dicom/rtkit
lib/rtkit/image_series.rb
RTKIT.ImageSeries.add_struct
def add_struct(struct) raise ArgumentError, "Invalid argument 'struct'. Expected StructureSet, got #{struct.class}." unless struct.is_a?(StructureSet) # Do not add it again if the struct already belongs to this instance: @structs << struct unless @associated_structs[struct.uid] @associated_structs[struct.uid] = struct end
ruby
def add_struct(struct) raise ArgumentError, "Invalid argument 'struct'. Expected StructureSet, got #{struct.class}." unless struct.is_a?(StructureSet) # Do not add it again if the struct already belongs to this instance: @structs << struct unless @associated_structs[struct.uid] @associated_structs[struct.uid] = struct end
[ "def", "add_struct", "(", "struct", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'struct'. Expected StructureSet, got #{struct.class}.\"", "unless", "struct", ".", "is_a?", "(", "StructureSet", ")", "@structs", "<<", "struct", "unless", "@associated_structs", "[", "struct", ".", "uid", "]", "@associated_structs", "[", "struct", ".", "uid", "]", "=", "struct", "end" ]
Adds a StructureSet to this ImageSeries. @param [Image] struct a structure set instance to be associated with this image series
[ "Adds", "a", "StructureSet", "to", "this", "ImageSeries", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image_series.rb#L133-L138
train
dicom/rtkit
lib/rtkit/image_series.rb
RTKIT.ImageSeries.match_image
def match_image(plane) raise ArgumentError, "Invalid argument 'plane'. Expected Plane, got #{plane.class}." unless plane.is_a?(Plane) matching_image = nil planes_in_series = Array.new @images.each do |image| # Get three coordinates from the image: col_indices = NArray.to_na([0,image.columns/2, image.columns-1]) row_indices = NArray.to_na([image.rows/2, image.rows-1, 0]) x, y, z = image.coordinates_from_indices(col_indices, row_indices) coordinates = Array.new x.length.times do |i| coordinates << Coordinate.new(x[i], y[i], z[i]) end # Determine the image plane: planes_in_series << Plane.calculate(coordinates[0], coordinates[1], coordinates[2]) end # Search for a match amongst the planes of this series: index = plane.match(planes_in_series) matching_image = @images[index] if index return matching_image end
ruby
def match_image(plane) raise ArgumentError, "Invalid argument 'plane'. Expected Plane, got #{plane.class}." unless plane.is_a?(Plane) matching_image = nil planes_in_series = Array.new @images.each do |image| # Get three coordinates from the image: col_indices = NArray.to_na([0,image.columns/2, image.columns-1]) row_indices = NArray.to_na([image.rows/2, image.rows-1, 0]) x, y, z = image.coordinates_from_indices(col_indices, row_indices) coordinates = Array.new x.length.times do |i| coordinates << Coordinate.new(x[i], y[i], z[i]) end # Determine the image plane: planes_in_series << Plane.calculate(coordinates[0], coordinates[1], coordinates[2]) end # Search for a match amongst the planes of this series: index = plane.match(planes_in_series) matching_image = @images[index] if index return matching_image end
[ "def", "match_image", "(", "plane", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'plane'. Expected Plane, got #{plane.class}.\"", "unless", "plane", ".", "is_a?", "(", "Plane", ")", "matching_image", "=", "nil", "planes_in_series", "=", "Array", ".", "new", "@images", ".", "each", "do", "|", "image", "|", "col_indices", "=", "NArray", ".", "to_na", "(", "[", "0", ",", "image", ".", "columns", "/", "2", ",", "image", ".", "columns", "-", "1", "]", ")", "row_indices", "=", "NArray", ".", "to_na", "(", "[", "image", ".", "rows", "/", "2", ",", "image", ".", "rows", "-", "1", ",", "0", "]", ")", "x", ",", "y", ",", "z", "=", "image", ".", "coordinates_from_indices", "(", "col_indices", ",", "row_indices", ")", "coordinates", "=", "Array", ".", "new", "x", ".", "length", ".", "times", "do", "|", "i", "|", "coordinates", "<<", "Coordinate", ".", "new", "(", "x", "[", "i", "]", ",", "y", "[", "i", "]", ",", "z", "[", "i", "]", ")", "end", "planes_in_series", "<<", "Plane", ".", "calculate", "(", "coordinates", "[", "0", "]", ",", "coordinates", "[", "1", "]", ",", "coordinates", "[", "2", "]", ")", "end", "index", "=", "plane", ".", "match", "(", "planes_in_series", ")", "matching_image", "=", "@images", "[", "index", "]", "if", "index", "return", "matching_image", "end" ]
Analyses the images belonging to this ImageSeries to determine if there is any image with a geometry that matches the specified plane. @param [Plane] plane an image plane to be compared against the associated images @return [SliceImage, NilClass] the matched image (or nil if no image is matched)
[ "Analyses", "the", "images", "belonging", "to", "this", "ImageSeries", "to", "determine", "if", "there", "is", "any", "image", "with", "a", "geometry", "that", "matches", "the", "specified", "plane", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image_series.rb#L213-L233
train
dicom/rtkit
lib/rtkit/image_series.rb
RTKIT.ImageSeries.set_resolution
def set_resolution(columns, rows, options={}) @images.each do |img| img.set_resolution(columns, rows, options) end end
ruby
def set_resolution(columns, rows, options={}) @images.each do |img| img.set_resolution(columns, rows, options) end end
[ "def", "set_resolution", "(", "columns", ",", "rows", ",", "options", "=", "{", "}", ")", "@images", ".", "each", "do", "|", "img", "|", "img", ".", "set_resolution", "(", "columns", ",", "rows", ",", "options", ")", "end", "end" ]
Sets the resolution of the associated images. The images will either be expanded or cropped depending on whether the specified resolution is bigger or smaller than the existing one. @param [Integer] columns the number of columns in the resized images @param [Integer] rows the number of rows in the resized images @param [Hash] options the options to use for changing the image resolution @option options [Float] :hor the side (in the horisontal image direction) at which to apply the crop/border operation (:left, :right or :even (default)) @option options [Float] :ver the side (in the vertical image direction) at which to apply the crop/border operation (:bottom, :top or :even (default))
[ "Sets", "the", "resolution", "of", "the", "associated", "images", ".", "The", "images", "will", "either", "be", "expanded", "or", "cropped", "depending", "on", "whether", "the", "specified", "resolution", "is", "bigger", "or", "smaller", "than", "the", "existing", "one", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image_series.rb#L245-L249
train
dicom/rtkit
lib/rtkit/image_series.rb
RTKIT.ImageSeries.struct
def struct(*args) raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length) if args.length == 1 raise ArgumentError, "Expected String (or nil), got #{args.first.class}." unless [String, NilClass].include?(args.first.class) return @associated_structs[args.first] else # No argument used, therefore we return the first StructureSet instance: return @structs.first end end
ruby
def struct(*args) raise ArgumentError, "Expected one or none arguments, got #{args.length}." unless [0, 1].include?(args.length) if args.length == 1 raise ArgumentError, "Expected String (or nil), got #{args.first.class}." unless [String, NilClass].include?(args.first.class) return @associated_structs[args.first] else # No argument used, therefore we return the first StructureSet instance: return @structs.first end end
[ "def", "struct", "(", "*", "args", ")", "raise", "ArgumentError", ",", "\"Expected one or none arguments, got #{args.length}.\"", "unless", "[", "0", ",", "1", "]", ".", "include?", "(", "args", ".", "length", ")", "if", "args", ".", "length", "==", "1", "raise", "ArgumentError", ",", "\"Expected String (or nil), got #{args.first.class}.\"", "unless", "[", "String", ",", "NilClass", "]", ".", "include?", "(", "args", ".", "first", ".", "class", ")", "return", "@associated_structs", "[", "args", ".", "first", "]", "else", "return", "@structs", ".", "first", "end", "end" ]
Gives the StructureSet instance mathcing the specified UID. @overload struct(uid) @param [String] uid the structure set SOP instance UID @return [StructureSet, NilClass] the matched structure set (or nil if no structure set is matched) @overload struct @return [StructureSet, NilClass] the first structure set of this instance (or nil if no child structure sets exists)
[ "Gives", "the", "StructureSet", "instance", "mathcing", "the", "specified", "UID", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/image_series.rb#L259-L268
train
dicom/rtkit
lib/rtkit/drr/pixel_space.rb
RTKIT.PixelSpace.coordinate
def coordinate(i, j) x = @pos.x + (i * @delta_col * @cosines[0]) + (j * @delta_row * @cosines[3]) y = @pos.y + (i * @delta_col * @cosines[1]) + (j * @delta_row * @cosines[4]) z = @pos.z + (i * @delta_col * @cosines[2]) + (j * @delta_row * @cosines[5]) Coordinate.new(x, y, z) end
ruby
def coordinate(i, j) x = @pos.x + (i * @delta_col * @cosines[0]) + (j * @delta_row * @cosines[3]) y = @pos.y + (i * @delta_col * @cosines[1]) + (j * @delta_row * @cosines[4]) z = @pos.z + (i * @delta_col * @cosines[2]) + (j * @delta_row * @cosines[5]) Coordinate.new(x, y, z) end
[ "def", "coordinate", "(", "i", ",", "j", ")", "x", "=", "@pos", ".", "x", "+", "(", "i", "*", "@delta_col", "*", "@cosines", "[", "0", "]", ")", "+", "(", "j", "*", "@delta_row", "*", "@cosines", "[", "3", "]", ")", "y", "=", "@pos", ".", "y", "+", "(", "i", "*", "@delta_col", "*", "@cosines", "[", "1", "]", ")", "+", "(", "j", "*", "@delta_row", "*", "@cosines", "[", "4", "]", ")", "z", "=", "@pos", ".", "z", "+", "(", "i", "*", "@delta_col", "*", "@cosines", "[", "2", "]", ")", "+", "(", "j", "*", "@delta_row", "*", "@cosines", "[", "5", "]", ")", "Coordinate", ".", "new", "(", "x", ",", "y", ",", "z", ")", "end" ]
Calculates the cartesian coordinate of the given pixel index pair. @param [Integer] i the image column index @param [Integer] j the image row index @return [Coordinate] the cartesian coordinate of the pixel
[ "Calculates", "the", "cartesian", "coordinate", "of", "the", "given", "pixel", "index", "pair", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/pixel_space.rb#L118-L123
train
dicom/rtkit
lib/rtkit/drr/pixel_space.rb
RTKIT.PixelSpace.cosines=
def cosines=(array) raise ArgumentError, "Invalid parameter 'array'. Exactly 6 elements needed, got #{array.length}" unless array.length == 6 @cosines = array.collect {|val| val.to_f} end
ruby
def cosines=(array) raise ArgumentError, "Invalid parameter 'array'. Exactly 6 elements needed, got #{array.length}" unless array.length == 6 @cosines = array.collect {|val| val.to_f} end
[ "def", "cosines", "=", "(", "array", ")", "raise", "ArgumentError", ",", "\"Invalid parameter 'array'. Exactly 6 elements needed, got #{array.length}\"", "unless", "array", ".", "length", "==", "6", "@cosines", "=", "array", ".", "collect", "{", "|", "val", "|", "val", ".", "to_f", "}", "end" ]
Sets the cosines attribute. @param [Array<Float>] array the 6 directional cosines which describes the orientation of the image
[ "Sets", "the", "cosines", "attribute", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/drr/pixel_space.rb#L129-L132
train
dicom/rtkit
lib/rtkit/slice_image.rb
RTKIT.SliceImage.binary_image
def binary_image(coords_x, coords_y, coords_z) # FIXME: Should we test whether the coordinates go outside the bounds of this image, and # give a descriptive warning/error instead of letting the code crash with a more cryptic error?! raise ArgumentError, "Invalid argument 'coords_x'. Expected at least 3 elements, got #{coords_x.length}" unless coords_x.length >= 3 raise ArgumentError, "Invalid argument 'coords_y'. Expected at least 3 elements, got #{coords_y.length}" unless coords_y.length >= 3 raise ArgumentError, "Invalid argument 'coords_z'. Expected at least 3 elements, got #{coords_z.length}" unless coords_z.length >= 3 # Values that will be used for image geometry: empty_value = 0 line_value = 1 fill_value = 2 # Convert physical coordinates to image indices: column_indices, row_indices = coordinates_to_indices(NArray.to_na(coords_x), NArray.to_na(coords_y), NArray.to_na(coords_z)) # Create an empty array and fill in the gathered points: empty_array = NArray.byte(@columns, @rows) delineated_array = draw_lines(column_indices.to_a, row_indices.to_a, empty_array, line_value) # Establish starting point indices for the coming flood fill algorithm: # (Using a rather simple approach by finding the average column and row index among the selection of indices) start_col = column_indices.mean start_row = row_indices.mean # Perform a flood fill to enable us to extract all pixels contained in a specific ROI: filled_array = flood_fill(start_col, start_row, delineated_array, fill_value) # Extract the indices of 'ROI pixels': if filled_array[0,0] != fill_value # ROI has been filled as expected. Extract indices of value line_value and fill_value: filled_array[(filled_array.eq line_value).where] = fill_value indices = (filled_array.eq fill_value).where else # An inversion has occured. The entire image except our ROI has been filled. Extract indices of value line_value and empty_value: filled_array[(filled_array.eq line_value).where] = empty_value indices = (filled_array.eq empty_value).where end # Create binary image: bin_image = NArray.byte(@columns, @rows) bin_image[indices] = 1 return bin_image end
ruby
def binary_image(coords_x, coords_y, coords_z) # FIXME: Should we test whether the coordinates go outside the bounds of this image, and # give a descriptive warning/error instead of letting the code crash with a more cryptic error?! raise ArgumentError, "Invalid argument 'coords_x'. Expected at least 3 elements, got #{coords_x.length}" unless coords_x.length >= 3 raise ArgumentError, "Invalid argument 'coords_y'. Expected at least 3 elements, got #{coords_y.length}" unless coords_y.length >= 3 raise ArgumentError, "Invalid argument 'coords_z'. Expected at least 3 elements, got #{coords_z.length}" unless coords_z.length >= 3 # Values that will be used for image geometry: empty_value = 0 line_value = 1 fill_value = 2 # Convert physical coordinates to image indices: column_indices, row_indices = coordinates_to_indices(NArray.to_na(coords_x), NArray.to_na(coords_y), NArray.to_na(coords_z)) # Create an empty array and fill in the gathered points: empty_array = NArray.byte(@columns, @rows) delineated_array = draw_lines(column_indices.to_a, row_indices.to_a, empty_array, line_value) # Establish starting point indices for the coming flood fill algorithm: # (Using a rather simple approach by finding the average column and row index among the selection of indices) start_col = column_indices.mean start_row = row_indices.mean # Perform a flood fill to enable us to extract all pixels contained in a specific ROI: filled_array = flood_fill(start_col, start_row, delineated_array, fill_value) # Extract the indices of 'ROI pixels': if filled_array[0,0] != fill_value # ROI has been filled as expected. Extract indices of value line_value and fill_value: filled_array[(filled_array.eq line_value).where] = fill_value indices = (filled_array.eq fill_value).where else # An inversion has occured. The entire image except our ROI has been filled. Extract indices of value line_value and empty_value: filled_array[(filled_array.eq line_value).where] = empty_value indices = (filled_array.eq empty_value).where end # Create binary image: bin_image = NArray.byte(@columns, @rows) bin_image[indices] = 1 return bin_image end
[ "def", "binary_image", "(", "coords_x", ",", "coords_y", ",", "coords_z", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'coords_x'. Expected at least 3 elements, got #{coords_x.length}\"", "unless", "coords_x", ".", "length", ">=", "3", "raise", "ArgumentError", ",", "\"Invalid argument 'coords_y'. Expected at least 3 elements, got #{coords_y.length}\"", "unless", "coords_y", ".", "length", ">=", "3", "raise", "ArgumentError", ",", "\"Invalid argument 'coords_z'. Expected at least 3 elements, got #{coords_z.length}\"", "unless", "coords_z", ".", "length", ">=", "3", "empty_value", "=", "0", "line_value", "=", "1", "fill_value", "=", "2", "column_indices", ",", "row_indices", "=", "coordinates_to_indices", "(", "NArray", ".", "to_na", "(", "coords_x", ")", ",", "NArray", ".", "to_na", "(", "coords_y", ")", ",", "NArray", ".", "to_na", "(", "coords_z", ")", ")", "empty_array", "=", "NArray", ".", "byte", "(", "@columns", ",", "@rows", ")", "delineated_array", "=", "draw_lines", "(", "column_indices", ".", "to_a", ",", "row_indices", ".", "to_a", ",", "empty_array", ",", "line_value", ")", "start_col", "=", "column_indices", ".", "mean", "start_row", "=", "row_indices", ".", "mean", "filled_array", "=", "flood_fill", "(", "start_col", ",", "start_row", ",", "delineated_array", ",", "fill_value", ")", "if", "filled_array", "[", "0", ",", "0", "]", "!=", "fill_value", "filled_array", "[", "(", "filled_array", ".", "eq", "line_value", ")", ".", "where", "]", "=", "fill_value", "indices", "=", "(", "filled_array", ".", "eq", "fill_value", ")", ".", "where", "else", "filled_array", "[", "(", "filled_array", ".", "eq", "line_value", ")", ".", "where", "]", "=", "empty_value", "indices", "=", "(", "filled_array", ".", "eq", "empty_value", ")", ".", "where", "end", "bin_image", "=", "NArray", ".", "byte", "(", "@columns", ",", "@rows", ")", "bin_image", "[", "indices", "]", "=", "1", "return", "bin_image", "end" ]
Creates a new SliceImage instance. The SOP Instance UID tag value is used to uniquely identify an image. @param [String] sop_uid the SOP Instance UID value @param [String] pos_slice the slice position of this image @param [Series] series the Series instance which this SliceImage is associated with @raise [ArgumentError] if the referenced series doesn't have a slice image type modality Creates a filled, binary NArray image ('segmented' image) based on the provided contour coordinates. @param [Array, NArray] coords_x the contour's x coordinates @param [Array, NArray] coords_y the contour's y coordinates @param [Array, NArray] coords_z the contour's z coordinates @return [BinImage] a filled, binary image @raise [ArgumentError] if any of the coordinate arrays have less than 3 elements
[ "Creates", "a", "new", "SliceImage", "instance", ".", "The", "SOP", "Instance", "UID", "tag", "value", "is", "used", "to", "uniquely", "identify", "an", "image", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/slice_image.rb#L68-L103
train
dicom/rtkit
lib/rtkit/slice_image.rb
RTKIT.SliceImage.to_dcm
def to_dcm # Setup general dicom image attributes: create_slice_image_dicom_scaffold update_dicom_image # Add/update tags that are specific for the slice image type: @dcm.add_element(IMAGE_POSITION, [@pos_x, @pos_y, @pos_slice].join("\\")) @dcm.add_element(SPACING, [@row_spacing, @col_spacing].join("\\")) @dcm.add_element(IMAGE_ORIENTATION, [@cosines].join("\\")) @dcm end
ruby
def to_dcm # Setup general dicom image attributes: create_slice_image_dicom_scaffold update_dicom_image # Add/update tags that are specific for the slice image type: @dcm.add_element(IMAGE_POSITION, [@pos_x, @pos_y, @pos_slice].join("\\")) @dcm.add_element(SPACING, [@row_spacing, @col_spacing].join("\\")) @dcm.add_element(IMAGE_ORIENTATION, [@cosines].join("\\")) @dcm end
[ "def", "to_dcm", "create_slice_image_dicom_scaffold", "update_dicom_image", "@dcm", ".", "add_element", "(", "IMAGE_POSITION", ",", "[", "@pos_x", ",", "@pos_y", ",", "@pos_slice", "]", ".", "join", "(", "\"\\\\\"", ")", ")", "@dcm", ".", "add_element", "(", "SPACING", ",", "[", "@row_spacing", ",", "@col_spacing", "]", ".", "join", "(", "\"\\\\\"", ")", ")", "@dcm", ".", "add_element", "(", "IMAGE_ORIENTATION", ",", "[", "@cosines", "]", ".", "join", "(", "\"\\\\\"", ")", ")", "@dcm", "end" ]
Converts the Image instance to a DICOM object. @note This method uses the image's original DICOM object (if present), and updates it with attributes from the image instance. @return [DICOM::DObject] the processed DICOM object
[ "Converts", "the", "Image", "instance", "to", "a", "DICOM", "object", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/slice_image.rb#L170-L179
train
dicom/rtkit
lib/rtkit/bin_volume.rb
RTKIT.BinVolume.to_roi
def to_roi(struct, options={}) raise ArgumentError, "Invalid argument 'struct'. Expected StructureSet, got #{struct.class}." unless struct.is_a?(StructureSet) # Set values: algorithm = options[:algorithm] name = options[:name] || 'BinVolume' number = options[:number] interpreter = options[:interpreter] type = options[:type] # Create the ROI: roi = struct.create_roi(@series.frame, :algorithm => algorithm, :name => name, :number => number, :interpreter => interpreter, :type => type) # Create Slices: @bin_images.each do |bin_image| bin_image.to_slice(roi) end return roi end
ruby
def to_roi(struct, options={}) raise ArgumentError, "Invalid argument 'struct'. Expected StructureSet, got #{struct.class}." unless struct.is_a?(StructureSet) # Set values: algorithm = options[:algorithm] name = options[:name] || 'BinVolume' number = options[:number] interpreter = options[:interpreter] type = options[:type] # Create the ROI: roi = struct.create_roi(@series.frame, :algorithm => algorithm, :name => name, :number => number, :interpreter => interpreter, :type => type) # Create Slices: @bin_images.each do |bin_image| bin_image.to_slice(roi) end return roi end
[ "def", "to_roi", "(", "struct", ",", "options", "=", "{", "}", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'struct'. Expected StructureSet, got #{struct.class}.\"", "unless", "struct", ".", "is_a?", "(", "StructureSet", ")", "algorithm", "=", "options", "[", ":algorithm", "]", "name", "=", "options", "[", ":name", "]", "||", "'BinVolume'", "number", "=", "options", "[", ":number", "]", "interpreter", "=", "options", "[", ":interpreter", "]", "type", "=", "options", "[", ":type", "]", "roi", "=", "struct", ".", "create_roi", "(", "@series", ".", "frame", ",", ":algorithm", "=>", "algorithm", ",", ":name", "=>", "name", ",", ":number", "=>", "number", ",", ":interpreter", "=>", "interpreter", ",", ":type", "=>", "type", ")", "@bin_images", ".", "each", "do", "|", "bin_image", "|", "bin_image", ".", "to_slice", "(", "roi", ")", "end", "return", "roi", "end" ]
Creates a ROI instance from the segmentation of this BinVolume. @param [StructureSet] struct the structure set instance which the created ROI will be associated with @param [Hash] options the options to use for creating the ROI @option options [String] :algorithm the ROI generation algorithm (defaults to 'STATIC') @option options [String] :name the ROI name (defaults to 'BinVolume') @option options [Integer] :number the ROI number (defaults to the first available ROI Number in the StructureSet) @option options [String] :interpreter the ROI interpreter (defaults to 'RTKIT') @option options [String] :type the ROI interpreted type (defaults to 'CONTROL') @return [ROI] the created ROI instance (including slice references from the associated binary images)
[ "Creates", "a", "ROI", "instance", "from", "the", "segmentation", "of", "this", "BinVolume", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_volume.rb#L250-L265
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.narray=
def narray=(image) raise ArgumentError, "Invalid argument 'image'. Expected NArray, got #{image.class}." unless image.is_a?(NArray) raise ArgumentError, "Invalid argument 'image'. Expected two-dimensional NArray, got #{image.shape.length} dimensions." unless image.shape.length == 2 raise ArgumentError, "Invalid argument 'image'. Expected NArray of element size 1 byte, got #{image.element_size} bytes (per element)." unless image.element_size == 1 raise ArgumentError, "Invalid argument 'image'. Expected binary NArray with max value 1, got #{image.max} as max." if image.max > 1 @narray = image # Create a corresponding array of the image indices (used in image processing): @narray_indices = NArray.int(columns, rows).indgen! end
ruby
def narray=(image) raise ArgumentError, "Invalid argument 'image'. Expected NArray, got #{image.class}." unless image.is_a?(NArray) raise ArgumentError, "Invalid argument 'image'. Expected two-dimensional NArray, got #{image.shape.length} dimensions." unless image.shape.length == 2 raise ArgumentError, "Invalid argument 'image'. Expected NArray of element size 1 byte, got #{image.element_size} bytes (per element)." unless image.element_size == 1 raise ArgumentError, "Invalid argument 'image'. Expected binary NArray with max value 1, got #{image.max} as max." if image.max > 1 @narray = image # Create a corresponding array of the image indices (used in image processing): @narray_indices = NArray.int(columns, rows).indgen! end
[ "def", "narray", "=", "(", "image", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected NArray, got #{image.class}.\"", "unless", "image", ".", "is_a?", "(", "NArray", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected two-dimensional NArray, got #{image.shape.length} dimensions.\"", "unless", "image", ".", "shape", ".", "length", "==", "2", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected NArray of element size 1 byte, got #{image.element_size} bytes (per element).\"", "unless", "image", ".", "element_size", "==", "1", "raise", "ArgumentError", ",", "\"Invalid argument 'image'. Expected binary NArray with max value 1, got #{image.max} as max.\"", "if", "image", ".", "max", ">", "1", "@narray", "=", "image", "@narray_indices", "=", "NArray", ".", "int", "(", "columns", ",", "rows", ")", ".", "indgen!", "end" ]
Sets a new binary array for this BinImage instance. @param [NArray] image a binary two-dimensional array
[ "Sets", "a", "new", "binary", "array", "for", "this", "BinImage", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L207-L215
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.to_contours
def to_contours(slice) raise ArgumentError, "Invalid argument 'slice. Expected Slice, got #{slice.class}." unless slice.is_a?(Slice) contours = Array.new # Iterate the extracted collection of contour indices and convert to Contour instances: contour_indices.each do |contour| # Convert column and row indices to X, Y and Z coordinates: x, y, z = coordinates_from_indices(NArray.to_na(contour.columns), NArray.to_na(contour.rows)) # Convert NArray to Array and round the coordinate floats: x = x.to_a.collect {|f| f.round(1)} y = y.to_a.collect {|f| f.round(1)} z = z.to_a.collect {|f| f.round(3)} contours << Contour.create_from_coordinates(x, y, z, slice) end return contours end
ruby
def to_contours(slice) raise ArgumentError, "Invalid argument 'slice. Expected Slice, got #{slice.class}." unless slice.is_a?(Slice) contours = Array.new # Iterate the extracted collection of contour indices and convert to Contour instances: contour_indices.each do |contour| # Convert column and row indices to X, Y and Z coordinates: x, y, z = coordinates_from_indices(NArray.to_na(contour.columns), NArray.to_na(contour.rows)) # Convert NArray to Array and round the coordinate floats: x = x.to_a.collect {|f| f.round(1)} y = y.to_a.collect {|f| f.round(1)} z = z.to_a.collect {|f| f.round(3)} contours << Contour.create_from_coordinates(x, y, z, slice) end return contours end
[ "def", "to_contours", "(", "slice", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'slice. Expected Slice, got #{slice.class}.\"", "unless", "slice", ".", "is_a?", "(", "Slice", ")", "contours", "=", "Array", ".", "new", "contour_indices", ".", "each", "do", "|", "contour", "|", "x", ",", "y", ",", "z", "=", "coordinates_from_indices", "(", "NArray", ".", "to_na", "(", "contour", ".", "columns", ")", ",", "NArray", ".", "to_na", "(", "contour", ".", "rows", ")", ")", "x", "=", "x", ".", "to_a", ".", "collect", "{", "|", "f", "|", "f", ".", "round", "(", "1", ")", "}", "y", "=", "y", ".", "to_a", ".", "collect", "{", "|", "f", "|", "f", ".", "round", "(", "1", ")", "}", "z", "=", "z", ".", "to_a", ".", "collect", "{", "|", "f", "|", "f", ".", "round", "(", "3", ")", "}", "contours", "<<", "Contour", ".", "create_from_coordinates", "(", "x", ",", "y", ",", "z", ",", "slice", ")", "end", "return", "contours", "end" ]
Creates an array of Contour instances from the segmentation of this BinImage. @param [Slice] slice the Slice instance which the created contours will be associated with @return [Array<Contour>] an array of contour instances (or an empty array if no contours are created)
[ "Creates", "an", "array", "of", "Contour", "instances", "from", "the", "segmentation", "of", "this", "BinImage", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L291-L305
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.to_dcm
def to_dcm # Use the original DICOM object as a starting point (keeping all non-sequence elements): # Note: Something like dcm.dup doesn't work here because that only performs a shallow copy on the DObject instance. dcm = DICOM::DObject.new @image.dcm.each_element do |element| # A bit of a hack to regenerate the DICOM elements: begin if element.value # ATM this fails for tags with integer values converted to a backslash-separated string: DICOM::Element.new(element.tag, element.value, :parent => dcm) else # Transfer the binary content as long as it is not the pixel data string: DICOM::Element.new(element.tag, element.bin, :encoded => true, :parent => dcm) end rescue DICOM::Element.new(element.tag, element.value.split("\\").collect {|val| val.to_i}, :parent => dcm) if element.value end end dcm.delete_group('0002') # Format the DICOM image ensure good contrast amongst the binary pixel values: # Window Center: DICOM::Element.new('0028,1050', '128', :parent => dcm) # Window Width: DICOM::Element.new('0028,1051', '256', :parent => dcm) # Rescale Intercept: DICOM::Element.new('0028,1052', '0', :parent => dcm) # Rescale Slope: DICOM::Element.new('0028,1053', '1', :parent => dcm) # Pixel data: dcm.pixels = @narray*255 return dcm end
ruby
def to_dcm # Use the original DICOM object as a starting point (keeping all non-sequence elements): # Note: Something like dcm.dup doesn't work here because that only performs a shallow copy on the DObject instance. dcm = DICOM::DObject.new @image.dcm.each_element do |element| # A bit of a hack to regenerate the DICOM elements: begin if element.value # ATM this fails for tags with integer values converted to a backslash-separated string: DICOM::Element.new(element.tag, element.value, :parent => dcm) else # Transfer the binary content as long as it is not the pixel data string: DICOM::Element.new(element.tag, element.bin, :encoded => true, :parent => dcm) end rescue DICOM::Element.new(element.tag, element.value.split("\\").collect {|val| val.to_i}, :parent => dcm) if element.value end end dcm.delete_group('0002') # Format the DICOM image ensure good contrast amongst the binary pixel values: # Window Center: DICOM::Element.new('0028,1050', '128', :parent => dcm) # Window Width: DICOM::Element.new('0028,1051', '256', :parent => dcm) # Rescale Intercept: DICOM::Element.new('0028,1052', '0', :parent => dcm) # Rescale Slope: DICOM::Element.new('0028,1053', '1', :parent => dcm) # Pixel data: dcm.pixels = @narray*255 return dcm end
[ "def", "to_dcm", "dcm", "=", "DICOM", "::", "DObject", ".", "new", "@image", ".", "dcm", ".", "each_element", "do", "|", "element", "|", "begin", "if", "element", ".", "value", "DICOM", "::", "Element", ".", "new", "(", "element", ".", "tag", ",", "element", ".", "value", ",", ":parent", "=>", "dcm", ")", "else", "DICOM", "::", "Element", ".", "new", "(", "element", ".", "tag", ",", "element", ".", "bin", ",", ":encoded", "=>", "true", ",", ":parent", "=>", "dcm", ")", "end", "rescue", "DICOM", "::", "Element", ".", "new", "(", "element", ".", "tag", ",", "element", ".", "value", ".", "split", "(", "\"\\\\\"", ")", ".", "collect", "{", "|", "val", "|", "val", ".", "to_i", "}", ",", ":parent", "=>", "dcm", ")", "if", "element", ".", "value", "end", "end", "dcm", ".", "delete_group", "(", "'0002'", ")", "DICOM", "::", "Element", ".", "new", "(", "'0028,1050'", ",", "'128'", ",", ":parent", "=>", "dcm", ")", "DICOM", "::", "Element", ".", "new", "(", "'0028,1051'", ",", "'256'", ",", ":parent", "=>", "dcm", ")", "DICOM", "::", "Element", ".", "new", "(", "'0028,1052'", ",", "'0'", ",", ":parent", "=>", "dcm", ")", "DICOM", "::", "Element", ".", "new", "(", "'0028,1053'", ",", "'1'", ",", ":parent", "=>", "dcm", ")", "dcm", ".", "pixels", "=", "@narray", "*", "255", "return", "dcm", "end" ]
Creates a DICOM object from the BinImage instance. This is achieved by copying the elements of the DICOM object of the Image instance referenced by this BinImage, and replacing its pixel data with the NArray of this instance. @return [DICOM::DObject] the created DICOM object
[ "Creates", "a", "DICOM", "object", "from", "the", "BinImage", "instance", ".", "This", "is", "achieved", "by", "copying", "the", "elements", "of", "the", "DICOM", "object", "of", "the", "Image", "instance", "referenced", "by", "this", "BinImage", "and", "replacing", "its", "pixel", "data", "with", "the", "NArray", "of", "this", "instance", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L314-L345
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.to_slice
def to_slice(roi) raise ArgumentError, "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi.is_a?(ROI) # Create the Slice: s = Slice.new(@image.uid, roi) # Create Contours: to_contours(s) return s end
ruby
def to_slice(roi) raise ArgumentError, "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi.is_a?(ROI) # Create the Slice: s = Slice.new(@image.uid, roi) # Create Contours: to_contours(s) return s end
[ "def", "to_slice", "(", "roi", ")", "raise", "ArgumentError", ",", "\"Invalid argument 'roi'. Expected ROI, got #{roi.class}.\"", "unless", "roi", ".", "is_a?", "(", "ROI", ")", "s", "=", "Slice", ".", "new", "(", "@image", ".", "uid", ",", "roi", ")", "to_contours", "(", "s", ")", "return", "s", "end" ]
Creates a Slice instance from the segmentation of this BinImage. @param [ROI] roi the ROI instance which the created Slice will be associated with @return [Slice] the created slice instance (including contour references if the binary image is segmented)
[ "Creates", "a", "Slice", "instance", "from", "the", "segmentation", "of", "this", "BinImage", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L352-L359
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.external_contour
def external_contour start_index = (@narray > 0).where[0] - 1 s_col, s_row = indices_general_to_specific(start_index, columns) col, row = s_col, s_row row_indices = Array.new(1, row) col_indices = Array.new(1, col) last_dir = :north # on first step, pretend we came from the south (going north) directions = { :north => {:dir => [:east, :north, :west, :south], :col => [1, 0, -1, 0], :row => [0, -1, 0, 1]}, :east => {:dir => [:south, :east, :north, :west], :col => [0, 1, 0, -1], :row => [1, 0, -1, 0]}, :south => {:dir => [:west, :south, :east, :north], :col => [-1, 0, 1, 0], :row => [0, 1, 0, -1]}, :west => {:dir => [:north, :west, :south, :east], :col => [0, -1, 0, 1], :row => [-1, 0, 1, 0]}, } loop = true while loop do # Probe the neighbourhood pixels in a CCW order: map = directions[last_dir] 4.times do |i| # Find the first 'free' (zero) pixel, and make that index # the next pixel of our external contour: if @narray[col + map[:col][i], row + map[:row][i]] == 0 last_dir = map[:dir][i] col = col + map[:col][i] row = row + map[:row][i] col_indices << col row_indices << row break end end loop = false if col == s_col and row == s_row end return Selection.create_from_array(indices_specific_to_general(col_indices, row_indices, columns), self) end
ruby
def external_contour start_index = (@narray > 0).where[0] - 1 s_col, s_row = indices_general_to_specific(start_index, columns) col, row = s_col, s_row row_indices = Array.new(1, row) col_indices = Array.new(1, col) last_dir = :north # on first step, pretend we came from the south (going north) directions = { :north => {:dir => [:east, :north, :west, :south], :col => [1, 0, -1, 0], :row => [0, -1, 0, 1]}, :east => {:dir => [:south, :east, :north, :west], :col => [0, 1, 0, -1], :row => [1, 0, -1, 0]}, :south => {:dir => [:west, :south, :east, :north], :col => [-1, 0, 1, 0], :row => [0, 1, 0, -1]}, :west => {:dir => [:north, :west, :south, :east], :col => [0, -1, 0, 1], :row => [-1, 0, 1, 0]}, } loop = true while loop do # Probe the neighbourhood pixels in a CCW order: map = directions[last_dir] 4.times do |i| # Find the first 'free' (zero) pixel, and make that index # the next pixel of our external contour: if @narray[col + map[:col][i], row + map[:row][i]] == 0 last_dir = map[:dir][i] col = col + map[:col][i] row = row + map[:row][i] col_indices << col row_indices << row break end end loop = false if col == s_col and row == s_row end return Selection.create_from_array(indices_specific_to_general(col_indices, row_indices, columns), self) end
[ "def", "external_contour", "start_index", "=", "(", "@narray", ">", "0", ")", ".", "where", "[", "0", "]", "-", "1", "s_col", ",", "s_row", "=", "indices_general_to_specific", "(", "start_index", ",", "columns", ")", "col", ",", "row", "=", "s_col", ",", "s_row", "row_indices", "=", "Array", ".", "new", "(", "1", ",", "row", ")", "col_indices", "=", "Array", ".", "new", "(", "1", ",", "col", ")", "last_dir", "=", ":north", "directions", "=", "{", ":north", "=>", "{", ":dir", "=>", "[", ":east", ",", ":north", ",", ":west", ",", ":south", "]", ",", ":col", "=>", "[", "1", ",", "0", ",", "-", "1", ",", "0", "]", ",", ":row", "=>", "[", "0", ",", "-", "1", ",", "0", ",", "1", "]", "}", ",", ":east", "=>", "{", ":dir", "=>", "[", ":south", ",", ":east", ",", ":north", ",", ":west", "]", ",", ":col", "=>", "[", "0", ",", "1", ",", "0", ",", "-", "1", "]", ",", ":row", "=>", "[", "1", ",", "0", ",", "-", "1", ",", "0", "]", "}", ",", ":south", "=>", "{", ":dir", "=>", "[", ":west", ",", ":south", ",", ":east", ",", ":north", "]", ",", ":col", "=>", "[", "-", "1", ",", "0", ",", "1", ",", "0", "]", ",", ":row", "=>", "[", "0", ",", "1", ",", "0", ",", "-", "1", "]", "}", ",", ":west", "=>", "{", ":dir", "=>", "[", ":north", ",", ":west", ",", ":south", ",", ":east", "]", ",", ":col", "=>", "[", "0", ",", "-", "1", ",", "0", ",", "1", "]", ",", ":row", "=>", "[", "-", "1", ",", "0", ",", "1", ",", "0", "]", "}", ",", "}", "loop", "=", "true", "while", "loop", "do", "map", "=", "directions", "[", "last_dir", "]", "4", ".", "times", "do", "|", "i", "|", "if", "@narray", "[", "col", "+", "map", "[", ":col", "]", "[", "i", "]", ",", "row", "+", "map", "[", ":row", "]", "[", "i", "]", "]", "==", "0", "last_dir", "=", "map", "[", ":dir", "]", "[", "i", "]", "col", "=", "col", "+", "map", "[", ":col", "]", "[", "i", "]", "row", "=", "row", "+", "map", "[", ":row", "]", "[", "i", "]", "col_indices", "<<", "col", "row_indices", "<<", "row", "break", "end", "end", "loop", "=", "false", "if", "col", "==", "s_col", "and", "row", "==", "s_row", "end", "return", "Selection", ".", "create_from_array", "(", "indices_specific_to_general", "(", "col_indices", ",", "row_indices", ",", "columns", ")", ",", "self", ")", "end" ]
Determines a set of pixel indices which enclose the structure. @see This implementation uses Roman Khudeevs algorithm: A New Flood-Fill Algorithm for Closed Contour. https://docs.google.com/viewer?a=v&q=cache:UZ6bo7pXRoIJ:file.lw23.com/file1/01611214.pdf+flood+fill+from+contour+coordinate&hl=no&gl=no&pid=bl&srcid=ADGEEShV4gbKYYq8cDagjT7poT677cIL44K0QW8SR0ODanFy-CD1CHEQi2RvHF8MND7_PXPGYRJMJAcMJO-NEXkM-vU4iA2rNljVetbzuARWuHtKLJKMTNjd3vaDWrIeSU4rKLCVwvff&sig=AHIEtbSAnH6fp584c0_Krv298n-tgpNcJw&pli=1 @return [Selection] the contour's indices
[ "Determines", "a", "set", "of", "pixel", "indices", "which", "enclose", "the", "structure", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L373-L405
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.extract_contours
def extract_contours contours = Array.new if @narray.segmented? # Get contours: corners, continuous = extract_single_contour # If we dont get at least 3 indices, there is no area to fill. if continuous.indices.length < 3 # In this case we remove the pixels and do not record the contour indices: roi = continuous else # Record the indices and get all indices of the structure: contours << corners # Flood fill the image to determine all pixels contained by the contoured structure: roi = roi_indices(continuous) # A precaution: raise "Unexpected result: #{roi.indices.length}. Raising an error to avoid an infinite recursion!" if roi.indices.length < 3 end # Reset the pixels belonging to the contoured structure from the image: @narray[roi.indices] = 0 # Repeat with the 'cleaned' image to get any additional contours present: contours += extract_contours end return contours end
ruby
def extract_contours contours = Array.new if @narray.segmented? # Get contours: corners, continuous = extract_single_contour # If we dont get at least 3 indices, there is no area to fill. if continuous.indices.length < 3 # In this case we remove the pixels and do not record the contour indices: roi = continuous else # Record the indices and get all indices of the structure: contours << corners # Flood fill the image to determine all pixels contained by the contoured structure: roi = roi_indices(continuous) # A precaution: raise "Unexpected result: #{roi.indices.length}. Raising an error to avoid an infinite recursion!" if roi.indices.length < 3 end # Reset the pixels belonging to the contoured structure from the image: @narray[roi.indices] = 0 # Repeat with the 'cleaned' image to get any additional contours present: contours += extract_contours end return contours end
[ "def", "extract_contours", "contours", "=", "Array", ".", "new", "if", "@narray", ".", "segmented?", "corners", ",", "continuous", "=", "extract_single_contour", "if", "continuous", ".", "indices", ".", "length", "<", "3", "roi", "=", "continuous", "else", "contours", "<<", "corners", "roi", "=", "roi_indices", "(", "continuous", ")", "raise", "\"Unexpected result: #{roi.indices.length}. Raising an error to avoid an infinite recursion!\"", "if", "roi", ".", "indices", ".", "length", "<", "3", "end", "@narray", "[", "roi", ".", "indices", "]", "=", "0", "contours", "+=", "extract_contours", "end", "return", "contours", "end" ]
This is a recursive method which extracts a contour, determines all pixels belonging to this contour, removes them from the binary image, then repeats collecting contours until there are no more pixels left. @return [Array<Selection>] an array of indices for all the contours derived from the segmented image
[ "This", "is", "a", "recursive", "method", "which", "extracts", "a", "contour", "determines", "all", "pixels", "belonging", "to", "this", "contour", "removes", "them", "from", "the", "binary", "image", "then", "repeats", "collecting", "contours", "until", "there", "are", "no", "more", "pixels", "left", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L413-L436
train
dicom/rtkit
lib/rtkit/bin_image.rb
RTKIT.BinImage.initialize_contour_reorder_structures
def initialize_contour_reorder_structures @reorder = Hash.new @reorder[:west] = NArray[0,1,2,5,8,7,6,3] @reorder[:nw] = NArray[1,2,5,8,7,6,3,0] @reorder[:north] = NArray[2,5,8,7,6,3,0,1] @reorder[:ne] = NArray[5,8,7,6,3,0,1,2] @reorder[:east] = NArray[8,7,6,3,0,1,2,5] @reorder[:se] = NArray[7,6,3,0,1,2,5,8] @reorder[:south] = NArray[6,3,0,1,2,5,8,7] @reorder[:sw] = NArray[3,0,1,2,5,8,7,6] @arrived_from_directions = Hash.new @arrived_from_directions[0] = :se @arrived_from_directions[1] = :south @arrived_from_directions[2] = :sw @arrived_from_directions[3] = :east @arrived_from_directions[5] = :west @arrived_from_directions[6] = :ne @arrived_from_directions[7] = :north @arrived_from_directions[8] = :nw # Set up the index of pixels in a neighborhood image extract: @relative_indices = NArray.int(3, 3).indgen! end
ruby
def initialize_contour_reorder_structures @reorder = Hash.new @reorder[:west] = NArray[0,1,2,5,8,7,6,3] @reorder[:nw] = NArray[1,2,5,8,7,6,3,0] @reorder[:north] = NArray[2,5,8,7,6,3,0,1] @reorder[:ne] = NArray[5,8,7,6,3,0,1,2] @reorder[:east] = NArray[8,7,6,3,0,1,2,5] @reorder[:se] = NArray[7,6,3,0,1,2,5,8] @reorder[:south] = NArray[6,3,0,1,2,5,8,7] @reorder[:sw] = NArray[3,0,1,2,5,8,7,6] @arrived_from_directions = Hash.new @arrived_from_directions[0] = :se @arrived_from_directions[1] = :south @arrived_from_directions[2] = :sw @arrived_from_directions[3] = :east @arrived_from_directions[5] = :west @arrived_from_directions[6] = :ne @arrived_from_directions[7] = :north @arrived_from_directions[8] = :nw # Set up the index of pixels in a neighborhood image extract: @relative_indices = NArray.int(3, 3).indgen! end
[ "def", "initialize_contour_reorder_structures", "@reorder", "=", "Hash", ".", "new", "@reorder", "[", ":west", "]", "=", "NArray", "[", "0", ",", "1", ",", "2", ",", "5", ",", "8", ",", "7", ",", "6", ",", "3", "]", "@reorder", "[", ":nw", "]", "=", "NArray", "[", "1", ",", "2", ",", "5", ",", "8", ",", "7", ",", "6", ",", "3", ",", "0", "]", "@reorder", "[", ":north", "]", "=", "NArray", "[", "2", ",", "5", ",", "8", ",", "7", ",", "6", ",", "3", ",", "0", ",", "1", "]", "@reorder", "[", ":ne", "]", "=", "NArray", "[", "5", ",", "8", ",", "7", ",", "6", ",", "3", ",", "0", ",", "1", ",", "2", "]", "@reorder", "[", ":east", "]", "=", "NArray", "[", "8", ",", "7", ",", "6", ",", "3", ",", "0", ",", "1", ",", "2", ",", "5", "]", "@reorder", "[", ":se", "]", "=", "NArray", "[", "7", ",", "6", ",", "3", ",", "0", ",", "1", ",", "2", ",", "5", ",", "8", "]", "@reorder", "[", ":south", "]", "=", "NArray", "[", "6", ",", "3", ",", "0", ",", "1", ",", "2", ",", "5", ",", "8", ",", "7", "]", "@reorder", "[", ":sw", "]", "=", "NArray", "[", "3", ",", "0", ",", "1", ",", "2", ",", "5", ",", "8", ",", "7", ",", "6", "]", "@arrived_from_directions", "=", "Hash", ".", "new", "@arrived_from_directions", "[", "0", "]", "=", ":se", "@arrived_from_directions", "[", "1", "]", "=", ":south", "@arrived_from_directions", "[", "2", "]", "=", ":sw", "@arrived_from_directions", "[", "3", "]", "=", ":east", "@arrived_from_directions", "[", "5", "]", "=", ":west", "@arrived_from_directions", "[", "6", "]", "=", ":ne", "@arrived_from_directions", "[", "7", "]", "=", ":north", "@arrived_from_directions", "[", "8", "]", "=", ":nw", "@relative_indices", "=", "NArray", ".", "int", "(", "3", ",", "3", ")", ".", "indgen!", "end" ]
Initializes a couple of instance variables containing directional information, which are used by the contour algorithm. The directional vectors of indices are used for extracting a vector of neighbour pixels from a 3*3 pixel array, where the resulting vector contains 7 neighbour pixels (the previous pixel is removed), in a clockwise order, where the first pixel is the neighbour pixel that is next to the previous pixel, following a clockwise rotation.
[ "Initializes", "a", "couple", "of", "instance", "variables", "containing", "directional", "information", "which", "are", "used", "by", "the", "contour", "algorithm", "." ]
08248bf294769ae5b45ed4a9671f0620d5740252
https://github.com/dicom/rtkit/blob/08248bf294769ae5b45ed4a9671f0620d5740252/lib/rtkit/bin_image.rb#L525-L546
train
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
train
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", ")", "@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
train
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", ")", "@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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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", "@items", ".", "delete", "id", "nil", "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
train
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", "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
train
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", "@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", "]", "@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", "]", "if", "@energy", ">=", "20.0", "@ac_water", "=", "@att_coeffs", ".", "last", "else", "if", "i", "=", "@energies", ".", "index", "(", "@energy", ")", "@ac_water", "=", "@att_coeffs", "[", "i", "]", "else", "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
train
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
train
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", ")", "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
train
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", "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_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", "@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", "@length", "=", "Math", ".", "sqrt", "(", "(", "@p2", ".", "x", "-", "@p1", ".", "x", ")", "**", "2", "+", "(", "@p2", ".", "y", "-", "@p1", ".", "y", ")", "**", "2", "+", "(", "@p2", ".", "z", "-", "@p1", ".", "x", ")", "**", "2", ")", "intersection_with_voxel_space", "if", "@alpha_max", ">", "0", "&&", "@alpha_min", "<", "1", "min_and_max_indices", "number_of_planes", "axf", ",", "ayf", ",", "azf", "=", "first_intersection_point_in_voxel_space", "if", "[", "axf", ",", "ayf", ",", "azf", "]", ".", "any?", "initialize_alphas", "(", "axf", ",", "ayf", ",", "azf", ")", "@i", ",", "@j", ",", "@k", "=", "indices_first_intersection", "(", "axf", ",", "ayf", ",", "azf", ")", "if", "@i", "&&", "@j", "&&", "@k", "update", "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
train
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
train
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
train
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", "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
train
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
train
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
train
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
train
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", ")", "dcm", ".", "add_element", "(", "SOP_CLASS", ",", "@class_uid", ")", "dcm", ".", "add_element", "(", "SERIES_UID", ",", "@series_uid", ")", "dcm", ".", "add_element", "(", "SERIES_NUMBER", ",", "'1'", ")", "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", ")", "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", "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
train
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", "a", "=", "NArray", ".", "float", "(", "@n", ")", "b", "=", "NArray", ".", "float", "(", "@n", ")", "@n", ".", "times", "do", "|", "i", "|", "@weights_current", "[", "i", "]", "=", "@decisions", "[", "i", ",", "true", "]", ".", "mean", "end", "k", "=", "0", "while", "k", "<", "max_iterations", "do", "@weights_previous", "=", "@weights_current", ".", "dup", "@n", ".", "times", "do", "|", "i", "|", "voxel_decisions", "=", "@decisions", "[", "i", ",", "true", "]", "positive_indices", ",", "negative_indices", "=", "(", "voxel_decisions", ".", "eq", "1", ")", ".", "where2", "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", "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", "if", "a", "[", "i", "]", ">", "0", "or", "b", "[", "i", "]", ">", "0", "@weights_current", "[", "i", "]", "=", "a", "[", "i", "]", "/", "(", "a", "[", "i", "]", "+", "b", "[", "i", "]", ")", "else", "@weights_current", "[", "i", "]", "=", "0", "end", "end", "@r", ".", "times", "do", "|", "j", "|", "voxel_decisions", "=", "@decisions", "[", "true", ",", "j", "]", "positive_indices", ",", "negative_indices", "=", "(", "voxel_decisions", ".", "eq", "1", ")", ".", "where2", "sum_positive", "=", "(", "positive_indices", ".", "length", "==", "0", "?", "0", ":", "@weights_current", "[", "positive_indices", "]", ".", "sum", ")", "@p", "[", "j", "]", "=", "sum_positive", "/", "@weights_current", ".", "sum", "sum_negative", "=", "(", "negative_indices", ".", "length", "==", "0", "?", "0", ":", "(", "1", "-", "@weights_current", "[", "negative_indices", "]", ")", ".", "sum", ")", "@q", "[", "j", "]", "=", "sum_negative", "/", "(", "1", "-", "@weights_current", ")", ".", "sum", "end", "k", "+=", "1", "if", "@weights_current", ".", "sum", "-", "@weights_previous", ".", "sum", "==", "0", "break", "end", "end", "@true_segmentation_vector", "=", "@weights_current", ".", "round", "@weights", "=", "@weights_current", "construct_segmentation_volume", "update_bin_matcher", "@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
train
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", "@true_segmentation", "=", "@true_segmentation_vector", ".", "reshape", "(", "*", "@original_volumes", ".", "first", ".", "shape", ")", ".", "to_type", "(", "1", ")", "else", "@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
train
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", "@vectors", "=", "Array", ".", "new", "@volumes", ".", "each", "{", "|", "volume", "|", "@vectors", "<<", "volume", ".", "flatten", "}", "verify_equal_vector_lengths", "@n", "=", "@vectors", ".", "first", ".", "length", "@r", "=", "@vectors", ".", "length", "@decisions", "=", "NArray", ".", "int", "(", "@n", ",", "@r", ")", "@p", "=", "NArray", ".", "float", "(", "@r", ")", "@q", "=", "NArray", ".", "float", "(", "@r", ")", "@p", ".", "fill!", "(", "0.99999", ")", "@q", ".", "fill!", "(", "0.99999", ")", "@phi", "=", "NArray", ".", "float", "(", "2", ",", "@r", ")", "@vectors", ".", "each_with_index", "do", "|", "decision", ",", "j", "|", "@decisions", "[", "true", ",", "j", "]", "=", "decision", "end", "@true_segmentation", "=", "NArray", ".", "byte", "(", "@n", ")", "@weights_previous", "=", "NArray", ".", "float", "(", "@n", ")", "@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
train
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
train
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", "case", "dcm", ".", "value", "(", "MODALITY", ")", "when", "*", "IMAGE_SERIES", "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_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
train
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", ")", "@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
train
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", "}", "@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
train
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", "@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
train
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
train
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
train
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
train
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
train
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", "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
train
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", "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
train
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
train
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
train
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
train
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
train
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", ")", "@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
train
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", "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", "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
train
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
train
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
train
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", ")", "@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
train
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
train
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
train
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
train
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
train
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
train
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", ")", "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", "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
train
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", "bin_vol", "=", "bin_volume", "(", "dose_volume", ")", "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
train
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
train
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
train
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
train
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
train
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", ")", "column_indices", ",", "row_indices", "=", "coordinates_to_indices", "(", "x_coords", ",", "y_coords", ",", "z_coords", ")", "indices", "=", "indices_specific_to_general", "(", "column_indices", ",", "row_indices", ")", "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
train
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", ")", "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", ")", "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", "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
train
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
train
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", "unless", "@dcm", "@dcm", "=", "DICOM", "::", "DObject", ".", "new", "@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'", ")", "@dcm", ".", "add_element", "(", "MANUFACTURER", ",", "'RTKIT'", ")", "@dcm", ".", "add_element", "(", "TIMEZONE_OFFSET_FROM_UTC", ",", "Time", ".", "now", ".", "strftime", "(", "'%z'", ")", ")", "@dcm", ".", "add_element", "(", "MANUFACTURERS_MODEL_NAME", ",", "\"RTKIT_#{VERSION}\"", ")", "@dcm", ".", "add_element", "(", "SOFTWARE_VERSION", ",", "\"RTKIT_#{VERSION}\"", ")", "@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
train
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", "@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", ")", "@dcm", ".", "pixels", "=", "@narray", "@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
train
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
train
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
train
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
train
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
train
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
train
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
train
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", ")", ")", "@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
train
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", "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
train
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
train
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", "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", ")", ")", "@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
train
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", ")", "@image_positions", ".", "delete", "(", "image", ".", "pos_slice", ")", "@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
train