Skip to content

Conversation

@bpeake-illuscio
Copy link
Contributor

@bpeake-illuscio bpeake-illuscio commented Mar 25, 2021

Hello again!

In writing some code, I realized it would be useful to get the number of inner values a Value contains without having to do a type assert (or really knowing anything about the inner type).

This is a small PR that adds a ValueCount()int and GetValueIndex(i int)interface{} methods to Value.

Example:

package main

import (
	"fmt"
	"github.com/suyashkumar/dicom"
	"github.com/suyashkumar/dicom/pkg/tag"
)

func main() {
	element, err := dicom.NewElement(tag.ModalitiesInStudy, []string{"MR", "CT"})
	if err != nil {
		panic(err)
	}

	tagInfo, err := tag.Find(tag.ModalitiesInStudy)
	if err != nil {
		panic(err)
	}

	fmt.Println("TAG        :", element.Tag)
	fmt.Println("VM         :", tagInfo.VM)
	fmt.Println("VALUE COUNT:", element.Value.ValueCount())

	for i := 0 ; i < element.Value.ValueCount() ; i++ {
		fmt.Printf("VALUE %v    : %v\n", i, element.Value.GetValueIndex(i))
	}

	// Output:
	// TAG        : (0008,0061)
	// VM         : 1-n
	// VALUE COUNT: 2
	// VALUE 0    : MR
	// VALUE 1    : CT
}

I've opened this as a draft PR in case you feel it doesn't fit the lib. Let me know what you think!

@bpeake-illuscio bpeake-illuscio changed the title Feature/add ValueCount() method to Value Feature/add ValueCount() and GetValueIndex() method to Value Mar 26, 2021
@bpeake-illuscio
Copy link
Contributor Author

I just updated this PR to also include a GetValueIndex() method. I am working on a problem where it would be useful in testing to be able to build a []interface{} slice of the inner Element values.

@bpeake-illuscio
Copy link
Contributor Author

Although, looking at this I think it might make more sense to handle PixelData like []byte, always return a count of 1, and return the entire data, instead of frames. I'm going to update that real quick.

@bpeake-illuscio
Copy link
Contributor Author

alright, that change is up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants