Replace separate parse function with constructor.

This commit is contained in:
2018-04-09 13:56:34 +02:00
parent 2c373fbd1e
commit 8cdeefc37b
3 changed files with 21 additions and 30 deletions

View File

@@ -48,31 +48,32 @@ static void parse_color(const char *input, Color &targetColor)
throw std::invalid_argument(errorBuf);
}
Options Options::parse(const int argc, char *const argv[])
Options::Options(int argc, char * const argv[]):
layerTransparancy_(1),
interactionTransparancy_(1),
pathColor_({1, 1, 1, 0.1})
{
using namespace boost::program_options;
try {
Options options;
options_description desc("Options");
positional_options_description positionals;
positionals.add("input", -1);
options_description hidden;
hidden.add_options()
("input", value<std::vector<std::string>>(&options.inputPaths)->required()->composing());
("input", value<std::vector<std::string>>(&inputPaths)->required()->composing());
desc.add_options()
("help,h", "Show this help message")
("weights,w", value<std::string>(&options.weightsPath)->required(), "weights file for the network")
("network,n", value<std::string>(&options.modelPath)->required(), "caffe model file for the network")
("labels,l", value<std::string>(&options.labelsPath), "labels file")
("means,m", value<std::string>(&options.meansPath), "means file")
("weights,w", value<std::string>(&weightsPath)->required(), "weights file for the network")
("network,n", value<std::string>(&modelPath)->required(), "caffe model file for the network")
("labels,l", value<std::string>(&labelsPath), "labels file")
("means,m", value<std::string>(&meansPath), "means file")
("path-color,p", value<std::string>(), "color for paths")
("layer-opacity", value<float>(&options.layerTransparancy_), "Opacity for layers")
("interaction-opacity", value<float>(&options.interactionTransparancy_), "Opacity for interactions")
("dump,d", value<std::string>(&options.dumpPath), "dump convolutional images in this directory");
("layer-opacity", value<float>(&layerTransparancy_), "Opacity for layers")
("interaction-opacity", value<float>(&interactionTransparancy_), "Opacity for interactions")
("dump,d", value<std::string>(&dumpPath), "dump convolutional images in this directory");
options_description composed = desc;
composed.add(hidden);
@@ -88,17 +89,16 @@ Options Options::parse(const int argc, char *const argv[])
notify(vm);
if (vm.count("path-color")) {
parse_color(vm["path-color"].as<std::string>().c_str(), options.pathColor_);
parse_color(vm["path-color"].as<std::string>().c_str(), pathColor_);
}
// Sanity checks
check_file(options.modelPath);
check_file(options.weightsPath);
if (!options.meansPath.empty()) check_file(options.meansPath);
if (!options.labelsPath.empty()) check_file(options.labelsPath);
std::for_each(options.inputPaths.begin(), options.inputPaths.end(), check_file);
return options;
check_file(modelPath);
check_file(weightsPath);
if (!meansPath.empty()) check_file(meansPath);
if (!labelsPath.empty()) check_file(labelsPath);
std::for_each(inputPaths.begin(), inputPaths.end(), check_file);
return;
} catch (required_option& e) {
if (e.get_option_name() == "--input") {
std::cerr << "No input files specified" << std::endl;
@@ -150,13 +150,6 @@ std::optional<PNGDumper> Options::imageDumper() const
}
}
Options::Options() noexcept :
layerTransparancy_(1),
interactionTransparancy_(1),
pathColor_({1, 1, 1, 0.1})
{
}
const Color &Options::pathColor() const
{
return pathColor_;

View File

@@ -14,7 +14,7 @@ namespace fmri {
class Options {
public:
static Options parse(const int argc, char *const argv[]);
Options(const int argc, char *const argv[]);
const string& model() const;
const string& weights() const;
@@ -37,7 +37,5 @@ namespace fmri {
string labelsPath;
string dumpPath;
vector<string> inputPaths;
Options() noexcept;
};
}

View File

@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
glutCreateWindow(argv[0]);
// Prepare data for simulations
Options options = Options::parse(argc, argv);
Options options(argc, argv);
RenderingState::instance().loadOptions(options);
loadSimulationData(options);