Expand DICOM decoding and Enhanced CT support
This commit is contained in:
1 parent
c7f9af8025
commit
6b95fbb1fc
9 files changed
+508
-96
No files matched your search
@@ -1,10 +1,13 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
struct DICOMViewer: View {
|
||||
let urls: [URL]
|
||||
let name: String
|
||||
|
||||
@State private var volume: DICOMVolume?
|
||||
@State private var error: String?
|
||||
@State private var exportError: String?
|
||||
@State private var plane = DICOMVolume.Plane.slices
|
||||
@State private var index = 0.0
|
||||
@State private var center = 0.0
|
||||
@@ -27,6 +30,14 @@ struct DICOMViewer: View {
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
.alert("Не удалось экспортировать DICOM", isPresented: Binding(
|
||||
get: { exportError != nil },
|
||||
set: { if !$0 { exportError = nil } }
|
||||
)) {
|
||||
Button("Закрыть", role: .cancel) {}
|
||||
} message: {
|
||||
Text(exportError ?? "")
|
||||
}
|
||||
.task {
|
||||
do {
|
||||
let urls = self.urls
|
||||
@@ -76,6 +87,13 @@ struct DICOMViewer: View {
|
||||
Text("DICOM • \(volume.size.x) × \(volume.size.y) × \(volume.size.z)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
Button {
|
||||
exportOriginals()
|
||||
} label: {
|
||||
Label("Экспорт DICOM…", systemImage: "square.and.arrow.up")
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
.help("Экспортировать исходные файлы DICOM")
|
||||
}
|
||||
.padding(10)
|
||||
|
||||
@@ -116,18 +134,45 @@ struct DICOMViewer: View {
|
||||
Text("Срез \(min(Int(index) + 1, volume.count(plane))) из \(volume.count(plane))")
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Slider(value: $center, in: centerRange(volume)) { Text(show3D && surface ? "Порог" : "Уровень") }
|
||||
if !show3D || !surface {
|
||||
Slider(value: $width, in: 1...windowLimit(volume)) { Text("Окно") }
|
||||
if volume.rgb == nil {
|
||||
HStack {
|
||||
Slider(value: $center, in: centerRange(volume)) { Text(show3D && surface ? "Порог" : "Уровень") }
|
||||
if !show3D || !surface {
|
||||
Slider(value: $width, in: 1...windowLimit(volume)) { Text("Окно") }
|
||||
}
|
||||
Button("Сбросить окно") { resetWindow(volume) }
|
||||
}
|
||||
Button("Сбросить окно") { resetWindow(volume) }
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
}
|
||||
}
|
||||
|
||||
private func exportOriginals() {
|
||||
let panel = NSSavePanel()
|
||||
panel.nameFieldStringValue = urls.count == 1 ? name : "Серия DICOM"
|
||||
guard panel.runModal() == .OK, let destination = panel.url else { return }
|
||||
do {
|
||||
if urls.count == 1 {
|
||||
try Data(contentsOf: urls[0], options: .mappedIfSafe).write(to: destination, options: .atomic)
|
||||
return
|
||||
}
|
||||
|
||||
let manager = FileManager.default
|
||||
try manager.createDirectory(at: destination, withIntermediateDirectories: false)
|
||||
do {
|
||||
for source in urls {
|
||||
try manager.copyItem(at: source, to: destination.appendingPathComponent(source.lastPathComponent))
|
||||
}
|
||||
} catch {
|
||||
try? manager.removeItem(at: destination)
|
||||
throw error
|
||||
}
|
||||
} catch {
|
||||
exportError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
private func centerRange(_ volume: DICOMVolume) -> ClosedRange<Double> {
|
||||
let preset = volume.window?.x ?? volume.minimum
|
||||
return Double(min(volume.minimum, preset))...Double(max(volume.minimum + 1, volume.maximum, preset))
|
||||
|
||||
Reference in new issue
Block a user