ResInsight/ApplicationCode/ModelVisualization/Riv3dWellLogCurveGeomertyGenerator.cpp

214 lines
9.6 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// 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"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RigCurveDataTools.h"
#include "RigWellPath.h"
#include "RigWellPathGeometryTools.h"
#include "cafDisplayCoordTransform.h"
#include "cvfPrimitiveSetIndexedUInt.h"
#include "cvfBoundingBox.h"
2018-03-13 03:42:54 -05:00
#include <cmath>
2018-03-21 10:22:35 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Riv3dWellLogCurveGeometryGenerator::Riv3dWellLogCurveGeometryGenerator(RimWellPath* wellPath)
2018-03-21 10:22:35 -05:00
: m_wellPath(wellPath)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo>
Riv3dWellLogCurveGeometryGenerator::createCurveLine(const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& wellPathClipBoundingBox,
const std::vector<double>& resultValues,
const std::vector<double>& resultMds,
double minResultValue,
double maxResultValue,
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth) const
{
std::vector<cvf::Vec3f> vertices;
std::vector<cvf::uint> indices;
2018-03-22 05:45:11 -05:00
createCurveVerticesAndIndices(resultValues,
resultMds,
minResultValue,
maxResultValue,
2018-03-22 05:45:11 -05:00
planeAngle,
planeOffsetFromWellPathCenter,
planeWidth,
displayCoordTransform,
wellPathClipBoundingBox,
&vertices,
&indices);
if (vertices.empty() || indices.empty())
{
return nullptr;
}
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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Riv3dWellLogCurveGeometryGenerator::createCurveVerticesAndIndices(const std::vector<double>& resultValues,
const std::vector<double>& resultMds,
double minResultValue,
double maxResultValue,
double planeAngle,
double planeOffsetFromWellPathCenter,
double planeWidth,
const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& wellPathClipBoundingBox,
std::vector<cvf::Vec3f>* vertices,
std::vector<cvf::uint>* indices) const
{
if (!wellPathGeometry()) return;
if (wellPathGeometry()->m_wellPathPoints.empty()) return;
if (!wellPathClipBoundingBox.isValid()) return;
if (resultValues.empty()) return;
2018-03-21 10:22:35 -05:00
CVF_ASSERT(resultValues.size() == resultMds.size());
if (maxResultValue - minResultValue < 1.0e-6)
{
return;
}
RimWellPathCollection* wellPathCollection = nullptr;
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
cvf::Vec3d clipLocation = wellPathGeometry()->m_wellPathPoints.front();
if (wellPathCollection->wellPathClip)
{
double clipZDistance = wellPathCollection->wellPathClipZDistance;
clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
}
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
std::vector<cvf::Vec3d> wellPathPoints = wellPathGeometry()->m_wellPathPoints;
for (cvf::Vec3d& wellPathPoint : wellPathPoints)
{
wellPathPoint = displayCoordTransform->transformToDisplayCoord(wellPathPoint);
}
std::vector<cvf::Vec3d> wellPathCurveNormals = RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathPoints, planeAngle);
std::vector<cvf::Vec3d> interpolatedWellPathPoints;
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++)
{
cvf::Vec3d point = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathPoints, *md);
cvf::Vec3d normal = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathCurveNormals, *md);
if (point.z() > clipLocation.z()) break;
interpolatedWellPathPoints.push_back(point);
interpolatedCurveNormals.push_back(normal.getNormalized());
}
2018-03-21 10:22:35 -05:00
if (interpolatedWellPathPoints.empty()) return;
// Reverse list, since it was filled in the opposite order
2018-03-21 10:22:35 -05:00
std::reverse(interpolatedWellPathPoints.begin(), interpolatedWellPathPoints.end());
std::reverse(interpolatedCurveNormals.begin(), interpolatedCurveNormals.end());
// The result values for the part of the well which is not clipped off, matching interpolatedWellPathPoints size
std::vector<double> resultValuesForInterpolatedPoints(resultValues.end() - interpolatedWellPathPoints.size(),
resultValues.end());
double maxClampedResult = -HUGE_VAL;
double minClampedResult = HUGE_VAL;
for (double& result : resultValuesForInterpolatedPoints)
{
if (!RigCurveDataTools::isValidValue(result, false)) continue;
result = cvf::Math::clamp(result, minResultValue, maxResultValue);
maxClampedResult = std::max(result, maxClampedResult);
minClampedResult = std::min(result, minClampedResult);
}
if (minClampedResult >= maxClampedResult)
{
return;
}
vertices->resize(interpolatedWellPathPoints.size());
double plotRangeToResultRangeFactor = planeWidth / (maxClampedResult - minClampedResult);
for (size_t i = 0; i < interpolatedCurveNormals.size(); i++)
{
double scaledResult = 0;
if (RigCurveDataTools::isValidValue(resultValuesForInterpolatedPoints[i], false))
{
scaledResult =
planeOffsetFromWellPathCenter + (resultValuesForInterpolatedPoints[i] - minClampedResult) * plotRangeToResultRangeFactor;
}
(*vertices)[i] = cvf::Vec3f(interpolatedWellPathPoints[i] + scaledResult * interpolatedCurveNormals[i]);
}
std::vector<std::pair<size_t, size_t>> valuesIntervals =
RigCurveDataTools::calculateIntervalsOfValidValues(resultValuesForInterpolatedPoints, 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));
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RigWellPath* Riv3dWellLogCurveGeometryGenerator::wellPathGeometry() const
{
return m_wellPath->wellPathGeometry();
}