1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "partition.h"
- #include "mat_min.h"
- IGL_INLINE void igl::partition(
- const Eigen::MatrixXd & W,
- const int k,
- Eigen::Matrix<int,Eigen::Dynamic,1> & G,
- Eigen::Matrix<int,Eigen::Dynamic,1> & S,
- Eigen::Matrix<double,Eigen::Dynamic,1> & D)
- {
-
- int n = W.rows();
-
- G.resize(n);
- S.resize(k);
-
-
- int s;
- (W.array().square().matrix()).rowwise().sum().maxCoeff(&s);
- S(0) = s;
-
- D = ((W.rowwise() - W.row(s)).array().square()).matrix().rowwise().sum();
- G.setZero();
-
- for(int i = 1;i<k;i++)
- {
-
- D.maxCoeff(&s);
- S(i) = s;
-
- Eigen::Matrix<double,Eigen::Dynamic,1> Ds =
- ((W.rowwise() - W.row(s)).array().square()).matrix().rowwise().sum();
-
- Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> DDs;
-
- DDs.resize(D.rows(),2);
- DDs.col(0) = D;
- DDs.col(1) = Ds;
-
-
-
- Eigen::Matrix<int,Eigen::Dynamic,1> C;
- igl::mat_min(DDs,2,D,C);
- G = (C.array() ==0).select(G,i);
- }
- }
|