DICOM file의 tag를 Hierarchy 형태로 출력, Test용 Dump 함수를 수정
1.기존 test_loaddcm()함수에 DumpDcmTagHierarchy()
함수를 통한 출력으로 변경
void test_loaddcm(char* fileName) { DcmFileFormat dcmfileFormat; OFCondition status = dcmfileFormat.loadFile(fileName); if (!status.good()) return; //DumpDcmTag(&dcmfileFormat); DumpDcmTagHierarchy(&dcmfileFormat); }
2. DumpDcmTagHierarchy()
는 단순히 dicom 파일의 root dataset()에서 printHierarchy
를 호출
int DumpDcmTagHierarchy(void* dcmPtr) { DcmFileFormat* pDcmFileFormat = (DcmFileFormat*)dcmPtr; if (pDcmFileFormat == NULL) return 0; DcmDataset* dset = pDcmFileFormat->getDataset(); printHierarchy(dset, dset->nextInContainer(NULL) /* gets first element in dataset */, 0 /* main level */); return 1; }
3.printHierarchy
를 재귀 호출 방식으로 leaf가 있는 Element를 DcmStack
을 이용하여 출력
void printHierarchy(DcmObject* container, DcmObject* current, unsigned int level) { // Check if we are already done at the current level if ((container == NULL) || (current == NULL)) return; OFBool isLeaf = current->isLeaf(); // Print current object char buffer[256]; sprintf(buffer, "%s %s %s", std::string(level * 2, ' ').c_str(), current->getTag().toString().c_str(), ((DcmTag&)current->getTag()).getTagName()); OutputDebugStringA(buffer); // If the current object has childs, advance to first child if (!current->isLeaf()) { DcmStack stack; current->nextObject(stack, OFTrue); printHierarchy(current, stack.top(), level + 1); } // Advance to next object on the same level as the current one printHierarchy(container, container->nextInContainer(current), level); }
4.출력 화면