From a987831c1d4a468440617704bef30a2e3219b38b Mon Sep 17 00:00:00 2001 From: Christina Rossmanith Date: Fri, 7 May 2021 15:28:32 +0200 Subject: [PATCH 1/2] Add optional flag to -comp --- ConvertImageND.cxx | 13 +++++++++++-- adapters/ConnectedComponents.cxx | 4 ++-- adapters/ConnectedComponents.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ConvertImageND.cxx b/ConvertImageND.cxx index d4595e9..4ec9b1a 100644 --- a/ConvertImageND.cxx +++ b/ConvertImageND.cxx @@ -593,8 +593,17 @@ ::ProcessCommand(int argc, char *argv[]) else if (cmd == "-connected-components" || cmd == "-connected" || cmd == "-comp") { ConnectedComponents adapter(this); - adapter(); - return 0; + if (argv[1][0] == '1') + { + adapter(true); + std::cout << "fully connected" << std::endl; + return 1; + } + else + { + adapter(false); + return 0; + } } else if (cmd == "-clear") diff --git a/adapters/ConnectedComponents.cxx b/adapters/ConnectedComponents.cxx index 1b71f1d..c010b54 100644 --- a/adapters/ConnectedComponents.cxx +++ b/adapters/ConnectedComponents.cxx @@ -32,7 +32,7 @@ template void ConnectedComponents -::operator() () +::operator() (bool fullyConnected) { // The image is assumed to be binary. If background is non-zero, call binarize // to map the background to zero @@ -61,7 +61,7 @@ ::operator() () // Plug in the filter's components typename CCFilter::Pointer fltConnect = CCFilter::New(); fltConnect->SetInput(image); - fltConnect->SetFullyConnected(false); + fltConnect->SetFullyConnected(fullyConnected); fltConnect->Update(); // Describe what we are doing diff --git a/adapters/ConnectedComponents.h b/adapters/ConnectedComponents.h index 5a31c56..d98f219 100644 --- a/adapters/ConnectedComponents.h +++ b/adapters/ConnectedComponents.h @@ -37,7 +37,7 @@ class ConnectedComponents : public ConvertAdapter ConnectedComponents(Converter *c) : c(c) {} - void operator() (); + void operator() (bool fullyConnected); private: Converter *c; From 08bd16f61ad2462d4f297b06dfcd9b8b2f88357e Mon Sep 17 00:00:00 2001 From: Christina Rossmanith Date: Fri, 7 May 2021 16:33:30 +0200 Subject: [PATCH 2/2] Add optional flag to -comp (part 2) --- ConvertImageND.cxx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ConvertImageND.cxx b/ConvertImageND.cxx index 4ec9b1a..2d1ffaa 100644 --- a/ConvertImageND.cxx +++ b/ConvertImageND.cxx @@ -593,17 +593,19 @@ ::ProcessCommand(int argc, char *argv[]) else if (cmd == "-connected-components" || cmd == "-connected" || cmd == "-comp") { ConnectedComponents adapter(this); - if (argv[1][0] == '1') - { - adapter(true); - std::cout << "fully connected" << std::endl; - return 1; - } - else - { - adapter(false); - return 0; - } + bool fullyConnected = false; + int np = 0; + if (argc > 1 && argv[1][0] != '-') + { + switch (atoi(argv[1])) { + case 0: break; + case 1: fullyConnected = true; break; + default: throw ConvertException("Valid value for option -comp [0|1] (fully connected = false|true)"); + } + np = 1; + } + adapter(fullyConnected); + return np; } else if (cmd == "-clear")