Browse Source
- Introduced `FeatureSampleConfig` class to encapsulate configuration parameters for feature sampling from command line arguments. - Implemented methods for parsing and validating input parameters, ensuring required fields are provided. - Updated `Source.cpp` to utilize the new configuration class, streamlining command line argument handling and improving code readability. - Enhanced error handling for missing or invalid parameters, promoting robustness in the feature sampling process.main
3 changed files with 181 additions and 67 deletions
@ -0,0 +1,94 @@ |
|||
#include "FeatureSampleConfig.h" |
|||
#include <iostream> |
|||
|
|||
namespace MeshLib { |
|||
|
|||
FeatureSampleConfig FeatureSampleConfig::FromCommandLine(int argc, char** argv) { |
|||
cxxopts::Options options("FeatureSample", "Feature sampling for 3D meshes"); |
|||
|
|||
options.add_options() |
|||
("i,input", "input mesh (obj/off format)", cxxopts::value<std::string>()) |
|||
("f,feature", "input feature file (fea format)", cxxopts::value<std::string>()) |
|||
("p,pointcloud", "input pointcloud", cxxopts::value<std::string>()) |
|||
("pf", "face of input pointcloud", cxxopts::value<std::string>()) |
|||
("o,output", "output mesh/points", cxxopts::value<std::string>()) |
|||
("k,mask", "output mask file", cxxopts::value<std::string>()) |
|||
("fs", "feature samples", cxxopts::value<int>()) |
|||
("ns", "non-feature samples", cxxopts::value<int>()) |
|||
("m,mode", "processing mode", cxxopts::value<int>()) |
|||
("c,color", "use coloring", cxxopts::value<int>()) |
|||
("mp", "max patches per cluster", cxxopts::value<int>()) |
|||
("cot", "use cotangent weight", cxxopts::value<int>()) |
|||
("s,sigma", "position noise sigma", cxxopts::value<double>()) |
|||
("sn", "normal noise sigma", cxxopts::value<double>()) |
|||
("csg", "generate csg tree", cxxopts::value<int>()) |
|||
("convex", "is first layer convex", cxxopts::value<int>()) |
|||
("r,repairturn", "repair turn vertex", cxxopts::value<int>()) |
|||
("verbose", "verbose level", cxxopts::value<int>()) |
|||
("strict", "strict mode") |
|||
("repairtree", "repair tree feature") |
|||
("h,help", "print help"); |
|||
|
|||
auto result = options.parse(argc, argv); |
|||
|
|||
if (result.count("help")) { |
|||
std::cout << options.help() << std::endl; |
|||
exit(0); |
|||
} |
|||
|
|||
FeatureSampleConfig config; |
|||
|
|||
// 检查必需参数
|
|||
if (!result.count("m") || !result.count("i") || !result.count("o")) { |
|||
throw std::runtime_error("Missing required parameters"); |
|||
} |
|||
|
|||
// 设置文件路径
|
|||
config.files.input_mesh = result["i"].as<std::string>(); |
|||
config.files.output_file = result["o"].as<std::string>(); |
|||
if (result.count("f")) config.files.input_feature = result["f"].as<std::string>(); |
|||
if (result.count("p")) config.files.input_pointcloud = result["p"].as<std::string>(); |
|||
if (result.count("pf")) config.files.input_pointcloud_face = result["pf"].as<std::string>(); |
|||
if (result.count("k")) config.files.output_mask = result["k"].as<std::string>(); |
|||
|
|||
// 设置采样参数
|
|||
if (result.count("fs")) config.sampling.feature_samples = result["fs"].as<int>(); |
|||
if (result.count("ns")) config.sampling.nonfeature_samples = result["ns"].as<int>(); |
|||
if (result.count("s")) config.sampling.sigma = result["s"].as<double>(); |
|||
if (result.count("sn")) config.sampling.sigma_normal = result["sn"].as<double>(); |
|||
if (result.count("cot")) config.sampling.use_cotweight = result["cot"].as<int>(); |
|||
|
|||
// 设置处理选项
|
|||
config.processing.mode = result["m"].as<int>(); |
|||
if (result.count("c")) config.processing.use_color = result["c"].as<int>(); |
|||
if (result.count("mp")) config.processing.max_patches = result["mp"].as<int>(); |
|||
if (result.count("csg")) config.processing.generate_csg = result["csg"].as<int>(); |
|||
if (result.count("convex")) config.processing.is_convex = result["convex"].as<int>(); |
|||
if (result.count("r")) config.processing.repair_turn = result["r"].as<int>(); |
|||
if (result.count("verbose")) config.processing.verbose = result["verbose"].as<int>(); |
|||
if (result.count("strict")) config.processing.strict_mode = true; |
|||
if (result.count("repairtree")) config.processing.repair_tree = true; |
|||
|
|||
return config; |
|||
} |
|||
|
|||
bool FeatureSampleConfig::Validate() const { |
|||
// 检查文件路径
|
|||
if (files.input_mesh.empty() || files.output_file.empty()) { |
|||
return false; |
|||
} |
|||
|
|||
// 检查采样参数
|
|||
if (sampling.feature_samples < 0 || sampling.nonfeature_samples < 0) { |
|||
return false; |
|||
} |
|||
|
|||
// 检查处理模式
|
|||
if (processing.mode != 0 && processing.mode != 1) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
} // namespace MeshLib
|
@ -0,0 +1,48 @@ |
|||
#pragma once |
|||
#include <string> |
|||
#include "cxxopts.hpp" |
|||
|
|||
namespace MeshLib { |
|||
|
|||
class FeatureSampleConfig { |
|||
public: |
|||
// 文件路径
|
|||
struct FilePaths { |
|||
std::string input_mesh; // 输入网格文件
|
|||
std::string input_feature; // 输入特征文件
|
|||
std::string input_pointcloud; // 输入点云文件
|
|||
std::string input_pointcloud_face; // 输入点云面片文件
|
|||
std::string output_file; // 输出文件
|
|||
std::string output_mask; // 输出掩码文件
|
|||
} files; |
|||
|
|||
// 采样参数
|
|||
struct SamplingParams { |
|||
int feature_samples = 10000; // 特征边采样点数
|
|||
int nonfeature_samples = 40000; // 非特征面采样点数
|
|||
double sigma = 0.0; // 位置噪声标准差
|
|||
double sigma_normal = 0.0; // 法向噪声标准差
|
|||
bool use_cotweight = false; // 是否使用余切权重
|
|||
} sampling; |
|||
|
|||
// 处理选项
|
|||
struct ProcessingOptions { |
|||
int mode = 1; // 处理模式 (0:标准化, 1:特征采样)
|
|||
bool use_color = false; // 是否使用颜色
|
|||
int max_patches = -1; // 每个颜色簇的最大面片数
|
|||
bool generate_csg = false; // 是否生成CSG树
|
|||
bool is_convex = false; // 第一层是否为凸的
|
|||
bool repair_turn = true; // 是否修复转角顶点
|
|||
bool repair_tree = false; // 是否修复树特征
|
|||
bool strict_mode = false; // 是否使用严格模式
|
|||
int verbose = 0; // 详细输出级别
|
|||
} processing; |
|||
|
|||
// 从命令行参数解析配置
|
|||
static FeatureSampleConfig FromCommandLine(int argc, char** argv); |
|||
|
|||
// 验证配置是否有效
|
|||
bool Validate() const; |
|||
}; |
|||
|
|||
} // namespace MeshLib
|
Loading…
Reference in new issue