Commit 7f3f66f2 authored by David Flynn's avatar David Flynn
Browse files

pointcloud: add addRemoveAttributes helper

This commit adds a helper to add / remove colour and reflectance
attributes in a single shot.
parent 22ab7537
...@@ -316,6 +316,18 @@ class PCCPointSet3 { ...@@ -316,6 +316,18 @@ class PCCPointSet3 {
colors.resize(0); colors.resize(0);
} }
void addRemoveAttributes(bool withColors, bool withReflectances) {
if (withColors)
addColors();
else
removeColors();
if (withReflectances)
addReflectances();
else
removeReflectances();
}
size_t getPointCount() const { return positions.size(); } size_t getPointCount() const { return positions.size(); }
void resize(const size_t size) { void resize(const size_t size) {
positions.resize(size); positions.resize(size);
......
...@@ -287,16 +287,7 @@ class PCCTMC3Decoder3 { ...@@ -287,16 +287,7 @@ class PCCTMC3Decoder3 {
PCCReadFromBuffer<uint8_t>(bitstream.buffer, u8value, bitstream.size); PCCReadFromBuffer<uint8_t>(bitstream.buffer, u8value, bitstream.size);
inferredDirectCodingModeEnabled = bool(u8value); inferredDirectCodingModeEnabled = bool(u8value);
if (hasColors) { pointCloud.addRemoveAttributes(hasColors, hasReflectances);
pointCloud.addColors();
} else {
pointCloud.removeColors();
}
if (hasReflectances) {
pointCloud.addReflectances();
} else {
pointCloud.removeReflectances();
}
pointCloud.resize(pointCount); pointCloud.resize(pointCount);
for (int k = 0; k < 3; ++k) { for (int k = 0; k < 3; ++k) {
...@@ -320,16 +311,8 @@ class PCCTMC3Decoder3 { ...@@ -320,16 +311,8 @@ class PCCTMC3Decoder3 {
PCCReadFromBuffer<uint8_t>(bitstream.buffer, hasColors, bitstream.size); PCCReadFromBuffer<uint8_t>(bitstream.buffer, hasColors, bitstream.size);
uint8_t hasReflectances = 0; uint8_t hasReflectances = 0;
PCCReadFromBuffer<uint8_t>(bitstream.buffer, hasReflectances, bitstream.size); PCCReadFromBuffer<uint8_t>(bitstream.buffer, hasReflectances, bitstream.size);
if (hasColors) {
pointCloud.addColors(); pointCloud.addRemoveAttributes(hasColors, hasReflectances);
} else {
pointCloud.removeColors();
}
if (hasReflectances) {
pointCloud.addReflectances();
} else {
pointCloud.removeReflectances();
}
pointCloud.resize(pointCount); pointCloud.resize(pointCount);
for (int k = 0; k < 3; ++k) { for (int k = 0; k < 3; ++k) {
......
...@@ -129,21 +129,14 @@ class PCCTMC3Encoder3 { ...@@ -129,21 +129,14 @@ class PCCTMC3Encoder3 {
const PCCTMC3Encoder3Parameters &params, PCCBitstream &bitstream, const PCCTMC3Encoder3Parameters &params, PCCBitstream &bitstream,
PCCPointSet3 *reconstructedCloud = nullptr) { PCCPointSet3 *reconstructedCloud = nullptr) {
init(); init();
pointCloud = inputPointCloud;
auto paramsColor = auto paramsColor =
params.getAttrParams(inputPointCloud.hasColors(), "color"); params.getAttrParams(inputPointCloud.hasColors(), "color");
if (!paramsColor) {
pointCloud.removeColors();
}
auto paramsReflectance = auto paramsReflectance =
params.getAttrParams(inputPointCloud.hasReflectances(), "reflectance"); params.getAttrParams(inputPointCloud.hasReflectances(), "reflectance");
if (!paramsReflectance) { pointCloud = inputPointCloud;
pointCloud.removeReflectances(); pointCloud.addRemoveAttributes(!!paramsColor, !!paramsReflectance);
}
PCCWriteToBuffer<uint32_t>(PCCTMC3MagicNumber, bitstream.buffer, bitstream.size); PCCWriteToBuffer<uint32_t>(PCCTMC3MagicNumber, bitstream.buffer, bitstream.size);
PCCWriteToBuffer<uint32_t>(PCCTMC3FormatVersion, bitstream.buffer, bitstream.size); PCCWriteToBuffer<uint32_t>(PCCTMC3FormatVersion, bitstream.buffer, bitstream.size);
...@@ -368,16 +361,8 @@ class PCCTMC3Encoder3 { ...@@ -368,16 +361,8 @@ class PCCTMC3Encoder3 {
} }
const size_t pointCount = pointCloud.getPointCount(); const size_t pointCount = pointCloud.getPointCount();
if (pointCloud.hasColors()) { reconstructedCloud->addRemoveAttributes(
reconstructedCloud->addColors(); pointCloud.hasColors(), pointCloud.hasReflectances());
} else {
pointCloud.removeColors();
}
if (pointCloud.hasReflectances()) {
reconstructedCloud->addReflectances();
} else {
pointCloud.removeReflectances();
}
reconstructedCloud->resize(pointCount); reconstructedCloud->resize(pointCount);
const double minPositionQuantizationScale = 0.0000000001; const double minPositionQuantizationScale = 0.0000000001;
...@@ -743,10 +728,8 @@ class PCCTMC3Encoder3 { ...@@ -743,10 +728,8 @@ class PCCTMC3Encoder3 {
// order since IDCM causes leaves to be coded earlier than they // order since IDCM causes leaves to be coded earlier than they
// otherwise would. // otherwise would.
PCCPointSet3 pointCloud2; PCCPointSet3 pointCloud2;
if (pointCloud.hasColors()) pointCloud2.addRemoveAttributes(
pointCloud2.addColors(); pointCloud.hasColors(), pointCloud.hasReflectances());
if (pointCloud.hasReflectances())
pointCloud2.addReflectances();
pointCloud2.resize(pointCloud.getPointCount()); pointCloud2.resize(pointCloud.getPointCount());
// copy points with DM points first, the rest second // copy points with DM points first, the rest second
...@@ -837,25 +820,14 @@ class PCCTMC3Encoder3 { ...@@ -837,25 +820,14 @@ class PCCTMC3Encoder3 {
int quantization(const PCCPointSet3 &inputPointCloud, const PCCTMC3Encoder3Parameters &params) { int quantization(const PCCPointSet3 &inputPointCloud, const PCCTMC3Encoder3Parameters &params) {
computeMinPositions(inputPointCloud); computeMinPositions(inputPointCloud);
pointCloud.resize(0);
auto paramsColor = auto paramsColor =
params.getAttrParams(inputPointCloud.hasColors(), "color"); params.getAttrParams(inputPointCloud.hasColors(), "color");
if (paramsColor) {
pointCloud.addColors();
} else {
pointCloud.removeColors();
}
auto paramsReflectance = auto paramsReflectance =
params.getAttrParams(inputPointCloud.hasReflectances(), "reflectance"); params.getAttrParams(inputPointCloud.hasReflectances(), "reflectance");
if (paramsReflectance) { pointCloud.resize(0);
pointCloud.addReflectances(); pointCloud.addRemoveAttributes(!!paramsColor, !!paramsReflectance);
} else {
pointCloud.removeReflectances();
}
const size_t inputPointCount = inputPointCloud.getPointCount(); const size_t inputPointCount = inputPointCloud.getPointCount();
if (params.mergeDuplicatedPoints) { // retain unique quantized points if (params.mergeDuplicatedPoints) { // retain unique quantized points
......
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