2018-03-22 08:35:54 -05: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 "Riv3dWellLogGridGeomertyGenerator.h"
|
|
|
|
|
|
|
|
#include "RimWellPath.h"
|
|
|
|
#include "RimWellPathCollection.h"
|
|
|
|
|
|
|
|
#include "RigWellPath.h"
|
|
|
|
#include "RigWellPathGeometryTools.h"
|
|
|
|
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
2018-04-12 10:44:50 -05:00
|
|
|
#include "cvfObject.h"
|
|
|
|
#include "cvfDrawableGeo.h"
|
2018-03-22 08:35:54 -05:00
|
|
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
|
|
|
|
|
|
|
#include "cvfBoundingBox.h"
|
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
#include <map>
|
|
|
|
|
2018-03-22 08:35:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
Riv3dWellLogGridGeometryGenerator::Riv3dWellLogGridGeometryGenerator(RimWellPath* wellPath)
|
|
|
|
: m_wellPath(wellPath)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-16 03:35:56 -05:00
|
|
|
bool
|
2018-04-12 10:44:50 -05:00
|
|
|
Riv3dWellLogGridGeometryGenerator::createGrid(const caf::DisplayCoordTransform* displayCoordTransform,
|
|
|
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
2018-04-13 08:29:13 -05:00
|
|
|
double planeAngle,
|
2018-04-12 10:44:50 -05:00
|
|
|
double planeOffsetFromWellPathCenter,
|
|
|
|
double planeWidth,
|
2018-04-16 03:35:56 -05:00
|
|
|
double gridIntervalSize)
|
2018-03-22 08:35:54 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(gridIntervalSize > 0);
|
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
if (!wellPathGeometry() || wellPathGeometry()->m_measuredDepths.empty())
|
|
|
|
{
|
2018-04-16 03:35:56 -05:00
|
|
|
return false;
|
2018-04-12 10:44:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!wellPathClipBoundingBox.isValid())
|
|
|
|
{
|
2018-04-16 03:35:56 -05:00
|
|
|
return false;
|
2018-04-12 10:44:50 -05:00
|
|
|
}
|
|
|
|
|
2018-03-22 08:35:54 -05:00
|
|
|
|
|
|
|
RimWellPathCollection* wellPathCollection = nullptr;
|
|
|
|
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
|
|
|
|
|
|
|
|
std::vector<cvf::Vec3d> wellPathPoints = wellPathGeometry()->m_wellPathPoints;
|
2018-04-12 10:44:50 -05:00
|
|
|
if (wellPathPoints.empty())
|
|
|
|
{
|
2018-04-16 03:35:56 -05:00
|
|
|
return false;
|
2018-04-12 10:44:50 -05:00
|
|
|
}
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-18 04:09:50 -05:00
|
|
|
for (cvf::Vec3d& wellPathPoint : wellPathPoints)
|
|
|
|
{
|
|
|
|
wellPathPoint = displayCoordTransform->transformToDisplayCoord(wellPathPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<cvf::Vec3d> wellPathSegmentNormals =
|
|
|
|
RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathPoints, planeAngle);
|
|
|
|
|
|
|
|
|
2018-03-22 08:35:54 -05:00
|
|
|
size_t originalWellPathSize = wellPathPoints.size();
|
|
|
|
|
|
|
|
if (wellPathCollection->wellPathClip)
|
|
|
|
{
|
2018-04-18 04:09:50 -05:00
|
|
|
double clipZDistance = wellPathCollection->wellPathClipZDistance;
|
2018-03-22 08:35:54 -05:00
|
|
|
double horizontalLengthAlongWellToClipPoint;
|
2018-04-18 04:09:50 -05:00
|
|
|
cvf::Vec3d clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
|
|
|
|
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
|
2018-03-22 08:35:54 -05:00
|
|
|
size_t indexToFirstVisibleSegment;
|
|
|
|
wellPathPoints = RigWellPath::clipPolylineStartAboveZ(
|
2018-04-18 04:09:50 -05:00
|
|
|
wellPathPoints, clipLocation.z(), &horizontalLengthAlongWellToClipPoint, &indexToFirstVisibleSegment);
|
2018-03-22 08:35:54 -05:00
|
|
|
}
|
|
|
|
|
2018-04-16 03:35:56 -05:00
|
|
|
if (wellPathPoints.size() < (size_t) 2)
|
2018-04-12 10:44:50 -05:00
|
|
|
{
|
2018-04-16 03:35:56 -05:00
|
|
|
// Need at least two well path points to create a valid path.
|
|
|
|
return false;
|
2018-04-12 10:44:50 -05:00
|
|
|
}
|
|
|
|
|
2018-04-18 04:09:50 -05:00
|
|
|
// Note that normals are calculated on the full non-clipped well path to increase the likelihood of creating good normals
|
|
|
|
// for the end points of the curve. So we need to clip the remainder here.
|
2018-03-22 08:35:54 -05:00
|
|
|
wellPathSegmentNormals.erase(wellPathSegmentNormals.begin(), wellPathSegmentNormals.end() - wellPathPoints.size());
|
|
|
|
|
|
|
|
{
|
2018-04-12 10:44:50 -05:00
|
|
|
std::vector<cvf::Vec3f> vertices;
|
2018-04-16 03:35:56 -05:00
|
|
|
vertices.reserve(wellPathPoints.size() * 2);
|
2018-04-12 10:44:50 -05:00
|
|
|
|
2018-04-16 03:35:56 -05:00
|
|
|
std::vector<cvf::uint> backgroundIndices;
|
|
|
|
backgroundIndices.reserve(wellPathPoints.size() * 2);
|
|
|
|
|
|
|
|
// Vertices are used for both surface and border
|
2018-04-12 10:44:50 -05:00
|
|
|
for (size_t i = 0; i < wellPathPoints.size(); i++)
|
|
|
|
{
|
2018-04-18 04:09:50 -05:00
|
|
|
vertices.push_back(cvf::Vec3f(
|
|
|
|
wellPathPoints[i] + wellPathSegmentNormals[i] * planeOffsetFromWellPathCenter));
|
|
|
|
vertices.push_back(cvf::Vec3f(
|
|
|
|
wellPathPoints[i] + wellPathSegmentNormals[i] * (planeOffsetFromWellPathCenter + planeWidth)));
|
2018-04-16 03:35:56 -05:00
|
|
|
backgroundIndices.push_back((cvf::uint) (2 * i));
|
|
|
|
backgroundIndices.push_back((cvf::uint) (2 * i + 1));
|
2018-04-12 10:44:50 -05:00
|
|
|
}
|
2018-04-16 03:35:56 -05:00
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices);
|
2018-04-16 03:35:56 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
// Background specific
|
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_TRIANGLE_STRIP);
|
|
|
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(backgroundIndices);
|
|
|
|
indexedUInt->setIndices(indexArray.p());
|
|
|
|
|
|
|
|
m_background = new cvf::DrawableGeo();
|
|
|
|
m_background->addPrimitiveSet(indexedUInt.p());
|
|
|
|
m_background->setVertexArray(vertexArray.p());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<cvf::uint> borderIndices;
|
|
|
|
borderIndices.reserve(vertices.size());
|
|
|
|
|
|
|
|
int secondLastEvenVertex = (int) vertices.size() - 4;
|
|
|
|
|
|
|
|
// Border close to the well. All even indices.
|
|
|
|
for (size_t i = 0; i <= secondLastEvenVertex; i += 2)
|
|
|
|
{
|
|
|
|
borderIndices.push_back((cvf::uint) i);
|
|
|
|
borderIndices.push_back((cvf::uint) i+2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect to border away from well
|
|
|
|
borderIndices.push_back((cvf::uint) (vertices.size() - 2));
|
|
|
|
borderIndices.push_back((cvf::uint) (vertices.size() - 1));
|
|
|
|
|
|
|
|
int secondOddVertex = 3;
|
|
|
|
int lastOddVertex = (int) vertices.size() - 1;
|
|
|
|
|
|
|
|
// Border away from from well are odd indices in reverse order to create a closed surface.
|
|
|
|
for (int i = lastOddVertex; i >= secondOddVertex; i -= 2)
|
|
|
|
{
|
|
|
|
borderIndices.push_back((cvf::uint) i);
|
|
|
|
borderIndices.push_back((cvf::uint) i - 2);
|
|
|
|
}
|
|
|
|
// Close border
|
|
|
|
borderIndices.push_back(1u);
|
|
|
|
borderIndices.push_back(0u);
|
|
|
|
|
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
|
|
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(borderIndices);
|
|
|
|
indexedUInt->setIndices(indexArray.p());
|
|
|
|
|
|
|
|
m_border = new cvf::DrawableGeo();
|
|
|
|
m_border->addPrimitiveSet(indexedUInt.p());
|
|
|
|
m_border->setVertexArray(vertexArray.p());
|
|
|
|
}
|
2018-03-22 08:35:54 -05:00
|
|
|
}
|
|
|
|
{
|
2018-04-13 07:36:37 -05:00
|
|
|
std::vector<cvf::Vec3d> interpolatedGridPoints;
|
2018-04-16 03:42:01 -05:00
|
|
|
std::vector<cvf::Vec3d> interpolatedGridCurveNormals;
|
2018-04-13 07:36:37 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-04-18 04:09:50 -05:00
|
|
|
cvf::Vec3d point = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathPoints, md);
|
2018-04-16 03:42:01 -05:00
|
|
|
cvf::Vec3d curveNormal = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathSegmentNormals, md);
|
2018-04-13 07:36:37 -05:00
|
|
|
interpolatedGridPoints.push_back(point);
|
2018-04-16 03:42:01 -05:00
|
|
|
interpolatedGridCurveNormals.push_back(curveNormal.getNormalized());
|
2018-04-13 07:36:37 -05:00
|
|
|
md -= gridIntervalSize;
|
|
|
|
}
|
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
std::vector<cvf::Vec3f> vertices;
|
2018-04-13 07:36:37 -05:00
|
|
|
vertices.reserve(interpolatedGridPoints.size());
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
std::vector<cvf::uint> indices;
|
2018-04-13 07:36:37 -05:00
|
|
|
indices.reserve(interpolatedGridPoints.size());
|
2018-04-12 10:44:50 -05:00
|
|
|
cvf::uint indexCounter = 0;
|
|
|
|
// Normal lines. Start from one to avoid drawing at surface edge.
|
2018-04-16 03:42:01 -05:00
|
|
|
for (size_t i = 1; i < interpolatedGridCurveNormals.size(); i++)
|
2018-04-12 10:44:50 -05:00
|
|
|
{
|
2018-04-18 04:09:50 -05:00
|
|
|
vertices.push_back(cvf::Vec3f(interpolatedGridPoints[i] + interpolatedGridCurveNormals[i] * planeOffsetFromWellPathCenter));
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-18 04:09:50 -05:00
|
|
|
vertices.push_back(cvf::Vec3f(interpolatedGridPoints[i] + interpolatedGridCurveNormals[i] * (planeOffsetFromWellPathCenter + planeWidth)));
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
indices.push_back(indexCounter++);
|
|
|
|
indices.push_back(indexCounter++);
|
|
|
|
}
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
|
|
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
cvf::ref<cvf::DrawableGeo> normalLinesDrawable = new cvf::DrawableGeo();
|
2018-03-22 08:35:54 -05:00
|
|
|
|
2018-04-12 10:44:50 -05:00
|
|
|
indexedUInt->setIndices(indexArray.p());
|
|
|
|
normalLinesDrawable->addPrimitiveSet(indexedUInt.p());
|
|
|
|
|
|
|
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices);
|
|
|
|
normalLinesDrawable->setVertexArray(vertexArray.p());
|
|
|
|
|
2018-04-16 03:42:01 -05:00
|
|
|
m_curveNormalLines = normalLinesDrawable;
|
2018-04-12 10:44:50 -05:00
|
|
|
}
|
2018-04-16 03:35:56 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::DrawableGeo> Riv3dWellLogGridGeometryGenerator::background()
|
|
|
|
{
|
|
|
|
return m_background;
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::DrawableGeo> Riv3dWellLogGridGeometryGenerator::border()
|
|
|
|
{
|
|
|
|
return m_border;
|
|
|
|
}
|
|
|
|
|
2018-04-16 03:42:01 -05:00
|
|
|
cvf::ref<cvf::DrawableGeo> Riv3dWellLogGridGeometryGenerator::curveNormalLines()
|
2018-04-16 03:35:56 -05:00
|
|
|
{
|
2018-04-16 03:42:01 -05:00
|
|
|
return m_curveNormalLines;
|
2018-03-22 08:35:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const RigWellPath* Riv3dWellLogGridGeometryGenerator::wellPathGeometry() const
|
|
|
|
{
|
|
|
|
return m_wellPath->wellPathGeometry();
|
|
|
|
}
|