(#687) Moved ReservoirDataModelUnitTests into ApplicationCode/UnitTests

This commit is contained in:
Magne Sjaastad
2015-12-03 10:57:10 +01:00
parent 563dd8c04f
commit e03b6495e8
6 changed files with 0 additions and 164 deletions

View File

@@ -1,118 +0,0 @@
cmake_minimum_required (VERSION 2.8)
SET (ProjectName RigReservoirDataModel_UnitTests)
project ( ${ProjectName} )
# Qt
find_package (Qt4 COMPONENTS QtCore QtGui QtMain QtOpenGl REQUIRED)
include (${QT_USE_FILE})
include_directories(
${LibCore_SOURCE_DIR}
${LibGeometry_SOURCE_DIR}
${LibRender_SOURCE_DIR}
${LibViewing_SOURCE_DIR}
${ResInsight_SOURCE_DIR}/ApplicationCode
${ResInsight_SOURCE_DIR}/ApplicationCode/ResultStatisticsCache
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel
${ResInsight_SOURCE_DIR}/ApplicationCode/FileInterface
${ResInsight_SOURCE_DIR}/ApplicationCode/ProjectDataModel
${ResInsight_SOURCE_DIR}/ThirdParty
${ResInsight_SOURCE_DIR}/ThirdParty/NRLib/nrlib/well
#${ResInsight_SOURCE_DIR}/Fwk/AppFwk/cafProjectDataModel
${cafProjectDataModel_SOURCE_DIR}
${cafPdmCore_SOURCE_DIR}
${ResInsight_SOURCE_DIR}/Fwk/AppFwk/CommonCode
#Remove when RigStatistics is out
#${ResInsight_SOURCE_DIR}/ApplicationCode/ModelVisualization
)
# Populate the filenames into variable lists
include ("${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists_files.cmake")
set( UNIT_TEST_CPP_SOURCES
${ResInsight_SOURCE_DIR}/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp
main.cpp
RigActiveCellInfo-Test.cpp
RigReservoir-Test.cpp
RigStatisticsMath-Test.cpp
cvfGeometryTools-Test.cpp
)
#############################################################################
# Adds folders for Visual Studio solution explorer (and for Xcode explorer)
#############################################################################
source_group( "UnitTests" FILES ${UNIT_TEST_CPP_SOURCES} )
set( LINK_LIBRARIES
CommonCode
ResultStatisticsCache
LibViewing
LibRender
LibGeometry
LibCore
ecl
ecl_well
ert_util
NRLib
${QT_LIBRARIES}
)
add_executable( ${ProjectName}
${CODE_SOURCE_FILES}
${UNIT_TEST_CPP_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists_files.cmake
${ResInsight_SOURCE_DIR}/ThirdParty/gtest/gtest-all.cc
)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set ( LINUX_LINK_LIBRARIES
pthread
)
# Linux specific code
set(CMAKE_CXX_FLAGS "-DCVF_LINUX -pipe -Wextra -Woverloaded-virtual -Wformat")
set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG -D_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNO_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries( ${ProjectName} ${LINK_LIBRARIES} ${LINUX_LINK_LIBRARIES})
# Copy Qt Dlls
if (MSVC)
set (QTLIBLIST QtCore QtGui QtOpenGl)
foreach (qtlib ${QTLIBLIST})
# Debug
execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}d4.dll ${CMAKE_CURRENT_BINARY_DIR}/Debug/${qtlib}d4.dll)
# Release
execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}4.dll ${CMAKE_CURRENT_BINARY_DIR}/Release/${qtlib}4.dll)
endforeach( qtlib )
endif(MSVC)

View File

