Skip to content

Commit

Permalink
fix data layout bug for volume grids
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Dec 24, 2023
1 parent 6d10766 commit 9f8a0a5
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions include/polyscope/volume_grid.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ inline glm::vec3 VolumeGrid::getBoundMin() const { return boundMin; }
inline glm::vec3 VolumeGrid::getBoundMax() const { return boundMax; }

inline uint64_t VolumeGrid::flattenNodeIndex(glm::uvec3 inds) const {
return static_cast<uint64_t>(gridNodeDim[1]) * gridNodeDim[2] * inds.x + gridNodeDim[2] * inds.y + inds.z;
return static_cast<uint64_t>(gridNodeDim[0]) * gridNodeDim[1] * inds.z + gridNodeDim[0] * inds.y + inds.x;
}

inline glm::uvec3 VolumeGrid::unflattenNodeIndex(uint64_t i) const {
uint64_t nYZ = gridNodeDim[1] * gridNodeDim[2];
uint64_t iX = i / nYZ;
i -= iX * nYZ;
uint64_t nZ = gridNodeDim[2];
uint64_t iY = i / nZ;
i -= iY * nZ;
uint64_t iZ = i;
uint64_t nXY = gridNodeDim[0] * gridNodeDim[1];
uint64_t iZ = i / nXY;
i -= iZ * nXY;
uint64_t nX = gridNodeDim[0];
uint64_t iY = i / nX;
i -= iY * nX;
uint64_t iX = i;
return glm::uvec3{static_cast<uint32_t>(iX), static_cast<uint32_t>(iY), static_cast<uint32_t>(iZ)};
}

Expand All @@ -45,17 +45,17 @@ inline glm::vec3 VolumeGrid::positionOfNodeIndex(glm::uvec3 inds) const {
}

inline uint64_t VolumeGrid::flattenCellIndex(glm::uvec3 inds) const {
return static_cast<uint64_t>(gridCellDim[1]) * gridCellDim[2] * inds.x + gridCellDim[2] * inds.y + inds.z;
return static_cast<uint64_t>(gridCellDim[0]) * gridCellDim[1] * inds.z + gridCellDim[0] * inds.y + inds.x;
}

inline glm::uvec3 VolumeGrid::unflattenCellIndex(uint64_t i) const {
uint64_t nYZ = gridCellDim[1] * gridCellDim[2];
uint64_t iX = i / nYZ;
i -= iX * nYZ;
uint64_t nZ = gridCellDim[2];
uint64_t iY = i / nZ;
i -= iY * nZ;
uint64_t iZ = i;
uint64_t nXY = gridCellDim[0] * gridCellDim[1];
uint64_t iZ = i / nXY;
i -= iZ * nXY;
uint64_t nX = gridCellDim[0];
uint64_t iY = i / nX;
i -= iY * nX;
uint64_t iX = i;
return glm::uvec3{static_cast<uint32_t>(iX), static_cast<uint32_t>(iY), static_cast<uint32_t>(iZ)};
}

Expand Down

0 comments on commit 9f8a0a5

Please sign in to comment.