Skip to content

Commit

Permalink
WIP: change pipeline interface
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Mar 6, 2024
1 parent 0b00b5e commit 80bdcf0
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 45 deletions.
11 changes: 1 addition & 10 deletions packages/dicom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,4 @@ set(CMAKE_CXX_STANDARD 17)

add_subdirectory(gdcm)
add_subdirectory(dcmtk)

find_package(ITK REQUIRED
COMPONENTS ITKCommon
ITKGDCM
WebAssemblyInterface
)
include(${ITK_USE_FILE})

add_executable(sort-dicom-series sort-dicom-series.cxx)
target_link_libraries(sort-dicom-series PUBLIC ${ITK_LIBRARIES})
add_subdirectory(sort-dicom-series)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path


def test_sort_dicom_series():
from itkwasm_dicom_wasi import sort_dicom_series

file_name = "ImageOrientation.1.dcm"
test_file_path = Path(
"..", "..", "test", "data", "input", "DicomImageOrientationTest", file_name
)

assert test_file_path.exists()

output_text = sort_dicom_series([test_file_path])
assert output_text
35 changes: 0 additions & 35 deletions packages/dicom/sort-dicom-series.cxx

This file was deleted.

20 changes: 20 additions & 0 deletions packages/dicom/sort-dicom-series/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
find_package(ITK REQUIRED
COMPONENTS ITKCommon
ITKGDCM
WebAssemblyInterface
)
include(${ITK_USE_FILE})

add_executable(sort-dicom-series sort-dicom-series.cxx)
target_link_libraries(sort-dicom-series PUBLIC ${ITK_LIBRARIES})

enable_testing()

add_test(NAME sort-dicom-series-help COMMAND sort-dicom-series --help)

add_test(NAME sort-dicom-series-smoke
COMMAND sort-dicom-series --files
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm
)
52 changes: 52 additions & 0 deletions packages/dicom/sort-dicom-series/sort-dicom-series.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*=========================================================================
* 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.
*
*=========================================================================*/

#include "itkPipeline.h"
#include "itkOutputTextStream.h"

#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"

int main(int argc, char *argv[])
{
itk::wasm::Pipeline pipeline("sort-dicom-series", "Group DICOM files into volumes", argc, argv);

std::vector<std::string> files;
pipeline.add_option("--files", files, "DICOM files to group")->required()->check(CLI::ExistingFile)->type_size(1, -1)->type_name("INPUT_BINARY_FILE");

itk::wasm::OutputTextStream volumes;
pipeline.add_option("volumes", volumes, "Files grouped into volumes")->required()->type_name("OUTPUT_JSON");

ITK_WASM_PARSE(pipeline);

rapidjson::Document volumesJson;
volumesJson.SetObject();
rapidjson::Document::AllocatorType &allocator = volumesJson.GetAllocator();

rapidjson::Value almostEqualValue;
almostEqualValue.SetBool(false);
volumesJson.AddMember("almostEqual", almostEqualValue, allocator);

rapidjson::StringBuffer stringBuffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(stringBuffer);
volumesJson.Accept(writer);
volumes.Get() << stringBuffer.GetString();

return EXIT_SUCCESS;
}
10 changes: 10 additions & 0 deletions packages/dicom/typescript/src/index-node-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ export type { ReadImageDicomFileSeriesNodeOptions }

import readImageDicomFileSeriesNode from './read-image-dicom-file-series-node.js'
export { readImageDicomFileSeriesNode }


import SortDicomSeriesNodeResult from './sort-dicom-series-node-result.js'
export type { SortDicomSeriesNodeResult }

import SortDicomSeriesNodeOptions from './sort-dicom-series-node-options.js'
export type { SortDicomSeriesNodeOptions }

import sortDicomSeriesNode from './sort-dicom-series-node.js'
export { sortDicomSeriesNode }
10 changes: 10 additions & 0 deletions packages/dicom/typescript/src/index-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ export { readImageDicomFileSeries }

import readImageDicomFileSeriesWorkerFunction from './read-image-dicom-file-series-worker-function.js'
export { readImageDicomFileSeriesWorkerFunction }


import SortDicomSeriesResult from "./sort-dicom-series-result.js";
export type { SortDicomSeriesResult };

import SortDicomSeriesOptions from "./sort-dicom-series-options.js";
export type { SortDicomSeriesOptions };

import sortDicomSeries from "./sort-dicom-series.js";
export { sortDicomSeries };
19 changes: 19 additions & 0 deletions packages/dicom/typescript/test/node/sort-dicom-series.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from "ava";
import path from "path";
import glob from "glob";

import { sortDicomSeriesNode } from "../../dist/index-node.js";

const testDataInputDirectory = path.resolve("..", "test", "data", "input");
const testSeriesDirectory = path.resolve(
testDataInputDirectory,
"DicomImageOrientationTest",
);
const testDicomSeriesFiles = glob.sync(`${testSeriesDirectory}/*.dcm`);

test("Test reading a DICOM file", async (t) => {
const { volumes } = await sortDicomSeriesNode({
files: testDicomSeriesFiles,
});
t.assert(!!volumes);
});

0 comments on commit 80bdcf0

Please sign in to comment.