39class BufferedFileReader {
42 FILE *file_ =
nullptr;
46 explicit BufferedFileReader(FILE *file) : file_(file), buffer_(
BUFFER_SIZE) {}
48 std::optional<Span<uint8_t>> read()
50 const size_t num_read_bytes = fread(buffer_.
data(), 1, buffer_.
size(), file_);
54 return buffer_.
as_span().slice(0, num_read_bytes);
60class StreamedGzipReader {
61 BufferedFileReader buffered_reader_;
65 explicit StreamedGzipReader(FILE *file) : buffered_reader_(file) {}
77 return inflateInit2(&stream_, 16 | MAX_WBITS) == Z_OK;
80 bool read_buffer(
const MutableSpan<uint8_t> buffer)
82 stream_.avail_out = buffer.size();
83 stream_.next_out = buffer.data();
89 if (stream_.avail_in == 0) {
90 std::optional<Span<uint8_t>> read_result = buffered_reader_.read();
91 if (!read_result.has_value() || read_result->size() == 0) {
94 stream_.avail_in = read_result->size();
95 stream_.next_in =
const_cast<Bytef *
>(read_result->data());
98 const int ret = inflate(&stream_, Z_NO_FLUSH);
100 if (
ret == Z_STREAM_END) {
101 if (stream_.avail_out != 0) {
110 }
while (stream_.avail_out != 0);
120 return read_buffer(MutableSpan<uint8_t>(
reinterpret_cast<uint8_t *
>(&
data),
sizeof(
T)));
128 StreamedGzipReader reader(file);
130 if (!reader.initialize()) {
136 if (!reader.read(header)) {
156 CLOG_WARN(&
LOG,
"SPZ data was trained with anti-aliasing which is not fully supported");
160 CLOG_WARN(&
LOG,
"SPZ file contains extensions that are not yet supported");
General operations for point clouds.
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
Span< T > as_span() const
MutableSpan< math::Quaternion > rotations_for_write()
MutableSpan< float3 > scales_for_write()
Span< MutableSpan< float3 > > sh_for_write()
MutableSpan< float3 > positions_for_write()
MutableSpan< float4 > radiance_base_for_write()
@ SPZ_HEADER_HAS_EXTENSIONS
bool read_sh(ReaderType &reader, const Span< MutableSpan< float3 > > sh)
PointCloud * read_spz_gzip_compressed_file(FILE *file, ReportList *reports)
bool read_positions(ReaderType &reader, const int fractional_bits, const MutableSpan< float3 > positions)
void convert_axis_to_blender(const MutableSpan< float3 > positions, const MutableSpan< math::Quaternion > rotations, const Span< MutableSpan< float3 > > sh_attrs)
std::optional< std::string > check_header_for_errors(const PackedGaussiansHeader &header)
bool read_colors(ReaderType &reader, const MutableSpan< float4 > radiance_base)
bool read_alphas(ReaderType &reader, const MutableSpan< float4 > radiance_base)
bool read_scales(ReaderType &reader, const MutableSpan< float3 > scales)
bool read_rotations(ReaderType &reader, const int version, const MutableSpan< math::Quaternion > rotations)
void BKE_report(ReportList *reports, eReportType type, const char *message)
BMesh const char void * data
void BKE_id_free(Main *bmain, void *idv)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
PointCloud * BKE_pointcloud_new_nomain(PointCloudType type, int totpoint)
T read(T depth_buffer_value)