Commit a298b199 authored by David Flynn's avatar David Flynn
Browse files

refactor: move common constants to constants.h

This commit moves various constants from PCCTMC3Common.h to a new
constants.h.  Hard coded values of constants have been replaced with
their symbolic name.
parent 5561887e
......@@ -36,6 +36,7 @@
#include "AttributeDecoder.h"
#include "ArithmeticCodec.h"
#include "constants.h"
#include "io_hls.h"
#include "RAHT.h"
......@@ -45,7 +46,6 @@ namespace pcc {
// An encapsulation of the entropy decoding methods used in attribute coding
struct PCCResidualsDecoder {
uint32_t alphabetSize;
o3dgc::Arithmetic_Codec arithmeticDecoder;
o3dgc::Static_Bit_Model binaryModel0;
o3dgc::Adaptive_Bit_Model binaryModelPred;
......@@ -54,9 +54,7 @@ struct PCCResidualsDecoder {
o3dgc::Adaptive_Bit_Model binaryModelDiff1;
o3dgc::Adaptive_Data_Model multiSymbolModelDiff1;
PCCResidualsDecoder() { alphabetSize = PCCTMC3SymbolCount; }
void start(const char* buf, int buf_len, uint32_t alphabetSize);
void start(const char* buf, int buf_len);
void stop();
bool decodePred();
uint32_t decode0();
......@@ -66,11 +64,10 @@ struct PCCResidualsDecoder {
//----------------------------------------------------------------------------
void
PCCResidualsDecoder::start(const char* buf, int buf_len, uint32_t alphabetSize)
PCCResidualsDecoder::start(const char* buf, int buf_len)
{
this->alphabetSize = alphabetSize;
multiSymbolModelDiff0.set_alphabet(alphabetSize + 1);
multiSymbolModelDiff1.set_alphabet(alphabetSize + 1);
multiSymbolModelDiff0.set_alphabet(kAttributeResidualAlphabetSize + 1);
multiSymbolModelDiff1.set_alphabet(kAttributeResidualAlphabetSize + 1);
arithmeticDecoder.set_buffer(
buf_len, reinterpret_cast<uint8_t*>(const_cast<char*>(buf)));
......@@ -100,7 +97,7 @@ uint32_t
PCCResidualsDecoder::decode0()
{
uint32_t value = arithmeticDecoder.decode(multiSymbolModelDiff0);
if (value == alphabetSize) {
if (value == kAttributeResidualAlphabetSize) {
value +=
arithmeticDecoder.ExpGolombDecode(0, binaryModel0, binaryModelDiff0);
}
......@@ -113,7 +110,7 @@ uint32_t
PCCResidualsDecoder::decode1()
{
uint32_t value = arithmeticDecoder.decode(multiSymbolModelDiff1);
if (value == alphabetSize) {
if (value == kAttributeResidualAlphabetSize) {
value +=
arithmeticDecoder.ExpGolombDecode(0, binaryModel0, binaryModelDiff1);
}
......@@ -134,9 +131,7 @@ AttributeDecoder::decode(
/* AttributeBrickHeader abh = */ parseAbh(payload, &abhSize);
PCCResidualsDecoder decoder;
const uint32_t alphabetSize = 64;
decoder.start(
payload.data() + abhSize, payload.size() - abhSize, alphabetSize);
decoder.start(payload.data() + abhSize, payload.size() - abhSize);
if (attr_desc.attr_num_dimensions == 1) {
switch (attr_aps.attr_encoding) {
......
......@@ -34,6 +34,8 @@
*/
#include "AttributeEncoder.h"
#include "constants.h"
#include "RAHT.h"
namespace pcc {
......@@ -41,7 +43,6 @@ namespace pcc {
// An encapsulation of the entropy coding methods used in attribute coding
struct PCCResidualsEncoder {
uint32_t alphabetSize;
o3dgc::Arithmetic_Codec arithmeticEncoder;
o3dgc::Static_Bit_Model binaryModel0;
o3dgc::Adaptive_Bit_Model binaryModelPred;
......@@ -50,9 +51,7 @@ struct PCCResidualsEncoder {
o3dgc::Adaptive_Bit_Model binaryModelDiff1;
o3dgc::Adaptive_Data_Model multiSymbolModelDiff1;
PCCResidualsEncoder() { alphabetSize = PCCTMC3SymbolCount; }
void start(int numPoints, uint32_t alphabetSize);
void start(int numPoints);
int stop();
void encode0(const uint32_t value);
void encode1(const uint32_t value);
......@@ -62,11 +61,10 @@ struct PCCResidualsEncoder {
//----------------------------------------------------------------------------
void
PCCResidualsEncoder::start(int pointCount, uint32_t alphabetSize)
PCCResidualsEncoder::start(int pointCount)
{
this->alphabetSize = alphabetSize;
multiSymbolModelDiff0.set_alphabet(alphabetSize + 1);
multiSymbolModelDiff1.set_alphabet(alphabetSize + 1);
multiSymbolModelDiff0.set_alphabet(kAttributeResidualAlphabetSize + 1);
multiSymbolModelDiff1.set_alphabet(kAttributeResidualAlphabetSize + 1);
// todo(df): remove estimate when arithmetic codec is replaced
int maxAcBufLen = pointCount * 3 * 2 + 1024;
......@@ -87,9 +85,10 @@ PCCResidualsEncoder::stop()
inline void
PCCResidualsEncoder::encode0(const uint32_t value)
{
if (value < alphabetSize) {
if (value < kAttributeResidualAlphabetSize) {
arithmeticEncoder.encode(value, multiSymbolModelDiff0);
} else {
int alphabetSize = kAttributeResidualAlphabetSize;
arithmeticEncoder.encode(alphabetSize, multiSymbolModelDiff0);
arithmeticEncoder.ExpGolombEncode(
value - alphabetSize, 0, binaryModel0, binaryModelDiff0);
......@@ -101,9 +100,10 @@ PCCResidualsEncoder::encode0(const uint32_t value)
inline void
PCCResidualsEncoder::encode1(const uint32_t value)
{
if (value < alphabetSize) {
if (value < kAttributeResidualAlphabetSize) {
arithmeticEncoder.encode(value, multiSymbolModelDiff1);
} else {
int alphabetSize = kAttributeResidualAlphabetSize;
arithmeticEncoder.encode(alphabetSize, multiSymbolModelDiff1);
arithmeticEncoder.ExpGolombEncode(
value - alphabetSize, 0, binaryModel0, binaryModelDiff1);
......@@ -122,8 +122,8 @@ PCCResidualsEncoder::encodePred(const bool value)
// An encapsulation of the entropy coding methods used in attribute coding
struct PCCResidualsEntropyEstimator {
size_t freq0[PCCTMC3SymbolCount + 1];
size_t freq1[PCCTMC3SymbolCount + 1];
size_t freq0[kAttributeResidualAlphabetSize + 1];
size_t freq1[kAttributeResidualAlphabetSize + 1];
size_t symbolCount0;
size_t symbolCount1;
size_t isZero0Count;
......@@ -147,12 +147,12 @@ struct PCCResidualsEntropyEstimator {
void
PCCResidualsEntropyEstimator::init()
{
for (size_t i = 0; i <= PCCTMC3SymbolCount; ++i) {
for (size_t i = 0; i <= kAttributeResidualAlphabetSize; ++i) {
freq0[i] = 1;
freq1[i] = 1;
}
symbolCount0 = PCCTMC3SymbolCount + 1;
symbolCount1 = PCCTMC3SymbolCount + 1;
symbolCount0 = kAttributeResidualAlphabetSize + 1;
symbolCount1 = kAttributeResidualAlphabetSize + 1;
isZero1Count = isZero0Count = symbolCount0 / 2;
}
......@@ -165,12 +165,12 @@ PCCResidualsEntropyEstimator::bitsDetail(
const size_t* const freq) const
{
const uint32_t detailClipped =
std::min(detail, uint32_t(PCCTMC3SymbolCount));
std::min(detail, uint32_t(kAttributeResidualAlphabetSize));
const double pDetail =
PCCClip(double(freq[detailClipped]) / symbolCount, 0.001, 0.999);
double bits = -log2(pDetail);
if (detail >= PCCTMC3SymbolCount) {
const double x = double(detail) - double(PCCTMC3SymbolCount);
if (detail >= kAttributeResidualAlphabetSize) {
const double x = double(detail) - double(kAttributeResidualAlphabetSize);
bits += 2.0 * std::floor(log2(x + 1.0)) + 1.0;
}
return bits;
......@@ -200,7 +200,7 @@ PCCResidualsEntropyEstimator::update(const uint32_t value0)
const bool isZero0 = value0 == 0;
++symbolCount0;
if (!isZero0) {
++freq0[std::min(value0 - 1, uint32_t(64))];
++freq0[std::min(value0 - 1, uint32_t(kAttributeResidualAlphabetSize))];
} else {
++isZero0Count;
}
......@@ -242,7 +242,7 @@ PCCResidualsEntropyEstimator::update(
const bool isZero0 = value0 == 0;
++symbolCount0;
if (!isZero0) {
++freq0[std::min(value0 - 1, uint32_t(64))];
++freq0[std::min(value0 - 1, uint32_t(kAttributeResidualAlphabetSize))];
} else {
++isZero0Count;
}
......@@ -250,8 +250,8 @@ PCCResidualsEntropyEstimator::update(
const bool isZero1 = value1 == 0 && value2 == 0;
symbolCount1 += 2;
if (!isZero1) {
++freq1[std::min(value1, uint32_t(PCCTMC3SymbolCount))];
++freq1[std::min(value2, uint32_t(PCCTMC3SymbolCount))];
++freq1[std::min(value1, uint32_t(kAttributeResidualAlphabetSize))];
++freq1[std::min(value2, uint32_t(kAttributeResidualAlphabetSize))];
} else {
++isZero1Count;
}
......@@ -268,8 +268,7 @@ AttributeEncoder::encode(
PayloadBuffer* payload)
{
PCCResidualsEncoder encoder;
const uint32_t alphabetSize = 64;
encoder.start(int(pointCloud.getPointCount()), alphabetSize);
encoder.start(int(pointCloud.getPointCount()));
if (desc.attr_num_dimensions == 1) {
switch (attr_aps.attr_encoding) {
......
......@@ -70,6 +70,7 @@ file(GLOB PROJECT_INC_FILES
"PCCTMC3Encoder.h"
"RAHT.h"
"TMC3.h"
"constants.h"
"geometry_octree.h"
"hls.h"
"io_hls.h"
......
......@@ -39,6 +39,7 @@
#include "ArithmeticCodec.h"
#include "PCCKdTree.h"
#include "PCCMath.h"
#include "constants.h"
#include "ringbuf.h"
#include "nanoflann.hpp"
......@@ -49,8 +50,6 @@
#include <vector>
namespace pcc {
const uint32_t PCCTMC3MaxPredictionNearestNeighborCount = 3;
const uint32_t PCCTMC3SymbolCount = 64;
// Structure for sorting weights.
struct WeightWithIndex {
......@@ -82,7 +81,7 @@ struct PCCNeighborInfo {
struct PCCPredictor {
size_t neighborCount;
uint32_t index;
PCCNeighborInfo neighbors[PCCTMC3MaxPredictionNearestNeighborCount];
PCCNeighborInfo neighbors[kAttributePredictionMaxNeighbourCount];
PCCColor3B predictColor(const PCCPointSet3& pointCloud) const
{
......@@ -407,7 +406,7 @@ PCCComputePredictors2(
const size_t pointCount = pointCloud.getPointCount();
const size_t lodCount = numberOfPointsPerLOD.size();
predictors.resize(pointCount);
PCCPointDistInfo nearestNeighbors[PCCTMC3MaxPredictionNearestNeighborCount];
PCCPointDistInfo nearestNeighbors[kAttributePredictionMaxNeighbourCount];
PCCNNQuery3 nNQuery = {PCCVector3D(0.0), std::numeric_limits<double>::max(),
numberOfNearestNeighborsInPrediction};
PCCNNResult nNResult = {nearestNeighbors, 0};
......@@ -479,8 +478,8 @@ PCCComputePredictors(
}
PointCloudWrapper pointCloudWrapper(pointCloud, indexes);
const nanoflann::SearchParams params(10, 0.0f, true);
size_t indices[PCCTMC3MaxPredictionNearestNeighborCount];
double sqrDist[PCCTMC3MaxPredictionNearestNeighborCount];
size_t indices[kAttributePredictionMaxNeighbourCount];
double sqrDist[kAttributePredictionMaxNeighbourCount];
nanoflann::KNNResultSet<double> resultSet(
numberOfNearestNeighborsInPrediction);
for (uint32_t lodIndex = 1; lodIndex < lodCount; ++lodIndex) {
......
......@@ -34,6 +34,7 @@
*/
#include "TMC3.h"
#include "constants.h"
#include "program_options_lite.h"
#include "io_tlv.h"
#include "version.h"
......@@ -517,10 +518,10 @@ ParseParameters(int argc, char* argv[], Parameters& params)
if (
attr_aps.num_pred_nearest_neighbours
> PCCTMC3MaxPredictionNearestNeighborCount) {
> kAttributePredictionMaxNeighbourCount) {
err.error() << it.first
<< ".numberOfNearestNeighborsInPrediction must be <= "
<< PCCTMC3MaxPredictionNearestNeighborCount << "\n";
<< kAttributePredictionMaxNeighbourCount << "\n";
}
}
}
......
/* The copyright in this software is being made available under the BSD
* Licence, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such
* rights are granted under this licence.
*
* Copyright (c) 2017-2018, ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the ISO/IEC nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace pcc {
//============================================================================
const uint32_t kAttributePredictionMaxNeighbourCount = 3;
const uint32_t kAttributeResidualAlphabetSize = 64;
//============================================================================
} // namespace pcc
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