首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数化尺度

参数化尺度
EN

Stack Overflow用户
提问于 2019-11-12 09:31:30
回答 1查看 108关注 0票数 1

我有下面的代码,与示例的匹配率为90%。我想通过参数化来“平平”3D模型。但投入和产出的规模并不相同。

我要问的问题是,我们如何才能保持规模不变。在下面的图像中,您可以找到输入和输出:

代码语言:javascript
复制
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Surface_mesh_parameterization/IO/File_off.h>
//#include <CGAL/Surface_mesh_parameterization/Circular_border_parameterizer_3.h>
//#include <CGAL/Surface_mesh_parameterization/Discrete_authalic_parameterizer_3.h>


//#include <CGAL/Surface_mesh_parameterization/Square_border_parameterizer_3.h>
//#include <CGAL/Surface_mesh_parameterization/Barycentric_mapping_parameterizer_3.h>

#include <CGAL/Surface_mesh_parameterization/Two_vertices_parameterizer_3.h>
#include <CGAL/Surface_mesh_parameterization/LSCM_parameterizer_3.h>

#include <CGAL/Surface_mesh_parameterization/Error_code.h>
#include <CGAL/Surface_mesh_parameterization/parameterize.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
typedef CGAL::Simple_cartesian<double>       Kernel;
typedef Kernel::Point_2                      Point_2;
typedef Kernel::Point_3                      Point_3;
typedef CGAL::Surface_mesh<Kernel::Point_3>  SurfaceMesh;
typedef boost::graph_traits<SurfaceMesh>::halfedge_descriptor  halfedge_descriptor;
typedef boost::graph_traits<SurfaceMesh>::vertex_descriptor    vertex_descriptor;
typedef boost::graph_traits<SurfaceMesh>::face_descriptor      face_descriptor;
namespace SMP = CGAL::Surface_mesh_parameterization;
int main(int argc, char** argv)
{
    std::ifstream in((argc > 1) ? argv[1] : "C:/Users/Niels/Desktop/CGAL/flatten.off");
    if (!in) {
        std::cerr << "Problem loading the input data" << std::endl;
        return EXIT_FAILURE;
    }
    SurfaceMesh sm;
    in >> sm;
    // A halfedge on the border
    halfedge_descriptor bhd = CGAL::Polygon_mesh_processing::longest_border(sm).first;
    // The 2D points of the uv parametrisation will be written into this map
    typedef SurfaceMesh::Property_map<vertex_descriptor, Point_2>  UV_pmap;
    UV_pmap uv_map = sm.add_property_map<vertex_descriptor, Point_2>("v:uv").first;

    typedef SMP::Two_vertices_parameterizer_3<SurfaceMesh> Border_parameterizer;
    typedef SMP::LSCM_parameterizer_3<SurfaceMesh, Border_parameterizer> Parameterizer;

    SMP::Error_code err = SMP::parameterize(sm, Parameterizer(), bhd, uv_map);
    if (err != SMP::OK) {
        std::cerr << "Error: " << SMP::get_error_message(err) << std::endl;
        return EXIT_FAILURE;
    }
    std::ofstream out("result.off");
    SMP::IO::output_uvmap_to_off(sm, bhd, uv_map, out);
    return EXIT_SUCCESS;
}

更新,但这是无限的:

代码语言:javascript
复制
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Surface_mesh_parameterization/IO/File_off.h>
//#include <CGAL/Surface_mesh_parameterization/Circular_border_parameterizer_3.h>
//#include <CGAL/Surface_mesh_parameterization/Discrete_authalic_parameterizer_3.h>


//#include <CGAL/Surface_mesh_parameterization/Square_border_parameterizer_3.h>
//#include <CGAL/Surface_mesh_parameterization/Barycentric_mapping_parameterizer_3.h>

#include <CGAL/Surface_mesh_parameterization/Two_vertices_parameterizer_3.h>
#include <CGAL/Surface_mesh_parameterization/LSCM_parameterizer_3.h>

#include <CGAL/Surface_mesh_parameterization/Error_code.h>
#include <CGAL/Surface_mesh_parameterization/parameterize.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
typedef CGAL::Simple_cartesian<double>       Kernel;
typedef Kernel::Point_2                      Point_2;
typedef Kernel::Point_3                      Point_3;
typedef CGAL::Surface_mesh<Kernel::Point_3>  SurfaceMesh;
typedef boost::graph_traits<SurfaceMesh>::halfedge_descriptor  halfedge_descriptor;
typedef boost::graph_traits<SurfaceMesh>::vertex_descriptor    vertex_descriptor;
typedef boost::graph_traits<SurfaceMesh>::face_descriptor      face_descriptor;
namespace SMP = CGAL::Surface_mesh_parameterization;

#include <CGAL/Surface_mesh_parameterization/ARAP_parameterizer_3.h>



int main(int argc, char** argv)
{
    std::ifstream in((argc > 1) ? argv[1] : "FlatteningObject.off");
    if (!in) {
        std::cerr << "Problem loading the input data" << std::endl;
        return EXIT_FAILURE;
    }
    SurfaceMesh sm;
    in >> sm;
    // A halfedge on the border
    halfedge_descriptor bhd = CGAL::Polygon_mesh_processing::longest_border(sm).first;
    // The 2D points of the uv parametrisation will be written into this map
    typedef SurfaceMesh::Property_map<vertex_descriptor, Point_2>  UV_pmap;
    UV_pmap uv_map = sm.add_property_map<vertex_descriptor, Point_2>("v:uv").first;

    typedef SMP::Two_vertices_parameterizer_3<SurfaceMesh> Border_parameterizer;
    typedef SMP::LSCM_parameterizer_3<SurfaceMesh, Border_parameterizer> Parameterizer;

    SMP::Error_code err = SMP::parameterize(
        sm, 
        SMP::ARAP_parameterizer_3<SurfaceMesh, Border_parameterizer>(
                    Border_parameterizer(),
                    CGAL::Eigen_solver_traits<Eigen::SparseLU<CGAL::Eigen_sparse_matrix<double>::EigenType> >(),
                    1000,
                    50
        ), 
        bhd, 
        uv_map);

    if (err != SMP::OK) {
        std::cerr << "Error: " << SMP::get_error_message(err) << std::endl;
        return EXIT_FAILURE;
    }
    std::ofstream out("result.off");
    SMP::IO::output_uvmap_to_off(sm, bhd, uv_map, out);
    return EXIT_SUCCESS;
}
EN

回答 1

Stack Overflow用户

发布于 2019-12-05 03:12:52

我在使用ARAP方法方面取得了一些成功。默认的50次迭代实际上是不够的,并且产生了一个交叉的网格。把迭代次数增加到500次是有效的。

代码语言:javascript
复制
SMP::Error_code err = SMP::parameterize(
            in, 
            SMP::ARAP_parameterizer_3<geometry::Mesh, Border_parameterizer>(
                Border_parameterizer(),
                CGAL::Eigen_solver_traits<Eigen::SparseLU<CGAL::Eigen_sparse_matrix<double>::EigenType> >(),
                1000,
                500), 
            bhd, 
            uv_map);

...Using提交bec70a6d52

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58815695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档