如何使用libigl在薄表面上执行布尔运算

如何使用libigl在薄表面上执行布尔运算

本文介绍了如何使用libigl在薄表面上执行布尔运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究 libigl ,并试图抓住位于内部的表面部分另一个身体.但是,似乎libigl仅适用于封闭体:

I am currently working on libigl, and trying to grab the part of the a surface which locates inside another body. However, it seems than libigl only works with closed bodies:

这是适用于封闭物体的代码. VA VF 是三角形棱柱,而 VB FB 是四面体:

Here is the code which works for closed bodies. VA,VF is a triangular prism and VB, FB is a tetrahedron:

#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 中删除了一个曲面,例如以下所示:

However, if I deleted one of the surfaces from A or B, like below for example:

//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 将为空(我想获得开放的薄表面而不是封闭的实体).我认为我使用的是错误的功能.有人知道该怎么做吗?

The result mesh C will be empty (I want to get a open thin surface instead of a closed body). I think I am using the wrong function. Anyone knows how to do this?

推荐答案

您可能正在寻找 igl :: copyleft :: cgal :: trim_with_solid .假设您有一个任意的网格 A ,并且还有另一个封闭的网格(实际上是实体网格或 PWN 网格) B .输出将是与 A 相同表面的网格,但是添加了新的边,因此每个面都可以标记为 B 内部或 B外/上.使用输出列表 D 中的标记,然后提取由 B 修剪的 A 部分是很简单的.

You might be looking for igl::copyleft::cgal::trim_with_solid. This assumes you have an arbitrary mesh A and you have another closed mesh (actually a solid or PWN mesh) B. The output will be a mesh of the same surface as A but with new edges added so that every face can be either flagged as inside B or outside/on B. Using the flags in the output list D, it's then trivial to extract the portion of A "trimmed" by B.

igl::copyleft::cgal::trim_with_solid(VA,FA,VB,FB,V,F,D,J);

这篇关于如何使用libigl在薄表面上执行布尔运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:10