Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Windows and CPP17 compatibility #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions src/cc/load-spz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,11 @@ PackedGaussians packGaussians(const GaussianCloud &g) {

// Use 12 bits for the fractional part of coordinates (~0.25 millimeter resolution). In the future
// we can use different values on a per-splat basis and still be compatible with the decoder.
PackedGaussians packed = {
.numPoints = g.numPoints,
.shDegree = g.shDegree,
.fractionalBits = 12,
.antialiased = g.antialiased,
};
PackedGaussians packed;
packed.numPoints = g.numPoints;
packed.shDegree = g.shDegree;
packed.fractionalBits = 12;
packed.antialiased = g.antialiased;
packed.positions.resize(numPoints * 3 * 3);
packed.scales.resize(numPoints * 3);
packed.rotations.resize(numPoints * 3);
Expand Down Expand Up @@ -378,11 +377,10 @@ GaussianCloud unpackGaussians(const PackedGaussians &packed) {
return {};
}

GaussianCloud result = {
.numPoints = packed.numPoints,
.shDegree = packed.shDegree,
.antialiased = packed.antialiased,
};
GaussianCloud result;
result.numPoints = packed.numPoints;
result.shDegree = packed.shDegree;
result.antialiased = packed.antialiased;
result.positions.resize(numPoints * 3);
result.scales.resize(numPoints * 3);
result.rotations.resize(numPoints * 4);
Expand Down Expand Up @@ -440,12 +438,11 @@ GaussianCloud unpackGaussians(const PackedGaussians &packed) {
}

void serializePackedGaussians(const PackedGaussians &packed, std::ostream &out) {
PackedGaussiansHeader header = {
.numPoints = static_cast<uint32_t>(packed.numPoints),
.shDegree = static_cast<uint8_t>(packed.shDegree),
.fractionalBits = static_cast<uint8_t>(packed.fractionalBits),
.flags = static_cast<uint8_t>(packed.antialiased ? FlagAntialiased : 0),
};
PackedGaussiansHeader header;
header.numPoints = static_cast<uint32_t>(packed.numPoints);
header.shDegree = static_cast<uint8_t>(packed.shDegree);
header.fractionalBits = static_cast<uint8_t>(packed.fractionalBits);
header.flags = static_cast<uint8_t>(packed.antialiased ? FlagAntialiased : 0);
out.write(reinterpret_cast<const char *>(&header), sizeof(header));
out.write(reinterpret_cast<const char *>(packed.positions.data()), countBytes(packed.positions));
out.write(reinterpret_cast<const char *>(packed.alphas.data()), countBytes(packed.alphas));
Expand Down Expand Up @@ -479,11 +476,11 @@ PackedGaussians deserializePackedGaussians(std::istream &in) {
const int numPoints = header.numPoints;
const int shDim = dimForDegree(header.shDegree);
const bool usesFloat16 = header.version == 1;
PackedGaussians result = {
.numPoints = numPoints,
.shDegree = header.shDegree,
.fractionalBits = header.fractionalBits,
.antialiased = (header.flags & FlagAntialiased) != 0};
PackedGaussians result;
result.numPoints = numPoints;
result.shDegree = header.shDegree;
result.fractionalBits = header.fractionalBits;
result.antialiased = (header.flags & FlagAntialiased) != 0;
result.positions.resize(numPoints * 3 * (usesFloat16 ? 2 : 3));
result.scales.resize(numPoints * 3);
result.rotations.resize(numPoints * 3);
Expand Down
2 changes: 2 additions & 0 deletions src/cc/splat-c-types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SPZ_SPLAT_C_TYPES_H_
#define SPZ_SPLAT_C_TYPES_H_

#define _USE_MATH_DEFINES
#include <math.h>
#include <stddef.h>

// These types are used to bridge between the C++ API and C (to interop with Swift and C#).
Expand Down
3 changes: 2 additions & 1 deletion src/cc/splat-types.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "splat-types.h"

#include <cmath>
#include <limits>

namespace spz {

Expand All @@ -17,7 +18,7 @@ float halfToFloat(Half h) {

if (exponent == 31) {
// Infinity or NaN.
return mantissa != 0 ? 0.0f / 0.0f : signMul * 1.0f / 0.0f;
return mantissa != 0 ? std::numeric_limits<float>::quiet_NaN() : signMul * std::numeric_limits<float>::infinity();
}

// non-zero exponent implies 1 in the mantissa decimal.
Expand Down
3 changes: 2 additions & 1 deletion src/cc/splat-types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
Expand Down Expand Up @@ -167,7 +168,7 @@ constexpr Vec3f times(const Quat4f &q, const Vec3f &p) {
vx * (xz2 - wy2) + vy * (yz2 + wx2) + vz * (1.0f - (xx2 + yy2))};
}

constexpr Quat4f times(const Quat4f &a, const Quat4f &b) {
inline Quat4f times(const Quat4f &a, const Quat4f &b) {
auto [w, x, y, z] = a;
auto [qw, qx, qy, qz] = b;
return normalized(std::array<float, 4>{
Expand Down