@@ -1,75 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
//
// ResInsight 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.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include "RigActiveCellInfo.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigActiveCellInfo, BasicTest)
{
RigActiveCellInfo rigActiveCellInfo;
size_t globalActiveCellCount = 10;
rigActiveCellInfo.setReservoirCellCount(globalActiveCellCount);
for (size_t i = 0; i < globalActiveCellCount; i++)
{
EXPECT_TRUE(rigActiveCellInfo.cellResultIndex(i) == cvf::UNDEFINED_SIZE_T);
EXPECT_FALSE(rigActiveCellInfo.isActive(i));
}
rigActiveCellInfo.setCellResultIndex(3, 1);
EXPECT_TRUE(rigActiveCellInfo.cellResultIndex(3) == 1);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigActiveCellInfo, GridCellCounts)
{
{
RigActiveCellInfo rigActiveCellInfo;
rigActiveCellInfo.setGridCount(3);
rigActiveCellInfo.setGridActiveCellCounts(0, 0);
rigActiveCellInfo.setGridActiveCellCounts(1, 1);
rigActiveCellInfo.setGridActiveCellCounts(2, 2);
rigActiveCellInfo.computeDerivedData();
EXPECT_TRUE(rigActiveCellInfo.reservoirActiveCellCount() == 3);
}
{
RigActiveCellInfo rigActiveCellInfo;
rigActiveCellInfo.setGridCount(3);
rigActiveCellInfo.setGridActiveCellCounts(0, 3 );
rigActiveCellInfo.setGridActiveCellCounts(1, 4 );
rigActiveCellInfo.setGridActiveCellCounts(2, 5 );
rigActiveCellInfo.computeDerivedData();
EXPECT_TRUE(rigActiveCellInfo.reservoirActiveCellCount() == 12);
}
}

View File

@@ -1,131 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight 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.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include "RigCaseData.h"
#include "RigGridManager.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigGridManager, BasicTest)
{
cvf::ref<RigMainGrid> mainGridA = new RigMainGrid;
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
eclipseCase->setMainGrid(mainGridA.p());
int count = mainGridA->refCount();
EXPECT_EQ(mainGridA->refCount(), 2);
RigGridManager gridCollection;
gridCollection.addCase(eclipseCase.p());
EXPECT_EQ(mainGridA->refCount(), 2);
cvf::ref<RigMainGrid> mainGridB = mainGridA;
EXPECT_EQ(mainGridA->refCount(), 3);
cvf::ref<RigMainGrid> existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.notNull());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigGridManager, EqualTests)
{
cvf::ref<RigMainGrid> mainGridA = new RigMainGrid;
mainGridA->nodes().push_back(cvf::Vec3d(0, 0, 0));
mainGridA->nodes().push_back(cvf::Vec3d(0, 0, 1));
mainGridA->nodes().push_back(cvf::Vec3d(0, 0, 2));
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
eclipseCase->setMainGrid(mainGridA.p());
RigGridManager gridCollection;
gridCollection.addCase(eclipseCase.p());
cvf::ref<RigMainGrid> mainGridB = new RigMainGrid;
cvf::ref<RigMainGrid> existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.isNull());
mainGridB->nodes().push_back(cvf::Vec3d(0, 0, 0));
existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.isNull());
// Insert nodes in opposite direction
mainGridB->nodes().push_back(cvf::Vec3d(0, 0, 2));
mainGridB->nodes().push_back(cvf::Vec3d(0, 0, 1));
existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.isNull());
// Overwrite to match the node structure of mainGridA
mainGridB->nodes()[1] = cvf::Vec3d(0, 0, 1);
mainGridB->nodes()[2] = cvf::Vec3d(0, 0, 2);
existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.notNull());
}
/*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigReservoirTest, BasicTest)
{
cvf::ref<RigSingleWellResultsData> wellCellTimeHistory = new RigSingleWellResultsData;
QDateTime wellStartTime = QDateTime::currentDateTime();
int wellTimeStepCount = 5;
wellCellTimeHistory->m_wellCellsTimeSteps.resize(wellTimeStepCount);
int i;
for (i = 0; i < wellTimeStepCount; i++)
{
wellCellTimeHistory->m_wellCellsTimeSteps[i].m_timestamp = QDateTime(wellStartTime).addYears(i);
}
int resultTimeStepCount = 2 * wellTimeStepCount;
std::vector<QDateTime> resultTimes;
for (i = 0; i < resultTimeStepCount; i++)
{
resultTimes.push_back(QDateTime(wellStartTime).addMonths(i * 6));
}
wellCellTimeHistory->computeMappingFromResultTimeIndicesToWellTimeIndices(resultTimes);
for (i = 0; i < resultTimeStepCount; i++)
{
qDebug() << "Index" << i << "is " << wellCellTimeHistory->m_resultTimeStepIndexToWellTimeStepIndex[i];
const RigWellResultFrame& wellCells = wellCellTimeHistory->wellResultFrame(wellCellTimeHistory->m_resultTimeStepIndexToWellTimeStepIndex[i]);
qDebug() << wellCells.m_timestamp;
}
}
*/

