Skip to content

Commit

Permalink
Proper LogError and LogWarning (#1237)
Browse files Browse the repository at this point in the history
* proper LogError and LogWarning; removing LogFatal

* addressing review comments
  • Loading branch information
griegler authored and yxlao committed Oct 14, 2019
1 parent edb5272 commit 661a9a1
Show file tree
Hide file tree
Showing 140 changed files with 1,482 additions and 1,654 deletions.
7 changes: 4 additions & 3 deletions docs/_static/C++/TestVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
if (io::ReadTriangleMesh(argv[2], *mesh_ptr)) {
utility::LogInfo("Successfully read {}\n", argv[2]);
} else {
utility::LogError("Failed to read {}\n\n", argv[2]);
utility::LogWarning("Failed to read {}\n\n", argv[2]);
return 1;
}
mesh_ptr->ComputeVertexNormals();
Expand All @@ -61,13 +61,14 @@ int main(int argc, char *argv[]) {
if (io::ReadPointCloud(argv[2], *cloud_ptr)) {
utility::LogInfo("Successfully read {}\n", argv[2]);
} else {
utility::LogError("Failed to read {}\n\n", argv[2]);
utility::LogWarning("Failed to read {}\n\n", argv[2]);
return 1;
}
cloud_ptr->NormalizeNormals();
visualization::DrawGeometries({cloud_ptr}, "PointCloud", 1600, 900);
} else {
utility::LogError("Unrecognized option: {}\n", option);
utility::LogWarning("Unrecognized option: {}\n", option);
return 1;
}
utility::LogInfo("End of the test.\n");

Expand Down
35 changes: 17 additions & 18 deletions examples/Cpp/AzureKinectMKVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace open3d;
void WriteJsonToFile(const std::string &filename, const Json::Value &value) {
std::ofstream out(filename);
if (!out.is_open()) {
utility::LogFatal("Cannot write to {}\n", filename);
utility::LogFatal("Cannot write to {}", filename);
}

Json::StreamWriterBuilder builder;
Expand All @@ -49,10 +49,10 @@ void WriteJsonToFile(const std::string &filename, const Json::Value &value) {
Json::Value GenerateDatasetConfig(const std::string &output_path) {
Json::Value value;

utility::LogInfo("Writing to config.json\n");
utility::LogInfo("Writing to config.json");
utility::LogInfo(
"Please change path_dataset and path_intrinsic when you move the "
"dataset.\n");
"dataset.");

if (output_path[0] == '/') { // global dir
value["path_dataset"] = output_path;
Expand Down Expand Up @@ -80,8 +80,8 @@ Json::Value GenerateDatasetConfig(const std::string &output_path) {
void PrintUsage() {
PrintOpen3DVersion();
// clang-format off
utility::LogInfo("Usage:\n");
utility::LogInfo("AzureKinectMKVReader --input input.mkv [--output] [path]\n");
utility::LogInfo("Usage:");
utility::LogInfo("AzureKinectMKVReader --input input.mkv [--output] [path]");
// clang-format on
}

Expand All @@ -98,25 +98,24 @@ int main(int argc, char **argv) {
bool write_image = false;
std::string output_path;
if (!utility::ProgramOptionExists(argc, argv, "--output")) {
utility::LogInfo("No output image path, only play mkv.\n");
utility::LogInfo("No output image path, only play mkv.");
} else {
output_path = utility::GetProgramOptionAsString(argc, argv, "--output");
if (output_path.empty()) {
utility::LogError("Output path {} is empty, only play mkv.\n",
utility::LogError("Output path {} is empty, only play mkv.",
output_path);
return 1;
}
if (utility::filesystem::DirectoryExists(output_path)) {
utility::LogError(
"Output path {} already existing, only play mkv.\n",
output_path);
utility::LogError("Output path {} already existing, only play mkv.",
output_path);
return 1;
} else if (!utility::filesystem::MakeDirectory(output_path)) {
utility::LogError("Unable to create path {}, only play mkv.\n",
utility::LogError("Unable to create path {}, only play mkv.",
output_path);
return 1;
} else {
utility::LogInfo("Decompress images to {}\n", output_path);
utility::LogInfo("Decompress images to {}", output_path);
utility::filesystem::MakeDirectoryHierarchy(output_path + "/color");
utility::filesystem::MakeDirectoryHierarchy(output_path + "/depth");
write_image = true;
Expand All @@ -126,7 +125,7 @@ int main(int argc, char **argv) {
io::MKVReader mkv_reader;
mkv_reader.Open(mkv_filename);
if (!mkv_reader.IsOpened()) {
utility::LogError("Unable to open {}\n", mkv_filename);
utility::LogError("Unable to open {}", mkv_filename);
return 1;
}

Expand All @@ -142,10 +141,10 @@ int main(int argc, char **argv) {
GLFW_KEY_SPACE, [&](visualization::Visualizer *vis) {
if (flag_play) {
utility::LogInfo(
"Playback paused, press [SPACE] to continue\n");
"Playback paused, press [SPACE] to continue");
} else {
utility::LogInfo(
"Playback resumed, press [SPACE] to pause\n");
"Playback resumed, press [SPACE] to pause");
}
flag_play = !flag_play;
return true;
Expand All @@ -154,7 +153,7 @@ int main(int argc, char **argv) {
vis.CreateVisualizerWindow("Open3D Azure Kinect MKV player", 1920, 540);
utility::LogInfo(
"Starting to play. Press [SPACE] to pause. Press [ESC] to "
"exit.\n");
"exit.");

bool is_geometry_added = false;
int idx = 0;
Expand All @@ -178,12 +177,12 @@ int main(int argc, char **argv) {
if (write_image) {
auto color_file =
fmt::format("{0}/color/{1:05d}.jpg", output_path, idx);
utility::LogInfo("Writing to {}\n", color_file);
utility::LogInfo("Writing to {}", color_file);
io::WriteImage(color_file, im_rgbd->color_);

auto depth_file =
fmt::format("{0}/depth/{1:05d}.png", output_path, idx);
utility::LogInfo("Writing to {}\n", depth_file);
utility::LogInfo("Writing to {}", depth_file);
io::WriteImage(depth_file, im_rgbd->depth_);

++idx;
Expand Down
42 changes: 21 additions & 21 deletions examples/Cpp/AzureKinectRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ using namespace open3d;
void PrintUsage() {
PrintOpen3DVersion();
// clang-format off
utility::LogInfo("Usage: \n");
utility::LogInfo("Options: \n");
utility::LogInfo("--config Config .json file (default: none)\n");
utility::LogInfo("--list List the currently connected K4A devices\n");
utility::LogInfo("--device Specify the device index to use (default: 0)\n");
utility::LogInfo("--output Output mkv file name (default: current_time.mkv)\n");
utility::LogInfo("-a Align depth with color image (default: disabled)\n");
utility::LogInfo("-h Print this helper\n");
utility::LogInfo("Usage: ");
utility::LogInfo("Options: ");
utility::LogInfo("--config Config .json file (default: none)");
utility::LogInfo("--list List the currently connected K4A devices");
utility::LogInfo("--device Specify the device index to use (default: 0)");
utility::LogInfo("--output Output mkv file name (default: current_time.mkv)");
utility::LogInfo("-a Align depth with color image (default: disabled)");
utility::LogInfo("-h Print this helper");
// clang-format on
}

Expand Down Expand Up @@ -53,18 +53,18 @@ int main(int argc, char **argv) {
bool success = io::ReadIJsonConvertibleFromJSON(config_filename,
sensor_config);
if (!success) {
utility::LogInfo("Invalid sensor config\n");
utility::LogInfo("Invalid sensor config");
return 1;
}
} else {
utility::LogInfo("Use default sensor config\n");
utility::LogInfo("Use default sensor config");
}

int sensor_index =
utility::GetProgramOptionAsInt(argc, argv, "--device", 0);
if (sensor_index < 0 || sensor_index > 255) {
utility::LogError("Sensor index must between [0, 255]: {}\n",
sensor_index);
utility::LogWarning("Sensor index must between [0, 255]: {}",
sensor_index);
return 1;
}

Expand All @@ -73,12 +73,12 @@ int main(int argc, char **argv) {

std::string recording_filename = utility::GetProgramOptionAsString(
argc, argv, "--output", utility::GetCurrentTimeStamp() + ".mkv");
utility::LogInfo("Prepare writing to {}\n", recording_filename);
utility::LogInfo("Prepare writing to {}", recording_filename);

// Init recorder
io::AzureKinectRecorder recorder(sensor_config, sensor_index);
if (!recorder.InitSensor()) {
utility::LogError("Failed to connect to sensor, abort.\n");
utility::LogWarning("Failed to connect to sensor, abort.");
return 1;
}

Expand All @@ -92,21 +92,21 @@ int main(int argc, char **argv) {
utility::LogInfo(
"Recording paused. "
"Press [SPACE] to continue. "
"Press [ESC] to save and exit.\n");
"Press [ESC] to save and exit.");
flag_record = false;
} else if (!recorder.IsRecordCreated()) {
if (recorder.OpenRecord(recording_filename)) {
utility::LogInfo(
"Recording started. "
"Press [SPACE] to pause. "
"Press [ESC] to save and exit.\n");
"Press [ESC] to save and exit.");
flag_record = true;
} // else flag_record keeps false
} else {
utility::LogInfo(
"Recording resumed, video may be discontinuous. "
"Press [SPACE] to pause. "
"Press [ESC] to save and exit.\n");
"Press [ESC] to save and exit.");
flag_record = true;
}
return false;
Expand All @@ -116,24 +116,24 @@ int main(int argc, char **argv) {
GLFW_KEY_ESCAPE, [&](visualization::Visualizer *vis) {
flag_exit = true;
if (recorder.IsRecordCreated()) {
utility::LogInfo("Recording finished.\n");
utility::LogInfo("Recording finished.");
} else {
utility::LogInfo("Nothing has been recorded.\n");
utility::LogInfo("Nothing has been recorded.");
}
return false;
});

utility::LogInfo(
"In the visulizer window, "
"press [SPACE] to start recording, "
"press [ESC] to exit.\n");
"press [ESC] to exit.");

vis.CreateVisualizerWindow("Open3D Azure Kinect Recorder", 1920, 540);
do {
auto im_rgbd =
recorder.RecordFrame(flag_record, enable_align_depth_to_color);
if (im_rgbd == nullptr) {
utility::LogInfo("Invalid capture, skipping this frame\n");
utility::LogInfo("Invalid capture, skipping this frame");
continue;
}

Expand Down
24 changes: 12 additions & 12 deletions examples/Cpp/AzureKinectViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ using namespace open3d;
void PrintUsage() {
PrintOpen3DVersion();
// clang-format off
utility::LogInfo("Options: \n");
utility::LogInfo("--config Config .json file (default: none)\n");
utility::LogInfo("--list List the currently connected K4A devices\n");
utility::LogInfo("--device Specify the device index to use (default: 0)\n");
utility::LogInfo("-a Align depth with color image (default: disabled)\n");
utility::LogInfo("-h Print this helper\n");
utility::LogInfo("Options: ");
utility::LogInfo("--config Config .json file (default: none)");
utility::LogInfo("--list List the currently connected K4A devices");
utility::LogInfo("--device Specify the device index to use (default: 0)");
utility::LogInfo("-a Align depth with color image (default: disabled)");
utility::LogInfo("-h Print this helper");
// clang-format on
}

Expand All @@ -44,18 +44,18 @@ int main(int argc, char **argv) {
auto config_filename =
utility::GetProgramOptionAsString(argc, argv, "--config", "");
if (!io::ReadIJsonConvertibleFromJSON(config_filename, sensor_config)) {
utility::LogInfo("Invalid sensor config\n");
utility::LogInfo("Invalid sensor config");
return 1;
}
} else {
utility::LogInfo("Use default sensor config\n");
utility::LogInfo("Use default sensor config");
}

int sensor_index =
utility::GetProgramOptionAsInt(argc, argv, "--device", 0);
if (sensor_index < 0 || sensor_index > 255) {
utility::LogError("Sensor index must between [0, 255]: {}\n",
sensor_index);
utility::LogWarning("Sensor index must between [0, 255]: {}",
sensor_index);
return 1;
}

Expand All @@ -65,7 +65,7 @@ int main(int argc, char **argv) {
// Init sensor
io::AzureKinectSensor sensor(sensor_config);
if (!sensor.Connect(sensor_index)) {
utility::LogError("Failed to connect to sensor, abort.\n");
utility::LogWarning("Failed to connect to sensor, abort.");
return 1;
}

Expand All @@ -83,7 +83,7 @@ int main(int argc, char **argv) {
do {
auto im_rgbd = sensor.CaptureFrame(enable_align_depth_to_color);
if (im_rgbd == nullptr) {
utility::LogInfo("Invalid capture, skipping this frame\n");
utility::LogInfo("Invalid capture, skipping this frame");
continue;
}

Expand Down
5 changes: 2 additions & 3 deletions examples/Cpp/CameraPoseTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ int main(int argc, char *argv[]) {
utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);

if (argc != 3) {
utility::LogInfo("Usage :\n");
utility::LogInfo(
"> CameraPoseTrajectory trajectory_file pcds_dir\n");
utility::LogInfo("Usage :");
utility::LogInfo("> CameraPoseTrajectory trajectory_file pcds_dir");
return 1;
}
const int NUM_OF_COLOR_PALETTE = 5;
Expand Down
8 changes: 4 additions & 4 deletions examples/Cpp/ColorMapOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ int main(int argc, char *argv[]) {
utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);

if (argc != 2) {
utility::LogInfo("Usage :\n");
utility::LogInfo("> ColorMapOptimization data_dir\n");
utility::LogInfo("Usage :");
utility::LogInfo("> ColorMapOptimization data_dir");
return 1;
}
// Read RGBD images
Expand All @@ -48,9 +48,9 @@ int main(int argc, char *argv[]) {
assert(depth_filenames.size() == color_filenames.size());
std::vector<std::shared_ptr<geometry::RGBDImage>> rgbd_images;
for (size_t i = 0; i < depth_filenames.size(); i++) {
utility::LogDebug("reading {}...\n", depth_filenames[i]);
utility::LogDebug("reading {}...", depth_filenames[i]);
auto depth = io::CreateImageFromFile(depth_filenames[i]);
utility::LogDebug("reading {}...\n", color_filenames[i]);
utility::LogDebug("reading {}...", color_filenames[i]);
auto color = io::CreateImageFromFile(color_filenames[i]);
auto rgbd_image = geometry::RGBDImage::CreateFromColorAndDepth(
*color, *depth, 1000.0, 3.0, false);
Expand Down
14 changes: 7 additions & 7 deletions examples/Cpp/DepthCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ int main(int argc, char *argv[]) {
utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
if (argc < 2) {
PrintOpen3DVersion();
utility::LogInfo("Usage:\n");
utility::LogInfo(" > DepthCapture [filename]\n");
utility::LogInfo("Usage:");
utility::LogInfo(" > DepthCapture [filename]");
return 1;
}

auto mesh_ptr = io::CreateMeshFromFile(argv[1]);
mesh_ptr->ComputeVertexNormals();
utility::LogInfo("Press S to capture a depth image.\n");
utility::LogInfo("Press S to capture a depth image.");
VisualizerWithDepthCapture visualizer;
visualizer.CreateVisualizerWindow("Depth Capture", 640, 480, 200, 200);
visualizer.AddGeometry(mesh_ptr);
Expand All @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {

if (!utility::filesystem::FileExists("depth.png") ||
!utility::filesystem::FileExists("camera.json")) {
utility::LogInfo("Depth has not been captured.\n");
utility::LogInfo("Depth has not been captured.");
return 1;
}

Expand All @@ -122,15 +122,15 @@ int main(int argc, char *argv[]) {
visualizer1.Run();
visualizer1.DestroyVisualizerWindow();

utility::LogInfo("Press L to validate the depth image.\n");
utility::LogInfo("Press P to load the capturing camera pose.\n");
utility::LogInfo("Press L to validate the depth image.");
utility::LogInfo("Press P to load the capturing camera pose.");
VisualizerWithDepthCapture visualizer2;
visualizer2.CreateVisualizerWindow("Depth Validation", 640, 480, 200, 200);
visualizer2.AddGeometry(mesh_ptr);
visualizer2.Run();
visualizer2.DestroyVisualizerWindow();

utility::LogInfo("End of the test.\n");
utility::LogInfo("End of the test.");

return 0;
}
Loading

0 comments on commit 661a9a1

Please sign in to comment.