Added a per-face barycentric constraints weight. Removed some annoying warnings.

This commit is contained in:
giorgiomarcias 2014-11-30 19:32:17 +00:00
parent 6ecf866467
commit 8f04d22bb6
1 changed files with 17 additions and 11 deletions

View File

@ -50,19 +50,23 @@ public:
int numF; int numF;
std::vector<ScalarType > BarycentricW; std::vector<ScalarType > BarycentricW;
CoordType TargetPos; CoordType TargetPos;
ScalarType facePenalty;
FaceConstraint() FaceConstraint()
{ {
numF=-1; numF=-1;
facePenalty=ScalarType(PENALTY);
} }
FaceConstraint(int _numF, FaceConstraint(int _numF,
const std::vector<ScalarType > &_BarycentricW, const std::vector<ScalarType > &_BarycentricW,
const CoordType &_TargetPos) const CoordType &_TargetPos,
const ScalarType fPenalty = ScalarType(PENALTY))
{ {
numF=_numF; numF=_numF;
BarycentricW= std::vector<ScalarType > (_BarycentricW.begin(),_BarycentricW.end()); BarycentricW= std::vector<ScalarType > (_BarycentricW.begin(),_BarycentricW.end());
TargetPos=_TargetPos; TargetPos=_TargetPos;
facePenalty=fPenalty;
} }
}; };
@ -99,8 +103,8 @@ private:
static void InitSparse(const std::vector<std::pair<int,int> > &Index, static void InitSparse(const std::vector<std::pair<int,int> > &Index,
const std::vector<ScalarType> &Values, const std::vector<ScalarType> &Values,
const size_t m, const int m,
const size_t n, const int n,
Eigen::SparseMatrix<ScalarType>& X) Eigen::SparseMatrix<ScalarType>& X)
{ {
assert(Index.size()==Values.size()); assert(Index.size()==Values.size());
@ -134,7 +138,7 @@ private:
if (SParam.fixBorder) if (SParam.fixBorder)
{ {
//add penalization constra //add penalization constra
for (int i=0;i<mesh.vert.size();i++) for (size_t i=0;i<mesh.vert.size();i++)
{ {
if (!mesh.vert[i].IsB())continue; if (!mesh.vert[i].IsB())continue;
To_Fix.push_back(i); To_Fix.push_back(i);
@ -166,6 +170,7 @@ private:
std::vector<int> &IndexRhs, std::vector<int> &IndexRhs,
std::vector<ScalarType> &ValueRhs) std::vector<ScalarType> &ValueRhs)
{ {
ScalarType penalty;
int baseIndex=mesh.vert.size(); int baseIndex=mesh.vert.size();
for (size_t i=0;i<SParam.ConstrainedF.size();i++) for (size_t i=0;i<SParam.ConstrainedF.size();i++)
{ {
@ -175,11 +180,12 @@ private:
//add one hard constraint //add one hard constraint
int FaceN=SParam.ConstrainedF[i].numF; int FaceN=SParam.ConstrainedF[i].numF;
assert(FaceN>=0); assert(FaceN>=0);
assert(FaceN<mesh.face.size()); assert(FaceN<(int)mesh.face.size());
assert(mesh.face[FaceN].VN()==SParam.ConstrainedF[i].BarycentricW.size()); assert(mesh.face[FaceN].VN()==(int)SParam.ConstrainedF[i].BarycentricW.size());
penalty=SParam.ConstrainedF[i].facePenalty;
//then add all the weights to impose the constraint //then add all the weights to impose the constraint
for (size_t j=0;j<mesh.face[FaceN].VN();j++) for (int j=0;j<mesh.face[FaceN].VN();j++)
{ {
//get the current weight //get the current weight
ScalarType currW=SParam.ConstrainedF[i].BarycentricW[j]; ScalarType currW=SParam.ConstrainedF[i].BarycentricW[j];
@ -197,10 +203,10 @@ private:
int ComponentConstraint=(IndexConstraint*3)+k; int ComponentConstraint=(IndexConstraint*3)+k;
IndexC.push_back(std::pair<int,int>(ComponentConstraint,IndexV)); IndexC.push_back(std::pair<int,int>(ComponentConstraint,IndexV));
WeightC.push_back(currW*PENALTY); WeightC.push_back(currW*penalty);
IndexC.push_back(std::pair<int,int>(IndexV,ComponentConstraint)); IndexC.push_back(std::pair<int,int>(IndexV,ComponentConstraint));
WeightC.push_back(currW*PENALTY); WeightC.push_back(currW*penalty);
//this to avoid the 1 on diagonal last entry of mass matrix //this to avoid the 1 on diagonal last entry of mass matrix
IndexC.push_back(std::pair<int,int>(ComponentConstraint,ComponentConstraint)); IndexC.push_back(std::pair<int,int>(ComponentConstraint,ComponentConstraint));
@ -218,7 +224,7 @@ private:
//add the diagonal value //add the diagonal value
IndexRhs.push_back(ComponentConstraint); IndexRhs.push_back(ComponentConstraint);
ValueRhs.push_back(ComponentV*PENALTY); ValueRhs.push_back(ComponentV*penalty);
} }
} }
@ -242,7 +248,7 @@ public:
//add the entries for mass matrix //add the entries for mass matrix
if (SParam.useMassMatrix) MeshToMatrix<MeshType>::MassMatrixEntry(mesh,IndexM,ValuesM); if (SParam.useMassMatrix) MeshToMatrix<MeshType>::MassMatrixEntry(mesh,IndexM,ValuesM);
//then add entries for lagrange mult due to barycentric constraints //then add entries for lagrange mult due to barycentric constraints
for (int i=0;i<SParam.ConstrainedF.size();i++) for (size_t i=0;i<SParam.ConstrainedF.size();i++)
{ {
int baseIndex=(mesh.vert.size()+i)*3; int baseIndex=(mesh.vert.size()+i)*3;
for (int j=0;j<3;j++) for (int j=0;j<3;j++)