View File

@@ -1,181 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight 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.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include "RigStatisticsMath.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, BasicTest)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
double min, max, range, mean, stdev;
RigStatisticsMath::calculateBasicStatistics(values, &min, &max, &range, &mean, &stdev);
EXPECT_DOUBLE_EQ(-98649.8109937874000, min );
EXPECT_DOUBLE_EQ(99372.9362079615000 , max );
EXPECT_DOUBLE_EQ(198022.7472017490000, range );
EXPECT_DOUBLE_EQ(16313.8051759152000 , mean );
EXPECT_DOUBLE_EQ(66104.391542887200 , stdev );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, RankPercentiles)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
std::vector<double> pValPos;
pValPos.push_back(10);
pValPos.push_back(40);
pValPos.push_back(50);
pValPos.push_back(90);
std::vector<double> pVals = RigStatisticsMath::calculateNearestRankPercentiles(values, pValPos);
EXPECT_DOUBLE_EQ( -76092.8157632591000, pVals[0]);
EXPECT_DOUBLE_EQ( 2788.2723335651900 , pVals[1]);
EXPECT_DOUBLE_EQ( 6391.979999097290 , pVals[2]);
EXPECT_DOUBLE_EQ( 96161.7546348456000 , pVals[3]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, HistogramPercentiles)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
double min, max, range, mean, stdev;
RigStatisticsMath::calculateBasicStatistics(values, &min, &max, &range, &mean, &stdev);
std::vector<size_t> histogram;
RigHistogramCalculator histCalc(min, max, 100, &histogram);
histCalc.addData(values);
std::vector<double> pVals;
double p10, p50, p90;
p10 = histCalc.calculatePercentil(0.1);
p50 = histCalc.calculatePercentil(0.5);
p90 = histCalc.calculatePercentil(0.9);
EXPECT_DOUBLE_EQ( -76273.240559989776, p10);
EXPECT_DOUBLE_EQ( 5312.1312871307755 , p50);
EXPECT_DOUBLE_EQ( 94818.413022321271 , p90);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, InterpolatedPercentiles)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
std::vector<double> pValPos;
pValPos.push_back(10);
pValPos.push_back(40);
pValPos.push_back(50);
pValPos.push_back(90);
std::vector<double> pVals = RigStatisticsMath::calculateInterpolatedPercentiles(values, pValPos);
EXPECT_DOUBLE_EQ( -72278.340409937548, pVals[0]);
EXPECT_DOUBLE_EQ( -2265.6006907818719, pVals[1]);
EXPECT_DOUBLE_EQ( 6391.9799990972897, pVals[2]);
EXPECT_DOUBLE_EQ( 93073.49128098879, pVals[3]);
}

View File

