diff --git a/packages/dicom/gdcm/discriminate-volume.cxx b/packages/dicom/gdcm/gdcmDiscriminateVolume.h similarity index 85% rename from packages/dicom/gdcm/discriminate-volume.cxx rename to packages/dicom/gdcm/gdcmDiscriminateVolume.h index d0a1a5db1..1f678d841 100644 --- a/packages/dicom/gdcm/discriminate-volume.cxx +++ b/packages/dicom/gdcm/gdcmDiscriminateVolume.h @@ -1,3 +1,38 @@ +/*========================================================================= + + Program: GDCM (Grassroots DICOM). A DICOM library + + Copyright (c) 2006-2011 Mathieu Malaterre + All rights reserved. + See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +/*========================================================================= + + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#ifndef DISCRIMINATE_VOLUME_H +#define DISCRIMINATE_VOLUME_H + #include "gdcmScanner.h" #include "gdcmTesting.h" #include "gdcmIPPSorter.h" @@ -220,45 +255,4 @@ namespace gdcm } // namespace gdcm -// int main(int argc, char *argv[]) -// { -// std::string dir1; -// if (argc < 2) -// { -// const char *extradataroot = nullptr; -// #ifdef GDCM_BUILD_TESTING -// extradataroot = gdcm::Testing::GetDataExtraRoot(); -// #endif -// if (!extradataroot) -// { -// return 1; -// } -// dir1 = extradataroot; -// dir1 += "/gdcmSampleData/ForSeriesTesting/VariousIncidences/ST1"; -// } -// else -// { -// dir1 = argv[1]; -// } - -// gdcm::Directory d; -// d.Load(dir1, true); // recursive ! - -// gdcm::Scanner s; -// s.AddTag(gdcm::t1); -// s.AddTag(gdcm::t2); -// s.AddTag(gdcm::t3); -// s.AddTag(gdcm::t4); -// bool b = s.Scan(d.GetFilenames()); -// if (!b) -// { -// std::cerr << "Scanner failed" << std::endl; -// return 1; -// } - -// gdcm::DiscriminateVolume dv; -// dv.ProcessIntoVolume(s); -// dv.Print(std::cout); - -// return 0; -// } \ No newline at end of file +#endif // DISCRIMINATE_VOLUME_H \ No newline at end of file diff --git a/packages/dicom/gdcm/image-sets-normalization.cxx b/packages/dicom/gdcm/image-sets-normalization.cxx index 137b6c58a..00729b1a9 100644 --- a/packages/dicom/gdcm/image-sets-normalization.cxx +++ b/packages/dicom/gdcm/image-sets-normalization.cxx @@ -23,7 +23,7 @@ #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" -#include "discriminate-volume.cxx" +#include "gdcmDiscriminateVolume.h" int main(int argc, char *argv[]) { @@ -37,6 +37,7 @@ int main(int argc, char *argv[]) ITK_WASM_PARSE(pipeline); + std::vector volumes; gdcm::Scanner s; const gdcm::Tag t1(0x0020, 0x000d); // Study Instance UID @@ -59,18 +60,26 @@ int main(int argc, char *argv[]) gdcm::DiscriminateVolume dv; dv.ProcessIntoVolume(s); - std::vector sortedFiles = dv.GetSortedFiles(); + std::vector sorted = dv.GetSortedFiles(); + for (gdcm::Directory::FilenamesType &volume : sorted) + { + volumes.push_back(volume); + } + + std::vector unsorted = dv.GetUnsortedFiles(); + for (gdcm::Directory::FilenamesType fileGroups : unsorted) + { + volumes.push_back(fileGroups); + } rapidjson::Document imageSetsJson; rapidjson::Document::AllocatorType &allocator = imageSetsJson.GetAllocator(); imageSetsJson.SetObject(); - int groupId = 0; for ( - std::vector::const_iterator fileNames = sortedFiles.begin(); - fileNames != sortedFiles.end(); ++fileNames) + std::vector::const_iterator fileNames = volumes.begin(); + fileNames != volumes.end(); ++fileNames) { - groupId++; rapidjson::Value sortedFileNameArray(rapidjson::kArrayType); for ( @@ -83,7 +92,7 @@ int main(int argc, char *argv[]) } std::string fileName = fileNames->front(); - const char* studyInstanceUID = s.GetValue(fileName.c_str(), t1); + const char *studyInstanceUID = s.GetValue(fileName.c_str(), t1); rapidjson::Value groupIdKey(studyInstanceUID, allocator); imageSetsJson.AddMember(groupIdKey, sortedFileNameArray, allocator); diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm index 66b15e5fc..b313e24d8 100755 Binary files a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm and b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm differ diff --git a/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py b/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py index 087720c9b..918639297 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py @@ -9,29 +9,37 @@ def test_one_series(): test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm", test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm", ] - assert files[0].exists() - image_sets = image_sets_normalization(files) - print(image_sets) - # assert image_sets - - assert image_sets == [ + assert image_sets + sorted_files = list(image_sets.values())[0] + assert sorted_files == [ str(files[1]), str(files[2]), str(files[0]), ] -# def test_two_series(): -# files = [ -# test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm", -# test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm", -# test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm", -# test_input_path / "dicom-images" / "CT" / "1-1.dcm", -# test_input_path / "dicom-images" / "CT" / "1-2.dcm", -# ] - -# assert files[0].exists() +def test_two_series(): + files = [ + test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm", + test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm", + test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm", + test_input_path / "dicom-images" / "MR" / "1-001.dcm", + test_input_path / "dicom-images" / "MR" / "1-002.dcm", + test_input_path / "dicom-images" / "MR" / "1-003.dcm", + test_input_path / "dicom-images" / "MR" / "1-004.dcm", + test_input_path / "dicom-images" / "MR" / "1-005.dcm", + ] + assert files[0].exists() + image_sets = image_sets_normalization(files) + assert image_sets + assert len(image_sets.keys()) == 2 -# image_sets = image_sets_normalization(files) -# assert image_sets \ No newline at end of file +def test_strange_ct(): + files = [ + test_input_path / "dicom-images" / "CT" / "1-1.dcm", + test_input_path / "dicom-images" / "CT" / "1-2.dcm", + ] + image_sets = image_sets_normalization(files) + assert image_sets + print(image_sets) \ No newline at end of file