VOXELFORMAT: reduced code duplication

master
Martin Gerhardy 2022-05-19 20:24:58 +02:00
parent e835a52fe3
commit 0a45bbb41e
21 changed files with 139 additions and 257 deletions

View File

@ -6,6 +6,7 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "core/Color.h"
#include "voxel/PagedVolumeWrapper.h"
#include "core/Log.h"
#include "voxel/PagedVolume.h"
@ -35,17 +36,13 @@ inline int countVoxels(const Volume& volume, const voxel::Voxel &voxel) {
return cnt;
}
inline bool volumeComparator(const voxel::RawVolume& volume1, const voxel::RawVolume& volume2, 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) {
const Region& r1 = volume1.region();
const Region& r2 = volume2.region();
if (includingRegion && r1 != r2) {
Log::error("regions differ: %s vs %s", r1.toString().c_str(), r2.toString().c_str());
return false;
if (includingRegion) {
ASSERT_EQ(r1, r2) << "regions differ: " << r1.toString() << " vs " << r2.toString();
}
// TODO: activate me again
includingColor = false;
const int32_t lowerX = r1.getLowerX();
const int32_t lowerY = r1.getLowerY();
const int32_t lowerZ = r1.getLowerZ();
@ -58,9 +55,6 @@ inline bool volumeComparator(const voxel::RawVolume& volume1, const voxel::RawVo
const int32_t upper2X = r2.getUpperX();
const int32_t upper2Y = r2.getUpperY();
const int32_t upper2Z = r2.getUpperZ();
core::DynamicArray<glm::vec4> materialColors;
const voxel::Palette &palette = voxel::getPalette();
palette.toVec4f(materialColors);
voxel::RawVolume::Sampler s1(volume1);
voxel::RawVolume::Sampler s2(volume2);
@ -71,26 +65,25 @@ inline bool volumeComparator(const voxel::RawVolume& volume1, const voxel::RawVo
s2.setPosition(x2, y2, z2);
const voxel::Voxel& voxel1 = s1.voxel();
const voxel::Voxel& voxel2 = s2.voxel();
if (voxel1.getMaterial() != voxel2.getMaterial()) {
Log::error("Voxel differs at %i:%i:%i in material - voxel1[%s, %i], voxel2[%s, %i]", x1, y1, z1,
voxel::VoxelTypeStr[(int)voxel1.getMaterial()], (int)voxel1.getColor(), voxel::VoxelTypeStr[(int)voxel2.getMaterial()], (int)voxel2.getColor());
return false;
}
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() << "]";
if (!includingColor) {
continue;
}
const glm::vec4& c1 = materialColors[voxel1.getColor()];
const glm::vec4& c2 = materialColors[voxel2.getColor()];
const glm::vec4& delta = c1 - c2;
if (glm::any(glm::greaterThan(delta, glm::vec4(glm::epsilon<float>())))) {
Log::error("Voxel differs at %i:%i:%i in color - voxel1[%s, %i], voxel2[%s, %i]", x1, y1, z1,
voxel::VoxelTypeStr[(int)voxel1.getMaterial()], (int)voxel1.getColor(), voxel::VoxelTypeStr[(int)voxel2.getMaterial()], (int)voxel2.getColor());
return false;
}
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, 1.0f) << "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 << "]";
}
}
}
return true;
}
inline ::std::ostream& operator<<(::std::ostream& os, const voxel::Region& region) {

View File

@ -4,6 +4,7 @@
#include "io/File.h"
#include "io/FileStream.h"
#include "io/Stream.h"
#include "voxel/MaterialColor.h"
#include "voxel/RawVolume.h"
#include "voxelformat/SceneGraph.h"
#include "voxelformat/SceneGraphNode.h"
@ -53,9 +54,10 @@ void AbstractVoxFormatTest::testFirstAndLastPaletteIndex(const core::String &fil
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
ASSERT_TRUE(format->save(&volume, filename, stream));
stream.seek(0);
std::unique_ptr<voxel::RawVolume> loaded(load(filename, stream, *format));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(volume, *loaded, false, includingRegion)) << "Volumes differ: " << volume << *loaded;
voxelformat::SceneGraph::MergedVolumePalette merged = load(filename, stream, *format);
ASSERT_NE(nullptr, merged.first);
std::unique_ptr<voxel::RawVolume> loaded(merged.first);
volumeComparator(volume, voxel::getPalette(), *loaded, merged.second, false, includingRegion);
}
void AbstractVoxFormatTest::testFirstAndLastPaletteIndexConversion(Format &srcFormat, const core::String& destFilename, Format &destFormat, bool includingColor, bool includingRegion) {
@ -66,21 +68,33 @@ void AbstractVoxFormatTest::testFirstAndLastPaletteIndexConversion(Format &srcFo
io::BufferedReadWriteStream srcFormatStream(10 * 1024 * 1024);
EXPECT_TRUE(srcFormat.save(&original, destFilename, srcFormatStream)) << "Could not save " << destFilename;
srcFormatStream.seek(0);
std::unique_ptr<voxel::RawVolume> origReloaded(load(destFilename, srcFormatStream, srcFormat));
voxelformat::SceneGraph::MergedVolumePalette merged = load(destFilename, srcFormatStream, srcFormat);
ASSERT_NE(nullptr, merged.first);
std::unique_ptr<voxel::RawVolume> origReloaded(merged.first);
if (includingRegion) {
ASSERT_EQ(original.region(), origReloaded->region());
}
EXPECT_TRUE(volumeComparator(original, *origReloaded, includingColor, includingRegion)) << "Volumes differ: " << original << *origReloaded;
volumeComparator(original, voxel::getPalette(), *origReloaded, merged.second, includingColor, includingRegion);
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
EXPECT_TRUE(destFormat.save(origReloaded.get(), destFilename, stream)) << "Could not save " << destFilename;
stream.seek(0);
std::unique_ptr<voxel::RawVolume> loaded(load(destFilename, stream, destFormat));
voxelformat::SceneGraph::MergedVolumePalette merged2 = load(destFilename, stream, destFormat);
std::unique_ptr<voxel::RawVolume> loaded(merged2.first);
ASSERT_NE(nullptr, loaded) << "Could not load " << destFilename;
if (includingRegion) {
ASSERT_EQ(original.region(), loaded->region());
}
EXPECT_TRUE(volumeComparator(original, *loaded, includingColor, includingRegion)) << "Volumes differ: " << original << *loaded;
volumeComparator(original, voxel::getPalette(), *loaded, merged2.second, includingColor, includingRegion);
}
void AbstractVoxFormatTest::canLoad(const core::String &filename, size_t expectedVolumes) {
voxelformat::SceneGraph sceneGraph;
const io::FilePtr& file = open(filename);
ASSERT_TRUE(file->validHandle()) << "Could not open " << filename;
io::FileStream stream(file);
ASSERT_TRUE(voxelformat::loadFormat(filename, stream, sceneGraph)) << "Could not load " << filename;
ASSERT_EQ(expectedVolumes, sceneGraph.size());
}
void AbstractVoxFormatTest::testRGB(const core::String &filename) {
@ -89,7 +103,7 @@ void AbstractVoxFormatTest::testRGB(const core::String &filename) {
ASSERT_TRUE(file->validHandle());
io::FileStream stream(file);
ASSERT_TRUE(voxelformat::loadFormat(filename, stream, sceneGraph));
EXPECT_EQ(1, sceneGraph.size());
EXPECT_EQ(1u, sceneGraph.size());
for (const voxelformat::SceneGraphNode &node : sceneGraph) {
const voxel::RawVolume *volume = node.volume();
@ -129,14 +143,44 @@ void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename,
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
EXPECT_TRUE(destFormat.saveGroups(sceneGraph, destFilename, stream)) << "Could not save " << destFilename;
stream.seek(0);
std::unique_ptr<voxel::RawVolume> loaded(load(destFilename, stream, destFormat));
voxelformat::SceneGraph::MergedVolumePalette mergedLoad = load(destFilename, stream, destFormat);
std::unique_ptr<voxel::RawVolume> loaded(mergedLoad.first);
ASSERT_NE(nullptr, loaded) << "Could not load " << destFilename;
SceneGraph::MergedVolumePalette merged = sceneGraph.merge();
voxelformat::SceneGraph::MergedVolumePalette merged = sceneGraph.merge();
std::unique_ptr<voxel::RawVolume> src(merged.first);
if (includingRegion) {
ASSERT_EQ(src->region(), loaded->region());
}
EXPECT_TRUE(volumeComparator(*src, *loaded, includingColor, includingRegion)) << "Volumes differ: " << *src << *loaded;
volumeComparator(*src, merged.second, *loaded, mergedLoad.second, includingColor, includingRegion);
}
void AbstractVoxFormatTest::testSaveSingleVoxel(const core::String& filename, Format* format) {
voxel::Region region(glm::ivec3(0), glm::ivec3(0));
voxel::RawVolume original(region);
original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1));
io::BufferedReadWriteStream bufferedStream(10 * 1024 * 1024);
ASSERT_TRUE(format->save(&original, filename, bufferedStream));
bufferedStream.seek(0);
voxelformat::SceneGraph::MergedVolumePalette mergedLoad = load(filename, bufferedStream, *format);
std::unique_ptr<voxel::RawVolume> loaded(mergedLoad.first);
ASSERT_NE(nullptr, loaded) << "Could not load single voxel file " << filename;
volumeComparator(original, voxel::getPalette(), *loaded, mergedLoad.second, true, true);
}
void AbstractVoxFormatTest::testSaveSmallVolume(const core::String& filename, Format* format) {
voxel::Region region(glm::ivec3(0), glm::ivec3(0, 1, 1));
voxel::RawVolume original(region);
ASSERT_TRUE(original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
ASSERT_TRUE(original.setVoxel(0, 0, 1, createVoxel(voxel::VoxelType::Generic, 200)));
ASSERT_TRUE(original.setVoxel(0, 1, 1, createVoxel(voxel::VoxelType::Generic, 201)));
ASSERT_TRUE(original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 202)));
io::BufferedReadWriteStream bufferedStream(10 * 1024 * 1024);
ASSERT_TRUE(format->save(&original, filename, bufferedStream));
bufferedStream.seek(0);
voxelformat::SceneGraph::MergedVolumePalette mergedLoad = load(filename, bufferedStream, *format);
std::unique_ptr<voxel::RawVolume> loaded(mergedLoad.first);
ASSERT_NE(nullptr, loaded) << "Could not load single voxel file " << filename;
volumeComparator(original, voxel::getPalette(), *loaded, mergedLoad.second, true, true);
}
void AbstractVoxFormatTest::testSaveMultipleLayers(const core::String &filename, Format *format) {
@ -149,26 +193,24 @@ void AbstractVoxFormatTest::testSaveMultipleLayers(const core::String &filename,
EXPECT_TRUE(layer2.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
EXPECT_TRUE(layer3.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
EXPECT_TRUE(layer4.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
SceneGraph sceneGraph;
SceneGraphNode node1;
voxelformat::SceneGraph sceneGraph;
voxelformat::SceneGraphNode node1;
node1.setVolume(&layer1, false);
SceneGraphNode node2;
voxelformat::SceneGraphNode node2;
node2.setVolume(&layer2, false);
SceneGraphNode node3;
voxelformat::SceneGraphNode node3;
node3.setVolume(&layer3, false);
SceneGraphNode node4;
voxelformat::SceneGraphNode node4;
node4.setVolume(&layer4, false);
sceneGraph.emplace(core::move(node1));
sceneGraph.emplace(core::move(node2));
sceneGraph.emplace(core::move(node3));
sceneGraph.emplace(core::move(node4));
const io::FilePtr &sfile = open(filename, io::FileMode::SysWrite);
io::FileStream sstream(sfile);
ASSERT_TRUE(format->saveGroups(sceneGraph, sfile->name(), sstream));
SceneGraph sceneGraphLoad;
const io::FilePtr &file = open(filename);
io::FileStream stream(file);
EXPECT_TRUE(format->loadGroups(file->name(), stream, sceneGraphLoad));
io::BufferedReadWriteStream bufferedStream(10 * 1024 * 1024);
ASSERT_TRUE(format->saveGroups(sceneGraph, filename, bufferedStream));
bufferedStream.seek(0);
voxelformat::SceneGraph sceneGraphLoad;
EXPECT_TRUE(format->loadGroups(filename, bufferedStream, sceneGraphLoad));
EXPECT_EQ(sceneGraphLoad.size(), sceneGraph.size());
}
@ -176,17 +218,15 @@ void AbstractVoxFormatTest::testSave(const core::String &filename, Format *forma
voxel::Region region(glm::ivec3(0), glm::ivec3(0));
voxel::RawVolume layer1(region);
EXPECT_TRUE(layer1.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
SceneGraph sceneGraph;
SceneGraphNode node1;
voxelformat::SceneGraph sceneGraph;
voxelformat::SceneGraphNode node1;
node1.setVolume(&layer1, false);
sceneGraph.emplace(core::move(node1));
const io::FilePtr &sfile = open(filename, io::FileMode::SysWrite);
io::FileStream sstream(sfile);
ASSERT_TRUE(format->saveGroups(sceneGraph, sfile->name(), sstream));
SceneGraph sceneGraphLoad;
const io::FilePtr &file = open(filename);
io::FileStream stream(file);
EXPECT_TRUE(format->loadGroups(file->name(), stream, sceneGraphLoad));
io::BufferedReadWriteStream bufferedStream(10 * 1024 * 1024);
ASSERT_TRUE(format->saveGroups(sceneGraph, filename, bufferedStream));
voxelformat::SceneGraph sceneGraphLoad;
bufferedStream.seek(0);
EXPECT_TRUE(format->loadGroups(filename, bufferedStream, sceneGraphLoad));
EXPECT_EQ(sceneGraphLoad.size(), sceneGraph.size());
}
@ -249,9 +289,11 @@ void AbstractVoxFormatTest::testSaveLoadVoxel(const core::String &filename, Form
#endif
readStream->seek(0);
std::unique_ptr<voxel::RawVolume> loaded(load(filename, *readStream, *format));
voxelformat::SceneGraph::MergedVolumePalette merged = load(filename, *readStream, *format);
std::unique_ptr<voxel::RawVolume> loaded(merged.first);
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(original, *loaded, true, true)) << "Volumes differ: " << original << *loaded;
volumeComparator(original, voxel::getPalette(), *loaded, merged.second, true, true);
}
} // namespace voxel

View File

@ -28,9 +28,12 @@ protected:
void testFirstAndLastPaletteIndexConversion(Format &srcFormat, const core::String &destFilename,
Format &destFormat, bool includingColor, bool includingRegion);
void canLoad(const core::String &filename, size_t expectedVolumes = 1);
void testRGB(const core::String &filename);
void testSaveMultipleLayers(const core::String& filename, Format* format);
void testSaveSingleVoxel(const core::String& filename, Format* format);
void testSaveSmallVolume(const core::String& filename, Format* format);
void testSave(const core::String& filename, Format* format);
@ -45,22 +48,20 @@ protected:
return file;
}
voxel::RawVolume* load(const core::String& filename, io::SeekableReadStream& stream, Format& format) {
SceneGraph::MergedVolumePalette load(const core::String& filename, io::SeekableReadStream& stream, Format& format) {
SceneGraph sceneGraph;
if (!format.loadGroups(filename, stream, sceneGraph)) {
return nullptr;
return SceneGraph::MergedVolumePalette{};
}
const SceneGraph::MergedVolumePalette &merged = sceneGraph.merge();
return merged.first;
return sceneGraph.merge();
}
voxel::RawVolume* load(const core::String& filename, Format& format) {
SceneGraph::MergedVolumePalette load(const core::String& filename, Format& format) {
SceneGraph sceneGraph;
if (!loadGroups(filename, format, sceneGraph)) {
return nullptr;
return SceneGraph::MergedVolumePalette{};
}
const SceneGraph::MergedVolumePalette &merged = sceneGraph.merge();
return merged.first;
return sceneGraph.merge();
}
bool loadGroups(const core::String& filename, Format& format, voxelformat::SceneGraph &sceneGraph) {

View File

@ -11,9 +11,7 @@ class AoSVXLFormatTest: public AbstractVoxFormatTest {
};
TEST_F(AoSVXLFormatTest, testLoad) {
AoSVXLFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("aceofspades.vxl", f));
ASSERT_NE(nullptr, volume) << "Could not load ace of spades file";
canLoad("aceofspades.vxl");
}
TEST_F(AoSVXLFormatTest, testLoadPalette) {

View File

@ -11,9 +11,7 @@ class BinVoxFormatTest: public AbstractVoxFormatTest {
};
TEST_F(BinVoxFormatTest, testLoad) {
BinVoxFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("test.binvox", f));
ASSERT_NE(nullptr, volume) << "Could not load binvox file";
canLoad("test.binvox");
}
TEST_F(BinVoxFormatTest, testSaveSmallVoxel) {

View File

@ -11,9 +11,7 @@ class CSMFormatTest: public AbstractVoxFormatTest {
};
TEST_F(CSMFormatTest, testLoad) {
CSMFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("chronovox-studio.csm", f));
ASSERT_NE(nullptr, volume) << "Could not load volume";
canLoad("chronovox-studio.csm");
}
}

View File

@ -12,9 +12,7 @@ class CubFormatTest: public AbstractVoxFormatTest {
};
TEST_F(CubFormatTest, testLoad) {
CubFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("cw.cub", f));
ASSERT_NE(nullptr, volume) << "Could not load volume";
canLoad("cw.cub");
}
TEST_F(CubFormatTest, testLoadPalette) {

View File

@ -11,9 +11,7 @@ class GoxFormatTest: public AbstractVoxFormatTest {
};
TEST_F(GoxFormatTest, testLoad) {
GoxFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("test.gox", f));
ASSERT_NE(nullptr, volume) << "Could not load volume";
canLoad("test.gox");
}
TEST_F(GoxFormatTest, testSaveSmallVoxel) {

View File

@ -11,9 +11,7 @@ class KV6FormatTest: public AbstractVoxFormatTest {
};
TEST_F(KV6FormatTest, testLoad) {
KV6Format f;
std::unique_ptr<voxel::RawVolume> volume(load("test.kv6", f));
ASSERT_NE(nullptr, volume) << "Could not load volume";
canLoad("test.kv6");
}
}

View File

@ -11,9 +11,7 @@ class KVXFormatTest: public AbstractVoxFormatTest {
};
TEST_F(KVXFormatTest, testLoad) {
KVXFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("test.kvx", f));
ASSERT_NE(nullptr, volume) << "Could not load volume";
canLoad("test.kvx");
}
}