@@ -1,518 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA
// Copyright (C) Ceetron Solutions AS
//
// ResInsight 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.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include "cvfLibCore.h"
#include "cvfLibViewing.h"
#include "cvfLibRender.h"
#include "cvfLibGeometry.h"
#include "cafFixedArray.h"
#include "cvfArrayWrapperToEdit.h"
#include "cvfArrayWrapperConst.h"
#include "cvfGeometryTools.h"
#include "cvfBoundingBoxTree.h"
using namespace cvf;
#if 0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void ControlVolume::calculateCubeFaceStatus(const cvf::Vec3dArray& nodeCoords, double areaTolerance)
{
int cubeFace;
cvf::uint cubeFaceIndices[4];
for (cubeFace = 0; cubeFace < 6; ++cubeFace)
{
surfaceNodeIndices(static_cast<Defines::CubeFace>(cubeFace), cubeFaceIndices);
std::vector<const brv::Connection*> conns;
connections(static_cast<Defines::CubeFace>(cubeFace), &conns);
if (!conns.size())
{
m_cubeFaceStatus[cubeFace] = FREE_FACE;
}
else
{
double area = 0.5 * (nodeCoords[cubeFaceIndices[1]]-nodeCoords[cubeFaceIndices[0]] ^ nodeCoords[cubeFaceIndices[3]]-nodeCoords[cubeFaceIndices[0]]).length();
area += 0.5 * (nodeCoords[cubeFaceIndices[3]]-nodeCoords[cubeFaceIndices[2]] ^ nodeCoords[cubeFaceIndices[1]]-nodeCoords[cubeFaceIndices[2]]).length();
double totConnectionArea = 0;
size_t i;
for (i = 0; i < conns.size(); ++i)
{
totConnectionArea += conns[i]->brfArea();
}
if ( totConnectionArea < area - areaTolerance )
{
m_cubeFaceStatus[cubeFace] = PARTIALLY_COVERED;
}
else
{
m_cubeFaceStatus[cubeFace] = COMPLETELY_COVERED;
}
}
// Create a polygon to store the complete polygon of the faces
// not completely covered by connections
// This polygon will be filled with nodes later
if (m_cubeFaceStatus[cubeFace] != COMPLETELY_COVERED )
{
m_freeFacePolygons[cubeFace] = new std::list<std::pair<cvf::uint, bool> >;
}
}
}
#endif
template <typename NodeArrayType, typename NodeType, typename IndexType>
NodeType quadNormal (ArrayWrapperConst<NodeArrayType, NodeType> nodeCoords,
const IndexType cubeFaceIndices[4] )
{
return ( nodeCoords[cubeFaceIndices[2]] - nodeCoords[cubeFaceIndices[0]]) ^
( nodeCoords[cubeFaceIndices[3]] - nodeCoords[cubeFaceIndices[1]]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class QuadFaceIntersectorImplHandle
{
public:
virtual ~QuadFaceIntersectorImplHandle() {}
virtual bool intersect() = 0;
};
template < typename NodeArrayType, typename NodeType, typename IndicesArrayType, typename IndicesType>
class QuadFaceIntersectorImpl : public QuadFaceIntersectorImplHandle
{
public:
QuadFaceIntersectorImpl( ArrayWrapperToEdit<NodeArrayType, NodeType> nodeArray, ArrayWrapperToEdit<IndicesArrayType, IndicesType> indices)
: m_nodeArray(nodeArray),
m_indices(indices){}
virtual bool intersect()
{
size_t nodeCount = m_nodeArray.size();
NodeType a = m_nodeArray[0];
IndicesType idx = m_indices[0];
return true;
}
private:
ArrayWrapperToEdit<NodeArrayType, NodeType> m_nodeArray;
ArrayWrapperToEdit<IndicesArrayType, IndicesType> m_indices;
};
class QuadFaceIntersector
{
public:
template <typename NodeArrayType, typename NodeType, typename IndicesArrayType, typename IndicesType>
void setup( ArrayWrapperToEdit<NodeArrayType, NodeType> nodeArray, ArrayWrapperToEdit<IndicesArrayType, IndicesType> indices)
{
m_implementation = new QuadFaceIntersectorImpl< NodeArrayType, NodeType, IndicesArrayType, IndicesType>( nodeArray, indices);
}
bool intersect() { return m_implementation->intersect(); }
private:
QuadFaceIntersectorImplHandle * m_implementation;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> createVertices()
{
std::vector<cvf::Vec3d> vxs;
vxs.resize(14, cvf::Vec3d::ZERO);
vxs[ 0]= cvf::Vec3d( 0 , 0 , 0 );
vxs[ 1]= cvf::Vec3d( 1 , 0 , 0 );
vxs[ 2]= cvf::Vec3d( 1 , 1 , 0 );
vxs[ 3]= cvf::Vec3d( 0 , 1 , 0 );
vxs[ 4]= cvf::Vec3d(-0.4 ,-0.2 , 0.0 );
vxs[ 5]= cvf::Vec3d( 0.4 , 0.6 , 0.0 );
vxs[ 6]= cvf::Vec3d( 0.8 , 0.2 , 0.0 );
vxs[ 7]= cvf::Vec3d( 0.0 ,-0.6 , 0.0 );
vxs[ 8]= cvf::Vec3d( 1.0 , 1.2 , 0.0 );
vxs[ 9]= cvf::Vec3d( 1.4 , 0.8 , 0.0 );
vxs[10]= cvf::Vec3d( 0.4 ,-0.2 , 0.0 );
vxs[11]= cvf::Vec3d( 1.2 , 0.6 , 0.0 );
vxs[12]= cvf::Vec3d( 1.6 , 0.2 , 0.0 );
vxs[13]= cvf::Vec3d( 0.8 ,-0.6 , 0.0 );
return vxs;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::UintArray4> getCubeFaces()
{
std::vector<caf::UintArray4 > cubeFaces;
cvf::uint faces[4*4] = {
0, 1, 2, 3,
4, 5, 6, 7,
5, 8, 9, 6,
10, 11, 12, 13
};
cubeFaces.resize(4);
cubeFaces[0] = &faces[0];
cubeFaces[1] = &faces[4];
cubeFaces[2] = &faces[8];
cubeFaces[3] = &faces[12];
return cubeFaces;
}
std::ostream& operator<< (std::ostream& stream, std::vector<cvf::uint> v)
{
for (size_t i = 0; i < v.size(); ++i)
{
stream << v[i] << " ";
}
return stream;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(CellFaceIntersectionTst, Intersection1)
{
std::vector<cvf::Vec3d> nodes = createVertices();
std::vector<cvf::Vec3d> additionalVertices;
std::vector< std::vector<cvf::uint> > overlapPolygons;
std::vector<caf::UintArray4> faces = getCubeFaces();
EdgeIntersectStorage<cvf::uint> edgeIntersectionStorage;
edgeIntersectionStorage.setVertexCount(nodes.size());
{
std::vector<cvf::uint> polygon;
bool isOk = false;
isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(
&polygon,
&additionalVertices,
&edgeIntersectionStorage,
wrapArrayConst(&nodes),
faces[0].data(),
faces[1].data(),
1e-6);
EXPECT_EQ( (size_t)5, polygon.size());
EXPECT_EQ( (size_t)2, additionalVertices.size());
EXPECT_TRUE(isOk);
overlapPolygons.push_back(polygon);
std::cout << polygon << std::endl;
}
{
std::vector<cvf::uint> polygon;
bool isOk = false;
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;
bool isOk = false;
isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(
&polygon,
&additionalVertices,
&edgeIntersectionStorage,
wrapArrayConst(&nodes),
faces[0].data(),
faces[3].data(),
1e-6);
EXPECT_EQ( (size_t)3, polygon.size());
EXPECT_EQ( (size_t)6, additionalVertices.size());
EXPECT_TRUE(isOk);
overlapPolygons.push_back(polygon);
std::cout << polygon << std::endl;
}
nodes.insert(nodes.end(), additionalVertices.begin(), additionalVertices.end());
std::vector<cvf::uint> basePolygon;
basePolygon.insert(basePolygon.begin(), faces[0].data(), &(faces[0].data()[4]));
for (cvf::uint vxIdx = 0; vxIdx < nodes.size(); ++vxIdx)
{
bool inserted = GeometryTools::insertVertexInPolygon(
&basePolygon,
wrapArrayConst(&nodes),
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)
{
for (cvf::uint vxIdx = 0; vxIdx < nodes.size(); ++vxIdx)
{
bool inserted = GeometryTools::insertVertexInPolygon(
&overlapPolygons[pIdx],
wrapArrayConst(&nodes),
vxIdx,
1e-6
);
}
if (pIdx == 0)
{
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;
}
Vec3d normal = quadNormal(wrapArrayConst(&nodes), faces[0].data());
std::vector<bool> faceOverlapPolygonWindingSameAsCubeFaceFlags;
faceOverlapPolygonWindingSameAsCubeFaceFlags.resize(overlapPolygons.size(), true);
{
std::vector<cvf::uint> freeFacePolygon;
bool hasHoles = false;
std::vector< std::vector<cvf::uint>* > overlapPolygonPtrs;
for (size_t pIdx = 0; pIdx < overlapPolygons.size(); ++pIdx)
{
overlapPolygonPtrs.push_back(&(overlapPolygons[pIdx]));
}
GeometryTools::calculatePartiallyFreeCubeFacePolygon(
wrapArrayConst(&nodes),
wrapArrayConst(&basePolygon),
normal,
overlapPolygonPtrs,
faceOverlapPolygonWindingSameAsCubeFaceFlags,
&freeFacePolygon,
&hasHoles
);
EXPECT_EQ( (size_t)4, freeFacePolygon.size());
EXPECT_FALSE(hasHoles);
std::cout << "FF1: " << freeFacePolygon << std::endl;
}
{
std::vector<cvf::uint> freeFacePolygon;
bool hasHoles = false;
std::vector< std::vector<cvf::uint>* > overlapPolygonPtrs;
for (size_t pIdx = 0; pIdx < 1; ++pIdx)
{
overlapPolygonPtrs.push_back(&(overlapPolygons[pIdx]));
}
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)
{
std::vector<cvf::Vec3d> additionalVertices;
cvf::Vec3dArray nodes;
std::vector<size_t> polygon;
cvf::Array<size_t> ids;
size_t cv1CubeFaceIndices[4] = {0, 1, 2, 3};
size_t cv2CubeFaceIndices[4] = {4, 5, 6, 7};
nodes.resize(8);
nodes.setAll(cvf::Vec3d(0, 0, 0));
EdgeIntersectStorage<size_t> edgeIntersectionStorage;
edgeIntersectionStorage.setVertexCount(nodes.size());
// Face 1
nodes[0] = cvf::Vec3d(0, 0, 0);
nodes[1] = cvf::Vec3d(1, 0, 0);
nodes[2] = cvf::Vec3d(1, 1, 0);
nodes[3] = cvf::Vec3d(0, 1, 0);
// Face 2
nodes[4] = cvf::Vec3d(0, 0, 0);
nodes[5] = cvf::Vec3d(1, 0, 0);
nodes[6] = cvf::Vec3d(1, 1, 0);
nodes[7] = cvf::Vec3d(0, 1, 0);
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6);
EXPECT_EQ( (size_t)4, polygon.size());
EXPECT_EQ( (size_t)0, additionalVertices.size());
EXPECT_TRUE(isOk);
// Face 1
nodes[0] = cvf::Vec3d(0, 0, 0);
nodes[1] = cvf::Vec3d(1, 0, 0);
nodes[2] = cvf::Vec3d(1, 1, 0);
nodes[3] = cvf::Vec3d(0, 1, 0);
// Face 2
nodes[4] = cvf::Vec3d(0.5, -0.25, 0);
nodes[5] = cvf::Vec3d(1.25, 0.5, 0);
nodes[6] = cvf::Vec3d(0.5, 1.25, 0);
nodes[7] = cvf::Vec3d(-0.25, 0.5, 0);
polygon.clear();
isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6);
EXPECT_EQ( (size_t)8, polygon.size());
EXPECT_EQ( (size_t)8, additionalVertices.size());
EXPECT_TRUE(isOk);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(CellFaceIntersectionTst, FreeFacePolygon)
{
std::vector<cvf::Vec3d> additionalVertices;
cvf::Vec3dArray nodes;
std::vector<size_t> polygon;
cvf::Array<size_t> ids;
size_t cv1CubeFaceIndices[4] = {0, 1, 2, 3};
size_t cv2CubeFaceIndices[4] = {4, 5, 6, 7};
nodes.resize(8);
nodes.setAll(cvf::Vec3d(0, 0, 0));
EdgeIntersectStorage<size_t> edgeIntersectionStorage;
edgeIntersectionStorage.setVertexCount(nodes.size());
// Face 1
nodes[0] = cvf::Vec3d(0, 0, 0);
nodes[1] = cvf::Vec3d(1, 0, 0);
nodes[2] = cvf::Vec3d(1, 1, 0);
nodes[3] = cvf::Vec3d(0, 1, 0);
// Face 2
nodes[4] = cvf::Vec3d(0, 0, 0);
nodes[5] = cvf::Vec3d(1, 0, 0);
nodes[6] = cvf::Vec3d(1, 1, 0);
nodes[7] = cvf::Vec3d(0, 1, 0);
bool isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6);
EXPECT_EQ( (size_t)4, polygon.size());
EXPECT_EQ( (size_t)0, additionalVertices.size());
EXPECT_TRUE(isOk);
std::vector< bool > faceOverlapPolygonWinding;
std::vector< std::vector<size_t>* > faceOverlapPolygons;
faceOverlapPolygons.push_back(&polygon);
faceOverlapPolygonWinding.push_back(true);
std::vector<size_t> partialFacePolygon;
bool hasHoles = false;
GeometryTools::calculatePartiallyFreeCubeFacePolygon(
wrapArrayConst(&nodes),
wrapArrayConst(cv1CubeFaceIndices, 4),
Vec3d(0,0,1),
faceOverlapPolygons,
faceOverlapPolygonWinding,
&partialFacePolygon,
&hasHoles);
// Face 1
nodes[0] = cvf::Vec3d(0, 0, 0);
nodes[1] = cvf::Vec3d(1, 0, 0);
nodes[2] = cvf::Vec3d(1, 1, 0);
nodes[3] = cvf::Vec3d(0, 1, 0);
// Face 2
nodes[4] = cvf::Vec3d(0.5, -0.25, 0);
nodes[5] = cvf::Vec3d(1.25, 0.5, 0);
nodes[6] = cvf::Vec3d(0.5, 1.25, 0);
nodes[7] = cvf::Vec3d(-0.25, 0.5, 0);
polygon.clear();
isOk = GeometryTools::calculateOverlapPolygonOfTwoQuads(&polygon, &additionalVertices, &edgeIntersectionStorage,
wrapArrayConst(&nodes), cv1CubeFaceIndices, cv2CubeFaceIndices, 1e-6);
EXPECT_EQ( (size_t)8, polygon.size());
EXPECT_EQ( (size_t)8, additionalVertices.size());
EXPECT_TRUE(isOk);
}

View File

@@ -1,46 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight 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.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "cvfBase.h"
#include "gtest/gtest.h"
#include <stdio.h>
#include "cvfTrace.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
//printf("Running main() from LibCore_UnitTests.cpp\n");
//printf("LibCore version: %s.%s-%s (%s) \n\n", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_BUILD_NUMBER, CVF_SPECIAL_BUILD);
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
std::cout << "Please press <Enter> to close the window.";
std::cin.get();
return result;
}