You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

94 lines
4.0 KiB

#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