Commit 46efadca authored by David Flynn's avatar David Flynn
Browse files

attr: refactor quantisation state and detail into Quantizer class

In order to simplify the introduction of quantisation using the
multiplicative inverse, the existing quantiser state is refactored
into a Quantizer class that represents the current step size.
parent b40f9396
...@@ -181,7 +181,7 @@ AttributeDecoder::decode( ...@@ -181,7 +181,7 @@ AttributeDecoder::decode(
{ {
int abhSize; int abhSize;
AttributeBrickHeader abh = parseAbh(attr_aps, payload, &abhSize); AttributeBrickHeader abh = parseAbh(attr_aps, payload, &abhSize);
Quantizers qstep = deriveQuantSteps(attr_aps, abh); Quantizers quant = deriveQuantizers(attr_aps, abh);
PCCResidualsDecoder decoder; PCCResidualsDecoder decoder;
decoder.start(payload.data() + abhSize, payload.size() - abhSize); decoder.start(payload.data() + abhSize, payload.size() - abhSize);
...@@ -189,29 +189,29 @@ AttributeDecoder::decode( ...@@ -189,29 +189,29 @@ AttributeDecoder::decode(
if (attr_desc.attr_num_dimensions == 1) { if (attr_desc.attr_num_dimensions == 1) {
switch (attr_aps.attr_encoding) { switch (attr_aps.attr_encoding) {
case AttributeEncoding::kRAHTransform: case AttributeEncoding::kRAHTransform:
decodeReflectancesRaht(attr_desc, attr_aps, qstep, decoder, pointCloud); decodeReflectancesRaht(attr_desc, attr_aps, quant, decoder, pointCloud);
break; break;
case AttributeEncoding::kPredictingTransform: case AttributeEncoding::kPredictingTransform:
decodeReflectancesPred(attr_desc, attr_aps, qstep, decoder, pointCloud); decodeReflectancesPred(attr_desc, attr_aps, quant, decoder, pointCloud);
break; break;
case AttributeEncoding::kLiftingTransform: case AttributeEncoding::kLiftingTransform:
decodeReflectancesLift(attr_desc, attr_aps, qstep, decoder, pointCloud); decodeReflectancesLift(attr_desc, attr_aps, quant, decoder, pointCloud);
break; break;
} }
} else if (attr_desc.attr_num_dimensions == 3) { } else if (attr_desc.attr_num_dimensions == 3) {
switch (attr_aps.attr_encoding) { switch (attr_aps.attr_encoding) {
case AttributeEncoding::kRAHTransform: case AttributeEncoding::kRAHTransform:
decodeColorsRaht(attr_desc, attr_aps, qstep, decoder, pointCloud); decodeColorsRaht(attr_desc, attr_aps, quant, decoder, pointCloud);
break; break;
case AttributeEncoding::kPredictingTransform: case AttributeEncoding::kPredictingTransform:
decodeColorsPred(attr_desc, attr_aps, qstep, decoder, pointCloud); decodeColorsPred(attr_desc, attr_aps, quant, decoder, pointCloud);
break; break;
case AttributeEncoding::kLiftingTransform: case AttributeEncoding::kLiftingTransform:
decodeColorsLift(attr_desc, attr_aps, qstep, decoder, pointCloud); decodeColorsLift(attr_desc, attr_aps, quant, decoder, pointCloud);
break; break;
} }
} else { } else {
...@@ -263,7 +263,7 @@ void ...@@ -263,7 +263,7 @@ void
AttributeDecoder::decodeReflectancesPred( AttributeDecoder::decodeReflectancesPred(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud) PCCPointSet3& pointCloud)
{ {
...@@ -283,7 +283,6 @@ AttributeDecoder::decodeReflectancesPred( ...@@ -283,7 +283,6 @@ AttributeDecoder::decodeReflectancesPred(
for (size_t predictorIndex = 0; predictorIndex < pointCount; for (size_t predictorIndex = 0; predictorIndex < pointCount;
++predictorIndex) { ++predictorIndex) {
auto& predictor = predictors[predictorIndex]; auto& predictor = predictors[predictorIndex];
const int64_t qs = qstep[0];
computeReflectancePredictionWeights( computeReflectancePredictionWeights(
aps, pointCloud, indexesLOD, predictor, decoder); aps, pointCloud, indexesLOD, predictor, decoder);
const uint32_t pointIndex = indexesLOD[predictorIndex]; const uint32_t pointIndex = indexesLOD[predictorIndex];
...@@ -298,8 +297,7 @@ AttributeDecoder::decodeReflectancesPred( ...@@ -298,8 +297,7 @@ AttributeDecoder::decodeReflectancesPred(
const int64_t quantPredAttValue = const int64_t quantPredAttValue =
predictor.predictReflectance(pointCloud, indexesLOD); predictor.predictReflectance(pointCloud, indexesLOD);
const int64_t delta = divExp2RoundHalfUp( const int64_t delta = divExp2RoundHalfUp(
PCCInverseQuantization(UIntToInt(attValue0), qs), quant[0].scale(UIntToInt(attValue0)), kFixedPointAttributeShift);
kFixedPointAttributeShift);
const int64_t reconstructedQuantAttValue = quantPredAttValue + delta; const int64_t reconstructedQuantAttValue = quantPredAttValue + delta;
reflectance = uint16_t( reflectance = uint16_t(
PCCClip(reconstructedQuantAttValue, int64_t(0), maxReflectance)); PCCClip(reconstructedQuantAttValue, int64_t(0), maxReflectance));
...@@ -350,7 +348,7 @@ void ...@@ -350,7 +348,7 @@ void
AttributeDecoder::decodeColorsPred( AttributeDecoder::decodeColorsPred(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud) PCCPointSet3& pointCloud)
{ {
...@@ -370,8 +368,6 @@ AttributeDecoder::decodeColorsPred( ...@@ -370,8 +368,6 @@ AttributeDecoder::decodeColorsPred(
for (size_t predictorIndex = 0; predictorIndex < pointCount; for (size_t predictorIndex = 0; predictorIndex < pointCount;
++predictorIndex) { ++predictorIndex) {
auto& predictor = predictors[predictorIndex]; auto& predictor = predictors[predictorIndex];
const int64_t qs = qstep[0];
const int64_t qs2 = qstep[1];
computeColorPredictionWeights( computeColorPredictionWeights(
aps, pointCloud, indexesLOD, predictor, decoder); aps, pointCloud, indexesLOD, predictor, decoder);
if (zero_cnt > 0) { if (zero_cnt > 0) {
...@@ -387,8 +383,7 @@ AttributeDecoder::decodeColorsPred( ...@@ -387,8 +383,7 @@ AttributeDecoder::decodeColorsPred(
predictor.predictColor(pointCloud, indexesLOD); predictor.predictColor(pointCloud, indexesLOD);
const int64_t quantPredAttValue = predictedColor[0]; const int64_t quantPredAttValue = predictedColor[0];
const int64_t delta = divExp2RoundHalfUp( const int64_t delta = divExp2RoundHalfUp(
PCCInverseQuantization(UIntToInt(values[0]), qs), quant[0].scale(UIntToInt(values[0])), kFixedPointAttributeShift);
kFixedPointAttributeShift);
const int64_t reconstructedQuantAttValue = quantPredAttValue + delta; const int64_t reconstructedQuantAttValue = quantPredAttValue + delta;
int64_t clipMax = (1 << desc.attr_bitdepth) - 1; int64_t clipMax = (1 << desc.attr_bitdepth) - 1;
color[0] = color[0] =
...@@ -396,8 +391,7 @@ AttributeDecoder::decodeColorsPred( ...@@ -396,8 +391,7 @@ AttributeDecoder::decodeColorsPred(
for (size_t k = 1; k < 3; ++k) { for (size_t k = 1; k < 3; ++k) {
const int64_t quantPredAttValue = predictedColor[k]; const int64_t quantPredAttValue = predictedColor[k];
const int64_t delta = divExp2RoundHalfUp( const int64_t delta = divExp2RoundHalfUp(
PCCInverseQuantization(UIntToInt(values[k]), qs2), quant[1].scale(UIntToInt(values[k])), kFixedPointAttributeShift);
kFixedPointAttributeShift);
const int64_t reconstructedQuantAttValue = quantPredAttValue + delta; const int64_t reconstructedQuantAttValue = quantPredAttValue + delta;
color[k] = color[k] =
uint8_t(PCCClip(reconstructedQuantAttValue, int64_t(0), clipMax)); uint8_t(PCCClip(reconstructedQuantAttValue, int64_t(0), clipMax));
...@@ -411,7 +405,7 @@ void ...@@ -411,7 +405,7 @@ void
AttributeDecoder::decodeReflectancesRaht( AttributeDecoder::decodeReflectancesRaht(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud) PCCPointSet3& pointCloud)
{ {
...@@ -447,7 +441,7 @@ AttributeDecoder::decodeReflectancesRaht( ...@@ -447,7 +441,7 @@ AttributeDecoder::decodeReflectancesRaht(
int* attributes = new int[attribCount * voxelCount]; int* attributes = new int[attribCount * voxelCount];
regionAdaptiveHierarchicalInverseTransform( regionAdaptiveHierarchicalInverseTransform(
aps.raht_prediction_enabled_flag, qstep, mortonCode, attributes, aps.raht_prediction_enabled_flag, quant, mortonCode, attributes,
attribCount, voxelCount, coefficients); attribCount, voxelCount, coefficients);
const int64_t maxReflectance = (1 << desc.attr_bitdepth) - 1; const int64_t maxReflectance = (1 << desc.attr_bitdepth) - 1;
...@@ -471,7 +465,7 @@ void ...@@ -471,7 +465,7 @@ void
AttributeDecoder::decodeColorsRaht( AttributeDecoder::decodeColorsRaht(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud) PCCPointSet3& pointCloud)
{ {
...@@ -511,7 +505,7 @@ AttributeDecoder::decodeColorsRaht( ...@@ -511,7 +505,7 @@ AttributeDecoder::decodeColorsRaht(
int* attributes = new int[attribCount * voxelCount]; int* attributes = new int[attribCount * voxelCount];
regionAdaptiveHierarchicalInverseTransform( regionAdaptiveHierarchicalInverseTransform(
aps.raht_prediction_enabled_flag, qstep, mortonCode, attributes, aps.raht_prediction_enabled_flag, quant, mortonCode, attributes,
attribCount, voxelCount, coefficients); attribCount, voxelCount, coefficients);
const int clipMax = (1 << desc.attr_bitdepth) - 1; const int clipMax = (1 << desc.attr_bitdepth) - 1;
...@@ -538,7 +532,7 @@ void ...@@ -538,7 +532,7 @@ void
AttributeDecoder::decodeColorsLift( AttributeDecoder::decodeColorsLift(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud) PCCPointSet3& pointCloud)
{ {
...@@ -574,17 +568,15 @@ AttributeDecoder::decodeColorsLift( ...@@ -574,17 +568,15 @@ AttributeDecoder::decodeColorsLift(
decoder.decode(values); decoder.decode(values);
zero_cnt = decoder.decodeZeroCnt(pointCount); zero_cnt = decoder.decodeZeroCnt(pointCount);
} }
const int64_t qs = qstep[0] << (kFixedPointWeightShift / 2);
const int64_t qs2 = qstep[1] << (kFixedPointWeightShift / 2);
// + kFixedPointAttributeShift ???
const int64_t quantWeight = weights[predictorIndex]; const int64_t quantWeight = weights[predictorIndex];
auto& color = colors[predictorIndex]; auto& color = colors[predictorIndex];
const int64_t delta = UIntToInt(values[0]); const int64_t delta = UIntToInt(values[0]);
const int64_t reconstructedDelta = PCCInverseQuantization(delta, qs); const int64_t reconstructedDelta = quant[0].scale(delta);
color[0] = reconstructedDelta / quantWeight; color[0] = reconstructedDelta / quantWeight;
for (size_t d = 1; d < 3; ++d) { for (size_t d = 1; d < 3; ++d) {
const int64_t delta = UIntToInt(values[d]); const int64_t delta = UIntToInt(values[d]);
const int64_t reconstructedDelta = PCCInverseQuantization(delta, qs2); const int64_t reconstructedDelta = quant[1].scale(delta);
color[d] = reconstructedDelta / quantWeight; color[d] = reconstructedDelta / quantWeight;
} }
} }
...@@ -615,7 +607,7 @@ void ...@@ -615,7 +607,7 @@ void
AttributeDecoder::decodeReflectancesLift( AttributeDecoder::decodeReflectancesLift(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud) PCCPointSet3& pointCloud)
{ {
...@@ -652,11 +644,10 @@ AttributeDecoder::decodeReflectancesLift( ...@@ -652,11 +644,10 @@ AttributeDecoder::decodeReflectancesLift(
detail = decoder.decode(); detail = decoder.decode();
zero_cnt = decoder.decodeZeroCnt(pointCount); zero_cnt = decoder.decodeZeroCnt(pointCount);
} }
const int64_t qs = qstep[0] << (kFixedPointWeightShift / 2);
const int64_t quantWeight = weights[predictorIndex]; const int64_t quantWeight = weights[predictorIndex];
auto& reflectance = reflectances[predictorIndex]; auto& reflectance = reflectances[predictorIndex];
const int64_t delta = UIntToInt(detail); const int64_t delta = UIntToInt(detail);
const int64_t reconstructedDelta = PCCInverseQuantization(delta, qs); const int64_t reconstructedDelta = quant[0].scale(delta);
reflectance = reconstructedDelta / quantWeight; reflectance = reconstructedDelta / quantWeight;
} }
......
...@@ -64,42 +64,42 @@ protected: ...@@ -64,42 +64,42 @@ protected:
void decodeReflectancesLift( void decodeReflectancesLift(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud); PCCPointSet3& pointCloud);
void decodeColorsLift( void decodeColorsLift(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud); PCCPointSet3& pointCloud);
void decodeReflectancesPred( void decodeReflectancesPred(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud); PCCPointSet3& pointCloud);
void decodeColorsPred( void decodeColorsPred(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud); PCCPointSet3& pointCloud);
void decodeReflectancesRaht( void decodeReflectancesRaht(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud); PCCPointSet3& pointCloud);
void decodeColorsRaht( void decodeColorsRaht(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCResidualsDecoder& decoder, PCCResidualsDecoder& decoder,
PCCPointSet3& pointCloud); PCCPointSet3& pointCloud);
......
...@@ -333,7 +333,7 @@ AttributeEncoder::encode( ...@@ -333,7 +333,7 @@ AttributeEncoder::encode(
PCCPointSet3& pointCloud, PCCPointSet3& pointCloud,
PayloadBuffer* payload) PayloadBuffer* payload)
{ {
Quantizers qstep = deriveQuantSteps(attr_aps, abh); Quantizers quant = deriveQuantizers(attr_aps, abh);
PCCResidualsEncoder encoder; PCCResidualsEncoder encoder;
encoder.start(int(pointCloud.getPointCount())); encoder.start(int(pointCloud.getPointCount()));
...@@ -342,29 +342,29 @@ AttributeEncoder::encode( ...@@ -342,29 +342,29 @@ AttributeEncoder::encode(
switch (attr_aps.attr_encoding) { switch (attr_aps.attr_encoding) {
case AttributeEncoding::kRAHTransform: case AttributeEncoding::kRAHTransform:
encodeReflectancesTransformRaht( encodeReflectancesTransformRaht(
desc, attr_aps, qstep, pointCloud, encoder); desc, attr_aps, quant, pointCloud, encoder);
break; break;
case AttributeEncoding::kPredictingTransform: case AttributeEncoding::kPredictingTransform:
encodeReflectancesPred(desc, attr_aps, qstep, pointCloud, encoder); encodeReflectancesPred(desc, attr_aps, quant, pointCloud, encoder);
break; break;
case AttributeEncoding::kLiftingTransform: case AttributeEncoding::kLiftingTransform:
encodeReflectancesLift(desc, attr_aps, qstep, pointCloud, encoder); encodeReflectancesLift(desc, attr_aps, quant, pointCloud, encoder);
break; break;
} }
} else if (desc.attr_num_dimensions == 3) { } else if (desc.attr_num_dimensions == 3) {
switch (attr_aps.attr_encoding) { switch (attr_aps.attr_encoding) {
case AttributeEncoding::kRAHTransform: case AttributeEncoding::kRAHTransform:
encodeColorsTransformRaht(desc, attr_aps, qstep, pointCloud, encoder); encodeColorsTransformRaht(desc, attr_aps, quant, pointCloud, encoder);
break; break;
case AttributeEncoding::kPredictingTransform: case AttributeEncoding::kPredictingTransform:
encodeColorsPred(desc, attr_aps, qstep, pointCloud, encoder); encodeColorsPred(desc, attr_aps, quant, pointCloud, encoder);
break; break;
case AttributeEncoding::kLiftingTransform: case AttributeEncoding::kLiftingTransform:
encodeColorsLift(desc, attr_aps, qstep, pointCloud, encoder); encodeColorsLift(desc, attr_aps, quant, pointCloud, encoder);
break; break;
} }
} else { } else {
...@@ -383,12 +383,12 @@ int64_t ...@@ -383,12 +383,12 @@ int64_t
AttributeEncoder::computeReflectanceResidual( AttributeEncoder::computeReflectanceResidual(
const uint64_t reflectance, const uint64_t reflectance,
const uint64_t predictedReflectance, const uint64_t predictedReflectance,
const int64_t qs) const Quantizer& quant)
{ {
const int64_t quantAttValue = reflectance; const int64_t quantAttValue = reflectance;
const int64_t quantPredAttValue = predictedReflectance; const int64_t quantPredAttValue = predictedReflectance;
const int64_t delta = PCCQuantization( const int64_t delta = quant.quantize(
(quantAttValue - quantPredAttValue) << kFixedPointAttributeShift, qs); (quantAttValue - quantPredAttValue) << kFixedPointAttributeShift);
return IntToUInt(delta); return IntToUInt(delta);
} }
...@@ -404,7 +404,7 @@ AttributeEncoder::computeReflectancePredictionWeights( ...@@ -404,7 +404,7 @@ AttributeEncoder::computeReflectancePredictionWeights(
PCCPredictor& predictor, PCCPredictor& predictor,
PCCResidualsEncoder& encoder, PCCResidualsEncoder& encoder,
PCCResidualsEntropyEstimator& context, PCCResidualsEntropyEstimator& context,
const int64_t qs) const Quantizer& quant)
{ {
predictor.computeWeights(); predictor.computeWeights();
predictor.maxDiff = 0; predictor.maxDiff = 0;
...@@ -431,10 +431,10 @@ AttributeEncoder::computeReflectancePredictionWeights( ...@@ -431,10 +431,10 @@ AttributeEncoder::computeReflectancePredictionWeights(
predictor.predMode = 0; predictor.predMode = 0;
uint64_t attrPred = predictor.predictReflectance(pointCloud, indexesLOD); uint64_t attrPred = predictor.predictReflectance(pointCloud, indexesLOD);
int64_t attrResidualQuant = int64_t attrResidualQuant =
computeReflectanceResidual(attrValue, attrPred, qs); computeReflectanceResidual(attrValue, attrPred, quant);
double best_score = attrResidualQuant double best_score = attrResidualQuant
+ kAttrPredLambdaR * (qs >> kFixedPointAttributeShift); + kAttrPredLambdaR * (quant.stepSize() >> kFixedPointAttributeShift);
for (int i = 0; i < predictor.neighborCount; i++) { for (int i = 0; i < predictor.neighborCount; i++) {
if (i == aps.max_num_direct_predictors) if (i == aps.max_num_direct_predictors)
...@@ -443,11 +443,12 @@ AttributeEncoder::computeReflectancePredictionWeights( ...@@ -443,11 +443,12 @@ AttributeEncoder::computeReflectancePredictionWeights(
attrPred = pointCloud.getReflectance( attrPred = pointCloud.getReflectance(
indexesLOD[predictor.neighbors[i].predictorIndex]); indexesLOD[predictor.neighbors[i].predictorIndex]);
attrResidualQuant = attrResidualQuant =
computeReflectanceResidual(attrValue, attrPred, qs); computeReflectanceResidual(attrValue, attrPred, quant);
double idxBits = i + (i == aps.max_num_direct_predictors - 1 ? 1 : 2); double idxBits = i + (i == aps.max_num_direct_predictors - 1 ? 1 : 2);
double score = attrResidualQuant double score = attrResidualQuant
+ idxBits * kAttrPredLambdaR * (qs >> kFixedPointAttributeShift); + idxBits * kAttrPredLambdaR
* (quant.stepSize() >> kFixedPointAttributeShift);
if (score < best_score) { if (score < best_score) {
best_score = score; best_score = score;
...@@ -466,7 +467,7 @@ void ...@@ -466,7 +467,7 @@ void
AttributeEncoder::encodeReflectancesPred( AttributeEncoder::encodeReflectancesPred(
const AttributeDescription& desc, const AttributeDescription& desc,
const AttributeParameterSet& aps, const AttributeParameterSet& aps,
const Quantizers& qstep, const Quantizers& quant,
PCCPointSet3& pointCloud, PCCPointSet3& pointCloud,
PCCResidualsEncoder& encoder) PCCResidualsEncoder& encoder)
{ {
...@@ -492,10 +493,9 @@ AttributeEncoder::encodeReflectancesPred( ...@@ -492,10 +493,9 @@ AttributeEncoder::encodeReflectancesPred(
for (size_t predictorIndex = 0; predictorIndex < pointCount; for (size_t predictorIndex = 0; predictorIndex < pointCount;
++predictorIndex) { ++predictorIndex) {
auto& predictor = predictors[predictorIndex]; auto& predictor = predictors[predictorIndex];
const int64_t qs = qstep[0];
computeReflectancePredictionWeights( computeReflectancePredictionWeights(
aps, pointCloud, indexesLOD, predictorIndex, predictor, encoder, context, aps, pointCloud, indexesLOD, predictorIndex, predictor, encoder, context,
qs); quant[0]);
const uint32_t pointIndex = indexesLOD[predictorIndex]; const uint32_t pointIndex = indexesLOD[predictorIndex];
const uint64_t reflectance = pointCloud.getReflectance(pointIndex); const uint64_t reflectance = pointCloud.getReflectance(pointIndex);
...@@ -503,11 +503,11 @@ AttributeEncoder::encodeReflectancesPred( ...@@ -503,11 +503,11 @@ AttributeEncoder::encodeReflectancesPred(
predictor.predictReflectance(pointCloud, indexesLOD); predictor.predictReflectance(pointCloud, indexesLOD);
const int64_t quantAttValue = reflectance; const int64_t quantAttValue = reflectance;
const int64_t quantPredAttValue = predictedReflectance; const int64_t quantPredAttValue = predictedReflectance;
const int64_t delta = PCCQuantization( const int64_t delta = quant[0].quantize(
(quantAttValue - quantPredAttValue) << kFixedPointAttributeShift, qs); (quantAttValue - quantPredAttValue) << kFixedPointAttributeShift);
const uint32_t attValue0 = uint32_t(IntToUInt(long(delta))); const uint32_t attValue0 = uint32_t(IntToUInt(long(delta)));
const int64_t reconstructedDelta = divExp2RoundHalfUp( const int64_t reconstructedDelta =
PCCInverseQuantization(delta, qs), kFixedPointAttributeShift); divExp2RoundHalfUp(quant[0].scale(delta), kFixedPointAttributeShift);
const int64_t reconstructedQuantAttValue = const int64_t reconstructedQuantAttValue =
quantPredAttValue + reconstructedDelta; quantPredAttValue + reconstructedDelta;
const uint16_t reconstructedReflectance = const uint16_t reconstructedReflectance =
...@@ -552,20 +552,19 @@ Vec3<int64_t> ...@@ -552,20 +552,19 @@ Vec3<int64_t>
AttributeEncoder::computeColorResiduals( AttributeEncoder::computeColorResiduals(
const Vec3<uint8_t> color, const Vec3<uint8_t> color,
const Vec3<uint8_t> predictedColor, const Vec3<uint8_t> predictedColor,
const int64_t qs, const Quantizers& quant)
const int64_t qs2)
{ {
Vec3<int64_t> residuals; Vec3<int64_t> residuals;
const int64_t quantAttValue = color[0]; const int64_t quantAttValue = color[0];
const int64_t quantPredAttValue = predictedColor[0]; const int64_t quantPredAttValue = predictedColor[0];
const int64_t delta = PCCQuantization( const int64_t delta = quant[0].quantize(
(quantAttValue - quantPredAttValue) << kFixedPointAttributeShift, qs); (quantAttValue - quantPredAttValue) << kFixedPointAttributeShift);
residuals[0] = IntToUInt(delta); residuals[0] = IntToUInt(delta);
for (size_t k = 1; k < 3; ++k) { for (size_t k = 1; k < 3; ++k) {
const int64_t quantAttValue = color[k]; const int64_t quantAttValue = color[k];
const int64_t quantPredAttValue = predictedColor[k]; const int64_t quantPredAttValue = predictedColor[k];
const int64_t delta = PCCQuantization( const int64_t delta = quant[1].quantize(
(quantAttValue - quantPredAttValue) << kFixedPointAttributeShift, qs2); (quantAttValue - quantPredAttValue) << kFixedPointAttributeShift);
residuals[k] = IntToUInt(delta); residuals[k] = IntToUInt(delta);
} }
return residuals; return residuals;
...@@ -582,8 +581,7 @@ AttributeEncoder::computeColorPredictionWeights( ...@@ -582,8 +581,7 @@ AttributeEncoder::computeColorPredictionWeights(
PCCPredictor& predictor, PCCPredictor& predictor,