diff --git a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake index 242927e1ac..926c871211 100644 --- a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake @@ -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 diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp index d3840eec23..edb8648b81 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp @@ -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) diff --git a/ApplicationCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp b/ApplicationCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp index b2814d2e0c..11c536b403 100644 --- a/ApplicationCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp @@ -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 diff --git a/ApplicationCode/ReservoirDataModel/RigHexIntersectionTools.cpp b/ApplicationCode/ReservoirDataModel/RigHexIntersectionTools.cpp new file mode 100644 index 0000000000..f3ea5ba4cf --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigHexIntersectionTools.cpp @@ -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 +// 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* intersections) +{ + CVF_ASSERT(intersections != NULL); + + int intersectionCount = 0; + + for ( int face = 0; face < 6 ; ++face ) + { + cvf::ubyte faceVertexIndices[4]; + cvf::StructGridInterface::cellFaceVertexIndices(static_cast(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(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(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; +} diff --git a/ApplicationCode/ReservoirDataModel/RigHexIntersectionTools.h b/ApplicationCode/ReservoirDataModel/RigHexIntersectionTools.h new file mode 100644 index 0000000000..eb240f25d8 --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigHexIntersectionTools.h @@ -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 +// 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* intersections); + + static bool isPointInCell(const cvf::Vec3d point, const cvf::Vec3d hexCorners[8]); + + +}; + + diff --git a/ApplicationCode/ReservoirDataModel/RigWellLogExtractionTools.h b/ApplicationCode/ReservoirDataModel/RigWellLogExtractionTools.h index 0cefe536eb..9c44c95ac7 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellLogExtractionTools.h +++ b/ApplicationCode/ReservoirDataModel/RigWellLogExtractionTools.h @@ -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* 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(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(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(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)); } }; diff --git a/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.cpp b/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.cpp index 8475aefc88..74f13fc9ba 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.cpp +++ b/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.cpp @@ -85,7 +85,7 @@ void RigWellLogExtractor::populateReturnArrays(std::mapfirst.measuredDepth, it2->first.measuredDepth)) + if (RigWellLogExtractionTools::isEqualDepth(it1->first.measuredDepth, it2->first.measuredDepth)) { if (it1->first.hexIndex == it2->first.hexIndex) { diff --git a/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.h b/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.h index a06ca717d6..29275b127d 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.h +++ b/ApplicationCode/ReservoirDataModel/RigWellLogExtractor.h @@ -28,6 +28,7 @@ #include "cvfStructGrid.h" #include "RigWellLogExtractionTools.h" +#include "RigHexIntersectionTools.h" class RigWellPath; diff --git a/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.cpp b/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.cpp index 544c5f7bde..781b2b6266 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.cpp +++ b/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.cpp @@ -115,7 +115,7 @@ std::vector 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; diff --git a/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.h b/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.h index 6711d8fdc6..705ca69654 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.h +++ b/ApplicationCode/ReservoirDataModel/RigWellPathIntersectionTools.h @@ -20,7 +20,7 @@ #include "RigCell.h" -#include "RigWellLogExtractionTools.h" +#include "RigHexIntersectionTools.h" #include "cvfVector3.h"