Commit 01a42d2b authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Some work on campvis-core testing:

* Introducing ImageRepresentationTest
* Improved ImageDataTest
* Silenced Debug output in test-campvis
parent ec7cc382
......@@ -38,8 +38,10 @@
*/
class ImageDataTest : public testing::Test {
protected:
ImageDataTest() {
_imgData0 = new campvis::ImageData(2, tgt::svec3(1,2,1), 4);
ImageDataTest()
: _size(3, 2, 1)
{
_imgData0 = new campvis::ImageData(2, _size, 4);
_imgData1 = _imgData0->clone();
_absData1 = _imgData1;
}
......@@ -59,9 +61,10 @@ protected:
protected:
campvis::ImageData *_imgData0, *_imgData1;//, *_imgData2, _imgData3, _imgData4;
campvis::ImageData *_imgData0, *_imgData1;
campvis::AbstractData * _absData1;
tgt::svec3 _size;
};
/**
......@@ -79,8 +82,7 @@ TEST_F(ImageDataTest, miscellaneousTest) {
EXPECT_EQ(2, _imgData0->getDimensionality());
EXPECT_EQ(4, _imgData0->getNumChannels());
EXPECT_EQ(tgt::hmul(tgt::svec3(1,2,1)), _imgData0->getNumElements());
EXPECT_EQ(tgt::svec3(1,2,1).size, _imgData0->getSize().size);
EXPECT_EQ(tgt::hmul(_size), _imgData0->getNumElements());
tgt::Bounds bound0 = _imgData0->getWorldBounds();
tgt::Bounds bound1 = _imgData1->getWorldBounds();
......@@ -91,13 +93,11 @@ TEST_F(ImageDataTest, miscellaneousTest) {
EXPECT_TRUE(temp.getMappingInformation() == _imgData0->getMappingInformation());
tgt::svec3 vec(1, 2, 3);
_imgData0->positionToIndex(vec);
EXPECT_EQ(1, 1);
size_t sz = 3;
_imgData0->indexToPosition(sz);
EXPECT_EQ(1, 1);
for (size_t i = 0; i < _imgData0->getNumElements(); ++i) {
tgt::svec3 position = _imgData0->indexToPosition(i);
EXPECT_EQ(_imgData0->positionToIndex(position), i);
}
}
/**
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "gtest/gtest.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationdisk.h"
#include "core/datastructures/imagerepresentationlocal.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
using namespace campvis;
/**
* Test class for ImageData class.
*/
class ImageRepresentationTest : public testing::Test {
protected:
ImageRepresentationTest()
: _image(nullptr)
, _size(10, 10, 9)
, _ushortRep(nullptr)
, _shortRep(nullptr)
, _uintRep(nullptr)
, _floatRep(nullptr)
{
// create image and load from disk
_image = new ImageData(3, _size, 1);
ImageRepresentationDisk::create(_image, CAMPVIS_SOURCE_DIR "/test/sampledata/10_10_9_image.raw", WeaklyTypedPointer::UINT16);
}
~ImageRepresentationTest() {
}
void performComparisonTest() {
// check that all representations are present
EXPECT_TRUE(_localRep != nullptr);
EXPECT_TRUE(_glRep != nullptr);
EXPECT_TRUE(_ushortRep != nullptr);
// download texture
const tgt::Texture* tex = _glRep->getTexture();
const_cast<tgt::Texture*>(tex)->downloadTexture();
// compare both representations voxel-wise
for (size_t i = 0; i < _image->getNumElements(); ++i) {
uint16_t localVoxel = _ushortRep->getElement(i);
uint16_t glVoxel = tex->texel<uint16_t>(_image->indexToPosition(i));
EXPECT_EQ(localVoxel, glVoxel);
}
}
void convertLocalGl() {
_localRep = _image->getRepresentation<ImageRepresentationLocal>();
_glRep = _image->getRepresentation<ImageRepresentationGL>();
_ushortRep = _image->getRepresentation< GenericImageRepresentationLocal<uint16_t, 1> >(false);
}
void convertGlLocal() {
_glRep = _image->getRepresentation<ImageRepresentationGL>();
_localRep = _image->getRepresentation<ImageRepresentationLocal>();
_ushortRep = _image->getRepresentation< GenericImageRepresentationLocal<uint16_t, 1> >(false);
}
void performBasetypeConversionTest() {
_localRep = _image->getRepresentation<ImageRepresentationLocal>();
// perform various basetype converting conversions:
_ushortRep = _image->getRepresentation< GenericImageRepresentationLocal<uint16_t, 1> >();
_shortRep = _image->getRepresentation< GenericImageRepresentationLocal<int16_t, 1> >();
_uintRep = _image->getRepresentation< GenericImageRepresentationLocal<uint32_t, 1> >();
_floatRep = _image->getRepresentation< GenericImageRepresentationLocal<float, 1> >();
// compare both representations voxel-wise
for (size_t i = 0; i < _image->getNumElements(); ++i) {
float ushortVoxel = _ushortRep->getElementNormalized(i, 0);
float shortVoxel = _shortRep->getElementNormalized(i, 0);
float uintVoxel = _uintRep->getElementNormalized(i, 0);
float floatVoxel = _floatRep->getElementNormalized(i, 0);
const uint32_t missingBit = std::numeric_limits<uint16_t>::max() - std::numeric_limits<int16_t>::max();
const float tolerance = 2.f / missingBit;
EXPECT_NEAR(ushortVoxel, shortVoxel, tolerance);
EXPECT_FLOAT_EQ(ushortVoxel, uintVoxel);
EXPECT_FLOAT_EQ(ushortVoxel, floatVoxel);
}
}
protected:
ImageData* _image;
tgt::svec3 _size;
const ImageRepresentationLocal* _localRep;
const ImageRepresentationGL* _glRep;
const GenericImageRepresentationLocal<uint16_t, 1>* _ushortRep;
const GenericImageRepresentationLocal<int16_t, 1>* _shortRep;
const GenericImageRepresentationLocal<uint32_t, 1>* _uintRep;
const GenericImageRepresentationLocal<float, 1>* _floatRep;
};
/**
* Tests conversion Disk -> Local -> GL.
* First performs conversion and then compares the values in each voxel .
*/
TEST_F(ImageRepresentationTest, conversion_disk_local_gl_test) {
convertLocalGl();
performComparisonTest();
}
/**
* Tests conversion Disk -> GL -> Local.
* First performs conversion and then compares the values in each voxel .
*/
TEST_F(ImageRepresentationTest, conversion_disk_gl_local_test) {
convertGlLocal();
performComparisonTest();
}
/**
* Tests conversion between different basetypes Disk -> Local<ushort> -> Local<ubyte> -> Local<float>.
* First performs conversion and then compares the values in each voxel .
*/
TEST_F(ImageRepresentationTest, basetype_conversion_test) {
performBasetypeConversionTest();
}
......@@ -68,7 +68,7 @@ void init() {
// Init TGT
tgt::InitFeature::Features featureset = tgt::InitFeature::ALL;
tgt::init(featureset);
LogMgr.getConsoleLog()->addCat("", true);
LogMgr.getConsoleLog()->addCat("", true, tgt::Info);
// create a local OpenGL context and init GL
_localContext = new tgt::QtThreadedCanvas("", tgt::ivec2(16, 16));
......
ObjectType = Image
NDims = 3
DimSize = 10 10 9
ElementSpacing = 17.7734 17.7734 17.5003
Position = 0 0 0
ElementType = MET_USHORT
ElementNumberOfChannels = 1
ElementByteOrderMSB = False
ElementDataFile = 10_10_9_image.raw
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment