#2636 3D Well log curve: Create well path geometry tools.

This commit is contained in:
Rebecca Cox 2018-03-22 14:35:54 +01:00
parent 73a08fffc4
commit 18bde3cd89
10 changed files with 404 additions and 240 deletions

View File

@ -42,6 +42,7 @@ ${CMAKE_CURRENT_LIST_DIR}/Riv3dWellLogCurveGeomertyGenerator.h
${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionFactorPartMgr.h
${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionFactorGeometryGenerator.h
${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionSourceInfo.h
${CMAKE_CURRENT_LIST_DIR}/Riv3dWellLogGridGeomertyGenerator.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -82,6 +83,7 @@ ${CMAKE_CURRENT_LIST_DIR}/Riv3dWellLogCurveGeomertyGenerator.cpp
${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionFactorPartMgr.cpp
${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionFactorGeometryGenerator.cpp
${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionSourceInfo.cpp
${CMAKE_CURRENT_LIST_DIR}/Riv3dWellLogGridGeomertyGenerator.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -23,6 +23,7 @@
#include "RigCurveDataTools.h"
#include "RigWellPath.h"
#include "RigWellPathGeometryTools.h"
#include "cafDisplayCoordTransform.h"
#include "cvfPrimitiveSetIndexedUInt.h"
@ -83,129 +84,6 @@ cvf::ref<cvf::DrawableGeo>
return drawable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> Riv3dWellLogCurveGeometryGenerator::createGrid(const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& wellPathClipBoundingBox,
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth,
double gridIntervalSize) const
{
CVF_ASSERT(gridIntervalSize > 0);
if (!wellPathGeometry()) return nullptr;
if (!wellPathClipBoundingBox.isValid()) return nullptr;
RimWellPathCollection* wellPathCollection = nullptr;
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
std::vector<cvf::Vec3d> wellPathPoints = wellPathGeometry()->m_wellPathPoints;
if (wellPathPoints.empty()) return nullptr;
size_t originalWellPathSize = wellPathPoints.size();
if (wellPathCollection->wellPathClip)
{
double horizontalLengthAlongWellToClipPoint;
double maxZClipHeight = wellPathClipBoundingBox.max().z() + wellPathCollection->wellPathClipZDistance;
size_t indexToFirstVisibleSegment;
wellPathPoints = RigWellPath::clipPolylineStartAboveZ(
wellPathPoints, maxZClipHeight, &horizontalLengthAlongWellToClipPoint, &indexToFirstVisibleSegment);
}
if (wellPathPoints.empty()) return nullptr;
std::vector<cvf::Vec3d> gridPoints;
if (wellPathGeometry()->m_measuredDepths.empty()) return nullptr;
size_t newStartIndex = originalWellPathSize - wellPathPoints.size();
double firstMd = wellPathGeometry()->m_measuredDepths.at(newStartIndex);
double lastMd = wellPathGeometry()->m_measuredDepths.back();
double md = lastMd;
while (md >= firstMd)
{
cvf::Vec3d point = wellPathGeometry()->interpolatedPointAlongWellPath(md);
gridPoints.push_back(point);
md -= gridIntervalSize;
}
std::vector<cvf::Vec3d> pointNormals;
std::vector<cvf::Vec3d> closestPoints;
calculatePairsOfClosestSamplingPointsAlongWellPath(&closestPoints, gridPoints);
pointNormals = calculateLineSegmentNormals(planeAngle, closestPoints, LINE_SEGMENTS);
if (pointNormals.size() != gridPoints.size()) return nullptr;
std::vector<cvf::Vec3f> vertices;
vertices.reserve(gridPoints.size() * 2);
std::vector<cvf::uint> indices;
indices.reserve(gridPoints.size() * 2);
cvf::uint indexCounter = 0;
// Normal lines
for (size_t i = 0; i < pointNormals.size(); i++)
{
vertices.push_back(cvf::Vec3f(
displayCoordTransform->transformToDisplayCoord(gridPoints[i] + pointNormals[i] * planeOffsetFromWellPathCenter)));
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(
gridPoints[i] + pointNormals[i] * (planeOffsetFromWellPathCenter + planeWidth))));
indices.push_back(indexCounter++);
indices.push_back(indexCounter++);
}
// calculateLineSegmentNormals returns normals for the whole well path. Erase the part which is clipped off
std::vector<cvf::Vec3d> wellPathSegmentNormals =
calculateLineSegmentNormals(planeAngle, wellPathGeometry()->m_wellPathPoints, POLYLINE);
wellPathSegmentNormals.erase(wellPathSegmentNormals.begin(), wellPathSegmentNormals.end() - wellPathPoints.size());
// Line along and close to well
for (size_t i = 0; i < wellPathPoints.size(); i++)
{
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(
wellPathPoints[i] + wellPathSegmentNormals[i] * planeOffsetFromWellPathCenter)));
indices.push_back(indexCounter);
indices.push_back(++indexCounter);
}
// Indices are added as line segments for the current point and the next point. The last point does not have a next point,
// therefore we remove the last line segment
indices.pop_back();
indices.pop_back();
// Line along and far away from well
for (size_t i = 0; i < wellPathPoints.size(); i++)
{
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(
wellPathPoints[i] + wellPathSegmentNormals[i] * (planeOffsetFromWellPathCenter + planeWidth))));
indices.push_back(indexCounter);
indices.push_back(++indexCounter);
}
indices.pop_back();
indices.pop_back();
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
cvf::ref<cvf::DrawableGeo> drawable = new cvf::DrawableGeo();
indexedUInt->setIndices(indexArray.p());
drawable->addPrimitiveSet(indexedUInt.p());
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices);
drawable->setVertexArray(vertexArray.p());
return drawable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -255,9 +133,9 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveVerticesAndIndices(const std
resultValues.end());
std::vector<cvf::Vec3d> pairsOfWellPathPoints;
calculatePairsOfClosestSamplingPointsAlongWellPath(&pairsOfWellPathPoints, interpolatedWellPathPoints);
RigWellPathGeometryTools::calculatePairsOfClosestSamplingPointsAlongWellPath(wellPathGeometry(), &pairsOfWellPathPoints, interpolatedWellPathPoints);
std::vector<cvf::Vec3d> pointNormals = calculateLineSegmentNormals(planeAngle, pairsOfWellPathPoints, LINE_SEGMENTS);
std::vector<cvf::Vec3d> pointNormals = RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathGeometry(), planeAngle, pairsOfWellPathPoints, RigWellPathGeometryTools::LINE_SEGMENTS);
if (interpolatedWellPathPoints.size() != pointNormals.size()) return;
double maxResult = -HUGE_VAL;
@ -302,73 +180,6 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveVerticesAndIndices(const std
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> Riv3dWellLogCurveGeometryGenerator::calculateLineSegmentNormals(double angle,
const std::vector<cvf::Vec3d>& vertices,
VertexOrganization organization) const
{
std::vector<cvf::Vec3d> pointNormals;
if (!wellPathGeometry()) return pointNormals;
if (vertices.empty()) return pointNormals;
const cvf::Vec3d globalDirection =
(wellPathGeometry()->m_wellPathPoints.back() - wellPathGeometry()->m_wellPathPoints.front()).getNormalized();
const cvf::Vec3d up(0, 0, 1);
size_t intervalSize;
if (organization == LINE_SEGMENTS)
{
pointNormals.reserve(vertices.size() / 2);
intervalSize = 2;
}
else // organization == POLYLINE
{
pointNormals.reserve(vertices.size());
intervalSize = 1;
}
cvf::Vec3d normal;
for (size_t i = 0; i < vertices.size() - 1; i += intervalSize)
{
cvf::Vec3d p1 = vertices[i];
cvf::Vec3d p2 = vertices[i + 1];
cvf::Vec3d vecAlongPath = (p2 - p1).getNormalized();
double dotProduct = up * vecAlongPath;
cvf::Vec3d Ex;
if (cvf::Math::abs(dotProduct) > 0.7071)
{
Ex = globalDirection;
}
else
{
Ex = vecAlongPath;
}
cvf::Vec3d Ey = (up ^ Ex).getNormalized();
cvf::Mat3d rotation;
normal = Ey.getTransformedVector(rotation.fromRotation(Ex, angle));
pointNormals.push_back(normal);
}
if (organization == POLYLINE)
{
pointNormals.push_back(normal);
}
return pointNormals;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -376,24 +187,3 @@ const RigWellPath* Riv3dWellLogCurveGeometryGenerator::wellPathGeometry() const
{
return m_wellPath->wellPathGeometry();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Riv3dWellLogCurveGeometryGenerator::calculatePairsOfClosestSamplingPointsAlongWellPath(
std::vector<cvf::Vec3d>* closestWellPathPoints,
std::vector<cvf::Vec3d>& points) const
{
CVF_ASSERT(closestWellPathPoints != nullptr);
for (const cvf::Vec3d point : points)
{
cvf::Vec3d p1 = cvf::Vec3d::UNDEFINED;
cvf::Vec3d p2 = cvf::Vec3d::UNDEFINED;
wellPathGeometry()->twoClosestPoints(point, &p1, &p2);
if (p1.isUndefined() || p2.isUndefined()) continue;
closestWellPathPoints->push_back(p1);
closestWellPathPoints->push_back(p2);
}
}

View File

@ -52,20 +52,6 @@ public:
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth) const;
cvf::ref<cvf::DrawableGeo> createGrid(const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& wellPathClipBoundingBox,
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth,
double gridIntervalSize) const;
private:
enum VertexOrganization
{
LINE_SEGMENTS,
POLYLINE
};
private:
void createCurveVerticesAndIndices(const std::vector<double>& resultValues,
const std::vector<double>& resultMds,
@ -77,15 +63,8 @@ private:
std::vector<cvf::Vec3f>* vertices,
std::vector<cvf::uint>* indices) const;
std::vector<cvf::Vec3d> calculateLineSegmentNormals(double angle,
const std::vector<cvf::Vec3d>& vertices,
VertexOrganization organization) const;
const RigWellPath* wellPathGeometry() const;
void calculatePairsOfClosestSamplingPointsAlongWellPath(std::vector<cvf::Vec3d>* closestWellPathPoints,
std::vector<cvf::Vec3d>& points) const;
private:
caf::PdmPointer<RimWellPath> m_wellPath;
};

View File

@ -0,0 +1,169 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- 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 "Riv3dWellLogGridGeomertyGenerator.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RigWellPath.h"
#include "RigWellPathGeometryTools.h"
#include "cafDisplayCoordTransform.h"
#include "cvfPrimitiveSetIndexedUInt.h"
#include "cvfBoundingBox.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Riv3dWellLogGridGeometryGenerator::Riv3dWellLogGridGeometryGenerator(RimWellPath* wellPath)
: m_wellPath(wellPath)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> Riv3dWellLogGridGeometryGenerator::createGrid(const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& wellPathClipBoundingBox,
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth,
double gridIntervalSize) const
{
CVF_ASSERT(gridIntervalSize > 0);
if (!wellPathGeometry()) return nullptr;
if (!wellPathClipBoundingBox.isValid()) return nullptr;
RimWellPathCollection* wellPathCollection = nullptr;
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
std::vector<cvf::Vec3d> wellPathPoints = wellPathGeometry()->m_wellPathPoints;
if (wellPathPoints.empty()) return nullptr;
size_t originalWellPathSize = wellPathPoints.size();
if (wellPathCollection->wellPathClip)
{
double horizontalLengthAlongWellToClipPoint;
double maxZClipHeight = wellPathClipBoundingBox.max().z() + wellPathCollection->wellPathClipZDistance;
size_t indexToFirstVisibleSegment;
wellPathPoints = RigWellPath::clipPolylineStartAboveZ(
wellPathPoints, maxZClipHeight, &horizontalLengthAlongWellToClipPoint, &indexToFirstVisibleSegment);
}
if (wellPathPoints.empty()) return nullptr;
std::vector<cvf::Vec3d> gridPoints;
if (wellPathGeometry()->m_measuredDepths.empty()) return nullptr;
size_t newStartIndex = originalWellPathSize - wellPathPoints.size();
double firstMd = wellPathGeometry()->m_measuredDepths.at(newStartIndex);
double lastMd = wellPathGeometry()->m_measuredDepths.back();
double md = lastMd;
while (md >= firstMd)
{
cvf::Vec3d point = wellPathGeometry()->interpolatedPointAlongWellPath(md);
gridPoints.push_back(point);
md -= gridIntervalSize;
}
std::vector<cvf::Vec3d> pointNormals;
std::vector<cvf::Vec3d> closestPoints;
RigWellPathGeometryTools::calculatePairsOfClosestSamplingPointsAlongWellPath(wellPathGeometry(), &closestPoints, gridPoints);
pointNormals = RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathGeometry(), planeAngle, closestPoints, RigWellPathGeometryTools::LINE_SEGMENTS);
if (pointNormals.size() != gridPoints.size()) return nullptr;
std::vector<cvf::Vec3f> vertices;
vertices.reserve(gridPoints.size() * 2);
std::vector<cvf::uint> indices;
indices.reserve(gridPoints.size() * 2);
cvf::uint indexCounter = 0;
// Normal lines
for (size_t i = 0; i < pointNormals.size(); i++)
{
vertices.push_back(cvf::Vec3f(
displayCoordTransform->transformToDisplayCoord(gridPoints[i] + pointNormals[i] * planeOffsetFromWellPathCenter)));
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(
gridPoints[i] + pointNormals[i] * (planeOffsetFromWellPathCenter + planeWidth))));
indices.push_back(indexCounter++);
indices.push_back(indexCounter++);
}
// calculateLineSegmentNormals returns normals for the whole well path. Erase the part which is clipped off
std::vector<cvf::Vec3d> wellPathSegmentNormals =
RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathGeometry(), planeAngle, wellPathGeometry()->m_wellPathPoints, RigWellPathGeometryTools::POLYLINE);
wellPathSegmentNormals.erase(wellPathSegmentNormals.begin(), wellPathSegmentNormals.end() - wellPathPoints.size());
// Line along and close to well
for (size_t i = 0; i < wellPathPoints.size(); i++)
{
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(
wellPathPoints[i] + wellPathSegmentNormals[i] * planeOffsetFromWellPathCenter)));
indices.push_back(indexCounter);
indices.push_back(++indexCounter);
}
// Indices are added as line segments for the current point and the next point. The last point does not have a next point,
// therefore we remove the last line segment
indices.pop_back();
indices.pop_back();
// Line along and far away from well
for (size_t i = 0; i < wellPathPoints.size(); i++)
{
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(
wellPathPoints[i] + wellPathSegmentNormals[i] * (planeOffsetFromWellPathCenter + planeWidth))));
indices.push_back(indexCounter);
indices.push_back(++indexCounter);
}
indices.pop_back();
indices.pop_back();
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
cvf::ref<cvf::DrawableGeo> drawable = new cvf::DrawableGeo();
indexedUInt->setIndices(indexArray.p());
drawable->addPrimitiveSet(indexedUInt.p());
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices);
drawable->setVertexArray(vertexArray.p());
return drawable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RigWellPath* Riv3dWellLogGridGeometryGenerator::wellPathGeometry() const
{
return m_wellPath->wellPathGeometry();
}

