#3927 Measurements : Add unit test for area computations

This commit is contained in:
Magne Sjaastad
2019-01-03 09:47:45 +01:00
parent ca39bd3407
commit 5bf13140e3

View File

@@ -2,17 +2,17 @@
// //
// Copyright (C) Statoil ASA // Copyright (C) Statoil ASA
// Copyright (C) Ceetron Solutions AS // Copyright (C) Ceetron Solutions AS
// //
// ResInsight is free software: you can redistribute it and/or modify // ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or // WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. // FITNESS FOR A PARTICULAR PURPOSE.
// //
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> // See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details. // for more details.
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@@ -20,15 +20,15 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "cvfLibCore.h" #include "cvfLibCore.h"
#include "cvfLibViewing.h"
#include "cvfLibRender.h"
#include "cvfLibGeometry.h" #include "cvfLibGeometry.h"
#include "cvfLibRender.h"
#include "cvfLibViewing.h"
#include "cvfArrayWrapperToEdit.h"
#include "cvfArrayWrapperConst.h" #include "cvfArrayWrapperConst.h"
#include "cvfArrayWrapperToEdit.h"
#include "cvfGeometryTools.h"
#include "cvfBoundingBoxTree.h" #include "cvfBoundingBoxTree.h"
#include "cvfGeometryTools.h"
#include <array> #include <array>
@@ -86,23 +86,22 @@ void ControlVolume::calculateCubeFaceStatus(const cvf::Vec3dArray& nodeCoords, d
} }
#endif #endif
template<typename NodeArrayType, typename NodeType, typename IndexType>
template <typename NodeArrayType, typename NodeType, typename IndexType> NodeType quadNormal(ArrayWrapperConst<NodeArrayType, NodeType> nodeCoords, const IndexType cubeFaceIndices[4])
NodeType quadNormal (ArrayWrapperConst<NodeArrayType, NodeType> nodeCoords,
const IndexType cubeFaceIndices[4] )
{ {
return ( nodeCoords[cubeFaceIndices[2]] - nodeCoords[cubeFaceIndices[0]]) ^ return (nodeCoords[cubeFaceIndices[2]] - nodeCoords[cubeFaceIndices[0]]) ^
( nodeCoords[cubeFaceIndices[3]] - nodeCoords[cubeFaceIndices[1]]); (nodeCoords[cubeFaceIndices[3]] - nodeCoords[cubeFaceIndices[1]]);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> createVertices() std::vector<cvf::Vec3d> createVertices()
{ {
std::vector<cvf::Vec3d> vxs; std::vector<cvf::Vec3d> vxs;
vxs.resize(14, cvf::Vec3d::ZERO); vxs.resize(14, cvf::Vec3d::ZERO);
// clang-format off
vxs[ 0]= cvf::Vec3d( 0 , 0 , 0 ); vxs[ 0]= cvf::Vec3d( 0 , 0 , 0 );
vxs[ 1]= cvf::Vec3d( 1 , 0 , 0 ); vxs[ 1]= cvf::Vec3d( 1 , 0 , 0 );
vxs[ 2]= cvf::Vec3d( 1 , 1 , 0 ); vxs[ 2]= cvf::Vec3d( 1 , 1 , 0 );
@@ -117,26 +116,27 @@ std::vector<cvf::Vec3d> createVertices()
vxs[11]= cvf::Vec3d( 1.2 , 0.6 , 0.0 ); vxs[11]= cvf::Vec3d( 1.2 , 0.6 , 0.0 );
vxs[12]= cvf::Vec3d( 1.6 , 0.2 , 0.0 ); vxs[12]= cvf::Vec3d( 1.6 , 0.2 , 0.0 );
vxs[13]= cvf::Vec3d( 0.8 ,-0.6 , 0.0 ); vxs[13]= cvf::Vec3d( 0.8 ,-0.6 , 0.0 );
// clang-format on
return vxs; return vxs;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<std::array<cvf::uint, 4>> getCubeFaces() std::vector<std::array<cvf::uint, 4>> getCubeFaces()
{ {
std::vector<std::array<cvf::uint, 4>> cubeFaces; std::vector<std::array<cvf::uint, 4>> cubeFaces;
cubeFaces.resize(4); cubeFaces.resize(4);
cubeFaces[0] = { 0, 1, 2, 3 }; cubeFaces[0] = {0, 1, 2, 3};
cubeFaces[1] = { 4, 5, 6, 7 }; cubeFaces[1] = {4, 5, 6, 7};
cubeFaces[2] = { 5, 8, 9, 6 }; cubeFaces[2] = {5, 8, 9, 6};
cubeFaces[3] = { 10, 11, 12, 13 }; cubeFaces[3] = {10, 11, 12, 13};
return cubeFaces; return cubeFaces;
} }
std::ostream& operator<< (std::ostream& stream, std::vector<cvf::uint> v) std::ostream& operator<<(std::ostream& stream, std::vector<cvf::uint> v)
{ {
for (size_t i = 0; i < v.size(); ++i) for (size_t i = 0; i < v.size(); ++i)
{ {
@@ -146,7 +146,7 @@ std::ostream& operator<< (std::ostream& stream, std::vector<cvf::uint> v)
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
TEST(CellFaceIntersectionTst, Intersection1) TEST(CellFaceIntersectionTst, Intersection1)
{ {
@@ -154,187 +154,162 @@ TEST(CellFaceIntersectionTst, Intersection1)
std::vector<cvf::Vec3d> additionalVertices; std::vector<cvf::Vec3d> additionalVertices;
std::vector< std::vector<cvf::uint> > overlapPolygons; std::vector<std::vector<cvf::uint>> overlapPolygons;
auto faces = getCubeFaces(); auto faces = getCubeFaces();
EdgeIntersectStorage<cvf::uint> edgeIntersectionStorage; EdgeIntersectStorage<cvf::uint> edgeIntersectionStorage;
edgeIntersectionStorage.setVertexCount(nodes.size()); edgeIntersectionStorage.setVertexCount(nodes.size());
{ {
std::vector<cvf::uint> polygon; std::vector<cvf::uint> polygon;
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads( bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
&polygon, &additionalVertices,
&additionalVertices, &edgeIntersectionStorage,
&edgeIntersectionStorage, wrapArrayConst(&nodes),
wrapArrayConst(&nodes), faces[0].data(),
faces[0].data(), faces[1].data(),
faces[1].data(), 1e-6);
1e-6);
EXPECT_EQ( (size_t)5, polygon.size()); EXPECT_EQ((size_t)5, polygon.size());
EXPECT_EQ( (size_t)2, additionalVertices.size()); EXPECT_EQ((size_t)2, additionalVertices.size());
EXPECT_TRUE(isOk); EXPECT_TRUE(isOk);
overlapPolygons.push_back(polygon); overlapPolygons.push_back(polygon);
std::cout << polygon << std::endl; std::cout << polygon << std::endl;
}
{
std::vector<cvf::uint> polygon;
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(
&polygon,
&additionalVertices,
&edgeIntersectionStorage,
wrapArrayConst(&nodes),
faces[0].data(),
faces[2].data(),
1e-6);
EXPECT_EQ( (size_t)5, polygon.size());
EXPECT_EQ( (size_t)4, additionalVertices.size());
EXPECT_TRUE(isOk);
overlapPolygons.push_back(polygon);
std::cout << polygon << std::endl;
} }
{ {
std::vector<cvf::uint> polygon; std::vector<cvf::uint> polygon;
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads( bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
&polygon, &additionalVertices,
&additionalVertices, &edgeIntersectionStorage,
&edgeIntersectionStorage, wrapArrayConst(&nodes),
wrapArrayConst(&nodes), faces[0].data(),
faces[0].data(), faces[2].data(),
faces[3].data(), 1e-6);
1e-6);
EXPECT_EQ( (size_t)3, polygon.size()); EXPECT_EQ((size_t)5, polygon.size());
EXPECT_EQ( (size_t)6, additionalVertices.size()); EXPECT_EQ((size_t)4, additionalVertices.size());
EXPECT_TRUE(isOk); EXPECT_TRUE(isOk);
overlapPolygons.push_back(polygon); overlapPolygons.push_back(polygon);
std::cout << polygon << std::endl; std::cout << polygon << std::endl;
} }
nodes.insert(nodes.end(), additionalVertices.begin(), additionalVertices.end()); {
std::vector<cvf::uint> basePolygon; std::vector<cvf::uint> polygon;
basePolygon.insert(basePolygon.begin(), faces[0].data(), &(faces[0].data()[4])); bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
&additionalVertices,
&edgeIntersectionStorage,
wrapArrayConst(&nodes),
faces[0].data(),
faces[3].data(),
1e-6);
for (cvf::uint vxIdx = 0; vxIdx < nodes.size(); ++vxIdx) EXPECT_EQ((size_t)3, polygon.size());
{ EXPECT_EQ((size_t)6, additionalVertices.size());
GeometryTools::insertVertexInPolygon( EXPECT_TRUE(isOk);
&basePolygon, overlapPolygons.push_back(polygon);
wrapArrayConst(&nodes), std::cout << polygon << std::endl;
vxIdx, }
1e-6
);
}
EXPECT_EQ( (size_t)8, basePolygon.size());
std::cout << "Bp: " << basePolygon << std::endl;
for (size_t pIdx = 0; pIdx < overlapPolygons.size(); ++pIdx) nodes.insert(nodes.end(), additionalVertices.begin(), additionalVertices.end());
{ std::vector<cvf::uint> basePolygon;
for (cvf::uint vxIdx = 0; vxIdx < nodes.size(); ++vxIdx) basePolygon.insert(basePolygon.begin(), faces[0].data(), &(faces[0].data()[4]));
{
GeometryTools::insertVertexInPolygon(
&overlapPolygons[pIdx],
wrapArrayConst(&nodes),
vxIdx,
1e-6
);
}
if (pIdx == 0) for (cvf::uint vxIdx = 0; vxIdx < nodes.size(); ++vxIdx)
{ {
EXPECT_EQ((size_t)5, overlapPolygons[pIdx].size()); GeometryTools::insertVertexInPolygon(&basePolygon, wrapArrayConst(&nodes), vxIdx, 1e-6);
} }
if (pIdx == 1)
{
EXPECT_EQ((size_t)5, overlapPolygons[pIdx].size());
}
if (pIdx == 2)
{
EXPECT_EQ((size_t)4, overlapPolygons[pIdx].size());
}
std::cout << "Op" << pIdx << ":" << overlapPolygons[pIdx] << std::endl; EXPECT_EQ((size_t)8, basePolygon.size());
} std::cout << "Bp: " << basePolygon << std::endl;
for (size_t pIdx = 0; pIdx < overlapPolygons.size(); ++pIdx)
{
for (cvf::uint vxIdx = 0; vxIdx < nodes.size(); ++vxIdx)
{
GeometryTools::insertVertexInPolygon(&overlapPolygons[pIdx], wrapArrayConst(&nodes), vxIdx, 1e-6);
}
Vec3d normal = quadNormal(wrapArrayConst(&nodes), faces[0].data()); if (pIdx == 0)
std::vector<bool> faceOverlapPolygonWindingSameAsCubeFaceFlags; {
faceOverlapPolygonWindingSameAsCubeFaceFlags.resize(overlapPolygons.size(), true); EXPECT_EQ((size_t)5, overlapPolygons[pIdx].size());
}
if (pIdx == 1)
{
EXPECT_EQ((size_t)5, overlapPolygons[pIdx].size());
}
if (pIdx == 2)
{
EXPECT_EQ((size_t)4, overlapPolygons[pIdx].size());
}
{ std::cout << "Op" << pIdx << ":" << overlapPolygons[pIdx] << std::endl;
std::vector<cvf::uint> freeFacePolygon; }
bool hasHoles = false;
std::vector< std::vector<cvf::uint>* > overlapPolygonPtrs; Vec3d normal = quadNormal(wrapArrayConst(&nodes), faces[0].data());
for (size_t pIdx = 0; pIdx < overlapPolygons.size(); ++pIdx) std::vector<bool> faceOverlapPolygonWindingSameAsCubeFaceFlags;
{ faceOverlapPolygonWindingSameAsCubeFaceFlags.resize(overlapPolygons.size(), true);
overlapPolygonPtrs.push_back(&(overlapPolygons[pIdx]));
}
GeometryTools::calculatePartiallyFreeCubeFacePolygon( {
wrapArrayConst(&nodes), std::vector<cvf::uint> freeFacePolygon;
wrapArrayConst(&basePolygon), bool hasHoles = false;
normal,
overlapPolygonPtrs,
faceOverlapPolygonWindingSameAsCubeFaceFlags,
&freeFacePolygon,
&hasHoles
);
EXPECT_EQ( (size_t)4, freeFacePolygon.size()); std::vector<std::vector<cvf::uint>*> overlapPolygonPtrs;
EXPECT_FALSE(hasHoles); for (size_t pIdx = 0; pIdx < overlapPolygons.size(); ++pIdx)
std::cout << "FF1: " << freeFacePolygon << std::endl; {
} overlapPolygonPtrs.push_back(&(overlapPolygons[pIdx]));
}
{ GeometryTools::calculatePartiallyFreeCubeFacePolygon(wrapArrayConst(&nodes),
std::vector<cvf::uint> freeFacePolygon; wrapArrayConst(&basePolygon),
bool hasHoles = false; normal,
overlapPolygonPtrs,
faceOverlapPolygonWindingSameAsCubeFaceFlags,
&freeFacePolygon,
&hasHoles);
std::vector< std::vector<cvf::uint>* > overlapPolygonPtrs; EXPECT_EQ((size_t)4, freeFacePolygon.size());
for (size_t pIdx = 0; pIdx < 1; ++pIdx) EXPECT_FALSE(hasHoles);
{ std::cout << "FF1: " << freeFacePolygon << std::endl;
overlapPolygonPtrs.push_back(&(overlapPolygons[pIdx])); }
}
GeometryTools::calculatePartiallyFreeCubeFacePolygon( {
wrapArrayConst(&nodes), std::vector<cvf::uint> freeFacePolygon;
wrapArrayConst(&basePolygon), bool hasHoles = false;
normal,
overlapPolygonPtrs,
faceOverlapPolygonWindingSameAsCubeFaceFlags,
&freeFacePolygon,
&hasHoles
);
EXPECT_EQ( (size_t)9, freeFacePolygon.size()); std::vector<std::vector<cvf::uint>*> overlapPolygonPtrs;
EXPECT_FALSE(hasHoles); for (size_t pIdx = 0; pIdx < 1; ++pIdx)
{
overlapPolygonPtrs.push_back(&(overlapPolygons[pIdx]));
}
std::cout << "FF2: " << freeFacePolygon << std::endl; GeometryTools::calculatePartiallyFreeCubeFacePolygon(wrapArrayConst(&nodes),
wrapArrayConst(&basePolygon),
} normal,
overlapPolygonPtrs,
faceOverlapPolygonWindingSameAsCubeFaceFlags,
&freeFacePolygon,
&hasHoles);
EXPECT_EQ((size_t)9, freeFacePolygon.size());
EXPECT_FALSE(hasHoles);
std::cout << "FF2: " << freeFacePolygon << std::endl;
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
TEST(CellFaceIntersectionTst, Intersection) TEST(CellFaceIntersectionTst, Intersection)
{ {
std::vector<cvf::Vec3d> additionalVertices; std::vector<cvf::Vec3d> additionalVertices;
cvf::Vec3dArray nodes; cvf::Vec3dArray nodes;
std::vector<size_t> polygon; std::vector<size_t> polygon;
cvf::Array<size_t> ids; cvf::Array<size_t> ids;
size_t cv1CubeFaceIndices[4] = {0, 1, 2, 3}; size_t cv1CubeFaceIndices[4] = {0, 1, 2, 3};
size_t cv2CubeFaceIndices[4] = {4, 5, 6, 7}; size_t cv2CubeFaceIndices[4] = {4, 5, 6, 7};
nodes.resize(8); nodes.resize(8);
nodes.setAll(cvf::Vec3d(0, 0, 0)); nodes.setAll(cvf::Vec3d(0, 0, 0));
@@ -352,11 +327,15 @@ TEST(CellFaceIntersectionTst, Intersection)
nodes[6] = cvf::Vec3d(1, 1, 0); nodes[6] = cvf::Vec3d(1, 1, 0);
nodes[7] = cvf::Vec3d(0, 1, 0); nodes[7] = cvf::Vec3d(0, 1, 0);
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage, &additionalVertices,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6); &edgeIntersectionStorage,
EXPECT_EQ( (size_t)4, polygon.size()); wrapArrayConst(&nodes),
EXPECT_EQ( (size_t)0, additionalVertices.size()); cv1CubeFaceIndices,
cv2CubeFaceIndices,
1e-6);
EXPECT_EQ((size_t)4, polygon.size());
EXPECT_EQ((size_t)0, additionalVertices.size());
EXPECT_TRUE(isOk); EXPECT_TRUE(isOk);
// Face 1 // Face 1
@@ -371,31 +350,30 @@ TEST(CellFaceIntersectionTst, Intersection)
nodes[7] = cvf::Vec3d(-0.25, 0.5, 0); nodes[7] = cvf::Vec3d(-0.25, 0.5, 0);
polygon.clear(); polygon.clear();
isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage, isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6); &additionalVertices,
EXPECT_EQ( (size_t)8, polygon.size()); &edgeIntersectionStorage,
EXPECT_EQ( (size_t)8, additionalVertices.size()); wrapArrayConst(&nodes),
cv1CubeFaceIndices,
cv2CubeFaceIndices,
1e-6);
EXPECT_EQ((size_t)8, polygon.size());
EXPECT_EQ((size_t)8, additionalVertices.size());
EXPECT_TRUE(isOk); EXPECT_TRUE(isOk);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
TEST(CellFaceIntersectionTst, FreeFacePolygon) TEST(CellFaceIntersectionTst, FreeFacePolygon)
{ {
std::vector<cvf::Vec3d> additionalVertices; std::vector<cvf::Vec3d> additionalVertices;
cvf::Vec3dArray nodes; cvf::Vec3dArray nodes;
std::vector<size_t> polygon; std::vector<size_t> polygon;
cvf::Array<size_t> ids; cvf::Array<size_t> ids;
size_t cv1CubeFaceIndices[4] = {0, 1, 2, 3}; size_t cv1CubeFaceIndices[4] = {0, 1, 2, 3};
size_t cv2CubeFaceIndices[4] = {4, 5, 6, 7}; size_t cv2CubeFaceIndices[4] = {4, 5, 6, 7};
nodes.resize(8); nodes.resize(8);
nodes.setAll(cvf::Vec3d(0, 0, 0)); nodes.setAll(cvf::Vec3d(0, 0, 0));
@@ -413,28 +391,31 @@ TEST(CellFaceIntersectionTst, FreeFacePolygon)
nodes[6] = cvf::Vec3d(1, 1, 0); nodes[6] = cvf::Vec3d(1, 1, 0);
nodes[7] = cvf::Vec3d(0, 1, 0); nodes[7] = cvf::Vec3d(0, 1, 0);
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage, &additionalVertices,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6); &edgeIntersectionStorage,
EXPECT_EQ( (size_t)4, polygon.size()); wrapArrayConst(&nodes),
EXPECT_EQ( (size_t)0, additionalVertices.size()); cv1CubeFaceIndices,
cv2CubeFaceIndices,
1e-6);
EXPECT_EQ((size_t)4, polygon.size());
EXPECT_EQ((size_t)0, additionalVertices.size());
EXPECT_TRUE(isOk); EXPECT_TRUE(isOk);
std::vector< bool > faceOverlapPolygonWinding; std::vector<bool> faceOverlapPolygonWinding;
std::vector< std::vector<size_t>* > faceOverlapPolygons; std::vector<std::vector<size_t>*> faceOverlapPolygons;
faceOverlapPolygons.push_back(&polygon); faceOverlapPolygons.push_back(&polygon);
faceOverlapPolygonWinding.push_back(true); faceOverlapPolygonWinding.push_back(true);
std::vector<size_t> partialFacePolygon; std::vector<size_t> partialFacePolygon;
bool hasHoles = false; bool hasHoles = false;
GeometryTools::calculatePartiallyFreeCubeFacePolygon( GeometryTools::calculatePartiallyFreeCubeFacePolygon(wrapArrayConst(&nodes),
wrapArrayConst(&nodes), wrapArrayConst(cv1CubeFaceIndices, 4),
wrapArrayConst(cv1CubeFaceIndices, 4), Vec3d(0, 0, 1),
Vec3d(0,0,1), faceOverlapPolygons,
faceOverlapPolygons, faceOverlapPolygonWinding,
faceOverlapPolygonWinding, &partialFacePolygon,
&partialFacePolygon, &hasHoles);
&hasHoles);
// Face 1 // Face 1
nodes[0] = cvf::Vec3d(0, 0, 0); nodes[0] = cvf::Vec3d(0, 0, 0);
@@ -448,12 +429,105 @@ TEST(CellFaceIntersectionTst, FreeFacePolygon)
nodes[7] = cvf::Vec3d(-0.25, 0.5, 0); nodes[7] = cvf::Vec3d(-0.25, 0.5, 0);
polygon.clear(); polygon.clear();
isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage, isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6); &additionalVertices,
EXPECT_EQ( (size_t)8, polygon.size()); &edgeIntersectionStorage,
EXPECT_EQ( (size_t)8, additionalVertices.size()); wrapArrayConst(&nodes),
cv1CubeFaceIndices,
cv2CubeFaceIndices,
1e-6);
EXPECT_EQ((size_t)8, polygon.size());
EXPECT_EQ((size_t)8, additionalVertices.size());
EXPECT_TRUE(isOk); EXPECT_TRUE(isOk);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(CellFaceIntersectionTst, PolygonAreaNormal3D)
{
// Test special cases with zero area
{
std::vector<cvf::Vec3d> vxs;
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_TRUE(area == cvf::Vec3d::ZERO);
}
{
std::vector<cvf::Vec3d> vxs;
vxs.push_back({0, 0, 0});
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_TRUE(area == cvf::Vec3d::ZERO);
}
{
std::vector<cvf::Vec3d> vxs;
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 1});
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_TRUE(area == cvf::Vec3d::ZERO);
}
// Three points
{
std::vector<cvf::Vec3d> vxs;
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 1});
vxs.push_back({0, 1, 1});
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_DOUBLE_EQ(-0.5, area.x());
EXPECT_DOUBLE_EQ(0.0, area.y());
EXPECT_DOUBLE_EQ(0.0, area.z());
}
// four identical points
{
std::vector<cvf::Vec3d> vxs;
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 0});
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_TRUE(area == cvf::Vec3d::ZERO);
}
// Square of four points
{
std::vector<cvf::Vec3d> vxs;
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 1});
vxs.push_back({0, 1, 1});
vxs.push_back({0, 1, 0});
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_DOUBLE_EQ(-1.0, area.x());
EXPECT_DOUBLE_EQ(0.0, area.y());
EXPECT_DOUBLE_EQ(0.0, area.z());
}
// Square of four points + one point in center of square
{
std::vector<cvf::Vec3d> vxs;
vxs.push_back({0, 0, 0});
vxs.push_back({0, 0, 1});
vxs.push_back({0, 1, 1});
vxs.push_back({0, 1, 0});
vxs.push_back({0, 0.5, 0.5}); // center of square
cvf::Vec3d area = GeometryTools::polygonAreaNormal3D(vxs);
EXPECT_DOUBLE_EQ(-0.75, area.x());
EXPECT_DOUBLE_EQ(0.0, area.y());
EXPECT_DOUBLE_EQ(0.0, area.z());
}
} }