View File

@ -12,34 +12,16 @@ namespace voxelformat {
class MCRFormatTest: public AbstractVoxFormatTest {
};
TEST_F(MCRFormatTest, DISABLED_testLoad117Compare) {
MCRFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("r.0.-2.mca", f));
ASSERT_NE(nullptr, volume) << "Could not load mca volume";
QBFormat f2;
std::unique_ptr<voxel::RawVolume> volumeqb(load("r.0.-2.qb", f2));
ASSERT_NE(nullptr, volumeqb) << "Could not load qb volume";
ASSERT_TRUE(volumeComparator(*volume.get(), *volumeqb.get(), true, true));
}
TEST_F(MCRFormatTest, testLoad117) {
MCRFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("r.0.-2.mca", f));
ASSERT_NE(nullptr, volume) << "Could not load mca volume";
canLoad("r.0.-2.mca", 128);
}
TEST_F(MCRFormatTest, testLoad110) {
MCRFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("minecraft_110.mca", f));
ASSERT_NE(nullptr, volume) << "Could not load mca volume";
canLoad("minecraft_110.mca", 1024);
}
TEST_F(MCRFormatTest, DISABLED_testLoad113) {
MCRFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("minecraft_113.mca", f));
ASSERT_NE(nullptr, volume) << "Could not load mca volume";
canLoad("minecraft_113.mca");
}
}

