Browse Source

docs:Enhance normalization process in Source.cpp for mesh vertices

- 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.
main
mckay 2 months ago
parent
commit
e4b6a7b47f
  1. 8
      code/pre_processing/FeatureSample/Source.cpp

8
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<TinyVector<double, 3>> 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")
{

Loading…
Cancel
Save