diff --git a/modules/odm_25dmeshing/src/Odm25dMeshing.cpp b/modules/odm_25dmeshing/src/Odm25dMeshing.cpp index 734ec627..1da5a9d9 100644 --- a/modules/odm_25dmeshing/src/Odm25dMeshing.cpp +++ b/modules/odm_25dmeshing/src/Odm25dMeshing.cpp @@ -141,6 +141,11 @@ void Odm25dMeshing::buildMesh(){ double extentX = bounds[1] - bounds[0]; double extentY = bounds[3] - bounds[2]; + if (resolution == 0.0){ + resolution = (double)maxVertexCount / (sqrt(extentX * extentY) * 75.0); + log << "Automatically set resolution to " << std::fixed << resolution << "\n"; + } + int width = ceil(extentX * resolution); int height = ceil(extentY * resolution); @@ -334,7 +339,7 @@ void Odm25dMeshing::parseArguments(int argc, char **argv) { ss >> resolution; if (ss.bad()) throw Odm25dMeshingException("Argument '" + argument + "' has a bad value (wrong type)."); - resolution = std::min(100000, std::max(resolution, 0.00001)); + resolution = std::min(100000, std::max(resolution, 0)); log << "Resolution was manually set to: " << resolution << "\n"; } else if (argument == "-neighbors" && argIndex < argc) { ++argIndex; @@ -427,7 +432,7 @@ void Odm25dMeshing::printHelp() { << " -verbose whether to print verbose output (default: " << (printInCoutPop ? "true" : "false") << ")\n" << " -maxVertexCount <0 - N> Maximum number of vertices in the output mesh. The mesh might have fewer vertices, but will not exceed this limit. (default: " << maxVertexCount << ")\n" << " -neighbors <1 - 1000> Number of nearest neighbors to consider when doing shepard's interpolation and outlier removal. Higher values lead to smoother meshes but take longer to process. (default: " << neighbors << ")\n" - << " -resolution <1 - N> Size of the interpolated digital surface model (DSM) used for deriving the 2.5D mesh, expressed in pixels per meter unit. (default: " << resolution << ")\n" + << " -resolution <0 - N> Size of the interpolated digital surface model (DSM) used for deriving the 2.5D mesh, expressed in pixels per meter unit. When set to zero, the program automatically attempts to find a good value based on the point cloud extent and target vertex count. (default: " << resolution << ")\n" << "\n"; diff --git a/modules/odm_25dmeshing/src/Odm25dMeshing.hpp b/modules/odm_25dmeshing/src/Odm25dMeshing.hpp index 2f5a8bc7..bc1ddd6c 100644 --- a/modules/odm_25dmeshing/src/Odm25dMeshing.hpp +++ b/modules/odm_25dmeshing/src/Odm25dMeshing.hpp @@ -83,7 +83,7 @@ private: std::string outputFile = "odm_25dmesh.ply"; std::string logFilePath = "odm_25dmeshing_log.txt"; int maxVertexCount = 100000; - double resolution = 20.0; + double resolution = 0; unsigned int neighbors = 24; std::string outputDsmFile = ""; bool showDebugWindow = false; diff --git a/opendm/config.py b/opendm/config.py index 044d6bd2..846278a8 100644 --- a/opendm/config.py +++ b/opendm/config.py @@ -258,12 +258,13 @@ def config(): parser.add_argument('--mesh-resolution', metavar='', - default=10, + default=0, type=float, help=('Size of the interpolated surface model used for deriving the 2.5D mesh, expressed in pixels per meter. ' 'Higher values work better for complex or urban terrains. ' 'Lower values work better on flat areas. ' 'Resolution has no effect on the number of vertices, but high values can severely impact runtime speed and memory usage. ' + 'When set to zero, the program automatically attempts to find a good value based on the point cloud extent and target vertex count. ' 'Applies to 2.5D mesh only. ' 'Default: %(default)s'))