CGAL布尔以3D网格的颜色操作



我要做的是在2个具有RGB颜色的模型上执行CGAL Boolean Operator(Union Operator(。但是结果不能保留颜色信息。也许您有一个想法如何解决此问题。

这是进行布尔操作(COFF格式(的模型:

model1

model2

输入模型的图像

这是我正在使用的代码:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Mesh;
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char* argv[])
{
    const char* filename1 = (argc > 1) ? argv[1] : "data/b1.off";
    const char* filename2 = (argc > 2) ? argv[2] : "data/b2.off";
    std::ifstream input(filename1);
    Mesh mesh1, mesh2;
    if (!input || !(input >> mesh1))
    {
        std::cerr << "First mesh is not a valid off file." << std::endl;
        return 1;
    }
    input.close();
    input.open(filename2);
    if (!input || !(input >> mesh2))
    {
        std::cerr << "Second mesh is not a valid off file." << std::endl;
        return 1;
    }
    Mesh out;
    bool valid_union = PMP::corefine_and_compute_union(mesh1, mesh2, out);
    if (valid_union)
    {
        std::cout << "Union was successfully computedn";
        std::ofstream output("union.off");
        output << out;
        return 0;
    }
    std::cout << "Union could not be computedn";
    return 1;
}

我最终得到的是正确的网格,但没有保留颜色信息。是否有机会修复颜色信息?

联合模型作为结果

这是不可能的。corefine中有一个隐藏参数可以保留这些属性,但是布尔操作的输出构建器缺少访问者(我希望这是有时间添加CGAL 4.13(。

有一些解决方法,但没有一个会处理所有可能的情况。

编辑:在CGAL 4.13中,通过传递命名参数A访问者将有可能。该公关是添加支持的人,已经合并到主分支中。以下示例显示了如何做。

我发现CGAL库中有一个命令加载" Coff"格式 其中包含颜色RGB。但是我不知道如何使用它。我的第一次 尝试是定义数据类型的方法。

据我所知,只有Surface_mesh数据结构才能与Coff文件一起使用。您可以在polyhedron/demo/polyhedron中查看Surface_mesh_io_plugin的代码。Coff格式是一个标准的,已有足够的文献记录。

最新更新