Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 尝试在MacOS上构建Pymesh时复制符号时发生ld错误_C++_Macos_Gcc - Fatal编程技术网

C++ 尝试在MacOS上构建Pymesh时复制符号时发生ld错误

C++ 尝试在MacOS上构建Pymesh时复制符号时发生ld错误,c++,macos,gcc,C++,Macos,Gcc,我一直在尝试用GCC 9.3.0在MacOS 10.15上构建Pymesh,在生成步骤中出现以下错误 Scanning dependencies of target lib_IGL [ 48%] Building CXX object tools/IGL/CMakeFiles/lib_IGL.dir/CellPartition.cpp.o [ 48%] Building CXX object tools/IGL/CMakeFiles/lib_IGL.dir/DiskCutter.cpp.o [

我一直在尝试用GCC 9.3.0在MacOS 10.15上构建Pymesh,在生成步骤中出现以下错误

Scanning dependencies of target lib_IGL
[ 48%] Building CXX object tools/IGL/CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
[ 48%] Building CXX object tools/IGL/CMakeFiles/lib_IGL.dir/DiskCutter.cpp.o
[ 48%] Building CXX object tools/IGL/CMakeFiles/lib_IGL.dir/HarmonicSolver.cpp.o
[ 49%] Building CXX object tools/IGL/CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
[ 49%] Linking CXX shared library ../../../python/pymesh/lib/libPyMesh-IGL.dylib
duplicate symbol 'typeinfo name for CORE::Realbase_for' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::Realbase_for' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::Realbase_for' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::Realbase_for' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::Realbase_forCORE::BigInt' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::Realbase_forCORE::BigInt' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::ConstPolyRepCORE::BigInt' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::ConstPolyRepCORE::BigInt' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::Realbase_forCORE::BigFloat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::Realbase_forCORE::BigFloat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::ConstPolyRepCORE::BigFloat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::ConstPolyRepCORE::BigFloat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::Realbase_forCORE::BigRat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::Realbase_forCORE::BigRat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::ConstPolyRepCORE::BigRat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::ConstPolyRepCORE::BigRat' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::ConstPolyRepCORE::Expr' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::ConstPolyRepCORE::Expr' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::AddSubRepCORE::Add' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::AddSubRepCORE::Add' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo name for CORE::AddSubRepCORE::Sub' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
duplicate symbol 'typeinfo for CORE::AddSubRepCORE::Sub' in:
CMakeFiles/lib_IGL.dir/CellPartition.cpp.o
CMakeFiles/lib_IGL.dir/MinkowskiSum.cpp.o
ld: 22 duplicate symbols for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [../python/pymesh/lib/libPyMesh-IGL.dylib] Error 1
make[1]: *** [tools/IGL/CMakeFiles/lib_IGL.dir/all] Error 2
make: *** [all] Error 2
所以我去查了一下档案,看看出了什么问题

MinkowskiSum.cpp

#ifdef WITH_IGL_AND_CGAL
#include "MinkowskiSum.h"
#include <Math/MatrixUtils.h>
#include <igl/copyleft/cgal/minkowski_sum.h>
#include <igl/copyleft/cgal/mesh_boolean.h>
#include <igl/MeshBooleanType.h>

#include <vector>

using namespace PyMesh;

MinkowskiSum::Ptr MinkowskiSum::create(const Mesh::Ptr& mesh) {
    const MatrixFr vertices = MatrixUtils::reshape<MatrixFr>(
            mesh->get_vertices(), mesh->get_num_vertices(), mesh->get_dim());
    const MatrixIr faces = MatrixUtils::reshape<MatrixIr>(
            mesh->get_faces(), mesh->get_num_faces(),
            mesh->get_vertex_per_face());
    return MinkowskiSum::Ptr(new MinkowskiSum(vertices, faces));
}

MinkowskiSum::Ptr MinkowskiSum::create_raw(
        const MatrixFr& vertices, const MatrixIr& faces) {
    return MinkowskiSum::Ptr(new MinkowskiSum(vertices, faces));
}

void MinkowskiSum::run(const MatrixFr& path) {
    const size_t num_pts = path.rows();
    if (num_pts <= 1) {
        m_out_vertices = m_vertices;
        m_out_faces = m_faces;
        return;
    }

    std::vector<MatrixFr> vertices;
    std::vector<MatrixIr> faces;

    for (size_t i=1; i<num_pts; i++) {
        const Eigen::Matrix<Float, 1, 3> s = path.row(i-1);
        const Eigen::Matrix<Float, 1, 3> d = path.row(i);
        MatrixFr V;
        MatrixIr F;
        VectorI J;

        igl::copyleft::cgal::minkowski_sum<
            MatrixFr, MatrixIr,
            Float, 3, 1,
            Float, 3, 1,
            MatrixFr, MatrixIr, VectorI>(m_vertices, m_faces, s, d, V, F, J);
        vertices.emplace_back(V);
        faces.emplace_back(F);
    }

    size_t v_count = 0;
    for (size_t i=0; i<num_pts-1; i++) {
        faces[i].array() += v_count;
        v_count += vertices[i].rows();
    }

    MatrixFr combined_vertices = MatrixUtils::vstack(vertices);
    MatrixIr combined_faces = MatrixUtils::vstack(faces);

    // Self union to remove self-intersections.
    MatrixFr empty_vertices;
    MatrixIr empty_faces;
    VectorI J;

    igl::copyleft::cgal::mesh_boolean(
            combined_vertices, combined_faces,
            empty_vertices, empty_faces,
            igl::MESH_BOOLEAN_TYPE_UNION,
            m_out_vertices, m_out_faces, J);
}

#endif
#带IGL和CGAL的ifdef
#包括“MinkowskiSum.h”
#包括
#包括
#包括
#包括
#包括
使用名称空间PyMesh;
MinkowskiSum::Ptr MinkowskiSum::create(const Mesh::Ptr&Mesh){
常量MatrixFr顶点=MatrixUtils::重塑(
网格->获取顶点(),网格->获取顶点数量(),网格->获取顶点尺寸();
常量MatrixIr faces=MatrixUtils::重塑(
网格->获取面(),网格->获取面数(),
网格->获取每个面的顶点();
返回MinkowskiSum::Ptr(新的MinkowskiSum(顶点、面));
}
MinkowskiSum::Ptr MinkowskiSum::创建_原始(
常数矩阵(顶点、常数矩阵和面){
返回MinkowskiSum::Ptr(新的MinkowskiSum(顶点、面));
}
void MinkowskiSum::run(常量矩阵和路径){
const size_t num_pts=path.rows();
如果(数量)
IGL_内联无效minkowski_和(
常数本征::矩阵基和VA,
常数本征::矩阵基和FA,
常数特征::矩阵与s,
常数特征::矩阵与d,
Eigen::PlainObjectBase&W,
Eigen::PlainObjectBase&G,
Eigen::PlainObjectBase&J);
}
}
}
#ifndef IGL_静态_库
#包括“minkowski_sum.cpp”
#恩迪夫
#恩迪夫
mesh_boolean.h

#ifndef IGL_COPYLEFT_CGAL_MESH_BOOLEAN_H
#define IGL_COPYLEFT_CGAL_MESH_BOOLEAN_H

#include "../../igl_inline.h"
#include "../../MeshBooleanType.h"
#include <Eigen/Core>
#include <functional>
#include <vector>

namespace igl
{
  namespace copyleft
  {
    namespace cgal
    {
      //  MESH_BOOLEAN Compute boolean csg operations on "solid", consistently
      //  oriented meshes.
      //
      //  Inputs:
      //    VA  #VA by 3 list of vertex positions of first mesh
      //    FA  #FA by 3 list of triangle indices into VA
      //    VB  #VB by 3 list of vertex positions of second mesh
      //    FB  #FB by 3 list of triangle indices into VB
      //    type  type of boolean operation
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of indices into [FA;FA.rows()+FB] revealing "birth" facet
      //  Returns true if inputs induce a piecewise constant winding number
      //  field and type is valid
      //
      //  See also: mesh_boolean_cork, intersect_other,
      //  remesh_self_intersections
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
        const Eigen::MatrixBase<DerivedVA > & VA,
        const Eigen::MatrixBase<DerivedFA > & FA,
        const Eigen::MatrixBase<DerivedVB > & VB,
        const Eigen::MatrixBase<DerivedFB > & FB,
        const MeshBooleanType & type,
        Eigen::PlainObjectBase<DerivedVC > & VC,
        Eigen::PlainObjectBase<DerivedFC > & FC,
        Eigen::PlainObjectBase<DerivedJ > & J);
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
        const Eigen::MatrixBase<DerivedVA > & VA,
        const Eigen::MatrixBase<DerivedFA > & FA,
        const Eigen::MatrixBase<DerivedVB > & VB,
        const Eigen::MatrixBase<DerivedFB > & FB,
        const std::string & type_str,
        Eigen::PlainObjectBase<DerivedVC > & VC,
        Eigen::PlainObjectBase<DerivedFC > & FC,
        Eigen::PlainObjectBase<DerivedJ > & J);
      //
      //  Inputs:
      //    VA  #VA by 3 list of vertex positions of first mesh
      //    FA  #FA by 3 list of triangle indices into VA
      //    VB  #VB by 3 list of vertex positions of second mesh
      //    FB  #FB by 3 list of triangle indices into VB
      //    wind_num_op  function handle for filtering winding numbers from
      //      tuples of integer values to [0,1] outside/inside values
      //    keep  function handle for determining if a patch should be "kept"
      //      in the output based on the winding number on either side
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of indices into [FA;FB] revealing "birth" facet
      //  Returns true iff inputs induce a piecewise constant winding number
      //    field
      //
      //  See also: mesh_boolean_cork, intersect_other,
      //  remesh_self_intersections
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const Eigen::MatrixBase<DerivedVA> & VA,
          const Eigen::MatrixBase<DerivedFA> & FA,
          const Eigen::MatrixBase<DerivedVB> & VB,
          const Eigen::MatrixBase<DerivedFB> & FB,
          const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
          const std::function<int(const int, const int)> & keep,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      //  MESH_BOOLEAN Variadic boolean operations
      //
      //  Inputs:
      //    Vlist  k-long list of lists of mesh vertex positions
      //    Flist  k-long list of lists of mesh face indices, so that Flist[i] indexes
      //      vertices in Vlist[i]
      //    wind_num_op  function handle for filtering winding numbers from
      //      n-tuples of integer values to [0,1] outside/inside values
      //    keep  function handle for determining if a patch should be "kept"
      //      in the output based on the winding number on either side
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of indices into [Flist[0];Flist[1];...;Flist[k]]
      //      revealing "birth" facet
      //  Returns true iff inputs induce a piecewise constant winding number
      //    field
      //
      //  See also: mesh_boolean_cork, intersect_other,
      //  remesh_self_intersections
      template <
        typename DerivedV,
        typename DerivedF,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const std::vector<DerivedV > & Vlist,
          const std::vector<DerivedF > & Flist,
          const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
          const std::function<int(const int, const int)> & keep,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      template <
        typename DerivedV,
        typename DerivedF,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const std::vector<DerivedV > & Vlist,
          const std::vector<DerivedF > & Flist,
          const MeshBooleanType & type,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      // Given a merged mesh (V,F) and list of sizes of inputs
      //
      // Inputs:
      //   V  #V by 3 list of merged mesh vertex positions
      //   F  #F by 3 list of merged mesh face indices so that first sizes(0)
      //     faces come from the first input, and the next sizes(1) faces come
      //     from the second input, and so on.
      //   sizes  #inputs list of sizes so that sizes(i) is the #faces in the
      //     ith input
      //    wind_num_op  function handle for filtering winding numbers from
      //      tuples of integer values to [0,1] outside/inside values
      //    keep  function handle for determining if a patch should be "kept"
      //      in the output based on the winding number on either side
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of birth parent indices
      // 
      template <
        typename DerivedVV,
        typename DerivedFF,
        typename Derivedsizes,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const Eigen::MatrixBase<DerivedVV > & VV,
          const Eigen::MatrixBase<DerivedFF > & FF,
          const Eigen::MatrixBase<Derivedsizes> & sizes,
          const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
          const std::function<int(const int, const int)> & keep,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      //  Inputs:
      //    VA  #VA by 3 list of vertex positions of first mesh
      //    FA  #FA by 3 list of triangle indices into VA
      //    VB  #VB by 3 list of vertex positions of second mesh
      //    FB  #FB by 3 list of triangle indices into VB
      //    type  type of boolean operation
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //  Returns true ff inputs induce a piecewise constant winding number
      //    field and type is valid
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC>
      IGL_INLINE bool mesh_boolean(
          const Eigen::MatrixBase<DerivedVA > & VA,
          const Eigen::MatrixBase<DerivedFA > & FA,
          const Eigen::MatrixBase<DerivedVB > & VB,
          const Eigen::MatrixBase<DerivedFB > & FB,
          const MeshBooleanType & type,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC);
    }
  }
}

