| 163 | } |
| 164 | |
| 165 | int main(int argc, char* argv[]) |
| 166 | { |
| 167 | int returnValue = EXIT_SUCCESS; |
| 168 | |
| 169 | mitkCommandLineParser parser; |
| 170 | InitializeCommandLineParser(parser); |
| 171 | |
| 172 | auto args = parser.parseArguments(argc, argv); |
| 173 | |
| 174 | if (args.empty()) |
| 175 | return EXIT_FAILURE; |
| 176 | |
| 177 | try |
| 178 | { |
| 179 | auto inputFilename = us::any_cast<std::string>(args["input"]); |
| 180 | auto referenceFilename = us::any_cast<std::string>(args["reference"]); |
| 181 | auto outputFilename = us::any_cast<std::string>(args["output"]); |
| 182 | auto format = ParseOutputFormat(args); |
| 183 | |
| 184 | auto referenceImage = mitk::IOUtil::Load<mitk::Image>(referenceFilename); |
| 185 | auto inputs = FilterValidInputs(mitk::IOUtil::Load(inputFilename)); |
| 186 | |
| 187 | MITK_INFO << "Found " << inputs.size() << " input contour set(s)"; |
| 188 | |
| 189 | fs::path outputPath(outputFilename); |
| 190 | CreateParentDirectories(outputPath); |
| 191 | |
| 192 | mitk::MultiLabelSegmentation::Pointer labelSetImage; // Only used for "multilabel" output |
| 193 | unsigned int nonameCounter = 0; // Helper variable to generate placeholder names for nameless contour sets |
| 194 | |
| 195 | for (auto input : inputs) |
| 196 | { |
| 197 | // If the input file contains multiple contour sets but the output format is not set to "multilabel", |
| 198 | // we create separate output files for each contour set. In this case the specified output filename |
| 199 | // is used only as a base filename and the names of the individual contour sets are appended accordingly. |
| 200 | |
| 201 | if (inputs.size() > 1 && format != OutputFormat::Multilabel) |
| 202 | { |
| 203 | outputPath = outputFilename; |
| 204 | auto name = GetSafeName(input); |
| 205 | |
| 206 | if (name.empty()) |
| 207 | name = "nameless_" + std::to_string(nonameCounter++); |
| 208 | |
| 209 | outputPath.replace_filename(outputPath.stem().string() + '_' + name + outputPath.extension().string()); |
| 210 | } |
| 211 | |
| 212 | // Do the actual conversion from a contour set to an image with a background pixel value of 0. |
| 213 | // - For "binary" output, use pixel value 1 and unsigned char as pixel type. |
| 214 | // - For "label" output, use pixel value 1 and our label pixel type. |
| 215 | // - For "multilabel" output, use the next available label value instead. |
| 216 | |
| 217 | const auto labelValue = labelSetImage.IsNotNull() |
| 218 | ? labelSetImage->GetUnusedLabelValue() |
| 219 | : 1; |
| 220 | |
| 221 | auto filter = mitk::ContourModelSetToImageFilter::New(); |
| 222 | filter->SetMakeOutputLabelPixelType(format != OutputFormat::Binary); |
nothing calls this directly
no test coverage detected