forked from suyashkumar/dicom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame.go
91 lines (82 loc) · 3.25 KB
/
frame.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package frame
import (
"errors"
"image"
)
// ErrorFrameTypeNotPresent is returned when the user asked to Get an underlying
// GetNativeFrame or GetEncapsulatedFrame that is not contained in that
// particular CommonFrame.
var ErrorFrameTypeNotPresent = errors.New("the frame type you requested is not present in this CommonFrame")
// CommonFrame represents a harmonized DICOM Frame with a consistent interface
// (harmonized across Native and Encapsulated frames), however users still have
// the ability to fetch underlying Native or Encapsulated frame constructs.
type CommonFrame interface {
// GetImage gets this frame as an image.Image. Beware that the underlying frame may perform
// some default rendering and conversions. Operate on the raw NativeFrame or EncapsulatedFrame
// if you need to do some custom rendering work or want the data from the dicom.
GetImage() (image.Image, error)
// IsEncapsulated indicates if the underlying Frame is an EncapsulatedFrame.
IsEncapsulated() bool
// GetNativeFrame attempts to get the underlying NativeFrame (or returns an error)
GetNativeFrame() (*NativeFrame, error)
// GetEncapsulatedFrame attempts to get the underlying EncapsulatedFrame (or returns an error)
GetEncapsulatedFrame() (*EncapsulatedFrame, error)
}
// Frame wraps a single encapsulated or native image frame
// TODO: deprecate this old intermediate representation in favor of CommonFrame
// once happy and solid with API.
type Frame struct {
// Encapsulated indicates whether the underlying frame is encapsulated or
// not.
Encapsulated bool
// EncapsulatedData holds the encapsulated data for this frame if
// Encapsulated is set to true.
EncapsulatedData EncapsulatedFrame
// NativeData holds the native data for this frame if Encapsulated is set
// to false.
NativeData NativeFrame
}
// IsEncapsulated indicates if the frame is encapsulated or not.
func (f *Frame) IsEncapsulated() bool { return f.Encapsulated }
// GetNativeFrame returns a NativeFrame from this frame. If the underlying frame
// is not a NativeFrame, ErrorFrameTypeNotPresent will be returned.
func (f *Frame) GetNativeFrame() (*NativeFrame, error) {
if f.Encapsulated {
return f.EncapsulatedData.GetNativeFrame()
}
return f.NativeData.GetNativeFrame()
}
// GetEncapsulatedFrame returns an EncapsulatedFrame from this frame.
// If the underlying frame is not an EncapsulatedFrame, ErrorFrameTypeNotPresent
// will be returned.
func (f *Frame) GetEncapsulatedFrame() (*EncapsulatedFrame, error) {
if f.Encapsulated {
return f.EncapsulatedData.GetEncapsulatedFrame()
}
return f.NativeData.GetEncapsulatedFrame()
}
// GetImage returns a Go image.Image from the underlying frame, regardless of
// the frame type.
func (f *Frame) GetImage() (image.Image, error) {
if f.Encapsulated {
return f.EncapsulatedData.GetImage()
}
return f.NativeData.GetImage()
}
// Equals returns true if this frame equals the provided target frame, otherwise
// false.
func (f *Frame) Equals(target *Frame) bool {
if target == nil || f == nil {
return f == target
}
if f.Encapsulated != target.Encapsulated {
return false
}
if f.Encapsulated && !f.EncapsulatedData.Equals(&target.EncapsulatedData) {
return false
}
if !f.Encapsulated && !f.NativeData.Equals(&target.NativeData) {
return false
}
return true
}