17 using namespace rsvs3d::constants;
19 void CalculateSnakeVel(
snake &snakein)
23 for (ii = 0; ii < int(snakein.snaxs.size()); ++ii)
25 if (snakein.snaxs(ii)->isfreeze == 1)
27 snakein.snaxs[ii].v = (0.5 - snakein.snaxs[ii].d) * 0.3;
28 snakein.snaxs[ii].isfreeze = 0;
31 snakein.snaxs[ii].v = (0.4 * (double(rand() % 1001) / 1000.0) + 0.8) * snakein.snaxs[ii].v;
35 void CalculateSnakeVelRand(
snake &snakein)
39 for (ii = 0; ii < int(snakein.snaxs.size()); ++ii)
41 if (snakein.snaxs(ii)->isfreeze == 1)
43 snakein.snaxs[ii].v = (0.5 - snakein.snaxs[ii].d) * 0.3;
44 snakein.snaxs[ii].isfreeze = 0;
46 snakein.snaxs[ii].v = (double(rand() % 1001) / 1000.0 + 0.5) * snakein.snaxs[ii].v;
51 void CalculateSnakeVelUnit(
snake &snakein)
55 for (ii = 0; ii < int(snakein.snaxs.size()); ++ii)
57 if (snakein.snaxs(ii)->isfreeze == 1)
59 snakein.snaxs[ii].v = 0;
60 snakein.snaxs[ii].isfreeze = 0;
64 snakein.snaxs[ii].v = 1;
69 void CalculateSnakeVelUnitReflect(
snake &snakein)
73 for (ii = 0; ii < int(snakein.snaxs.size()); ++ii)
75 if (snakein.snaxs(ii)->isfreeze == 1)
77 snakein.snaxs[ii].v = -0.2 * snakein.snaxs[ii].v;
78 snakein.snaxs[ii].isfreeze = 0;
82 snakein.snaxs[ii].v = 1 * snakein.snaxs[ii].v;
87 void CalculateSnakeVelFast(
snake &snakein)
91 for (ii = 0; ii < int(snakein.snaxs.size()); ++ii)
93 if (snakein.snaxs(ii)->isfreeze == 1)
95 snakein.snaxs[ii].v = 0;
96 snakein.snaxs[ii].isfreeze = 0;
99 snakein.snaxs[ii].v = 4;
103 void CalculateNoNanSnakeVel(
snake &snakein,
double deltaStep)
107 for (ii = 0; ii < int(snakein.snaxs.size()); ++ii)
114 if (!isfinite(snakein.snaxs[ii].v))
116 snakein.snaxs[ii].v = (0.5 - snakein.snaxs[ii].d) * deltaStep;
122 cerr << endl << ll <<
" velocities were not finite." << endl;
132 nSurf = meshin.surfs.size();
133 subList.reserve(nSurf);
135 meshin.SurfInParent(subList);
137 TriangulateContainer(meshin, triangleRSVS, meshtypes::mesh, subList);
138 triangleRSVS.meshDep = &meshin;
143 TriangulateContainer(snakein.snakeconn, triangleRSVS, meshtypes::snake);
144 triangleRSVS.snakeDep = &snakein;
149 vector<int> surfReTriangulate;
152 if (triangleRSVS.snakeDep != NULL)
154 triangleRSVS.snakeDep->snakeconn.surfs.ReturnModifInd(surfReTriangulate);
155 surfReTriangulate = triangleRSVS.snakeDep->snakeconn.surfs.find_list(surfReTriangulate);
156 triangleRSVS.CleanDynaTri();
157 triangleRSVS.trivert.SetMaxIndex();
158 if (surfReTriangulate.size() > 0)
160 TriangulateContainer(triangleRSVS.snakeDep->snakeconn, triangleRSVS, meshtypes::snake, surfReTriangulate);
163 BuildTriSurfGridSnakeIntersect(triangleRSVS);
164 surfReTriangulate.clear();
165 TriangulateContainer(triangleRSVS.snakeDep->snakeconn, triangleRSVS, meshtypes::triangulation,
168 n = triangleRSVS.trivert.size();
170 for (ii = 0; ii < n; ++ii)
172 triangleRSVS.CalcTriVertPosDyna(ii);
175 triangleRSVS.snakeDep->snakeconn.surfs.SetNoModif();
176 triangleRSVS.snakeDep->snakeconn.edges.SetNoModif();
177 triangleRSVS.SetConnectivity();
179 triangleRSVS.PrepareForUse();
180 if (triangleRSVS.snakeDep != NULL)
182 triangleRSVS.SetActiveStaticTri();
186 void TriangulateContainer(
const mesh &meshin,
triangulation &triangleRSVS,
const int typeMesh,
187 const vector<int> &subList)
189 int ii, n, nTriS, nTriE, maxIndVert, maxIndTriangle;
192 if (typeMesh == meshtypes::mesh)
194 mp = &triangulation::stattri;
196 else if (typeMesh == meshtypes::snake)
198 mp = &triangulation::dynatri;
200 else if (typeMesh == meshtypes::triangulation)
202 mp = &triangulation::intertri;
209 maxIndVert = triangleRSVS.trivert.GetMaxIndex();
210 maxIndTriangle = int((triangleRSVS.*mp).GetMaxIndex());
212 nTriS = int((triangleRSVS.*mp).size());
213 if (
int(subList.size()) == 0)
216 if (typeMesh != meshtypes::triangulation)
218 n = meshin.surfs.size();
219 for (ii = 0; ii < n; ++ii)
221 TriangulateSurface(*(meshin.surfs(ii)), meshin, triangleRSVS.*mp, triangleRSVS.trivert, typeMesh,
222 maxIndVert + ii + 1);
227 n = triangleRSVS.trisurf.size();
228 for (ii = 0; ii < n; ++ii)
230 TriangulateTriSurface(*(triangleRSVS.trisurf(ii)), triangleRSVS.*mp, triangleRSVS.trivert, typeMesh,
231 maxIndVert + ii + 1);
238 if (typeMesh != meshtypes::triangulation)
240 for (ii = 0; ii < n; ++ii)
242 TriangulateSurface(*(meshin.surfs(subList[ii])), meshin, triangleRSVS.*mp, triangleRSVS.trivert,
243 typeMesh, maxIndVert + ii + 1);
248 for (ii = 0; ii < n; ++ii)
250 TriangulateTriSurface(*(triangleRSVS.trisurf(subList[ii])), triangleRSVS.*mp, triangleRSVS.trivert,
251 typeMesh, maxIndVert + ii + 1);
255 nTriE = int((triangleRSVS.*mp).size());
256 for (ii = 0; ii < (nTriE - nTriS); ++ii)
258 (triangleRSVS.*mp)[nTriS + ii].index = ii + maxIndTriangle + 1;
263 const int typeMesh,
int trivertMaxInd)
273 vector<int> orderVert;
274 int nextInd = triangul.GetMaxIndex();
279 n = int(surfin.edgeind.size());
280 surfin.OrderedVerts(&meshin, orderVert);
281 triangleEdge.SetPointType(typeMesh, typeMesh, meshtypes::triangulation);
282 triangleEdge.pointind[2] = trivertMaxInd + 1;
283 triangleEdge.parentsurf = surfin.index;
285 if (typeMesh != meshtypes::snake)
287 triangleEdge.connec.celltarg = surfin.voluind;
288 triangleEdge.connec.constrinfluence = {-1.0, 1.0};
294 triangleEdge.connec.celltarg = {};
295 triangleEdge.connec.constrinfluence = {};
304 for (ii = 0; ii < n; ++ii)
314 triangleEdge.index = ++nextInd;
315 triangleEdge.pointind[0] = orderVert[ii];
316 triangleEdge.pointind[1] = orderVert[(ii + 1) % n];
317 triangul.push_back(triangleEdge);
321 surfCentre.index = trivertMaxInd + 1;
322 surfCentre.parentsurf = surfin.index;
323 surfCentre.parentType = typeMesh;
324 if (typeMesh == meshtypes::snake)
326 surfCentre.nInfluences = n;
328 trivert.push_back(surfCentre);
332 triangleEdge.SetPointType(typeMesh, typeMesh, typeMesh);
333 triangleEdge.index = ++nextInd;
334 triangleEdge.pointind = orderVert;
335 triangleEdge.parentsurf = surfin.index;
336 triangul.push_back(triangleEdge);
350 int nextInd = triangul.GetMaxIndex();
354 n = int(surfin.indvert.size());
356 triangleEdge.SetPointType(typeMesh, typeMesh, meshtypes::triangulation);
357 triangleEdge.pointind[2] = trivertMaxInd + 1;
358 triangleEdge.parentsurf = surfin.index;
361 triangleEdge.connec.celltarg = surfin.voluind;
362 triangleEdge.connec.constrinfluence = {-1.0, 1.0};
370 for (ii = 0; ii < n; ++ii)
372 triangleEdge.SetPointType(surfin.typevert[ii], surfin.typevert[(ii + 1) % n], meshtypes::triangulation);
374 triangleEdge.index = ++nextInd;
376 triangleEdge.pointind[0] = surfin.indvert[ii];
377 triangleEdge.pointind[1] = surfin.indvert[(ii + 1) % n];
378 triangul.push_back(triangleEdge);
379 kk += (surfin.typevert[ii] == meshtypes::snake);
382 surfCentre.index = trivertMaxInd + 1;
383 surfCentre.parentsurf = surfin.index;
384 surfCentre.parentType = typeMesh;
385 if (typeMesh == meshtypes::snake)
387 surfCentre.nInfluences = kk;
389 trivert.push_back(surfCentre);
393 triangleEdge.SetPointType(surfin.typevert[0], surfin.typevert[1], surfin.typevert[2]);
395 triangleEdge.index = ++nextInd;
396 triangleEdge.pointind = surfin.indvert;
397 triangleEdge.parentsurf = surfin.index;
398 triangul.push_back(triangleEdge);
402 void SurfaceCentroid_fun2(
coordvec &coord,
const surf &surfin,
const mesh &meshin)
406 double edgeLength, surfLength = 0;
407 coord.assign(0, 0, 0);
408 n = int(surfin.edgeind.size());
409 for (ii = 0; ii < n; ++ii)
411 meshin.edges.isearch(surfin.edgeind[ii])->GeometricProperties(&meshin, edgeCentre, edgeLength);
412 edgeCentre.mult(edgeLength);
413 coord.add(edgeCentre.usedata());
414 surfLength += edgeLength;
417 coord.div(surfLength);
420 void SnakeSurfaceCentroid_fun(
coordvec &coord,
const surf &surfin,
const mesh &meshin)
425 coord.assign(0, 0, 0);
427 tempCalc = SurfaceCentroid_SnakeSurf(surfin, meshin);
431 tempCalc.ReturnDat(tempCoord, jac, hes);
432 coord.assign(tempCoord[0][0], tempCoord[1][0], tempCoord[2][0]);
442 n = int(surfin.edgeind.size());
445 ConnVertFromConnEdge(meshin, surfin.edgeind, vertind);
447 for (ii = 0; ii < n; ++ii)
449 veccoord.push_back(&(meshin.verts.isearch(vertind[ii])->coord));
454 veccoord.push_back(&(meshin.verts.isearch(vertind[0])->coord));
457 tempCalc.assign(veccoord);
466 coord.assign(0, 0, 0);
468 tempCalc = SurfaceCentroid_TriangleSurf(surfin, meshin, snakeconn);
472 tempCalc.ReturnDat(tempCoord, jac, hes);
473 coord.assign(tempCoord[0][0], tempCoord[1][0], tempCoord[2][0]);
484 n = surfin.indvert.size();
485 for (ii = 0; ii < n; ++ii)
487 if (surfin.typevert[ii] == meshtypes::mesh)
489 veccoord.push_back(&(meshin.verts.isearch(surfin.indvert[ii])->coord));
491 else if (surfin.typevert[ii] == meshtypes::snake)
493 veccoord.push_back(&(snakeconn.verts.isearch(surfin.indvert[ii])->coord));
499 if (surfin.typevert[ii] == meshtypes::mesh)
501 veccoord.push_back(&(meshin.verts.isearch(surfin.indvert[ii])->coord));
503 else if (surfin.typevert[ii] == meshtypes::snake)
505 veccoord.push_back(&(snakeconn.verts.isearch(surfin.indvert[ii])->coord));
509 tempCalc.assign(veccoord);
517 int nVe, nE, nSurf, nVolu;
518 std::vector<int> voluInds;
522 nSurf = triin.size();
528 for (ii = 0; ii < ni; ++ii)
530 voluInds.push_back(triin(ii)->connec.celltarg[0]);
531 voluInds.push_back(triin(ii)->connec.celltarg[1]);
537 meshout.Init(nVe, nE, nSurf, nVolu);
538 meshout.PopulateIndices();
539 meshout.volus.HashArray();
542 for (ii = 0; ii < nSurf; ++ii)
545 meshout.surfs[ii].edgeind = {ii * 3 + 1, ii * 3 + 2, ii * 3 + 3};
546 meshout.surfs[ii].voluind.clear();
547 for (jj = 0; jj < int(triin(ii)->connec.celltarg.size()); jj++)
549 for (
auto x : calcObj.
constrMap.findall(triin(ii)->connec.celltarg[jj]))
551 meshout.surfs[ii].voluind.push_back(x + 1);
555 if (meshout.surfs[ii].voluind.size() == 1)
557 meshout.surfs[ii].voluind.push_back(0);
559 if (rsvs3d::utils::IsAproxEqual(triin(ii)->connec.constrinfluence[0], 1.0))
561 kk = meshout.surfs[ii].voluind[0];
562 meshout.surfs[ii].voluind[0] = meshout.surfs[ii].voluind[1];
563 meshout.surfs[ii].voluind[1] = kk;
566 for (jj = 0; jj < int(meshout.surfs[ii].voluind.size()); jj++)
568 kk = meshout.volus.find(meshout.surfs[ii].voluind[jj],
true);
571 meshout.volus[kk].surfind.push_back(ii + 1);
573 else if (meshout.surfs[ii].voluind[jj] != 0)
575 std::cerr <<
" w " << kk <<
" " << meshout.surfs[ii].voluind[jj] <<
" "
576 << triin(ii)->connec.celltarg[jj];
581 for (jj = 0; jj < 3; jj++)
583 meshout.edges[ii * 3 + jj].surfind = {meshout.surfs(ii)->index};
584 meshout.edges[ii * 3 + jj].vertind = {ii * 3 + 1 + jj, ii * 3 + 1 + ((jj + 1) % 3)};
585 if (triin(ii)->pointtype[jj] == meshtypes::mesh)
587 meshout.verts[ii * 3 + jj].coord = triangul.meshDep->verts.isearch(triin(ii)->pointind[jj])->coord;
589 else if (triin(ii)->pointtype[jj] == meshtypes::snake)
591 meshout.verts[ii * 3 + jj].coord =
592 triangul.snakeDep->snakeconn.verts.isearch(triin(ii)->pointind[jj])->coord;
594 else if (triin(ii)->pointtype[jj] == meshtypes::triangulation)
596 meshout.verts[ii * 3 + jj].coord = triangul.trivert.isearch(triin(ii)->pointind[jj])->coord.usedata();
598 meshout.verts[ii * 3 + jj].edgeind = {ii * 3 + 1 + jj, ii * 3 + 1 + ((jj + 3 - 1) % 3)};
601 meshout.PrepareForUse();
609 int ii, jj, kk, ll, n, nSub, subSurf, nSurfInd, mm;
610 int nNewVert, nNewEdge, nNewSurf, maxIndVert, maxIndEdge, maxIndSurf, vertSub;
611 vector<bool> isTriDone;
612 vector<int> tempSub, tempType, tempVert, tempEdge;
619 vector<ConnecRemv> conn;
623 meshout.PrepareForUse();
624 triangul.PrepareForUse();
625 trivert.PrepareForUse();
626 meshout.SetMaxIndex();
628 n = int(triangul.size());
629 isTriDone.assign(n,
false);
634 maxIndVert = meshout.verts.GetMaxIndex();
635 maxIndEdge = meshout.edges.GetMaxIndex();
636 maxIndSurf = meshout.surfs.GetMaxIndex();
640 buildEdge.vertind.assign(2, 0);
641 buildEdge.surfind.assign(2, 0);
643 for (ii = 0; ii < n; ++ii)
647 tempType = triangul(ii)->pointtype;
650 if (
int(tempType.size()) > 1)
652 triangul.findsiblings(triangul(ii)->KeyParent(), tempSub);
653 nSub = tempSub.size();
655 for (jj = 0; jj < nSub; ++jj)
657 isTriDone[tempSub[jj]] =
true;
660 subSurf = meshin.surfs.find(triangul(ii)->KeyParent());
661 tempVert = ConcatenateVectorField(meshin.edges, &edge::vertind,
662 meshin.edges.find_list(meshin.surfs(subSurf)->edgeind));
666 tempEdge = meshin.edges.find_list(meshin.surfs(subSurf)->edgeind);
672 for (jj = 0; jj < 3; ++jj)
674 if (triangul(ii)->pointtype[jj] == meshtypes::triangulation)
676 buildVert.index = maxIndVert + nNewVert + 1;
678 buildVert.coord = trivert.isearch(triangul(ii)->pointind[jj])->coord.usedata();
679 buildVert.edgeind.clear();
680 for (kk = 0; kk < int(tempVert.size()); ++kk)
682 buildVert.edgeind.push_back(maxIndEdge + nNewEdge + 1 + kk);
684 tempMesh.verts.push_back(buildVert);
691 flag = (meshin.edges(tempEdge[kk])->vertind[ll] == meshin.edges(tempEdge[kk + 1])->vertind[0]) |
692 (meshin.edges(tempEdge[kk])->vertind[ll] == meshin.edges(tempEdge[kk + 1])->vertind[1]);
698 nSub = int(tempEdge.size());
699 for (kk = 0; kk < nSub; ++kk)
701 buildEdge.index = (maxIndEdge + nNewEdge + 1 + kk);
702 buildEdge.vertind[0] = buildVert.index;
703 buildEdge.vertind[1] = meshin.edges(tempEdge[kk])->vertind[ll];
704 vertSub = meshin.verts.find(meshin.edges(tempEdge[kk])->vertind[ll]);
705 meshout.verts[vertSub].edgeind.push_back(maxIndEdge + nNewEdge + 1 + kk);
707 buildEdge.surfind[0] =
708 (kk == 0) * (meshin.surfs(subSurf)->index) + (kk != 0) * (maxIndSurf + nNewSurf + kk);
709 buildEdge.surfind[1] = (kk == (nSub - 1)) * (meshin.surfs(subSurf)->index) +
710 (kk != (nSub - 1)) * (maxIndSurf + nNewSurf + kk + 1);
712 tempMesh.edges.push_back(buildEdge);
716 meshout.surfs[subSurf].edgeind.clear();
717 meshout.surfs[subSurf].edgeind.push_back(maxIndEdge + nNewEdge + 1);
718 meshout.surfs[subSurf].edgeind.push_back(maxIndEdge + nNewEdge + nSub);
719 meshout.surfs[subSurf].edgeind.push_back(meshin.edges(tempEdge[kk])->index);
723 buildSurf = *(meshin.surfs(subSurf));
724 buildSurf.index = maxIndSurf + nNewSurf + kk;
725 buildSurf.edgeind.clear();
726 buildSurf.edgeind.push_back(maxIndEdge + nNewEdge + kk);
727 buildSurf.edgeind.push_back(maxIndEdge + nNewEdge + kk + 1);
728 buildSurf.edgeind.push_back(meshin.edges(tempEdge[kk])->index);
730 tempMesh.surfs.push_back(buildSurf);
732 nSurfInd = meshout.edges[tempEdge[kk]].surfind.size();
733 for (mm = 0; mm < nSurfInd; ++mm)
735 if (meshout.edges[tempEdge[kk]].surfind[mm] == meshin.surfs(subSurf)->index)
737 meshout.edges[tempEdge[kk]].surfind[mm] = maxIndSurf + nNewSurf + kk;
740 nSurfInd = buildSurf.voluind.size();
741 for (mm = 0; mm < nSurfInd; ++mm)
743 if (buildSurf.voluind[mm] != 0)
745 meshout.volus[meshin.volus.find(buildSurf.voluind[mm])].surfind.push_back(
751 if (kk <
int(tempEdge.size() - 1))
753 flag = (meshin.edges(tempEdge[kk])->vertind[0] == meshin.edges(tempEdge[kk + 1])->vertind[ll]) |
754 (meshin.edges(tempEdge[kk])->vertind[1] == meshin.edges(tempEdge[kk + 1])->vertind[ll]);
755 ll = ((ll + 1) % 2) * (flag) + ll * (!flag);
758 nNewEdge = nNewEdge + nSub;
759 nNewSurf = nNewSurf + nSub - 1;
761 isTriDone[ii] =
true;
765 meshout.Concatenate(tempMesh);
766 meshout.PrepareForUse();
770 bool FollowSnaxEdgeConnection(
int actSnax,
int actSurf,
int followSnaxEdge,
const snake &snakeRSVS,
771 vector<bool> &isSnaxEdgeDone,
int &returnIndex)
780 int snaxSub, snaxedgeSub, ii, kk, nE;
781 bool flagIter, isRepeat;
784 snaxSub = snakeRSVS.snakeconn.verts.find(actSnax);
785 nE = snakeRSVS.snakeconn.verts(snaxSub)->edgeind.size();
789 if (followSnaxEdge == 0)
799 while (ii < nE && !flagIter)
801 followSnaxEdge = snakeRSVS.snakeconn.verts(snaxSub)->edgeind[ii];
802 flagIter = snakeRSVS.snaxedges.isearch(followSnaxEdge)->surfind == actSurf;
808 cerr <<
"Error : Cannot build grid/snake intersection a suitable edge in "
811 cerr <<
" was not found." << endl;
812 cerr <<
"Error in " << __PRETTY_FUNCTION__ << endl;
816 snaxedgeSub = snakeRSVS.snaxedges.find(followSnaxEdge);
818 isRepeat = (isSnaxEdgeDone[snaxedgeSub]);
819 isSnaxEdgeDone[snaxedgeSub] =
true;
822 kk = snakeRSVS.snakeconn.edges(snaxedgeSub)->vertind[kk] != actSnax;
824 actSnax = snakeRSVS.snakeconn.edges(snaxedgeSub)->vertind[kk];
825 returnIndex = actSnax;
829 int FollowSnaxelDirection(
int actSnax,
const snake &snakeRSVS,
int &returnIndex,
int &returnType,
int &actEdge)
843 int currSnaxOrd, nextSnaxOrd, nextSnaxPos, testOrder;
844 vector<int> snaxSiblings;
846 snaxSub = snakeRSVS.snaxs.find(actSnax);
847 dirSnax = snakeRSVS.snaxs(snaxSub)->fromvert < snakeRSVS.snaxs(snaxSub)->tovert;
849 snakeRSVS.snaxs.findsiblings(snakeRSVS.snaxs(snaxSub)->edgeind, snaxSiblings);
850 actEdge = snakeRSVS.snaxs(snaxSub)->edgeind;
851 nSib = snaxSiblings.size();
855 returnIndex = snakeRSVS.snaxs(snaxSub)->fromvert;
859 currSnaxOrd = snakeRSVS.snaxs(snaxSub)->orderedge;
865 for (ii = 0; ii < nSib; ++ii)
867 testOrder = snakeRSVS.snaxs(snaxSiblings[ii])->orderedge;
869 if (testOrder < currSnaxOrd && (testOrder > nextSnaxOrd || nextSnaxPos == -1))
872 nextSnaxOrd = testOrder;
878 for (ii = 0; ii < nSib; ++ii)
880 testOrder = snakeRSVS.snaxs(snaxSiblings[ii])->orderedge;
882 if (testOrder > currSnaxOrd && (testOrder < nextSnaxOrd || nextSnaxPos == -1))
885 nextSnaxOrd = testOrder;
889 if (nextSnaxPos == -1)
892 returnIndex = snakeRSVS.snaxs(snaxSub)->fromvert;
897 returnIndex = snakeRSVS.snaxs(snaxSiblings[nextSnaxPos])->index;
905 int &returnIndex,
int &returnType,
int &nextEdge)
912 vector<int> tempVert, snaxTemp;
913 int ii, jj, kk, nSnax, currOrd, currSnax;
916 tempVert = vertSurfInd.findall(actVert);
918 if (tempVert.size() != 2)
924 jj = edgeSurfInd.vec[tempVert[jj] / 2] != prevEdge;
925 nextEdge = edgeSurfInd.vec[tempVert[jj] / 2];
927 snakeRSVS.snaxs.findsiblings(nextEdge, snaxTemp);
928 nSnax = snaxTemp.size();
932 returnIndex = vertSurfInd.vec[tempVert[jj] + 1 - ((tempVert[jj] % 2) * 2)];
937 returnIndex = snakeRSVS.snaxs(snaxTemp[0])->index;
941 kk = tempVert[jj] % 2;
943 isDir = meshRSVS.edges.isearch(nextEdge)->vertind[kk] < actVert;
944 currOrd = snakeRSVS.snaxs(snaxTemp[0])->orderedge;
945 currSnax = snakeRSVS.snaxs(snaxTemp[0])->index;
948 for (ii = 1; ii < nSnax; ++ii)
950 if (snakeRSVS.snaxs(snaxTemp[ii])->orderedge > currOrd)
952 currOrd = snakeRSVS.snaxs(snaxTemp[ii])->orderedge;
953 currSnax = snakeRSVS.snaxs(snaxTemp[0])->index;
959 for (ii = 1; ii < nSnax; ++ii)
961 if (snakeRSVS.snaxs(snaxTemp[ii])->orderedge < currOrd)
963 currOrd = snakeRSVS.snaxs(snaxTemp[ii])->orderedge;
964 currSnax = snakeRSVS.snaxs(snaxTemp[0])->index;
970 returnIndex = currSnax;
976 void BuildTriSurfGridSnakeIntersect(
triangulation &triangleRSVS)
981 vector<bool> isSnaxEdgeDone;
982 int ii, n2, nVert, nSnax;
983 int actIndex, actSurf, actEdge, actSurfSub, maxNEdge, isFlip;
984 int returnType, returnIndex, returnEdge, actType;
987 vector<int> edgeSub, pseudoEdgeInd;
990 n2 = triangleRSVS.snakeDep->snaxedges.size();
991 isSnaxEdgeDone.assign(n2,
false);
992 pseudoEdgeInd.assign(4, 0);
993 triangleRSVS.trisurf.clear();
994 newTrisSurf.index = 0;
995 for (ii = 0; ii < n2; ii++)
997 if (!isSnaxEdgeDone[ii])
1000 actEdge = triangleRSVS.snakeDep->snaxedges(ii)->index;
1001 actSurf = triangleRSVS.snakeDep->snaxedges(ii)->surfind;
1002 actSurfSub = triangleRSVS.meshDep->surfs.find(actSurf);
1005 if (triangleRSVS.meshDep->SurfInParent(actSurf) >= 0)
1007 newTrisSurf.parentsurfmesh = actSurf;
1008 newTrisSurf.indvert.clear();
1009 newTrisSurf.typevert.clear();
1010 newTrisSurf.indvert.reserve(8);
1011 newTrisSurf.typevert.reserve(8);
1012 newTrisSurf.index++;
1014 hashedEdgeInd.vec = triangleRSVS.meshDep->surfs(actSurfSub)->edgeind;
1015 edgeSub = triangleRSVS.meshDep->edges.find_list(hashedEdgeInd.vec);
1016 hashedEdgeInd.GenerateHash();
1017 vertSurfList.vec = ConcatenateVectorField(triangleRSVS.meshDep->edges, &edge::vertind, edgeSub);
1018 vertSurfList.GenerateHash();
1020 actIndex = triangleRSVS.snakeDep->snakeconn.edges(ii)->vertind[0];
1025 maxNEdge = hashedEdgeInd.vec.size();
1027 while (!flagDone && nVert < maxNEdge + 2)
1029 if (actType == meshtypes::mesh)
1031 newTrisSurf.indvert.push_back(actIndex);
1032 newTrisSurf.typevert.push_back(actType);
1033 FollowVertexConnection(actIndex, actEdge, hashedEdgeInd, vertSurfList, *(triangleRSVS.snakeDep),
1034 *(triangleRSVS.meshDep), returnIndex, returnType, returnEdge);
1035 pseudoEdgeInd[1] = actEdge;
1036 pseudoEdgeInd[2] = returnEdge;
1037 actEdge = returnEdge;
1038 actType = returnType;
1039 actIndex = returnIndex;
1042 else if (actType == meshtypes::snake)
1044 flagDone = FollowSnaxEdgeConnection(actIndex, actSurf, actEdge, *(triangleRSVS.snakeDep),
1045 isSnaxEdgeDone, returnIndex);
1049 newTrisSurf.indvert.push_back(actIndex);
1050 newTrisSurf.typevert.push_back(actType);
1052 actIndex = returnIndex;
1054 newTrisSurf.indvert.push_back(actIndex);
1055 newTrisSurf.typevert.push_back(actType);
1058 FollowSnaxelDirection(actIndex, *(triangleRSVS.snakeDep), returnIndex, returnType, actEdge);
1059 actType = returnType;
1060 actIndex = returnIndex;
1062 else if (nVert == 0)
1065 pseudoEdgeInd[1] = triangleRSVS.snakeDep->snaxs.isearch(actIndex)->edgeind;
1066 FollowVertexConnection(triangleRSVS.snakeDep->snaxs.isearch(actIndex)->tovert,
1067 pseudoEdgeInd[1], hashedEdgeInd, vertSurfList,
1068 *(triangleRSVS.snakeDep), *(triangleRSVS.meshDep), returnIndex,
1069 returnType, returnEdge);
1070 pseudoEdgeInd[2] = returnEdge;
1073 if (actType == meshtypes::snake)
1078 if (nVert > maxNEdge)
1084 newTrisSurf.voluind = triangleRSVS.meshDep->surfs(actSurfSub)->voluind;
1085 isFlip = OrderMatchLists(pseudoEdgeInd, triangleRSVS.meshDep->surfs(actSurfSub)->edgeind,
1086 pseudoEdgeInd[1], pseudoEdgeInd[2]);
1089 isFlip = newTrisSurf.voluind[0];
1090 newTrisSurf.voluind[0] = newTrisSurf.voluind[1];
1091 newTrisSurf.voluind[1] = isFlip;
1093 triangleRSVS.trisurf.push_back(newTrisSurf);
1095 isSnaxEdgeDone[ii] =
true;
1116 void triangulation::disp()
const
1118 cout <<
"This is a triangulation object" << endl;
1120 void triangulation::PrepareForUse()
1122 stattri.PrepareForUse();
1123 dynatri.PrepareForUse();
1124 intertri.PrepareForUse();
1125 trivert.PrepareForUse();
1126 trisurf.PrepareForUse();
1129 void triangulation::CleanDynaTri()
1131 vector<int> triDel, pDEl;
1136 for (ii = 0; ii < n; ++ii)
1138 if (snakeDep->snakeconn.surfs.find(dynatri(ii)->KeyParent()) == __notfound)
1140 triDel.push_back(dynatri(ii)->index);
1142 else if (snakeDep->snakeconn.surfs.isearch(dynatri(ii)->KeyParent())->returnIsModif())
1144 triDel.push_back(dynatri(ii)->index);
1149 for (ii = 0; ii < n; ++ii)
1152 for (jj = 0; jj < n2; ++jj)
1154 if (dynatri.isearch(triDel[ii])->pointtype[jj] == meshtypes::triangulation)
1156 pDEl.push_back(dynatri.isearch(triDel[ii])->pointind[jj]);
1163 for (ii = 0; ii < n; ++ii)
1165 if (trivert(ii)->parentType == meshtypes::triangulation)
1167 pDEl.push_back(trivert(ii)->index);
1171 dynatri.remove(triDel);
1172 trivert.remove(pDEl);
1178 void triangulation::CalcTriVertPos()
1182 for (ii = 0; ii < n; ++ii)
1187 void triangulation::CalcTriVertPos(
int ii)
1189 if (trivert(ii)->parentType == meshtypes::mesh)
1191 SnakeSurfaceCentroid_fun(trivert[ii].coord, *(meshDep->surfs.isearch(trivert(ii)->parentsurf)), *meshDep);
1193 else if (trivert(ii)->parentType == meshtypes::snake)
1195 SnakeSurfaceCentroid_fun(trivert[ii].coord, *(snakeDep->snakeconn.surfs.isearch(trivert(ii)->parentsurf)),
1196 snakeDep->snakeconn);
1198 else if (trivert(ii)->parentType == meshtypes::triangulation)
1200 HybridSurfaceCentroid_fun(trivert[ii].coord, *(trisurf.isearch(trivert(ii)->parentsurf)), *(meshDep),
1201 snakeDep->snakeconn);
1204 void triangulation::CalcTriVertPosDyna()
1208 for (ii = 0; ii < n; ++ii)
1210 CalcTriVertPosDyna(ii);
1213 void triangulation::CalcTriVertPosDyna(
int ii)
1215 if (trivert(ii)->parentType == meshtypes::snake)
1217 SnakeSurfaceCentroid_fun(trivert[ii].coord, *(snakeDep->snakeconn.surfs.isearch(trivert(ii)->parentsurf)),
1218 snakeDep->snakeconn);
1220 else if (trivert(ii)->parentType == meshtypes::triangulation)
1222 HybridSurfaceCentroid_fun(trivert[ii].coord, *(trisurf.isearch(trivert(ii)->parentsurf)), *(meshDep),
1223 snakeDep->snakeconn);
1226 void triangulation::SetActiveStaticTri()
1228 vector<int> subList;
1229 vector<bool> isObjDone;
1233 ni = stattri.size();
1234 isObjDone.assign(ni,
false);
1236 for (ii = 0; ii < ni; ++ii)
1240 stattri.findsiblings(stattri(ii)->KeyParent(), subList);
1241 if (trisurf.findparent(stattri(ii)->KeyParent()) == __notfound)
1243 nj = stattri(ii)->pointtype.size();
1244 for (jj = 0; jj < nj; ++jj)
1246 if (stattri(ii)->pointtype[jj] == meshtypes::mesh)
1254 "return a mesh vertex");
1256 if (snakeDep->isMeshVertIn[meshDep->verts.find(stattri(ii)->pointind[jj])])
1258 nj = subList.size();
1259 for (jj = 0; jj < nj; ++jj)
1261 acttri.push_back(stattri(subList[jj])->index);
1265 nj = subList.size();
1266 for (jj = 0; jj < nj; ++jj)
1268 isObjDone[subList[jj]] =
true;
1274 void triangulation::SetConnectivity()
1277 ni = stattri.size();
1278 for (ii = 0; ii < ni; ++ii)
1280 if (stattri(ii)->connec.celltarg.size() == 0)
1282 this->SetConnectivityStat(ii);
1286 ni = intertri.size();
1287 for (ii = 0; ii < ni; ++ii)
1290 this->SetConnectivityInter(ii);
1293 ni = dynatri.size();
1294 for (ii = 0; ii < ni; ++ii)
1296 if (dynatri(ii)->connec.celltarg.size() == 0)
1298 this->SetConnectivityDyna(ii);
1303 void triangulation::SetConnectivityInter(
int ii)
1305 int prevHash = this->intertri.isHash;
1306 this->intertri[ii].connec.celltarg = this->trisurf.isearch(this->intertri(ii)->parentsurf)->voluind;
1307 this->intertri[ii].connec.constrinfluence = {-1.0, 1.0};
1308 this->intertri.isHash = prevHash;
1310 void triangulation::SetConnectivityStat(
int ii)
1312 int prevHash = stattri.isHash;
1313 stattri[ii].connec.celltarg = meshDep->surfs.isearch(stattri(ii)->parentsurf)->voluind;
1314 stattri[ii].connec.constrinfluence = {-1.0, 1.0};
1315 stattri.isHash = prevHash;
1317 void triangulation::SetConnectivityDyna(
int ii)
1323 int voluStore, jj, prevHash;
1325 voluStore = snakeDep->snaxsurfs.isearch(dynatri(ii)->parentsurf)->voluind;
1327 jj = (snakeDep->snakeconn.surfs.isearch(dynatri(ii)->parentsurf)->voluind[jj] == 0);
1329 prevHash = dynatri.isHash;
1330 dynatri[ii].connec.celltarg.clear();
1331 dynatri[ii].connec.constrinfluence.clear();
1332 dynatri[ii].connec.celltarg.push_back(voluStore);
1333 dynatri[ii].connec.constrinfluence.push_back(
float(-1 + 2 * jj));
1334 dynatri.isHash = prevHash;
1343 this->stattri.clear();
1344 this->dynatri.clear();
1345 this->intertri.clear();
1346 this->trivert.clear();
1347 this->trisurf.clear();
1348 this->acttri.clear();
1350 #pragma GCC diagnostic push
1351 #pragma GCC diagnostic ignored "-Wunused-parameter"
1352 void triangle::disp()
const
1355 void triangle::ChangeIndices(
int nVert,
int nEdge,
int nSurf,
int nVolu)
1358 void triangle::read(FILE *fid)
1361 void triangle::write(FILE *fid)
const
1365 void trianglepoint::disp()
const
1368 void trianglepoint::ChangeIndices(
int nVert,
int nEdge,
int nSurf,
int nVolu)
1371 void trianglepoint::ChangeIndicesSnakeMesh(
int nVert,
int nEdge,
int nSurf,
int nVolu)
1374 void trianglepoint::read(FILE *fid)
1377 void trianglepoint::write(FILE *fid)
const
1381 void trianglesurf::disp()
const
1383 cout <<
"trianglesurf " << index <<
" parent " << parentsurfmesh << endl;
1384 cout <<
"indvert: ";
1385 DisplayVector(indvert);
1387 cout <<
"typevert: ";
1388 DisplayVector(typevert);
1391 void trianglesurf::ChangeIndices(
int nVert,
int nEdge,
int nSurf,
int nVolu)
1394 void trianglesurf::ChangeIndicesSnakeMesh(
int nVert,
int nEdge,
int nSurf,
int nVolu)
1397 void trianglesurf::read(FILE *fid)
1400 void trianglesurf::write(FILE *fid)
const
1403 #pragma GCC diagnostic pop
Provides the infrastructure for calculation of the RSVS equations.
Performs Volume and Area calculations for the RSVS process.
Provide std::vector container with hashed index mapping.
Class containing the information needed to trim objects from a mesh.
Class to handle the RSVS calculation.
void PrepTriangulationCalc(const triangulation &triRSVS)
Groups actions needed before the calculation of triangular quantities.
HashedMap< int, int, int > constrMap
maps snakemesh() volu onto constr
int numConstr() const
Getter for the number of constraints.
Handles the use and norm of a vector for which the norm and the unit value might be needed.
Class for an edge object in a mesh.
Class for surface object in a mesh.
void clear()
Clears the contents of the triangulation making sure we can restart the process.
Class for a vertex in a mesh.
Provides all the mesh tools used for the generation of 3D grids and geometries.
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 the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.