1

Do you know how to get the intersection (corresponding) volume/meshes of two polygon meshes consisting of the set of faces and vertices in Matlab?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Joon An
  • 11
  • 2
  • 2
    what did you already try? – m.s. Jul 30 '15 at 20:41
  • I have the two sets (polygon meshes) of faces and vertices. Each mesh (vertices & faces) has the intersection volume. Therefore, I would like to get the intersection volume of two meshes. – Joon An Jul 30 '15 at 20:56
  • how does your matlab code look like? what is your input data? – m.s. Jul 30 '15 at 20:57
  • I just have the data sets of vertices and faces. Input data seems that first one is (fv1.vertices & fv1.faces) and second one is (fv2.vertices & fv2.faces). – Joon An Jul 30 '15 at 21:02

1 Answers1

1

I am not aware of a builtin MATLAB method to do this. But via mex functions you can make use of ready-made C++ libraries.

The following example uses libigl's boolean mesh operation.

It has some dependencies, I installed them on Ubuntu Linux using:

$ sudo apt-get install libcgal-dev git mercurial
$ cd /opt/
$ hg clone https://bitbucket.org/eigen/eigen/
$ git clone https://github.com/libigl/libigl.git

get_intersection_mesh.cpp

#include "mex.h"

#include <Eigen/Core>
#include <igl/matlab/prepare_lhs.h>
#include <igl/matlab/parse_rhs.h>
#include <igl/boolean/mesh_boolean.h>

void mexFunction(
     int          nlhs,
     mxArray      *plhs[],
     int          nrhs,
     const mxArray *prhs[]
     )
{
  using namespace Eigen;
  if (nrhs != 4) 
  {
    mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin",
        "get_intersection_mesh requires 4 input parameters: F1, V1, F2, V2");
  }
  if (nlhs != 2) 
  {
    mexErrMsgIdAndTxt("MATLAB:mexcpp:nargout",
        "get_intersection_mesh requires 2 output parameters: F, V");
  }

  MatrixXd V1, V2, V_i;
  MatrixXi F1, F2, F_i;

  // read input meshes
  igl::matlab::parse_rhs_index(prhs+0, F1);
  igl::matlab::parse_rhs_double(prhs+1,V1);
  igl::matlab::parse_rhs_index(prhs+2, F2);
  igl::matlab::parse_rhs_double(prhs+3,V2);

  // calculate intersection
  igl::boolean::mesh_boolean(V1,F1,V2,F2,igl::boolean::MESH_BOOLEAN_TYPE_INTERSECT,V_i,F_i);

  // write output
  igl::matlab::prepare_lhs_index(F_i,plhs+1);
  igl::matlab::prepare_lhs_double(V_i,plhs);
}

You compile it in MATLAB using:

mex get_intersection_mesh.cpp -I/opt/libigl/include -I/opt/eigen -lboost_thread -lCGAL -lmpfr -lgmp -lboost_system

You would then use it like this:

[V_i, F_i] = get_intersection_mesh(fv1.faces, fv1.vertices, fv2.faces, fv2.vertices);

% plot intersection mesh
patch('Faces',F_i,'Vertices',V_i, 'FaceColor','w');
Community
  • 1
  • 1
m.s.
  • 16,063
  • 7
  • 53
  • 88
  • Thanks for your answer. My development environment is not same to yours now. Can I receive all compiled files to use the get_intersection_mesh() Matlab function? I just want to test this function with my data sets first. – Joon An Jul 31 '15 at 22:28
  • @JoonAn No you need to compile it yourself since the dependencies must be the same, the operating system must fit etc. – m.s. Aug 01 '15 at 06:32