|
@@ -20,24 +20,61 @@ IGL_INLINE void igl::remove_unreferenced(
|
|
Eigen::PlainObjectBase<DerivedNF> &NF,
|
|
Eigen::PlainObjectBase<DerivedNF> &NF,
|
|
Eigen::PlainObjectBase<DerivedI> &I)
|
|
Eigen::PlainObjectBase<DerivedI> &I)
|
|
{
|
|
{
|
|
|
|
+ Eigen::Matrix<typename DerivedI::Scalar,Eigen::Dynamic,1> J;
|
|
|
|
+ remove_unreferenced(V,F,NV,NF,I,J);
|
|
|
|
+}
|
|
|
|
|
|
- // Mark referenced vertices
|
|
|
|
- Eigen::MatrixXi mark = Eigen::MatrixXi::Zero(V.rows(),1);
|
|
|
|
|
|
+template <
|
|
|
|
+ typename DerivedV,
|
|
|
|
+ typename DerivedF,
|
|
|
|
+ typename DerivedNV,
|
|
|
|
+ typename DerivedNF,
|
|
|
|
+ typename DerivedI,
|
|
|
|
+ typename DerivedJ>
|
|
|
|
+IGL_INLINE void igl::remove_unreferenced(
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedV> &V,
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedF> &F,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedNV> &NV,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedNF> &NF,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedI> &I,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedJ> &J)
|
|
|
|
+{
|
|
|
|
+ const size_t n = V.rows();
|
|
|
|
+ remove_unreferenced(n,F,I,J);
|
|
|
|
+ NF = F;
|
|
|
|
+ for_each(NF.data(),NF.data()+NF.size(),[&I](int & a){a=I(a);});
|
|
|
|
+ slice(V,J,1,NV);
|
|
|
|
+}
|
|
|
|
|
|
|
|
+template <
|
|
|
|
+ typename DerivedF,
|
|
|
|
+ typename DerivedI,
|
|
|
|
+ typename DerivedJ>
|
|
|
|
+IGL_INLINE void igl::remove_unreferenced(
|
|
|
|
+ const size_t n,
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedF> &F,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedI> &I,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedJ> &J)
|
|
|
|
+{
|
|
|
|
+ // Mark referenced vertices
|
|
|
|
+ typedef Eigen::Matrix<bool,Eigen::Dynamic,1> MatrixXb;
|
|
|
|
+ MatrixXb mark = MatrixXb::Zero(n,1);
|
|
for(int i=0; i<F.rows(); ++i)
|
|
for(int i=0; i<F.rows(); ++i)
|
|
{
|
|
{
|
|
for(int j=0; j<F.cols(); ++j)
|
|
for(int j=0; j<F.cols(); ++j)
|
|
{
|
|
{
|
|
if (F(i,j) != -1)
|
|
if (F(i,j) != -1)
|
|
|
|
+ {
|
|
mark(F(i,j)) = 1;
|
|
mark(F(i,j)) = 1;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Sum the occupied cells
|
|
// Sum the occupied cells
|
|
- int newsize = mark.sum();
|
|
|
|
|
|
+ int newsize = mark.count();
|
|
|
|
|
|
- NV.resize(newsize,V.cols());
|
|
|
|
- I.resize(V.rows(),1);
|
|
|
|
|
|
+ I.resize(n,1);
|
|
|
|
+ J.resize(newsize,1);
|
|
|
|
|
|
// Do a pass on the marked vector and remove the unreferenced vertices
|
|
// Do a pass on the marked vector and remove the unreferenced vertices
|
|
int count = 0;
|
|
int count = 0;
|
|
@@ -45,8 +82,8 @@ IGL_INLINE void igl::remove_unreferenced(
|
|
{
|
|
{
|
|
if (mark(i) == 1)
|
|
if (mark(i) == 1)
|
|
{
|
|
{
|
|
- NV.row(count) = V.row(i);
|
|
|
|
I(i) = count;
|
|
I(i) = count;
|
|
|
|
+ J(count) = i;
|
|
count++;
|
|
count++;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -54,18 +91,6 @@ IGL_INLINE void igl::remove_unreferenced(
|
|
I(i) = -1;
|
|
I(i) = -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- NF.resize(F.rows(),F.cols());
|
|
|
|
-
|
|
|
|
- // Apply I on F
|
|
|
|
- for (int i=0; i<F.rows(); ++i)
|
|
|
|
- {
|
|
|
|
- Eigen::RowVectorXi t(F.cols());
|
|
|
|
- for (int j=0; j<F.cols(); ++j)
|
|
|
|
- t(j) = I(F(i,j));
|
|
|
|
-
|
|
|
|
- NF.row(i) = t;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
#ifdef IGL_STATIC_LIBRARY
|