Skip to content

Commit f892552

Browse files
committed
Keep discriminating volumes until all files grouped
1 parent 0775d5b commit f892552

File tree

4 files changed

+78
-67
lines changed

4 files changed

+78
-67
lines changed

packages/dicom/gdcm/discriminate-volume.cxx packages/dicom/gdcm/gdcmDiscriminateVolume.h

+36-42
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
/*=========================================================================
2+
3+
Program: GDCM (Grassroots DICOM). A DICOM library
4+
5+
Copyright (c) 2006-2011 Mathieu Malaterre
6+
All rights reserved.
7+
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8+
9+
This software is distributed WITHOUT ANY WARRANTY; without even
10+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11+
PURPOSE. See the above copyright notice for more information.
12+
13+
=========================================================================*/
14+
15+
/*=========================================================================
16+
17+
* Copyright NumFOCUS
18+
*
19+
* Licensed under the Apache License, Version 2.0 (the "License");
20+
* you may not use this file except in compliance with the License.
21+
* You may obtain a copy of the License at
22+
*
23+
* https://www.apache.org/licenses/LICENSE-2.0.txt
24+
*
25+
* Unless required by applicable law or agreed to in writing, software
26+
* distributed under the License is distributed on an "AS IS" BASIS,
27+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
* See the License for the specific language governing permissions and
29+
* limitations under the License.
30+
*
31+
*=========================================================================*/
32+
33+
#ifndef DISCRIMINATE_VOLUME_H
34+
#define DISCRIMINATE_VOLUME_H
35+
136
#include "gdcmScanner.h"
237
#include "gdcmTesting.h"
338
#include "gdcmIPPSorter.h"
@@ -220,45 +255,4 @@ namespace gdcm
220255

221256
} // namespace gdcm
222257

223-
// int main(int argc, char *argv[])
224-
// {
225-
// std::string dir1;
226-
// if (argc < 2)
227-
// {
228-
// const char *extradataroot = nullptr;
229-
// #ifdef GDCM_BUILD_TESTING
230-
// extradataroot = gdcm::Testing::GetDataExtraRoot();
231-
// #endif
232-
// if (!extradataroot)
233-
// {
234-
// return 1;
235-
// }
236-
// dir1 = extradataroot;
237-
// dir1 += "/gdcmSampleData/ForSeriesTesting/VariousIncidences/ST1";
238-
// }
239-
// else
240-
// {
241-
// dir1 = argv[1];
242-
// }
243-
244-
// gdcm::Directory d;
245-
// d.Load(dir1, true); // recursive !
246-
247-
// gdcm::Scanner s;
248-
// s.AddTag(gdcm::t1);
249-
// s.AddTag(gdcm::t2);
250-
// s.AddTag(gdcm::t3);
251-
// s.AddTag(gdcm::t4);
252-
// bool b = s.Scan(d.GetFilenames());
253-
// if (!b)
254-
// {
255-
// std::cerr << "Scanner failed" << std::endl;
256-
// return 1;
257-
// }
258-
259-
// gdcm::DiscriminateVolume dv;
260-
// dv.ProcessIntoVolume(s);
261-
// dv.Print(std::cout);
262-
263-
// return 0;
264-
// }
258+
#endif // DISCRIMINATE_VOLUME_H

packages/dicom/gdcm/image-sets-normalization.cxx

+16-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "rapidjson/stringbuffer.h"
2424
#include "rapidjson/writer.h"
2525

26-
#include "discriminate-volume.cxx"
26+
#include "gdcmDiscriminateVolume.h"
2727