View File

@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- 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 "cvfDrawableGeo.h"
#include "cvfObject.h"
#include "cafPdmPointer.h"
#include <vector>
namespace caf
{
class DisplayCoordTransform;
}
namespace cvf
{
class BoundingBox;
}
class RigWellPath;
class RimWellPath;
class Riv3dWellLogGridGeometryGenerator : public cvf::Object
{
public:
Riv3dWellLogGridGeometryGenerator(RimWellPath* wellPath);
cvf::ref<cvf::DrawableGeo> createGrid(const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& wellPathClipBoundingBox,
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth,
double gridIntervalSize) const;
private:
const RigWellPath* wellPathGeometry() const;
private:
caf::PdmPointer<RimWellPath> m_wellPath;
};

View File

@ -27,6 +27,7 @@
#include "RimWellPath.h"
#include "Riv3dWellLogCurveGeomertyGenerator.h"
#include "Riv3dWellLogGridGeomertyGenerator.h"
#include "cafDisplayCoordTransform.h"
#include "cafEffectGenerator.h"
@ -46,6 +47,7 @@ Riv3dWellLogPlanePartMgr::Riv3dWellLogPlanePartMgr(RimWellPath* wellPath, RimGri
{
CVF_ASSERT(m_wellPath.notNull());
m_3dWellLogCurveGeometryGenerator = new Riv3dWellLogCurveGeometryGenerator(m_wellPath.p());
m_3dWellLogGridGeometryGenerator = new Riv3dWellLogGridGeometryGenerator(m_wellPath.p());
}
//--------------------------------------------------------------------------------------------------
@ -222,12 +224,12 @@ void Riv3dWellLogPlanePartMgr::appendGridToModel(cvf::ModelBasicList*
caf::MeshEffectGenerator meshEffectGen(cvf::Color3f(0.4f, 0.4f, 0.4f));
cvf::ref<cvf::Drawable> gridHorizontalDrawable =
m_3dWellLogCurveGeometryGenerator->createGrid(displayCoordTransform,
wellPathClipBoundingBox,
planeAngle(drawPlane),
wellPathCenterToPlotStartOffset(planePosition),
planeWidth(),
gridIntervalSize);
m_3dWellLogGridGeometryGenerator->createGrid(displayCoordTransform,
wellPathClipBoundingBox,
planeAngle(drawPlane),
wellPathCenterToPlotStartOffset(planePosition),
planeWidth(),
gridIntervalSize);
cvf::ref<cvf::Effect> effect = meshEffectGen.generateCachedEffect();
cvf::ref<cvf::Part> part = createPart(gridHorizontalDrawable.p(), effect.p());

View File

@ -46,6 +46,7 @@ class DisplayCoordTransform;
class RimGridView;
class RimWellPath;
class Riv3dWellLogCurveGeometryGenerator;
class Riv3dWellLogGridGeometryGenerator;
class Riv3dWellLogPlanePartMgr : public cvf::Object
{
@ -77,6 +78,7 @@ private:
private:
cvf::ref<Riv3dWellLogCurveGeometryGenerator> m_3dWellLogCurveGeometryGenerator;
cvf::ref<Riv3dWellLogGridGeometryGenerator> m_3dWellLogGridGeometryGenerator;
caf::PdmPointer<RimWellPath> m_wellPath;
caf::PdmPointer<RimGridView> m_gridView;

View File

@ -63,6 +63,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigWellPathFormations.h
${CMAKE_CURRENT_LIST_DIR}/RigStimPlanFractureDefinition.h
${CMAKE_CURRENT_LIST_DIR}/RigFractureGrid.h
${CMAKE_CURRENT_LIST_DIR}/RigFractureCell.h
${CMAKE_CURRENT_LIST_DIR}/RigWellPathGeometryTools.h
)
@ -125,6 +126,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigWellPathFormations.cpp
${CMAKE_CURRENT_LIST_DIR}/RigStimPlanFractureDefinition.cpp
${CMAKE_CURRENT_LIST_DIR}/RigFractureGrid.cpp
${CMAKE_CURRENT_LIST_DIR}/RigFractureCell.cpp
${CMAKE_CURRENT_LIST_DIR}/RigWellPathGeometryTools.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,111 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- 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 "RigWellPathGeometryTools.h"
#include "RigWellPath.h"
#include "cvfMatrix3.h"
#include "cvfMath.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> RigWellPathGeometryTools::calculateLineSegmentNormals(const RigWellPath* wellPathGeometry,
double angle,
const std::vector<cvf::Vec3d>& vertices,
VertexOrganization organization)
{
std::vector<cvf::Vec3d> pointNormals;
if (!wellPathGeometry) return pointNormals;
if (vertices.empty()) return pointNormals;
const cvf::Vec3d globalDirection =
(wellPathGeometry->m_wellPathPoints.back() - wellPathGeometry->m_wellPathPoints.front()).getNormalized();
const cvf::Vec3d up(0, 0, 1);
size_t intervalSize;
if (organization == LINE_SEGMENTS)
{
pointNormals.reserve(vertices.size() / 2);
intervalSize = 2;
}
else // organization == POLYLINE
{
pointNormals.reserve(vertices.size());
intervalSize = 1;
}
cvf::Vec3d normal;
for (size_t i = 0; i < vertices.size() - 1; i += intervalSize)
{
cvf::Vec3d p1 = vertices[i];
cvf::Vec3d p2 = vertices[i + 1];
cvf::Vec3d vecAlongPath = (p2 - p1).getNormalized();
double dotProduct = up * vecAlongPath;
cvf::Vec3d Ex;
if (cvf::Math::abs(dotProduct) > 0.7071)
{
Ex = globalDirection;
}
else
{
Ex = vecAlongPath;
}
cvf::Vec3d Ey = (up ^ Ex).getNormalized();
cvf::Mat3d rotation;
normal = Ey.getTransformedVector(rotation.fromRotation(Ex, angle));
pointNormals.push_back(normal);
}
if (organization == POLYLINE)
{
pointNormals.push_back(normal);
}
return pointNormals;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigWellPathGeometryTools::calculatePairsOfClosestSamplingPointsAlongWellPath(const RigWellPath* wellPathGeometry, std::vector<cvf::Vec3d>* closestWellPathPoints, std::vector<cvf::Vec3d>& points)
{
CVF_ASSERT(closestWellPathPoints != nullptr);
for (const cvf::Vec3d point : points)
{
cvf::Vec3d p1 = cvf::Vec3d::UNDEFINED;
cvf::Vec3d p2 = cvf::Vec3d::UNDEFINED;
wellPathGeometry->twoClosestPoints(point, &p1, &p2);
if (p1.isUndefined() || p2.isUndefined()) continue;
closestWellPathPoints->push_back(p1);
closestWellPathPoints->push_back(p2);
}
}

View File

@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- 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 <vector>
#include "cvfBase.h"
#include "cvfVector3.h"
class RigWellPath;
//==================================================================================================
///
//==================================================================================================
class RigWellPathGeometryTools
{
public:
enum VertexOrganization
{
LINE_SEGMENTS,
POLYLINE
};
public:
static std::vector<cvf::Vec3d> calculateLineSegmentNormals(const RigWellPath* wellPathGeometry,
double angle,
const std::vector<cvf::Vec3d>& vertices,
VertexOrganization organization);
static void calculatePairsOfClosestSamplingPointsAlongWellPath(const RigWellPath* wellPathGeometry,
std::vector<cvf::Vec3d>* closestWellPathPoints,
std::vector<cvf::Vec3d>& points);
};