Skip to content

Commit

Permalink
Keep discriminating volumes until all files grouped
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Mar 19, 2024
1 parent 0775d5b commit f892552
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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;
// }
#endif // DISCRIMINATE_VOLUME_H
23 changes: 16 additions & 7 deletions packages/dicom/gdcm/image-sets-normalization.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
{
Expand All @@ -37,6 +37,7 @@ int main(int argc, char *argv[])

ITK_WASM_PARSE(pipeline);

std::vector<gdcm::Directory::FilenamesType> volumes;
gdcm::Scanner s;

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

std::vector<gdcm::Directory::FilenamesType> sortedFiles = dv.GetSortedFiles();
std::vector<gdcm::Directory::FilenamesType> sorted = dv.GetSortedFiles();
for (gdcm::Directory::FilenamesType &volume : sorted)
{
volumes.push_back(volume);
}

std::vector<gdcm::Directory::FilenamesType> 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<gdcm::Directory::FilenamesType>::const_iterator fileNames = sortedFiles.begin();
fileNames != sortedFiles.end(); ++fileNames)
std::vector<gdcm::Directory::FilenamesType>::const_iterator fileNames = volumes.begin();
fileNames != volumes.end(); ++fileNames)
{
groupId++;
rapidjson::Value sortedFileNameArray(rapidjson::kArrayType);

for (
Expand All @@ -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);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)

0 comments on commit f892552

Please sign in to comment.