Class: DicomS::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/dicoms/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/dicoms/cli.rb', line 7

def self.exit_on_failure?
  true
end

Instance Method Details

#extract(dicom_dir) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dicoms/cli.rb', line 91

def extract(dicom_dir)000
  DICOM.logger.level = Logger::FATAL
  settings = {} # TODO: ...
  unless File.exists?(dicom_dir)
    raise Error, set_color("Directory not found: #{dicom_dir}", :red)
    say options
  end

  raw = options.raw
  if options.big
    raw = true
    big_endian = true
  elsif options.little
    raw = true
    little_endian = true
  end

  packer = DicomS.new(settings)
  packer.extract(
    dicom_dir,
    transfer: DicomS.transfer_options(options),
    output: options.output,
    raw: raw, big_endian: big_endian, little_endian: little_endian
  )
  # rescue => raise Error?
  0
end

#pack(dicom_dir) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dicoms/cli.rb', line 32

def pack(dicom_dir)
  DICOM.logger.level = Logger::FATAL
  strategy_parameters = {
    ignore_min: true
  }
  settings = {} # TODO: ...
  unless File.directory?(dicom_dir)
    raise Error, set_color("Directory not found: #{dicom_dir}", :red)
    say options
  end
  cmd_options = CommandOptions[
    settings: options.settings,
    settings_io: options.settings_io,
    output: options.output,
    tmp:  options.tmp,
    reorder: options.reorder,
    dicom_metadata: true
  ]
  packer = DicomS.new(settings)
  packer.pack dicom_dir, cmd_options
  # rescue => raise Error?
  0
end

#projection(dicom_dir) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/dicoms/cli.rb', line 149

def projection(dicom_dir)
  DICOM.logger.level = Logger::FATAL
  settings = {} # TODO: ...
  unless File.directory?(dicom_dir)
    raise Error, set_color("Directory not found: #{dicom_dir}", :red)
    say options
  end
  if options.settings_io || options.settings
    cmd_options = CommandOptions[
      settings: options.settings,
      settings_io: options.settings_io,
      output: options.output,
      max_x_pixels: options.max_x_pixels && options.max_x_pixels.to_i,
      max_y_pixels: options.max_y_pixels && options.max_y_pixels.to_i,
      max_z_pixels: options.max_z_pixels && options.max_z_pixels.to_i,
      reorder: options.reorder,
    ]
  else
    cmd_options = CommandOptions[
      transfer: DicomS.transfer_options(options),
      output: options.output,
      axial: options.axial == 'axial' ? 'mip' : options.axial,
      sagittal: options.sagittal == 'sagittal' ? 'mip' : options.sagittal,
      coronal: options.coronal == 'coronal' ? 'mip' : options.coronal,
      max_x_pixels: options.max_x_pixels && options.max_x_pixels.to_i,
      max_y_pixels: options.max_y_pixels && options.max_y_pixels.to_i,
      max_z_pixels: options.max_z_pixels && options.max_z_pixels.to_i,
      reorder: options.reorder,
    ]
  end
  unless cmd_options.axial || options.sagittal || options.coronal
    raise Error, "Must specify at least one projection (axial/sagittal/coronal)"
  end
  packer = DicomS.new(settings)
  packer.projection(dicom_dir, cmd_options)
  # rescue => raise Error?
  0
end

#remap(dicom_dir) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/dicoms/cli.rb', line 199

def remap(dicom_dir)
  DICOM.logger.level = Logger::FATAL
  settings = {} # TODO: ...
  unless File.directory?(dicom_dir)
    raise Error, set_color("Directory not found: #{dicom_dir}", :red)
    say options
  end
  packer = DicomS.new(settings)
  packer.remap(
    dicom_dir,
    transfer: DicomS.transfer_options(options),
    output: options.output
  )
  # rescue => raise Error?
  0
end

#stats(dicom_dir) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dicoms/cli.rb', line 120

def stats(dicom_dir)
  DICOM.logger.level = Logger::FATAL
  settings = {} # TODO: ...
  dicoms = DicomS.new(settings)
  stats = dicoms.stats dicom_dir
  puts "Aggregate values for #{stats[:n]} DICOM files:"
  puts "  Minimum level: #{stats[:min]}"
  puts "  Next minimum level: #{stats[:next_min]}"
  puts "  Maximum level: #{stats[:max]}"
  0
end

#unpack(dspack) ⇒ Object

TODO: parameters for dicom regeneration



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dicoms/cli.rb', line 60

def unpack(dspack)
  DICOM.logger.level = Logger::FATAL
  unless File.file?(dspack)
    raise Error, set_color("File not found: #{dspack}", :red)
    say options
  end
  settings = {} # TODO: ...
  packer = DicomS.new(settings)
  packer.unpack(
    dspack,
    settings: options.settings,
    settings_io: options.settings_io,
    output: options.output,
    dicom_output: options.dicom
  )
  # rescue => raise Error?
  0
end

#versionObject



13
14
15
# File 'lib/dicoms/cli.rb', line 13

def version
  say "dicoms #{VERSION}"
end