mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-23 23:13:39 -06:00
#2841 Fix bad result when z-clipping is applied.
This commit is contained in:
parent
98af9e00ab
commit
ffccb078e8
@ -73,8 +73,9 @@ Riv3dWellLogDrawSurfaceGenerator::createDrawSurface(const caf::DisplayCoordTrans
|
|||||||
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
|
m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection);
|
||||||
|
|
||||||
std::vector<cvf::Vec3d> wellPathPoints = wellPathGeometry()->m_wellPathPoints;
|
std::vector<cvf::Vec3d> wellPathPoints = wellPathGeometry()->m_wellPathPoints;
|
||||||
if (wellPathPoints.empty())
|
if (wellPathPoints.size() < (size_t)2)
|
||||||
{
|
{
|
||||||
|
// Need at least two well path points to create a valid path.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,154 +84,46 @@ Riv3dWellLogDrawSurfaceGenerator::createDrawSurface(const caf::DisplayCoordTrans
|
|||||||
wellPathPoint = displayCoordTransform->transformToDisplayCoord(wellPathPoint);
|
wellPathPoint = displayCoordTransform->transformToDisplayCoord(wellPathPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<cvf::Vec3d> segmentNormals =
|
std::vector<cvf::Vec3d> wellPathSegmentNormals =
|
||||||
RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathPoints, planeAngle);
|
RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathPoints, planeAngle);
|
||||||
|
|
||||||
|
size_t indexToFirstVisibleSegment = 0u;
|
||||||
size_t originalWellPathSize = wellPathPoints.size();
|
|
||||||
|
|
||||||
if (wellPathCollection->wellPathClip)
|
if (wellPathCollection->wellPathClip)
|
||||||
{
|
{
|
||||||
double clipZDistance = wellPathCollection->wellPathClipZDistance;
|
double clipZDistance = wellPathCollection->wellPathClipZDistance;
|
||||||
double horizontalLengthAlongWellToClipPoint;
|
|
||||||
cvf::Vec3d clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
|
cvf::Vec3d clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d(0, 0, 1);
|
||||||
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
|
clipLocation = displayCoordTransform->transformToDisplayCoord(clipLocation);
|
||||||
size_t indexToFirstVisibleSegment;
|
double horizontalLengthAlongWellToClipPoint;
|
||||||
|
|
||||||
wellPathPoints = RigWellPath::clipPolylineStartAboveZ(
|
wellPathPoints = RigWellPath::clipPolylineStartAboveZ(
|
||||||
wellPathPoints, clipLocation.z(), &horizontalLengthAlongWellToClipPoint, &indexToFirstVisibleSegment);
|
wellPathPoints, clipLocation.z(), &horizontalLengthAlongWellToClipPoint, &indexToFirstVisibleSegment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wellPathPoints.size() < (size_t) 2)
|
// Create curve normal vectors using the unclipped well path points and normals.
|
||||||
|
createCurveNormalVectors(displayCoordTransform, indexToFirstVisibleSegment, planeOffsetFromWellPathCenter, planeWidth, samplingIntervalSize, wellPathSegmentNormals);
|
||||||
|
|
||||||
|
// Note that normals are calculated on the full non-clipped well path. So we need to clip the remainder here.
|
||||||
|
wellPathSegmentNormals.erase(wellPathSegmentNormals.begin(), wellPathSegmentNormals.end() - wellPathPoints.size());
|
||||||
|
|
||||||
|
if (wellPathPoints.size() < (size_t)2)
|
||||||
{
|
{
|
||||||
// Need at least two well path points to create a valid path.
|
// Need at least two well path points to create a valid path.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that normals are calculated on the full non-clipped well path to increase the likelihood of creating good normals
|
m_vertices.reserve(wellPathPoints.size() * 2);
|
||||||
// for the end points of the curve. So we need to clip the remainder here.
|
for (size_t i = 0; i < wellPathPoints.size(); i++)
|
||||||
segmentNormals.erase(segmentNormals.begin(), segmentNormals.end() - wellPathPoints.size());
|
|
||||||
|
|
||||||
{
|
{
|
||||||
m_vertices.reserve(wellPathPoints.size() * 2);
|
m_vertices.push_back(cvf::Vec3f(
|
||||||
|
wellPathPoints[i] + wellPathSegmentNormals[i] * planeOffsetFromWellPathCenter));
|
||||||
std::vector<cvf::uint> backgroundIndices;
|
m_vertices.push_back(cvf::Vec3f(
|
||||||
backgroundIndices.reserve(wellPathPoints.size() * 2);
|
wellPathPoints[i] + wellPathSegmentNormals[i] * (planeOffsetFromWellPathCenter + planeWidth)));
|
||||||
|
|
||||||
// Vertices are used for both surface and border
|
|
||||||
for (size_t i = 0; i < wellPathPoints.size(); i++)
|
|
||||||
{
|
|
||||||
m_vertices.push_back(cvf::Vec3f(
|
|
||||||
wellPathPoints[i] + segmentNormals[i] * planeOffsetFromWellPathCenter));
|
|
||||||
m_vertices.push_back(cvf::Vec3f(
|
|
||||||
wellPathPoints[i] + segmentNormals[i] * (planeOffsetFromWellPathCenter + planeWidth)));
|
|
||||||
backgroundIndices.push_back((cvf::uint) (2 * i));
|
|
||||||
backgroundIndices.push_back((cvf::uint) (2 * i + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(m_vertices);
|
|
||||||
|
|
||||||
{
|
|
||||||
// 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(m_vertices.size());
|
|
||||||
|
|
||||||
int secondLastEvenVertex = (int) m_vertices.size() - 4;
|
|
||||||
|
|
||||||
// Border close to the well. All even indices.
|
|
||||||
for (int 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) (m_vertices.size() - 2));
|
|
||||||
borderIndices.push_back((cvf::uint) (m_vertices.size() - 1));
|
|
||||||
|
|
||||||
int secondOddVertex = 3;
|
|
||||||
int lastOddVertex = (int) m_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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
|
||||||
std::vector<cvf::Vec3d> interpolatedGridPoints;
|
|
||||||
std::vector<cvf::Vec3d> interpolatedGridCurveNormals;
|
|
||||||
|
|
||||||
size_t newStartIndex = originalWellPathSize - wellPathPoints.size();
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(m_vertices);
|
||||||
double firstMd = wellPathGeometry()->m_measuredDepths.at(newStartIndex);
|
createBackground(vertexArray.p());
|
||||||
double lastMd = wellPathGeometry()->m_measuredDepths.back();
|
createBorder(vertexArray.p());
|
||||||
|
|
||||||
double md = lastMd;
|
|
||||||
while (md >= firstMd)
|
|
||||||
{
|
|
||||||
cvf::Vec3d point = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathPoints, md);
|
|
||||||
cvf::Vec3d curveNormal = wellPathGeometry()->interpolatedVectorAlongWellPath(segmentNormals, md);
|
|
||||||
interpolatedGridPoints.push_back(point);
|
|
||||||
interpolatedGridCurveNormals.push_back(curveNormal.getNormalized());
|
|
||||||
md -= samplingIntervalSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<cvf::Vec3f> arrowVertices;
|
|
||||||
std::vector<cvf::Vec3f> arrowVectors;
|
|
||||||
arrowVertices.reserve(interpolatedGridPoints.size());
|
|
||||||
arrowVectors.reserve(interpolatedGridPoints.size());
|
|
||||||
|
|
||||||
double shaftRelativeRadius = 0.0125f;
|
|
||||||
double arrowHeadRelativeRadius = shaftRelativeRadius * 3;
|
|
||||||
double arrowHeadRelativeLength = arrowHeadRelativeRadius * 3;
|
|
||||||
double totalArrowScaling = 1.0 / (1.0 - arrowHeadRelativeLength);
|
|
||||||
// Normal lines. Start from one to avoid drawing at surface edge.
|
|
||||||
for (size_t i = 1; i < interpolatedGridCurveNormals.size(); i++)
|
|
||||||
{
|
|
||||||
arrowVertices.push_back(cvf::Vec3f(interpolatedGridPoints[i] + interpolatedGridCurveNormals[i] * planeOffsetFromWellPathCenter));
|
|
||||||
|
|
||||||
arrowVectors.push_back(cvf::Vec3f(interpolatedGridCurveNormals[i] * planeWidth * totalArrowScaling));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_curveNormalVectors = new cvf::DrawableVectors();
|
|
||||||
|
|
||||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(arrowVertices);
|
|
||||||
cvf::ref<cvf::Vec3fArray> vectorArray = new cvf::Vec3fArray(arrowVectors);
|
|
||||||
|
|
||||||
// Create the arrow glyph for the vector drawer
|
|
||||||
cvf::GeometryBuilderTriangles arrowBuilder;
|
|
||||||
cvf::ArrowGenerator gen;
|
|
||||||
gen.setShaftRelativeRadius(shaftRelativeRadius);
|
|
||||||
gen.setHeadRelativeRadius(arrowHeadRelativeRadius);
|
|
||||||
gen.setHeadRelativeLength(arrowHeadRelativeLength);
|
|
||||||
gen.setNumSlices(4);
|
|
||||||
gen.generate(&arrowBuilder);
|
|
||||||
|
|
||||||
m_curveNormalVectors->setGlyph(arrowBuilder.trianglesUShort().p(), arrowBuilder.vertices().p());
|
|
||||||
m_curveNormalVectors->setVectors(vertexArray.p(), vectorArray.p());
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,6 +170,133 @@ const std::vector<cvf::Vec3f>& Riv3dWellLogDrawSurfaceGenerator::vertices() cons
|
|||||||
return m_vertices;
|
return m_vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void Riv3dWellLogDrawSurfaceGenerator::createCurveNormalVectors(const caf::DisplayCoordTransform* displayCoordTransform,
|
||||||
|
size_t clipStartIndex,
|
||||||
|
double planeOffsetFromWellPathCenter,
|
||||||
|
double planeWidth,
|
||||||
|
double samplingIntervalSize,
|
||||||
|
const std::vector<cvf::Vec3d>& segmentNormals)
|
||||||
|
{
|
||||||
|
std::vector<cvf::Vec3d> interpolatedWellPathPoints;
|
||||||
|
std::vector<cvf::Vec3d> interpolatedWellPathNormals;
|
||||||
|
|
||||||
|
double firstMd = wellPathGeometry()->m_measuredDepths.at(clipStartIndex);
|
||||||
|
double lastMd = wellPathGeometry()->m_measuredDepths.back();
|
||||||
|
|
||||||
|
double md = lastMd;
|
||||||
|
while (md >= firstMd)
|
||||||
|
{
|
||||||
|
cvf::Vec3d point = wellPathGeometry()->interpolatedPointAlongWellPath(md);
|
||||||
|
point = displayCoordTransform->transformToDisplayCoord(point);
|
||||||
|
cvf::Vec3d curveNormal = wellPathGeometry()->interpolatedVectorAlongWellPath(segmentNormals, md);
|
||||||
|
interpolatedWellPathPoints.push_back(point);
|
||||||
|
interpolatedWellPathNormals.push_back(curveNormal.getNormalized());
|
||||||
|
md -= samplingIntervalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<cvf::Vec3f> arrowVertices;
|
||||||
|
std::vector<cvf::Vec3f> arrowVectors;
|
||||||
|
arrowVertices.reserve(interpolatedWellPathPoints.size());
|
||||||
|
arrowVectors.reserve(interpolatedWellPathPoints.size());
|
||||||
|
|
||||||
|
double shaftRelativeRadius = 0.0125f;
|
||||||
|
double arrowHeadRelativeRadius = shaftRelativeRadius * 3;
|
||||||
|
double arrowHeadRelativeLength = arrowHeadRelativeRadius * 3;
|
||||||
|
double totalArrowScaling = 1.0 / (1.0 - arrowHeadRelativeLength);
|
||||||
|
// Normal lines. Start from one to avoid drawing at surface edge.
|
||||||
|
for (size_t i = 1; i < interpolatedWellPathNormals.size(); i++)
|
||||||
|
{
|
||||||
|
arrowVertices.push_back(cvf::Vec3f(interpolatedWellPathPoints[i] + interpolatedWellPathNormals[i] * planeOffsetFromWellPathCenter));
|
||||||
|
|
||||||
|
arrowVectors.push_back(cvf::Vec3f(interpolatedWellPathNormals[i] * planeWidth * totalArrowScaling));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_curveNormalVectors = new cvf::DrawableVectors();
|
||||||
|
|
||||||
|
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(arrowVertices);
|
||||||
|
cvf::ref<cvf::Vec3fArray> vectorArray = new cvf::Vec3fArray(arrowVectors);
|
||||||
|
|
||||||
|
// Create the arrow glyph for the vector drawer
|
||||||
|
cvf::GeometryBuilderTriangles arrowBuilder;
|
||||||
|
cvf::ArrowGenerator gen;
|
||||||
|
gen.setShaftRelativeRadius(shaftRelativeRadius);
|
||||||
|
gen.setHeadRelativeRadius(arrowHeadRelativeRadius);
|
||||||
|
gen.setHeadRelativeLength(arrowHeadRelativeLength);
|
||||||
|
gen.setNumSlices(4);
|
||||||
|
gen.generate(&arrowBuilder);
|
||||||
|
|
||||||
|
m_curveNormalVectors->setGlyph(arrowBuilder.trianglesUShort().p(), arrowBuilder.vertices().p());
|
||||||
|
m_curveNormalVectors->setVectors(vertexArray.p(), vectorArray.p());
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void Riv3dWellLogDrawSurfaceGenerator::createBackground(cvf::Vec3fArray* vertexArray)
|
||||||
|
{
|
||||||
|
std::vector<cvf::uint> backgroundIndices;
|
||||||
|
backgroundIndices.reserve(vertexArray->size());
|
||||||
|
for (size_t i = 0; i < vertexArray->size(); ++i)
|
||||||
|
{
|
||||||
|
backgroundIndices.push_back((cvf::uint) (i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void Riv3dWellLogDrawSurfaceGenerator::createBorder(cvf::Vec3fArray* vertexArray)
|
||||||
|
{
|
||||||
|
std::vector<cvf::uint> borderIndices;
|
||||||
|
borderIndices.reserve(m_vertices.size());
|
||||||
|
|
||||||
|
int secondLastEvenVertex = (int)vertexArray->size() - 4;
|
||||||
|
|
||||||
|
// Border close to the well. All even indices.
|
||||||
|
for (int 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) (vertexArray->size() - 2));
|
||||||
|
borderIndices.push_back((cvf::uint) (vertexArray->size() - 1));
|
||||||
|
|
||||||
|
int secondOddVertex = 3;
|
||||||
|
int lastOddVertex = (int)vertexArray->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);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -45,12 +45,12 @@ class Riv3dWellLogDrawSurfaceGenerator : public cvf::Object
|
|||||||
public:
|
public:
|
||||||
Riv3dWellLogDrawSurfaceGenerator(RimWellPath* wellPath);
|
Riv3dWellLogDrawSurfaceGenerator(RimWellPath* wellPath);
|
||||||
|
|
||||||
bool createDrawSurface(const caf::DisplayCoordTransform* displayCoordTransform,
|
bool createDrawSurface(const caf::DisplayCoordTransform* displayCoordTransform,
|
||||||
const cvf::BoundingBox& wellPathClipBoundingBox,
|
const cvf::BoundingBox& wellPathClipBoundingBox,
|
||||||
double planeAngle,
|
double planeAngle,
|
||||||
double planeOffsetFromWellPathCenter,
|
double planeOffsetFromWellPathCenter,
|
||||||
double planeWidth,
|
double planeWidth,
|
||||||
double samplingIntervalSize);
|
double samplingIntervalSize);
|
||||||
|
|
||||||
void clearGeometry();
|
void clearGeometry();
|
||||||
|
|
||||||
@ -61,6 +61,16 @@ public:
|
|||||||
const std::vector<cvf::Vec3f>& vertices() const;
|
const std::vector<cvf::Vec3f>& vertices() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createCurveNormalVectors(const caf::DisplayCoordTransform* displayCoordTransform,
|
||||||
|
size_t clipStartIndex,
|
||||||
|
double planeOffsetFromWellPathCenter,
|
||||||
|
double planeWidth,
|
||||||
|
double samplingIntervalSize,
|
||||||
|
const std::vector<cvf::Vec3d>& wellPathSegmentNormals);
|
||||||
|
|
||||||
|
void createBackground(cvf::Vec3fArray* vertexArray);
|
||||||
|
void createBorder(cvf::Vec3fArray* vertexArray);
|
||||||
|
|
||||||
const RigWellPath* wellPathGeometry() const;
|
const RigWellPath* wellPathGeometry() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user