2018-03-09 06:15:01 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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 "Riv3dWellLogCurveGeomertyGenerator.h"
|
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
#include "RigCurveDataTools.h"
|
2018-03-12 10:18:40 -05:00
|
|
|
#include "RigWellPath.h"
|
|
|
|
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
2018-03-13 03:25:29 -05:00
|
|
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
2018-03-09 06:15:01 -06:00
|
|
|
|
2018-03-13 03:42:54 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
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-03-13 03:25:29 -05:00
|
|
|
cvf::ref<cvf::DrawableGeo>
|
|
|
|
Riv3dWellLogCurveGeometryGenerator::createCurveLine(const caf::DisplayCoordTransform* displayCoordTransform,
|
|
|
|
const Rim3dWellLogCurve* rim3dWellLogCurve) const
|
2018-03-09 06:15:01 -06:00
|
|
|
{
|
2018-03-13 03:25:29 -05:00
|
|
|
std::vector<cvf::Vec3f> vertices;
|
|
|
|
std::vector<cvf::uint> indices;
|
|
|
|
|
|
|
|
createCurveVerticesAndIndices(rim3dWellLogCurve, displayCoordTransform, &vertices, &indices);
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-15 07:04:39 -05:00
|
|
|
if (vertices.empty() || indices.empty())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-09 06:15:01 -06:00
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
2018-03-13 03:25:29 -05:00
|
|
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
2018-03-09 06:15:01 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-03-12 10:18:40 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-13 03:25:29 -05:00
|
|
|
///
|
2018-03-12 10:18:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-13 03:25:29 -05:00
|
|
|
cvf::ref<cvf::DrawableGeo> Riv3dWellLogCurveGeometryGenerator::createGrid(const caf::DisplayCoordTransform* displayCoordTransform,
|
2018-03-20 05:29:46 -05:00
|
|
|
const Rim3dWellLogCurve::DrawPlane drawPlane,
|
2018-03-20 02:26:28 -05:00
|
|
|
double gridIntervalSize) const
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-20 02:26:28 -05:00
|
|
|
CVF_ASSERT(gridIntervalSize > 0);
|
|
|
|
|
|
|
|
if (m_wellPathGeometry.isNull()) return nullptr;
|
2018-03-15 07:04:39 -05:00
|
|
|
|
2018-03-12 10:18:40 -05:00
|
|
|
std::vector<cvf::Vec3d> wellPathPoints = m_wellPathGeometry->m_wellPathPoints;
|
2018-03-20 02:26:28 -05:00
|
|
|
if (wellPathPoints.empty()) return nullptr;
|
|
|
|
|
|
|
|
const cvf::Vec3d globalDirection = (wellPathPoints.back() - wellPathPoints.front()).getNormalized();
|
|
|
|
const cvf::Vec3d up(0, 0, 1);
|
|
|
|
|
|
|
|
std::vector<cvf::Vec3d> pointNormals;
|
|
|
|
std::vector<cvf::Vec3d> gridPoints;
|
|
|
|
|
|
|
|
double firstMd = m_wellPathGeometry->m_measuredDepths.front();
|
|
|
|
double lastMd = m_wellPathGeometry->m_measuredDepths.back();
|
|
|
|
if (m_wellPathGeometry->m_measuredDepths.empty()) return nullptr;
|
|
|
|
|
|
|
|
double md = firstMd;
|
|
|
|
while (md <= lastMd)
|
|
|
|
{
|
|
|
|
cvf::Vec3d point = m_wellPathGeometry->interpolatedPointAlongWellPath(md);
|
|
|
|
gridPoints.push_back(point);
|
|
|
|
md += gridIntervalSize;
|
|
|
|
}
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-20 05:29:46 -05:00
|
|
|
pointNormals = calculatePointNormals(drawPlane, gridPoints);
|
2018-03-20 03:10:06 -05:00
|
|
|
if (pointNormals.size() != gridPoints.size()) return nullptr;
|
|
|
|
|
2018-03-14 08:22:14 -05:00
|
|
|
std::vector<cvf::Vec3f> vertices;
|
2018-03-20 02:26:28 -05:00
|
|
|
vertices.reserve(gridPoints.size() * 2);
|
2018-03-12 10:18:40 -05:00
|
|
|
|
|
|
|
std::vector<cvf::uint> indices;
|
2018-03-20 02:26:28 -05:00
|
|
|
indices.reserve(gridPoints.size() * 2);
|
2018-03-12 10:18:40 -05:00
|
|
|
|
|
|
|
cvf::uint counter = 0;
|
|
|
|
|
2018-03-20 02:26:28 -05:00
|
|
|
for (size_t i = 0; i < pointNormals.size(); i++)
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-20 02:26:28 -05:00
|
|
|
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(gridPoints[i])));
|
|
|
|
vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord(gridPoints[i] + pointNormals[i] * 100)));
|
2018-03-12 10:18:40 -05:00
|
|
|
|
|
|
|
indices.push_back(counter++);
|
|
|
|
indices.push_back(counter++);
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
2018-03-13 03:25:29 -05:00
|
|
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-20 02:26:28 -05:00
|
|
|
cvf::ref<cvf::DrawableGeo> drawable = new cvf::DrawableGeo();
|
2018-03-12 10:18:40 -05:00
|
|
|
|
|
|
|
indexedUInt->setIndices(indexArray.p());
|
|
|
|
drawable->addPrimitiveSet(indexedUInt.p());
|
|
|
|
|
|
|
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices);
|
|
|
|
drawable->setVertexArray(vertexArray.p());
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-13 03:25:29 -05:00
|
|
|
///
|
2018-03-12 10:18:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-13 03:25:29 -05:00
|
|
|
void Riv3dWellLogCurveGeometryGenerator::createCurveVerticesAndIndices(const Rim3dWellLogCurve* rim3dWellLogCurve,
|
|
|
|
const caf::DisplayCoordTransform* displayCoordTransform,
|
|
|
|
std::vector<cvf::Vec3f>* vertices,
|
|
|
|
std::vector<cvf::uint>* indices) const
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-15 06:55:50 -05:00
|
|
|
if (m_wellPathGeometry.isNull()) return;
|
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
std::vector<double> resultValues;
|
|
|
|
std::vector<double> mds;
|
2018-03-15 06:55:50 -05:00
|
|
|
rim3dWellLogCurve->curveValuesAndMds(&resultValues, &mds);
|
2018-03-13 03:25:29 -05:00
|
|
|
|
2018-03-15 06:55:50 -05:00
|
|
|
if (resultValues.empty()) return;
|
2018-03-13 03:25:29 -05:00
|
|
|
CVF_ASSERT(resultValues.size() == mds.size());
|
|
|
|
|
2018-03-14 08:22:14 -05:00
|
|
|
cvf::Vec3d globalDirection =
|
|
|
|
(m_wellPathGeometry->m_wellPathPoints.back() - m_wellPathGeometry->m_wellPathPoints.front()).getNormalized();
|
|
|
|
|
|
|
|
std::vector<cvf::Vec3d> interpolatedWellPathPoints;
|
|
|
|
interpolatedWellPathPoints.reserve(mds.size());
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
for (double md : mds)
|
|
|
|
{
|
2018-03-14 08:22:14 -05:00
|
|
|
interpolatedWellPathPoints.push_back(m_wellPathGeometry->interpolatedPointAlongWellPath(md));
|
2018-03-13 03:25:29 -05:00
|
|
|
}
|
|
|
|
|
2018-03-14 08:22:14 -05:00
|
|
|
std::vector<cvf::Vec3d> pointNormals = calculatePointNormals(rim3dWellLogCurve->drawPlane(), interpolatedWellPathPoints);
|
2018-03-20 03:10:06 -05:00
|
|
|
if (interpolatedWellPathPoints.size() != pointNormals.size()) return;
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
double maxResult = -HUGE_VAL;
|
|
|
|
double minResult = HUGE_VAL;
|
|
|
|
|
|
|
|
for (double result : resultValues)
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-13 03:25:29 -05:00
|
|
|
if (!RigCurveDataTools::isValidValue(result, false)) continue;
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
maxResult = std::max(result, maxResult);
|
|
|
|
minResult = std::min(result, minResult);
|
|
|
|
}
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-14 08:22:14 -05:00
|
|
|
vertices->resize(interpolatedWellPathPoints.size());
|
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
double range = maxResult - minResult;
|
|
|
|
double factor = 60.0 / range;
|
2018-03-14 08:22:14 -05:00
|
|
|
double offset = 30.0;
|
|
|
|
|
|
|
|
if (minResult < 0)
|
|
|
|
{
|
|
|
|
offset += cvf::Math::abs(minResult * factor);
|
|
|
|
}
|
2018-03-12 10:18:40 -05:00
|
|
|
|
2018-03-14 08:22:14 -05:00
|
|
|
for (size_t i = 0; i < pointNormals.size(); i++)
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-13 03:25:29 -05:00
|
|
|
cvf::Vec3d result(0, 0, 0);
|
|
|
|
|
|
|
|
if (RigCurveDataTools::isValidValue(resultValues[i], false))
|
|
|
|
{
|
2018-03-14 08:22:14 -05:00
|
|
|
result = resultValues[i] * factor * pointNormals[i];
|
2018-03-13 03:25:29 -05:00
|
|
|
}
|
|
|
|
|
2018-03-14 08:22:14 -05:00
|
|
|
(*vertices)[i] = cvf::Vec3f(
|
|
|
|
displayCoordTransform->transformToDisplayCoord(interpolatedWellPathPoints[i] + pointNormals[i] * offset + result));
|
2018-03-12 10:18:40 -05:00
|
|
|
}
|
|
|
|
|
2018-03-13 03:25:29 -05:00
|
|
|
std::vector<std::pair<size_t, size_t>> valuesIntervals =
|
|
|
|
RigCurveDataTools::calculateIntervalsOfValidValues(resultValues, false);
|
|
|
|
|
|
|
|
for (const std::pair<size_t, size_t>& interval : valuesIntervals)
|
|
|
|
{
|
|
|
|
for (size_t i = interval.first; i < interval.second; i++)
|
|
|
|
{
|
|
|
|
indices->push_back(cvf::uint(i));
|
|
|
|
indices->push_back(cvf::uint(i + 1));
|
|
|
|
}
|
|
|
|
}
|
2018-03-12 10:18:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-13 03:25:29 -05:00
|
|
|
///
|
2018-03-12 10:18:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-20 02:26:28 -05:00
|
|
|
std::vector<cvf::Vec3d> Riv3dWellLogCurveGeometryGenerator::calculatePointNormals(Rim3dWellLogCurve::DrawPlane drawPlane,
|
2018-03-20 03:10:06 -05:00
|
|
|
const std::vector<cvf::Vec3d>& points) const
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-20 03:10:06 -05:00
|
|
|
std::vector<cvf::Vec3d> pointNormals;
|
|
|
|
|
|
|
|
if (m_wellPathGeometry.isNull()) return pointNormals;
|
|
|
|
pointNormals.reserve(points.size());
|
2018-03-20 02:26:28 -05:00
|
|
|
|
2018-03-20 03:10:06 -05:00
|
|
|
const cvf::Vec3d globalDirection = (points.back() - points.front()).getNormalized();
|
2018-03-14 08:22:14 -05:00
|
|
|
const cvf::Vec3d up(0, 0, 1);
|
|
|
|
|
2018-03-20 03:10:06 -05:00
|
|
|
for (const cvf::Vec3d point : points)
|
2018-03-12 10:18:40 -05:00
|
|
|
{
|
2018-03-20 03:10:06 -05:00
|
|
|
cvf::Vec3d p1 = cvf::Vec3d::UNDEFINED;
|
|
|
|
cvf::Vec3d p2 = cvf::Vec3d::UNDEFINED;
|
|
|
|
m_wellPathGeometry->twoClosestPoints(point, &p1, &p2);
|
|
|
|
if (p1.isUndefined() || p2.isUndefined()) continue;
|
|
|
|
|
|
|
|
cvf::Vec3d vecAlongPath = (p2 - p1).getNormalized();
|
2018-03-14 08:22:14 -05:00
|
|
|
|
|
|
|
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::Vec3d Ez = (Ex ^ Ey).getNormalized();
|
|
|
|
|
|
|
|
cvf::Vec3d normal;
|
|
|
|
|
|
|
|
switch (drawPlane)
|
|
|
|
{
|
2018-03-20 03:10:06 -05:00
|
|
|
case Rim3dWellLogCurve::HORIZONTAL_LEFT:
|
|
|
|
normal = -Ey;
|
|
|
|
break;
|
|
|
|
case Rim3dWellLogCurve::HORIZONTAL_RIGHT:
|
|
|
|
normal = Ey;
|
|
|
|
break;
|
|
|
|
case Rim3dWellLogCurve::VERTICAL_ABOVE:
|
|
|
|
normal = Ez;
|
|
|
|
break;
|
|
|
|
case Rim3dWellLogCurve::VERTICAL_BELOW:
|
|
|
|
normal = -Ez;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-03-14 08:22:14 -05:00
|
|
|
}
|
|
|
|
|
2018-03-20 03:10:06 -05:00
|
|
|
pointNormals.push_back(normal);
|
2018-03-12 10:18:40 -05:00
|
|
|
}
|
2018-03-14 08:22:14 -05:00
|
|
|
|
|
|
|
return pointNormals;
|
2018-03-12 10:18:40 -05:00
|
|
|
}
|