#ifndef IGL_STATIC_LIBRARY
#  include "mesh_boolean.cpp"
#endif

#endif
\ifndef IGL\u COPYLEFT\u CGAL\u MESH\u BOOLEAN\u H
#定义IGL\u COPYLEFT\u CGAL\u MESH\u BOOLEAN\u H
#包括“../../igl_inline.h”
#包括“../../MeshBooleanType.h”
#包括
#包括
#包括
名称空间igl
{
命名空间copyleft
{
名称空间cgal
{
//网格布尔计算“实体”上的布尔csg运算,一致
//定向网格。
//
//投入:
//VA#VA乘以3第一个网格的顶点位置列表
//FA#FA由3个三角形索引列表转换为VA
//VB#VB乘以3第二个网格的顶点位置列表
//FB#FB由3个三角形索引列表转换为VB
//布尔运算类型
//产出:
//VC#VC乘以3布尔结果网格的顶点位置列表
//FC#FC由3个三角形索引列表转换为VC
//J#FC索引到[FA;FA.rows()+FB]的列表,显示“出生”方面
//如果输入导致分段恒定绕组数,则返回true
//字段和类型无效
//
//另请参见:网格\u布尔\u软木、相交\u其他、,
//重新设置自相交点
模板<
类型名DerivedVA,
typename-DerivedFA,
typename-DerivedVB,
typename派生fb,
typename-DerivedVC,
typename-DerivedFC,
typename DerivedJ>
IGL_内联布尔网格布尔(
常数本征::矩阵基和VA,
常数本征::矩阵基和FA,
常数本征::矩阵基和VB,
常数本征::矩阵基和FB,
常量网格布尔类型和类型,
Eigen::PlainObjectBase和VC,
Eigen::PlainObjectBase和FC,
Eigen::PlainObjectBase&J);
模板<
类型名DerivedVA,
typename-DerivedFA,
typename-DerivedVB,
typename派生fb,
typename-DerivedVC,
typename-DerivedFC,
typename DerivedJ>
IGL_内联布尔网格布尔(
常数本征::矩阵基和VA,
常数本征::矩阵基和FA,
常数本征::矩阵基和VB,
常数本征::矩阵基和FB,
常量标准::字符串和类型\u str,
Eigen::PlainObjectBase和VC,
Eigen::PlainObjectBase和FC,
Eigen::PlainObjectBase&J);
//
//投入:
//VA#VA乘以3第一个网格的顶点位置列表
//FA#FA由3个三角形索引列表转换为VA
//VB#VB乘以3第二个网格的顶点位置列表
//FB#FB由3个三角形索引列表转换为VB
//wind_num_op功能手柄,用于从
//整数值到[0,1]外部/内部值的元组
//keep函数句柄,用于确定是否应“保留”修补程序
//根据任意一侧的绕组编号输入输出
//产出:
//VC#VC乘以3布尔结果网格的顶点位置列表
//FC#FC由3个三角形索引列表转换为VC
//J#FC指数列表进入[FA;FB]揭示“出生”方面
//返回一个分段常数绕组数的真iff输入
//场
//
//另请参见:网格\u布尔\u软木、相交\u其他、,
//重新设置自相交点
模板<
类型名DerivedVA,
typename-DerivedFA,
typename-DerivedVB,
typename派生fb,
typename-DerivedVC,
typename-DerivedFC,
typename DerivedJ>
IGL_内联布尔网格布尔(
常数本征::矩阵基和VA,
常数本征::矩阵基和FA,
常数本征::矩阵基和VB,
常数本征::矩阵基和FB,
常数标准::功能和风量,
const std::函数和保持,
Eigen::PlainObjectBase和VC,
Eigen::PlainObjectBase和FC,
Eigen::PlainObjectBase&J);
//网格布尔变量布尔运算
//
//投入:
//Vlist网格顶点位置列表的k长列表
//Flist k-网格面索引列表的长列表,因此Flist[i]索引
//Vlist中的顶点[i]
//wind_num_op功能手柄,用于从
//整数值到[0,1]外部/内部值的n元组
//keep函数句柄,用于确定是否应“保留”修补程序
//根据任意一侧的绕组编号输入输出
//产出:
//VC#VC乘以3布尔结果网格的顶点位置列表
//FC#FC由3个三角形索引列表转换为VC
//
#ifndef IGL_COPYLEFT_CGAL_MINKOWSKI_SUM_H
#define IGL_COPYLEFT_CGAL_MINKOWSKI_SUM_H

#include "../../igl_inline.h"
#include <Eigen/Core>

namespace igl
{
  namespace copyleft
  {
    namespace cgal
    {
      // Compute the Minkowski sum of a closed triangle mesh (V,F) and a
      // set of simplices in 3D.
      //
      // Inputs:
      //   VA  #VA by 3 list of mesh vertices in 3D
      //   FA  #FA by 3 list of triangle indices into VA
      //   VB  #VB by 3 list of mesh vertices in 3D
      //   FB  #FB by ss list of simplex indices into VB, ss<=3
      //   resolve_overlaps  whether or not to resolve self-union. If false
      //     then result may contain self-intersections if input mesh is
      //     non-convex.
      // Outputs:
      //   W  #W by 3 list of mesh vertices in 3D
      //   G  #G by 3 list of triangle indices into W
      //   J  #G by 2 list of indices into 
      //   
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedW,
        typename DerivedG,
        typename DerivedJ>
      IGL_INLINE void minkowski_sum(
        const Eigen::MatrixBase<DerivedVA> & VA,
        const Eigen::MatrixBase<DerivedFA> & FA,
        const Eigen::MatrixBase<DerivedVB> & VB,
        const Eigen::MatrixBase<DerivedFB> & FB,
        const bool resolve_overlaps,
        Eigen::PlainObjectBase<DerivedW> & W,
        Eigen::PlainObjectBase<DerivedG> & G,
        Eigen::PlainObjectBase<DerivedJ> & J);
      // Compute the Minkowski sum of a closed triangle mesh (V,F) and a
      // segment [s,d] in 3D.
      //
      // Inputs:
      //   VA  #VA by 3 list of mesh vertices in 3D
      //   FA  #FA by 3 list of triangle indices into VA
      //   s  segment source endpoint in 3D
      //   d  segment source endpoint in 3D
      //   resolve_overlaps  whether or not to resolve self-union. If false
      //     then result may contain self-intersections if input mesh is
      //     non-convex.
      // Outputs:
      //   W  #W by 3 list of mesh vertices in 3D
      //   G  #G by 3 list of triangle indices into W
      //   J  #G list of indices into [F;#V+F;[s d]] of birth parents
      //
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename sType, int sCols, int sOptions,
        typename dType, int dCols, int dOptions,
        typename DerivedW,
        typename DerivedG,
        typename DerivedJ>
      IGL_INLINE void minkowski_sum(
        const Eigen::MatrixBase<DerivedVA> & VA,
        const Eigen::MatrixBase<DerivedFA> & FA,
        const Eigen::Matrix<sType,1,sCols,sOptions> & s,
        const Eigen::Matrix<dType,1,dCols,dOptions> & d,
        const bool resolve_overlaps,
        Eigen::PlainObjectBase<DerivedW> & W,
        Eigen::PlainObjectBase<DerivedG> & G,
        Eigen::PlainObjectBase<DerivedJ> & J);
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename sType, int sCols, int sOptions,
        typename dType, int dCols, int dOptions,
        typename DerivedW,
        typename DerivedG,
        typename DerivedJ>
      IGL_INLINE void minkowski_sum(
        const Eigen::MatrixBase<DerivedVA> & VA,
        const Eigen::MatrixBase<DerivedFA> & FA,
        const Eigen::Matrix<sType,1,sCols,sOptions> & s,
        const Eigen::Matrix<dType,1,dCols,dOptions> & d,
        Eigen::PlainObjectBase<DerivedW> & W,
        Eigen::PlainObjectBase<DerivedG> & G,
        Eigen::PlainObjectBase<DerivedJ> & J);
    }
  }
}

#ifndef IGL_STATIC_LIBRARY
#  include "minkowski_sum.cpp"
#endif

#endif
#ifndef IGL_COPYLEFT_CGAL_MESH_BOOLEAN_H
#define IGL_COPYLEFT_CGAL_MESH_BOOLEAN_H

#include "../../igl_inline.h"
#include "../../MeshBooleanType.h"
#include <Eigen/Core>
#include <functional>
#include <vector>

namespace igl
{
  namespace copyleft
  {
    namespace cgal
    {
      //  MESH_BOOLEAN Compute boolean csg operations on "solid", consistently
      //  oriented meshes.
      //
      //  Inputs:
      //    VA  #VA by 3 list of vertex positions of first mesh
      //    FA  #FA by 3 list of triangle indices into VA
      //    VB  #VB by 3 list of vertex positions of second mesh
      //    FB  #FB by 3 list of triangle indices into VB
      //    type  type of boolean operation
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of indices into [FA;FA.rows()+FB] revealing "birth" facet
      //  Returns true if inputs induce a piecewise constant winding number
      //  field and type is valid
      //
      //  See also: mesh_boolean_cork, intersect_other,
      //  remesh_self_intersections
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
        const Eigen::MatrixBase<DerivedVA > & VA,
        const Eigen::MatrixBase<DerivedFA > & FA,
        const Eigen::MatrixBase<DerivedVB > & VB,
        const Eigen::MatrixBase<DerivedFB > & FB,
        const MeshBooleanType & type,
        Eigen::PlainObjectBase<DerivedVC > & VC,
        Eigen::PlainObjectBase<DerivedFC > & FC,
        Eigen::PlainObjectBase<DerivedJ > & J);
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
        const Eigen::MatrixBase<DerivedVA > & VA,
        const Eigen::MatrixBase<DerivedFA > & FA,
        const Eigen::MatrixBase<DerivedVB > & VB,
        const Eigen::MatrixBase<DerivedFB > & FB,
        const std::string & type_str,
        Eigen::PlainObjectBase<DerivedVC > & VC,
        Eigen::PlainObjectBase<DerivedFC > & FC,
        Eigen::PlainObjectBase<DerivedJ > & J);
      //
      //  Inputs:
      //    VA  #VA by 3 list of vertex positions of first mesh
      //    FA  #FA by 3 list of triangle indices into VA
      //    VB  #VB by 3 list of vertex positions of second mesh
      //    FB  #FB by 3 list of triangle indices into VB
      //    wind_num_op  function handle for filtering winding numbers from
      //      tuples of integer values to [0,1] outside/inside values
      //    keep  function handle for determining if a patch should be "kept"
      //      in the output based on the winding number on either side
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of indices into [FA;FB] revealing "birth" facet
      //  Returns true iff inputs induce a piecewise constant winding number
      //    field
      //
      //  See also: mesh_boolean_cork, intersect_other,
      //  remesh_self_intersections
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const Eigen::MatrixBase<DerivedVA> & VA,
          const Eigen::MatrixBase<DerivedFA> & FA,
          const Eigen::MatrixBase<DerivedVB> & VB,
          const Eigen::MatrixBase<DerivedFB> & FB,
          const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
          const std::function<int(const int, const int)> & keep,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      //  MESH_BOOLEAN Variadic boolean operations
      //
      //  Inputs:
      //    Vlist  k-long list of lists of mesh vertex positions
      //    Flist  k-long list of lists of mesh face indices, so that Flist[i] indexes
      //      vertices in Vlist[i]
      //    wind_num_op  function handle for filtering winding numbers from
      //      n-tuples of integer values to [0,1] outside/inside values
      //    keep  function handle for determining if a patch should be "kept"
      //      in the output based on the winding number on either side
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of indices into [Flist[0];Flist[1];...;Flist[k]]
      //      revealing "birth" facet
      //  Returns true iff inputs induce a piecewise constant winding number
      //    field
      //
      //  See also: mesh_boolean_cork, intersect_other,
      //  remesh_self_intersections
      template <
        typename DerivedV,
        typename DerivedF,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const std::vector<DerivedV > & Vlist,
          const std::vector<DerivedF > & Flist,
          const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
          const std::function<int(const int, const int)> & keep,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      template <
        typename DerivedV,
        typename DerivedF,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const std::vector<DerivedV > & Vlist,
          const std::vector<DerivedF > & Flist,
          const MeshBooleanType & type,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      // Given a merged mesh (V,F) and list of sizes of inputs
      //
      // Inputs:
      //   V  #V by 3 list of merged mesh vertex positions
      //   F  #F by 3 list of merged mesh face indices so that first sizes(0)
      //     faces come from the first input, and the next sizes(1) faces come
      //     from the second input, and so on.
      //   sizes  #inputs list of sizes so that sizes(i) is the #faces in the
      //     ith input
      //    wind_num_op  function handle for filtering winding numbers from
      //      tuples of integer values to [0,1] outside/inside values
      //    keep  function handle for determining if a patch should be "kept"
      //      in the output based on the winding number on either side
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //    J  #FC list of birth parent indices
      // 
      template <
        typename DerivedVV,
        typename DerivedFF,
        typename Derivedsizes,
        typename DerivedVC,
        typename DerivedFC,
        typename DerivedJ>
      IGL_INLINE bool mesh_boolean(
          const Eigen::MatrixBase<DerivedVV > & VV,
          const Eigen::MatrixBase<DerivedFF > & FF,
          const Eigen::MatrixBase<Derivedsizes> & sizes,
          const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
          const std::function<int(const int, const int)> & keep,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC,
          Eigen::PlainObjectBase<DerivedJ > & J);
      //  Inputs:
      //    VA  #VA by 3 list of vertex positions of first mesh
      //    FA  #FA by 3 list of triangle indices into VA
      //    VB  #VB by 3 list of vertex positions of second mesh
      //    FB  #FB by 3 list of triangle indices into VB
      //    type  type of boolean operation
      //  Outputs:
      //    VC  #VC by 3 list of vertex positions of boolean result mesh
      //    FC  #FC by 3 list of triangle indices into VC
      //  Returns true ff inputs induce a piecewise constant winding number
      //    field and type is valid
      template <
        typename DerivedVA,
        typename DerivedFA,
        typename DerivedVB,
        typename DerivedFB,
        typename DerivedVC,
        typename DerivedFC>
      IGL_INLINE bool mesh_boolean(
          const Eigen::MatrixBase<DerivedVA > & VA,
          const Eigen::MatrixBase<DerivedFA > & FA,
          const Eigen::MatrixBase<DerivedVB > & VB,
          const Eigen::MatrixBase<DerivedFB > & FB,
          const MeshBooleanType & type,
          Eigen::PlainObjectBase<DerivedVC > & VC,
          Eigen::PlainObjectBase<DerivedFC > & FC);
    }
  }
}

#ifndef IGL_STATIC_LIBRARY
#  include "mesh_boolean.cpp"
#endif

#endif
#include "minkowski_sum.h"
#include "mesh_boolean.h"

#include "../../slice.h"
#include "../../slice_mask.h"
#include "../../LinSpaced.h"
#include "../../unique_rows.h"
#include "../../get_seconds.h"
#include "../../edges.h"
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <cassert>
#include <vector>
#include <iostream>


template <
  typename DerivedVA,
  typename DerivedFA,
  typename DerivedVB,
  typename DerivedFB,
  typename DerivedW,
  typename DerivedG,
  typename DerivedJ>
IGL_INLINE void igl::copyleft::cgal::minkowski_sum(
  const Eigen::MatrixBase<DerivedVA> & VA,
  const Eigen::MatrixBase<DerivedFA> & FA,
  const Eigen::MatrixBase<DerivedVB> & VB,
  const Eigen::MatrixBase<DerivedFB> & FB,
  const bool resolve_overlaps,
  Eigen::PlainObjectBase<DerivedW> & W,
  Eigen::PlainObjectBase<DerivedG> & G,
  Eigen::PlainObjectBase<DerivedJ> & J)
{
  using namespace std;
  using namespace Eigen;
  assert(FA.cols() == 3 && "FA must contain a closed triangle mesh");
  assert(FB.cols() <= FA.cols() && 
    "FB must contain lower diemnsional simplices than FA");
  const auto tictoc = []()->double
  {
    static double t_start;
    double now = igl::get_seconds();
    double interval = now-t_start;
    t_start = now;
    return interval;
  };
  tictoc();
  Matrix<typename DerivedFB::Scalar,Dynamic,2> EB;
  edges(FB,EB);
  Matrix<typename DerivedFA::Scalar,Dynamic,2> EA(0,2);
  if(FB.cols() == 3)
  {
    edges(FA,EA);
  }
  // number of copies of A along edges of B
  const int n_ab = EB.rows();
  // number of copies of B along edges of A
  const int n_ba = EA.rows();

  vector<DerivedW> vW(n_ab + n_ba);
  vector<DerivedG> vG(n_ab + n_ba);
  vector<DerivedJ> vJ(n_ab + n_ba);
  vector<int> offsets(n_ab + n_ba + 1);
  offsets[0] = 0;
  // sweep A along edges of B
  for(int e = 0;e<n_ab;e++)
  {
    Matrix<typename DerivedJ::Scalar,Dynamic,1> eJ;
    minkowski_sum(
      VA,
      FA,
      VB.row(EB(e,0)).eval(),
      VB.row(EB(e,1)).eval(),
      false,
      vW[e],
      vG[e],
      eJ);
    assert(vG[e].rows() == eJ.rows());
    assert(eJ.cols() == 1);
    vJ[e].resize(vG[e].rows(),2);
    vJ[e].col(0) = eJ;
    vJ[e].col(1).setConstant(e);
    offsets[e+1] = offsets[e] + vW[e].rows();
  }
  // sweep B along edges of A
  for(int e = 0;e<n_ba;e++)
  {
    Matrix<typename DerivedJ::Scalar,Dynamic,1> eJ;
    const int ee = n_ab+e;
    minkowski_sum(
      VB,
      FB,
      VA.row(EA(e,0)).eval(),
      VA.row(EA(e,1)).eval(),
      false,
      vW[ee],
      vG[ee],
      eJ);
    vJ[ee].resize(vG[ee].rows(),2);
    vJ[ee].col(0) = eJ.array() + (FA.rows()+1);
    vJ[ee].col(1).setConstant(ee);
    offsets[ee+1] = offsets[ee] + vW[ee].rows();
  }
  // Combine meshes
  int n=0,m=0;
  for_each(vW.begin(),vW.end(),[&n](const DerivedW & w){n+=w.rows();});
  for_each(vG.begin(),vG.end(),[&m](const DerivedG & g){m+=g.rows();});
  assert(n == offsets.back());

  W.resize(n,3);
  G.resize(m,3);
  J.resize(m,2);
  {
    int m_off = 0,n_off = 0;
    for(int i = 0;i<vG.size();i++)
    {
      W.block(n_off,0,vW[i].rows(),3) = vW[i];
      G.block(m_off,0,vG[i].rows(),3) = vG[i].array()+offsets[i];
      J.block(m_off,0,vJ[i].rows(),2) = vJ[i];
      n_off += vW[i].rows();
      m_off += vG[i].rows();
    }
    assert(n == n_off);
    assert(m == m_off);
  }
  if(resolve_overlaps)
  {
    Eigen::Matrix<typename DerivedJ::Scalar, Eigen::Dynamic,1> SJ;
    mesh_boolean(
      DerivedW(W),
      DerivedG(G),
      Matrix<typename DerivedW::Scalar,Dynamic,Dynamic>(),
      Matrix<typename DerivedG::Scalar,Dynamic,Dynamic>(),
      MESH_BOOLEAN_TYPE_UNION,
      W,
      G,
      SJ);
    slice(DerivedJ(J),SJ,1,J);
  }
}

#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
// generated by autoexplicit.sh
template void igl::copyleft::cgal::minkowski_sum<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, CGAL::Lazy_exact_nt<CGAL::Gmpq>, 3, 1, CGAL::Lazy_exact_nt<CGAL::Gmpq>, 3, 1, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 3, 1, 1, 3> const&, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 3, 1, 1, 3> const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
// generated by autoexplicit.sh
template void igl::copyleft::cgal::minkowski_sum<
  Eigen::Matrix<float, -1, 3, 1, -1, 3>, 
  Eigen::Matrix<int, -1, 3, 1, -1, 3>, 
  double, 3, 1, 
  float, 3, 1, 
  Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, 
  Eigen::Matrix<int, -1, -1, 0, -1, -1>, 
  Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, Eigen::Matrix<float, 1, 3, 1, 1, 3> const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
#endif