#1558 Move Hexintersection methods to a separate file

To make it easierr to see and use from other code.
This commit is contained in:
Jacob Støren 2017-06-14 14:15:29 +02:00
parent cb72a4bfa4
commit c0d493f690
10 changed files with 172 additions and 102 deletions

View File

@ -49,6 +49,7 @@ ${CEE_CURRENT_LIST_DIR}RigEclipseNativeVisibleCellsStatCalc.h
${CEE_CURRENT_LIST_DIR}RigEclipseMultiPropertyStatCalc.h
${CEE_CURRENT_LIST_DIR}RigWellLogCurveData.h
${CEE_CURRENT_LIST_DIR}RigWellLogExtractionTools.h
${CEE_CURRENT_LIST_DIR}RigHexIntersectionTools.h
${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.h
${CEE_CURRENT_LIST_DIR}RigCurveDataTools.h
${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.h
@ -100,6 +101,7 @@ ${CEE_CURRENT_LIST_DIR}RigEclipseNativeStatCalc.cpp
${CEE_CURRENT_LIST_DIR}RigEclipseNativeVisibleCellsStatCalc.cpp
${CEE_CURRENT_LIST_DIR}RigEclipseMultiPropertyStatCalc.cpp
${CEE_CURRENT_LIST_DIR}RigWellLogCurveData.cpp
${CEE_CURRENT_LIST_DIR}RigHexIntersectionTools.cpp
${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.cpp
${CEE_CURRENT_LIST_DIR}RigCurveDataTools.cpp
${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.cpp

View File

@ -85,7 +85,7 @@ void RigEclipseWellLogExtractor::calculateIntersection()
hexCorners[7] = nodeCoords[cornerIndices[7]];
//int intersectionCount = RigHexIntersector::lineHexCellIntersection(p1, p2, hexCorners, closeCells[cIdx], &intersections);
RigHexIntersector::lineHexCellIntersection(p1, p2, hexCorners, closeCells[cIdx], &intersections);
RigHexIntersectionTools::lineHexCellIntersection(p1, p2, hexCorners, closeCells[cIdx], &intersections);
}
if (!isCellFaceNormalsOut)

View File

@ -28,6 +28,7 @@
#include "RigWellLogExtractionTools.h"
#include "RigWellPath.h"
#include "cvfGeometryTools.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -155,7 +156,7 @@ void RigGeoMechWellLogExtractor::calculateIntersection()
hexCorners[7] = cvf::Vec3d(nodeCoords[cornerIndices[7]]);
//int intersectionCount = RigHexIntersector::lineHexCellIntersection(p1, p2, hexCorners, closeCells[ccIdx], &intersections);
RigHexIntersector::lineHexCellIntersection(p1, p2, hexCorners, closeCells[ccIdx], &intersections);
RigHexIntersectionTools::lineHexCellIntersection(p1, p2, hexCorners, closeCells[ccIdx], &intersections);
}
// Now, with all the intersections of this piece of line, we need to

View File

@ -0,0 +1,91 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
// 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 "RigHexIntersectionTools.h"
#include "cvfBoundingBox.h"
#include "cvfGeometryTools.h"
#include "cvfRay.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RigHexIntersectionTools::lineHexCellIntersection(const cvf::Vec3d p1, const cvf::Vec3d p2, const cvf::Vec3d hexCorners[8], const size_t hexIndex, std::vector<HexIntersectionInfo>* intersections)
{
CVF_ASSERT(intersections != NULL);
int intersectionCount = 0;
for ( int face = 0; face < 6 ; ++face )
{
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(static_cast<cvf::StructGridInterface::FaceType>(face), faceVertexIndices);
cvf::Vec3d intersection;
bool isEntering = false;
cvf::Vec3d faceCenter = cvf::GeometryTools::computeFaceCenter(hexCorners[faceVertexIndices[0]], hexCorners[faceVertexIndices[1]], hexCorners[faceVertexIndices[2]], hexCorners[faceVertexIndices[3]]);
for ( int i = 0; i < 4; ++i )
{
int next = i < 3 ? i+1 : 0;
int intsStatus = cvf::GeometryTools::intersectLineSegmentTriangle(p1, p2,
hexCorners[faceVertexIndices[i]],
hexCorners[faceVertexIndices[next]],
faceCenter,
&intersection,
&isEntering);
if ( intsStatus == 1 )
{
intersectionCount++;
intersections->push_back(HexIntersectionInfo(intersection,
isEntering,
static_cast<cvf::StructGridInterface::FaceType>(face), hexIndex));
}
}
}
return intersectionCount;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigHexIntersectionTools::isPointInCell(const cvf::Vec3d point, const cvf::Vec3d hexCorners[8])
{
cvf::Ray ray;
ray.setOrigin(point);
size_t intersections = 0;
for ( int face = 0; face < 6; ++face )
{
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(static_cast<cvf::StructGridInterface::FaceType>(face), faceVertexIndices);
cvf::Vec3d faceCenter = cvf::GeometryTools::computeFaceCenter(hexCorners[faceVertexIndices[0]], hexCorners[faceVertexIndices[1]], hexCorners[faceVertexIndices[2]], hexCorners[faceVertexIndices[3]]);
for ( int i = 0; i < 4; ++i )
{
int next = i < 3 ? i + 1 : 0;
if ( ray.triangleIntersect(hexCorners[faceVertexIndices[i]], hexCorners[faceVertexIndices[next]], faceCenter) )
{
++intersections;
}
}
}
return intersections % 2 == 1;
}

View File

@ -0,0 +1,64 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfVector3.h"
#include "cvfStructGrid.h"
//==================================================================================================
/// Internal class for intersection point info
//==================================================================================================
struct HexIntersectionInfo
{
public:
HexIntersectionInfo( cvf::Vec3d intersectionPoint,
bool isIntersectionEntering,
cvf::StructGridInterface::FaceType face,
size_t hexIndex)
: m_intersectionPoint(intersectionPoint),
m_isIntersectionEntering(isIntersectionEntering),
m_face(face),
m_hexIndex(hexIndex) {}
cvf::Vec3d m_intersectionPoint;
bool m_isIntersectionEntering;
cvf::StructGridInterface::FaceType m_face;
size_t m_hexIndex;
};
//--------------------------------------------------------------------------------------------------
/// Specialized Line - Hex intersection
//--------------------------------------------------------------------------------------------------
struct RigHexIntersectionTools
{
static int lineHexCellIntersection(const cvf::Vec3d p1,
const cvf::Vec3d p2,
const cvf::Vec3d hexCorners[8],
const size_t hexIndex,
std::vector<HexIntersectionInfo>* intersections);
static bool isPointInCell(const cvf::Vec3d point, const cvf::Vec3d hexCorners[8]);
};

View File

@ -18,105 +18,16 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBoundingBox.h"
#include "cvfGeometryTools.h"
#include "cvfStructGrid.h"
#include "cvfRay.h"
//==================================================================================================
/// Internal class for intersection point info
///
///
//==================================================================================================
struct HexIntersectionInfo
struct RigWellLogExtractionTools
{
public:
HexIntersectionInfo( cvf::Vec3d intersectionPoint,
bool isIntersectionEntering,
cvf::StructGridInterface::FaceType face,
size_t hexIndex)
: m_intersectionPoint(intersectionPoint),
m_isIntersectionEntering(isIntersectionEntering),
m_face(face),
m_hexIndex(hexIndex) {}
cvf::Vec3d m_intersectionPoint;
bool m_isIntersectionEntering;
cvf::StructGridInterface::FaceType m_face;
size_t m_hexIndex;
};
//--------------------------------------------------------------------------------------------------
/// Specialized Line - Hex intersection
//--------------------------------------------------------------------------------------------------
struct RigHexIntersector
{
static int lineHexCellIntersection(const cvf::Vec3d p1, const cvf::Vec3d p2, const cvf::Vec3d hexCorners[8], const size_t hexIndex,
std::vector<HexIntersectionInfo>* intersections)
static bool isEqualDepth(double d1, double d2)
{
CVF_ASSERT(intersections != NULL);
int intersectionCount = 0;
for (int face = 0; face < 6 ; ++face)
{
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(static_cast<cvf::StructGridInterface::FaceType>(face), faceVertexIndices);
cvf::Vec3d intersection;
bool isEntering = false;
cvf::Vec3d faceCenter = cvf::GeometryTools::computeFaceCenter(hexCorners[faceVertexIndices[0]], hexCorners[faceVertexIndices[1]], hexCorners[faceVertexIndices[2]], hexCorners[faceVertexIndices[3]]);
for (int i = 0; i < 4; ++i)
{
int next = i < 3 ? i+1 : 0;
int intsStatus = cvf::GeometryTools::intersectLineSegmentTriangle(p1, p2,
hexCorners[faceVertexIndices[i]],
hexCorners[faceVertexIndices[next]],
faceCenter,
&intersection,
&isEntering);
if (intsStatus == 1)
{
intersectionCount++;
intersections->push_back(HexIntersectionInfo(intersection,
isEntering,
static_cast<cvf::StructGridInterface::FaceType>(face), hexIndex));
}
}
}
return intersectionCount;
}
static bool isPointInCell(const cvf::Vec3d point, const cvf::Vec3d hexCorners[8])
{
cvf::Ray ray;
ray.setOrigin(point);
size_t intersections = 0;
for (int face = 0; face < 6; ++face)
{
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(static_cast<cvf::StructGridInterface::FaceType>(face), faceVertexIndices);
cvf::Vec3d faceCenter = cvf::GeometryTools::computeFaceCenter(hexCorners[faceVertexIndices[0]], hexCorners[faceVertexIndices[1]], hexCorners[faceVertexIndices[2]], hexCorners[faceVertexIndices[3]]);
for (int i = 0; i < 4; ++i)
{
int next = i < 3 ? i + 1 : 0;
if (ray.triangleIntersect(hexCorners[faceVertexIndices[i]], hexCorners[faceVertexIndices[next]], faceCenter))
{
++intersections;
}
}
}
return intersections % 2 == 1;
}
static bool isEqualDepth(double d1, double d2)
{
double depthDiff = d1 - d2;
const double tolerance = 0.1;// Meters To handle inaccuracies across faults
@ -142,7 +53,7 @@ struct RigMDCellIdxEnterLeaveKey
bool operator < (const RigMDCellIdxEnterLeaveKey& other) const
{
if (RigHexIntersector::isEqualDepth(measuredDepth, other.measuredDepth))
if (RigWellLogExtractionTools::isEqualDepth(measuredDepth, other.measuredDepth))
{
if (hexIndex == other.hexIndex)
{
@ -182,7 +93,7 @@ struct RigMDEnterLeaveCellIdxKey
bool operator < (const RigMDEnterLeaveCellIdxKey& other) const
{
if (RigHexIntersector::isEqualDepth(measuredDepth, other.measuredDepth))
if (RigWellLogExtractionTools::isEqualDepth(measuredDepth, other.measuredDepth))
{
if (isEnteringCell == other.isEnteringCell)
{
@ -207,7 +118,7 @@ struct RigMDEnterLeaveCellIdxKey
{
return ( key1.hexIndex == key2.hexIndex
&& key1.isEnteringCell && key2.isLeavingCell()
&& !RigHexIntersector::isEqualDepth(key1.measuredDepth, key2.measuredDepth));
&& !RigWellLogExtractionTools::isEqualDepth(key1.measuredDepth, key2.measuredDepth));
}
};

View File

@ -85,7 +85,7 @@ void RigWellLogExtractor::populateReturnArrays(std::map<RigMDCellIdxEnterLeaveKe
++it2;
if (it2 != uniqueIntersections.end())
{
if (RigHexIntersector::isEqualDepth(it1->first.measuredDepth, it2->first.measuredDepth))
if (RigWellLogExtractionTools::isEqualDepth(it1->first.measuredDepth, it2->first.measuredDepth))
{
if (it1->first.hexIndex == it2->first.hexIndex)
{

View File

@ -28,6 +28,7 @@
#include "cvfStructGrid.h"
#include "RigWellLogExtractionTools.h"
#include "RigHexIntersectionTools.h"
class RigWellPath;

View File

@ -115,7 +115,7 @@ std::vector<HexIntersectionInfo> RigWellPathIntersectionTools::getIntersectedCel
grid->cellCornerVertices(closeCell, hexCorners.data());
RigHexIntersector::lineHexCellIntersection(coords[i], coords[i + 1], hexCorners.data(), closeCell, &intersections);
RigHexIntersectionTools::lineHexCellIntersection(coords[i], coords[i + 1], hexCorners.data(), closeCell, &intersections);
}
}
@ -181,7 +181,7 @@ size_t RigWellPathIntersectionTools::findCellFromCoords(const RigMainGrid* grid,
grid->cellCornerVertices(closeCell, hexCorners.data());
if (RigHexIntersector::isPointInCell(coords, hexCorners.data()))
if (RigHexIntersectionTools::isPointInCell(coords, hexCorners.data()))
{
*foundCell = true;
return closeCell;

View File

@ -20,7 +20,7 @@
#include "RigCell.h"
#include "RigWellLogExtractionTools.h"
#include "RigHexIntersectionTools.h"
#include "cvfVector3.h"