5#include "testing/testing.h"
55 float f_dc(
const int point,
const int channel)
const
57 return 0.5f + channel + 0.25f * point;
61 return 0.25f * point - 0.5f;
63 float scale(
const int point,
const int axis)
const
65 return -1.0f + 0.5f * axis + 0.125f * point;
67 float rotation(
const int point,
const int component)
const
69 return (component == 0) ? 1.0f : 0.0625f * point;
71 float f_rest(
const int point,
const int attribute_index)
const
76 const int channel = attribute_index / num_file_coefficients;
77 const int coefficient = attribute_index % num_file_coefficients;
78 return 100.0f * channel + coefficient + 0.25f * point;
83 return float3(coefficient + 0.25f * point,
84 100.0f + coefficient + 0.25f * point,
85 200.0f + coefficient + 0.25f * point);
91 for (
int point = 0; point <
num_points; point++) {
95 auto add_attribute = [&](
const std::string &name,
auto value_for_point) {
97 for (
int point = 0; point <
num_points; point++) {
98 attribute.data[point] = value_for_point(point);
103 for (
int channel = 0; channel < 3; channel++) {
104 add_attribute(
"f_dc_" + std::to_string(channel),
105 [&](
const int point) {
return f_dc(point, channel); });
107 add_attribute(
"opacity", [&](
const int point) {
return opacity(point); });
108 for (
int axis = 0; axis < 3; axis++) {
109 add_attribute(
"scale_" + std::to_string(axis),
110 [&](
const int point) {
return scale(point, axis); });
112 for (
int component = 0; component < 4; component++) {
113 add_attribute(
"rot_" + std::to_string(component),
114 [&](
const int point) {
return rotation(point, component); });
117 add_attribute(
"f_rest_" + std::to_string(i),
118 [&](
const int point) {
return f_rest(point, i); });
150 if (message ==
nullptr) {
153 const bool found = strstr(message, needle) !=
nullptr;
167 while (attributes.
contains(
"radiance:sh_" + std::to_string(count))) {
175 const int expected_num_coefficients)
180 for (
int coefficient = 0; coefficient < expected_num_coefficients; coefficient++) {
184 for (
int point = 0; point < builder.
num_points; point++) {
187 for (
int channel = 0; channel < 3; channel++) {
188 EXPECT_FLOAT_EQ(value[channel], expected[channel])
189 <<
"coefficient " << coefficient <<
" channel " << channel <<
" point " << point;
212 ASSERT_NE(point_cloud,
nullptr);
213 ASSERT_EQ(point_cloud->
totpoint, 3);
216 const Span<float3> positions = point_cloud->positions();
224 ASSERT_TRUE(radiance_base);
226 ASSERT_TRUE(rotations);
228 for (
int point = 0; point < builder.
num_points; point++) {
232 for (
int axis = 0; axis < 3; axis++) {
233 EXPECT_FLOAT_EQ(positions[point][axis], builder.
position(point)[axis]);
234 EXPECT_FLOAT_EQ(base[axis], builder.
f_dc(point, axis));
238 builder.
scale(point, 0), builder.
scale(point, 1), builder.
scale(point, 2)))[axis]);
240 EXPECT_FLOAT_EQ(base.w,
248 EXPECT_FLOAT_EQ(rotation.w, expected_rotation.
w);
249 EXPECT_FLOAT_EQ(rotation.x, expected_rotation.
x);
250 EXPECT_FLOAT_EQ(rotation.y, expected_rotation.
y);
251 EXPECT_FLOAT_EQ(rotation.z, expected_rotation.
z);
259 for (
const int num_coefficients : {0, 3, 8, 15, 24}) {
262 ASSERT_NE(point_cloud,
nullptr);
264 expect_sh_attributes(*point_cloud, builder, num_coefficients);
265 EXPECT_FALSE(has_any_report()) <<
"for coefficient count " << num_coefficients;
278 ASSERT_NE(point_cloud,
nullptr);
280 expect_sh_attributes(*point_cloud, builder, 3);
281 EXPECT_TRUE(has_warning_containing(
"spherical harmonics"));
291 ASSERT_NE(point_cloud,
nullptr);
293 expect_sh_attributes(*point_cloud, builder, 15);
294 EXPECT_TRUE(has_warning_containing(
"spherical harmonics"));
303 ASSERT_NE(point_cloud,
nullptr);
305 EXPECT_EQ(count_sh_attributes(*point_cloud), 0);
306 EXPECT_TRUE(has_warning_containing(
"spherical harmonics"));
317 ASSERT_NE(point_cloud,
nullptr);
319 EXPECT_EQ(count_sh_attributes(*point_cloud), 0);
320 EXPECT_TRUE(has_warning_containing(
"spherical harmonics"));
Read Blender memory allocation and freeing.
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
float f_dc(const int point, const int channel) const
float3 position(const int point) const
GsplatPlyDataBuilder(const int num_points, const int num_rest_attributes)
float rotation(const int point, const int component) const
float scale(const int point, const int axis) const
float3 expected_sh(const int point, const int coefficient) const
float f_rest(const int point, const int attribute_index) const
float opacity(const int point) const
static void SetUpTestSuite()
static int count_sh_attributes(const PointCloud &point_cloud)
static void TearDownTestSuite()
bool has_warning_containing(const char *needle)
void expect_sh_attributes(const PointCloud &point_cloud, const GsplatPlyDataBuilder &builder, const int expected_num_coefficients)
float3x3 scale(float3x3 mat, float2 scale)
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
TEST_F(PLYExportTest, WriteHeaderAscii)
PointCloud * convert_gsplat_ply_to_point_cloud(const PlyData &data, const PLYImportParams ¶ms)
QuaternionBase< float > Quaternion
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void BKE_reports_free(ReportList *reports)
void BKE_reports_init(ReportList *reports, int flag)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
VecBase< float, 4 > float4
BMesh const char void * data
void BKE_id_free(Main *bmain, void *idv)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
VecBase< float, 3 > float3
char * BKE_reports_string(ReportList *reports, eReportType level)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
static float decode_opacity(const float opacity)
static float3 decode_scale(const float3 scale)