Skip to content

Commit

Permalink
some more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar committed Nov 6, 2023
1 parent 22805da commit d7ffe99
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 72 deletions.
28 changes: 14 additions & 14 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/suyashkumar/dicom/pkg/tag"
)

// ErrorUnexpectedDataType indicates that an unexpected (not allowed) data type was sent to NewValue.
var ErrorUnexpectedDataType = errors.New("the type of the data was unexpected or not allowed")
// ErrorUnexpectedDataType indicates that an unexpected (not allowed) int16Data type was sent to NewValue.
var ErrorUnexpectedDataType = errors.New("the type of the int16Data was unexpected or not allowed")

// Element represents a standard DICOM data element (see the DICOM standard:
// Element represents a standard DICOM int16Data element (see the DICOM standard:
// https://dicom.nema.org/medical/dicom/current/output/html/part05.html#sect_7.1 ).
// This Element can be serialized to JSON out of the box and pretty printed as a string via the String() method.
type Element struct {
Expand Down Expand Up @@ -57,14 +57,14 @@ func (e *Element) String() string {
e.Value.String())
}

// Value represents a DICOM value. The underlying data that a Value stores can be determined by inspecting its
// Value represents a DICOM value. The underlying int16Data that a Value stores can be determined by inspecting its
// ValueType. DICOM values typically can be one of many types (ints, strings, bytes, sequences of other elements, etc),
// so this Value interface attempts to represent this as canoically as possible in Golang (since generics do not exist
// yet).
//
// Value is JSON serializable out of the box (implements json.Marshaler).
//
// If necessary, a Value's data can be efficiently unpacked by inspecting its underlying ValueType and either using a
// If necessary, a Value's int16Data can be efficiently unpacked by inspecting its underlying ValueType and either using a
// Golang type assertion or using the helper functions provided (like MustGetStrings). Because for each ValueType there
// is exactly one underlying Golang type, this should be safe, efficient, and straightforward.
//
Expand All @@ -79,14 +79,14 @@ func (e *Element) String() string {
// // ...
// }
//
// Unpacking the data like above is only necessary if something specific needs to be done with the underlying data.
// See the Element and Dataset examples as well to see how to work with this kind of data, and common patterns for doing
// Unpacking the int16Data like above is only necessary if something specific needs to be done with the underlying int16Data.
// See the Element and Dataset examples as well to see how to work with this kind of int16Data, and common patterns for doing
// so.
type Value interface {
// All types that can be a "Value" for an element will implement this empty method, similar to how protocol buffers
// implement "oneof" in Go
isElementValue()
// ValueType returns the underlying ValueType of this Value. This can be used to unpack the underlying data in this
// ValueType returns the underlying ValueType of this Value. This can be used to unpack the underlying int16Data in this
// Value.
ValueType() ValueType
// GetValue returns the underlying value that this Value holds. What type is returned here can be determined exactly
Expand All @@ -98,7 +98,7 @@ type Value interface {
Equals(Value) bool
}

// NewValue creates a new DICOM value for the supplied data. Likely most useful
// NewValue creates a new DICOM value for the supplied int16Data. Likely most useful
// if creating an Element in testing or write scenarios.
//
// Data must be one of the following types, otherwise and error will be returned
Expand Down Expand Up @@ -140,7 +140,7 @@ func mustNewValue(data interface{}) Value {
}

// NewElement creates a new DICOM Element with the supplied tag and with a value
// built from the provided data. The data can be one of the types that is
// built from the provided int16Data. The int16Data can be one of the types that is
// acceptable to NewValue.
func NewElement(t tag.Tag, data interface{}) (*Element, error) {
tagInfo, err := tag.Find(t)
Expand Down Expand Up @@ -337,7 +337,7 @@ type SequenceItemValue struct {
func (s *SequenceItemValue) isElementValue() {}

// ValueType returns the underlying ValueType of this Value. This can be used
// to unpack the underlying data in this Value.
// to unpack the underlying int16Data in this Value.
func (s *SequenceItemValue) ValueType() ValueType { return SequenceItem }

// GetValue returns the underlying value that this Value holds. What type is
Expand Down Expand Up @@ -406,7 +406,7 @@ func (s *sequencesValue) Equals(target Value) bool {
// PixelDataInfo is a representation of DICOM PixelData.
type PixelDataInfo struct {
// IntentionallySkipped indicates that reading the PixelData value was
// intentionally skipped and no Value data for this tag was read.
// intentionally skipped and no Value int16Data for this tag was read.
// This is likely true if the dicom.SkipPixelData option was set. If true,
// the rest of this PixelDataInfo will be empty.
IntentionallySkipped bool `json:"intentionallySkipped"`
Expand All @@ -428,7 +428,7 @@ type PixelDataInfo struct {
// should work. This will be true if the
// dicom.SkipProcessingPixelDataValue flag is set with a PixelData tag.
IntentionallyUnprocessed bool `json:"intentionallyUnprocessed"`
// UnprocessedValueData holds the unprocessed Element value data if
// UnprocessedValueData holds the unprocessed Element value int16Data if
// IntentionallyUnprocessed=true.
UnprocessedValueData []byte
}
Expand All @@ -443,7 +443,7 @@ func (p *pixelDataValue) ValueType() ValueType { return PixelData }
func (p *pixelDataValue) GetValue() interface{} { return p.PixelDataInfo }
func (p *pixelDataValue) String() string {
if len(p.Frames) == 0 {
return "empty pixel data"
return "empty pixel int16Data"
}
if p.IsEncapsulated {
return fmt.Sprintf("encapsulated FramesLength=%d Frame[0] size=%d", len(p.Frames), len(p.Frames[0].EncapsulatedData.Data))
Expand Down
10 changes: 5 additions & 5 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// work with DICOM (https://dicom.nema.org/) medical image files in Go.
//
// dicom.Parse and dicom.Write provide the core functionality to read and write
// DICOM Datasets. This package provides Go data structures that represent
// DICOM Datasets. This package provides Go int16Data structures that represent
// DICOM concepts (for example, dicom.Dataset and dicom.Element). These
// structures will pretty-print by default and are JSON serializable out of the
// box.
Expand Down Expand Up @@ -260,10 +260,10 @@ func SkipMetadataReadOnNewParserInit() ParseOption {
}
}

// SkipPixelData skips reading data from the PixelData tag, wherever it appears
// SkipPixelData skips reading int16Data from the PixelData tag, wherever it appears
// (e.g. even if within an IconSequence). A PixelDataInfo will be added to the
// Dataset with the IntentionallySkipped property set to true, and no other
// data. Use this option if you don't need the PixelData value to be in the
// int16Data. Use this option if you don't need the PixelData value to be in the
// Dataset at all, and want to save both CPU and Memory. If you need the
// PixelData value in the Dataset (e.g. so it can be written out identically
// later) but _don't_ want to process/parse the value, see the
Expand All @@ -281,8 +281,8 @@ func SkipPixelData() ParseOption {
// a PixelData element will be added to the dataset with the
// PixelDataInfo.IntentionallyUnprocessed = true, and the raw bytes of the
// entire PixelData element stored in PixelDataInfo.UnprocessedValueData.
//
// In the future, we may be able to extend this functionality to support
//
// In the future, we may be able to extend this functionality to support
// on-demand processing of elements elsewhere in the library.
func SkipProcessingPixelDataValue() ParseOption {
return func(set *parseOptSet) {
Expand Down
2 changes: 1 addition & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func Example_readFile() {
// See also: dicom.Parse, which uses a more generic io.Reader API.
dataset, _ := dicom.ParseFile("testdata/1.dcm", nil)

// Dataset will nicely print the DICOM dataset data out of the box.
// Dataset will nicely print the DICOM dataset int16Data out of the box.
fmt.Println(dataset)

// Dataset is also JSON serializable out of the box.
Expand Down
12 changes: 6 additions & 6 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ var (
ErrorUnsupportedBitsAllocated = errors.New("unsupported BitsAllocated")
errorUnableToParseFloat = errors.New("unable to parse float type")
ErrorExpectedEvenLength = errors.New("field length is not even, in violation of DICOM spec")
ErrorSignedNativePixelDataUnsupported = errors.New("the Pixel Representation tag indicates signed native pixel data is present, _and_ negative Pixel Data values were found, but this is not yet supported")
ErrorSignedNativePixelDataUnsupported = errors.New("the Pixel Representation tag indicates signed native pixel int16Data is present, _and_ negative Pixel Data values were found, but this is not yet supported")
)

// reader is responsible for mid-level dicom parsing capabilities, like
// reading tags, VRs, and elements from the low-level dicomio.Reader dicom data.
// reading tags, VRs, and elements from the low-level dicomio.Reader dicom int16Data.
// TODO(suyashkumar): consider revisiting naming of this struct "reader" as it
// interplays with the rawReader dicomio.Reader. We could consider combining
// them, or embedding the dicomio.Reader struct into reader.
Expand Down Expand Up @@ -211,7 +211,7 @@ func (r *reader) readHeader() ([]*Element, error) {
return nil, err
}
debug.Logf("header-group: %v", group)
// Only read group 2 data
// Only read group 2 int16Data
if group != 0x0002 {
break
}
Expand Down Expand Up @@ -281,8 +281,8 @@ func (r *reader) readPixelData(vl uint32, d *Dataset, fc chan<- *frame.Frame) (V
return val, err
}

// Assume we're reading NativeData data since we have a defined value length as per Part 5 Sec A.4 of DICOM spec.
// We need Elements that have been already parsed (rows, cols, etc) to parse frames out of NativeData Pixel data
// Assume we're reading NativeData int16Data since we have a defined value length as per Part 5 Sec A.4 of DICOM spec.
// We need Elements that have been already parsed (rows, cols, etc) to parse frames out of NativeData Pixel int16Data
if d == nil {
return nil, errors.New("the Dataset context cannot be nil in order to read Native PixelData")
}
Expand Down Expand Up @@ -323,7 +323,7 @@ func fillBufferSingleBitAllocated(pixelData []int, d dicomio.Reader, bo binary.B
debug.Logf("currentByte: %0b", currentByte)

// Read in the 8 bits from the current byte.
// Always treat the data as LittleEndian encoded.
// Always treat the int16Data as LittleEndian encoded.
// This is what pydicom appears to do, and I can't get Go to properly
// write out bytes literals in BigEndian, even using binary.Write
// (in order to test what BigEndian might look like). We should consider
Expand Down
Loading

0 comments on commit d7ffe99

Please sign in to comment.