mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3695 Well path creation : Crash when creating a vertical well
Caused by two identical reference points next to each other
This commit is contained in:
@@ -17,16 +17,15 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaPolyArcLineSampler.h"
|
||||
#include "cvfGeometryTools.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "RiaArcCurveCalculator.h"
|
||||
|
||||
#include "cvfGeometryTools.h"
|
||||
#include "cvfMatrix4.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaPolyArcLineSampler::RiaPolyArcLineSampler(const cvf::Vec3d& startTangent,
|
||||
const std::vector<cvf::Vec3d>& lineArcEndPoints)
|
||||
RiaPolyArcLineSampler::RiaPolyArcLineSampler(const cvf::Vec3d& startTangent, const std::vector<cvf::Vec3d>& lineArcEndPoints)
|
||||
: m_startTangent(startTangent)
|
||||
, m_lineArcEndPoints(lineArcEndPoints)
|
||||
, m_samplingsInterval(0.15)
|
||||
@@ -35,7 +34,6 @@ RiaPolyArcLineSampler::RiaPolyArcLineSampler(const cvf::Vec3d& startTangent,
|
||||
, m_points(nullptr)
|
||||
, m_meshDs(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -56,23 +54,25 @@ void RiaPolyArcLineSampler::sampledPointsAndMDs(double sampleInterval,
|
||||
points->clear();
|
||||
mds->clear();
|
||||
|
||||
if (m_lineArcEndPoints.size() < 2) return ;
|
||||
std::vector<cvf::Vec3d> pointsNoDuplicates = RiaPolyArcLineSampler::pointsWithoutDuplicates(m_lineArcEndPoints);
|
||||
|
||||
if (pointsNoDuplicates.size() < 2) return;
|
||||
|
||||
m_points = points;
|
||||
m_meshDs = mds;
|
||||
m_totalMD = startMD;
|
||||
|
||||
cvf::Vec3d p1 = m_lineArcEndPoints[0];
|
||||
cvf::Vec3d p2 = m_lineArcEndPoints[1];
|
||||
cvf::Vec3d p1 = pointsNoDuplicates[0];
|
||||
cvf::Vec3d p2 = pointsNoDuplicates[1];
|
||||
|
||||
m_points->push_back(p1);
|
||||
m_meshDs->push_back(m_totalMD);
|
||||
|
||||
cvf::Vec3d t2 = m_startTangent;
|
||||
|
||||
for (size_t pIdx = 0; pIdx < m_lineArcEndPoints.size() - 1 ; ++pIdx)
|
||||
for (size_t pIdx = 0; pIdx < pointsNoDuplicates.size() - 1; ++pIdx)
|
||||
{
|
||||
sampleSegment(t2, m_lineArcEndPoints[pIdx], m_lineArcEndPoints[pIdx + 1] , &t2);
|
||||
sampleSegment(t2, pointsNoDuplicates[pIdx], pointsNoDuplicates[pIdx + 1], &t2);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -97,6 +97,27 @@ void RiaPolyArcLineSampler::sampleSegment(cvf::Vec3d t1, cvf::Vec3d p1, cvf::Vec
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Vec3d> RiaPolyArcLineSampler::pointsWithoutDuplicates(const std::vector<cvf::Vec3d>& points)
|
||||
{
|
||||
std::vector<cvf::Vec3d> outputPoints;
|
||||
|
||||
cvf::Vec3d previousPoint = cvf::Vec3d::UNDEFINED;
|
||||
const double threshold = 1e-6;
|
||||
for (const auto& p : points)
|
||||
{
|
||||
if (previousPoint.isUndefined() || ((previousPoint - p).lengthSquared()) > threshold)
|
||||
{
|
||||
outputPoints.push_back(p);
|
||||
previousPoint = p;
|
||||
}
|
||||
}
|
||||
|
||||
return outputPoints;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -159,7 +180,6 @@ void RiaPolyArcLineSampler::sampleArc(cvf::Vec3d t1, cvf::Vec3d p1, cvf::Vec3d p
|
||||
|
||||
m_points->push_back(C_to_incP);
|
||||
m_meshDs->push_back(m_totalMD + angle * radius);
|
||||
|
||||
}
|
||||
m_totalMD += arcAngle * radius;
|
||||
m_points->push_back(p2);
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
class RiaPolyArcLineSampler
|
||||
{
|
||||
public:
|
||||
RiaPolyArcLineSampler(const cvf::Vec3d& startTangent,
|
||||
const std::vector<cvf::Vec3d>& lineArcEndPoints);
|
||||
|
||||
RiaPolyArcLineSampler(const cvf::Vec3d& startTangent, const std::vector<cvf::Vec3d>& lineArcEndPoints);
|
||||
|
||||
void sampledPointsAndMDs(double sampleInterval,
|
||||
bool isResamplingLines,
|
||||
std::vector<cvf::Vec3d>* points,
|
||||
std::vector<double>* mds);
|
||||
|
||||
static std::vector<cvf::Vec3d> pointsWithoutDuplicates(const std::vector<cvf::Vec3d>& points);
|
||||
|
||||
private:
|
||||
void sampleLine(cvf::Vec3d p1, cvf::Vec3d p2, cvf::Vec3d* endTangent);
|
||||
void sampleArc(cvf::Vec3d t1, cvf::Vec3d p1, cvf::Vec3d p2, cvf::Vec3d* endTangent);
|
||||
@@ -49,4 +49,3 @@ private:
|
||||
cvf::Vec3d m_startTangent;
|
||||
std::vector<cvf::Vec3d> m_lineArcEndPoints;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,3 +31,47 @@ TEST(RiaPolyArcLineSampler, Basic)
|
||||
EXPECT_NEAR(points[4].y(), sampledPoints[25].y(), 2);
|
||||
EXPECT_NEAR(points[4].z(), sampledPoints[25].z(), 2);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RiaPolyArcLineSampler, TestInvalidInput)
|
||||
{
|
||||
{
|
||||
// Two identical points after each other
|
||||
std::vector<cvf::Vec3d> points{{0, 0, -20}, {0, 0, -20}};
|
||||
|
||||
RiaPolyArcLineSampler sampler({0, 0, -1}, points);
|
||||
|
||||
std::vector<cvf::Vec3d> sampledPoints;
|
||||
std::vector<double> mds;
|
||||
|
||||
sampler.sampledPointsAndMDs(2, true, &sampledPoints, &mds);
|
||||
|
||||
EXPECT_EQ(0, (int)sampledPoints.size());
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<cvf::Vec3d> points;
|
||||
|
||||
RiaPolyArcLineSampler sampler({0, 0, -1}, points);
|
||||
|
||||
std::vector<cvf::Vec3d> sampledPoints;
|
||||
std::vector<double> mds;
|
||||
|
||||
sampler.sampledPointsAndMDs(2, true, &sampledPoints, &mds);
|
||||
|
||||
EXPECT_EQ(0, (int)sampledPoints.size());
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<cvf::Vec3d> points{{0, 0, 0}};
|
||||
|
||||
RiaPolyArcLineSampler sampler({0, 0, -1}, points);
|
||||
|
||||
std::vector<cvf::Vec3d> sampledPoints;
|
||||
std::vector<double> mds;
|
||||
|
||||
sampler.sampledPointsAndMDs(2, true, &sampledPoints, &mds);
|
||||
|
||||
EXPECT_EQ(0, (int)sampledPoints.size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user