gpt4 book ai didi

c++ - 带颜色的 3d 网格上的 CGAL boolean 运算

转载 作者:行者123 更新时间:2023-11-28 04:48:50 26 4
gpt4 key购买 nike

我想做的是对每个顶点具有 RGB 颜色的 2 个模型执行 CGAL boolean 运算符( union 运算符)。但结果不保留颜色信息。也许您知道如何解决这个问题。

这里是做 boolean 运算的模型(coff 格式):

model1

model2

image of input models

这是我使用的代码:

#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 computed\n";
std::ofstream output("union.off");
output << out;
return 0;
}
std::cout << "Union could not be computed\n";
return 1;
}

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

union model as result

最佳答案

这还不可能。 corefine 中有一个隐藏参数来保留这些属性,但 boolean 运算的输出构建器缺少一位访问者(我希望有时间在 CGAL 4.13 中添加)。

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

编辑:在 CGAL 4.13 中,这可以通过将命名参数传递给访问者来实现。这PR是添加支持并且已经合并到 master 分支中的那个。以下example展示了如何做到这一点。

关于c++ - 带颜色的 3d 网格上的 CGAL boolean 运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48625808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com