Commit 8b329a8a authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Merge branch 'gtest' into 'development'

Merging GoogleTest
parents 1f90eb62 ab355cc2
......@@ -79,4 +79,14 @@ namespace campvis {
return _worldToVoxelTransformation;
}
bool ImageMappingInformation::operator==(const ImageMappingInformation& obj) const{
return (this->_offset == obj._offset)
&& (this->_size == obj._size)
&& (this->_voxelSize == obj._voxelSize)
&& (this->_realWorldValueMapping == obj._realWorldValueMapping)
&& (this->_textureToWorldTransformation == obj._textureToWorldTransformation)
&& (this->_voxelToWorldTransformation == obj._voxelToWorldTransformation)
&& (this->_worldToTextureTransformation == obj._worldToTextureTransformation)
&& (this->_worldToVoxelTransformation == obj._worldToVoxelTransformation);
}
}
......@@ -95,13 +95,19 @@ namespace campvis {
* \return Linear mapping for mapping element values to real world values.
*/
const LinearMapping<float>& getRealWorldMapping() const;
/**
* Set the real world value mapping.
* \param rwvm Linear mapping for mapping element values to real world values.
*/
void setRealWorldMapping(const LinearMapping<float>& rwvm);
/**
* Overloaded equal operator
* \param obj Object to compare with.
*/
bool operator==(const ImageMappingInformation& obj) const ;
private:
/**
* Updates the X-to-Y matrices.
......
......@@ -5,8 +5,8 @@
// 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
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
......
......@@ -77,6 +77,5 @@ namespace campvis {
tgtAssert(index < _images.size(), "Index out of bounds.");
return _images[index];
}
}
\ No newline at end of file
......@@ -202,7 +202,7 @@ namespace campvis {
}
/**
* Returns wheter the invalidation level is valid (i.e. no invalid flag is set).
* Returns whether the invalidation level is valid (i.e. no invalid flag is set).
* \return _level == VALID
*/
bool isValid() const {
......@@ -210,7 +210,7 @@ namespace campvis {
}
/**
* Returns wheter the the INVALID_RESULT flag is set.
* Returns whether the the INVALID_RESULT flag is set.
* \return _level & INVALID_RESULT
*/
bool hasInvalidResult() const {
......@@ -218,7 +218,7 @@ namespace campvis {
}
/**
* Returns wheter the the INVALID_SHADER flag is set.
* Returns whether the the INVALID_SHADER flag is set.
* \return _level & INVALID_SHADER
*/
bool hasInvalidShader() const {
......@@ -226,7 +226,7 @@ namespace campvis {
}
/**
* Returns wheter the the INVALID_PROPERTIES flag is set.
* Returns whether the the INVALID_PROPERTIES flag is set.
* \return _level & INVALID_PROPERTIES
*/
bool hasInvalidProperties() const {
......
......@@ -35,7 +35,7 @@ namespace campvis {
/**
* Generic implementation of thread-safe n-D histograms.
* After successfull creation ConcurrentGenericHistogramND ensures:
* After successful creation ConcurrentGenericHistogramND ensures:
* * Calling addSample() is thread-safe.
*
* \tparam T Base data type of the histogram elements
......
......@@ -53,6 +53,7 @@ namespace campvis {
_shader1d = ShdrMgr.load("core/glsl/passthrough.vert", "core/glsl/tools/glreduction.frag", generateGlslHeader(_reductionOperator) + "#define REDUCTION_1D\n");
_shader2d = ShdrMgr.load("core/glsl/passthrough.vert", "core/glsl/tools/glreduction.frag", generateGlslHeader(_reductionOperator) + "#define REDUCTION_2D\n");
_shader3d = ShdrMgr.load("core/glsl/passthrough.vert", "core/glsl/tools/glreduction.frag", generateGlslHeader(_reductionOperator) + "#define REDUCTION_3D\n");
if (_shader1d == 0 || _shader2d == 0 || _shader3d == 0) {
LERROR("Could not load Shader for OpenGL reduction. Reduction will not work!");
return;
......
......@@ -45,7 +45,7 @@ namespace campvis {
class FaceGeometry;
/**
* Class performing a reduction of 2D image data using OpenGL.
* Class performing a reduction of 2D or 3D image data using OpenGL.
* \note All methods need to be called from a valid OpenGL context.
*/
class CAMPVIS_CORE_API GlReduction {
......
......@@ -64,6 +64,10 @@ namespace campvis {
return (value - _shift) / _scale;
}
bool operator==(const LinearMapping<T>& obj) const{
return this->_shift == obj._shift && this->_scale == obj._scale;
}
T _shift; ///< Shifting coefficient of mapping
T _scale; ///< Scaling coefficient of mapping
......
......@@ -193,6 +193,6 @@ namespace campvis {
}
#define GLJobProc tgt::Singleton<OpenGLJobProcessor>::getRef()
#define GLJobProc tgt::Singleton<campvis::OpenGLJobProcessor>::getRef()
#endif // OPENGLJOBPROCESSOR_H__
......@@ -103,18 +103,20 @@ namespace campvis {
// check whether there are quotes
if (str[strpos] == quotes) {
// find position of closing quotes
endpos = str.find_first_of('"', strpos + 1);
endpos = str.find_first_of(quotes, strpos + 1);
std::string toPush = str.substr(strpos + 1 , endpos - strpos - 1);
// ensure we haven't found double quotes ("") which shall be resolved to one double quote in resulting string
while ((endpos != std::string::npos) && (endpos + 1 < str.length()) && (str[endpos + 1] == '"')) {
while ((endpos != std::string::npos) && (endpos + 1 < str.length()) && (str[endpos + 1] == quotes)) {
strpos = endpos + 1;
endpos = str.find_first_of('"', endpos + 2);
endpos = str.find_first_of(quotes, endpos + 2);
toPush.append(str.substr(strpos, endpos - strpos));
}
// push string in quotes onto toReturn
toReturn.push_back(StringUtils::trim(toPush, whitespace));
toReturn.push_back(toPush);
// use the following if whitespace trimming is necessary in between <quote>s
//toReturn.push_back(StringUtils::trim(toPush, whitespace));
// ignore everything until next delimiter
endpos = str.find_first_of(delimiter, endpos);
......
......@@ -64,17 +64,17 @@ namespace campvis {
*
* \param str Input string to parse.
*
* \note TODO: The detection algorithm is a litte simplified and will not yield correct results
* \note TODO: The detection algorithm is a little simplified and will not yield correct results
* in every case.
**/
static std::vector<std::string> parseFloats(const std::string& str);
/**
* Replaces all occurences of \a from in \a str with \a to.
* Replaces all occurrences of \a from in \a str with \a to.
* \param str String to perform replacement on.
* \param from String to be replaced.
* \param to String repace.
* \return \a str with all occurences of \a from replaced with \a to.
* \param to String replace.
* \return \a str with all occurrences of \a from replaced with \a to.
*/
static std::string replaceAll(const std::string& str, const std::string& from, const std::string& to);
......@@ -97,11 +97,11 @@ namespace campvis {
* \param whitespace Set of whitespace characters which shall be removed during trimming.
* \return Vector of the split substrings.
*/
static std::vector<std::string> splitStringsafe(const std::string& str, const std::string& delimiter, char quotes = '"', const std::string& whitespace = " \t\n\r\0\x0B");
static std::vector<std::string> splitStringsafe(const std::string& str, const std::string& delimiter, char quotes = '\'', const std::string& whitespace = " \t\n\r\0\x0B");
/**
* Trims the string \a str.
* All leading and trailing occurences of the characters in \a whitespace will be removed.
* All leading and trailing occurrences of the characters in \a whitespace will be removed.
*
* \param str The string to trim.
* \param whitespace Set of whitespace characters which shall be removed at the beginning and the end.
......
......@@ -41,8 +41,8 @@
namespace campvis {
/**
* Struct for handling void pointers slightly more typesafe.
* Therfore it stores an enum value together with the pointer for deducing its data type.
* Struct for handling void pointers slightly more type safe.
* Therefore it stores an enum value together with the pointer for deducing its data type.
* \note WeaklyTypedPointer takes _not_ take ownership of its pointer, hence it won't take care of deleting it!
*/
struct CAMPVIS_CORE_API WeaklyTypedPointer {
......@@ -62,7 +62,7 @@ namespace campvis {
/**
* Returns the number of bytes occupied by one element of the type \a bt with \a numChannels channels.
*
* \note There is a compiletime version in WeaklyTypedPointerTraits.
* \note There is a compile time version in WeaklyTypedPointerTraits.
* \sa WeaklyTypedPointerTraits::numBytes()
* \param bt Image base type
* \param numChannels Number of channels per element.
......
......@@ -31,13 +31,11 @@
#include "gtest/gtest.h"
//int PullInMyLibrary();
GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from gtest_main.cc\n");
testing::InitGoogleTest(&argc, argv);
int ret= RUN_ALL_TESTS();
getchar();
return ret;
printf("gtest_main.cc returned with %d\n", ret);
return 0;
}
PROJECT(test-campvis)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
#INCLUDE(../cmake/commonconf.cmake)
MESSAGE(STATUS "Configuring googletest for campvis Modules")
#SET_DEFAULT_MODULES("vis")
#RESOLVE_MODULE_DEPENDENCIES()
#WRITE_PIPELINE_REGISTRATION("gen_pipelineregistration.h")
FILE(GLOB TestCampvisHeaders
FILE(GLOB TestCampvisHeaders RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.h
)
FILE(GLOB TestCampvisSources
FILE(GLOB TestCampvisSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.cpp
core/datastructures/*.cpp
core/properties/*.cpp
core/tools/*.cpp
core/pipeline/*.cpp
)
# Summary of tuple support for Microsoft Visual Studio:
......@@ -32,9 +31,9 @@ ADD_EXECUTABLE(test-campvis
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisModulesDefinitions} ${CampvisApplicationDefinitions} ${QT_DEFINITIONS})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CampvisModulesIncludeDirs} ${CampvisHome}/ext/gtest-1.7.0/ ${CampvisHome}/ext/gtest-1.7.0/include)
TARGET_LINK_LIBRARIES(test-campvis campvis-modules campvis-core tgt gtest_main ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs})
TARGET_LINK_LIBRARIES(test-campvis campvis-modules campvis-core tgt gtest ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} ${QT_LIBRARIES})
IF(CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisSources ${CampvisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisHeaders ${CampvisHome} "")
if (CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisSources ${CampvisHome}/test "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisHeaders ${CampvisHome}/test "")
ENDIF()
// ================================================================================================
//
// 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.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/datahandle.h"
#include "core/datastructures/imagedata.h"
using namespace campvis;
/**
* Test class for DataContainer class
*/
class DataContainerTest : public ::testing::Test {
protected:
DataContainerTest() {
this->_data = new ImageData(2, tgt::svec3(1,2,1), 4);
this->_dc0 = new DataContainer("dc0");
}
~DataContainerTest() {
delete this->_dc0;
}
virtual void SetUp() {
}
virtual void TearDown() {
}
protected:
DataContainer *_dc0;
AbstractData * _data;
};
/**
* Tests the trivial operations of the class.
* getName()
* addData()
* addDataHandle()
* getData()
* hasData()
* removeData()
*/
TEST_F(DataContainerTest, miscellaneousTest) {
EXPECT_EQ("dc0", this->_dc0->getName());
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
this->_dc0->addData("data1", this->_data);
EXPECT_EQ(this->_data, this->_dc0->getData("data1").getData());
this->_dc0->addDataHandle("data2", DataHandle(this->_data));
this->_dc0->removeData("data1");
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
EXPECT_EQ(false, this->_dc0->hasData("data1"));
EXPECT_EQ(true, this->_dc0->hasData("data2"));
}
/**
* Tests the function getDataHandlesCopy.
*/
TEST_F(DataContainerTest, getDataHandlesCopyTest) {
EXPECT_EQ(0, this->_dc0->getDataHandlesCopy().size());
this->_dc0->addData("data1", this->_data);
EXPECT_EQ(1, this->_dc0->getDataHandlesCopy().size());
std::pair<std::string, DataHandle> pair = this->_dc0->getDataHandlesCopy()[0];
EXPECT_EQ("data1", pair.first);
EXPECT_EQ(this->_data, pair.second.getData());
}
/**
* Tests the concurrent access settings of the class.
*
* DataHandle of previously added data obtained with getData() should remains valid
* even if the data in the container is replaced with new data.
*/
TEST_F(DataContainerTest, concurrentAccessTest) {
this->_dc0->addData("data1", this->_data);
DataHandle dh = this->_dc0->getData("data1");
AbstractData *someData = new ImageData(2, tgt::svec3(1,2,1), 4);
this->_dc0->addData("data1", someData);
EXPECT_EQ(someData, this->_dc0->getData("data1").getData());
EXPECT_NE(_data, this->_dc0->getData("data1").getData());
EXPECT_EQ(_data, dh.getData());
}
// ================================================================================================
//
// 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.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/datastructures/datahandle.h"
#include "core/datastructures/imagedata.h"
/**
* Test class for DataHandle class. This class along with ImageDataTest and
* ImageSeriesTest completes the overall test environments for DataHandle and
* AbstractData.
*/
class DataHandleTest : public testing::Test {
protected:
DataHandleTest() {
_data1 = new campvis::ImageData(2, tgt::svec3(1,2,1), 4);
_dh0 = campvis::DataHandle();
_dh1 = campvis::DataHandle(_data1);
_dh2 = campvis::DataHandle(_dh1);
_dh3 = _dh2;
}
~DataHandleTest() {
}
virtual void SetUp() {
}
virtual void TearDown() {
}
protected:
campvis::DataHandle _dh0, _dh1, _dh2, _dh3, _dh4;
campvis::AbstractData * _data1;
};
TEST_F(DataHandleTest, getDataTest) {
ASSERT_TRUE(nullptr == _dh0.getData());
EXPECT_EQ(_dh1.getData(), _dh2.getData());
EXPECT_EQ(_dh1.getData(), _dh3.getData());
EXPECT_EQ(nullptr, _dh4.getData());
}
TEST_F(DataHandleTest, getTimestampTest) {
EXPECT_NE(-1, _dh0.getTimestamp());
EXPECT_NE(-1, _dh1.getTimestamp());
EXPECT_NE(-1, _dh2.getTimestamp());
EXPECT_NE(-1, _dh3.getTimestamp());
EXPECT_NE(-1, _dh4.getTimestamp());
EXPECT_EQ(_dh1.getTimestamp(), _dh2.getTimestamp());
EXPECT_EQ(_dh1.getTimestamp(), _dh3.getTimestamp());
}
// ================================================================================================
//
// 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.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagedata.h"
/**
* Test class for ImageData class.
*/
class ImageDataTest : public testing::Test {
protected:
ImageDataTest() {
_imgData0 = new campvis::ImageData(2, tgt::svec3(1,2,1), 4);
_imgData1 = _imgData0->clone();
_absData1 = _imgData1;
}
~ImageDataTest() {
delete _imgData0;
delete _imgData1;
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following two methods
virtual void SetUp() {
}
virtual void TearDown() {
}
protected:
campvis::ImageData *_imgData0, *_imgData1;//, *_imgData2, _imgData3, _imgData4;
campvis::AbstractData * _absData1;
};
/**
* Tests the trivial operations of the class.
* initialization
* getDimensionality()
* getNumChannels()
* getNumElements()
* getWorldBounds()
* get/setMappingInformation()
* positionToIndex()/indexToPosition()
*/
TEST_F(ImageDataTest, miscellaneousTest) {
ASSERT_TRUE(nullptr != _imgData1);
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);
tgt::Bounds bound0 = _imgData0->getWorldBounds();
tgt::Bounds bound1 = _imgData1->getWorldBounds();
EXPECT_EQ(bound0, bound1);
campvis::ImageData temp = campvis::ImageData(3, tgt::svec3(3,2,1), 5);
temp.setMappingInformation(_imgData0->getMappingInformation());
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);
}
/**
* Tests the clone() function.
*/
// TODO: extend the test for proper ImageData cloning
TEST_F(ImageDataTest, cloneTest) {
ASSERT_TRUE(nullptr != _imgData1);
EXPECT_EQ(_imgData0->getDimensionality(), _imgData1->getDimensionality());
EXPECT_EQ(_imgData0->getLocalMemoryFootprint(), _imgData1->getLocalMemoryFootprint());
EXPECT_TRUE(_imgData0->getMappingInformation() == _imgData1->getMappingInformation());
EXPECT_EQ(_imgData0->getNumChannels(), _imgData1->getNumChannels());
EXPECT_EQ(_imgData0->getNumElements(), _imgData1->getNumElements());
//EXPECT_EQ(_imgData0->getRepresentation(), _imgData1->getRepresentation());
EXPECT_EQ(_imgData0->getSize(), _imgData1->getSize());
//EXPECT_EQ(_imgData0->getSubImage(), _imgData1->getSubImage());
EXPECT_EQ(_imgData0->getVideoMemoryFootprint(), _imgData1->getVideoMemoryFootprint());
}
// ================================================================================================
//
// 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>