Skip to content

Commit 73afc37

Browse files
authored
VisualizePPM: Remove volpkg requirement (#122)
1 parent 2e4cebb commit 73afc37

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

utils/src/VisualizePPM.cpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ auto main(int argc, char* argv[]) -> int
1919
po::options_description required("General Options");
2020
required.add_options()
2121
("help,h", "Show this message")
22-
("volpkg,v", po::value<std::string>(), "VolumePkg path")
22+
("dims,d", po::value<std::vector<int>>()->multitoken(),
23+
"Volume dimensions (X Y Z). Required if normalizing the outputs "
24+
"and --volpkg is not provided")
25+
("volpkg,v", po::value<std::string>(), "VolumePkg path. Required if "
26+
"normalizing the outputs and --dims is not provided.")
2327
("volume", po::value<std::string>(), "Volume to use for position "
2428
"normalization. Default: The first volume in the volume package.")
2529
("ppm,p", po::value<std::string>()->required(), "Input PPM file")
@@ -61,29 +65,47 @@ auto main(int argc, char* argv[]) -> int
6165
vc::Volume::Pointer vol;
6266
cv::Vec3d dims;
6367
if (normalize) {
64-
if (parsed.count("volpkg") == 0) {
68+
const auto have_dims = parsed.count("dims") > 0;
69+
const auto have_vpkg = parsed.count("volpkg") > 0;
70+
if (have_dims and have_vpkg) {
6571
vc::Logger()->error(
66-
"the option '--volpkg' is required but missing");
72+
"The options '--dims' and '--volpkg' are "
73+
"mutually exclusive");
6774
return EXIT_FAILURE;
6875
}
69-
const fs::path volpkgPath = parsed["volpkg"].as<std::string>();
70-
auto vpkg = vc::VolumePkg::New(volpkgPath);
71-
try {
72-
if (parsed.count("volume") > 0) {
73-
vol = vpkg->volume(parsed["volume"].as<std::string>());
74-
} else {
75-
vol = vpkg->volume();
76+
if (have_dims) {
77+
const auto d = parsed["dims"].as<std::vector<int>>();
78+
if (d.size() != 3) {
79+
vc::Logger()->error("Volume dims should be 3D");
80+
}
81+
dims[0] = d[0];
82+
dims[1] = d[1];
83+
dims[2] = d[2];
84+
} else if (have_vpkg) {
85+
const fs::path volpkgPath = parsed["volpkg"].as<std::string>();
86+
auto vpkg = vc::VolumePkg::New(volpkgPath);
87+
try {
88+
if (parsed.count("volume") > 0) {
89+
vol = vpkg->volume(parsed["volume"].as<std::string>());
90+
} else {
91+
vol = vpkg->volume();
92+
}
93+
} catch (const std::exception&) {
94+
vc::Logger()->error(
95+
"Cannot load volume. Please check that the Volume Package "
96+
"has volumes and that the volume ID is correct.");
97+
return EXIT_FAILURE;
7698
}
77-
} catch (const std::exception& e) {
99+
dims = {
100+
static_cast<double>(vol->sliceWidth()),
101+
static_cast<double>(vol->sliceHeight()),
102+
static_cast<double>(vol->numSlices())};
103+
} else {
78104
vc::Logger()->error(
79-
"Cannot load volume. Please check that the Volume Package has "
80-
"volumes and that the volume ID is correct.");
105+
"must provided '--dims' or '--volpkg' when normalizing"
106+
"PPM values");
81107
return EXIT_FAILURE;
82108
}
83-
dims = {
84-
static_cast<double>(vol->sliceWidth()),
85-
static_cast<double>(vol->sliceHeight()),
86-
static_cast<double>(vol->numSlices())};
87109
}
88110

89111
// Get input file

0 commit comments

Comments
 (0)