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