123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #include "boundary_conditions.h"
- #include "verbose.h"
- #include "EPS.h"
- #include "project_to_line.h"
- #include <vector>
- #include <map>
- #include <iostream>
- IGL_INLINE bool igl::boundary_conditions(
- const Eigen::MatrixXd & V ,
- const Eigen::MatrixXi & ,
- const Eigen::MatrixXd & C ,
- const Eigen::VectorXi & P ,
- const Eigen::MatrixXi & BE ,
- const Eigen::MatrixXi & CE ,
- Eigen::VectorXi & b ,
- Eigen::MatrixXd & bc )
- {
- using namespace Eigen;
- using namespace std;
- if(P.size()+BE.rows() == 0)
- {
- verbose("^%s: Error: no handles found\n",__FUNCTION__);
- return false;
- }
- vector<int> bci;
- vector<int> bcj;
- vector<double> bcv;
-
- for(int p = 0;p<P.size();p++)
- {
- VectorXd pos = C.row(P(p));
-
- for(int i = 0;i<V.rows();i++)
- {
-
-
-
-
-
- VectorXd vi = V.row(i);
- double sqrd = (vi-pos).squaredNorm();
- if(sqrd <= FLOAT_EPS)
- {
-
-
-
-
-
-
-
- bci.push_back(i);
- bcj.push_back(p);
- bcv.push_back(1.0);
- }
- }
- }
-
- for(int e = 0;e<BE.rows();e++)
- {
-
- for(int i = 0;i<V.rows();i++)
- {
-
- VectorXd tip = C.row(BE(e,0));
- VectorXd tail = C.row(BE(e,1));
-
- double t,sqrd;
- project_to_line(
- V(i,0),V(i,1),V(i,2),
- tip(0),tip(1),tip(2),
- tail(0),tail(1),tail(2),
- t,sqrd);
- if(t>=-FLOAT_EPS && t<=(1.0f+FLOAT_EPS) && sqrd<=FLOAT_EPS)
- {
- bci.push_back(i);
- bcj.push_back(P.size()+e);
- bcv.push_back(1.0);
- }
- }
- }
-
- for(int e = 0;e<CE.rows();e++)
- {
-
- for(int i = 0;i<V.rows();i++)
- {
-
- VectorXd tip = C.row(P(CE(e,0)));
- VectorXd tail = C.row(P(CE(e,1)));
-
- double t,sqrd;
- project_to_line(
- V(i,0),V(i,1),V(i,2),
- tip(0),tip(1),tip(2),
- tail(0),tail(1),tail(2),
- t,sqrd);
- if(t>=-FLOAT_EPS && t<=(1.0f+FLOAT_EPS) && sqrd<=FLOAT_EPS)
- {
- bci.push_back(i);
- bcj.push_back(CE(e,0));
- bcv.push_back(1.0-t);
- bci.push_back(i);
- bcj.push_back(CE(e,1));
- bcv.push_back(t);
- }
- }
- }
-
- vector<int> vb = bci;
- sort(vb.begin(),vb.end());
- vb.erase(unique(vb.begin(), vb.end()), vb.end());
- b.resize(vb.size());
- bc = MatrixXd::Zero(vb.size(),P.size()+BE.rows());
-
- map<int,int> bim;
- int i = 0;
-
- for(vector<int>::iterator bit = vb.begin();bit != vb.end();bit++)
- {
- b(i) = *bit;
- bim[*bit] = i;
- i++;
- }
-
- for(i = 0;i < (int)bci.size();i++)
- {
- assert(bim.find(bci[i]) != bim.end());
- bc(bim[bci[i]],bcj[i]) = bcv[i];
- }
-
- for(i = 0;i<bc.rows();i++)
- {
- double sum = bc.row(i).sum();
- assert(sum != 0 && "Some boundary vertex getting all zero BCs");
- bc.row(i).array() /= sum;
- }
- if(bc.size() == 0)
- {
- verbose("^%s: Error: boundary conditions are empty.\n",__FUNCTION__);
- return false;
- }
-
-
- if(bc.cols() == 1)
- {
-
-
- assert(P.rows() + BE.rows() == 1);
- return true;
- }
-
-
- for(i = 0;i<bc.cols();i++)
- {
- double min_abs_c = bc.col(i).array().abs().minCoeff();
- double max_c = bc.col(i).maxCoeff();
- if(min_abs_c > FLOAT_EPS)
- {
- verbose("^%s: Error: handle %d does not receive 0 weight\n",__FUNCTION__,i);
- return false;
- }
- if(max_c< (1-FLOAT_EPS))
- {
- verbose("^%s: Error: handle %d does not receive 1 weight\n",__FUNCTION__,i);
- return false;
- }
- }
- return true;
- }
|