2018-03-09 06:15:01 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-03-09 06:15:01 -06:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-02 05:10:05 -05:00
|
|
|
#include "Riv3dWellLogCurveGeometryGenerator.h"
|
2018-03-09 06:15:01 -06:00
|
|
|
|
2018-06-08 08:10:45 -05:00
|
|
|
#include "RiaCurveDataTools.h"
|
2018-03-12 10:18:40 -05:00
|
|
|
#include "RigWellPath.h"
|
2018-03-22 08:35:54 -05:00
|
|
|
#include "RigWellPathGeometryTools.h"
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-10-11 09:03:49 -05:00
|
|
|
#include "Rim3dWellLogCurve.h"
|
|
|
|
#include "RimWellPath.h"
|
|
|
|
#include "RimWellPathCollection.h"
|
|
|
|
|
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
#include "cafLine.h"
|
2018-03-12 10:18:40 -05:00
|
|
|
#include "cafDisplayCoordTransform.h"
|
2018-03-13 03:25:29 -05:00
|
|
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
2018-03-09 06:15:01 -06:00
|
|
|
|
2018-03-21 03:48:51 -05:00
|
|
|
#include "cvfBoundingBox.h"
|
2018-04-20 09:08:17 -05:00
|
|
|
#include "cvfMath.h"
|
2018-03-21 03:48:51 -05:00
|
|
|
|
2018-03-21 10:22:35 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-22 03:54:58 -05:00
|
|
|
Riv3dWellLogCurveGeometryGenerator::Riv3dWellLogCurveGeometryGenerator(RimWellPath* wellPath)
|
2018-03-21 10:22:35 -05:00
|
|
|
: m_wellPath(wellPath)
|
2018-04-20 09:08:17 -05:00
|
|
|
, m_planeWidth(0.0)
|
2018-03-21 10:22:35 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-09 06:15:01 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-13 03:25:29 -05:00
|
|
|
///
|
2018-03-09 06:15:01 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-20 09:08:17 -05:00
|
|
|
void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::DisplayCoordTransform* displayCoordTransform,
|
|
|
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
2018-04-30 02:22:59 -05:00
|
|
|
const Rim3dWellLogCurve* rim3dWellLogCurve,
|
2018-04-20 09:08:17 -05:00
|
|
|
double planeOffsetFromWellPathCenter,
|
2018-05-02 03:21:27 -05:00
|
|
|
double planeWidth,
|
2018-06-20 03:31:03 -05:00
|
|
|
const std::vector<cvf::Vec3d>& drawSurfaceVertices,
|
|
|
|
int currentTimeStep)
|
2018-03-09 06:15:01 -06:00
|
|
|
{
|
2018-05-07 07:47:03 -05:00
|
|
|
CVF_ASSERT(rim3dWellLogCurve);
|
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
// Make sure all drawables are cleared in case we return early to avoid a
|
|
|
|
// previous drawable being "stuck" when changing result type.
|
|
|
|
clearCurvePointsAndGeometry();
|
2018-05-07 07:47:03 -05:00
|
|
|
|
|
|
|
float curveUIRange = rim3dWellLogCurve->maxCurveUIValue() - rim3dWellLogCurve->minCurveUIValue();
|
|
|
|
if (curveUIRange < 1.0e-6f)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
|
2018-04-30 02:22:59 -05:00
|
|
|
std::vector<double> resultValues;
|
|
|
|
std::vector<double> resultMds;
|
2018-06-20 03:31:03 -05:00
|
|
|
if (rim3dWellLogCurve->followAnimationTimeStep())
|
|
|
|
{
|
|
|
|
rim3dWellLogCurve->curveValuesAndMdsAtTimeStep(&resultValues, &resultMds, currentTimeStep);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rim3dWellLogCurve->curveValuesAndMds(&resultValues, &resultMds);
|
|
|
|
}
|
2018-04-30 02:22:59 -05:00
|
|
|
|
2018-04-20 09:08:17 -05:00
|
|
|
m_planeWidth = planeWidth;
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-20 07:51:51 -05:00
|
|
|
if (!wellPathGeometry()) return;
|
2018-03-21 07:15:48 -05:00
|
|
|
if (wellPathGeometry()->m_wellPathPoints.empty()) return;
|
|
|
|
if (!wellPathClipBoundingBox.isValid()) return;
|
2018-03-15 06:55:50 -05:00
|
|
|
|
|
|
|
if (resultValues.empty()) return;
|
2018-03-21 10:22:35 -05:00
|
|
|
CVF_ASSERT(resultValues.size() == resultMds.size());
|
2018-03-13 03:25:29 -05:00
|
|
|
|
2018-03-21 07:15:48 -05:00
|
|
|
RimWellPathCollection* wellPathCollection = nullptr;
|
|
|
|
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
|
|
|
|
|
2018-04-18 04:09:50 -05:00
|
|
|
cvf::Vec3d clipLocation = wellPathGeometry()->m_wellPathPoints.front();
|
2018-03-21 07:15:48 -05:00
|
|
|
if (wellPathCollection->wellPathClip)
|
|
|
|
{
|
2018-04-18 04:09:50 -05:00
|
|
|
double clipZDistance = wellPathCollection->wellPathClipZDistance;
|
2018-05-02 03:21:27 -05:00
|
|
|
clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
|
2018-03-21 07:15:48 -05:00
|
|
|
}
|
2018-04-18 04:09:50 -05:00
|
|
|
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
|
2018-03-14 08:22:14 -05:00
|
|
|
|
2019-01-03 06:16:26 -06:00
|
|
|
std::vector<cvf::Vec3d> displayCoords = displayCoordTransform->transformToDisplayCoords(wellPathGeometry()->m_wellPathPoints);
|
2018-04-18 04:09:50 -05:00
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
std::vector<cvf::Vec3d> wellPathCurveNormals =
|
2019-01-03 06:16:26 -06:00
|
|
|
RigWellPathGeometryTools::calculateLineSegmentNormals(displayCoords, rim3dWellLogCurve->drawPlaneAngle(rim3dWellLogCurve->drawPlane()));
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-04-13 07:36:37 -05:00
|
|
|
std::vector<cvf::Vec3d> interpolatedWellPathPoints;
|
2018-04-16 03:42:01 -05:00
|
|
|
std::vector<cvf::Vec3d> interpolatedCurveNormals;
|
2018-03-21 10:22:35 -05:00
|
|
|
// Iterate from bottom of well path and up to be able to stop at given Z max clipping height
|
|
|
|
for (auto md = resultMds.rbegin(); md != resultMds.rend(); md++)
|
2018-03-13 03:25:29 -05:00
|
|
|
{
|
2019-01-03 06:16:26 -06:00
|
|
|
cvf::Vec3d point = wellPathGeometry()->interpolatedVectorValuesAlongWellPath(displayCoords, *md);
|
2018-09-27 02:55:28 -05:00
|
|
|
cvf::Vec3d normal = wellPathGeometry()->interpolatedVectorValuesAlongWellPath(wellPathCurveNormals, *md);
|
2018-04-18 04:09:50 -05:00
|
|
|
if (point.z() > clipLocation.z()) break;
|
2018-03-21 07:15:48 -05:00
|
|
|
|
|
|
|
interpolatedWellPathPoints.push_back(point);
|
2018-04-16 03:42:01 -05:00
|
|
|
interpolatedCurveNormals.push_back(normal.getNormalized());
|
2018-03-13 03:25:29 -05:00
|
|
|
}
|
2018-03-21 10:22:35 -05:00
|
|
|
if (interpolatedWellPathPoints.empty()) return;
|
2018-03-13 03:25:29 -05:00
|
|
|
|
2018-03-22 02:54:48 -05:00
|
|
|
// Reverse list, since it was filled in the opposite order
|
2018-03-21 10:22:35 -05:00
|
|
|
std::reverse(interpolatedWellPathPoints.begin(), interpolatedWellPathPoints.end());
|
2018-04-16 03:42:01 -05:00
|
|
|
std::reverse(interpolatedCurveNormals.begin(), interpolatedCurveNormals.end());
|
2018-03-21 07:15:48 -05:00
|
|
|
|
2018-03-22 02:54:48 -05:00
|
|
|
// The result values for the part of the well which is not clipped off, matching interpolatedWellPathPoints size
|
2018-05-02 03:21:27 -05:00
|
|
|
m_curveValues = std::vector<double>(resultValues.end() - interpolatedWellPathPoints.size(), resultValues.end());
|
|
|
|
m_curveMeasuredDepths = std::vector<double>(resultMds.end() - interpolatedWellPathPoints.size(), resultMds.end());
|
2018-03-21 07:15:48 -05:00
|
|
|
|
2018-05-18 03:50:13 -05:00
|
|
|
double maxVisibleResult = -std::numeric_limits<double>::max();
|
|
|
|
double minVisibleResult = std::numeric_limits<double>::max();
|
2018-05-07 07:47:03 -05:00
|
|
|
|
2018-05-15 10:16:43 -05:00
|
|
|
double minCurveValue = rim3dWellLogCurve->minCurveUIValue();
|
|
|
|
double maxCurveValue = rim3dWellLogCurve->maxCurveUIValue();
|
|
|
|
|
2018-05-07 07:47:03 -05:00
|
|
|
double curveEpsilon = 1.0e-6;
|
2018-03-13 03:25:29 -05:00
|
|
|
|
2018-04-20 09:08:17 -05:00
|
|
|
for (double& result : m_curveValues)
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-06-08 08:10:45 -05:00
|
|
|
if (!RiaCurveDataTools::isValidValue(result, false)) continue;
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-05-15 10:16:43 -05:00
|
|
|
if ((minCurveValue - result) > curveEpsilon * curveUIRange)
|
2018-05-07 07:47:03 -05:00
|
|
|
{
|
2018-05-15 10:16:43 -05:00
|
|
|
result = minCurveValue - curveEpsilon;
|
2018-05-07 07:47:03 -05:00
|
|
|
}
|
2018-05-15 10:16:43 -05:00
|
|
|
else if ((result - maxCurveValue) > curveEpsilon * curveUIRange)
|
2018-05-07 07:47:03 -05:00
|
|
|
{
|
2018-05-15 10:16:43 -05:00
|
|
|
result = maxCurveValue + curveEpsilon;
|
2018-05-07 07:47:03 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maxVisibleResult = std::max(result, maxVisibleResult);
|
|
|
|
minVisibleResult = std::min(result, minVisibleResult);
|
|
|
|
}
|
2018-04-19 06:42:53 -05:00
|
|
|
}
|
|
|
|
|
2018-05-07 07:47:03 -05:00
|
|
|
if (minVisibleResult > maxVisibleResult)
|
2018-04-19 06:42:53 -05:00
|
|
|
{
|
|
|
|
return;
|
2018-03-13 03:25:29 -05:00
|
|
|
}
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-05-07 07:47:03 -05:00
|
|
|
double plotRangeToResultRangeFactor = planeWidth / curveUIRange;
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-05-04 06:20:49 -05:00
|
|
|
m_curveVertices.reserve(interpolatedWellPathPoints.size());
|
2018-04-20 09:08:17 -05:00
|
|
|
for (size_t i = 0; i < interpolatedWellPathPoints.size(); i++)
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-20 09:36:57 -05:00
|
|
|
double scaledResult = 0;
|
2018-03-13 03:25:29 -05:00
|
|
|
|
2018-06-08 08:10:45 -05:00
|
|
|
if (RiaCurveDataTools::isValidValue(m_curveValues[i], false))
|
2018-03-13 03:25:29 -05:00
|
|
|
{
|
2018-05-15 10:16:43 -05:00
|
|
|
scaledResult = planeOffsetFromWellPathCenter + (m_curveValues[i] - minCurveValue) * plotRangeToResultRangeFactor;
|
2018-03-13 03:25:29 -05:00
|
|
|
}
|
2018-04-20 09:08:17 -05:00
|
|
|
cvf::Vec3d curvePoint(interpolatedWellPathPoints[i] + scaledResult * interpolatedCurveNormals[i]);
|
2018-05-18 03:50:13 -05:00
|
|
|
m_curveVertices.push_back(curvePoint);
|
2018-03-12 10:18:40 -05:00
|
|
|
}
|
2018-05-04 06:20:49 -05:00
|
|
|
m_curveVertices = projectVerticesOntoTriangles(m_curveVertices, drawSurfaceVertices);
|
|
|
|
|
2018-05-03 02:24:23 -05:00
|
|
|
createNewVerticesAlongTriangleEdges(drawSurfaceVertices);
|
2018-05-02 03:21:27 -05:00
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
{
|
2018-05-04 06:20:49 -05:00
|
|
|
std::vector<cvf::uint> indices;
|
|
|
|
indices.reserve(m_curveVertices.size() * 2);
|
|
|
|
for (size_t i = 0; i < m_curveVertices.size() - 1; ++i)
|
|
|
|
{
|
2018-06-08 08:10:45 -05:00
|
|
|
if (RiaCurveDataTools::isValidValue(m_curveValues[i], false) &&
|
|
|
|
RiaCurveDataTools::isValidValue(m_curveValues[i + 1], false))
|
2018-05-07 07:47:03 -05:00
|
|
|
{
|
2018-05-15 10:16:43 -05:00
|
|
|
if (cvf::Math::valueInRange(m_curveValues[i], minCurveValue, maxCurveValue) ||
|
|
|
|
cvf::Math::valueInRange(m_curveValues[i + 1], minCurveValue, maxCurveValue))
|
|
|
|
{
|
|
|
|
indices.push_back(cvf::uint(i));
|
|
|
|
indices.push_back(cvf::uint(i + 1));
|
|
|
|
}
|
2018-05-07 07:47:03 -05:00
|
|
|
}
|
2018-05-04 06:20:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
|
|
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
|
|
|
|
|
|
|
m_curveDrawable = new cvf::DrawableGeo();
|
|
|
|
|
|
|
|
indexedUInt->setIndices(indexArray.p());
|
|
|
|
m_curveDrawable->addPrimitiveSet(indexedUInt.p());
|
|
|
|
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(m_curveVertices.size());
|
|
|
|
for (size_t i = 0; i < m_curveVertices.size(); ++i)
|
|
|
|
{
|
|
|
|
(*vertexArray)[i] = cvf::Vec3f(m_curveVertices[i]);
|
|
|
|
}
|
2018-05-04 06:20:49 -05:00
|
|
|
m_curveDrawable->setVertexArray(vertexArray.p());
|
2018-03-13 03:25:29 -05:00
|
|
|
}
|
2018-04-20 09:08:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-30 01:11:06 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void Riv3dWellLogCurveGeometryGenerator::clearCurvePointsAndGeometry()
|
|
|
|
{
|
|
|
|
m_curveDrawable = nullptr;
|
|
|
|
m_curveVertices.clear();
|
|
|
|
m_curveMeasuredDepths.clear();
|
|
|
|
m_curveValues.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-20 09:08:17 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::ref<cvf::DrawableGeo> Riv3dWellLogCurveGeometryGenerator::curveDrawable()
|
|
|
|
{
|
|
|
|
return m_curveDrawable;
|
2018-03-12 10:18:40 -05:00
|
|
|
}
|
|
|
|
|
2018-03-20 07:51:51 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-20 09:36:57 -05:00
|
|
|
///
|
2018-03-20 07:51:51 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const RigWellPath* Riv3dWellLogCurveGeometryGenerator::wellPathGeometry() const
|
|
|
|
{
|
|
|
|
return m_wellPath->wellPathGeometry();
|
|
|
|
}
|
2018-04-20 09:08:17 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool Riv3dWellLogCurveGeometryGenerator::findClosestPointOnCurve(const cvf::Vec3d& globalIntersection,
|
|
|
|
cvf::Vec3d* closestPoint,
|
|
|
|
double* measuredDepthAtPoint,
|
|
|
|
double* valueAtClosestPoint) const
|
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
double closestDistance = m_planeWidth * 0.1;
|
2018-05-02 03:21:27 -05:00
|
|
|
*closestPoint = cvf::Vec3d::UNDEFINED;
|
|
|
|
*measuredDepthAtPoint = cvf::UNDEFINED_DOUBLE;
|
|
|
|
*valueAtClosestPoint = cvf::UNDEFINED_DOUBLE;
|
2018-04-20 09:08:17 -05:00
|
|
|
if (m_curveVertices.size() < 2u) false;
|
|
|
|
CVF_ASSERT(m_curveVertices.size() == m_curveValues.size());
|
|
|
|
for (size_t i = 1; i < m_curveVertices.size(); ++i)
|
|
|
|
{
|
2018-06-08 08:10:45 -05:00
|
|
|
bool validCurveSegment = RiaCurveDataTools::isValidValue(m_curveValues[i], false) &&
|
|
|
|
RiaCurveDataTools::isValidValue(m_curveValues[i - 1], false);
|
2018-04-20 09:08:17 -05:00
|
|
|
if (validCurveSegment)
|
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d a = m_curveVertices[i - 1];
|
|
|
|
cvf::Vec3d b = m_curveVertices[i];
|
|
|
|
cvf::Vec3d ap = globalIntersection - a;
|
|
|
|
cvf::Vec3d ab = b - a;
|
2018-04-20 09:08:17 -05:00
|
|
|
// Projected point is clamped to one of the end points of the segment.
|
2018-05-18 03:50:13 -05:00
|
|
|
double distanceToProjectedPointAlongAB = ap * ab / (ab * ab);
|
|
|
|
double clampedDistance = cvf::Math::clamp(distanceToProjectedPointAlongAB, 0.0, 1.0);
|
|
|
|
cvf::Vec3d projectionOfGlobalIntersection = a + clampedDistance * ab;
|
|
|
|
double distance = (projectionOfGlobalIntersection - globalIntersection).length();
|
2018-04-20 09:08:17 -05:00
|
|
|
if (distance < closestDistance)
|
|
|
|
{
|
2018-05-02 03:21:27 -05:00
|
|
|
*closestPoint = cvf::Vec3d(projectionOfGlobalIntersection);
|
2018-04-20 09:08:17 -05:00
|
|
|
closestDistance = distance;
|
2018-05-02 03:21:27 -05:00
|
|
|
*measuredDepthAtPoint =
|
2018-05-18 03:50:13 -05:00
|
|
|
m_curveMeasuredDepths[i - 1] * (1.0 - clampedDistance) + m_curveMeasuredDepths[i] * clampedDistance;
|
|
|
|
*valueAtClosestPoint = m_curveValues[i - 1] * (1.0 - clampedDistance) + m_curveValues[i] * clampedDistance;
|
2018-04-20 09:08:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
if (closestPoint->isUndefined()) return false;
|
|
|
|
|
2018-04-20 09:08:17 -05:00
|
|
|
return true;
|
|
|
|
}
|
2018-05-02 03:21:27 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-05-18 03:50:13 -05:00
|
|
|
void Riv3dWellLogCurveGeometryGenerator::createNewVerticesAlongTriangleEdges(const std::vector<cvf::Vec3d>& drawSurfaceVertices)
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
std::vector<cvf::Vec3d> expandedCurveVertices;
|
2018-05-04 06:20:49 -05:00
|
|
|
std::vector<double> expandedMeasuredDepths;
|
|
|
|
std::vector<double> expandedValues;
|
|
|
|
size_t estimatedNumberOfPoints = m_curveVertices.size() + drawSurfaceVertices.size();
|
2018-05-02 03:21:27 -05:00
|
|
|
expandedCurveVertices.reserve(estimatedNumberOfPoints);
|
|
|
|
expandedMeasuredDepths.reserve(estimatedNumberOfPoints);
|
|
|
|
expandedValues.reserve(estimatedNumberOfPoints);
|
2018-05-04 06:20:49 -05:00
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
for (size_t i = 0; i < m_curveVertices.size() - 1; i += 2)
|
|
|
|
{
|
2018-06-08 08:10:45 -05:00
|
|
|
if (RiaCurveDataTools::isValidValue(m_curveValues[i], false) &&
|
|
|
|
RiaCurveDataTools::isValidValue(m_curveValues[i + 1], false))
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d lastVertex = m_curveVertices[i];
|
|
|
|
cvf::Vec3d fullSegmentVector = m_curveVertices[i + 1] - m_curveVertices[i];
|
2018-05-04 06:20:49 -05:00
|
|
|
|
2018-05-18 03:50:13 -05:00
|
|
|
std::vector<cvf::Vec3d> extraVertices;
|
2018-05-04 06:20:49 -05:00
|
|
|
|
|
|
|
createNewVerticesAlongSegment(m_curveVertices[i],
|
|
|
|
m_curveVertices[i + 1],
|
|
|
|
drawSurfaceVertices,
|
2018-05-18 04:04:42 -05:00
|
|
|
&extraVertices);
|
2018-05-04 06:20:49 -05:00
|
|
|
|
2018-05-18 03:50:13 -05:00
|
|
|
for (const cvf::Vec3d& extraVertex : extraVertices)
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d newSegmentVector = extraVertex - lastVertex;
|
2018-05-04 06:20:49 -05:00
|
|
|
// Scalar projection (a * b / |b|) divided by full segment length to become (a * b / |b|^2)
|
2018-05-18 03:50:13 -05:00
|
|
|
double dotProduct = newSegmentVector * fullSegmentVector;
|
|
|
|
double fractionAlongFullSegment = dotProduct / fullSegmentVector.lengthSquared();
|
|
|
|
double measuredDepth = m_curveMeasuredDepths[i] * (1 - fractionAlongFullSegment) +
|
|
|
|
m_curveMeasuredDepths[i + 1] * fractionAlongFullSegment;
|
|
|
|
double valueAtPoint =
|
2018-05-04 06:20:49 -05:00
|
|
|
m_curveValues[i] * (1 - fractionAlongFullSegment) + m_curveValues[i + 1] * fractionAlongFullSegment;
|
|
|
|
expandedCurveVertices.push_back(extraVertex);
|
|
|
|
expandedMeasuredDepths.push_back(measuredDepth);
|
|
|
|
expandedValues.push_back(valueAtPoint);
|
|
|
|
lastVertex = extraVertex;
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
}
|
2018-05-07 07:47:03 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add the invalid points and values.
|
|
|
|
expandedCurveVertices.push_back(m_curveVertices[i]);
|
|
|
|
expandedMeasuredDepths.push_back(m_curveMeasuredDepths[i]);
|
|
|
|
expandedValues.push_back(m_curveValues[i]);
|
|
|
|
|
|
|
|
}
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_curveVertices.swap(expandedCurveVertices);
|
|
|
|
m_curveMeasuredDepths.swap(expandedMeasuredDepths);
|
|
|
|
m_curveValues.swap(expandedValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-05-18 03:50:13 -05:00
|
|
|
void Riv3dWellLogCurveGeometryGenerator::createNewVerticesAlongSegment(const cvf::Vec3d& ptStart,
|
|
|
|
const cvf::Vec3d& ptEnd,
|
|
|
|
const std::vector<cvf::Vec3d>& drawSurfaceVertices,
|
2018-05-18 04:04:42 -05:00
|
|
|
std::vector<cvf::Vec3d>* extraVertices)
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d fullSegmentVector = ptEnd - ptStart;
|
2018-05-04 06:20:49 -05:00
|
|
|
extraVertices->push_back(ptStart);
|
|
|
|
|
|
|
|
// Find segments that intersects the triangle edges
|
|
|
|
for (size_t j = 0; j < drawSurfaceVertices.size() - 2; j += 1)
|
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
caf::Line<double> triangleEdge1 = caf::Line<double>(drawSurfaceVertices[j], drawSurfaceVertices[j + 1]);
|
|
|
|
caf::Line<double> triangleEdge2 = caf::Line<double>(drawSurfaceVertices[j + 2], drawSurfaceVertices[j + 1]);
|
|
|
|
cvf::Vec3d triangleNormal =
|
2018-05-04 06:20:49 -05:00
|
|
|
(triangleEdge1.vector().getNormalized() ^ triangleEdge2.vector().getNormalized()).getNormalized();
|
|
|
|
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d currentSubSegment = ptEnd - extraVertices->back();
|
|
|
|
cvf::Vec3d projectedSegmentVector = currentSubSegment - (currentSubSegment * triangleNormal) * triangleNormal;
|
|
|
|
caf::Line<double> projectedCurveLine(extraVertices->back(), extraVertices->back() + projectedSegmentVector);
|
2018-05-04 06:20:49 -05:00
|
|
|
|
|
|
|
// Only attempt to find intersections with the first edge. The other edge is handled with the next triangle.
|
2018-05-18 03:50:13 -05:00
|
|
|
bool withinSegments = false;
|
|
|
|
caf::Line<double> connectingLine = projectedCurveLine.findLineBetweenNearestPoints(triangleEdge1, &withinSegments);
|
2018-05-04 06:20:49 -05:00
|
|
|
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d newVertex = connectingLine.end();
|
|
|
|
cvf::Vec3d newSegmentVector = newVertex - extraVertices->back();
|
2018-05-07 13:07:12 -05:00
|
|
|
if (withinSegments && newSegmentVector.lengthSquared() < currentSubSegment.lengthSquared())
|
2018-05-04 06:20:49 -05:00
|
|
|
{
|
|
|
|
extraVertices->push_back(newVertex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extraVertices->push_back(ptEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-05-18 03:50:13 -05:00
|
|
|
std::vector<cvf::Vec3d>
|
|
|
|
Riv3dWellLogCurveGeometryGenerator::projectVerticesOntoTriangles(const std::vector<cvf::Vec3d>& originalVertices,
|
|
|
|
const std::vector<cvf::Vec3d>& drawSurfaceVertices)
|
2018-05-04 06:20:49 -05:00
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
std::vector<cvf::Vec3d> projectedVertices;
|
2018-05-04 06:20:49 -05:00
|
|
|
projectedVertices.reserve(originalVertices.size());
|
|
|
|
for (size_t i = 0; i < originalVertices.size(); ++i)
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
2018-05-03 02:24:23 -05:00
|
|
|
// Sort projections onto triangle by the distance of the projection.
|
2018-05-18 03:50:13 -05:00
|
|
|
std::map<double, cvf::Vec3d> projectionsInsideTriangle;
|
2018-05-02 05:10:05 -05:00
|
|
|
for (size_t j = 0; j < drawSurfaceVertices.size() - 2; j += 1)
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d triangleVertex1, triangleVertex2, triangleVertex3;
|
2018-05-02 03:21:27 -05:00
|
|
|
if (j % 2 == 0)
|
|
|
|
{
|
2018-05-02 05:10:05 -05:00
|
|
|
triangleVertex1 = drawSurfaceVertices[j];
|
|
|
|
triangleVertex2 = drawSurfaceVertices[j + 1];
|
|
|
|
triangleVertex3 = drawSurfaceVertices[j + 2];
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-02 05:10:05 -05:00
|
|
|
triangleVertex1 = drawSurfaceVertices[j];
|
|
|
|
triangleVertex2 = drawSurfaceVertices[j + 2];
|
|
|
|
triangleVertex3 = drawSurfaceVertices[j + 1];
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
|
2018-05-04 06:20:49 -05:00
|
|
|
bool wasInsideTriangle = false;
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d projectedPoint = projectPointOntoTriangle(
|
2018-05-04 06:20:49 -05:00
|
|
|
originalVertices[i], triangleVertex1, triangleVertex2, triangleVertex3, &wasInsideTriangle);
|
2018-05-02 03:21:27 -05:00
|
|
|
if (wasInsideTriangle)
|
|
|
|
{
|
2018-05-04 06:20:49 -05:00
|
|
|
projectionsInsideTriangle.insert(
|
|
|
|
std::make_pair((projectedPoint - originalVertices[i]).lengthSquared(), projectedPoint));
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
}
|
2018-05-04 06:20:49 -05:00
|
|
|
|
2018-05-03 02:24:23 -05:00
|
|
|
// Take the closest projection
|
|
|
|
if (!projectionsInsideTriangle.empty())
|
|
|
|
{
|
2018-05-04 06:20:49 -05:00
|
|
|
projectedVertices.push_back(projectionsInsideTriangle.begin()->second);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
projectedVertices.push_back(originalVertices[i]);
|
2018-05-03 02:24:23 -05:00
|
|
|
}
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
2018-05-04 06:20:49 -05:00
|
|
|
return projectedVertices;
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d Riv3dWellLogCurveGeometryGenerator::projectPointOntoTriangle(const cvf::Vec3d& point,
|
|
|
|
const cvf::Vec3d& triangleVertex1,
|
|
|
|
const cvf::Vec3d& triangleVertex2,
|
|
|
|
const cvf::Vec3d& triangleVertex3,
|
2018-05-02 03:21:27 -05:00
|
|
|
bool* wasInsideTriangle)
|
|
|
|
{
|
|
|
|
*wasInsideTriangle = false;
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d e1 = triangleVertex2 - triangleVertex1;
|
|
|
|
cvf::Vec3d e2 = triangleVertex3 - triangleVertex1;
|
|
|
|
cvf::Vec3d n = (e1.getNormalized() ^ e2.getNormalized()).getNormalized();
|
2018-05-02 03:21:27 -05:00
|
|
|
|
|
|
|
// Project vertex onto triangle plane
|
2018-05-18 03:50:13 -05:00
|
|
|
cvf::Vec3d av = point - triangleVertex1;
|
|
|
|
cvf::Vec3d projectedAv = av - (av * n) * n;
|
|
|
|
cvf::Vec3d projectedPoint = projectedAv + triangleVertex1;
|
2018-05-04 06:20:49 -05:00
|
|
|
|
2018-05-02 03:21:27 -05:00
|
|
|
// Calculate barycentric coordinates
|
2018-05-18 03:50:13 -05:00
|
|
|
double areaABC = n * (e1 ^ e2);
|
|
|
|
double areaPBC = n * ((triangleVertex2 - projectedPoint) ^ (triangleVertex3 - projectedPoint));
|
|
|
|
double areaPCA = n * ((triangleVertex3 - projectedPoint) ^ (triangleVertex1 - projectedPoint));
|
|
|
|
double u = areaPBC / areaABC;
|
|
|
|
double v = areaPCA / areaABC;
|
|
|
|
double w = 1.0 - u - v;
|
2018-05-02 03:21:27 -05:00
|
|
|
|
2018-05-03 02:24:23 -05:00
|
|
|
if (u >= -1.0e-6 && v >= -1.0e-6 && w >= -1.0e-6)
|
2018-05-02 03:21:27 -05:00
|
|
|
{
|
|
|
|
*wasInsideTriangle = true;
|
2018-05-03 02:24:23 -05:00
|
|
|
// Clamp to ensure it is inside the triangle
|
2018-05-18 03:50:13 -05:00
|
|
|
u = cvf::Math::clamp(u, 0.0, 1.0);
|
|
|
|
v = cvf::Math::clamp(v, 0.0, 1.0);
|
|
|
|
w = cvf::Math::clamp(w, 0.0, 1.0);
|
2018-05-03 02:24:23 -05:00
|
|
|
projectedPoint = triangleVertex1 * u + triangleVertex2 * v + triangleVertex3 * w;
|
2018-05-02 03:21:27 -05:00
|
|
|
}
|
|
|
|
return projectedPoint;
|
|
|
|
}
|