_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q22900 | RTKIT.DataSet.add | train | 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 | {
"resource": ""
} |
q22901 | RTKIT.DataSet.add_frame | train | 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 | {
"resource": ""
} |
q22902 | RTKIT.DataSet.add_patient | train | 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 | {
"resource": ""
} |
q22903 | RTKIT.DataSet.print | train | 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 | {
"resource": ""
} |
q22904 | RTKIT.DataSet.print_rt | train | 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 | {
"resource": ""
} |
q22905 | Radius.Context.stack | train | 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 | {
"resource": ""
} |
q22906 | Radius.Context.numeric_specificity | train | 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 | {
"resource": ""
} |
q22907 | RTKIT.Coordinate.translate | train | def translate(x, y, z)
@x += x.to_f
@y += y.to_f
@z += z.to_f
end | ruby | {
"resource": ""
} |
q22908 | DCell.ResourceManager.register | train | 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 | {
"resource": ""
} |
q22909 | DCell.ResourceManager.each | train | def each
@lock.synchronize do
@items.each do |id, ref|
begin
yield id, ref.__getobj__
rescue WeakRef::RefError
end
end
end
end | ruby | {
"resource": ""
} |
q22910 | DCell.ResourceManager.clear | train | 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 | {
"resource": ""
} |
q22911 | DCell.ResourceManager.find | train | 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 | {
"resource": ""
} |
q22912 | RTKIT.Attenuation.vector_attenuation | train | 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 | {
"resource": ""
} |
q22913 | RTKIT.Attenuation.determine_coefficient | train | 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 | {
"resource": ""
} |
q22914 | Harvest.User.timezone= | train | 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 | {
"resource": ""
} |
q22915 | RTKIT.Dose.bed | train | 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 | {
"resource": ""
} |
q22916 | RTKIT.Ray.trace | train | def trace
# Set up instance varibles which depends on the initial conditions.
# Delta positions determines whether the ray's travel is positive
# or negative in the three directions.
delta_x = @p1.x < @p2.x ? 1 : -1
delta_y = @p1.y < @p2.y ? 1 : -1
delta_z = @p1.z < @p2.z ? 1 : -1
# Delta indices determines whether the ray's voxel space indices increments
# in a positive or negative fashion as it travels through the voxel space.
# Note that for rays travelling perpendicular on a particular axis, the
# delta value of that axis will be undefined (zero).
@delta_i = @p1.x == @p2.x ? 0 : delta_x
@delta_j = @p1.y == @p2.y ? 0 : delta_y
@delta_k = @p1.z == @p2.z ? 0 : delta_z
# These variables describe how much the alpha fraction changes (in a
# given axis) when we follow the ray through one voxel (across two planes).
# This value is high if the ray is perpendicular on the axis (angle high, or close to 90 degrees),
# and low if the angle is parallell with the axis (angle low, or close to 0 degrees).
@delta_ax = @vs.delta_x / (@p2.x - @p1.x).abs
@delta_ay = @vs.delta_y / (@p2.y - @p1.y).abs
@delta_az = @vs.delta_z / (@p2.z - @p1.z).abs
# Determines the ray length (from p1 to p2).
@length = Math.sqrt((@p2.x-@p1.x)**2 + (@p2.y-@p1.y)**2 + (@p2.z-@p1.x)**2)
# Perform the ray tracing:
# Number of voxels: nx, ny, nz
# Number of planes: nx+1, ny+1, nz+1
# Voxel indices: 0..(nx-1), etc.
# Plane indices: 0..nx, etc.
intersection_with_voxel_space
# Perform the ray trace only if the ray's intersection with the
# voxel space is between the ray's start and end points:
if @alpha_max > 0 && @alpha_min < 1
min_and_max_indices
number_of_planes
axf, ayf, azf = first_intersection_point_in_voxel_space
# If we didn't get any intersection points, there's no need to proceed with the ray trace:
if [axf, ayf, azf].any?
# Initialize the starting alpha values:
initialize_alphas(axf, ayf, azf)
@i, @j, @k = indices_first_intersection(axf, ayf, azf)
# Initiate the ray tracing if we got valid starting coordinates:
if @i && @j && @k
# Calculate the first move:
update
# Next interactions:
# To avoid float impresision issues we choose to round here before
# doing the comparison. How many decimals should we choose to round to?
# Perhaps there is a more prinipal way than the chosen solution?
alpha_max_rounded = @alpha_max.round(8)
while @ac.round(8) < alpha_max_rounded do
update
end
end
end
end
end | ruby | {
"resource": ""
} |
q22917 | RTKIT.Ray.alpha_min | train | def alpha_min(fractions)
fractions.compact.collect { |a| a >= 0 ? a : nil}.compact.min
end | ruby | {
"resource": ""
} |
q22918 | RTKIT.Ray.first_intersection_point_in_voxel_space | train | 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 | {
"resource": ""
} |
q22919 | RTKIT.Ray.indices_first_intersection | train | 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 | {
"resource": ""
} |
q22920 | RTKIT.Ray.indices_within_voxel_space | train | 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 | {
"resource": ""
} |
q22921 | RTKIT.Ray.sorted_real_alpha_values | train | def sorted_real_alpha_values(fractions)
fractions.compact.collect { |a| a >= 0 && a.finite? ? a : nil}.compact.sort
end | ruby | {
"resource": ""
} |
q22922 | Radius.Parser.parse | train | def parse(string)
@stack = [ ParseContainerTag.new { |t| Utility.array_to_s(t.contents) } ]
tokenize(string)
stack_up
@stack.last.to_s
end | ruby | {
"resource": ""
} |
q22923 | RTKIT.Series.add_attributes_to_dcm | train | 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 | {
"resource": ""
} |
q22924 | RTKIT.Staple.solve | train | 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 | {
"resource": ""
} |
q22925 | RTKIT.Staple.construct_segmentation_volume | train | 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 | {
"resource": ""
} |
q22926 | RTKIT.Staple.set_parameters | train | 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 | {
"resource": ""
} |
q22927 | RTKIT.Staple.verify_equal_vector_lengths | train | 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 | {
"resource": ""
} |
q22928 | RTKIT.Study.add | train | 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 | {
"resource": ""
} |
q22929 | RTKIT.Study.add_series | train | 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 | {
"resource": ""
} |
q22930 | RTKIT.Selection.shift | train | 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 | {
"resource": ""
} |
q22931 | RTKIT.Selection.shift_columns | train | 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 | {
"resource": ""
} |
q22932 | DCell.NodeManager.each | train | def each
Directory.each do |id|
remote = NodeCache.register id
next unless remote
yield remote
end
end | ruby | {
"resource": ""
} |
q22933 | RTKIT.CRSeries.add_image | train | 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 | {
"resource": ""
} |
q22934 | DCell.ClassMethods.find | train | 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 | {
"resource": ""
} |
q22935 | DCell.ClassMethods.run! | train | def run!
Directory[id].actors = local_actors
Directory[id].pubkey = crypto ? crypto_keys[:pubkey] : nil
DCell::SupervisionGroup.run!
end | ruby | {
"resource": ""
} |
q22936 | DCell.ClassMethods.generate_node_id | train | 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 | {
"resource": ""
} |
q22937 | DCell.Node.find | train | 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 | {
"resource": ""
} |
q22938 | DCell.Node.actors | train | def actors
request = Message::List.new(Thread.mailbox)
list = send_request request
list.map!(&:to_sym)
end | ruby | {
"resource": ""
} |
q22939 | DCell.Node.ping | train | def ping(timeout=nil)
request = Message::Ping.new(Thread.mailbox)
send_request request, :request, timeout
end | ruby | {
"resource": ""
} |
q22940 | DCell.Node.shutdown | train | 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 | {
"resource": ""
} |
q22941 | RTKIT.Slice.add_contour | train | 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 | {
"resource": ""
} |
q22942 | RTKIT.Slice.bin_image | train | 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 | {
"resource": ""
} |
q22943 | RTKIT.Slice.plane | train | 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 | {
"resource": ""
} |
q22944 | RTKIT.Structure.ss_item | train | 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 | {
"resource": ""
} |
q22945 | RTKIT.Patient.add | train | def add(dcm)
s = study(dcm.value(STUDY_UID))
if s
s.add(dcm)
else
add_study(Study.load(dcm, self))
end
end | ruby | {
"resource": ""
} |
q22946 | RTKIT.Patient.add_study | train | 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 | {
"resource": ""
} |
q22947 | Limelight.Prop.play_sound | train | def play_sound(filename)
path = Java::limelight.Context.fs.path_to(scene.path, filename)
@peer.play_sound(path)
end | ruby | {
"resource": ""
} |
q22948 | Limelight.Scene.open_production | train | def open_production(production_path)
Thread.new { Java::limelight.Context.instance.studio.open(production_path) }
end | ruby | {
"resource": ""
} |
q22949 | Limelight.Scene.find_by_id | train | def find_by_id(id)
peer_result = @peer.find(id.to_s)
peer_result.nil? ? nil : peer_result.proxy
end | ruby | {
"resource": ""
} |
q22950 | RTKIT.CollimatorSetup.to_item | train | 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 | {
"resource": ""
} |
q22951 | RTKIT.ROI.add_slice | train | 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 | {
"resource": ""
} |
q22952 | RTKIT.ROI.create_slices | train | 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 | {
"resource": ""
} |
q22953 | RTKIT.ROI.distribution | train | def distribution(dose_volume=@struct.plan.rt_dose.sum)
raise ArgumentError, "Invalid argument 'dose_volume'. Expected DoseVolume, got #{dose_volume.class}." unless dose_volume.is_a?(DoseVolume)
raise ArgumentError, "Invalid argument 'dose_volume'. The specified DoseVolume does not belong to this ROI's StructureSet." unless dose_volume.dose_series.plan.struct == @struct
# Extract a binary volume from the ROI, based on the dose data:
bin_vol = bin_volume(dose_volume)
# Create a DoseDistribution from the BinVolume:
dose_distribution = DoseDistribution.create(bin_vol)
return dose_distribution
end | ruby | {
"resource": ""
} |
q22954 | RTKIT.ROI.translate | train | def translate(x, y, z)
@slices.each do |s|
s.translate(x, y, z)
end
end | ruby | {
"resource": ""
} |
q22955 | Limelight.Pen.smooth= | train | 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 | {
"resource": ""
} |
q22956 | Limelight.Pen.fill_oval | train | def fill_oval(x, y, width, height)
@context.fillOval(x, y, width, height)
end | ruby | {
"resource": ""
} |
q22957 | RTKIT.Image.draw_lines | train | 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 | {
"resource": ""
} |
q22958 | RTKIT.Image.extract_pixels | train | 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 | {
"resource": ""
} |
q22959 | RTKIT.Image.flood_fill | train | 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 | {
"resource": ""
} |
q22960 | RTKIT.Image.print_img | train | 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 | {
"resource": ""
} |
q22961 | RTKIT.Image.create_general_dicom_image_scaffold | train | 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 | {
"resource": ""
} |
q22962 | RTKIT.Image.update_dicom_image | train | 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 | {
"resource": ""
} |
q22963 | RTKIT.RTDose.add_volume | train | 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 | {
"resource": ""
} |
q22964 | RTKIT.Plan.add_beam | train | 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 | {
"resource": ""
} |
q22965 | RTKIT.Plan.add_rt_dose | train | 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 | {
"resource": ""
} |
q22966 | RTKIT.Plan.add_rt_image | train | 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 | {
"resource": ""
} |
q22967 | RTKIT.Beam.add_collimator | train | 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 | {
"resource": ""
} |
q22968 | RTKIT.Beam.add_control_point | train | 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 | {
"resource": ""
} |
q22969 | RTKIT.Beam.beam_item | train | 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 | {
"resource": ""
} |
q22970 | RTKIT.Beam.control_point | train | 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 | {
"resource": ""
} |
q22971 | RTKIT.Beam.ref_beam_item | train | 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 | {
"resource": ""
} |
q22972 | RTKIT.ImageParent.to_voxel_space | train | 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 | {
"resource": ""
} |
q22973 | RTKIT.ImageParent.update_image_position | train | 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 | {
"resource": ""
} |
q22974 | RTKIT.StructureSet.add_plan | train | def add_plan(plan)
raise ArgumentError, "Invalid argument 'plan'. Expected Plan, got #{plan.class}." unless plan.is_a?(Plan)
@plans << plan unless @associated_plans[plan.uid]
@associated_plans[plan.uid] = plan
end | ruby | {
"resource": ""
} |
q22975 | RTKIT.StructureSet.add_poi | train | def add_poi(poi)
raise ArgumentError, "Invalid argument 'poi'. Expected POI, got #{poi.class}." unless poi.is_a?(POI)
@structures << poi unless @structures.include?(poi)
end | ruby | {
"resource": ""
} |
q22976 | RTKIT.StructureSet.add_structure | train | def add_structure(structure)
raise ArgumentError, "Invalid argument 'structure'. Expected ROI/POI, got #{structure.class}." unless structure.respond_to?(:to_roi) or structure.respond_to?(:to_poi)
@structures << structure unless @structures.include?(structure)
end | ruby | {
"resource": ""
} |
q22977 | RTKIT.StructureSet.add_roi | train | def add_roi(roi)
raise ArgumentError, "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi.is_a?(ROI)
@structures << roi unless @structures.include?(roi)
end | ruby | {
"resource": ""
} |
q22978 | RTKIT.StructureSet.create_roi | train | def create_roi(frame, options={})
raise ArgumentError, "Expected Frame, got #{frame.class}." unless frame.is_a?(Frame)
# Set values:
algorithm = options[:algorithm] || 'Automatic'
name = options[:name] || 'RTKIT-VOLUME'
interpreter = options[:interpreter] || 'RTKIT'
type = options[:type] || 'CONTROL'
if options[:number]
raise ArgumentError, "Expected Integer, got #{options[:number].class} for the option :number." unless options[:number].is_a?(Integer)
raise ArgumentError, "The specified ROI Number (#{options[:roi_number]}) is already used by one of the existing ROIs (#{roi_numbers})." if structure_numbers.include?(options[:number])
number = options[:number]
else
number = (structure_numbers.max ? structure_numbers.max + 1 : 1)
end
# Create ROI:
roi = ROI.new(name, number, frame, self, :algorithm => algorithm, :name => name, :number => number, :interpreter => interpreter, :type => type)
return roi
end | ruby | {
"resource": ""
} |
q22979 | RTKIT.StructureSet.remove_structure | train | def remove_structure(instance_or_number)
raise ArgumentError, "Invalid argument 'instance_or_number'. Expected a ROI Instance or an Integer (ROI Number). Got #{instance_or_number.class}." unless [ROI, Integer].include?(instance_or_number.class)
s_instance = instance_or_number
if instance_or_number.is_a?(Integer)
s_instance = structure(instance_or_number)
end
index = @structures.index(s_instance)
if index
@structures.delete_at(index)
s_instance.remove_references
end
end | ruby | {
"resource": ""
} |
q22980 | RTKIT.StructureSet.structure_names | train | def structure_names
names = Array.new
@structures.each do |s|
names << s.name
end
return names
end | ruby | {
"resource": ""
} |
q22981 | RTKIT.StructureSet.structure_numbers | train | def structure_numbers
numbers = Array.new
@structures.each do |s|
numbers << s.number
end
return numbers
end | ruby | {
"resource": ""
} |
q22982 | RTKIT.StructureSet.to_dcm | train | def to_dcm
# Use the original DICOM object as a starting point (keeping all non-sequence elements):
#@dcm[REF_FRAME_OF_REF_SQ].delete_children
@dcm[STRUCTURE_SET_ROI_SQ].delete_children
@dcm[ROI_CONTOUR_SQ].delete_children
@dcm[RT_ROI_OBS_SQ].delete_children
# Create DICOM
@rois.each do |roi|
@dcm[STRUCTURE_SET_ROI_SQ].add_item(roi.ss_item)
@dcm[ROI_CONTOUR_SQ].add_item(roi.contour_item)
@dcm[RT_ROI_OBS_SQ].add_item(roi.obs_item)
end
return @dcm
end | ruby | {
"resource": ""
} |
q22983 | RTKIT.StructureSet.load_structures | train | def load_structures
if @dcm[STRUCTURE_SET_ROI_SQ] && @dcm[ROI_CONTOUR_SQ] && @dcm[RT_ROI_OBS_SQ]
# Load the information in a nested hash:
item_group = Hash.new
@dcm[STRUCTURE_SET_ROI_SQ].each do |roi_item|
item_group[roi_item.value(ROI_NUMBER)] = {:roi => roi_item}
end
@dcm[ROI_CONTOUR_SQ].each do |contour_item|
item_group[contour_item.value(REF_ROI_NUMBER)][:contour] = contour_item
end
@dcm[RT_ROI_OBS_SQ].each do |rt_item|
item_group[rt_item.value(REF_ROI_NUMBER)][:rt] = rt_item
end
# Create a ROI instance for each set of items:
item_group.each_value do |roi_items|
Structure.create_from_items(roi_items[:roi], roi_items[:contour], roi_items[:rt], self)
end
else
RTKIT.logger.warn "The structure set contained one or more empty ROI sequences. No ROIs extracted."
end
end | ruby | {
"resource": ""
} |
q22984 | RTKIT.Frame.add_image | train | def add_image(image)
raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image)
@associated_instance_uids[image.uid] = image
# If the ImageSeries of an added Image is not connected to this Frame yet, do so:
add_series(image.series) unless series(image.series.uid)
end | ruby | {
"resource": ""
} |
q22985 | RTKIT.Frame.add_series | train | def add_series(series)
raise ArgumentError, "Invalid argument 'series' Expected ImageSeries or DoseVolume, got #{series.class}." unless [ImageSeries, DoseVolume].include?(series.class)
@image_series << series
@associated_series[series.uid] = series
end | ruby | {
"resource": ""
} |
q22986 | RTKIT.Contour.add_coordinate | train | def add_coordinate(coordinate)
raise ArgumentError, "Invalid argument 'coordinate'. Expected Coordinate, got #{coordinate.class}." unless coordinate.is_a?(Coordinate)
@coordinates << coordinate unless @coordinates.include?(coordinate)
end | ruby | {
"resource": ""
} |
q22987 | RTKIT.Contour.coords | train | def coords
x, y, z = Array.new, Array.new, Array.new
@coordinates.each do |coord|
x << coord.x
y << coord.y
z << coord.z
end
return x, y, z
end | ruby | {
"resource": ""
} |
q22988 | RTKIT.Contour.create_coordinates | train | def create_coordinates(contour_data)
raise ArgumentError, "Invalid argument 'contour_data'. Expected String (or nil), got #{contour_data.class}." unless [String, NilClass].include?(contour_data.class)
if contour_data && contour_data != ""
# Split the number strings, sperated by a '\', into an array:
string_values = contour_data.split("\\")
size = string_values.length/3
# Extract every third value of the string array as x, y, and z, respectively, and collect them as floats instead of strings:
x = string_values.values_at(*(Array.new(size){|i| i*3 })).collect{|val| val.to_f}
y = string_values.values_at(*(Array.new(size){|i| i*3+1})).collect{|val| val.to_f}
z = string_values.values_at(*(Array.new(size){|i| i*3+2})).collect{|val| val.to_f}
x.each_index do |i|
Coordinate.new(x[i], y[i], z[i], self)
end
end
end | ruby | {
"resource": ""
} |
q22989 | RTKIT.Contour.to_item | train | def to_item
# FIXME: We need to decide on how to principally handle the situation when an image series has not been
# loaded, and how to set up the ROI slices. A possible solution is to create Image instances if they hasn't been loaded.
item = DICOM::Item.new
item.add(DICOM::Sequence.new(CONTOUR_IMAGE_SQ))
item[CONTOUR_IMAGE_SQ].add_item
item[CONTOUR_IMAGE_SQ][0].add(DICOM::Element.new(REF_SOP_CLASS_UID, @slice.image ? @slice.image.series.class_uid : '1.2.840.10008.5.1.4.1.1.2')) # Deafult to CT if image ref. doesn't exist.
item[CONTOUR_IMAGE_SQ][0].add(DICOM::Element.new(REF_SOP_UID, @slice.uid))
item.add(DICOM::Element.new(CONTOUR_GEO_TYPE, @type))
item.add(DICOM::Element.new(NR_CONTOUR_POINTS, @coordinates.length.to_s))
item.add(DICOM::Element.new(CONTOUR_NUMBER, @number.to_s))
item.add(DICOM::Element.new(CONTOUR_DATA, contour_data))
return item
end | ruby | {
"resource": ""
} |
q22990 | RTKIT.Contour.translate | train | def translate(x, y, z)
@coordinates.each do |c|
c.translate(x, y, z)
end
end | ruby | {
"resource": ""
} |
q22991 | DCell.MessageHandler.handle_message | train | def handle_message(message)
begin
message = decode_message message
rescue InvalidMessageError => ex
Logger.crash("couldn't decode message", ex)
return
end
begin
message.dispatch
rescue => ex
Logger.crash("message dispatch failed", ex)
end
end | ruby | {
"resource": ""
} |
q22992 | DCell.MessageHandler.decode_message | train | def decode_message(message)
begin
msg = MessagePack.unpack(message, symbolize_keys: true)
rescue => ex
raise InvalidMessageError, "couldn't unpack message: #{ex}"
end
begin
klass = Utils.full_const_get msg[:type]
o = klass.new(*msg[:args])
o.id = msg[:id] if o.respond_to?(:id=) && msg[:id]
o
rescue => ex
raise InvalidMessageError, "invalid message: #{ex}"
end
end | ruby | {
"resource": ""
} |
q22993 | DCell.Server.run | train | def run
while true
message = @socket.read_multipart
if @socket.is_a? Celluloid::ZMQ::RouterSocket
message = message[1]
else
message = message[0]
end
handle_message message
end
end | ruby | {
"resource": ""
} |
q22994 | Radius.Scanner.operate | train | def operate(prefix, data)
data = Radius::OrdString.new data
@nodes = ['']
re = scanner_regex(prefix)
if md = re.match(data)
remainder = ''
while md
start_tag, attributes, self_enclosed, end_tag = $1, $2, $3, $4
flavor = self_enclosed == '/' ? :self : (start_tag ? :open : :close)
# save the part before the current match as a string node
@nodes << md.pre_match
# save the tag that was found as a tag hash node
@nodes << {:prefix=>prefix, :name=>(start_tag || end_tag), :flavor => flavor, :attrs => parse_attributes(attributes)}
# remember the part after the current match
remainder = md.post_match
# see if we find another tag in the remaining string
md = re.match(md.post_match)
end
# add the last remaining string after the last tag that was found as a string node
@nodes << remainder
else
@nodes << data
end
return @nodes
end | ruby | {
"resource": ""
} |
q22995 | Limelight.Theater.add_stage | train | def add_stage(name, options = {})
stage = build_stage(name, options).proxy
@peer.add(stage.peer)
return stage
end | ruby | {
"resource": ""
} |
q22996 | RTKIT.BinMatcher.fill_blanks | train | def fill_blanks
if @volumes.length > 0
# Register all unique images referenced by the various volumes:
images = Set.new
# Include the master volume (if it is present):
[@volumes, @master].flatten.compact.each do |volume|
volume.bin_images.each do |bin_image|
images << bin_image.image unless images.include?(bin_image.image)
end
end
# Check if any of the volumes have images missing, and if so, create empty images:
images.each do |image|
[@volumes, @master].flatten.compact.each do |volume|
match = false
volume.bin_images.each do |bin_image|
match = true if bin_image.image == image
end
unless match
# Create BinImage:
bin_img = BinImage.new(NArray.byte(image.columns, image.rows), image)
volume.add(bin_img)
end
end
end
end
end | ruby | {
"resource": ""
} |
q22997 | RTKIT.DoseVolume.add_image | train | def add_image(image)
raise ArgumentError, "Invalid argument 'image'. Expected Image, got #{image.class}." unless image.is_a?(Image)
@images << image unless @associated_images[image.uid]
@associated_images[image.uid] = image
@image_positions[image.pos_slice.round(2)] = image
end | ruby | {
"resource": ""
} |
q22998 | RTKIT.DoseVolume.image_by_slice_pos | train | def image_by_slice_pos(pos)
# Step 1: Try for an (exact) match:
image = @image_positions[pos.round(2)]
# Step 2: If no match, try to search for a close match:
# (A close match is defined as the given slice position being within 1/3 of the
# slice distance from an existing image instance in the series)
if !image && @images.length > 1
proximity = @images.collect{|img| (img.pos_slice - pos).abs}
if proximity.min < slice_spacing / 3.0
index = proximity.index(proximity.min)
image = @images[index]
end
end
return image
end | ruby | {
"resource": ""
} |
q22999 | Dradis::Plugins.Settings.dirty_or_db_setting_or_default | train | def dirty_or_db_setting_or_default(key)
if @dirty_options.key?(key)
@dirty_options[key]
elsif Configuration.exists?(name: namespaced_key(key))
db_setting(key)
else
@default_options[key]
end
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.