Commit adb005a9 authored by Max Lyon's avatar Max Lyon

add more unittests

parent 256b89ea
Pipeline #11532 passed with stage
in 5 minutes and 44 seconds
......@@ -28,11 +28,19 @@
namespace HexEx{
template <typename T>
class Matrix4x4T;
template <typename T>
bool operator==(const Matrix4x4T<T>& _mat, const Matrix4x4T<T>& _other);
template <typename T>
class Matrix4x4T
{
using Matrix4x4 = Matrix4x4T<T>;
friend bool operator==<>(const Matrix4x4T<T>& _mat, const Matrix4x4T<T>& _other);
public:
Matrix4x4T()
{
......@@ -87,6 +95,11 @@ public:
return res;
}
bool operator==(const Matrix4x4& _other)
{
return entries == _other.entries;
}
template <typename Vec>
Vec transform_point(const Vec& _vec)
{
......@@ -257,6 +270,12 @@ private:
std::array<T, 16> entries;
};
template <typename T>
bool operator==(const Matrix4x4T<T>& _mat, const Matrix4x4T<T>& _other)
{
return _mat.entries == _other.entries;
}
template <typename T>
std::ostream& operator<<(std::ostream& _os, const Matrix4x4T<T>& _mat)
......
/*
* Copyright 2019 Computer Graphics Group, RWTH Aachen University
* Author: Max Lyon <lyon@cs.rwth-aachen.de>
*
* This file is part of HexEx.
*
* HexEx is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* HexEx is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with HexEx. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "common.hh"
#include <HexExtractor.hh>
......
/*
* Copyright 2019 Computer Graphics Group, RWTH Aachen University
* Author: Max Lyon <lyon@cs.rwth-aachen.de>
*
* This file is part of HexEx.
*
* HexEx is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* HexEx is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with HexEx. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "common.hh"
#include <HexExtractor.hh>
#include <FileAccessor.hh>
#include <sstream>
#include <stdio.h>
using namespace HexEx;
TEST(FileAccess, StreamTest) {
for (auto transition : {false, true})
for (auto size : {1.0,2.2,3 + 1.0/3.0,4.0,5.0})
{
TetrahedralMesh mesh;
if (transition)
createCubeWithTransition(mesh, size);
else
createCube(mesh, size);
OpenVolumeMesh::CellPropertyT<std::map<VertexHandle, HexEx::Vec3d>> parametrization = mesh.template request_cell_property<std::map<OpenVolumeMesh::VertexHandle, HexEx::Vec3d>>("Parametrization");
std::stringstream ss;
ASSERT_NO_FATAL_FAILURE(HexEx::writeToStream(ss, mesh, parametrization));
TetrahedralMesh mesh2;
OpenVolumeMesh::CellPropertyT<std::map<VertexHandle, HexEx::Vec3d>> parametrization2 = mesh2.template request_cell_property<std::map<OpenVolumeMesh::VertexHandle, HexEx::Vec3d>>("Parametrization");
ASSERT_NO_FATAL_FAILURE(HexEx::readFromStream(ss, mesh2, parametrization2));
ASSERT_EQ(mesh.n_vertices(), mesh2.n_vertices());
ASSERT_EQ(mesh.n_cells(), mesh2.n_cells());
for (auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it)
EXPECT_EQ(mesh.vertex(*v_it), mesh2.vertex(*v_it));
for (auto c_it = mesh.cells_begin(); c_it != mesh.cells_end(); ++c_it)
for (auto cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
EXPECT_EQ(parametrization[*c_it][*cv_it], parametrization2[*c_it][*cv_it]);
}
}
TEST(FileAccess, FileTest) {
std::string fileName = "asdfahdfgsdfgadsfggfadgfgvnvhkilprt.test";
for (auto transition : {false, true})
for (auto size : {1.0,2.2,3 + 1.0/3.0,4.0,5.0})
{
TetrahedralMesh mesh;
if (transition)
createCubeWithTransition(mesh, size);
else
createCube(mesh, size);
OpenVolumeMesh::CellPropertyT<std::map<VertexHandle, HexEx::Vec3d>> parametrization = mesh.template request_cell_property<std::map<OpenVolumeMesh::VertexHandle, HexEx::Vec3d>>("Parametrization");
ASSERT_NO_FATAL_FAILURE(HexEx::writeToFile(fileName, mesh, parametrization));
TetrahedralMesh mesh2;
OpenVolumeMesh::CellPropertyT<std::map<VertexHandle, HexEx::Vec3d>> parametrization2 = mesh2.template request_cell_property<std::map<OpenVolumeMesh::VertexHandle, HexEx::Vec3d>>("Parametrization");
ASSERT_NO_FATAL_FAILURE(HexEx::readFromFile(fileName, mesh2, parametrization2));
ASSERT_EQ(mesh.n_vertices(), mesh2.n_vertices());
ASSERT_EQ(mesh.n_cells(), mesh2.n_cells());
for (auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it)
EXPECT_EQ(mesh.vertex(*v_it), mesh2.vertex(*v_it));
for (auto c_it = mesh.cells_begin(); c_it != mesh.cells_end(); ++c_it)
for (auto cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
EXPECT_EQ(parametrization[*c_it][*cv_it], parametrization2[*c_it][*cv_it]);
}
std::remove(fileName.c_str());
}
/*
* Copyright 2019 Computer Graphics Group, RWTH Aachen University
* Author: Max Lyon <lyon@cs.rwth-aachen.de>
*
* This file is part of HexEx.
*
* HexEx is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* HexEx is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with HexEx. If not, see <http://www.gnu.org/licenses/>.
*/
#include <chrono>
#include <gtest/gtest.h>
#include "common.hh"
#include "Utils.hh"
#include <HexExtractor.hh>
#include <GridIsomorphism.hh>
using namespace HexEx;
TEST(GridIsomorphismTest, matrixTest) {
double entries[] = {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
3, 2, 0, 1 };
auto t1 = Matrix4x4d(entries);
Vec3d test = Vec3d(1,2,3);
auto test2 = test;
test2 = t1.transform_point(test2);
EXPECT_EQ(test + Vec3d(3,2,0), test2);
}
TEST(GridIsomorphismTest, coversionTest) {
for (auto i = 0; i < 24; i++)
{
auto rr = HexEx::RestrictedRotation(i);
auto m = rr.toMatrix();
auto rr2 = HexEx::RestrictedRotation(m);
EXPECT_EQ(rr, rr2);
}
}
TEST(GridIsomorphismTest, transformationTest) {
for (auto i = 0; i < 24; i++)
{
auto rr = HexEx::RestrictedRotation(i);
auto m = rr.toMatrix();
for (auto j = 0; j < 100; ++j)
{
auto randomVec = HexEx::getRandomVector(10);
EXPECT_EQ(m.transform_point(randomVec), rr.transform(randomVec)) << i;
}
}
}
TEST(GridIsomorphismTest, inversionTest) {
for (char i = 0; i < 24; i++)
{
auto rr = HexEx::RestrictedRotation(i);
auto m = rr.toMatrix();
m.invert();
auto rr2 = rr;
rr2.invert();
auto m2 = rr2.toMatrix();
EXPECT_EQ(m2, m) << i;
}
}
TEST(GridIsomorphismTest, multiplicationTest) {
for (auto i = 0u; i < 24; i++)
for (auto j = 0u; j < 24; j++)
{
auto rr1 = HexEx::RestrictedRotation(i);
auto rr2 = HexEx::RestrictedRotation(j);
auto res = rr1 * rr2;
EXPECT_EQ(res.toMatrix(), rr1.toMatrix()*rr2.toMatrix()) << i << " " << j;
}
}
TEST(GridIsomorphismTest, isomorphismInversionTest) {
for (auto j = 0; j < 3; ++j)
for (auto k = 0; k < 3; ++k)
for (auto l = 0; l < 3; ++l)
{
auto t = HexEx::GridIsomorphism::Translation(j,k,l);
for (auto i = 0; i < 24; i++)
{
auto gi = HexEx::GridIsomorphism(i, t);
auto m = gi.toMatrix();
m.invert();
auto gi2 = gi.inverted();
auto m2 = gi2.toMatrix();
EXPECT_EQ(m2, m) << i;
}
}
}
//TEST(GridIsomorphismTest, performanceMulitplicitionTest) {
// using namespace std::chrono;
// auto N = 1000000;
//#ifdef DEBUG
// N /= 100;
//#endif
// auto gis = std::vector<HexEx::GridIsomorphism>();
// for (auto i = 0; i < 24; ++i)
// gis.push_back(HexEx::GridIsomorphism(i));
// auto matrices = std::vector<Matrix4x4dd>();
// for (auto i = 0; i < 24; ++i)
// matrices.push_back(gis[i].toMatrix());
// auto startGI = steady_clock::now();
// auto res = HexEx::GridIsomorphism(0);
// for (auto n = 0; n < N; ++n)
// {
// for (auto i = 0u; i < 24; i++)
// for (auto j = 0u; j < 24; j++)
// {
// res = gis[i] * gis[j];
// }
// }
// auto stopGI = steady_clock::now();
// auto durationGI = duration_cast<duration<double>>(stopGI - startGI);
// std::cout << res.transform_point(Vec3d(0,0,0)) << std::endl;
// auto startMatrices = steady_clock::now();
// auto res2 = Matrix4x4dd();
// for (auto n = 0; n < N; ++n)
// {
// for (auto i = 0u; i < 24; i++)
// for (auto j = 0u; j < 24; j++)
// {
// res2 = matrices[i] * matrices[j];
// }
// }
// auto stopMatrices = steady_clock::now();
// auto durationMatrices = duration_cast<duration<double>>(stopMatrices - startMatrices);
// std::cout << res2.transform_point(Vec3d(0,0,0)) << std::endl;
// std::cout << "Duration GridIsomorphism: " << durationGI.count() << std::endl;
// std::cout << "Duration Matrices : " << durationMatrices.count() << std::endl;
// std::cout << "Ratio : " << static_cast<double>(durationGI.count())/durationMatrices.count() << std::endl;
//}
//TEST(GridIsomorphismTest, performanceInversionTest) {
// using namespace std::chrono;
// auto N = 10000000;
//#ifdef DEBUG
// N /= 100;
//#endif
// auto gis = std::vector<HexEx::GridIsomorphism>();
// for (auto i = 0; i < 24; ++i)
// gis.push_back(HexEx::GridIsomorphism(i));
// auto matrices = std::vector<Matrix4x4dd>();
// for (size_t i = 0; i < 24; ++i)
// matrices.push_back(gis[i].toMatrix());
// auto startGI = steady_clock::now();
// for (auto n = 0; n < N; ++n)
// {
// for (auto i = 0u; i < 24; i++)
// gis[i].invert();
// }
// auto stopGI = steady_clock::now();
// auto durationGI = duration_cast<duration<double>>(stopGI - startGI);
// auto startMatrices = steady_clock::now();
// for (auto n = 0; n < N; ++n)
// {
// for (auto i = 0u; i < 24; i++)
// matrices[i].invert();
// }
// auto stopMatrices = steady_clock::now();
// auto durationMatrices = duration_cast<duration<double>>(stopMatrices - startMatrices);
// std::cout << "Duration GridIsomorphism: " << durationGI.count() << std::endl;
// std::cout << "Duration Matrices : " << durationMatrices.count() << std::endl;
// std::cout << "Ratio : " << (double)durationGI.count()/durationMatrices.count() << std::endl;
//}
//TEST(GridIsomorphismTest, performanceTransformationTest) {
// using namespace std::chrono;
// auto N = 10000000;
//#ifdef DEBUG
// N /= 100;
//#endif
// auto gis = std::vector<HexEx::GridIsomorphism>();
// for (auto i = 0; i < 24; ++i)
// gis.push_back(HexEx::GridIsomorphism(i));
// auto matrices = std::vector<Matrix4x4dd>();
// for (auto i = 0; i < 24; ++i)
// matrices.push_back(gis[i].toMatrix());
// auto startGI = steady_clock::now();
// auto res = Vec3d(3,3,3);
// for (auto n = 0; n < N; ++n)
// {
// for (auto i = 0u; i < 24; i++)
// res += gis[i].transform_point(res);
// }
// auto stopGI = steady_clock::now();
// auto durationGI = duration_cast<duration<double>>(stopGI - startGI);
// std::cout << res << std::endl;
// auto startMatrices = steady_clock::now();
// auto res2 = Vec3d(3,3,3);
// for (auto n = 0; n < N; ++n)
// {
// for (auto i = 0u; i < 24; i++)
// res2 += matrices[i].transform_point(res2);
// }
// auto stopMatrices = steady_clock::now();
// auto durationMatrices = duration_cast<duration<double>>(stopMatrices - startMatrices);
// std::cout << res2 << std::endl;
// std::cout << "Duration GridIsomorphism: " << durationGI.count() << std::endl;
// std::cout << "Duration Matrices : " << durationMatrices.count() << std::endl;
// std::cout << "Ratio : " << (double)durationGI.count()/durationMatrices.count() << std::endl;
//}
/*
* Copyright 2019 Computer Graphics Group, RWTH Aachen University
* Author: Max Lyon <lyon@cs.rwth-aachen.de>
*
* This file is part of HexEx.
*
* HexEx is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* HexEx is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with HexEx. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "common.hh"
#include <HexExtractor.hh>
using namespace HexEx;
class NavigationTest : public ::testing::Test {
protected:
virtual void SetUp() {
vhs.push_back(mesh.add_vertex(Vec3d(0,0,0)));
vhs.push_back(mesh.add_vertex(Vec3d(1,0,0)));
vhs.push_back(mesh.add_vertex(Vec3d(1,0,-1)));
vhs.push_back(mesh.add_vertex(Vec3d(0,1,0)));
hfhs.push_back(mesh.halfface_handle(mesh.add_face({vhs[0],vhs[1],vhs[2]}), 0));
hfhs.push_back(mesh.halfface_handle(mesh.add_face({vhs[0],vhs[2],vhs[3]}), 0));
hfhs.push_back(mesh.halfface_handle(mesh.add_face({vhs[0],vhs[3],vhs[1]}), 0));
hfhs.push_back(mesh.halfface_handle(mesh.add_face({vhs[1],vhs[3],vhs[2]}), 0));
ch = mesh.add_cell({hfhs[0],hfhs[1],hfhs[2],hfhs[3]},true);
OpenVolumeMesh::CellPropertyT<std::map<OpenVolumeMesh::VertexHandle, Vec3d>> parametrization = mesh.request_cell_property<std::map<OpenVolumeMesh::VertexHandle, Vec3d>>("Parametrization");
mesh.set_persistent(parametrization);
for (auto vh : mesh.vertices())
parametrization[ch][vh] = mesh.vertex(vh);
hexExtractor = new HexExtractor(mesh, parametrization);
hexExtractor->parameter(ch,vhs[0]) = Parameter( 0, 0, 0);
}
virtual void TearDown() { delete hexExtractor; }
HexExtractor* hexExtractor;
std::vector<OpenVolumeMesh::VertexHandle> vhs;
std::vector<OpenVolumeMesh::HalfFaceHandle> hfhs;
OpenVolumeMesh::CellHandle ch;
TetrahedralMesh mesh;
TetrahedralMesh paramesh;
PolyhedralMesh outputMesh;
PolyhedralMesh irregEdglesMesh;
PolyhedralMesh hportMesh;
PolyhedralMesh intermediateMesh;
HexahedralMesh realHexMesh;
};
TEST_F(NavigationTest, HalfedgeRotation) {
auto& hexEx = *hexExtractor;
hexEx.parameter(ch,vhs[0]) = Parameter( 0, 0,-1);
hexEx.parameter(ch,vhs[1]) = Parameter( 0, 0, 1);
hexEx.parameter(ch,vhs[2]) = Parameter(0.5,-1, 0);
hexEx.parameter(ch,vhs[3]) = Parameter(0.5, 1, 0);
auto halfedge = mesh.halfedge(vhs[2],vhs[3]);
auto traceHfh = hexEx.rotateAroundHalfedge(ch, halfedge, true);
EXPECT_EQ(hfhs[3], traceHfh);
}
TEST_F(NavigationTest, HalfedgeRotationInverted) {
auto& hexEx = *hexExtractor;
hexEx.parameter(ch,vhs[0]) = Parameter( 0, 0,-1);
hexEx.parameter(ch,vhs[1]) = Parameter( 0, 0, 1);
hexEx.parameter(ch,vhs[2]) = Parameter(0.5, 1, 0);
hexEx.parameter(ch,vhs[3]) = Parameter(0.5,-1, 0);
auto halfedge = mesh.halfedge(vhs[2],vhs[3]);
auto traceHfh = hexEx.rotateAroundHalfedge(ch, halfedge, true);
EXPECT_EQ(hfhs[3], traceHfh);
}
TEST_F(NavigationTest, SimpleFacePiercing) {
auto& hexEx = *hexExtractor;
hexEx.parameter(ch,vhs[0]) = Parameter( 0, 0, 0);
hexEx.parameter(ch,vhs[1]) = Parameter(0.5,-1, 1);
hexEx.parameter(ch,vhs[2]) = Parameter(0.5,-1,-1);
hexEx.parameter(ch,vhs[3]) = Parameter(0.5, 1, 0);
auto traceHfh = hexEx.alpha0NextFace(HalfFaceHandle(), ch, Parameter(0,0,0), Direction(1,0,0), Direction(0,0,1), Direction(0,1,0));
EXPECT_EQ(hfhs[3], traceHfh);
}
TEST_F(NavigationTest, SimpleFacePiercingInverted) {
auto& hexEx = *hexExtractor;
hexEx.parameter(ch,vhs[0]) = Parameter( 0, 0, 0);
hexEx.parameter(ch,vhs[1]) = Parameter(0.5,-1, 1);
hexEx.parameter(ch,vhs[2]) = Parameter(0.5, 1, 0);
hexEx.parameter(ch,vhs[3]) = Parameter(0.5,-1,-1);
auto traceHfh = hexEx.alpha0NextFace(HalfFaceHandle(), ch, Parameter(0,0,0), Direction(1,0,0), Direction(0,0,1), Direction(0,1,0));
EXPECT_EQ(hfhs[3], traceHfh);
}
TEST_F(NavigationTest, EdgePiercing) {
auto& hexEx = *hexExtractor;
hexEx.parameter(ch,vhs[0]) = Parameter( 0, 0,-1);
hexEx.parameter(ch,vhs[1]) = Parameter( 0, 0, 1);
hexEx.parameter(ch,vhs[2]) = Parameter(0.5,-1, 0);
hexEx.parameter(ch,vhs[3]) = Parameter(0.5, 1, 0);
auto traceHfh = hexEx.alpha0NextFace(HalfFaceHandle(), ch,