2828
int main(int argc, char *argv[])
2929
{
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
3737

3838
ITK_WASM_PARSE(pipeline);
3939

40+
std::vector<gdcm::Directory::FilenamesType> volumes;
4041
gdcm::Scanner s;
4142

4243
const gdcm::Tag t1(0x0020, 0x000d); // Study Instance UID
@@ -59,18 +60,26 @@ int main(int argc, char *argv[])
5960
gdcm::DiscriminateVolume dv;
6061
dv.ProcessIntoVolume(s);
6162

62-
std::vector<gdcm::Directory::FilenamesType> sortedFiles = dv.GetSortedFiles();
63+
std::vector<gdcm::Directory::FilenamesType> sorted = dv.GetSortedFiles();
64+
for (gdcm::Directory::FilenamesType &volume : sorted)
65+
{
66+
volumes.push_back(volume);
67+
}
68+
69+
std::vector<gdcm::Directory::FilenamesType> unsorted = dv.GetUnsortedFiles();
70+
for (gdcm::Directory::FilenamesType fileGroups : unsorted)
71+
{
72+
volumes.push_back(fileGroups);
73+
}
6374

6475
rapidjson::Document imageSetsJson;
6576
rapidjson::Document::AllocatorType &allocator = imageSetsJson.GetAllocator();
6677
imageSetsJson.SetObject();
6778

68-
int groupId = 0;
6979
for (
70-
std::vector<gdcm::Directory::FilenamesType>::const_iterator fileNames = sortedFiles.begin();
71-
fileNames != sortedFiles.end(); ++fileNames)
80+
std::vector<gdcm::Directory::FilenamesType>::const_iterator fileNames = volumes.begin();
81+
fileNames != volumes.end(); ++fileNames)
7282
{
73-
groupId++;
7483
rapidjson::Value sortedFileNameArray(rapidjson::kArrayType);
7584

7685
for (
@@ -83,7 +92,7 @@ int main(int argc, char *argv[])
8392
}
8493

8594
std::string fileName = fileNames->front();
86-
const char* studyInstanceUID = s.GetValue(fileName.c_str(), t1);
95+
const char *studyInstanceUID = s.GetValue(fileName.c_str(), t1);
8796

8897
rapidjson::Value groupIdKey(studyInstanceUID, allocator);
8998
imageSetsJson.AddMember(groupIdKey, sortedFileNameArray, allocator);

packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,37 @@ def test_one_series():
99
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm",
1010
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm",
1111
]
12-
1312
assert files[0].exists()
14-
1513
image_sets = image_sets_normalization(files)
16-
print(image_sets)
17-
# assert image_sets
18-
19-
assert image_sets == [
14+
assert image_sets
15+
sorted_files = list(image_sets.values())[0]
16+
assert sorted_files == [
2017
str(files[1]),
2118
str(files[2]),
2219
str(files[0]),
2320
]
2421

25-
# def test_two_series():
26-
# files = [
27-
# test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm",
28-
# test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm",
29-
# test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm",
30-
# test_input_path / "dicom-images" / "CT" / "1-1.dcm",
31-
# test_input_path / "dicom-images" / "CT" / "1-2.dcm",
32-
# ]
33-
34-
# assert files[0].exists()
22+
def test_two_series():
23+
files = [
24+
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm",
25+
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm",
26+
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm",
27+
test_input_path / "dicom-images" / "MR" / "1-001.dcm",
28+
test_input_path / "dicom-images" / "MR" / "1-002.dcm",
29+
test_input_path / "dicom-images" / "MR" / "1-003.dcm",
30+
test_input_path / "dicom-images" / "MR" / "1-004.dcm",
31+
test_input_path / "dicom-images" / "MR" / "1-005.dcm",
32+
]
33+
assert files[0].exists()
34+
image_sets = image_sets_normalization(files)
35+
assert image_sets
36+
assert len(image_sets.keys()) == 2
3537

36-
# image_sets = image_sets_normalization(files)
37-
# assert image_sets
38+
def test_strange_ct():
39+
files = [
40+
test_input_path / "dicom-images" / "CT" / "1-1.dcm",
41+
test_input_path / "dicom-images" / "CT" / "1-2.dcm",
42+
]
43+
image_sets = image_sets_normalization(files)
44+
assert image_sets
45+
print(image_sets)

0 commit comments

Comments
 (0)