11#include < volt/cli/common.h>
22#include < volt/grain_segmentation_service.h>
3+ #include < volt/plugin/option_reader.h>
34#include < oneapi/tbb/global_control.h>
45#include < tbb/info.h>
56
910
1011using namespace Volt ;
1112using namespace Volt ::CLI ;
13+ using namespace Volt ::Plugin;
1214
13- void showUsage (const std::string& name) {
14- printUsageHeader (name, " Volt - Grain Segmentation" );
15- std::cerr
16- << " --rmsd <float> RMSD threshold for PTM. [default: 0.1]\n "
17- << " --minGrainAtomCount <int> Minimum atoms per grain. [default: 100]\n "
18- << " --adoptOrphanAtoms <true|false> Adopt orphan atoms. [default: true]\n "
19- << " --handleCoherentInterfaces <true|false> Handle coherent interfaces. [default: true]\n "
20- << " --mergeAlgorithm <name> Merge algorithm: GraphClusteringAutomatic | GraphClusteringManual | MinimumSpanningTree. [default: GraphClusteringAutomatic]\n "
21- << " --mergingThreshold <float> Merge threshold (used by Manual/MST modes). [default: 0]\n "
22- << " --outputBonds Output neighbor bonds. [default: false]\n "
23- << " --threads <int> Max worker threads (TBB/OMP). [default: auto]\n " ;
24- printHelpOption ();
15+ static PluginDescriptor buildDescriptor () {
16+ return {
17+ " grain-segmentation" ,
18+ " Grain Segmentation" ,
19+ {
20+ {" --rmsd" , " float" , " RMSD threshold for PTM." , " 0.1" , {}, " " },
21+ {" --minGrainAtomCount" , " int" , " Minimum atoms per grain." , " 100" , {}, " " },
22+ {" --adoptOrphanAtoms" , " bool" , " Adopt orphan atoms." , " true" , {}, " " },
23+ {" --handleCoherentInterfaces" , " bool" , " Handle coherent interfaces." , " true" , {}, " " },
24+ {" --mergeAlgorithm" , " enum" , " Grain merge algorithm." , " GraphClusteringAutomatic" ,
25+ {" GraphClusteringAutomatic" , " GraphClusteringManual" , " MinimumSpanningTree" }, " " },
26+ {" --mergingThreshold" , " float" , " Merge threshold (used by Manual/MST modes)." , " 0" , {}, " " },
27+ {" --outputBonds" , " bool" , " Output neighbor bonds." , " false" , {}, " " },
28+ }
29+ };
2530}
2631
2732int main (int argc, char * argv[]) {
33+ const PluginDescriptor descriptor = buildDescriptor ();
34+
2835 if (argc < 2 ) {
29- showUsage (argv[0 ]);
36+ showPluginUsage (argv[0 ], descriptor );
3037 return 1 ;
3138 }
32-
39+
3340 std::string filename, outputBase;
3441 auto opts = parseArgs (argc, argv, filename, outputBase);
35-
36- if (hasOption (opts, " --help" ) || filename.empty ()) {
37- showUsage (argv[0 ]);
38- return filename.empty () ? 1 : 0 ;
42+
43+ if (auto exitCode = handleIntrospection (argv[0 ], descriptor, opts, filename)) {
44+ return *exitCode;
3945 }
40-
46+
4147 if (!hasOption (opts, " --threads" )) {
4248 const int maxAvailableThreads = static_cast <int >(oneapi::tbb::info::default_concurrency ());
4349 int physicalCores = 0 ;
@@ -93,12 +99,14 @@ int main(int argc, char* argv[]) {
9399 outputBase = deriveOutputBase (filename, outputBase);
94100 spdlog::info (" Output base: {}" , outputBase);
95101
96- bool adoptOrphanAtoms = getString (opts, " --adoptOrphanAtoms" , " true" ) == " true" ;
97- int minGrainAtomCount = getInt (opts, " --minGrainAtomCount" , 100 );
98- bool handleCoherentInterfaces = getString (opts, " --handleCoherentInterfaces" , " true" ) == " true" ;
99- bool outputBonds = hasOption (opts, " --outputBonds" );
102+ const OptionReader options (descriptor, opts);
103+
104+ bool adoptOrphanAtoms = options.boolean (" --adoptOrphanAtoms" );
105+ int minGrainAtomCount = options.integer (" --minGrainAtomCount" );
106+ bool handleCoherentInterfaces = options.boolean (" --handleCoherentInterfaces" );
107+ bool outputBonds = options.boolean (" --outputBonds" );
100108
101- const std::string mergeAlgorithmStr = getString (opts, " --mergeAlgorithm" , " GraphClusteringAutomatic " );
109+ const std::string mergeAlgorithmStr = options. text ( " --mergeAlgorithm" );
102110 MergeAlgorithm mergeAlgorithm = MergeAlgorithm::GraphClusteringAutomatic;
103111 if (mergeAlgorithmStr == " GraphClusteringManual" ){
104112 mergeAlgorithm = MergeAlgorithm::GraphClusteringManual;
@@ -107,7 +115,7 @@ int main(int argc, char* argv[]) {
107115 }else if (mergeAlgorithmStr != " GraphClusteringAutomatic" ){
108116 spdlog::warn (" Unknown mergeAlgorithm '{}', defaulting to GraphClusteringAutomatic" , mergeAlgorithmStr);
109117 }
110- double mergingThreshold = getDouble (opts, " --mergingThreshold" , 0 . 0f );
118+ double mergingThreshold = options. number ( " --mergingThreshold" );
111119
112120 spdlog::info (" Grain segmentation parameters:" );
113121 spdlog::info (" - adoptOrphanAtoms: {}" , adoptOrphanAtoms);
@@ -118,7 +126,7 @@ int main(int argc, char* argv[]) {
118126 spdlog::info (" - outputBonds: {}" , outputBonds);
119127
120128 GrainSegmentationService analyzer;
121- analyzer.setRMSD (getDouble (opts, " --rmsd" , 0 . 1f ));
129+ analyzer.setRMSD (options. number ( " --rmsd" ));
122130 analyzer.setParameters (
123131 adoptOrphanAtoms,
124132 minGrainAtomCount,
0 commit comments