Commit 770872d1 authored by David Flynn's avatar David Flynn
Browse files

general: always use int64_t to represent morton codes

A 64 bit integer can represent a three dimensional 21 bit position with
one spare bit.  In order te allow the computation of abs(a-b), a signed
representation should be used, making use of the full 64 bits.
parent d14f2bdd
......@@ -430,7 +430,7 @@ AttributeDecoder::decodeReflectancesRaht(
sort(packedVoxel.begin(), packedVoxel.end());
// Morton codes
uint64_t* mortonCode = new uint64_t[voxelCount];
int64_t* mortonCode = new int64_t[voxelCount];
for (int n = 0; n < voxelCount; n++) {
mortonCode[n] = packedVoxel[n].mortonCode;
}
......@@ -495,7 +495,7 @@ AttributeDecoder::decodeColorsRaht(
sort(packedVoxel.begin(), packedVoxel.end());
// Morton codes
uint64_t* mortonCode = new uint64_t[voxelCount];
int64_t* mortonCode = new int64_t[voxelCount];
for (int n = 0; n < voxelCount; n++) {
mortonCode[n] = packedVoxel[n].mortonCode;
}
......
......@@ -781,7 +781,7 @@ AttributeEncoder::encodeReflectancesTransformRaht(
sort(packedVoxel.begin(), packedVoxel.end());
// Allocate arrays.
uint64_t* mortonCode = new uint64_t[voxelCount];
int64_t* mortonCode = new int64_t[voxelCount];
const int attribCount = 1;
FixedPoint* attributes = new FixedPoint[attribCount * voxelCount];
int* integerizedAttributes = new int[attribCount * voxelCount];
......@@ -865,7 +865,7 @@ AttributeEncoder::encodeColorsTransformRaht(
sort(packedVoxel.begin(), packedVoxel.end());
// Allocate arrays.
uint64_t* mortonCode = new uint64_t[voxelCount];
int64_t* mortonCode = new int64_t[voxelCount];
const int attribCount = 3;
FixedPoint* attributes = new FixedPoint[attribCount * voxelCount];
int* integerizedAttributes = new int[attribCount * voxelCount];
......
......@@ -359,11 +359,11 @@ PCCApproximatelyEqual(
//---------------------------------------------------------------------------
inline uint64_t
inline int64_t
mortonAddr(const int32_t x, const int32_t y, const int32_t z)
{
assert(x >= 0 && y >= 0 && z >= 0);
uint64_t answer = kMortonCode256X[(x >> 16) & 0xFF]
int64_t answer = kMortonCode256X[(x >> 16) & 0xFF]
| kMortonCode256Y[(y >> 16) & 0xFF] | kMortonCode256Z[(z >> 16) & 0xFF];
answer = answer << 24 | kMortonCode256X[(x >> 8) & 0xFF]
| kMortonCode256Y[(y >> 8) & 0xFF] | kMortonCode256Z[(z >> 8) & 0xFF];
......@@ -376,7 +376,7 @@ mortonAddr(const int32_t x, const int32_t y, const int32_t z)
// Convert a vector position (divided by 2^depth) to morton order address.
template<typename T>
uint64_t
int64_t
mortonAddr(const Vec3<T>& vec, int depth)
{
int x = int(vec.x()) >> depth;
......
......@@ -179,10 +179,10 @@ uint32_t isqrt(uint64_t x);
//---------------------------------------------------------------------------
// Decrement the @axis-th dimension of 3D morton code @x.
//
inline uint64_t
morton3dAxisDec(uint64_t val, int axis)
inline int64_t
morton3dAxisDec(int64_t val, int axis)
{
const uint64_t mask0 = 0x9249249249249249llu << axis;
const int64_t mask0 = 0x9249249249249249llu << axis;
return ((val & mask0) - 1 & mask0) | (val & ~mask0);
}
......
......@@ -72,7 +72,7 @@ struct WeightWithIndex {
//---------------------------------------------------------------------------
struct MortonCodeWithIndex {
uint64_t mortonCode;
int64_t mortonCode;
int32_t index;
bool operator<(const MortonCodeWithIndex& rhs) const
{
......@@ -540,7 +540,7 @@ computeNearestNeighbors(
for (int32_t i = startIndex, j = 0; i < endIndex; ++i) {
const int32_t index = indexes[i];
const uint64_t mortonCode = packedVoxel[index].mortonCode;
const int64_t mortonCode = packedVoxel[index].mortonCode;
const int32_t pointIndex = packedVoxel[index].index;
const auto& point = pointCloud[pointIndex];
indexes[i] = pointIndex;
......
......@@ -138,7 +138,7 @@ rahtFixedPointInverseRotation(
void
regionAdaptiveHierarchicalTransform(
FixedPoint quantStepSizeLuma,
uint64_t* mortonCode,
int64_t* mortonCode,
FixedPoint* attributes,
uint64_t* weight,
int* binaryLayer,
......@@ -153,7 +153,7 @@ regionAdaptiveHierarchicalTransform(
FixedPoint* attributesTransformed = new FixedPoint[voxelCount * attribCount];
uint64_t* weightTransformed = new uint64_t[voxelCount];
uint64_t* mortonCodeTransformed = new uint64_t[voxelCount];
int64_t* mortonCodeTransformed = new int64_t[voxelCount];
d = 0;
while (N > 1 || d % 2) {
......@@ -239,7 +239,7 @@ regionAdaptiveHierarchicalTransform(
void
regionAdaptiveHierarchicalInverseTransform(
FixedPoint quantStepSizeLuma,
uint64_t* mortonCode,
int64_t* mortonCode,
FixedPoint* attributes,
uint64_t* weight,
const int attribCount,
......@@ -253,21 +253,21 @@ regionAdaptiveHierarchicalInverseTransform(
FixedPoint* attributesTransformed = new FixedPoint[voxelCount * attribCount];
uint64_t* weightTransformed = new uint64_t[voxelCount];
uint64_t* mortonCodeTransformed = new uint64_t[voxelCount];
int64_t* mortonCodeTransformed = new int64_t[voxelCount];
uint64_t** mortonCodeBuffer;
int64_t** mortonCodeBuffer;
uint64_t** weightBuffer;
size_t* M_buffer;
{
size_t depth = 0;
uint64_t maxMortonCode = mortonCode[voxelCount - 1];
int64_t maxMortonCode = mortonCode[voxelCount - 1];
while (maxMortonCode--) {
depth++;
maxMortonCode >>= 1;
}
mortonCodeBuffer = new uint64_t*[depth + 1];
mortonCodeBuffer = new int64_t*[depth + 1];
weightBuffer = new uint64_t*[depth + 1];
M_buffer = new size_t[depth + 1];
}
......@@ -295,7 +295,7 @@ regionAdaptiveHierarchicalInverseTransform(
// Re-obtain weights at the decoder by partially executing the encoder
d = 0;
while (N > 1) {
uint64_t* _mortonCode = new uint64_t[M];
int64_t* _mortonCode = new int64_t[M];
uint64_t* _weight = new uint64_t[M];
M_buffer[d] = M;
......
......@@ -43,7 +43,7 @@ namespace pcc {
void regionAdaptiveHierarchicalTransform(
FixedPoint quantStepSizeLuma,
uint64_t* mortonCode,
int64_t* mortonCode,
FixedPoint* attributes,
uint64_t* weight,
int* binaryLayer,
......@@ -53,7 +53,7 @@ void regionAdaptiveHierarchicalTransform(
void regionAdaptiveHierarchicalInverseTransform(
FixedPoint quantStepSizeLuma,
uint64_t* mortonCode,
int64_t* mortonCode,
FixedPoint* attributes,
uint64_t* weight,
const int attribCount,
......
......@@ -122,7 +122,7 @@ updateGeometryNeighState(
uint8_t neighPattern,
uint8_t parentOccupancy)
{
uint64_t midx;
int64_t midx;
if (!siblingRestriction) {
midx = child.mortonIdx = mortonAddr(child.pos, childSizeLog2);
}
......@@ -179,7 +179,7 @@ updateGeometryNeighState(
auto found = std::lower_bound(
posStart, posEnd, mortonIdxNeigh,
[](const PCCOctree3Node& node, uint64_t mortonIdx) {
[](const PCCOctree3Node& node, int64_t mortonIdx) {
return node.mortonIdx < mortonIdx;
});
......
......@@ -61,7 +61,7 @@ struct PCCOctree3Node {
uint32_t end;
// address of the current node in 3D morton order.
uint64_t mortonIdx;
int64_t mortonIdx;
// pattern denoting occupied neighbour nodes.
// 32 8 (y)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment