mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2825 Fix curve stitching issues against 3dwell log curve background.
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "RigWellPath.h"
|
#include "RigWellPath.h"
|
||||||
#include "RigWellPathGeometryTools.h"
|
#include "RigWellPathGeometryTools.h"
|
||||||
|
|
||||||
|
#include "cafLine.h"
|
||||||
#include "cafDisplayCoordTransform.h"
|
#include "cafDisplayCoordTransform.h"
|
||||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||||
|
|
||||||
@@ -49,18 +50,19 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::Display
|
|||||||
const cvf::BoundingBox& wellPathClipBoundingBox,
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
||||||
const Rim3dWellLogCurve* rim3dWellLogCurve,
|
const Rim3dWellLogCurve* rim3dWellLogCurve,
|
||||||
double planeOffsetFromWellPathCenter,
|
double planeOffsetFromWellPathCenter,
|
||||||
double planeWidth)
|
double planeWidth,
|
||||||
|
const std::vector<cvf::Vec3f>& gridVertices)
|
||||||
{
|
{
|
||||||
|
// Make sure all drawables are cleared in case we return early to avoid a
|
||||||
|
// previous drawable being "stuck" when changing result type.
|
||||||
|
clearCurvePointsAndGeometry();
|
||||||
|
|
||||||
std::vector<double> resultValues;
|
std::vector<double> resultValues;
|
||||||
std::vector<double> resultMds;
|
std::vector<double> resultMds;
|
||||||
rim3dWellLogCurve->curveValuesAndMds(&resultValues, &resultMds);
|
rim3dWellLogCurve->curveValuesAndMds(&resultValues, &resultMds);
|
||||||
|
|
||||||
m_planeWidth = planeWidth;
|
m_planeWidth = planeWidth;
|
||||||
|
|
||||||
// Make sure all drawables are cleared in case we return early to avoid a
|
|
||||||
// previous drawable being "stuck" when changing result type.
|
|
||||||
clearCurvePointsAndGeometry();
|
|
||||||
|
|
||||||
if (!wellPathGeometry()) return;
|
if (!wellPathGeometry()) return;
|
||||||
if (wellPathGeometry()->m_wellPathPoints.empty()) return;
|
if (wellPathGeometry()->m_wellPathPoints.empty()) return;
|
||||||
if (!wellPathClipBoundingBox.isValid()) return;
|
if (!wellPathClipBoundingBox.isValid()) return;
|
||||||
@@ -80,7 +82,7 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::Display
|
|||||||
if (wellPathCollection->wellPathClip)
|
if (wellPathCollection->wellPathClip)
|
||||||
{
|
{
|
||||||
double clipZDistance = wellPathCollection->wellPathClipZDistance;
|
double clipZDistance = wellPathCollection->wellPathClipZDistance;
|
||||||
clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
|
clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
|
||||||
}
|
}
|
||||||
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
|
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
|
||||||
|
|
||||||
@@ -90,14 +92,15 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::Display
|
|||||||
wellPathPoint = displayCoordTransform->transformToDisplayCoord(wellPathPoint);
|
wellPathPoint = displayCoordTransform->transformToDisplayCoord(wellPathPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<cvf::Vec3d> wellPathCurveNormals = RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathPoints, rim3dWellLogCurve->drawPlaneAngle());
|
std::vector<cvf::Vec3d> wellPathCurveNormals =
|
||||||
|
RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathPoints, rim3dWellLogCurve->drawPlaneAngle());
|
||||||
|
|
||||||
std::vector<cvf::Vec3d> interpolatedWellPathPoints;
|
std::vector<cvf::Vec3d> interpolatedWellPathPoints;
|
||||||
std::vector<cvf::Vec3d> interpolatedCurveNormals;
|
std::vector<cvf::Vec3d> interpolatedCurveNormals;
|
||||||
// Iterate from bottom of well path and up to be able to stop at given Z max clipping height
|
// 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++)
|
for (auto md = resultMds.rbegin(); md != resultMds.rend(); md++)
|
||||||
{
|
{
|
||||||
cvf::Vec3d point = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathPoints, *md);
|
cvf::Vec3d point = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathPoints, *md);
|
||||||
cvf::Vec3d normal = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathCurveNormals, *md);
|
cvf::Vec3d normal = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathCurveNormals, *md);
|
||||||
if (point.z() > clipLocation.z()) break;
|
if (point.z() > clipLocation.z()) break;
|
||||||
|
|
||||||
@@ -111,10 +114,8 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::Display
|
|||||||
std::reverse(interpolatedCurveNormals.begin(), interpolatedCurveNormals.end());
|
std::reverse(interpolatedCurveNormals.begin(), interpolatedCurveNormals.end());
|
||||||
|
|
||||||
// The result values for the part of the well which is not clipped off, matching interpolatedWellPathPoints size
|
// The result values for the part of the well which is not clipped off, matching interpolatedWellPathPoints size
|
||||||
m_curveValues = std::vector<double>(resultValues.end() - interpolatedWellPathPoints.size(),
|
m_curveValues = std::vector<double>(resultValues.end() - interpolatedWellPathPoints.size(), resultValues.end());
|
||||||
resultValues.end());
|
m_curveMeasuredDepths = std::vector<double>(resultMds.end() - interpolatedWellPathPoints.size(), resultMds.end());
|
||||||
m_curveMeasuredDepths = std::vector<double>(resultMds.end() - interpolatedWellPathPoints.size(),
|
|
||||||
resultMds.end());
|
|
||||||
|
|
||||||
double maxClampedResult = -HUGE_VAL;
|
double maxClampedResult = -HUGE_VAL;
|
||||||
double minClampedResult = HUGE_VAL;
|
double minClampedResult = HUGE_VAL;
|
||||||
@@ -145,27 +146,26 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::Display
|
|||||||
|
|
||||||
if (RigCurveDataTools::isValidValue(m_curveValues[i], false))
|
if (RigCurveDataTools::isValidValue(m_curveValues[i], false))
|
||||||
{
|
{
|
||||||
scaledResult =
|
scaledResult = planeOffsetFromWellPathCenter + (m_curveValues[i] - minClampedResult) * plotRangeToResultRangeFactor;
|
||||||
planeOffsetFromWellPathCenter + (m_curveValues[i] - minClampedResult) * plotRangeToResultRangeFactor;
|
|
||||||
}
|
}
|
||||||
cvf::Vec3d curvePoint(interpolatedWellPathPoints[i] + scaledResult * interpolatedCurveNormals[i]);
|
cvf::Vec3d curvePoint(interpolatedWellPathPoints[i] + scaledResult * interpolatedCurveNormals[i]);
|
||||||
m_curveVertices.push_back(cvf::Vec3f(curvePoint));
|
m_curveVertices.push_back(cvf::Vec3f(curvePoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createNewVerticesAlongTriangleEdges(gridVertices);
|
||||||
|
projectVerticesOntoTriangles(gridVertices);
|
||||||
|
|
||||||
|
|
||||||
std::vector<cvf::uint> indices;
|
std::vector<cvf::uint> indices;
|
||||||
indices.reserve(interpolatedWellPathPoints.size());
|
indices.reserve(m_curveVertices.size() * 2);
|
||||||
for (size_t i = 0; i < m_curveValues.size() - 1; ++i)
|
for (size_t i = 0; i < m_curveVertices.size() - 1; ++i)
|
||||||
{
|
{
|
||||||
if (RigCurveDataTools::isValidValue(m_curveValues[i], false) &&
|
indices.push_back(cvf::uint(i));
|
||||||
RigCurveDataTools::isValidValue(m_curveValues[i + 1], false))
|
indices.push_back(cvf::uint(i + 1));
|
||||||
{
|
|
||||||
indices.push_back(cvf::uint(i));
|
|
||||||
indices.push_back(cvf::uint(i + 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
||||||
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
||||||
|
|
||||||
m_curveDrawable = new cvf::DrawableGeo();
|
m_curveDrawable = new cvf::DrawableGeo();
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ void Riv3dWellLogCurveGeometryGenerator::createCurveDrawables(const caf::Display
|
|||||||
m_curveDrawable->addPrimitiveSet(indexedUInt.p());
|
m_curveDrawable->addPrimitiveSet(indexedUInt.p());
|
||||||
|
|
||||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(m_curveVertices);
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(m_curveVertices);
|
||||||
m_curveDrawable->setVertexArray(vertexArray.p());
|
m_curveDrawable->setVertexArray(vertexArray.p());
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -212,10 +212,10 @@ bool Riv3dWellLogCurveGeometryGenerator::findClosestPointOnCurve(const cvf::Vec3
|
|||||||
double* valueAtClosestPoint) const
|
double* valueAtClosestPoint) const
|
||||||
{
|
{
|
||||||
cvf::Vec3f globalIntersectionFloat(globalIntersection);
|
cvf::Vec3f globalIntersectionFloat(globalIntersection);
|
||||||
float closestDistance = m_planeWidth * 0.1;
|
float closestDistance = m_planeWidth * 0.1;
|
||||||
*closestPoint = cvf::Vec3d::UNDEFINED;
|
*closestPoint = cvf::Vec3d::UNDEFINED;
|
||||||
*measuredDepthAtPoint = cvf::UNDEFINED_DOUBLE;
|
*measuredDepthAtPoint = cvf::UNDEFINED_DOUBLE;
|
||||||
*valueAtClosestPoint = cvf::UNDEFINED_DOUBLE;
|
*valueAtClosestPoint = cvf::UNDEFINED_DOUBLE;
|
||||||
if (m_curveVertices.size() < 2u) false;
|
if (m_curveVertices.size() < 2u) false;
|
||||||
CVF_ASSERT(m_curveVertices.size() == m_curveValues.size());
|
CVF_ASSERT(m_curveVertices.size() == m_curveValues.size());
|
||||||
for (size_t i = 1; i < m_curveVertices.size(); ++i)
|
for (size_t i = 1; i < m_curveVertices.size(); ++i)
|
||||||
@@ -224,27 +224,154 @@ bool Riv3dWellLogCurveGeometryGenerator::findClosestPointOnCurve(const cvf::Vec3
|
|||||||
RigCurveDataTools::isValidValue(m_curveValues[i - 1], false);
|
RigCurveDataTools::isValidValue(m_curveValues[i - 1], false);
|
||||||
if (validCurveSegment)
|
if (validCurveSegment)
|
||||||
{
|
{
|
||||||
cvf::Vec3f a = m_curveVertices[i - 1];
|
cvf::Vec3f a = m_curveVertices[i - 1];
|
||||||
cvf::Vec3f b = m_curveVertices[i];
|
cvf::Vec3f b = m_curveVertices[i];
|
||||||
cvf::Vec3f ap = globalIntersectionFloat - a;
|
cvf::Vec3f ap = globalIntersectionFloat - a;
|
||||||
cvf::Vec3f ab = b - a;
|
cvf::Vec3f ab = b - a;
|
||||||
// Projected point is clamped to one of the end points of the segment.
|
// Projected point is clamped to one of the end points of the segment.
|
||||||
float distanceToProjectedPointAlongAB = ap * ab / (ab * ab);
|
float distanceToProjectedPointAlongAB = ap * ab / (ab * ab);
|
||||||
float clampedDistance = cvf::Math::clamp(distanceToProjectedPointAlongAB, 0.0f, 1.0f);
|
float clampedDistance = cvf::Math::clamp(distanceToProjectedPointAlongAB, 0.0f, 1.0f);
|
||||||
cvf::Vec3f projectionOfGlobalIntersection = a + clampedDistance * ab;
|
cvf::Vec3f projectionOfGlobalIntersection = a + clampedDistance * ab;
|
||||||
float distance = (projectionOfGlobalIntersection - globalIntersectionFloat).length();
|
float distance = (projectionOfGlobalIntersection - globalIntersectionFloat).length();
|
||||||
if (distance < closestDistance)
|
if (distance < closestDistance)
|
||||||
{
|
{
|
||||||
*closestPoint = cvf::Vec3d(projectionOfGlobalIntersection);
|
*closestPoint = cvf::Vec3d(projectionOfGlobalIntersection);
|
||||||
closestDistance = distance;
|
closestDistance = distance;
|
||||||
*measuredDepthAtPoint = m_curveMeasuredDepths[i - 1] * (1.0f - clampedDistance) + m_curveMeasuredDepths[i] * clampedDistance;
|
*measuredDepthAtPoint =
|
||||||
|
m_curveMeasuredDepths[i - 1] * (1.0f - clampedDistance) + m_curveMeasuredDepths[i] * clampedDistance;
|
||||||
*valueAtClosestPoint = m_curveValues[i - 1] * (1.0f - clampedDistance) + m_curveValues[i] * clampedDistance;
|
*valueAtClosestPoint = m_curveValues[i - 1] * (1.0f - clampedDistance) + m_curveValues[i] * clampedDistance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closestPoint->isUndefined())
|
if (closestPoint->isUndefined()) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void Riv3dWellLogCurveGeometryGenerator::createNewVerticesAlongTriangleEdges(const std::vector<cvf::Vec3f>& gridVertices)
|
||||||
|
{
|
||||||
|
std::vector<cvf::Vec3f> expandedCurveVertices;
|
||||||
|
std::vector<double> expandedMeasuredDepths;
|
||||||
|
std::vector<double> expandedValues;
|
||||||
|
size_t estimatedNumberOfPoints = m_curveVertices.size() + gridVertices.size();
|
||||||
|
expandedCurveVertices.reserve(estimatedNumberOfPoints);
|
||||||
|
expandedMeasuredDepths.reserve(estimatedNumberOfPoints);
|
||||||
|
expandedValues.reserve(estimatedNumberOfPoints);
|
||||||
|
for (size_t i = 0; i < m_curveVertices.size() - 1; i += 2)
|
||||||
|
{
|
||||||
|
if (RigCurveDataTools::isValidValue(m_curveValues[i], false) &&
|
||||||
|
RigCurveDataTools::isValidValue(m_curveValues[i + 1], false))
|
||||||
|
{
|
||||||
|
expandedCurveVertices.push_back(m_curveVertices[i]);
|
||||||
|
expandedMeasuredDepths.push_back(m_curveMeasuredDepths[i]);
|
||||||
|
expandedValues.push_back(m_curveValues[i]);
|
||||||
|
// Find segments that intersects the triangle edge
|
||||||
|
caf::Line<float> curveLine(m_curveVertices[i], m_curveVertices[i + 1]);
|
||||||
|
|
||||||
|
for (size_t j = 0; j < gridVertices.size() - 1; ++j)
|
||||||
|
{
|
||||||
|
caf::Line<float> gridLine(gridVertices[j], gridVertices[j + 1]);
|
||||||
|
bool withinSegments = false;
|
||||||
|
caf::Line<float> connectingLine = curveLine.findLineBetweenNearestPoints(gridLine, &withinSegments);
|
||||||
|
|
||||||
|
if (withinSegments)
|
||||||
|
{
|
||||||
|
cvf::Vec3f closestGridPoint = connectingLine.end();
|
||||||
|
double measuredDepth;
|
||||||
|
double valueAtPoint;
|
||||||
|
cvf::Vec3d closestPoint(closestGridPoint);
|
||||||
|
cvf::Vec3d dummyArgument;
|
||||||
|
// Interpolate measured depth and value
|
||||||
|
bool worked = findClosestPointOnCurve(closestPoint, &dummyArgument, &measuredDepth, &valueAtPoint);
|
||||||
|
if (worked)
|
||||||
|
{
|
||||||
|
expandedCurveVertices.push_back(closestGridPoint);
|
||||||
|
expandedMeasuredDepths.push_back(measuredDepth);
|
||||||
|
expandedValues.push_back(valueAtPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next original segment point
|
||||||
|
expandedCurveVertices.push_back(m_curveVertices[i + 1]);
|
||||||
|
expandedMeasuredDepths.push_back(m_curveMeasuredDepths[i + 1]);
|
||||||
|
expandedValues.push_back(m_curveValues[i + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_curveVertices.swap(expandedCurveVertices);
|
||||||
|
m_curveMeasuredDepths.swap(expandedMeasuredDepths);
|
||||||
|
m_curveValues.swap(expandedValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void Riv3dWellLogCurveGeometryGenerator::projectVerticesOntoTriangles(const std::vector<cvf::Vec3f>& gridVertices)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_curveVertices.size(); ++i)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < gridVertices.size() - 2; j += 1)
|
||||||
|
{
|
||||||
|
cvf::Vec3f triangleVertex1, triangleVertex2, triangleVertex3;
|
||||||
|
if (j % 2 == 0)
|
||||||
|
{
|
||||||
|
triangleVertex1 = gridVertices[j];
|
||||||
|
triangleVertex2 = gridVertices[j + 1];
|
||||||
|
triangleVertex3 = gridVertices[j + 2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
triangleVertex1 = gridVertices[j];
|
||||||
|
triangleVertex2 = gridVertices[j + 2];
|
||||||
|
triangleVertex3 = gridVertices[j + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wasInsideTriangle = false;
|
||||||
|
cvf::Vec3f projectedPoint = projectPointOntoTriangle(
|
||||||
|
m_curveVertices[i], triangleVertex1, triangleVertex2, triangleVertex3, &wasInsideTriangle);
|
||||||
|
if (wasInsideTriangle)
|
||||||
|
{
|
||||||
|
m_curveVertices[i] = projectedPoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Vec3f Riv3dWellLogCurveGeometryGenerator::projectPointOntoTriangle(const cvf::Vec3f& point,
|
||||||
|
const cvf::Vec3f& triangleVertex1,
|
||||||
|
const cvf::Vec3f& triangleVertex2,
|
||||||
|
const cvf::Vec3f& triangleVertex3,
|
||||||
|
bool* wasInsideTriangle)
|
||||||
|
{
|
||||||
|
*wasInsideTriangle = false;
|
||||||
|
cvf::Vec3f e1 = triangleVertex2 - triangleVertex1;
|
||||||
|
cvf::Vec3f e2 = triangleVertex3 - triangleVertex1;
|
||||||
|
cvf::Vec3f n = (e1.getNormalized() ^ e2.getNormalized()).getNormalized();
|
||||||
|
|
||||||
|
// Project vertex onto triangle plane
|
||||||
|
cvf::Vec3f av = point - triangleVertex1;
|
||||||
|
cvf::Vec3f projectedPoint = point - (av * n) * n;
|
||||||
|
|
||||||
|
// Calculate barycentric coordinates
|
||||||
|
float areaABC = n * (e1 ^ e2);
|
||||||
|
float areaPBC = n * ((triangleVertex2 - projectedPoint) ^ (triangleVertex3 - projectedPoint));
|
||||||
|
float areaPCA = n * ((triangleVertex3 - projectedPoint) ^ (triangleVertex1 - projectedPoint));
|
||||||
|
float u = areaPBC / areaABC;
|
||||||
|
float v = areaPCA / areaABC;
|
||||||
|
float w = 1.0 - u - v;
|
||||||
|
|
||||||
|
if (u >= 0.0 && v >= 0.0 && w >= 0.0)
|
||||||
|
{
|
||||||
|
*wasInsideTriangle = true;
|
||||||
|
}
|
||||||
|
return projectedPoint;
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ public:
|
|||||||
const cvf::BoundingBox& wellPathClipBoundingBox,
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
||||||
const Rim3dWellLogCurve* rim3dWellLogCurve,
|
const Rim3dWellLogCurve* rim3dWellLogCurve,
|
||||||
double planeOffsetFromWellPathCenter,
|
double planeOffsetFromWellPathCenter,
|
||||||
double planeWidth);
|
double planeWidth,
|
||||||
|
const std::vector<cvf::Vec3f>& gridVertices);
|
||||||
|
|
||||||
void clearCurvePointsAndGeometry();
|
void clearCurvePointsAndGeometry();
|
||||||
|
|
||||||
const RigWellPath* wellPathGeometry() const;
|
const RigWellPath* wellPathGeometry() const;
|
||||||
@@ -65,6 +66,13 @@ public:
|
|||||||
double* valueAtClosestPoint) const;
|
double* valueAtClosestPoint) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createNewVerticesAlongTriangleEdges(const std::vector<cvf::Vec3f>& gridVertices);
|
||||||
|
void projectVerticesOntoTriangles(const std::vector<cvf::Vec3f>& gridVertices);
|
||||||
|
static cvf::Vec3f projectPointOntoTriangle(const cvf::Vec3f& point,
|
||||||
|
const cvf::Vec3f& triangleVertex1,
|
||||||
|
const cvf::Vec3f& triangleVertex2,
|
||||||
|
const cvf::Vec3f& triangleVertex3,
|
||||||
|
bool* wasInsideTriangle);
|
||||||
caf::PdmPointer<RimWellPath> m_wellPath;
|
caf::PdmPointer<RimWellPath> m_wellPath;
|
||||||
double m_planeWidth;
|
double m_planeWidth;
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,15 @@ void Riv3dWellLogPlanePartMgr::appendPlaneToModel(cvf::ModelBasicList*
|
|||||||
|
|
||||||
for (Rim3dWellLogCurve* rim3dWellLogCurve : m_wellPath->rim3dWellLogCurveCollection()->vectorOf3dWellLogCurves())
|
for (Rim3dWellLogCurve* rim3dWellLogCurve : m_wellPath->rim3dWellLogCurveCollection()->vectorOf3dWellLogCurves())
|
||||||
{
|
{
|
||||||
appendGridToModel(model, displayCoordTransform, wellPathClipBoundingBox, rim3dWellLogCurve, planeWidth());
|
if (rim3dWellLogCurve->isShowingCurve())
|
||||||
append3dWellLogCurveToModel(model, displayCoordTransform, wellPathClipBoundingBox, rim3dWellLogCurve);
|
{
|
||||||
|
appendGridToModel(model, displayCoordTransform, wellPathClipBoundingBox, rim3dWellLogCurve, planeWidth());
|
||||||
|
append3dWellLogCurveToModel(model,
|
||||||
|
displayCoordTransform,
|
||||||
|
wellPathClipBoundingBox,
|
||||||
|
rim3dWellLogCurve,
|
||||||
|
m_3dWellLogGridGeometryGenerator->vertices());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,10 +90,10 @@ void Riv3dWellLogPlanePartMgr::appendPlaneToModel(cvf::ModelBasicList*
|
|||||||
void Riv3dWellLogPlanePartMgr::append3dWellLogCurveToModel(cvf::ModelBasicList* model,
|
void Riv3dWellLogPlanePartMgr::append3dWellLogCurveToModel(cvf::ModelBasicList* model,
|
||||||
const caf::DisplayCoordTransform* displayCoordTransform,
|
const caf::DisplayCoordTransform* displayCoordTransform,
|
||||||
const cvf::BoundingBox& wellPathClipBoundingBox,
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
||||||
Rim3dWellLogCurve* rim3dWellLogCurve)
|
Rim3dWellLogCurve* rim3dWellLogCurve,
|
||||||
|
const std::vector<cvf::Vec3f>& gridVertices)
|
||||||
{
|
{
|
||||||
CVF_ASSERT(rim3dWellLogCurve);
|
CVF_ASSERT(rim3dWellLogCurve);
|
||||||
if (!rim3dWellLogCurve->isShowingCurve()) return;
|
|
||||||
|
|
||||||
cvf::ref<Riv3dWellLogCurveGeometryGenerator> generator = rim3dWellLogCurve->geometryGenerator();
|
cvf::ref<Riv3dWellLogCurveGeometryGenerator> generator = rim3dWellLogCurve->geometryGenerator();
|
||||||
if (generator.isNull())
|
if (generator.isNull())
|
||||||
@@ -99,7 +106,8 @@ void Riv3dWellLogPlanePartMgr::append3dWellLogCurveToModel(cvf::ModelBasicList*
|
|||||||
wellPathClipBoundingBox,
|
wellPathClipBoundingBox,
|
||||||
rim3dWellLogCurve,
|
rim3dWellLogCurve,
|
||||||
wellPathCenterToPlotStartOffset(rim3dWellLogCurve),
|
wellPathCenterToPlotStartOffset(rim3dWellLogCurve),
|
||||||
planeWidth());
|
planeWidth(),
|
||||||
|
gridVertices);
|
||||||
|
|
||||||
cvf::ref<cvf::DrawableGeo> curveDrawable = generator->curveDrawable();
|
cvf::ref<cvf::DrawableGeo> curveDrawable = generator->curveDrawable();
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ private:
|
|||||||
void append3dWellLogCurveToModel(cvf::ModelBasicList* model,
|
void append3dWellLogCurveToModel(cvf::ModelBasicList* model,
|
||||||
const caf::DisplayCoordTransform* displayCoordTransform,
|
const caf::DisplayCoordTransform* displayCoordTransform,
|
||||||
const cvf::BoundingBox& wellPathClipBoundingBox,
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
||||||
Rim3dWellLogCurve* rim3dWellLogCurve);
|
Rim3dWellLogCurve* rim3dWellLogCurve,
|
||||||
|
const std::vector<cvf::Vec3f>& gridVertices);
|
||||||
|
|
||||||
void appendGridToModel(cvf::ModelBasicList* model,
|
void appendGridToModel(cvf::ModelBasicList* model,
|
||||||
const caf::DisplayCoordTransform* displayCoordTransform,
|
const caf::DisplayCoordTransform* displayCoordTransform,
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ add_library( ${PROJECT_NAME}
|
|||||||
cafFixedAtlasFont.cpp
|
cafFixedAtlasFont.cpp
|
||||||
cafTransparentWBRenderConfiguration.h
|
cafTransparentWBRenderConfiguration.h
|
||||||
cafTransparentWBRenderConfiguration.cpp
|
cafTransparentWBRenderConfiguration.cpp
|
||||||
|
cafLine.h
|
||||||
|
cafLine.inl
|
||||||
TranspWB_CombinationFrag.glsl
|
TranspWB_CombinationFrag.glsl
|
||||||
TranspWB_PartlyTranspPartsFrag.glsl
|
TranspWB_PartlyTranspPartsFrag.glsl
|
||||||
TranspWB_TransparentPartsFrag.glsl
|
TranspWB_TransparentPartsFrag.glsl
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "cafBoxManipulatorGeometryGenerator.h"
|
#include "cafBoxManipulatorGeometryGenerator.h"
|
||||||
#include "cafEffectGenerator.h"
|
#include "cafEffectGenerator.h"
|
||||||
|
#include "cafLine.h"
|
||||||
|
|
||||||
#include "cvfBoxGenerator.h"
|
#include "cvfBoxGenerator.h"
|
||||||
#include "cvfDrawableGeo.h"
|
#include "cvfDrawableGeo.h"
|
||||||
@@ -150,11 +151,12 @@ void BoxManipulatorPartManager::updateManipulatorFromRay(const cvf::Ray* ray)
|
|||||||
BoxFace face = m_handleIds[m_currentHandleIndex].first;
|
BoxFace face = m_handleIds[m_currentHandleIndex].first;
|
||||||
cvf::Vec3d faceDir = normalFromFace(face);
|
cvf::Vec3d faceDir = normalFromFace(face);
|
||||||
|
|
||||||
cvf::Vec3d closestPointOnMouseRay;
|
caf::Line<double> rayLine(ray->origin(), ray->origin() + ray->direction());
|
||||||
cvf::Vec3d closestPointOnHandleRay;
|
caf::Line<double> pickLine(m_initialPickPoint, m_initialPickPoint + faceDir);
|
||||||
BoxManipulatorPartManager::closestPointOfTwoLines(ray->origin(), ray->origin() + ray->direction(),
|
|
||||||
m_initialPickPoint, m_initialPickPoint + faceDir,
|
caf::Line<double> mouseHandleLine = rayLine.findLineBetweenNearestPoints(pickLine);
|
||||||
&closestPointOnMouseRay, &closestPointOnHandleRay);
|
cvf::Vec3d closestPointOnMouseRay = mouseHandleLine.start();
|
||||||
|
cvf::Vec3d closestPointOnHandleRay = mouseHandleLine.end();
|
||||||
|
|
||||||
cvf::Vec3d newOrigin = m_origin;
|
cvf::Vec3d newOrigin = m_origin;
|
||||||
cvf::Vec3d newSize = m_size;
|
cvf::Vec3d newSize = m_size;
|
||||||
@@ -402,72 +404,5 @@ void BoxManipulatorPartManager::createBoundingBoxPart()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
} // namespace caf
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
bool BoxManipulatorPartManager::closestPointOfTwoLines(const cvf::Vec3d& L1p1, const cvf::Vec3d& L1p2,
|
|
||||||
const cvf::Vec3d& L2p1, const cvf::Vec3d& L2p2,
|
|
||||||
cvf::Vec3d* closestPointOnL1, cvf::Vec3d* closestPointOnL2)
|
|
||||||
{
|
|
||||||
// qDebug() << p1 << " " << q1 << " " << p2 << " " << q2;
|
|
||||||
|
|
||||||
// Taken from Real-Time Collistion Detection, Christer Ericson, 2005, p146-147
|
|
||||||
|
|
||||||
// L1(s) = P1 + sd1
|
|
||||||
// L2(t) = P2 + td2
|
|
||||||
|
|
||||||
// d1 = Q1-P1
|
|
||||||
// d2 = Q2-P2
|
|
||||||
|
|
||||||
// r = P1-P2
|
|
||||||
|
|
||||||
// a = d1*d1
|
|
||||||
// b = d1*d2
|
|
||||||
// c = d1*r
|
|
||||||
// e = d2*d2;
|
|
||||||
// d = ae-b^2
|
|
||||||
// f = d2*r
|
|
||||||
|
|
||||||
// s = (bf-ce)/d
|
|
||||||
// t = (af-bc)/d
|
|
||||||
|
|
||||||
|
|
||||||
cvf::Vec3d d1 = L1p2 - L1p1;
|
|
||||||
cvf::Vec3d d2 = L2p2 - L2p1;
|
|
||||||
|
|
||||||
double a = d1.dot(d1);
|
|
||||||
double b = d1.dot(d2);
|
|
||||||
double e = d2.dot(d2);
|
|
||||||
|
|
||||||
double d = a*e - b*b;
|
|
||||||
|
|
||||||
if (d < std::numeric_limits<double>::epsilon())
|
|
||||||
{
|
|
||||||
// Parallel lines
|
|
||||||
if (closestPointOnL1) *closestPointOnL1 = L1p1;
|
|
||||||
if (closestPointOnL2) *closestPointOnL2 = L2p1;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cvf::Vec3d r = L1p1 - L2p1;
|
|
||||||
double c = d1.dot(r);
|
|
||||||
double f = d2.dot(r);
|
|
||||||
|
|
||||||
double s = (b*f - c*e) / d;
|
|
||||||
double t = (a*f - b*c) / d;
|
|
||||||
|
|
||||||
if (closestPointOnL1) *closestPointOnL1 = L1p1 + s*d1;
|
|
||||||
if (closestPointOnL2) *closestPointOnL2 = L2p1 + t*d2;
|
|
||||||
|
|
||||||
if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cvf
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ private:
|
|||||||
const cvf::Vec3f& v3,
|
const cvf::Vec3f& v3,
|
||||||
const cvf::Vec3f& v4,
|
const cvf::Vec3f& v4,
|
||||||
const cvf::Vec3f& v5);
|
const cvf::Vec3f& v5);
|
||||||
static bool closestPointOfTwoLines(const cvf::Vec3d& p1, const cvf::Vec3d& q1,
|
|
||||||
const cvf::Vec3d& p2, const cvf::Vec3d& q2,
|
|
||||||
cvf::Vec3d* closestPoint1, cvf::Vec3d* closestPoint2);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector< std::pair<BoxFace, HandleType> > m_handleIds; // These arrays have the same length
|
std::vector< std::pair<BoxFace, HandleType> > m_handleIds; // These arrays have the same length
|
||||||
|
|||||||
68
Fwk/AppFwk/cafVizExtensions/cafLine.h
Normal file
68
Fwk/AppFwk/cafVizExtensions/cafLine.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
//##################################################################################################
|
||||||
|
//
|
||||||
|
// Custom Visualization Core library
|
||||||
|
// Copyright (C) 2018- Ceetron Solutions AS
|
||||||
|
//
|
||||||
|
// This library may be used under the terms of either the GNU General Public License or
|
||||||
|
// the GNU Lesser General Public License as follows:
|
||||||
|
//
|
||||||
|
// GNU General Public License Usage
|
||||||
|
// This library 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.
|
||||||
|
//
|
||||||
|
// This library 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.
|
||||||
|
//
|
||||||
|
// GNU Lesser General Public License Usage
|
||||||
|
// This library is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
//##################################################################################################
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cvfBase.h"
|
||||||
|
#include "cvfVector3.h"
|
||||||
|
|
||||||
|
namespace caf
|
||||||
|
{
|
||||||
|
template<typename S>
|
||||||
|
class Line
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Line();
|
||||||
|
Line(const cvf::Vector3<S>& startPoint, const cvf::Vector3<S>& endPoint);
|
||||||
|
Line(const Line& copyFrom);
|
||||||
|
Line& operator=(const Line& copyFrom);
|
||||||
|
|
||||||
|
const cvf::Vector3<S>& start() const;
|
||||||
|
const cvf::Vector3<S>& end() const;
|
||||||
|
cvf::Vector3<S> vector() const;
|
||||||
|
|
||||||
|
Line findLineBetweenNearestPoints(const Line& otherLine, bool* withinLineSegments = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
cvf::Vector3<S> m_start;
|
||||||
|
cvf::Vector3<S> m_end;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "cafLine.inl"
|
||||||
|
|
||||||
|
|
||||||
111
Fwk/AppFwk/cafVizExtensions/cafLine.inl
Normal file
111
Fwk/AppFwk/cafVizExtensions/cafLine.inl
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#include "cafLine.h"
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
caf::Line<S>::Line()
|
||||||
|
: m_start(cvf::Vector3<S>::UNDEFINED)
|
||||||
|
, m_end(cvf::Vector3<S>::UNDEFINED)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
caf::Line<S>::Line(const cvf::Vector3<S>& startPoint, const cvf::Vector3<S>& endPoint)
|
||||||
|
: m_start(startPoint)
|
||||||
|
, m_end(endPoint)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
caf::Line<S>::Line(const Line& copyFrom)
|
||||||
|
{
|
||||||
|
m_start = copyFrom.start();
|
||||||
|
m_end = copyFrom.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
caf::Line<S>& caf::Line<S>::operator=(const Line& copyFrom)
|
||||||
|
{
|
||||||
|
m_start = copyFrom.start();
|
||||||
|
m_end = copyFrom.end();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
const cvf::Vector3<S>& caf::Line<S>::start() const
|
||||||
|
{
|
||||||
|
return m_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
const cvf::Vector3<S>& caf::Line<S>::end() const
|
||||||
|
{
|
||||||
|
return m_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
cvf::Vector3<S> caf::Line<S>::vector() const
|
||||||
|
{
|
||||||
|
return m_end - m_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename S>
|
||||||
|
caf::Line<S> caf::Line<S>::findLineBetweenNearestPoints(const Line& otherLine, bool* withinLineSegments)
|
||||||
|
{
|
||||||
|
// Taken from Real-Time Collision Detection, Christer Ericson, 2005, p146-147
|
||||||
|
cvf::Vector3<S> d1 = vector();
|
||||||
|
cvf::Vector3<S> d2 = otherLine.vector();
|
||||||
|
|
||||||
|
S a = d1.dot(d1);
|
||||||
|
S b = d1.dot(d2);
|
||||||
|
S e = d2.dot(d2);
|
||||||
|
|
||||||
|
S d = a * e - b * b;
|
||||||
|
|
||||||
|
if (d < std::numeric_limits<typename S>::epsilon())
|
||||||
|
{
|
||||||
|
// Parallel lines. Choice of closest points is arbitrary.
|
||||||
|
// Just use start to start.
|
||||||
|
if (withinLineSegments) *withinLineSegments = true;
|
||||||
|
return Line(start(), otherLine.start());
|
||||||
|
}
|
||||||
|
|
||||||
|
cvf::Vector3<S> r = start() - otherLine.start();
|
||||||
|
S c = d1.dot(r);
|
||||||
|
S f = d2.dot(r);
|
||||||
|
|
||||||
|
S s = (b*f - c * e) / d;
|
||||||
|
S t = (a*f - b * c) / d;
|
||||||
|
|
||||||
|
if (withinLineSegments)
|
||||||
|
{
|
||||||
|
*withinLineSegments = s >= 0 && s <= 1 && t >= 0 && t <= 1;
|
||||||
|
}
|
||||||
|
return Line(start() + s * d1, otherLine.start() + t * d2);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user