ctkDICOMDatasetTest1.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // ctkDICOMCore includes
  15. #include "ctkDICOMDataset.h"
  16. // STD includes
  17. #include <iostream>
  18. int ctkDICOMDatasetTest1( int argc, char * argv [] )
  19. {
  20. Q_UNUSED(argc);
  21. Q_UNUSED(argv);
  22. ctkDICOMDataset dataset;
  23. dataset.InitializeFromDataset(0);
  24. dataset.InitializeFromFile(QString());
  25. try
  26. {
  27. dataset.Serialize();
  28. }
  29. catch(...)
  30. {
  31. std::cout << "ctkDICOMDataset::Serialize() throws exceptions" << std::endl;
  32. //return EXIT_FAILURE;
  33. }
  34. try
  35. {
  36. dataset.Deserialize();
  37. }
  38. catch(...)
  39. {
  40. std::cout << "ctkDICOMDataset::Deserialize() throws exceptions"
  41. << std::endl;
  42. //return EXIT_FAILURE;
  43. }
  44. dataset.MarkForInitialization();
  45. try
  46. {
  47. dataset.EnsureDcmDataSetIsInitialized();
  48. }
  49. catch(...)
  50. {
  51. std::cout << "ctkDICOMDataset::EnsureDcmDataSetIsInitialized() throws"
  52. << " exceptions" << std::endl;
  53. //return EXIT_FAILURE;
  54. }
  55. dataset.CopyElement(0, DcmTagKey(), 0);
  56. QString decode = dataset.Decode(DcmTag(),OFString());
  57. if (!decode.isEmpty())
  58. {
  59. std::cerr << "ctkDICOMDataset::Decode() failed: "
  60. << qPrintable(decode) << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. OFString encode = dataset.Encode(DcmTag(), decode);
  64. DcmElement* element = 0;
  65. OFCondition condition = dataset.findAndGetElement(DcmTag(), element);
  66. if (ctkDICOMDataset::CheckCondition(condition))
  67. {
  68. std::cerr << "ctkDICOMDataset::findAndGetElement() failed" << std::endl;
  69. return EXIT_FAILURE;
  70. }
  71. OFString string;
  72. condition = dataset.findAndGetOFString(DcmTag(), string);
  73. if (ctkDICOMDataset::CheckCondition(condition))
  74. {
  75. std::cerr << "ctkDICOMDataset::findAndGetOFString() failed" << std::endl;
  76. return EXIT_FAILURE;
  77. }
  78. try
  79. {
  80. QString string = dataset.GetAllElementValuesAsString(DcmTag());
  81. QString string2 = dataset.GetElementAsString(DcmTag());
  82. QStringList list = dataset.GetElementAsStringList(DcmTag());
  83. ctkDICOMPersonName name = dataset.GetElementAsPersonName(DcmTag());
  84. ctkDICOMPersonNameList nameList = dataset.GetElementAsPersonNameList(DcmTag());
  85. QDate date = dataset.GetElementAsDate(DcmTag());
  86. QTime time = dataset.GetElementAsTime(DcmTag());
  87. double doubleValue = dataset.GetElementAsDouble(DcmTag());
  88. int integerValue = dataset.GetElementAsInteger(DcmTag());
  89. int shortValue = dataset.GetElementAsSignedShort(DcmTag());
  90. int ushortValue = dataset.GetElementAsUnsignedShort(DcmTag());
  91. QDateTime dateTime = dataset.GetElementAsDateTime(DcmTag());
  92. Q_UNUSED(string);
  93. Q_UNUSED(string2);
  94. Q_UNUSED(list);
  95. Q_UNUSED(name);
  96. Q_UNUSED(nameList);
  97. Q_UNUSED(date);
  98. Q_UNUSED(time);
  99. Q_UNUSED(doubleValue);
  100. Q_UNUSED(integerValue);
  101. Q_UNUSED(shortValue);
  102. Q_UNUSED(ushortValue);
  103. Q_UNUSED(dateTime);
  104. dataset.SetElementAsString( DcmTag(), QString());
  105. dataset.SetElementAsStringList( DcmTag(), QStringList() );
  106. dataset.SetElementAsPersonName( DcmTag(), ctkDICOMPersonName());
  107. dataset.SetElementAsPersonNameList( DcmTag(), ctkDICOMPersonNameList() );
  108. dataset.SetElementAsDate( DcmTag(), QDate() );
  109. dataset.SetElementAsTime( DcmTag(), QTime() );
  110. dataset.SetElementAsDateTime( DcmTag(), QDateTime() );
  111. dataset.SetElementAsInteger( DcmTag(), 0 ); // type IS
  112. dataset.SetElementAsSignedShort( DcmTag(), 0 ); // type SS
  113. dataset.SetElementAsUnsignedShort( DcmTag(), 0 ); // type US
  114. }
  115. catch(...)
  116. {
  117. std::cout << "ctkDICOMDataset::GetElementValueAsXXX() throws exceptions"
  118. << std::endl;
  119. //return EXIT_FAILURE;
  120. }
  121. ctkDICOMDataset::TranslateDefinedTermPatientPosition(QString());
  122. ctkDICOMDataset::TranslateDefinedTermModality(QString());
  123. ctkDICOMDataset::TagKey(DcmTag());
  124. ctkDICOMDataset::TagDescription(DcmTag());
  125. ctkDICOMDataset::TagVR(DcmTag());
  126. return EXIT_SUCCESS;
  127. }