ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ManuallyCropGeometry.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "CloudViewer.h"
9 
10 void PrintHelp() {
11  using namespace cloudViewer;
12  PrintCloudViewerVersion();
13 
14  // clang-format off
15  utility::LogInfo("Usage:");
16  utility::LogInfo(" > ManuallyCropGeometry [--pointcloud/mesh] geometry_file [options]");
17  utility::LogInfo(" Manually crop geometry in speficied file.");
18  utility::LogInfo("");
19  utility::LogInfo("Options:");
20  utility::LogInfo(" --pointcloud, : Read geometry as point cloud.");
21  utility::LogInfo(" --mesh, : Read geometry as mesh.");
22  utility::LogInfo(" --help, -h : Print help information.");
23  utility::LogInfo(" --verbose n : Set verbose level (0-4).");
24  utility::LogInfo(" --voxel_size d : Set downsample voxel size.");
25  utility::LogInfo(" --without_dialog : Disable dialogs. Default files will be used.");
26  // clang-format on
27 }
28 
29 int main(int argc, char **argv) {
30  using namespace cloudViewer;
31 
32  if (argc < 2 || utility::ProgramOptionExists(argc, argv, "--help") ||
33  utility::ProgramOptionExists(argc, argv, "-h")) {
34  PrintHelp();
35  return 0;
36  }
37 
38  int verbose = utility::GetProgramOptionAsInt(argc, argv, "--verbose", 2);
40  double voxel_size =
41  utility::GetProgramOptionAsDouble(argc, argv, "--voxel_size", -1.0);
42  bool with_dialog =
43  !utility::ProgramOptionExists(argc, argv, "--without_dialog");
44 
46  voxel_size, with_dialog,
48  vis.CreateVisualizerWindow("Crop Point Cloud", 1920, 1080, 100, 100);
49  if (utility::ProgramOptionExists(argc, argv, "--pointcloud")) {
50  auto pcd_ptr = io::CreatePointCloudFromFile(argv[2]);
51  if (pcd_ptr == nullptr || !pcd_ptr->IsEmpty()) {
52  utility::LogWarning("Failed to read the point cloud.");
53  return 1;
54  }
55  vis.AddGeometry(pcd_ptr);
56  if (pcd_ptr->size() > 5000000) {
57  vis.GetRenderOption().point_size_ = 1.0;
58  }
59  } else if (utility::ProgramOptionExists(argc, argv, "--mesh")) {
60  auto mesh_ptr = io::CreateMeshFromFile(argv[2]);
61  if (mesh_ptr == nullptr || mesh_ptr->IsEmpty()) {
62  utility::LogWarning("Failed to read the mesh.");
63  return 1;
64  }
65  vis.AddGeometry(mesh_ptr);
66  }
67  vis.Run();
69  return 0;
70 }
int main(int argc, char **argv)
void PrintHelp()
virtual bool IsEmpty() const override
Definition: ecvMesh.h:735
double point_size_
Point size for PointCloud.
Definition: RenderOption.h:178
bool AddGeometry(std::shared_ptr< const ccHObject > geometry_ptr, bool reset_bounding_box=true) override
Function to add geometry to the scene and create corresponding shaders.
RenderOption & GetRenderOption()
Function to retrieve the associated RenderOption.
Definition: Visualizer.h:177
void DestroyVisualizerWindow()
Function to destroy a window.
Definition: Visualizer.cpp:235
void Run()
Function to activate the window.
Definition: Visualizer.cpp:289
bool CreateVisualizerWindow(const std::string &window_name="CloudViewer", const int width=640, const int height=480, const int left=50, const int top=50, const bool visible=true)
Function to create a window and initialize GLFW.
Definition: Visualizer.cpp:95
ccMesh * mesh_ptr
#define LogWarning(...)
Definition: Logging.h:72
#define LogInfo(...)
Definition: Logging.h:81
std::shared_ptr< ccMesh > CreateMeshFromFile(const std::string &filename, bool print_progress)
std::shared_ptr< ccPointCloud > CreatePointCloudFromFile(const std::string &filename, const std::string &format, bool print_progress)
std::string GetFileParentDirectory(const std::string &filename)
Definition: FileSystem.cpp:314
int GetProgramOptionAsInt(int argc, char **argv, const std::string &option, const int default_value=0)
Definition: Console.cpp:31
void SetVerbosityLevel(VerbosityLevel level)
Definition: Logging.cpp:89
bool ProgramOptionExists(int argc, char **argv, const std::string &option)
Definition: Console.cpp:100
double GetProgramOptionAsDouble(int argc, char **argv, const std::string &option, const double default_value=0.0)
Definition: Console.cpp:52
Generic file read and write utility for python interface.