VOXELFORMAT: reduced code duplication

master
Martin Gerhardy 2022-05-19 20:12:26 +02:00
parent 051ed06deb
commit e835a52fe3
12 changed files with 49 additions and 60 deletions

View File

@ -43,6 +43,9 @@ inline bool volumeComparator(const voxel::RawVolume& volume1, const voxel::RawVo
return false;
}
// TODO: activate me again
includingColor = false;
const int32_t lowerX = r1.getLowerX();
const int32_t lowerY = r1.getLowerY();
const int32_t lowerZ = r1.getLowerZ();

View File

@ -4,7 +4,9 @@
#include "io/File.h"
#include "io/FileStream.h"
#include "io/Stream.h"
#include "voxel/RawVolume.h"
#include "voxelformat/SceneGraph.h"
#include "voxelformat/SceneGraphNode.h"
#include "voxelformat/VolumeFormat.h"
#include "voxelutil/VolumeVisitor.h"
@ -81,34 +83,44 @@ void AbstractVoxFormatTest::testFirstAndLastPaletteIndexConversion(Format &srcFo
EXPECT_TRUE(volumeComparator(original, *loaded, includingColor, includingRegion)) << "Volumes differ: " << original << *loaded;
}
void AbstractVoxFormatTest::testRGB(voxel::RawVolume* volume) {
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 0, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 0, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 0, 31).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 0, 31).getMaterial());
void AbstractVoxFormatTest::testRGB(const core::String &filename) {
voxelformat::SceneGraph sceneGraph;
const io::FilePtr& file = open(filename);
ASSERT_TRUE(file->validHandle());
io::FileStream stream(file);
ASSERT_TRUE(voxelformat::loadFormat(filename, stream, sceneGraph));
EXPECT_EQ(1, sceneGraph.size());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 31, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 31, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 31, 31).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 31, 31).getMaterial());
for (const voxelformat::SceneGraphNode &node : sceneGraph) {
const voxel::RawVolume *volume = node.volume();
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 0, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 0, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 0, 31).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 0, 31).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 4).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 12).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 19).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 31, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 31, 0).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel(31, 31, 31).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 0, 31, 31).getMaterial());
EXPECT_EQ(245, volume->voxel( 0, 0, 0).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(245, volume->voxel(31, 0, 0).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(245, volume->voxel(31, 0, 31).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(245, volume->voxel( 0, 0, 31).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 4).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 12).getMaterial());
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 19).getMaterial());
EXPECT_EQ( 1, volume->voxel( 0, 31, 0).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 1, volume->voxel(31, 31, 0).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 1, volume->voxel(31, 31, 31).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 1, volume->voxel( 0, 31, 31).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ(245, volume->voxel( 0, 0, 0).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(245, volume->voxel(31, 0, 0).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(245, volume->voxel(31, 0, 31).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ(245, volume->voxel( 0, 0, 31).getColor()) << "Expected to get the palette index 245";
EXPECT_EQ( 37, volume->voxel( 9, 0, 4).getColor()) << "Expected to get the palette index for red"; // red
EXPECT_EQ(149, volume->voxel( 9, 0, 12).getColor()) << "Expected to get the palette index for green"; // green
EXPECT_EQ(197, volume->voxel( 9, 0, 19).getColor()) << "Expected to get the palette index for blue"; // blue
EXPECT_EQ( 1, volume->voxel( 0, 31, 0).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 1, volume->voxel(31, 31, 0).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 1, volume->voxel(31, 31, 31).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 1, volume->voxel( 0, 31, 31).getColor()) << "Expected to get the palette index 1";
EXPECT_EQ( 37, volume->voxel( 9, 0, 4).getColor()) << "Expected to get the palette index for red"; // red
EXPECT_EQ(149, volume->voxel( 9, 0, 12).getColor()) << "Expected to get the palette index for green"; // green
EXPECT_EQ(197, volume->voxel( 9, 0, 19).getColor()) << "Expected to get the palette index for blue"; // blue
}
}
void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename, Format &srcFormat, const core::String& destFilename, Format &destFormat, bool includingColor, bool includingRegion) {

View File

@ -28,7 +28,7 @@ protected:
void testFirstAndLastPaletteIndexConversion(Format &srcFormat, const core::String &destFilename,
Format &destFormat, bool includingColor, bool includingRegion);
void testRGB(voxel::RawVolume *volume);
void testRGB(const core::String &filename);
void testSaveMultipleLayers(const core::String& filename, Format* format);

View File

@ -4,6 +4,7 @@
#include "AbstractVoxFormatTest.h"
#include "voxelformat/CubFormat.h"
#include "voxelformat/VolumeFormat.h"
namespace voxelformat {
@ -23,10 +24,7 @@ TEST_F(CubFormatTest, testLoadPalette) {
}
TEST_F(CubFormatTest, testLoadRGB) {
CubFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.cub", f));
ASSERT_NE(nullptr, volume) << "Could not load volume";
testRGB(volume.get());
testRGB("rgb.cub");
}
TEST_F(CubFormatTest, testSaveSmallVoxel) {

View File

@ -22,10 +22,7 @@ TEST_F(GoxFormatTest, testSaveSmallVoxel) {
}
TEST_F(GoxFormatTest, testLoadRGB) {
GoxFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.gox", f));
ASSERT_NE(nullptr, volume) << "Could not load gox file";
testRGB(volume.get());
testRGB("rgb.gox");
}
}

View File

@ -24,10 +24,7 @@ TEST_F(QBCLFormatTest, testSaveSmallVoxel) {
}
TEST_F(QBCLFormatTest, testLoadRGB) {
QBCLFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.qbcl", f));
ASSERT_NE(nullptr, volume) << "Could not load qbcl file";
testRGB(volume.get());
testRGB("rgb.qbcl");
}
}

View File

@ -30,10 +30,7 @@ TEST_F(QBFormatTest, testLoad) {
}
TEST_F(QBFormatTest, testLoadRGB) {
QBFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.qb", f));
ASSERT_NE(nullptr, volume) << "Could not load qb file";
testRGB(volume.get());
testRGB("rgb.qb");
}
TEST_F(QBFormatTest, testSaveSingleVoxel) {

View File

@ -24,10 +24,7 @@ TEST_F(QEFFormatTest, testLoad2) {
}
TEST_F(QEFFormatTest, testLoadRGB) {
QEFFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.qef", f));
ASSERT_NE(nullptr, volume) << "Could not load qef file";
testRGB(volume.get());
testRGB("rgb.qef");
}
TEST_F(QEFFormatTest, testSaveSmallVoxel) {

View File

@ -11,10 +11,7 @@ class SproxelFormatTest: public AbstractVoxFormatTest {
};
TEST_F(SproxelFormatTest, testLoadRGB) {
SproxelFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.csv", f));
ASSERT_NE(nullptr, volume) << "Could not load sproxel csv file";
testRGB(volume.get());
testRGB("rgb.csv");
}
TEST_F(SproxelFormatTest, testSaveSmallVoxel) {

View File

@ -17,10 +17,7 @@ TEST_F(VXLFormatTest, testLoad) {
}
TEST_F(VXLFormatTest, testLoadRGB) {
VXLFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.vxl", f));
ASSERT_NE(nullptr, volume) << "Could not load vxl file";
testRGB(volume.get());
testRGB("rgb.vxl");
}
TEST_F(VXLFormatTest, testSave) {

View File

@ -11,10 +11,7 @@ class VXMFormatTest: public AbstractVoxFormatTest {
};
TEST_F(VXMFormatTest, DISABLED_testLoadRGB) {
VXMFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.vxm", f));
ASSERT_NE(nullptr, volume) << "Could not load vxm file";
testRGB(volume.get());
testRGB("rgb.vxm");
}
TEST_F(VXMFormatTest, testLoad) {

View File

@ -101,10 +101,7 @@ TEST_F(VoxFormatTest, testLoad8OnTop) {
}
TEST_F(VoxFormatTest, testLoadRGB) {
VoxFormat f;
std::unique_ptr<voxel::RawVolume> volume(load("rgb.vox", f));
ASSERT_NE(nullptr, volume) << "Could not load vox file";
testRGB(volume.get());
testRGB("rgb.vox");
}
TEST_F(VoxFormatTest, testSaveSmallVoxel) {