我目前正在研究libigl,并试图抓住位于另一个体内的表面的一部分。然而,似乎 libigl 只适用于封闭的机构:
这是适用于封闭机构的代码。VA
,VF
是三棱柱,VB
,FB
是四面体:
#include <igl/readOFF.h>
//#define IGL_NO_CORK
//#undef IGL_STATIC_LIBRARY
#include <igl/copyleft/cgal/mesh_boolean.h>
#include <igl/viewer/Viewer.h>
#include <Eigen/Core>
#include <iostream>
Eigen::MatrixXd VA,VB,VC;
Eigen::VectorXi J,I;
Eigen::MatrixXi FA,FB,FC;
igl::MeshBooleanType boolean_type(
igl::MESH_BOOLEAN_TYPE_UNION);
const char * MESH_BOOLEAN_TYPE_NAMES[] =
{
"Union",
"Intersect",
"Minus",
"XOR",
"Resolve",
};
bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
{
switch(key)
{
default:
return false;
case 'A':
viewer.data.clear();
std::cout << "Loading A" << std::endl;
viewer.data.set_mesh(VA, FA);
break;
case 'B':
viewer.data.clear();
std::cout << "Loading B" << std::endl;
viewer.data.set_mesh(VB, FB);
break;
case 'C':
viewer.data.clear();
std::cout << "Loading C" << std::endl;
viewer.data.set_mesh(VC, FC);
return true;
}
return true;
}
int main(int argc, char *argv[])
{
using namespace Eigen;
using namespace std;
double prismSize = 150;
double Heigh = 300;
VA.resize(6, 3);
VA << -prismSize, prismSize, 0,
prismSize, prismSize, 0,
0, 2 * prismSize, 0,
-prismSize, prismSize, Heigh,
prismSize, prismSize, Heigh,
0, 2 * prismSize, Heigh;
FA.resize(8, 3);
FA << 1, 0, 2,
5, 3, 4,
4, 1, 2,
2, 5, 4,
3, 5, 2,
2, 0, 3,
0, 1, 4,
4, 3, 0;
double tetsize = 300;
VB.resize(4, 3);
VB << 0, 0, tetsize,
-tetsize, 0, 0,
tetsize, 0, 0,
0, tetsize*2, 0;
FB.resize(4, 3);
FB << 2, 1, 3,
2, 0, 1,
3, 0, 2,
1, 0, 3;
igl::copyleft::cgal::mesh_boolean(VA, FA, VB, FB, igl::MESH_BOOLEAN_TYPE_INTERSECT, VC, FC);
std::cout
<< "VA:" << std::endl << VA << std::endl << "==============" << std::endl
<< "FA:" << std::endl << FA << std::endl << "==============" << std::endl
<< "VB:" << std::endl << VB << std::endl << "==============" << std::endl
<< "FB:" << std::endl << FB << std::endl << "==============" << std::endl
<< "VC:" << std::endl << VC << std::endl << "==============" << std::endl
<< "FC:" << std::endl << FC << std::endl << "==============" << std::endl;
// Plot the mesh with pseudocolors
igl::viewer::Viewer viewer;
viewer.data.set_mesh(VA, FA);
//viewer.data.set_mesh(VB, FB);
//viewer.data.set_mesh(VC, FC);
viewer.core.show_lines = true;
viewer.callback_key_down = &key_down;
viewer.core.camera_dnear = 3.9;
cout<<
"Press '.' to switch to next boolean operation type."<<endl<<
"Press ',' to switch to previous boolean operation type."<<endl<<
"Press ']' to push near cutting plane away from camera."<<endl<<
"Press '[' to pull near cutting plane closer to camera."<<endl<<
"Hint: investigate _inside_ the model to see orientation changes."<<endl;
viewer.launch();
}
A
但是,如果我从或中删除了其中一个曲面B
,例如如下所示:
//FA.resize(8, 3);
FA.resize(7, 3);
//FA << 1, 0, 2,
FA << 5, 3, 4,
4, 1, 2,
2, 5, 4,
3, 5, 2,
2, 0, 3,
0, 1, 4,
4, 3, 0;
结果网格C
将是空的(我想要一个开放的薄表面而不是一个封闭的实体)。我想我使用了错误的功能。任何人都知道如何做到这一点?