18 using namespace Eigen;
19 using namespace rsvs3d::constants;
35 int ii, jj, nj, nCellTarg;
40 vector<int> subTempVec;
45 MatrixXd dConstrPart, HConstrPart, HObjPart;
47 double constrPart, objPart;
51 auto clock1 = rsvs3d::TimeStamp(NULL, 0);
56 this->useSurfCentreHessian);
58 auto clock2 = rsvs3d::TimeStamp(NULL, clock1);
59 this->timer1 += (clock2 - clock1);
64 nDvAct = dvListMap.vec.size();
65 VolumeCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
66 AreaCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
70 dConstrPart.setZero(1, nDvAct);
71 HConstrPart.setZero(nDvAct, nDvAct);
76 VolumeCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
77 ArrayVec2MatrixXd(*HValpnt, HVal);
78 ArrayVec2MatrixXd(*dValpnt, dVal);
79 Deriv1stChainScalar(dVal, dPos, dConstrPart);
80 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HConstrPart);
87 nCellTarg = triIn.connec.celltarg.size();
88 for (ii = 0; ii < nCellTarg; ++ii)
90 subTempVec = this->constrMap.findall(triIn.connec.celltarg[ii]);
91 nj = subTempVec.size();
92 for (jj = 0; jj < nj; ++jj)
94 if (subTempVec[jj] != __notfound)
96 this->constr[subTempVec[jj]] += triIn.connec.constrinfluence[ii] * constrPart;
99 if (this->UseFullMath())
101 AssignConstraintDerivativesFullMath(*
this, triIn, dvListMap, dConstrPart, HConstrPart,
106 AssignConstraintDerivativesSparseMath(*
this, triIn, dvListMap, dConstrPart, HConstrPart,
118 clock2 = rsvs3d::TimeStamp(NULL, clock1);
119 this->timer2 += (clock2 - clock1);
124 dObjPart.setZero(1, nDvAct);
125 HObjPart.setZero(nDvAct, nDvAct);
130 AreaCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
131 ArrayVec2MatrixXd(*HValpnt, HVal);
132 ArrayVec2MatrixXd(*dValpnt, dVal);
133 Deriv1stChainScalar(dVal, dPos, dObjPart);
134 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HObjPart);
140 this->obj += objPart;
144 for (ii = 0; ii < nDvAct; ++ii)
146 this->dObj[this->dvMap.find(dvListMap.vec[ii])] += dObjPart(0, ii);
147 if (this->UseFullMath())
149 for (jj = 0; jj < nDvAct; ++jj)
151 this->HObj(dvMap.find(dvListMap.vec[jj]), this->dvMap.find(dvListMap.vec[ii])) +=
157 for (jj = 0; jj < nDvAct; ++jj)
159 if (!rsvs3d::utils::IsAproxEqual(HObjPart(jj, ii), 0.0))
161 this->HObj_sparse.coeffRef(dvMap.find(dvListMap.vec[jj]),
162 this->dvMap.find(dvListMap.vec[ii])) += HObjPart(jj, ii);
169 clock2 = rsvs3d::TimeStamp(NULL, clock1);
170 this->timer3 += (clock2 - clock1);
173 for (ii = 0; ii < nDvAct; ++ii)
175 this->isDvAct.at(dvMap.find(dvListMap.vec[ii])) =
true;
179 nCellTarg = triIn.connec.celltarg.size();
180 for (ii = 0; ii < nCellTarg; ++ii)
182 subTempVec = constrMap.findall(triIn.connec.celltarg[ii]);
183 nj = subTempVec.size();
184 for (jj = 0; jj < nj; ++jj)
186 if (subTempVec[jj] != __notfound)
188 this->isConstrAct.at(subTempVec[jj]) =
true;
208 int ii, jj, nj, nCellTarg;
213 vector<int> dvList, subTempVec;
218 MatrixXd dConstrPart, HConstrPart, HObjPart;
220 double constrPart, objPart;
228 this->useSurfCentreHessian);
231 nDvAct = dvListMap.vec.size();
232 VolumeCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
233 AreaCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
237 dConstrPart.setZero(1, nDvAct);
238 HConstrPart.setZero(nDvAct, nDvAct);
243 VolumeCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
244 ArrayVec2MatrixXd(*HValpnt, HVal);
245 ArrayVec2MatrixXd(*dValpnt, dVal);
246 Deriv1stChainScalar(dVal, dPos, dConstrPart);
247 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HConstrPart);
249 constrPart = *retVal;
253 nCellTarg = triIn.connec.celltarg.size();
254 for (ii = 0; ii < nCellTarg; ++ii)
256 subTempVec = this->constrMap.findall(triIn.connec.celltarg[ii]);
257 nj = subTempVec.size();
258 for (jj = 0; jj < nj; ++jj)
260 if (subTempVec[jj] != __notfound)
262 this->constr[subTempVec[jj]] += triIn.connec.constrinfluence[ii] * constrPart;
265 if (this->UseFullMath())
267 AssignConstraintDerivativesFullMath(*
this, triIn, dvListMap, dConstrPart, HConstrPart,
272 AssignConstraintDerivativesSparseMath(*
this, triIn, dvListMap, dConstrPart, HConstrPart,
287 dObjPart.setZero(1, nDvAct);
288 HObjPart.setZero(nDvAct, nDvAct);
293 AreaCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
294 ArrayVec2MatrixXd(*HValpnt, HVal);
295 ArrayVec2MatrixXd(*dValpnt, dVal);
296 Deriv1stChainScalar(dVal, dPos, dObjPart);
297 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HObjPart);
303 this->obj += objPart;
307 for (ii = 0; ii < nDvAct; ++ii)
309 this->dObj[this->dvMap.find(dvListMap.vec[ii])] += dObjPart(0, ii);
310 if (this->UseFullMath())
312 for (jj = 0; jj < nDvAct; ++jj)
314 this->HObj(dvMap.find(dvListMap.vec[jj]), this->dvMap.find(dvListMap.vec[ii])) +=
320 for (jj = 0; jj < nDvAct; ++jj)
322 this->HObj_sparse.coeffRef(dvMap.find(dvListMap.vec[jj]),
323 this->dvMap.find(dvListMap.vec[ii])) += HObjPart(jj, ii);
330 for (ii = 0; ii < nDvAct; ++ii)
332 this->isDvAct.at(dvMap.find(dvListMap.vec[ii])) =
true;
336 nCellTarg = triIn.connec.celltarg.size();
337 for (ii = 0; ii < nCellTarg; ++ii)
339 subTempVec = constrMap.findall(triIn.connec.celltarg[ii]);
340 nj = subTempVec.size();
341 for (jj = 0; jj < nj; ++jj)
343 if (subTempVec[jj] != __notfound)
345 this->isConstrAct.at(subTempVec[jj]) =
true;
364 int ii, ni, jj, nj, nCellTarg;
370 vector<int> dvList, subTempVec, dvOrder;
376 MatrixXd dConstrPart, HConstrPart, HObjPart;
378 double constrPart, objPart;
381 double *retVal = NULL;
382 double *retVal2 = NULL;
388 this->useSurfCentreHessian);
391 nDvAct = dvListMap.vec.size();
392 VolumeCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
393 AreaCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
397 dConstrPart.setZero(1, nDvAct);
398 HConstrPart.setZero(nDvAct, nDvAct);
401 dvOrder.assign(3, 0);
403 for (ii = 0; ii < ni; ++ii)
405 if (triIn.pointtype[ii] == meshtypes::mesh)
408 veccoordvol[1 + ii] = &(triRSVS.meshDep->verts.isearch(triIn.pointind[ii])->coord);
409 veccoordvol[1 + 3 + ii] = &(triRSVS.meshDep->verts.isearch(triIn.pointind[ii])->coord);
411 else if (triIn.pointtype[ii] == meshtypes::snake)
413 subTemp = triRSVS.snakeDep->snakeconn.verts.find(triIn.pointind[ii]);
414 dvOrder[ii] = triIn.pointind[ii];
415 dvec[ii] = triRSVS.snakeDep->snaxs(subTemp)->d;
416 veccoordvol[1 + ii] = &(triRSVS.meshDep->verts.isearch(triRSVS.snakeDep->snaxs(subTemp)->fromvert)->coord);
417 veccoordvol[1 + ii + 3] =
418 &(triRSVS.meshDep->verts.isearch(triRSVS.snakeDep->snaxs(subTemp)->tovert)->coord);
420 else if (triIn.pointtype[ii] == meshtypes::triangulation)
423 veccoordvol[1 + ii] = (triRSVS.trivert.isearch(triIn.pointind[ii])->coord.retPtr());
424 veccoordvol[1 + ii + 3] = (triRSVS.trivert.isearch(triIn.pointind[ii])->coord.retPtr());
429 VolumeCalc2.assign(veccoordvol);
430 VolumeCalc.assign(veccoord[0], veccoord[1],
432 AreaCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
436 dConstrPart.setZero(1, nDvAct);
437 HConstrPart.setZero(nDvAct, nDvAct);
443 VolumeCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
444 VolumeCalc2.ReturnDatPoint(&retVal2, &dValpnt2, &HValpnt2);
445 ArrayVec2MatrixXd(*HValpnt2, HConstrPart);
446 ArrayVec2MatrixXd(*dValpnt2, dConstrPart);
448 if (fabs(*retVal - *retVal2) > 1e-10)
452 constrPart = *retVal2;
454 if (dvListMap.find(1044) != __notfound && isDeriv)
457 DisplayVector(dvOrder);
459 PrintMatrix(dConstrPart);
466 nCellTarg = triIn.connec.celltarg.size();
467 for (ii = 0; ii < nCellTarg; ++ii)
469 subTempVec = this->constrMap.findall(triIn.connec.celltarg[ii]);
470 nj = subTempVec.size();
471 for (jj = 0; jj < nj; ++jj)
473 if (subTempVec[jj] != __notfound)
475 this->constr[subTempVec[jj]] += triIn.connec.constrinfluence[ii] * constrPart;
478 if (this->UseFullMath())
480 AssignConstraintDerivativesFullMath(*
this, triIn, dvListMap, dConstrPart, HConstrPart,
485 AssignConstraintDerivativesSparseMath(*
this, triIn, dvListMap, dConstrPart, HConstrPart,
500 dObjPart.setZero(1, nDvAct);
501 HObjPart.setZero(nDvAct, nDvAct);
506 AreaCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
507 ArrayVec2MatrixXd(*HValpnt, HVal);
508 ArrayVec2MatrixXd(*dValpnt, dVal);
509 Deriv1stChainScalar(dVal, dPos, dObjPart);
510 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HObjPart);
515 this->obj += objPart;
519 for (ii = 0; ii < nDvAct; ++ii)
521 this->dObj[this->dvMap.find(dvListMap.vec[ii])] += dObjPart(0, ii);
522 if (this->UseFullMath())
524 for (jj = 0; jj < nDvAct; ++jj)
526 this->HObj(dvMap.find(dvListMap.vec[jj]), this->dvMap.find(dvListMap.vec[ii])) +=
532 for (jj = 0; jj < nDvAct; ++jj)
534 this->HObj_sparse.coeffRef(dvMap.find(dvListMap.vec[jj]),
535 this->dvMap.find(dvListMap.vec[ii])) += HObjPart(jj, ii);
542 for (ii = 0; ii < nDvAct; ++ii)
544 this->isDvAct.at(dvMap.find(dvListMap.vec[ii])) =
true;
548 nCellTarg = triIn.connec.celltarg.size();
549 for (ii = 0; ii < nCellTarg; ++ii)
551 subTempVec = constrMap.findall(triIn.connec.celltarg[ii]);
552 nj = subTempVec.size();
553 for (jj = 0; jj < nj; ++jj)
555 if (subTempVec[jj] != __notfound)
557 this->isConstrAct.at(subTempVec[jj]) =
true;
572 #pragma GCC diagnostic push
573 #pragma GCC diagnostic ignored "-Wunused-parameter"
577 #pragma GCC diagnostic pop
579 int ii, ni, jj, nj, nCellTarg;
580 int subTemp, subTemp1, subTemp2, subTemp3, nDvAct;
584 vector<int> dvList, subTempVec;
588 MatrixXd HVal, dVal, HVal2, dVal2;
589 MatrixXd dConstrPart, HConstrPart, HObjPart;
597 for (ii = 0; ii < ni; ++ii)
599 if (triIn.pointtype[ii] == meshtypes::mesh)
601 veccoord.push_back(&(triRSVS.meshDep->verts.isearch(triIn.pointind[ii])->coord));
603 else if (triIn.pointtype[ii] == meshtypes::snake)
605 veccoord.push_back(&(triRSVS.snakeDep->snakeconn.verts.isearch(triIn.pointind[ii])->coord));
607 else if (triIn.pointtype[ii] == meshtypes::triangulation)
609 veccoord.push_back((triRSVS.trivert.isearch(triIn.pointind[ii])->coord.retPtr()));
615 AreaCalc.assign(veccoord[0], veccoord[1], veccoord[2]);
619 for (ii = 0; ii < ni; ++ii)
621 if (triIn.pointtype[ii] == meshtypes::snake && this->dvMap.find(triIn.pointind[ii]) != __notfound)
623 dvList.push_back(triIn.pointind[ii]);
625 else if (triIn.pointtype[ii] == meshtypes::triangulation &&
false)
627 subTemp = triRSVS.trivert.find(triIn.pointind[ii]);
628 nj = triRSVS.trisurf(subTemp)->indvert.size();
629 for (jj = 0; jj < nj; ++jj)
631 if (triRSVS.trisurf(subTemp)->typevert[jj] == meshtypes::snake)
633 dvList.push_back(triRSVS.trisurf(subTemp)->indvert[jj]);
638 dvListMap.vec = dvList;
640 unique(dvListMap.vec);
641 dvListMap.GenerateHash();
642 nDvAct = dvListMap.vec.size();
648 HPos.setZero(nDvAct, nDvAct);
649 dPos.setZero(9, nDvAct);
650 for (ii = 0; ii < ni; ++ii)
652 if (triIn.pointtype[ii] == meshtypes::snake && this->dvMap.find(triIn.pointind[ii]) != __notfound)
654 subTemp = triRSVS.snakeDep->snaxs.find(triIn.pointind[ii]);
655 subTemp1 = triRSVS.meshDep->verts.find(triRSVS.snakeDep->snaxs(subTemp)->fromvert);
656 subTemp2 = triRSVS.meshDep->verts.find(triRSVS.snakeDep->snaxs(subTemp)->tovert);
657 subTemp3 = dvListMap.find(triIn.pointind[ii]);
658 for (jj = 0; jj < 3; ++jj)
660 dPos(ii * 3 + jj, subTemp3) +=
661 triRSVS.meshDep->verts(subTemp2)->coord[jj] - triRSVS.meshDep->verts(subTemp1)->coord[jj];
672 dConstrPart.setZero(1, nDvAct);
673 HConstrPart.setZero(nDvAct, nDvAct);
675 AreaCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
676 ArrayVec2MatrixXd(*HValpnt, HVal);
677 ArrayVec2MatrixXd(*dValpnt, dVal);
678 Deriv1stChainScalar(dVal, dPos, dConstrPart);
679 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HConstrPart);
687 for (
int ed = 0; ed < 3; ++ed)
689 if (triIn.pointtype[ed] == meshtypes::snake && triIn.pointtype[(ed + 1) % 3] == meshtypes::snake)
693 EdgeCalc.assign(0, (triRSVS.snakeDep->snakeconn.verts.isearch(triIn.pointind[ed])->coord));
694 EdgeCalc.assign(1, (triRSVS.snakeDep->snakeconn.verts.isearch(triIn.pointind[(ed + 1) % 3])->coord));
696 EdgeCalc.ReturnDatPoint(&retVal, &dValpnt, &HValpnt);
698 ArrayVec2MatrixXd(*HValpnt, HVal2);
699 ArrayVec2MatrixXd(*dValpnt, dVal2);
700 for (ii = 0; ii < 6; ++ii)
702 dVal(0, (ed * 3 + ii) % 9) += dVal2(0, ii);
703 for (jj = 0; jj < 6; ++jj)
705 HVal((ed * 3 + jj) % 9, (ed * 3 + ii) % 9) += HVal2(0, jj);
711 Deriv1stChainScalar(dVal, dPos, dObjPart);
712 Deriv2ndChainScalar(dVal, dPos, HVal, HPos, HObjPart);
715 this->obj += objPart;
719 for (ii = 0; ii < nDvAct; ++ii)
721 this->dObj[this->dvMap.find(dvListMap.vec[ii])] += dObjPart(0, ii);
722 for (jj = 0; jj < nDvAct; ++jj)
724 this->HObj(dvMap.find(dvListMap.vec[jj]), this->dvMap.find(dvListMap.vec[ii])) += HObjPart(jj, ii);
731 for (ii = 0; ii < nDvAct; ++ii)
733 this->isDvAct.at(dvMap.find(dvListMap.vec[ii])) =
true;
735 nCellTarg = triIn.connec.celltarg.size();
736 for (ii = 0; ii < nCellTarg; ++ii)
738 subTempVec = constrMap.findall(triIn.connec.celltarg[ii]);
739 nj = subTempVec.size();
740 for (jj = 0; jj < nj; ++jj)
742 if (subTempVec[jj] != __notfound)
744 this->isConstrAct.at(subTempVec[jj]) =
true;
Provides the infrastructure for calculation of the RSVS equations.
Performs Volume and Area calculations for the RSVS process.
void CalcTriangleEdgeLength(const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
Calculates the properties of single triangle for 2D RSVS.
void CalcTriangle(const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
Calculates the properties of single triangle.
void CalcTriangleDirectVolume(const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
Calculates the properties of single triangle using direct calculation.
void CalcTriangleFD(const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
Calculates the properties of single triangle using Finite difference.
std::vector< const std::vector< double > * > coordlist
Defines a list of coordinates.
Provides various utility functions for the RSVS operation.
Provides the core restricted surface snake container.
Provides a triangulation for snake and meshes.
Provides a 2D std::vector based container.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.