View File

@ -13,9 +13,7 @@ class QBCLFormatTest: public AbstractVoxFormatTest {
};
TEST_F(QBCLFormatTest, testLoad) {
QBCLFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("qubicle.qbcl", f));
ASSERT_NE(nullptr, volume) << "Could not load qbcl file";
canLoad("qubicle.qbcl");
}
TEST_F(QBCLFormatTest, testSaveSmallVoxel) {

View File

@ -12,21 +12,7 @@ class QBFormatTest: public AbstractVoxFormatTest {
};
TEST_F(QBFormatTest, testLoad) {
QBFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("qubicle.qb", f));
voxel::VolumePrintThreshold = 40;
ASSERT_NE(nullptr, volume) << "Could not load qb file";
// feet
//EXPECT_NE(Empty, volume->voxel(-3, 0, -1)) << *volume;
//EXPECT_NE(Empty, volume->voxel(-6, 0, -1)) << *volume;
EXPECT_EQ(Empty, volume->voxel(-3, 5, -1)) << *volume;
EXPECT_EQ(Empty, volume->voxel(-6, 5, -1)) << *volume;
//EXPECT_NE(Empty, volume->voxel(-3, 1, 2)) << *volume;
//EXPECT_NE(Empty, volume->voxel(-6, 1, 2)) << *volume;
EXPECT_EQ(Empty, volume->voxel(-3, 4, -1)) << *volume;
EXPECT_EQ(Empty, volume->voxel(-6, 4, -1)) << *volume;
canLoad("qubicle.qb");
}
TEST_F(QBFormatTest, testLoadRGB) {
@ -35,16 +21,7 @@ TEST_F(QBFormatTest, testLoadRGB) {
TEST_F(QBFormatTest, testSaveSingleVoxel) {
QBFormat f;
voxel::Region region(glm::ivec3(0), glm::ivec3(0));
voxel::RawVolume original(region);
original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1));
const io::FilePtr &file = open("qubicle-singlevoxelsavetest.qb", io::FileMode::SysWrite);
io::FileStream stream(file);
ASSERT_TRUE(f.save(&original, file->name(), stream));
f = QBFormat();
std::unique_ptr<voxel::RawVolume> loaded(load("qubicle-singlevoxelsavetest.qb", f));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(original, *loaded, true, true)) << "Volumes differ: " << original << *loaded;
testSaveSingleVoxel("qubicle-singlevoxelsavetest.qb", &f);
}
TEST_F(QBFormatTest, testSaveSmallVoxel) {
@ -59,15 +36,7 @@ TEST_F(QBFormatTest, testSaveMultipleLayers) {
TEST_F(QBFormatTest, testLoadSave) {
QBFormat f;
std::unique_ptr<voxel::RawVolume> original(load("qubicle.qb", f));
ASSERT_NE(nullptr, original);
const io::FilePtr &sfile = open("qubicle-savetest.qb", io::FileMode::SysWrite);
io::FileStream sstream(sfile);
ASSERT_TRUE(f.save(original.get(), sfile->name(), sstream));
ASSERT_TRUE(open("qubicle-savetest.qb")->length() > 177);
f = QBFormat();
std::unique_ptr<voxel::RawVolume> loaded(load("qubicle-savetest.qb", f));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(*original, *loaded, true, true)) << "Volumes differ: " << *original << *loaded;
testLoadSaveAndLoad("qubicle.qb", f, "qubicle-savetest.qb", f, true, true);
}
}

