VOXELFORMAT: print the colors to the console if they differ

master
Martin Gerhardy 2022-05-21 10:17:57 +02:00
parent 95809b6ebb
commit 13a056a156
6 changed files with 31 additions and 25 deletions

View File

@ -36,7 +36,7 @@ inline int countVoxels(const Volume& volume, const voxel::Voxel &voxel) {
return cnt;
}
inline void volumeComparator(const voxel::RawVolume& volume1, const voxel::Palette &pal1, const voxel::RawVolume& volume2, const voxel::Palette &pal2, bool includingColor, bool includingRegion) {
inline void volumeComparator(const voxel::RawVolume& volume1, const voxel::Palette &pal1, const voxel::RawVolume& volume2, const voxel::Palette &pal2, bool includingColor, bool includingRegion, float maxDelta = 0.001f) {
const Region& r1 = volume1.region();
const Region& r2 = volume2.region();
if (includingRegion) {
@ -68,7 +68,9 @@ inline void volumeComparator(const voxel::RawVolume& volume1, const voxel::Palet
ASSERT_EQ(voxel1.getMaterial(), voxel2.getMaterial())
<< "Voxel differs at " << x1 << ":" << y1 << ":" << z1 << " in material - voxel1["
<< voxel::VoxelTypeStr[(int)voxel1.getMaterial()] << ", " << (int)voxel1.getColor() << "], voxel2["
<< voxel::VoxelTypeStr[(int)voxel2.getMaterial()] << ", " << (int)voxel2.getColor() << "]";
<< voxel::VoxelTypeStr[(int)voxel2.getMaterial()] << ", " << (int)voxel2.getColor() << "], color1["
<< core::Color::print(voxel1.getColor()) << "], color2[" << core::Color::print(voxel2.getColor())
<< "]";
if (voxel::isAir(voxel1.getMaterial())) {
continue;
}
@ -78,12 +80,12 @@ inline void volumeComparator(const voxel::RawVolume& volume1, const voxel::Palet
const core::RGBA& c1 = pal1.colors[voxel1.getColor()];
const core::RGBA& c2 = pal2.colors[voxel2.getColor()];
const float delta = core::Color::getDistance(c1, c2);
ASSERT_LT(delta, 0.001f) << "Voxel differs at " << x1 << ":" << y1 << ":" << z1
ASSERT_LT(delta, maxDelta) << "Voxel differs at " << x1 << ":" << y1 << ":" << z1
<< " in material - voxel1[" << voxel::VoxelTypeStr[(int)voxel1.getMaterial()]
<< ", " << (int)voxel1.getColor() << "], voxel2["
<< voxel::VoxelTypeStr[(int)voxel2.getMaterial()] << ", "
<< (int)voxel2.getColor() << "], color1[" << core::Color::toHex(c1)
<< "], color2[" << core::Color::toHex(c2) << "], delta[" << delta << "]";
<< (int)voxel2.getColor() << "], color1[" << core::Color::print(c1)
<< "], color2[" << core::Color::print(c2) << "], delta[" << delta << "]";
}
}
}

View File

@ -307,7 +307,7 @@ bool VoxFormat::saveGroups(const SceneGraph &sceneGraph, const core::String &fil
}
ogt_vox_group default_group;
memset(&default_group, 0, sizeof(default_group));
core_memset(&default_group, 0, sizeof(default_group));
default_group.hidden = false;
default_group.layer_index = 0;
default_group.parent_group_index = k_invalid_group_index;
@ -359,7 +359,7 @@ bool VoxFormat::saveGroups(const SceneGraph &sceneGraph, const core::String &fil
instance.transform_anim.keyframes = instance.transform_anim.num_keyframes ? &keyframeTransforms[transformKeyFrameIdx] : nullptr;
for (const SceneGraphKeyFrame& kf : node.keyFrames()) {
ogt_vox_keyframe_transform kft;
memset(&kft, 0, sizeof(kft));
core_memset(&kft, 0, sizeof(kft));
kft.frame_index = kf.frame;
kft.transform = ogt_identity_transform;
// y and z are flipped here
@ -375,7 +375,7 @@ bool VoxFormat::saveGroups(const SceneGraph &sceneGraph, const core::String &fil
}
ogt_vox_scene output_scene;
memset(&output_scene, 0, sizeof(output_scene));
core_memset(&output_scene, 0, sizeof(output_scene));
output_scene.groups = &default_group;
output_scene.num_groups = 1;
output_scene.instances = &instances[0];

View File

@ -98,14 +98,14 @@ void AbstractVoxFormatTest::canLoad(const core::String &filename, size_t expecte
ASSERT_EQ(expectedVolumes, sceneGraph.size());
}
void AbstractVoxFormatTest::checkColor(core::RGBA c1, const voxel::Palette &palette, uint8_t index) {
void AbstractVoxFormatTest::checkColor(core::RGBA c1, const voxel::Palette &palette, uint8_t index, float maxDelta) {
const core::RGBA c2 = palette.colors[index];
const float delta = core::Color::getDistance(c1, c2);
ASSERT_LT(delta, 0.001f) << "color1[" << core::Color::toHex(c1) << "], color2[" << core::Color::toHex(c2)
ASSERT_LT(delta, maxDelta) << "color1[" << core::Color::print(c1) << "], color2[" << core::Color::print(c2)
<< "], delta[" << delta << "]";
}
void AbstractVoxFormatTest::testRGB(const core::String &filename) {
void AbstractVoxFormatTest::testRGB(const core::String &filename, float maxDelta) {
voxelformat::SceneGraph sceneGraph;
const io::FilePtr& file = open(filename);
ASSERT_TRUE(file->validHandle());
@ -113,9 +113,12 @@ void AbstractVoxFormatTest::testRGB(const core::String &filename) {
ASSERT_TRUE(voxelformat::loadFormat(filename, stream, sceneGraph));
EXPECT_EQ(1u, sceneGraph.size());
const core::RGBA red = core::Color::getRGBA(core::Color::Red);
const core::RGBA green = core::Color::getRGBA(core::Color::Green);
const core::RGBA blue = core::Color::getRGBA(core::Color::Blue);
voxel::Palette palette;
palette.nippon();
const core::RGBA red = palette.colors[37];
const core::RGBA green = palette.colors[149];
const core::RGBA blue = palette.colors[197];
for (const voxelformat::SceneGraphNode &node : sceneGraph) {
const voxel::RawVolume *volume = node.volume();
@ -133,13 +136,13 @@ void AbstractVoxFormatTest::testRGB(const core::String &filename) {
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 12).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 19).getMaterial());
checkColor(red, node.palette(), volume->voxel( 9, 0, 4).getColor());
checkColor(green, node.palette(), volume->voxel( 9, 0, 12).getColor());
checkColor(blue, node.palette(), volume->voxel( 9, 0, 19).getColor());
checkColor(red, node.palette(), volume->voxel( 9, 0, 4).getColor(), maxDelta);
checkColor(green, node.palette(), volume->voxel( 9, 0, 12).getColor(), maxDelta);
checkColor(blue, node.palette(), volume->voxel( 9, 0, 19).getColor(), maxDelta);
}
}
void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename, Format &srcFormat, const core::String& destFilename, Format &destFormat, bool includingColor, bool includingRegion) {
void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename, Format &srcFormat, const core::String& destFilename, Format &destFormat, bool includingColor, bool includingRegion, float maxDelta) {
voxelformat::SceneGraph sceneGraph;
EXPECT_TRUE(loadGroups(srcFilename, srcFormat, sceneGraph));
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
@ -153,7 +156,7 @@ void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename,
if (includingRegion) {
ASSERT_EQ(src->region(), loaded->region());
}
volumeComparator(*src, merged.second, *loaded, mergedLoad.second, includingColor, includingRegion);
volumeComparator(*src, merged.second, *loaded, mergedLoad.second, includingColor, includingRegion, maxDelta);
}
void AbstractVoxFormatTest::testSaveSingleVoxel(const core::String& filename, Format* format) {

View File

@ -21,7 +21,7 @@ class AbstractVoxFormatTest: public voxel::AbstractVoxelTest {
protected:
static const voxel::Voxel Empty;
void checkColor(core::RGBA, const voxel::Palette &palette, uint8_t index);
void checkColor(core::RGBA, const voxel::Palette &palette, uint8_t index, float maxDelta);
void dump(const core::String& srcFilename, const SceneGraph &sceneGraph);
void dump(const core::String& structName, voxel::RawVolume* v, const core::String& filename);
@ -32,7 +32,7 @@ protected:
Format &destFormat, bool includingColor, bool includingRegion);
void canLoad(const core::String &filename, size_t expectedVolumes = 1);
void testRGB(const core::String &filename);
void testRGB(const core::String &filename, float maxDelta = 0.001f);
void testSaveMultipleLayers(const core::String& filename, Format* format);
void testSaveSingleVoxel(const core::String& filename, Format* format);
@ -44,7 +44,7 @@ protected:
void testLoadSaveAndLoad(const core::String &srcFilename, Format &srcFormat,
const core::String &destFilename, Format &destFormat, bool includingColor,
bool includingRegion);
bool includingRegion, float maxDelta = 0.001f);
io::FilePtr open(const core::String& filename, io::FileMode mode = io::FileMode::Read) {
const io::FilePtr& file = io::filesystem()->open(core::String(filename), mode);

View File

@ -100,7 +100,7 @@ TEST_F(ConvertTest, testQbToVXM) {
TEST_F(ConvertTest, testVXMToQb) {
VXMFormat src;
QBFormat target;
testLoadSaveAndLoad("test.vxm", src, "test.qb", target, true, true);
testLoadSaveAndLoad("test.vxm", src, "test.qb", target, true, true, 0.0018);
}
TEST_F(ConvertTest, testQbToCub) {
@ -118,7 +118,7 @@ TEST_F(ConvertTest, testCubToQb) {
TEST_F(ConvertTest, testKVXToQb) {
KVXFormat src;
QBFormat target;
testLoadSaveAndLoad("test.kvx", src, "test.qb", target, true, true);
testLoadSaveAndLoad("test.kvx", src, "test.qb", target, true, true, 0.0028f);
}
TEST_F(ConvertTest, testKV6ToQb) {

View File

@ -8,6 +8,7 @@
#include "io/File.h"
#include "io/FileStream.h"
#include "voxel/MaterialColor.h"
#include "voxel/Palette.h"
#include "voxel/RawVolume.h"
#include "voxel/Voxel.h"
#include "voxelformat/VolumeFormat.h"
@ -40,7 +41,7 @@ TEST_F(VoxFormatTest, testLoadCharacter) {
for (int i = 0; i < lengthof(volumes); ++i) {
const voxel::RawVolume &v1 = *volumes[i].get();
const voxel::RawVolume &v2 = *sceneGraph[i]->volume();
volumeComparator(v1, voxel::getPalette(), v2, sceneGraph[i]->palette(), true, true);
volumeComparator(v1, voxel::getPalette(), v2, sceneGraph[i]->palette(), true, true, 0.01f);
}
}