// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipelineNode } from 'itk-wasm';
import path from 'path';
import { fileURLToPath } from 'url';
/**
 * Write DICOM segmentation object for overlapping segments.
 *
 * @param {Image} segImage - dicom segmentation object as an image
 * @param {JsonCompatible} metaInfo - JSON file containing the meta-information that describesthe measurements to be encoded. See DCMQI documentation for details.
 * @param {string} outputDicomFile - File name of the DICOM SEG object that will store theresult of conversion.
 * @param {WriteOverlappingSegmentationNodeOptions} options - options object
 *
 * @returns {Promise<WriteOverlappingSegmentationNodeResult>} - result object
 */
async function writeOverlappingSegmentationNode(segImage, metaInfo, outputDicomFile, options = { refDicomSeries: [], }) {
    const mountDirs = new Set();
    const desiredOutputs = [];
    const inputs = [
        { type: InterfaceTypes.Image, data: segImage },
        { type: InterfaceTypes.JsonCompatible, data: metaInfo },
    ];
    const args = [];
    // Inputs
    const segImageName = '0';
    args.push(segImageName);
    const metaInfoName = '1';
    args.push(metaInfoName);
    // Outputs
    const outputDicomFileName = outputDicomFile;
    args.push(outputDicomFileName);
    mountDirs.add(path.dirname(outputDicomFileName));
    // Options
    args.push('--memory-io');
    if (options.refDicomSeries) {
        if (options.refDicomSeries.length < 1) {
            throw new Error('"ref-dicom-series" option must have a length > 1');
        }
        args.push('--ref-dicom-series');
        options.refDicomSeries.forEach((value) => {
            mountDirs.add(path.dirname(value));
            args.push(value);
        });
    }
    if (options.skipEmptySlices) {
        options.skipEmptySlices && args.push('--skip-empty-slices');
    }
    if (options.useLabelidAsSegmentnumber) {
        options.useLabelidAsSegmentnumber && args.push('--use-labelid-as-segmentnumber');
    }
    const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'write-overlapping-segmentation');
    const { returnValue, stderr, } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs);
    if (returnValue !== 0 && stderr !== "") {
        throw new Error(stderr);
    }
    const result = {};
    return result;
}
export default writeOverlappingSegmentationNode;
//# sourceMappingURL=write-overlapping-segmentation-node.js.map