View File

@ -13,23 +13,12 @@ class QBTFormatTest: public AbstractVoxFormatTest {
};
TEST_F(QBTFormatTest, testLoad) {
QBTFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("qubicle.qbt", f));
ASSERT_NE(nullptr, volume) << "Could not load qbt file";
canLoad("qubicle.qbt");
}
TEST_F(QBTFormatTest, testSaveSingleVoxel) {
QBTFormat f;
voxel::Region region(glm::ivec3(0), glm::ivec3(0));
voxel::RawVolume original(region);
ASSERT_TRUE(original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
const io::FilePtr &file = open("qubicle-singlevoxelsavetest.qbt", io::FileMode::SysWrite);
io::FileStream stream(file);
ASSERT_TRUE(f.save(&original, file->name(), stream));
f = QBTFormat();
std::unique_ptr<voxel::RawVolume> loaded(load("qubicle-singlevoxelsavetest.qbt", f));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(original, *loaded, true, true)) << "Volumes differ: " << original << *loaded;
testSaveSingleVoxel("qubicle-singlevoxelsavetest.qb", &f);
}
TEST_F(QBTFormatTest, testSaveSmallVoxel) {
@ -44,16 +33,7 @@ TEST_F(QBTFormatTest, testSaveMultipleLayers) {
TEST_F(QBTFormatTest, testSave) {
QBTFormat f;
std::unique_ptr<voxel::RawVolume> original(load("qubicle.qbt", f));
ASSERT_NE(nullptr, original);
const io::FilePtr &file = open("qubicle-savetest.qbt", io::FileMode::SysWrite);
io::FileStream stream(file);
ASSERT_TRUE(f.save(original.get(), file->name(), stream));
EXPECT_TRUE(open("qubicle-savetest.qbt")->length() > 200);
f = QBTFormat();
std::unique_ptr<voxel::RawVolume> loaded(load("qubicle-savetest.qbt", f));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(*original, *loaded, true, true)) << "Volumes differ: " << *original << *loaded;
testLoadSaveAndLoad("qubicle.qbt", f, "qubicle-savetest.qbt", f, true, true);
}
TEST_F(QBTFormatTest, testResaveMultipleLayers) {

View File

@ -12,15 +12,11 @@ class QEFFormatTest: public AbstractVoxFormatTest {
};
TEST_F(QEFFormatTest, testLoad) {
QEFFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("qubicle.qef", f));
ASSERT_NE(nullptr, volume) << "Could not load qef file";
canLoad("qubicle.qef");
}
TEST_F(QEFFormatTest, testLoad2) {
QEFFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("testload.qef", f));
ASSERT_NE(nullptr, volume) << "Could not load qef file";
canLoad("testload.qef");
}
TEST_F(QEFFormatTest, testLoadRGB) {

View File

@ -12,10 +12,8 @@ namespace voxelformat {
class SchematicFormatTest : public AbstractVoxFormatTest {};
TEST_F(SchematicFormatTest, DISABLED_testLoad) {
SchematicFormat f;
// https://www.planetminecraft.com/project/viking-island-4911284/
std::unique_ptr<voxel::RawVolume> volume(load("viking_island.schematic", f));
ASSERT_NE(nullptr, volume) << "Could not load schematic file";
canLoad("viking_island.schematic");
}
TEST_F(SchematicFormatTest, DISABLED_testSaveSmallVoxel) {

View File

@ -11,9 +11,7 @@ class VXLFormatTest: public AbstractVoxFormatTest {
};
TEST_F(VXLFormatTest, testLoad) {
VXLFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("cc.vxl", f));
ASSERT_NE(nullptr, volume) << "Could not load vxl file";
canLoad("cc.vxl");
}
TEST_F(VXLFormatTest, testLoadRGB) {
@ -22,20 +20,7 @@ TEST_F(VXLFormatTest, testLoadRGB) {
TEST_F(VXLFormatTest, testSave) {
VXLFormat f;
voxel::RawVolume* loadedVolume = load("cc.vxl", f);
ASSERT_NE(nullptr, loadedVolume) << "Could not load vxl file";
const io::FilePtr& file = open("cc-save.vxl", io::FileMode::SysWrite);
io::FileStream stream(file);
ASSERT_TRUE(f.save(loadedVolume, file->name(), stream));
f = VXLFormat();
voxel::RawVolume *savedVolume = load("cc-save.vxl", f);
EXPECT_NE(nullptr, savedVolume) << "Could not load saved vxl file " << file->name();
if (savedVolume) {
EXPECT_TRUE(volumeComparator(*savedVolume, *loadedVolume, true, true)) << "Volumes differ: " << *savedVolume << *loadedVolume;
delete savedVolume;
}
delete loadedVolume;
testLoadSaveAndLoad("cc.vxl", f, "cc-save.vxl", f, true, true);
}
TEST_F(VXLFormatTest, testSaveSmallVoxel) {

View File

@ -15,32 +15,16 @@ TEST_F(VXMFormatTest, DISABLED_testLoadRGB) {
}
TEST_F(VXMFormatTest, testLoad) {
VXMFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("test.vxm", f));
ASSERT_NE(nullptr, volume) << "Could not load vxm file";
canLoad("test.vxm");
}
TEST_F(VXMFormatTest, testLoadFileCreatedBySandboxVoxeditVersion12) {
VXMFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("test2.vxm", f));
ASSERT_NE(nullptr, volume) << "Could not load vxm file";
canLoad("test2.vxm");
}
TEST_F(VXMFormatTest, testSaveVerySmallVoxel) {
VXMFormat f;
voxel::Region region(glm::ivec3(0), glm::ivec3(0, 1, 1));
voxel::RawVolume original(region);
ASSERT_TRUE(original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
ASSERT_TRUE(original.setVoxel(0, 0, 1, createVoxel(voxel::VoxelType::Generic, 200)));
ASSERT_TRUE(original.setVoxel(0, 1, 1, createVoxel(voxel::VoxelType::Generic, 201)));
ASSERT_TRUE(original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 202)));
const io::FilePtr &file = open("verysmallvolumesavetest.vxm", io::FileMode::SysWrite);
io::FileStream stream(file);
ASSERT_TRUE(f.save(&original, file->name(), stream));
f = VXMFormat();
std::unique_ptr<voxel::RawVolume> loaded(load("verysmallvolumesavetest.vxm", f));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(original, *loaded, true, true)) << "Volumes differ: " << original << *loaded;
testSaveSmallVolume("verysmallvolumesavetest.vxm", &f);
}
TEST_F(VXMFormatTest, testSaveSmallVoxel) {
@ -48,21 +32,4 @@ TEST_F(VXMFormatTest, testSaveSmallVoxel) {
testSaveLoadVoxel("sandbox-smallvolumesavetest.vxm", &f);
}
TEST_F(VXMFormatTest, testSaveRLE) {
VXMFormat f;
voxel::Region region(glm::ivec3(0), glm::ivec3(1));
voxel::RawVolume original(region);
ASSERT_TRUE(original.setVoxel(0, 0, 0, createVoxel(voxel::VoxelType::Generic, 1)));
ASSERT_TRUE(original.setVoxel(0, 0, 1, createVoxel(voxel::VoxelType::Generic, 1)));
ASSERT_TRUE(original.setVoxel(0, 1, 1, createVoxel(voxel::VoxelType::Generic, 127)));
ASSERT_TRUE(original.setVoxel(0, 1, 0, createVoxel(voxel::VoxelType::Generic, 127)));
const io::FilePtr &file = open("smallvolumesavetest.vxm", io::FileMode::SysWrite);
io::FileStream stream(file);
ASSERT_TRUE(f.save(&original, file->name(), stream));
f = VXMFormat();
std::unique_ptr<voxel::RawVolume> loaded(load("smallvolumesavetest.vxm", f));
ASSERT_NE(nullptr, loaded);
EXPECT_TRUE(volumeComparator(original, *loaded, true, true)) << "Volumes differ: " << original << *loaded;
}
}

View File

@ -7,6 +7,7 @@
#include "io/BufferedReadWriteStream.h"
#include "io/File.h"
#include "io/FileStream.h"
#include "voxel/MaterialColor.h"
#include "voxel/RawVolume.h"
#include "voxel/Voxel.h"
#include "voxelformat/VolumeFormat.h"
@ -19,9 +20,7 @@ namespace voxelformat {
class VoxFormatTest : public AbstractVoxFormatTest {};
TEST_F(VoxFormatTest, testLoad) {
VoxFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("magicavoxel.vox", f));
ASSERT_NE(nullptr, volume) << "Could not load vox file";
canLoad("magicavoxel.vox");
}
TEST_F(VoxFormatTest, testLoadCharacter) {
@ -41,7 +40,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();
EXPECT_TRUE(volumeComparator(v1, v2, true, true)) << "Volumes differ: " << v1 << v2;
volumeComparator(v1, voxel::getPalette(), v2, sceneGraph[i]->palette(), true, true);
}
}
@ -59,7 +58,7 @@ TEST_F(VoxFormatTest, testLoadGlasses) {
for (int i = 0; i < lengthof(volumes); ++i) {
const voxel::RawVolume &v1 = *volumes[i].get();
const voxel::RawVolume &v2 = *sceneGraph[i]->volume();
EXPECT_TRUE(volumeComparator(v1, v2, true, true)) << "Volumes differ: " << v1 << v2;
volumeComparator(v1, voxel::getPalette(), v2, sceneGraph[i]->palette(), true, true);
}
}
@ -96,7 +95,7 @@ TEST_F(VoxFormatTest, testLoad8OnTop) {
for (int i = 0; i < lengthof(volumes); ++i) {
const voxel::RawVolume &v1 = *volumes[i].get();
const voxel::RawVolume &v2 = *sceneGraph[i]->volume();
EXPECT_TRUE(volumeComparator(v1, v2, true, true)) << "Volumes differ: " << v1 << v2;
volumeComparator(v1, voxel::getPalette(), v2, sceneGraph[i]->palette(), true, true);
}
}
@ -143,21 +142,7 @@ TEST_F(VoxFormatTest, testSaveBigVolume) {
TEST_F(VoxFormatTest, testSave) {
VoxFormat f;
voxel::RawVolume *loadedVolume = load("magicavoxel.vox", f);
ASSERT_NE(nullptr, loadedVolume) << "Could not load vox file";
const io::FilePtr &fileSave = open("magicavoxel-save.vox", io::FileMode::SysWrite);
io::FileStream sstream(fileSave);
EXPECT_TRUE(f.save(loadedVolume, fileSave->name(), sstream));
const io::FilePtr &fileLoadAfterSave = open("magicavoxel-save.vox");
io::FileStream stream2(fileLoadAfterSave);
voxel::RawVolume *savedVolume = load(fileLoadAfterSave->name(), stream2, f);
EXPECT_NE(nullptr, savedVolume) << "Could not load saved vox file";
if (savedVolume) {
EXPECT_TRUE(volumeComparator(*savedVolume, *loadedVolume, true, true)) << "Volumes differ: " << *savedVolume << *loadedVolume;
delete savedVolume;
}
delete loadedVolume;
testLoadSaveAndLoad("magicavoxel.vox", f, "magicavoxel-save.vox", f, true, true);
}
} // namespace voxel

