mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 19:33:47 +00:00
Update eigen to v5.0.1 and libigl to v2.6.0. (#11311)
* Update eigen from v3.3.7 to v5.0.1. This updates eigen from v3.3.7 released on December 11, 2018-12-11 to v5.0.1 released on 2025-11-11. There have be a large number of bug-fixes, optimizations, and improvements between these releases. See the details at; https://gitlab.com/libeigen/eigen/-/releases It retains the previous custom minimal `CMakeLists.txt`, and adds a README-OrcaSlicer.md that explains what version and parts of the upstream eigen release have been included, and where the full release can be found. * Update libigl from v2.0.0 (or older) to v2.6.0. This updates libigl from what was probably v2.0.0 released on 2018-10-16 to v2.6.0 released on 2025-05-15. It's possible the old version was even older than that but there is no version indicators in the code and I ran out of patience identifying missing changes and only went back as far as v2.0.0. There have been a large number of bug-fixes, optimizations, and improvements between these versions. See the following for details; https://github.com/libigl/libigl/releases I retained the minimal custom `CMakeLists.txt`, added `README.md` from the libigl distribution which identifies the version, and added a README-OrcaSlicer.md that details the version and parts that have been included. * Update libslic3r for libigl v2.6.0 changes. This updates libslic3r for all changes moving to eigen v5.0.1 and libigl v2.6.0. Despite the large number of updates to both dependencies, no changes were required for the eigen update, and only one change was required for the libigl update. For libigl, `igl::Hit` was changed to a template taking the Scalar type to use. Previously it was hard-coded to `float`, so to minimize possible impact I've updated all places it is used from `igl::Hit` to `igl::Hit<float>`. * Add compiler option `-DNOMINMAX` for libigl with MSVC. MSVC by default defines `min(()` and `max()` macros that break `std::numeric_limits<>::max()`. The upstream cmake that we don't include adds `-DNOMINMAX` for the libigl module when compiling with MSVC, so we need to add the same thing here. * Fix src/libslic3r/TriangleMeshDeal.cpp for the unmodified upstream libigl. This fixes `TriangleMeshDeal.cpp` to work with the unmodified upstream libigl v2.6.0. loop.{h,cpp} implementation. This file and feature was added in PR "BBS Port: Mesh Subdivision" (#12150) which included changes to `loop.{h,cpp}` in the old version of libigl. This PR avoids modifying the included dependencies, and uses the updated upstream versions of those files without any modifications, which requires fixing TriangleMeshDeal.cpp to work with them. In particular, the modifications made to `loop.{h,cpp}` included changing the return type from void to bool, adding additional validation checking of the input meshes, and returning false if they failed validation. These added checks looked unnecessary and would only have caught problems if the input mesh was very corrupt. To make `TriangleMeshDeal.cpp` work without this built-in checking functionality, I removed checking/handling of any `false` return value. There was also a hell of a lot of redundant copying and casting back and forth between float and double, so I cleaned that up. The input and output meshs use floats for the vertexes, and there would be no accuracy benefits from casting to and from doubles for the simple weighted average operations done by igl::loop(). So this just uses `Eigen:Map` to use the original input mesh vertex data directly without requiring any copy or casting. * Move eigen from included `deps_src` to externaly fetched `deps`. This copys what PrusaSlicer did and moved it from an included dependency under `deps_src` to an externaly fetched dependency under `deps`. This requires updating some `CMakeList.txt` configs and removing the old and obsolete `cmake/modules/FindEigen3.cmake`. The details of when this was done in PrusaSlicer and the followup fixes are at; *21116995d7* https://github.com/prusa3d/PrusaSlicer/issues/13608 * https://github.com/prusa3d/PrusaSlicer/pull/13609 *e3c277b9eeFor some reason I don't fully understand this also required fixing `src/slic3r/GUI/GUI_App.cpp` by adding `#include <boost/nowide/cstdio.hpp>` to fix an `error: ‘remove’ is not a member of ‘boost::nowide'`. The main thing I don't understand is how it worked before. Note that this include is in the PrusaSlicer version of this file, but it also significantly deviates from what is currently in OrcaSlicer in many other ways. * Whups... I missed adding the deps/Eigen/Eigen.cmake file... * Tidy some whitespace indenting in CMakeLists.txt. * Ugh... tabs indenting needing fixes. * Change the include order of deps/Eigen. It turns out that although Boost includes some references to Eigen, Eigen also includes some references to Boost for supporting some of it's additional numeric types. I don't think it matters much since we are not using these features, but I think technically its more correct to say Eigen depends on Boost than the other way around, so I've re-ordered them. * Add source for Eigen 5.0.1 download to flatpak yml config. * Add explicit `DEPENDS dep_Boost to deps/Eigen. I missed this before. This ensures we don't rely on include orders to make sure Boost is installed before we configure Eigen. * Add `DEPENDS dep_Boost dep_GMP dep_MPFR` to deps/Eigen. It turns out Eigen can also use GMP and MPFR for multi-precision and multi-precision-rounded numeric types if they are available. Again, I don't think we are using these so it doesn't really matter, but it is technically correct and ensures they are there if we ever do need them. * Fix deps DEPENDENCY ordering for GMP, MPFR, Eigen, and CGAL. I think this is finally correct. Apparently CGAL also optionally depends on Eigen, so the correct dependency order from lowest to highest is GMP, MPFR, Eigen, and CGAL. --------- Co-authored-by: Donovan Baarda <dbaarda@google.com> Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
This commit is contained in:
committed by
SoftFever
parent
797ee70b0b
commit
807520ca1d
@@ -1,21 +1,25 @@
|
||||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
//
|
||||
// Copyright (C) 2015 Qingnan Zhou <qnzhou@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
//
|
||||
#include "extract_cells.h"
|
||||
#include "extract_cells_single_component.h"
|
||||
#include "closest_facet.h"
|
||||
#include "order_facets_around_edge.h"
|
||||
#include "outer_facet.h"
|
||||
#include "submesh_aabb_tree.h"
|
||||
#include "../../extract_manifold_patches.h"
|
||||
#include "../../facet_components.h"
|
||||
#include "../../IGL_ASSERT.h"
|
||||
#include "../../parallel_for.h"
|
||||
#include "../../get_seconds.h"
|
||||
#include "../../PlainMatrix.h"
|
||||
#include "../../triangle_triangle_adjacency.h"
|
||||
#include "../../unique_edge_map.h"
|
||||
#include "../../C_STR.h"
|
||||
#include "../../vertex_triangle_adjacency.h"
|
||||
|
||||
#include <CGAL/AABB_tree.h>
|
||||
@@ -30,37 +34,42 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
//#define EXTRACT_CELLS_DEBUG
|
||||
//#define EXTRACT_CELLS_TIMING
|
||||
|
||||
template<
|
||||
typename DerivedV,
|
||||
typename DerivedF,
|
||||
typename DerivedC >
|
||||
IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
const Eigen::PlainObjectBase<DerivedV>& V,
|
||||
const Eigen::PlainObjectBase<DerivedF>& F,
|
||||
const Eigen::MatrixBase<DerivedV>& V,
|
||||
const Eigen::MatrixBase<DerivedF>& F,
|
||||
Eigen::PlainObjectBase<DerivedC>& cells)
|
||||
{
|
||||
using Index = typename DerivedF::Scalar;
|
||||
static_assert(
|
||||
std::is_same<Index, typename DerivedC::Scalar>::value,
|
||||
"Index type mismatch");
|
||||
using MatrixXI = Eigen::Matrix<Index, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
using VectorXI = Eigen::Matrix<Index, Eigen::Dynamic, 1>;
|
||||
const size_t num_faces = F.rows();
|
||||
// Construct edge adjacency
|
||||
Eigen::MatrixXi E, uE;
|
||||
Eigen::VectorXi EMAP;
|
||||
std::vector<std::vector<size_t> > uE2E;
|
||||
igl::unique_edge_map(F, E, uE, EMAP, uE2E);
|
||||
MatrixXI E, uE;
|
||||
VectorXI EMAP;
|
||||
VectorXI uEC,uEE;
|
||||
igl::unique_edge_map(F, E, uE, EMAP, uEC, uEE);
|
||||
// Cluster into manifold patches
|
||||
Eigen::VectorXi P;
|
||||
igl::extract_manifold_patches(F, EMAP, uE2E, P);
|
||||
VectorXI P;
|
||||
igl::extract_manifold_patches(F, EMAP, uEC, uEE, P);
|
||||
// Extract cells
|
||||
DerivedC per_patch_cells;
|
||||
const size_t num_cells =
|
||||
igl::copyleft::cgal::extract_cells(V,F,P,E,uE,uE2E,EMAP,per_patch_cells);
|
||||
const size_t ncells = extract_cells(V,F,P,uE,EMAP,uEC,uEE,per_patch_cells);
|
||||
// Distribute per-patch cell information to each face
|
||||
cells.resize(num_faces, 2);
|
||||
for (size_t i=0; i<num_faces; i++)
|
||||
for (size_t i=0; i<num_faces; i++)
|
||||
{
|
||||
cells.row(i) = per_patch_cells.row(P[i]);
|
||||
}
|
||||
return num_cells;
|
||||
return ncells;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,20 +77,20 @@ template<
|
||||
typename DerivedV,
|
||||
typename DerivedF,
|
||||
typename DerivedP,
|
||||
typename DerivedE,
|
||||
typename DeriveduE,
|
||||
typename uE2EType,
|
||||
typename DerivedEMAP,
|
||||
typename DeriveduEC,
|
||||
typename DeriveduEE,
|
||||
typename DerivedC >
|
||||
IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
const Eigen::PlainObjectBase<DerivedV>& V,
|
||||
const Eigen::PlainObjectBase<DerivedF>& F,
|
||||
const Eigen::PlainObjectBase<DerivedP>& P,
|
||||
const Eigen::PlainObjectBase<DerivedE>& E,
|
||||
const Eigen::PlainObjectBase<DeriveduE>& uE,
|
||||
const std::vector<std::vector<uE2EType> >& uE2E,
|
||||
const Eigen::PlainObjectBase<DerivedEMAP>& EMAP,
|
||||
Eigen::PlainObjectBase<DerivedC>& cells)
|
||||
const Eigen::MatrixBase<DerivedV>& V,
|
||||
const Eigen::MatrixBase<DerivedF>& F,
|
||||
const Eigen::MatrixBase<DerivedP>& P,
|
||||
const Eigen::MatrixBase<DeriveduE>& uE,
|
||||
const Eigen::MatrixBase<DerivedEMAP>& EMAP,
|
||||
const Eigen::MatrixBase<DeriveduEC>& uEC,
|
||||
const Eigen::MatrixBase<DeriveduEE>& uEE,
|
||||
Eigen::PlainObjectBase<DerivedC>& cells)
|
||||
{
|
||||
// Trivial base case
|
||||
if(P.size() == 0)
|
||||
@@ -92,16 +101,8 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
}
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Plane_3 Plane_3;
|
||||
typedef Kernel::Segment_3 Segment_3;
|
||||
typedef Kernel::Triangle_3 Triangle;
|
||||
typedef std::vector<Triangle>::iterator Iterator;
|
||||
typedef CGAL::AABB_triangle_primitive<Kernel, Iterator> Primitive;
|
||||
typedef CGAL::AABB_traits<Kernel, Primitive> AABB_triangle_traits;
|
||||
typedef CGAL::AABB_tree<AABB_triangle_traits> Tree;
|
||||
|
||||
#ifdef EXTRACT_CELLS_DEBUG
|
||||
#ifdef EXTRACT_CELLS_TIMING
|
||||
const auto & tictoc = []() -> double
|
||||
{
|
||||
static double t_start = igl::get_seconds();
|
||||
@@ -110,8 +111,8 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
return diff;
|
||||
};
|
||||
const auto log_time = [&](const std::string& label) -> void {
|
||||
std::cout << "extract_cells." << label << ": "
|
||||
<< tictoc() << std::endl;
|
||||
printf("%50s: %0.5lf\n",
|
||||
C_STR("extract_cells." << label),tictoc());
|
||||
};
|
||||
tictoc();
|
||||
#else
|
||||
@@ -120,18 +121,19 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
#endif
|
||||
const size_t num_faces = F.rows();
|
||||
typedef typename DerivedF::Scalar Index;
|
||||
using VectorXI = Eigen::Matrix<Index, Eigen::Dynamic, 1>;
|
||||
assert(P.size() > 0);
|
||||
const size_t num_patches = P.maxCoeff()+1;
|
||||
|
||||
// Extract all cells...
|
||||
DerivedC raw_cells;
|
||||
const size_t num_raw_cells =
|
||||
extract_cells_single_component(V,F,P,uE,uE2E,EMAP,raw_cells);
|
||||
log_time("extract_single_component_cells");
|
||||
const int num_raw_cells =
|
||||
extract_cells_single_component(V,F,P,uE,uEC,uEE,raw_cells);
|
||||
log_time("extract_cells_single_component");
|
||||
|
||||
// Compute triangle-triangle adjacency data-structure
|
||||
std::vector<std::vector<std::vector<Index > > > TT,_1;
|
||||
igl::triangle_triangle_adjacency(E, EMAP, uE2E, false, TT, _1);
|
||||
igl::triangle_triangle_adjacency(EMAP, uEC, uEE, false, TT, _1);
|
||||
log_time("compute_face_adjacency");
|
||||
|
||||
// Compute connected components of the mesh
|
||||
@@ -143,7 +145,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
// components[c] --> list of face indices into F of faces in component c
|
||||
std::vector<std::vector<size_t> > components(num_components);
|
||||
// Loop over all faces
|
||||
for (size_t i=0; i<num_faces; i++)
|
||||
for (size_t i=0; i<num_faces; i++)
|
||||
{
|
||||
components[C[i]].push_back(i);
|
||||
}
|
||||
@@ -151,23 +153,27 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
// and precompute data-structures for each component
|
||||
std::vector<std::vector<size_t> > VF,VFi;
|
||||
igl::vertex_triangle_adjacency(V.rows(), F, VF, VFi);
|
||||
std::vector<Eigen::VectorXi> Is(num_components);
|
||||
std::vector<VectorXI> Is(num_components);
|
||||
std::vector<
|
||||
CGAL::AABB_tree<
|
||||
CGAL::AABB_traits<
|
||||
Kernel,
|
||||
Kernel,
|
||||
CGAL::AABB_triangle_primitive<
|
||||
Kernel, std::vector<
|
||||
Kernel::Triangle_3 >::iterator > > > > trees(num_components);
|
||||
std::vector< std::vector<Kernel::Triangle_3 > >
|
||||
std::vector< std::vector<Kernel::Triangle_3 > >
|
||||
triangle_lists(num_components);
|
||||
// O(num_components * num_faces)
|
||||
// In general, extract_cells appears to have O(num_components * num_faces)
|
||||
// performance. This could be painfully tested by a processing a cloud of
|
||||
// tetrahedra.
|
||||
std::vector<std::vector<bool> > in_Is(num_components);
|
||||
|
||||
// Find outer facets, their orientations and cells for each component
|
||||
Eigen::VectorXi outer_facets(num_components);
|
||||
Eigen::VectorXi outer_facet_orientation(num_components);
|
||||
Eigen::VectorXi outer_cells(num_components);
|
||||
for (size_t i=0; i<num_components; i++)
|
||||
VectorXI outer_facets(num_components);
|
||||
VectorXI outer_facet_orientation(num_components);
|
||||
VectorXI outer_cells(num_components);
|
||||
igl::parallel_for(num_components,[&](size_t i)
|
||||
{
|
||||
Is[i].resize(components[i].size());
|
||||
std::copy(components[i].begin(), components[i].end(),Is[i].data());
|
||||
@@ -175,8 +181,8 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
igl::copyleft::cgal::outer_facet(V, F, Is[i], outer_facets[i], flipped);
|
||||
outer_facet_orientation[i] = flipped?1:0;
|
||||
outer_cells[i] = raw_cells(P[outer_facets[i]], outer_facet_orientation[i]);
|
||||
}
|
||||
#ifdef EXTRACT_CELLS_DEBUG
|
||||
},1000);
|
||||
#ifdef EXTRACT_CELLS_TIMING
|
||||
log_time("outer_facet_per_component");
|
||||
#endif
|
||||
|
||||
@@ -185,7 +191,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
// Inputs:
|
||||
// fid index into F
|
||||
// Returns row-vector of barycenter coordinates
|
||||
const auto get_triangle_center = [&V,&F](const size_t fid)
|
||||
const auto get_triangle_center = [&V,&F](const size_t fid)
|
||||
{
|
||||
return ((V.row(F(fid,0))+V.row(F(fid,1))+V.row(F(fid,2)))/3.0).eval();
|
||||
};
|
||||
@@ -193,21 +199,21 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
std::vector<std::vector<size_t> > ambient_cells(num_raw_cells);
|
||||
std::vector<std::vector<size_t> > ambient_comps(num_components);
|
||||
// Only bother if there's more than one component
|
||||
if(num_components > 1)
|
||||
if(num_components > 1)
|
||||
{
|
||||
// construct bounding boxes for each component
|
||||
DerivedV bbox_min(num_components, 3);
|
||||
DerivedV bbox_max(num_components, 3);
|
||||
PlainMatrix<DerivedV,Eigen::Dynamic,3> bbox_min(num_components, 3);
|
||||
PlainMatrix<DerivedV,Eigen::Dynamic,3> bbox_max(num_components, 3);
|
||||
// Assuming our mesh (in exact numbers) fits in the range of double.
|
||||
bbox_min.setConstant(std::numeric_limits<double>::max());
|
||||
bbox_max.setConstant(std::numeric_limits<double>::min());
|
||||
bbox_max.setConstant(std::numeric_limits<double>::lowest());
|
||||
// Loop over faces
|
||||
for (size_t i=0; i<num_faces; i++)
|
||||
{
|
||||
// component of this face
|
||||
const auto comp_id = C[i];
|
||||
const auto& f = F.row(i);
|
||||
for (size_t j=0; j<3; j++)
|
||||
for (size_t j=0; j<3; j++)
|
||||
{
|
||||
for(size_t d=0;d<3;d++)
|
||||
{
|
||||
@@ -227,7 +233,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
bbox_max(cj,1) < bbox_min(ci,1) ||
|
||||
bbox_max(cj,2) < bbox_min(ci,2));
|
||||
};
|
||||
|
||||
|
||||
// Loop over components. This section is O(m²)
|
||||
for (size_t i=0; i<num_components; i++)
|
||||
{
|
||||
@@ -235,7 +241,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
std::vector<size_t> candidate_comps;
|
||||
candidate_comps.reserve(num_components);
|
||||
// Loop over components
|
||||
for (size_t j=0; j<num_components; j++)
|
||||
for (size_t j=0; j<num_components; j++)
|
||||
{
|
||||
if (i == j) continue;
|
||||
if (bbox_intersects(i,j)) candidate_comps.push_back(j);
|
||||
@@ -248,8 +254,8 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
submesh_aabb_tree(V,F,Is[i],trees[i],triangle_lists[i],in_Is[i]);
|
||||
|
||||
// Get query points on each candidate component: barycenter of
|
||||
// outer-facet
|
||||
DerivedV queries(num_candidate_comps, 3);
|
||||
// outer-facet
|
||||
PlainMatrix<DerivedV,Eigen::Dynamic,3> queries(num_candidate_comps, 3);
|
||||
for (size_t j=0; j<num_candidate_comps; j++)
|
||||
{
|
||||
const size_t index = candidate_comps[j];
|
||||
@@ -263,20 +269,21 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
const auto& in_I = in_Is[i];
|
||||
const auto& triangles = triangle_lists[i];
|
||||
|
||||
Eigen::VectorXi closest_facets, closest_facet_orientations;
|
||||
VectorXI closest_facets, closest_facet_orientations;
|
||||
closest_facet(
|
||||
V,
|
||||
F,
|
||||
I,
|
||||
F,
|
||||
I,
|
||||
queries,
|
||||
uE2E,
|
||||
EMAP,
|
||||
EMAP,
|
||||
uEC,
|
||||
uEE,
|
||||
VF,
|
||||
VFi,
|
||||
tree,
|
||||
triangles,
|
||||
in_I,
|
||||
closest_facets,
|
||||
closest_facets,
|
||||
closest_facet_orientations);
|
||||
// Loop over all candidates
|
||||
for (size_t j=0; j<num_candidate_comps; j++)
|
||||
@@ -301,7 +308,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef EXTRACT_CELLS_DEBUG
|
||||
#ifdef EXTRACT_CELLS_TIMING
|
||||
log_time("nested_relationship");
|
||||
#endif
|
||||
|
||||
@@ -325,8 +332,8 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(embedded_comp != INVALID);
|
||||
assert(embedded_cell != INVALID);
|
||||
IGL_ASSERT(embedded_comp != INVALID);
|
||||
IGL_ASSERT(embedded_cell != INVALID);
|
||||
embedded_cells[outer_cell] = embedded_cell;
|
||||
} else {
|
||||
embedded_cells[outer_cell] = INFINITE_CELL;
|
||||
@@ -369,179 +376,19 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
|
||||
raw_cells(i, 1) = negative_cell_id;
|
||||
}
|
||||
cells = raw_cells;
|
||||
#ifdef EXTRACT_CELLS_DEBUG
|
||||
#ifdef EXTRACT_CELLS_TIMING
|
||||
log_time("finalize");
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
template<
|
||||
typename DerivedV,
|
||||
typename DerivedF,
|
||||
typename DerivedP,
|
||||
typename DeriveduE,
|
||||
typename uE2EType,
|
||||
typename DerivedEMAP,
|
||||
typename DerivedC>
|
||||
IGL_INLINE size_t igl::copyleft::cgal::extract_cells_single_component(
|
||||
const Eigen::PlainObjectBase<DerivedV>& V,
|
||||
const Eigen::PlainObjectBase<DerivedF>& F,
|
||||
const Eigen::PlainObjectBase<DerivedP>& P,
|
||||
const Eigen::PlainObjectBase<DeriveduE>& uE,
|
||||
const std::vector<std::vector<uE2EType> >& uE2E,
|
||||
const Eigen::PlainObjectBase<DerivedEMAP>& EMAP,
|
||||
Eigen::PlainObjectBase<DerivedC>& cells)
|
||||
{
|
||||
const size_t num_faces = F.rows();
|
||||
// Input:
|
||||
// index index into #F*3 list of undirect edges
|
||||
// Returns index into face
|
||||
const auto edge_index_to_face_index = [&num_faces](size_t index)
|
||||
{
|
||||
return index % num_faces;
|
||||
};
|
||||
// Determine if a face (containing undirected edge {s,d} is consistently
|
||||
// oriented with directed edge {s,d} (or otherwise it is with {d,s})
|
||||
//
|
||||
// Inputs:
|
||||
// fid face index into F
|
||||
// s source index of edge
|
||||
// d destination index of edge
|
||||
// Returns true if face F(fid,:) is consistent with {s,d}
|
||||
const auto is_consistent =
|
||||
[&F](const size_t fid, const size_t s, const size_t d) -> bool
|
||||
{
|
||||
if ((size_t)F(fid, 0) == s && (size_t)F(fid, 1) == d) return false;
|
||||
if ((size_t)F(fid, 1) == s && (size_t)F(fid, 2) == d) return false;
|
||||
if ((size_t)F(fid, 2) == s && (size_t)F(fid, 0) == d) return false;
|
||||
|
||||
if ((size_t)F(fid, 0) == d && (size_t)F(fid, 1) == s) return true;
|
||||
if ((size_t)F(fid, 1) == d && (size_t)F(fid, 2) == s) return true;
|
||||
if ((size_t)F(fid, 2) == d && (size_t)F(fid, 0) == s) return true;
|
||||
throw "Invalid face!";
|
||||
return false;
|
||||
};
|
||||
|
||||
const size_t num_unique_edges = uE.rows();
|
||||
const size_t num_patches = P.maxCoeff() + 1;
|
||||
|
||||
// Build patch-patch adjacency list.
|
||||
std::vector<std::map<size_t, size_t> > patch_adj(num_patches);
|
||||
for (size_t i=0; i<num_unique_edges; i++) {
|
||||
const size_t s = uE(i,0);
|
||||
const size_t d = uE(i,1);
|
||||
const auto adj_faces = uE2E[i];
|
||||
const size_t num_adj_faces = adj_faces.size();
|
||||
if (num_adj_faces > 2) {
|
||||
for (size_t j=0; j<num_adj_faces; j++) {
|
||||
const size_t patch_j = P[edge_index_to_face_index(adj_faces[j])];
|
||||
for (size_t k=j+1; k<num_adj_faces; k++) {
|
||||
const size_t patch_k = P[edge_index_to_face_index(adj_faces[k])];
|
||||
if (patch_adj[patch_j].find(patch_k) == patch_adj[patch_j].end()) {
|
||||
patch_adj[patch_j].insert({patch_k, i});
|
||||
}
|
||||
if (patch_adj[patch_k].find(patch_j) == patch_adj[patch_k].end()) {
|
||||
patch_adj[patch_k].insert({patch_j, i});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const int INVALID = std::numeric_limits<int>::max();
|
||||
std::vector<size_t> cell_labels(num_patches * 2);
|
||||
for (size_t i=0; i<num_patches; i++) cell_labels[i] = i;
|
||||
std::vector<std::set<size_t> > equivalent_cells(num_patches*2);
|
||||
std::vector<bool> processed(num_unique_edges, false);
|
||||
|
||||
size_t label_count=0;
|
||||
for (size_t i=0; i<num_patches; i++) {
|
||||
for (const auto& entry : patch_adj[i]) {
|
||||
const size_t neighbor_patch = entry.first;
|
||||
const size_t uei = entry.second;
|
||||
if (processed[uei]) continue;
|
||||
processed[uei] = true;
|
||||
|
||||
const auto& adj_faces = uE2E[uei];
|
||||
const size_t num_adj_faces = adj_faces.size();
|
||||
assert(num_adj_faces > 2);
|
||||
|
||||
const size_t s = uE(uei,0);
|
||||
const size_t d = uE(uei,1);
|
||||
|
||||
std::vector<int> signed_adj_faces;
|
||||
for (auto ej : adj_faces)
|
||||
{
|
||||
const size_t fid = edge_index_to_face_index(ej);
|
||||
bool cons = is_consistent(fid, s, d);
|
||||
signed_adj_faces.push_back((fid+1)*(cons ? 1:-1));
|
||||
}
|
||||
{
|
||||
// Sort adjacent faces cyclically around {s,d}
|
||||
Eigen::VectorXi order;
|
||||
// order[f] will reveal the order of face f in signed_adj_faces
|
||||
order_facets_around_edge(V, F, s, d, signed_adj_faces, order);
|
||||
for (size_t j=0; j<num_adj_faces; j++) {
|
||||
const size_t curr_idx = j;
|
||||
const size_t next_idx = (j+1)%num_adj_faces;
|
||||
const size_t curr_patch_idx =
|
||||
P[edge_index_to_face_index(adj_faces[order[curr_idx]])];
|
||||
const size_t next_patch_idx =
|
||||
P[edge_index_to_face_index(adj_faces[order[next_idx]])];
|
||||
const bool curr_cons = signed_adj_faces[order[curr_idx]] > 0;
|
||||
const bool next_cons = signed_adj_faces[order[next_idx]] > 0;
|
||||
const size_t curr_cell_idx = curr_patch_idx*2 + (curr_cons?0:1);
|
||||
const size_t next_cell_idx = next_patch_idx*2 + (next_cons?1:0);
|
||||
equivalent_cells[curr_cell_idx].insert(next_cell_idx);
|
||||
equivalent_cells[next_cell_idx].insert(curr_cell_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t count=0;
|
||||
cells.resize(num_patches, 2);
|
||||
cells.setConstant(INVALID);
|
||||
const auto extract_equivalent_cells = [&](size_t i) {
|
||||
if (cells(i/2, i%2) != INVALID) return;
|
||||
std::queue<size_t> Q;
|
||||
Q.push(i);
|
||||
cells(i/2, i%2) = count;
|
||||
while (!Q.empty()) {
|
||||
const size_t index = Q.front();
|
||||
Q.pop();
|
||||
for (const auto j : equivalent_cells[index]) {
|
||||
if (cells(j/2, j%2) == INVALID) {
|
||||
cells(j/2, j%2) = count;
|
||||
Q.push(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
count++;
|
||||
};
|
||||
for (size_t i=0; i<num_patches; i++) {
|
||||
extract_equivalent_cells(i*2);
|
||||
extract_equivalent_cells(i*2+1);
|
||||
}
|
||||
|
||||
assert((cells.array() != INVALID).all());
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
#ifdef IGL_STATIC_LIBRARY
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
// Explicit template instantiation
|
||||
// generated by autoexplicit.sh
|
||||
template unsigned long igl::copyleft::cgal::extract_cells<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned long, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
// generated by autoexplicit.sh
|
||||
template unsigned long igl::copyleft::cgal::extract_cells<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::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned long, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
template unsigned long igl::copyleft::cgal::extract_cells<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned long, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
template unsigned long igl::copyleft::cgal::extract_cells<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
template size_t igl::copyleft::cgal::extract_cells<Eigen::Matrix<CGAL::Epeck::FT, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<CGAL::Epeck::FT, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
template size_t igl::copyleft::cgal::extract_cells<Eigen::Matrix<CGAL::Epeck::FT, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<CGAL::Epeck::FT, -1, -1, 1, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
template size_t igl::copyleft::cgal::extract_cells<Eigen::Matrix<CGAL::Epeck::FT, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<CGAL::Epeck::FT, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
||||
#ifdef WIN32
|
||||
template unsigned __int64 igl::copyleft::cgal::extract_cells<class Eigen::Matrix<class CGAL::Lazy_exact_nt<class CGAL::Gmpq>, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, 1, 0, -1, 1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned __int64, class Eigen::Matrix<int, -1, 1, 0, -1, 1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>>(class Eigen::PlainObjectBase<class Eigen::Matrix<class CGAL::Lazy_exact_nt<class CGAL::Gmpq>, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 1, 0, -1, 1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class std::vector<class std::vector<unsigned __int64, class std::allocator<unsigned __int64>>, class std::allocator<class std::vector<unsigned __int64, class std::allocator<unsigned __int64>>>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 1, 0, -1, 1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> &);
|
||||
template unsigned __int64 igl::copyleft::cgal::extract_cells<class Eigen::Matrix<class CGAL::Lazy_exact_nt<class CGAL::Gmpq>, -1, -1, 1, -1, -1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, 1, 0, -1, 1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned __int64, class Eigen::Matrix<int, -1, 1, 0, -1, 1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>>(class Eigen::PlainObjectBase<class Eigen::Matrix<class CGAL::Lazy_exact_nt<class CGAL::Gmpq>, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 1, 0, -1, 1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class std::vector<class std::vector<unsigned __int64, class std::allocator<unsigned __int64>>, class std::allocator<class std::vector<unsigned __int64, class std::allocator<unsigned __int64>>>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 1, 0, -1, 1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> &);
|
||||
template unsigned __int64 igl::copyleft::cgal::extract_cells<class Eigen::Matrix<class CGAL::Lazy_exact_nt<class CGAL::Gmpq>, -1, -1, 1, -1, -1>, class Eigen::Matrix<int, -1, 3, 1, -1, 3>, class Eigen::Matrix<int, -1, 1, 0, -1, 1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned __int64, class Eigen::Matrix<int, -1, 1, 0, -1, 1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>>(class Eigen::PlainObjectBase<class Eigen::Matrix<class CGAL::Lazy_exact_nt<class CGAL::Gmpq>, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 3, 1, -1, 3>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 1, 0, -1, 1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class std::vector<class std::vector<unsigned __int64, class std::allocator<unsigned __int64>>, class std::allocator<class std::vector<unsigned __int64, class std::allocator<unsigned __int64>>>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, 1, 0, -1, 1>> const &, class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> &);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user