MatrixXd V_out;
vector<MatrixXd> VV;
vector<MatrixXi> FF;
vector<MatrixXd> P;
vector<HalfedgeDS> M;
//Matrix<MatrixXd, Dynamic,1> P;
//P.resize(k, 1);
for (int i = 0; i < k; i++) {
int idx_F = 0;
int idx_V = 0;
for (int f = 0; f < R.rows(); f++) {
//we only add the triangles that belong to the region i
if (R(f, 0) == i) { ///第i个区域
FF[i].row(idx_F) = F.row(f);
idx_F++;
VV[i].row(idx_V) = V.row(F(f, 0));
idx_V++;
HalfedgeBuilder* builder = new HalfedgeBuilder(); ///“new”用来创建一个对象,它会返回这个对象的指针
HalfedgeDS HE = builder->createMesh(VV[i].rows(), FF[i]);
M[i] = HE;
出错的代码是最后一行“M[i] = HE;”
解决办法是将“M[i] = HE;”改成“M.push_back(HE);”
MatrixXd V_out;
vector<MatrixXd> VV;
vector<MatrixXi> FF;
vector<MatrixXd> P;
vector<HalfedgeDS> M;
//Matrix<MatrixXd, Dynamic,1> P;
//P.resize(k, 1);
for (int i = 0; i < k; i++) {
int idx_F = 0;
int idx_V = 0;
for (int f = 0; f < R.rows(); f++) {
//we only add the triangles that belong to the region i
if (R(f, 0) == i) { ///第i个区域
FF[i].row(idx_F) = F.row(f);
idx_F++;
VV[i].row(idx_V) = V.row(F(f, 0));
idx_V++;
HalfedgeBuilder* builder = new HalfedgeBuilder(); ///“new”用来创建一个对象,它会返回这个对象的指针
HalfedgeDS HE = builder->createMesh(VV[i].rows(), FF[i]);
M.push_back(HE);