|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | + |
| 19 | +#include "itkDCMTKImageIO.h" |
| 20 | +#include "itkMetaDataObject.h" |
| 21 | +#include "itkTestingMacros.h" |
| 22 | + |
| 23 | +#include <iostream> |
| 24 | + |
| 25 | +// Tests that DCMTKImageIO::ReadImageInformation() populates the metadata |
| 26 | +// dictionary with DICOM tag values using "GGGG|EEEE" keys (lowercase |
| 27 | +// matching GDCMImageIO behavior). Expected values are verified against |
| 28 | +// Input/DicomSeries/Image0075.dcm using the same fixture as |
| 29 | +// itkDCMTKGetDicomTagsTest. |
| 30 | +int |
| 31 | +itkDCMTKImageIOMetadataTest(int argc, char * argv[]) |
| 32 | +{ |
| 33 | + if (argc != 2) |
| 34 | + { |
| 35 | + std::cerr << "Missing parameters." << std::endl; |
| 36 | + std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " <DicomImage>" << std::endl; |
| 37 | + return EXIT_FAILURE; |
| 38 | + } |
| 39 | + |
| 40 | + auto dcmtkIO = itk::DCMTKImageIO::New(); |
| 41 | + |
| 42 | + ITK_TEST_EXPECT_TRUE(dcmtkIO->CanReadFile(argv[1])); |
| 43 | + dcmtkIO->SetFileName(argv[1]); |
| 44 | + ITK_TRY_EXPECT_NO_EXCEPTION(dcmtkIO->ReadImageInformation()); |
| 45 | + |
| 46 | + const itk::MetaDataDictionary & dict = dcmtkIO->GetMetaDataDictionary(); |
| 47 | + |
| 48 | + // Dictionary must be populated |
| 49 | + ITK_TEST_EXPECT_TRUE(!dict.GetKeys().empty()); |
| 50 | + |
| 51 | + // Pixel data (7FE0,0010) must NOT appear in the dictionary |
| 52 | + ITK_TEST_EXPECT_TRUE(!dict.HasKey("7fe0|0010")); |
| 53 | + |
| 54 | + // Verify string-valued DICOM tags using the "GGGG|EEEE" key format. |
| 55 | + // Values are specific to the test file Input/DicomSeries/Image0075.dcm |
| 56 | + std::string value; |
| 57 | + |
| 58 | + // (0008,0021) DA StudyDate |
| 59 | + ITK_TEST_EXPECT_TRUE(itk::ExposeMetaData<std::string>(dict, "0008|0021", value)); |
| 60 | + ITK_TEST_EXPECT_EQUAL(value, std::string("20030625")); |
| 61 | + |
| 62 | + // (0010,0010) PN PatientName |
| 63 | + ITK_TEST_EXPECT_TRUE(itk::ExposeMetaData<std::string>(dict, "0010|0010", value)); |
| 64 | + ITK_TEST_EXPECT_EQUAL(value, std::string("Wes Turner")); |
| 65 | + |
| 66 | + // (0010,0040) CS PatientSex |
| 67 | + ITK_TEST_EXPECT_TRUE(itk::ExposeMetaData<std::string>(dict, "0010|0040", value)); |
| 68 | + ITK_TEST_EXPECT_EQUAL(value, std::string("O")); |
| 69 | + |
| 70 | + // (0028,0004) CS PhotometricInterpretation |
| 71 | + ITK_TEST_EXPECT_TRUE(itk::ExposeMetaData<std::string>(dict, "0028|0004", value)); |
| 72 | + ITK_TEST_EXPECT_EQUAL(value, std::string("MONOCHROME2")); |
| 73 | + |
| 74 | + std::cout << "Test finished." << std::endl; |
| 75 | + return EXIT_SUCCESS; |
| 76 | +} |
0 commit comments