View File

@ -3,6 +3,7 @@
*/
#include "app/App.h"
#include "core/ScopedPtr.h"
#include "io/FileStream.h"
#include "io/Filesystem.h"
#include "app/tests/AbstractTest.h"
@ -38,10 +39,9 @@ protected:
voxelformat::SceneGraph sceneGraph;
ASSERT_TRUE(format.loadGroups(file->fileName(), stream, sceneGraph));
voxelformat::SceneGraph::MergedVolumePalette merged = sceneGraph.merge();
voxel::RawVolume* v = merged.first;
core::ScopedPtr<voxel::RawVolume> v( merged.first);
ASSERT_NE(nullptr, v) << "Can't load " << filename;
EXPECT_TRUE(volumeComparator(v, *_volume, true, true)) << "Volumes differ: " << v << *_volume;
delete v;
volumeComparator(*v, voxel::getPalette(), *_volume, voxel::getPalette(), true, true);
}
public:
void SetUp() override {

View File

@ -3,6 +3,7 @@
*/
#include "app/tests/AbstractTest.h"
#include "voxel/MaterialColor.h"
#include "voxel/tests/TestHelper.h"
#include "voxelutil/VolumeRotator.h"
@ -86,8 +87,7 @@ TEST_F(VolumeRotatorTest, DISABLED_testRotate90_FourTimes) {
EXPECT_EQ(rotatedRegion, region) << "Rotating by 360 degree should increase the size of the volume "
<< str(rotatedRegion) << " " << str(region);
EXPECT_TRUE(volumeComparator(*rotated, smallVolume, true, true))
<< "Expected to get the same volume after 360 degree rotation, but volumes differ: " << *rotated << smallVolume;
volumeComparator(*rotated, voxel::getPalette(), smallVolume, voxel::getPalette(), true, true);
delete rotated;
}
}