Commit 00bac43d authored by David Flynn's avatar David Flynn
Browse files

refactor: rename pcc::PCCVector3<T> to pcc::Vec3<T>

This is part of a series attempting to remove unhelpful typedefs.
parent 6980ddc2
......@@ -479,14 +479,14 @@ AttributeEncoder::encodeReflectancesPred(
//----------------------------------------------------------------------------
PCCVector3<int64_t>
Vec3<int64_t>
AttributeEncoder::computeColorResiduals(
const PCCColor3B color,
const PCCColor3B predictedColor,
const int64_t qs,
const int64_t qs2)
{
PCCVector3<int64_t> residuals;
Vec3<int64_t> residuals;
const int64_t quantAttValue = color[0];
const int64_t quantPredAttValue = predictedColor[0];
const int64_t delta = PCCQuantization(quantAttValue - quantPredAttValue, qs);
......@@ -540,7 +540,7 @@ AttributeEncoder::computeColorPredictionWeights(
// base case: weighted average of n neighbours
predictor.predMode = 0;
PCCColor3B attrPred = predictor.predictColor(pointCloud, indexesLOD);
PCCVector3<int64_t> attrResidualQuant =
Vec3<int64_t> attrResidualQuant =
computeColorResiduals(attrValue, attrPred, qs, qs2);
double best_score = attrResidualQuant[0] + attrResidualQuant[1]
......
......@@ -98,7 +98,7 @@ protected:
PCCPointSet3& pointCloud,
PCCResidualsEncoder& encoder);
static PCCVector3<int64_t> computeColorResiduals(
static Vec3<int64_t> computeColorResiduals(
const PCCColor3B color,
const PCCColor3B predictedColor,
const int64_t qs,
......
......@@ -43,12 +43,12 @@ namespace pcc {
void
updateGeometryOccupancyAtlas(
const PCCVector3<uint32_t>& currentPosition,
const Vec3<uint32_t>& currentPosition,
const int nodeSizeLog2,
const pcc::ringbuf<PCCOctree3Node>& fifo,
const pcc::ringbuf<PCCOctree3Node>::iterator& fifoCurrLvlEnd,
MortonMap3D* occupancyAtlas,
PCCVector3<uint32_t>* atlasOrigin)
Vec3<uint32_t>* atlasOrigin)
{
const uint32_t mask = (1 << occupancyAtlas->cubeSizeLog2()) - 1;
const int shift = occupancyAtlas->cubeSizeLog2() + nodeSizeLog2;
......@@ -78,7 +78,7 @@ updateGeometryOccupancyAtlas(
void
updateGeometryOccupancyAtlasOccChild(
const PCCVector3<uint32_t>& pos,
const Vec3<uint32_t>& pos,
int nodeSizeLog2,
uint8_t childOccupancy,
MortonMap3D* occupancyAtlas)
......@@ -135,7 +135,7 @@ updatePatternFromNeighOccupancy(
GeometryNeighPattern
makeGeometryNeighPattern(
bool adjacent_child_contextualization_enabled_flag,
const PCCVector3<uint32_t>& position,
const Vec3<uint32_t>& position,
const int nodeSizeLog2,
const MortonMap3D& occupancyAtlas)
{
......
......@@ -172,22 +172,22 @@ struct GeometryNeighPattern {
// the neighbour pattern and derive external adjacency counts for each child.
GeometryNeighPattern makeGeometryNeighPattern(
bool adjacent_child_contextualization_enabled_flag,
const PCCVector3<uint32_t>& currentPosition,
const Vec3<uint32_t>& currentPosition,
const int nodeSizeLog2,
const MortonMap3D& occupancyAtlas);
// populate (if necessary) the occupancy atlas with occupancy information
// from @fifo.
void updateGeometryOccupancyAtlas(
const PCCVector3<uint32_t>& position,
const Vec3<uint32_t>& position,
const int nodeSizeLog2,
const ringbuf<PCCOctree3Node>& fifo,
const ringbuf<PCCOctree3Node>::iterator& fifoCurrLvlEnd,
MortonMap3D* occupancyAtlas,
PCCVector3<uint32_t>* atlasOrigin);
Vec3<uint32_t>* atlasOrigin);
void updateGeometryOccupancyAtlasOccChild(
const PCCVector3<uint32_t>& pos,
const Vec3<uint32_t>& pos,
int nodeSizeLog2,
uint8_t childOccupancy,
MortonMap3D* occupancyAtlas);
......
......@@ -49,7 +49,7 @@
namespace pcc {
/// Vector dim 3
template<typename T>
class PCCVector3 {
class Vec3 {
public:
T* begin() { return &data[0]; }
const T* begin() const { return &data[0]; }
......@@ -87,54 +87,54 @@ public:
{
return std::max(data[2], std::max(abs(data[0]), abs(data[1])));
}
PCCVector3& operator=(const PCCVector3& rhs)
Vec3& operator=(const Vec3& rhs)
{
memcpy(data, rhs.data, sizeof(data));
return *this;
}
PCCVector3& operator+=(const PCCVector3& rhs)
Vec3& operator+=(const Vec3& rhs)
{
data[0] += rhs.data[0];
data[1] += rhs.data[1];
data[2] += rhs.data[2];
return *this;
}
PCCVector3& operator-=(const PCCVector3& rhs)
Vec3& operator-=(const Vec3& rhs)
{
data[0] -= rhs.data[0];
data[1] -= rhs.data[1];
data[2] -= rhs.data[2];
return *this;
}
PCCVector3& operator-=(const T a)
Vec3& operator-=(const T a)
{
data[0] -= a;
data[1] -= a;
data[2] -= a;
return *this;
}
PCCVector3& operator+=(const T a)
Vec3& operator+=(const T a)
{
data[0] += a;
data[1] += a;
data[2] += a;
return *this;
}
PCCVector3& operator<<=(int val)
Vec3& operator<<=(int val)
{
data[0] <<= val;
data[1] <<= val;
data[2] <<= val;
return *this;
}
PCCVector3& operator>>=(int val)
Vec3& operator>>=(int val)
{
data[0] >>= val;
data[1] >>= val;
data[2] >>= val;
return *this;
}
PCCVector3& operator/=(const T a)
Vec3& operator/=(const T a)
{
assert(a != 0);
data[0] /= a;
......@@ -142,95 +142,83 @@ public:
data[2] /= a;
return *this;
}
PCCVector3& operator*=(const T a)
Vec3& operator*=(const T a)
{
data[0] *= a;
data[1] *= a;
data[2] *= a;
return *this;
}
PCCVector3& operator=(const T a)
Vec3& operator=(const T a)
{
data[0] = a;
data[1] = a;
data[2] = a;
return *this;
}
PCCVector3& operator=(const T* const rhs)
Vec3& operator=(const T* const rhs)
{
data[0] = rhs[0];
data[1] = rhs[1];
data[2] = rhs[2];
return *this;
}
T operator*(const PCCVector3& rhs) const
T operator*(const Vec3& rhs) const
{
return (
data[0] * rhs.data[0] + data[1] * rhs.data[1] + data[2] * rhs.data[2]);
}
PCCVector3 operator-() const
Vec3 operator-() const { return Vec3<T>(-data[0], -data[1], -data[2]); }
friend Vec3 operator+(const Vec3& lhs, const Vec3& rhs)
{
return PCCVector3<T>(-data[0], -data[1], -data[2]);
}
friend PCCVector3 operator+(const PCCVector3& lhs, const PCCVector3& rhs)
{
return PCCVector3<T>(
return Vec3<T>(
lhs.data[0] + rhs.data[0], lhs.data[1] + rhs.data[1],
lhs.data[2] + rhs.data[2]);
}
friend PCCVector3 operator+(const T lhs, const PCCVector3& rhs)
friend Vec3 operator+(const T lhs, const Vec3& rhs)
{
return PCCVector3<T>(
lhs + rhs.data[0], lhs + rhs.data[1], lhs + rhs.data[2]);
return Vec3<T>(lhs + rhs.data[0], lhs + rhs.data[1], lhs + rhs.data[2]);
}
friend PCCVector3 operator+(const PCCVector3& lhs, const T rhs)
friend Vec3 operator+(const Vec3& lhs, const T rhs)
{
return PCCVector3<T>(
lhs.data[0] + rhs, lhs.data[1] + rhs, lhs.data[2] + rhs);
return Vec3<T>(lhs.data[0] + rhs, lhs.data[1] + rhs, lhs.data[2] + rhs);
}
friend PCCVector3 operator-(const PCCVector3& lhs, const PCCVector3& rhs)
friend Vec3 operator-(const Vec3& lhs, const Vec3& rhs)
{
return PCCVector3<T>(
return Vec3<T>(
lhs.data[0] - rhs.data[0], lhs.data[1] - rhs.data[1],
lhs.data[2] - rhs.data[2]);
}
friend PCCVector3 operator-(const T lhs, const PCCVector3& rhs)
friend Vec3 operator-(const T lhs, const Vec3& rhs)
{
return PCCVector3<T>(
lhs - rhs.data[0], lhs - rhs.data[1], lhs - rhs.data[2]);
return Vec3<T>(lhs - rhs.data[0], lhs - rhs.data[1], lhs - rhs.data[2]);
}
friend PCCVector3 operator-(const PCCVector3& lhs, const T rhs)
friend Vec3 operator-(const Vec3& lhs, const T rhs)
{
return PCCVector3<T>(
lhs.data[0] - rhs, lhs.data[1] - rhs, lhs.data[2] - rhs);
return Vec3<T>(lhs.data[0] - rhs, lhs.data[1] - rhs, lhs.data[2] - rhs);
}
friend PCCVector3 operator*(const T lhs, const PCCVector3& rhs)
friend Vec3 operator*(const T lhs, const Vec3& rhs)
{
return PCCVector3<T>(
lhs * rhs.data[0], lhs * rhs.data[1], lhs * rhs.data[2]);
return Vec3<T>(lhs * rhs.data[0], lhs * rhs.data[1], lhs * rhs.data[2]);
}
friend PCCVector3 operator*(const PCCVector3& lhs, const T rhs)
friend Vec3 operator*(const Vec3& lhs, const T rhs)
{
return PCCVector3<T>(
lhs.data[0] * rhs, lhs.data[1] * rhs, lhs.data[2] * rhs);
return Vec3<T>(lhs.data[0] * rhs, lhs.data[1] * rhs, lhs.data[2] * rhs);
}
friend PCCVector3 operator/(const PCCVector3& lhs, const T rhs)
friend Vec3 operator/(const Vec3& lhs, const T rhs)
{
assert(rhs != 0);
return PCCVector3<T>(
lhs.data[0] / rhs, lhs.data[1] / rhs, lhs.data[2] / rhs);
return Vec3<T>(lhs.data[0] / rhs, lhs.data[1] / rhs, lhs.data[2] / rhs);
}
friend PCCVector3 operator<<(const PCCVector3& lhs, int val)
friend Vec3 operator<<(const Vec3& lhs, int val)
{
return PCCVector3<T>(
lhs.data[0] << val, lhs.data[1] << val, lhs.data[2] << val);
return Vec3<T>(lhs.data[0] << val, lhs.data[1] << val, lhs.data[2] << val);
}
friend PCCVector3 operator>>(const PCCVector3& lhs, int val)
friend Vec3 operator>>(const Vec3& lhs, int val)
{
return PCCVector3<T>(
lhs.data[0] >> val, lhs.data[1] >> val, lhs.data[2] >> val);
return Vec3<T>(lhs.data[0] >> val, lhs.data[1] >> val, lhs.data[2] >> val);
}
bool operator<(const PCCVector3& rhs) const
bool operator<(const Vec3& rhs) const
{
if (data[0] == rhs.data[0]) {
if (data[1] == rhs.data[1]) {
......@@ -240,7 +228,7 @@ public:
}
return (data[0] < rhs.data[0]);
}
bool operator>(const PCCVector3& rhs) const
bool operator>(const Vec3& rhs) const
{
if (data[0] == rhs.data[0]) {
if (data[1] == rhs.data[1]) {
......@@ -250,43 +238,43 @@ public:
}
return (data[0] > rhs.data[0]);
}
bool operator==(const PCCVector3& rhs) const
bool operator==(const Vec3& rhs) const
{
return (
data[0] == rhs.data[0] && data[1] == rhs.data[1]
&& data[2] == rhs.data[2]);
}
bool operator!=(const PCCVector3& rhs) const
bool operator!=(const Vec3& rhs) const
{
return (
data[0] != rhs.data[0] || data[1] != rhs.data[1]
|| data[2] != rhs.data[2]);
}
friend std::ostream& operator<<(std::ostream& os, const PCCVector3& vec)
friend std::ostream& operator<<(std::ostream& os, const Vec3& vec)
{
os << vec[0] << " " << vec[1] << " " << vec[2] << std::endl;
return os;
}
friend std::istream& operator>>(std::istream& is, PCCVector3& vec)
friend std::istream& operator>>(std::istream& is, Vec3& vec)
{
is >> vec[0] >> vec[1] >> vec[2];
return is;
}
PCCVector3(const T a) { data[0] = data[1] = data[2] = a; }
PCCVector3(const T x, const T y, const T z)
Vec3(const T a) { data[0] = data[1] = data[2] = a; }
Vec3(const T x, const T y, const T z)
{
data[0] = x;
data[1] = y;
data[2] = z;
}
PCCVector3(const PCCVector3& vec)
Vec3(const Vec3& vec)
{
data[0] = vec.data[0];
data[1] = vec.data[1];
data[2] = vec.data[2];
}
PCCVector3() = default;
~PCCVector3(void) = default;
Vec3() = default;
~Vec3(void) = default;
private:
T data[3];
......@@ -294,9 +282,9 @@ private:
template<typename T>
struct PCCBox3 {
PCCVector3<T> min;
PCCVector3<T> max;
bool contains(const PCCVector3<T> point) const
Vec3<T> min;
Vec3<T> max;
bool contains(const Vec3<T> point) const
{
return !(
point.x() < min.x() || point.x() > max.x() || point.y() < min.y()
......@@ -321,7 +309,7 @@ struct PCCBox3 {
&& max.z() >= box.min.z() && min.z() <= box.max.z();
}
T getDist2(const PCCVector3<T>& point) const
T getDist2(const Vec3<T>& point) const
{
const T dx = std::max(std::max(min[0] - point[0], 0.0), point[0] - max[0]);
const T dy = std::max(std::max(min[1] - point[1], 0.0), point[1] - max[1]);
......@@ -343,12 +331,10 @@ struct PCCBox3 {
}
};
typedef PCCVector3<double> PCCVector3D;
typedef PCCVector3<double> PCCPoint3D;
typedef Vec3<double> PCCVector3D;
typedef Vec3<double> PCCPoint3D;
typedef PCCBox3<double> PCCBox3D;
typedef PCCVector3<uint8_t> PCCColor3B;
template<typename T>
using Vec3 = PCCVector3<T>;
typedef Vec3<uint8_t> PCCColor3B;
template<typename T>
T
......@@ -384,7 +370,7 @@ mortonAddr(const int32_t x, const int32_t y, const int32_t z)
template<typename T>
uint64_t
mortonAddr(const PCCVector3<T>& vec, int depth)
mortonAddr(const Vec3<T>& vec, int depth)
{
int x = int(vec.x()) >> depth;
int y = int(vec.y()) >> depth;
......
......@@ -58,19 +58,19 @@ namespace pcc {
inline void
quantizePositionsUniq(
const float scaleFactor,
const PCCVector3<int> offset,
const Vec3<int> offset,
const PCCBox3<int> clamp,
const PCCPointSet3& src,
PCCPointSet3* dst)
{
// Determine the set of unique quantised points
std::set<PCCVector3<int32_t>> uniquePoints;
std::set<Vec3<int32_t>> uniquePoints;
int numSrcPoints = src.getPointCount();
for (int i = 0; i < numSrcPoints; ++i) {
const PCCVector3D& point = src[i];
PCCVector3<int32_t> quantizedPoint;
Vec3<int32_t> quantizedPoint;
for (int k = 0; k < 3; k++) {
double k_pos = std::round((point[k] - offset[k]) * scaleFactor);
quantizedPoint[k] = PCCClip(int32_t(k_pos), clamp.min[k], clamp.max[k]);
......@@ -107,7 +107,7 @@ quantizePositionsUniq(
inline void
quantizePositions(
const float scaleFactor,
const PCCVector3<int> offset,
const Vec3<int> offset,
const PCCBox3<int> clamp,
const PCCPointSet3& src,
PCCPointSet3* dst)
......@@ -353,8 +353,8 @@ inline int
recolour(
const PCCPointSet3& source,
float sourceToTargetScaleFactor,
PCCVector3<int> targetToSourceOffset,
PCCVector3<int> offset,
Vec3<int> targetToSourceOffset,
Vec3<int> offset,
PCCPointSet3* target)
{
PCCVector3D combinedOffset;
......
......@@ -92,7 +92,7 @@ private:
int _sliceId;
// Position of the slice in the translated+scaled co-ordinate system.
PCCVector3<int> _sliceOrigin;
Vec3<int> _sliceOrigin;
// The point cloud currently being decoded
PCCPointSet3 _currentPointCloud;
......
......@@ -121,10 +121,10 @@ private:
PCCPointSet3 pointCloud;
// Position of the slice in the translated+scaled co-ordinate system.
PCCVector3<int> _sliceOrigin;
Vec3<int> _sliceOrigin;
// Size of the current slice
PCCVector3<int> _sliceBoxWhd;
Vec3<int> _sliceBoxWhd;
// The active parameter sets
const SequenceParameterSet* _sps;
......
......@@ -179,13 +179,13 @@ operator<<(std::ostream& out, const PartitionMethod& val)
namespace df {
namespace program_options_lite {
template<typename T>
struct option_detail<pcc::PCCVector3<T>> {
struct option_detail<pcc::Vec3<T>> {
static constexpr bool is_container = true;
static constexpr bool is_fixed_size = true;
typedef T* output_iterator;
static void clear(pcc::PCCVector3<T>& container){};
static output_iterator make_output_iterator(pcc::PCCVector3<T>& container)
static void clear(pcc::Vec3<T>& container){};
static output_iterator make_output_iterator(pcc::Vec3<T>& container)
{
return &container[0];
}
......
......@@ -60,7 +60,7 @@ PCCTMC3Encoder3::compress(
fixupParameterSets(params);
// Determine input bounding box (for SPS metadata) if not manually set
if (params->sps.seq_bounding_box_whd == PCCVector3<int>{0}) {
if (params->sps.seq_bounding_box_whd == Vec3<int>{0}) {
const auto& bbox = inputPointCloud.computeBoundingBox();
for (int k = 0; k < 3; k++) {
params->sps.seq_bounding_box_xyz0[k] = int(bbox.min[k]);
......@@ -98,7 +98,7 @@ PCCTMC3Encoder3::compress(
// If partitioning is not enabled, encode input as a single "partition"
if (params->partitionMethod == PartitionMethod::kNone) {
// todo(df): params->gps.geom_box_present_flag = false;
_sliceOrigin = PCCVector3<int>{0};
_sliceOrigin = Vec3<int>{0};
compressPartition(inputPointCloud, params, outputFn, reconstructedCloud);
return 0;
}
......@@ -406,12 +406,12 @@ void
PCCTMC3Encoder3::quantization(const PCCPointSet3& inputPointCloud)
{
// Currently the sequence width/height/depth must be set
assert(_sps->seq_bounding_box_whd != PCCVector3<int>{0});
assert(_sps->seq_bounding_box_whd != Vec3<int>{0});
// Clamp all points to [clampBox.min, clampBox.max] after translation
// and quantisation.
PCCBox3<int32_t> clampBox{{0, 0, 0}, {INT32_MAX, INT32_MAX, INT32_MAX}};
if (_sps->seq_bounding_box_whd != PCCVector3<int>{0}) {
if (_sps->seq_bounding_box_whd != Vec3<int>{0}) {
// todo(df): this is icky (not to mention rounding issues)
// NB: the sps seq_bounding_box_* uses unscaled co-ordinates => convert
// NB: minus 1 to convert to max x/y/z position
......@@ -436,7 +436,7 @@ PCCTMC3Encoder3::quantization(const PCCPointSet3& inputPointCloud)
double(_sliceOrigin[2])};
// The new maximum bounds of the offset cloud
PCCVector3<int> maxBound{0};
Vec3<int> maxBound{0};
const size_t pointCount = pointCloud.getPointCount();
for (size_t i = 0; i < pointCount; ++i) {
......
......@@ -62,7 +62,7 @@ static const int LUT_th1[5] = {67, 66, 65, 66, 64};
void
predictGeometryOccupancyIntra(
const MortonMap3D& occupancyAtlas,
PCCVector3<uint32_t> pos,
Vec3<uint32_t> pos,
int nodeSizeLog2,
int* occupancyIsPredicted,
int* occupancyPrediction)
......
......@@ -46,7 +46,7 @@ namespace pcc {
void predictGeometryOccupancyIntra(
const MortonMap3D& occupancyAtlas,
PCCVector3<uint32_t> pos,
Vec3<uint32_t> pos,
int nodeSizeLog2,
int* occupacyIsPredIntra,
int* occupacyPredIntra);
......
......@@ -54,7 +54,7 @@ const int MAX_NUM_DM_LEAF_POINTS = 2;
struct PCCOctree3Node {
// 3D position of the current node's origin (local x,y,z = 0).
PCCVector3<uint32_t> pos;
Vec3<uint32_t> pos;
// Range of point indexes spanned by node
uint32_t start;
......
......@@ -84,7 +84,7 @@ public:
int occupancyAdjGt0,
int occupancyAdjGt1);
PCCVector3<uint32_t> decodePointPosition(int nodeSizeLog2);
Vec3<uint32_t> decodePointPosition(int nodeSizeLog2);
template<class OutputIt>
int decodeDirectPosition(
......@@ -338,10 +338,10 @@ GeometryOctreeDecoder::decodeOccupancy(
//-------------------------------------------------------------------------
// Decode a position of a point in a given volume.
PCCVector3<uint32_t>
Vec3<uint32_t>
GeometryOctreeDecoder::decodePointPosition(int nodeSizeLog2)
{
PCCVector3<uint32_t> delta{};
Vec3<uint32_t> delta{};
for (int i = nodeSizeLog2; i > 0; i--) {
delta <<= 1;
delta[0] |= _arithmeticDecoder->decode(_ctxEquiProb);
......@@ -373,7 +373,7 @@ GeometryOctreeDecoder::decodeDirectPosition(
for (int i = 0; i < numPoints; i++) {
// convert node-relative position to world position
PCCVector3<uint32_t> pos = node.pos + decodePointPosition(nodeSizeLog2);
Vec3<uint32_t> pos = node.pos + decodePointPosition(nodeSizeLog2);
*(outputPoints++) = {double(pos[0]), double(pos[1]), double(pos[2])};
}
......@@ -419,7 +419,7 @@ decodeGeometryOctree(
// ie, the number of nodes added to the next level of the tree
int numNodesNextLvl = 0;
PCCVector3<uint32_t> occupancyAtlasOrigin(0xffffffff);
Vec3<uint32_t> occupancyAtlasOrigin(0xffffffff);
MortonMap3D occupancyAtlas;
if (gps.neighbour_avail_boundary_log2) {
occupancyAtlas.resize(gps.neighbour_avail_boundary_log2);
......