Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2D position computation #1047

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
32 changes: 16 additions & 16 deletions core/base/implicitTriangulation/ImplicitTriangulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,27 +1747,27 @@ int ImplicitTriangulationCRTP<Derived>::getTriangleVertexInternal(
switch(localVertexId) {
break;
case 0:
vertexId = p[0] / 2 + p[1] * vshift_[0];
vertexId = p[0] + p[1] * vshift_[0];
break;
case 1:
vertexId = p[0] / 2 + p[1] * vshift_[0] + 1;
vertexId = p[0] + p[1] * vshift_[0] + 1;
break;
case 2:
vertexId = p[0] / 2 + p[1] * vshift_[0] + vshift_[0];
vertexId = p[0] + p[1] * vshift_[0] + vshift_[0];
break;
}
break;
case TrianglePosition::BOTTOM_2D:
switch(localVertexId) {
break;
case 0:
vertexId = p[0] / 2 + p[1] * vshift_[0] + 1;
vertexId = p[0] + p[1] * vshift_[0] + 1;
break;
case 1:
vertexId = p[0] / 2 + p[1] * vshift_[0] + vshift_[0] + 1;
vertexId = p[0] + p[1] * vshift_[0] + vshift_[0] + 1;
break;
case 2:
vertexId = p[0] / 2 + p[1] * vshift_[0] + vshift_[0];
vertexId = p[0] + p[1] * vshift_[0] + vshift_[0];
break;
}
}
Expand Down Expand Up @@ -1820,27 +1820,27 @@ int ImplicitTriangulationCRTP<Derived>::getTriangleEdgeInternal(
switch(localEdgeId) {
break;
case 0:
edgeId = p[0] / 2 + p[1] * eshift_[0];
edgeId = p[0] + p[1] * eshift_[0];
break;
case 1:
edgeId = esetshift_[0] + p[0] / 2 + p[1] * eshift_[2];
edgeId = esetshift_[0] + p[0] + p[1] * eshift_[2];
break;
case 2:
edgeId = esetshift_[1] + p[0] / 2 + p[1] * eshift_[4];
edgeId = esetshift_[1] + p[0] + p[1] * eshift_[4];
break;
}
break;
case TrianglePosition::BOTTOM_2D:
switch(localEdgeId) {
break;
case 0:
edgeId = p[0] / 2 + (p[1] + 1) * eshift_[0];
edgeId = p[0] + (p[1] + 1) * eshift_[0];
break;
case 1:
edgeId = esetshift_[0] + (p[0] + 1) / 2 + p[1] * eshift_[2];
edgeId = esetshift_[0] + (p[0] + 1) + p[1] * eshift_[2];
break;
case 2:
edgeId = esetshift_[1] + p[0] / 2 + p[1] * eshift_[4];
edgeId = esetshift_[1] + p[0] + p[1] * eshift_[4];
break;
}
}
Expand Down Expand Up @@ -2056,9 +2056,9 @@ SimplexId ImplicitTriangulationCRTP<Derived>::getTriangleNeighborNumber(
const SimplexId id = triangleId % 2;

if(id) {
if(p[0] / 2 == nbvoxels_[Di_] - 1 and p[1] == nbvoxels_[Dj_] - 1)
if(p[0] == nbvoxels_[Di_] - 1 and p[1] == nbvoxels_[Dj_] - 1)
return 1;
else if(p[0] / 2 == nbvoxels_[Di_] - 1 or p[1] == nbvoxels_[Dj_] - 1)
else if(p[0] == nbvoxels_[Di_] - 1 or p[1] == nbvoxels_[Dj_] - 1)
return 2;
else
return 3;
Expand Down Expand Up @@ -2093,9 +2093,9 @@ int ImplicitTriangulationCRTP<Derived>::getTriangleNeighbor(
const SimplexId id = triangleId % 2;

if(id) {
if(p[0] / 2 == nbvoxels_[Di_] - 1 and p[1] == nbvoxels_[Dj_] - 1)
if(p[0] == nbvoxels_[Di_] - 1 and p[1] == nbvoxels_[Dj_] - 1)
neighborId = triangleId - 1;
else if(p[0] / 2 == nbvoxels_[Di_] - 1) {
else if(p[0] == nbvoxels_[Di_] - 1) {
switch(localNeighborId) {
case 0:
neighborId = triangleId - 1;
Expand Down
2 changes: 1 addition & 1 deletion core/base/implicitTriangulation/ImplicitTriangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ inline void ttk::ImplicitTriangulation::edgeToPosition2d(const SimplexId edge,
inline void
ttk::ImplicitTriangulation::triangleToPosition2d(const SimplexId triangle,
SimplexId p[2]) const {
p[0] = triangle % tshift_[0];
p[0] = triangle % tshift_[0] / 2;
p[1] = triangle / tshift_[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleVertexInternal(

vertexId = -1;
const auto &p = this->underlying().getTriangleCoords(triangleId);
const SimplexId wrapXRight = (p[0] / 2 == nbvoxels_[Di_]) ? -wrap_[0] : 0;
const SimplexId wrapXRight = (p[0] == nbvoxels_[Di_]) ? -wrap_[0] : 0;
const SimplexId wrapYBottom = (p[1] == nbvoxels_[Dj_]) ? -wrap_[1] : 0;

switch(this->underlying().getTrianglePosition(triangleId)) {
Expand All @@ -1283,21 +1283,21 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleVertexInternal(
break;
case TrianglePosition::TOP_2D:
if(localVertexId == 0) {
vertexId = p[0] / 2 + p[1] * vshift_[0];
vertexId = p[0] + p[1] * vshift_[0];
} else if(localVertexId == 1) {
vertexId = p[0] / 2 + p[1] * vshift_[0] + 1 + wrapXRight;
vertexId = p[0] + p[1] * vshift_[0] + 1 + wrapXRight;
} else if(localVertexId == 2) {
vertexId = p[0] / 2 + p[1] * vshift_[0] + vshift_[0] + wrapYBottom;
vertexId = p[0] + p[1] * vshift_[0] + vshift_[0] + wrapYBottom;
}
break;
case TrianglePosition::BOTTOM_2D:
if(localVertexId == 0) {
vertexId = p[0] / 2 + p[1] * vshift_[0] + 1 + wrapXRight;
vertexId = p[0] + p[1] * vshift_[0] + 1 + wrapXRight;
} else if(localVertexId == 1) {
vertexId = p[0] / 2 + p[1] * vshift_[0] + vshift_[0] + 1 + wrapXRight
vertexId = p[0] + p[1] * vshift_[0] + vshift_[0] + 1 + wrapXRight
+ wrapYBottom;
} else if(localVertexId == 2) {
vertexId = p[0] / 2 + p[1] * vshift_[0] + vshift_[0] + wrapYBottom;
vertexId = p[0] + p[1] * vshift_[0] + vshift_[0] + wrapYBottom;
}
break;
default:
Expand All @@ -1321,7 +1321,7 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleEdgeInternal(

edgeId = -1;
const auto &p = this->underlying().getTriangleCoords(triangleId);
const SimplexId wrapXRight = (p[0] / 2 == nbvoxels_[Di_]) ? -wrap_[0] : 0;
const SimplexId wrapXRight = (p[0] == nbvoxels_[Di_]) ? -wrap_[0] : 0;
const SimplexId wrapYBottom = (p[1] == nbvoxels_[Dj_]) ? -wrap_[1] : 0;
const SimplexId id = triangleId % 2;

Expand Down Expand Up @@ -1352,21 +1352,20 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleEdgeInternal(
break;
case TrianglePosition::TOP_2D:
if(localEdgeId == 0) {
edgeId = p[0] / 2 + p[1] * eshift_[0];
edgeId = p[0] + p[1] * eshift_[0];
} else if(localEdgeId == 1) {
edgeId = esetshift_[0] + p[0] / 2 + p[1] * eshift_[2];
edgeId = esetshift_[0] + p[0] + p[1] * eshift_[2];
} else if(localEdgeId == 2) {
edgeId = esetshift_[1] + p[0] / 2 + p[1] * eshift_[4];
edgeId = esetshift_[1] + p[0] + p[1] * eshift_[4];
}
break;
case TrianglePosition::BOTTOM_2D:
if(localEdgeId == 0) {
edgeId = p[0] / 2 + (p[1] + 1) * eshift_[0] + wrapYBottom;
edgeId = p[0] + (p[1] + 1) * eshift_[0] + wrapYBottom;
} else if(localEdgeId == 1) {
edgeId
= esetshift_[0] + (p[0] + 1) / 2 + p[1] * eshift_[2] + wrapXRight;
edgeId = esetshift_[0] + (p[0] + 1) + p[1] * eshift_[2] + wrapXRight;
} else if(localEdgeId == 2) {
edgeId = esetshift_[1] + p[0] / 2 + p[1] * eshift_[4];
edgeId = esetshift_[1] + p[0] + p[1] * eshift_[4];
}
break;
default:
Expand Down Expand Up @@ -1593,7 +1592,7 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleNeighbor(
switch(this->underlying().getTrianglePosition(triangleId)) {
case TrianglePosition::BOTTOM_2D:

if(p[0] / 2 == nbvoxels_[Di_] and p[1] == nbvoxels_[Dj_]) {
if(p[0] == nbvoxels_[Di_] and p[1] == nbvoxels_[Dj_]) {
if(localNeighborId == 0) {
neighborId = triangleId - 1;
} else if(localNeighborId == 1) {
Expand All @@ -1602,7 +1601,7 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleNeighbor(
neighborId = triangleId + tshift_[0] - 1 - wrap_[1] * 2;
}

} else if(p[0] / 2 == nbvoxels_[Di_]) {
} else if(p[0] == nbvoxels_[Di_]) {
if(localNeighborId == 0) {
neighborId = triangleId - 1;
} else if(localNeighborId == 1) {
Expand Down Expand Up @@ -1633,7 +1632,7 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleNeighbor(

case TrianglePosition::TOP_2D:

if(p[0] / 2 == 0 and p[1] == 0) {
if(p[0] == 0 and p[1] == 0) {
if(localNeighborId == 0) {
neighborId = triangleId + 1;
} else if(localNeighborId == 1) {
Expand All @@ -1642,7 +1641,7 @@ int PeriodicImplicitTriangulationCRTP<Derived>::getTriangleNeighbor(
neighborId = triangleId - tshift_[0] + 1 + wrap_[1] * 2;
}

} else if(p[0] / 2 == 0) {
} else if(p[0] == 0) {
if(localNeighborId == 0) {
neighborId = triangleId + 1;
} else if(localNeighborId == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ inline void ttk::PeriodicImplicitTriangulation::edgeToPosition2d(

inline void ttk::PeriodicImplicitTriangulation::triangleToPosition2d(
const SimplexId triangle, SimplexId p[2]) const {
p[0] = triangle % tshift_[0];
p[0] = triangle % tshift_[0] / 2;
p[1] = triangle / tshift_[0];
}

Expand Down
Loading