Skip to content

Commit

Permalink
OpenNI apps: Improve handling of command line arguments (#5494)
Browse files Browse the repository at this point in the history
* #5491

* Fixed typo at line 212 in parse.h

* Fixed formatting.

* Deleted whitespaces.

* Dependency update before attempting fix.

* Fixed formatting style.

* Revert . . formatting?

* Weird formatting error test?

* Fixed dependency, this should hopefully build.

* Removed unused variable in openni_ii_normal_estimation.cpp

* Build test after improvements and refactors.

* Build Test #2.

* deleted whitespace.

* Fixed formatting errors.

* Fixed formatting openni_boundary_estimation.cpp.

* Fixed formatting openni_boundary_estimation.cpp.

* Fixed formatting openni_boundary_estimation.cpp.

* Formatting check #1.

* Formatting check 2.

* Deleted whitespace.

* Changed general parsing structure, improved usage().

* Fixed formatting errors.

* Fixed!

* resolve merge conflict

* resolve merge conflict

* format test

* new format test

* test formatting

* test formatting

* test formatting

* command line behavior mimics previous version(s), consistent help flags

* rest of the files
  • Loading branch information
filbert14 committed Jan 31, 2023
1 parent 2beb1bb commit 7b7dabe
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 271 deletions.
43 changes: 29 additions & 14 deletions apps/src/openni_3d_concave_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include <pcl/common/time.h>
#include <pcl/console/parse.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/openni_camera/openni_driver.h>
#include <pcl/io/openni_grabber.h>
Expand Down Expand Up @@ -165,19 +166,29 @@ class OpenNI3DConcaveHull {
void
usage(char** argv)
{
std::cout << "usage: " << argv[0] << " <device_id> <options>\n\n";
std::cout << "usage: " << argv[0] << " [-device_id X (default: \"#1\")]\n\n";

openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance();
if (driver.getNumberDevices() > 0) {
for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices(); ++deviceIdx) {
// clang-format off
std::cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << std::endl;
std::cout << "device_id may be #1, #2, ... for the first second etc device in the list or" << std::endl
<< " bus@address for the device connected to a specific usb-bus / address combination (works only in Linux) or" << std::endl
<< " <serial-number> (only in Linux and for devices which provide serial numbers)" << std::endl;
std::cout << "Device: " << deviceIdx + 1
<< ", vendor: " << driver.getVendorName (deviceIdx)
<< ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'"
<< std::endl;
// clang-format on
}

std::cout << "\ndevice_id may be:" << std::endl
<< " #1, #2, ... for the first second etc device in the list or"
<< std::endl

<< " bus@address for the device connected to a specific "
"usb-bus/address combination (works only in Linux) or"

<< " <serial-number> (only in Linux and for devices which provide "
"serial numbers)";
}
else
std::cout << "No devices connected." << std::endl;
Expand All @@ -186,24 +197,28 @@ usage(char** argv)
int
main(int argc, char** argv)
{
std::string arg;
if (argc > 1)
arg = std::string(argv[1]);

if (arg == "--help" || arg == "-h") {
/////////////////////////////////////////////////////////////////////
if (pcl::console::find_argument(argc, argv, "-h") != -1 ||
pcl::console::find_argument(argc, argv, "--help") != -1) {
usage(argv);
return 1;
}

pcl::OpenNIGrabber grabber(arg);
std::string device_id = "";
if (pcl::console::parse_argument(argc, argv, "-device_id", device_id) == -1 &&
argc > 1 && argv[1][0] != '-')
device_id = argv[1];
/////////////////////////////////////////////////////////////////////

pcl::OpenNIGrabber grabber(device_id);
if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgba>()) {
PCL_INFO("PointXYZRGBA mode enabled.\n");
OpenNI3DConcaveHull<pcl::PointXYZRGBA> v(arg);
OpenNI3DConcaveHull<pcl::PointXYZRGBA> v(device_id);
v.run();
}
else {
PCL_INFO("PointXYZ mode enabled.\n");
OpenNI3DConcaveHull<pcl::PointXYZ> v(arg);
OpenNI3DConcaveHull<pcl::PointXYZ> v(device_id);
v.run();
}
return 0;
Expand Down
43 changes: 29 additions & 14 deletions apps/src/openni_3d_convex_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include <pcl/common/time.h>
#include <pcl/console/parse.h>
#include <pcl/filters/passthrough.h>
#include <pcl/io/openni_camera/openni_driver.h>
#include <pcl/io/openni_grabber.h>
Expand Down Expand Up @@ -163,19 +164,29 @@ class OpenNI3DConvexHull {
void
usage(char** argv)
{
std::cout << "usage: " << argv[0] << " <device_id> <options>\n\n";
std::cout << "usage: " << argv[0] << " [-device_id X (default: \"#1\")]\n\n";

openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance();
if (driver.getNumberDevices() > 0) {
for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices(); ++deviceIdx) {
// clang-format off
std::cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << std::endl;
std::cout << "device_id may be #1, #2, ... for the first second etc device in the list or" << std::endl
<< " bus@address for the device connected to a specific usb-bus / address combination (works only in Linux) or" << std::endl
<< " <serial-number> (only in Linux and for devices which provide serial numbers)" << std::endl;
std::cout << "Device: " << deviceIdx + 1
<< ", vendor: " << driver.getVendorName (deviceIdx)
<< ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'"
<< std::endl;
// clang-format on
}

std::cout << "\ndevice_id may be:" << std::endl
<< " #1, #2, ... for the first second etc device in the list or"
<< std::endl

<< " bus@address for the device connected to a specific "
"usb-bus/address combination (works only in Linux) or"

<< " <serial-number> (only in Linux and for devices which provide "
"serial numbers)";
}
else
std::cout << "No devices connected." << std::endl;
Expand All @@ -184,24 +195,28 @@ usage(char** argv)
int
main(int argc, char** argv)
{
std::string arg;
if (argc > 1)
arg = std::string(argv[1]);

if (arg == "--help" || arg == "-h") {
/////////////////////////////////////////////////////////////////////
if (pcl::console::find_argument(argc, argv, "-h") != -1 ||
pcl::console::find_argument(argc, argv, "--help") != -1) {
usage(argv);
return 1;
}

pcl::OpenNIGrabber grabber(arg);
std::string device_id = "";
if (pcl::console::parse_argument(argc, argv, "-device_id", device_id) == -1 &&
argc > 1 && argv[1][0] != '-')
device_id = argv[1];
/////////////////////////////////////////////////////////////////////

pcl::OpenNIGrabber grabber(device_id);
if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgba>()) {
PCL_INFO("PointXYZRGBA mode enabled.\n");
OpenNI3DConvexHull<pcl::PointXYZRGBA> v(arg);
OpenNI3DConvexHull<pcl::PointXYZRGBA> v(device_id);
v.run();
}
else {
PCL_INFO("PointXYZ mode enabled.\n");
OpenNI3DConvexHull<pcl::PointXYZ> v(arg);
OpenNI3DConvexHull<pcl::PointXYZ> v(device_id);
v.run();
}
return 0;
Expand Down
41 changes: 28 additions & 13 deletions apps/src/openni_boundary_estimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/

#include <pcl/common/time.h>
#include <pcl/console/parse.h>
#include <pcl/features/boundary.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/filters/approximate_voxel_grid.h>
Expand Down Expand Up @@ -180,19 +181,29 @@ class OpenNIIntegralImageNormalEstimation {
void
usage(char** argv)
{
std::cout << "usage: " << argv[0] << " <device_id> <options>\n\n";
std::cout << "usage: " << argv[0] << " [-device_id X (default: \"#1\")]\n\n";

openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance();
if (driver.getNumberDevices() > 0) {
for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices(); ++deviceIdx) {
// clang-format off
std::cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << std::endl;
std::cout << "device_id may be #1, #2, ... for the first second etc device in the list or" << std::endl
<< " bus@address for the device connected to a specific usb-bus / address combination (works only in Linux) or" << std::endl
<< " <serial-number> (only in Linux and for devices which provide serial numbers)" << std::endl;
std::cout << "Device: " << deviceIdx + 1
<< ", vendor: " << driver.getVendorName (deviceIdx)
<< ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'"
<< std::endl;
// clang-format on
}

std::cout << "\ndevice_id may be:" << std::endl
<< " #1, #2, ... for the first second etc device in the list or"
<< std::endl

<< " bus@address for the device connected to a specific "
"usb-bus/address combination (works only in Linux) or"

<< " <serial-number> (only in Linux and for devices which provide "
"serial numbers)";
}
else
std::cout << "No devices connected." << std::endl;
Expand All @@ -201,18 +212,22 @@ usage(char** argv)
int
main(int argc, char** argv)
{
std::string arg;
if (argc > 1)
arg = std::string(argv[1]);

if (arg == "--help" || arg == "-h") {
/////////////////////////////////////////////////////////////////////
if (pcl::console::find_argument(argc, argv, "-h") != -1 ||
pcl::console::find_argument(argc, argv, "--help") != -1) {
usage(argv);
return 1;
}

pcl::OpenNIGrabber grabber(arg);
std::string device_id = "";
if (pcl::console::parse_argument(argc, argv, "-device_id", device_id) == -1 &&
argc > 1 && argv[1][0] != '-')
device_id = argv[1];
/////////////////////////////////////////////////////////////////////

pcl::OpenNIGrabber grabber(device_id);
if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgb>()) {
OpenNIIntegralImageNormalEstimation v(arg);
OpenNIIntegralImageNormalEstimation v(device_id);
v.run();
}
else
Expand Down
46 changes: 29 additions & 17 deletions apps/src/openni_color_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,33 @@ class OpenNIPassthrough {
void
usage(char** argv)
{
std::cout << "usage: " << argv[0]
<< " <device_id> [-rgb <red> <green> <blue> [-radius <radius>] ]\n\n"
<< std::endl;
std::cout << "usage: " << argv[0] << " [options]\n\n"
<< "where options are:\n"
<< " -device_id X: specify the device id (default: \"#1\").\n"
<< " -rgb R G B: -- (default: 0 0 0)\n"
<< " -radius X: -- (default: 442)\n\n";

openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance();
if (driver.getNumberDevices() > 0) {
for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices(); ++deviceIdx) {
// clang-format off
std::cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << (int)driver.getBus (deviceIdx) << " @ " << (int)driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << std::endl;
std::cout << "device_id may be #1, #2, ... for the first second etc device in the list or" << std::endl
<< " bus@address for the device connected to a specific usb-bus / address combination (works only in Linux) or" << std::endl
<< " <serial-number> (only in Linux and for devices which provide serial numbers)" << std::endl;
std::cout << "Device: " << deviceIdx + 1
<< ", vendor: " << driver.getVendorName (deviceIdx)
<< ", product: " << driver.getProductName (deviceIdx)
<< ", connected: " << driver.getBus (deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'"
<< std::endl;
// clang-format on
}

std::cout << "\ndevice_id may be:" << std::endl
<< " #1, #2, ... for the first second etc device in the list or"
<< std::endl

<< " bus@address for the device connected to a specific "
"usb-bus/address combination (works only in Linux) or"

<< " <serial-number> (only in Linux and for devices which provide "
"serial numbers)";
}
else
std::cout << "No devices connected." << std::endl;
Expand All @@ -182,22 +194,21 @@ usage(char** argv)
int
main(int argc, char** argv)
{
if (argc < 2) {
usage(argv);
return 1;
}

std::string arg(argv[1]);

if (arg == "--help" || arg == "-h") {
/////////////////////////////////////////////////////////////////////
if (pcl::console::find_argument(argc, argv, "-h") != -1 ||
pcl::console::find_argument(argc, argv, "--help") != -1) {
usage(argv);
return 1;
}

std::string device_id = "";
unsigned char red = 0, green = 0, blue = 0;
int rr, gg, bb;
unsigned char radius = 442; // all colors!

if (pcl::console::parse_argument(argc, argv, "-device_id", device_id) == -1 &&
argc > 1 && argv[1][0] != '-')
device_id = argv[1];
if (pcl::console::parse_3x_arguments(argc, argv, "-rgb", rr, gg, bb, true) != -1) {
std::cout << "-rgb present" << std::endl;
int rad;
Expand All @@ -213,8 +224,9 @@ main(int argc, char** argv)
if (bb >= 0 && bb < 256)
blue = (unsigned char)bb;
}
/////////////////////////////////////////////////////////////////////

pcl::OpenNIGrabber grabber(arg);
pcl::OpenNIGrabber grabber(device_id);

if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgba>()) {
OpenNIPassthrough<pcl::PointXYZRGBA> v(grabber, red, green, blue, radius);
Expand Down

0 comments on commit 7b7dabe

Please sign in to comment.