From e4b6a7b47fccc5c07636d515d1759e7a2fb8a792 Mon Sep 17 00:00:00 2001 From: mckay Date: Tue, 21 Jan 2025 21:16:41 +0800 Subject: [PATCH] =?UTF-8?q?docs=EF=BC=9AEnhance=20normalization=20process?= =?UTF-8?q?=20in=20Source.cpp=20for=20mesh=20vertices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added detailed comments to clarify the steps involved in the normalization of mesh vertices. - Implemented calculations for the bounding box size and center point of the model. - Updated the vertex normalization logic to center and scale vertices to the range of [-0.9, 0.9]. - Improved code readability and maintainability by providing clear explanations for each processing step. --- code/pre_processing/FeatureSample/Source.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/pre_processing/FeatureSample/Source.cpp b/code/pre_processing/FeatureSample/Source.cpp index 669e082..46691fb 100644 --- a/code/pre_processing/FeatureSample/Source.cpp +++ b/code/pre_processing/FeatureSample/Source.cpp @@ -168,26 +168,32 @@ int main(int argc, char** argv) if (processing_mode == 0) { + // 网络处理模式 //normalization part begin //[-0.9, 0.9]^3 std::vector> pts_nl(mesh.get_vertices_list()->size()); + + // 1. 计算模型的包围盒大小 double max_range = mesh.xmax - mesh.xmin; max_range = max_range < (mesh.ymax - mesh.ymin) ? (mesh.ymax - mesh.ymin) : max_range; max_range = max_range < (mesh.zmax - mesh.zmin) ? (mesh.zmax - mesh.zmin) : max_range; + // 2. 计算模型中心点 double xcenter = (mesh.xmin + mesh.xmax) / 2; double ycenter = (mesh.ymin + mesh.ymax) / 2; double zcenter = (mesh.zmin + mesh.zmax) / 2; std::cout << "center " << xcenter << " " << ycenter << " " << zcenter << std::endl; + // 3. 对每个顶点进行规范化 for (size_t i = 0; i < mesh.get_vertices_list()->size(); i++) { + // 将顶点移动到中心,然后缩放到[-0.9, 0.9]范围 mesh.get_vertices_list()->at(i)->pos[0] = (mesh.get_vertices_list()->at(i)->pos[0] - xcenter) / max_range * 1.8; mesh.get_vertices_list()->at(i)->pos[1] = (mesh.get_vertices_list()->at(i)->pos[1] - ycenter) / max_range * 1.8; mesh.get_vertices_list()->at(i)->pos[2] = (mesh.get_vertices_list()->at(i)->pos[2] - zcenter) / max_range * 1.8; } - //output mesh + // 4. 输出规范化后的网格 std::string outputext = GetFileExtension(outputfile); if (outputext == "obj") {