#1442 Moved geometry functions to RigFishbonesGeometry

This commit is contained in:
Magne Sjaastad
2017-05-08 07:54:02 +02:00
parent a85883228c
commit b0c5ceeab6
7 changed files with 288 additions and 146 deletions

View File

@@ -84,131 +84,36 @@ void RivFishbonesSubsPartMgr::clearGeometryCache()
//--------------------------------------------------------------------------------------------------
void RivFishbonesSubsPartMgr::buildParts(caf::DisplayCoordTransform* displayCoordTransform, double characteristicCellSize)
{
std::vector<double> locationOfSubs = m_rimFishbonesSubs->locationOfSubs();
RimWellPath* wellPath = nullptr;
m_rimFishbonesSubs->firstAncestorOrThisOfTypeAsserted(wellPath);
RigWellPath* rigWellPath = wellPath->wellPathGeometry();
RivPipeGeometryGenerator geoGenerator;
geoGenerator.setRadius(m_rimFishbonesSubs->tubingRadius());
for (size_t instanceIndex = 0; instanceIndex < locationOfSubs.size(); instanceIndex++)
for (size_t subIndex = 0; subIndex < m_rimFishbonesSubs->locationOfSubs().size(); subIndex++)
{
double measuredDepth = locationOfSubs[instanceIndex];
cvf::Vec3d position = rigWellPath->interpolatedPointAlongWellPath(measuredDepth);
cvf::Vec3d p1 = cvf::Vec3d::UNDEFINED;
cvf::Vec3d p2 = cvf::Vec3d::UNDEFINED;
rigWellPath->twoClosestPoints(position, &p1, &p2);
if (!p1.isUndefined() && !p2.isUndefined())
for (size_t lateralIndex = 0; lateralIndex < m_rimFishbonesSubs->lateralLengths().size(); lateralIndex++)
{
std::vector<double> lateralLengths = m_rimFishbonesSubs->lateralLengths();
cvf::Mat4d buildAngleRotationMatrix;
std::vector<cvf::Vec3d> lateralDomainCoords = m_rimFishbonesSubs->coordsForLateral(subIndex, lateralIndex);
for (size_t i = 0; i < lateralLengths.size(); i++)
std::vector<cvf::Vec3d> displayCoords;
for (auto domainCoord : lateralDomainCoords)
{
cvf::Vec3d lateralDirection;
{
cvf::Vec3d alongWellPath = (p2 - p1).getNormalized();
displayCoords.push_back(displayCoordTransform->transformToDisplayCoord(domainCoord));
}
cvf::Vec3d lateralInitialDirection = cvf::Vec3d::Z_AXIS;
cylinderWithCenterLineParts(&m_parts, displayCoords, wellPath->wellPathColor(), wellPath->combinedScaleFactor() * characteristicCellSize * 0.5);
if (RivFishbonesSubsPartMgr::closestMainAxis(alongWellPath) == cvf::Vec3d::Z_AXIS)
{
// Use x-axis if well path is heading close to z-axis
lateralInitialDirection = cvf::Vec3d::X_AXIS;
}
cvf::ref<RivObjectSourceInfo> objectSourceInfo = new RivObjectSourceInfo(m_rimFishbonesSubs);
{
double intialRotationAngle = m_rimFishbonesSubs->rotationAngle(instanceIndex);
double lateralOffsetDegrees = 360.0 / lateralLengths.size();
double lateralOffsetRadians = cvf::Math::toRadians(intialRotationAngle + lateralOffsetDegrees * i);
cvf::Mat4d lateralOffsetMatrix = cvf::Mat4d::fromRotation(alongWellPath, lateralOffsetRadians);
lateralInitialDirection = lateralInitialDirection.getTransformedVector(lateralOffsetMatrix);
}
cvf::Vec3d rotationAxis;
rotationAxis.cross(alongWellPath, lateralInitialDirection);
double exitAngleRadians = cvf::Math::toRadians(m_rimFishbonesSubs->exitAngle());
cvf::Mat4d lateralRotationMatrix = cvf::Mat4d::fromRotation(rotationAxis, exitAngleRadians);
lateralDirection = alongWellPath.getTransformedVector(lateralRotationMatrix);
double buildAngleRadians = cvf::Math::toRadians(m_rimFishbonesSubs->buildAngle());
buildAngleRotationMatrix = cvf::Mat4d::fromRotation(rotationAxis, buildAngleRadians);
}
std::vector<cvf::Vec3d> lateralDomainCoords =
RivFishbonesSubsPartMgr::computeLateralCoords(position, lateralLengths[i], lateralDirection, buildAngleRotationMatrix);
std::vector<cvf::Vec3d> displayCoords;
for (auto domainCoord : lateralDomainCoords)
{
displayCoords.push_back(displayCoordTransform->transformToDisplayCoord(domainCoord));
}
cylinderWithCenterLineParts(&m_parts, displayCoords, wellPath->wellPathColor(), wellPath->combinedScaleFactor() * characteristicCellSize * 0.5);
cvf::ref<RivObjectSourceInfo> objectSourceInfo = new RivObjectSourceInfo(m_rimFishbonesSubs);
for (auto p : m_parts)
{
p->setSourceInfo(objectSourceInfo.p());
}
for (auto p : m_parts)
{
p->setSourceInfo(objectSourceInfo.p());
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> RivFishbonesSubsPartMgr::computeLateralCoords(const cvf::Vec3d& startCoord, double lateralLength, const cvf::Vec3d& lateralStartDirection, const cvf::Mat4d& buildAngleRotationMatrix)
{
std::vector<cvf::Vec3d> coords;
cvf::Vec3d lateralDirection(lateralStartDirection);
// Compute coordinates along the lateral by modifying the lateral direction by the build angle for
// every unit vector along the lateral
cvf::Vec3d accumulatedPosition = startCoord;
double accumulatedLength = 0.0;
while (accumulatedLength < lateralLength)
{
coords.push_back(accumulatedPosition);
double delta = 1.0;
if (lateralLength - accumulatedLength < 1.0)
{
delta = lateralLength - accumulatedLength;
}
accumulatedPosition += delta * lateralDirection;
// Modify the lateral direction by the build angle for each unit vector
lateralDirection = lateralDirection.getTransformedVector(buildAngleRotationMatrix);
accumulatedLength += delta;
}
// Add the last accumulated position if it is not present
if (coords.back() != accumulatedPosition)
{
coords.push_back(accumulatedPosition);
}
return coords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -250,36 +155,3 @@ void RivFishbonesSubsPartMgr::cylinderWithCenterLineParts(cvf::Collection<cvf::P
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RivFishbonesSubsPartMgr::closestMainAxis(const cvf::Vec3d& vec)
{
size_t maxComponent = 0;
double maxValue = cvf::Math::abs(vec.x());
if (cvf::Math::abs(vec.y()) > maxValue)
{
maxComponent = 1;
maxValue = cvf::Math::abs(vec.y());
}
if (cvf::Math::abs(vec.z()) > maxValue)
{
maxComponent = 2;
maxValue = cvf::Math::abs(vec.z());
}
if (maxComponent == 0)
{
return cvf::Vec3d::X_AXIS;
}
else if (maxComponent == 1)
{
return cvf::Vec3d::Y_AXIS;
}
else
{
return cvf::Vec3d::Z_AXIS;
}
}

View File

@@ -59,14 +59,8 @@ public:
private:
void buildParts(caf::DisplayCoordTransform* displayCoordTransform, double characteristicCellSize);
static std::vector<cvf::Vec3d> computeLateralCoords(const cvf::Vec3d& startCoord,
double lateralLength, const cvf::Vec3d& lateralStartDirection,
const cvf::Mat4d& buildAngleRotationMatrix);
static void cylinderWithCenterLineParts(cvf::Collection<cvf::Part>* destinationParts, const std::vector<cvf::Vec3d>& centerCoords, const cvf::Color3f& color, double radius);
static cvf::Vec3d closestMainAxis(const cvf::Vec3d& vec);
private:
caf::PdmPointer<RimFishbonesMultipleSubs> m_rimFishbonesSubs;
cvf::Collection<cvf::Part> m_parts;

View File

@@ -19,6 +19,7 @@
#include "RimFishbonesMultipleSubs.h"
#include "RimProject.h"
#include "RigFishbonesGeometry.h"
#include "cafPdmUiListEditor.h"
@@ -89,6 +90,8 @@ RimFishbonesMultipleSubs::RimFishbonesMultipleSubs()
CAF_PDM_InitFieldNoDefault(&m_installationRotationAngles, "InstallationRotationAngles", "Installation Rotation Angles [deg]", "", "", "");
m_installationRotationAngles.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_fixedInstallationRotationAngle, "FixedInstallationRotationAngle", 0.0, " Fixed Angle [deg]", "", "", "");
m_rigFishbonesGeometry = std::unique_ptr<RigFisbonesGeometry>(new RigFisbonesGeometry(this));
}
//--------------------------------------------------------------------------------------------------
@@ -183,6 +186,22 @@ std::vector<double> RimFishbonesMultipleSubs::lateralLengths() const
return lengths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> RimFishbonesMultipleSubs::coordsForLateral(size_t subIndex, size_t lateralIndex) const
{
std::vector<RigCoordAndMD> coordsAndMD = m_rigFishbonesGeometry->coordsForLateral(subIndex, lateralIndex);
std::vector<cvf::Vec3d> domainCoords;
for (auto c :coordsAndMD)
{
domainCoords.push_back(c.m_coord);
}
return domainCoords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -20,6 +20,14 @@
#include "RimCheckableNamedObject.h"
#include "cvfBase.h"
#include "cvfVector3.h"
#include <algorithm>
#include <memory>
class RigFisbonesGeometry;
//==================================================================================================
///
///
@@ -56,6 +64,8 @@ public:
double lateralCountPerSub() const;
std::vector<double> lateralLengths() const;
std::vector<cvf::Vec3d> coordsForLateral(size_t subIndex, size_t lateralIndex) const;
protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
@@ -100,4 +110,6 @@ private:
caf::PdmField<std::vector<double>> m_installationRotationAngles;
caf::PdmField<double> m_fixedInstallationRotationAngle;
std::unique_ptr<RigFisbonesGeometry> m_rigFishbonesGeometry;
};

View File

@@ -51,6 +51,7 @@ ${CEE_CURRENT_LIST_DIR}RigCurveDataTools.h
${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.h
${CEE_CURRENT_LIST_DIR}RigLasFileExporter.h
${CEE_CURRENT_LIST_DIR}RigSimulationWellCoordsAndMD.h
${CEE_CURRENT_LIST_DIR}RigFishbonesGeometry.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -96,6 +97,7 @@ ${CEE_CURRENT_LIST_DIR}RigCurveDataTools.cpp
${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.cpp
${CEE_CURRENT_LIST_DIR}RigLasFileExporter.cpp
${CEE_CURRENT_LIST_DIR}RigSimulationWellCoordsAndMD.cpp
${CEE_CURRENT_LIST_DIR}RigFishbonesGeometry.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,187 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 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 "RigFishbonesGeometry.h"
#include "RimFishbonesMultipleSubs.h"
#include "cvfAssert.h"
#include "RimWellPath.h"
#include "RigWellPath.h"
#include "cvfMatrix4.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFisbonesGeometry::RigFisbonesGeometry(RimFishbonesMultipleSubs* fishbonesSub)
: m_fishbonesSub(fishbonesSub)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::pair<cvf::Vec3d, double>> RigFisbonesGeometry::coordsForLateral(size_t subIndex, size_t lateralIndex) const
{
CVF_ASSERT(subIndex < m_fishbonesSub->locationOfSubs().size());
CVF_ASSERT(lateralIndex < m_fishbonesSub->lateralLengths().size());
cvf::Vec3d position;
cvf::Vec3d lateralInitialDirection;
cvf::Mat4d buildAngleRotationMatrix;
computeLateralPositionAndOrientation(subIndex, lateralIndex, &position, &lateralInitialDirection, &buildAngleRotationMatrix);
return computeCoordsAlongLateral(m_fishbonesSub->locationOfSubs()[subIndex], m_fishbonesSub->lateralLengths()[lateralIndex], position, lateralInitialDirection, buildAngleRotationMatrix);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFisbonesGeometry::computeLateralPositionAndOrientation(size_t subIndex, size_t lateralIndex, cvf::Vec3d* startCoord, cvf::Vec3d* startDirection, cvf::Mat4d* buildAngleMatrix) const
{
RimWellPath* wellPath = nullptr;
m_fishbonesSub->firstAncestorOrThisOfTypeAsserted(wellPath);
RigWellPath* rigWellPath = wellPath->wellPathGeometry();
CVF_ASSERT(rigWellPath);
double measuredDepth = m_fishbonesSub->locationOfSubs()[subIndex];
cvf::Vec3d position = rigWellPath->interpolatedPointAlongWellPath(measuredDepth);
cvf::Mat4d buildAngleMat;
cvf::Vec3d lateralInitialDirection = cvf::Vec3d::Z_AXIS;
{
cvf::Vec3d p1 = cvf::Vec3d::UNDEFINED;
cvf::Vec3d p2 = cvf::Vec3d::UNDEFINED;
rigWellPath->twoClosestPoints(position, &p1, &p2);
CVF_ASSERT(!p1.isUndefined() && !p2.isUndefined());
cvf::Vec3d lateralDirection;
cvf::Vec3d alongWellPath = (p2 - p1).getNormalized();
if (RigFisbonesGeometry::closestMainAxis(alongWellPath) == cvf::Vec3d::Z_AXIS)
{
// Use x-axis if well path is heading close to z-axis
lateralInitialDirection = cvf::Vec3d::X_AXIS;
}
{
double intialRotationAngle = m_fishbonesSub->rotationAngle(subIndex);
double lateralOffsetDegrees = 360.0 / m_fishbonesSub->lateralLengths().size();
double lateralOffsetRadians = cvf::Math::toRadians(intialRotationAngle + lateralOffsetDegrees * lateralIndex);
cvf::Mat4d lateralOffsetMatrix = cvf::Mat4d::fromRotation(alongWellPath, lateralOffsetRadians);
lateralInitialDirection = lateralInitialDirection.getTransformedVector(lateralOffsetMatrix);
}
cvf::Vec3d rotationAxis;
rotationAxis.cross(alongWellPath, lateralInitialDirection);
double exitAngleRadians = cvf::Math::toRadians(m_fishbonesSub->exitAngle());
cvf::Mat4d lateralRotationMatrix = cvf::Mat4d::fromRotation(rotationAxis, exitAngleRadians);
lateralDirection = alongWellPath.getTransformedVector(lateralRotationMatrix);
double buildAngleRadians = cvf::Math::toRadians(m_fishbonesSub->buildAngle());
buildAngleMat = cvf::Mat4d::fromRotation(rotationAxis, buildAngleRadians);
}
*startCoord = position;
*startDirection = lateralInitialDirection;
*buildAngleMatrix = buildAngleMat;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::pair<cvf::Vec3d, double>> RigFisbonesGeometry::computeCoordsAlongLateral(double startMeasuredDepth, double lateralLength, const cvf::Vec3d& startCoord, const cvf::Vec3d& startDirection, const cvf::Mat4d& buildAngleMatrix)
{
std::vector<std::pair<cvf::Vec3d, double>> coords;
cvf::Vec3d lateralDirection(startDirection);
// Compute coordinates along the lateral by modifying the lateral direction by the build angle for
// every unit vector along the lateral
cvf::Vec3d accumulatedPosition = startCoord;
double measuredDepth = startMeasuredDepth;
double accumulatedLength = 0.0;
while (accumulatedLength < lateralLength)
{
coords.push_back(std::make_pair(accumulatedPosition, measuredDepth));
double delta = 1.0;
if (lateralLength - accumulatedLength < 1.0)
{
delta = lateralLength - accumulatedLength;
}
accumulatedPosition += delta * lateralDirection;
// Modify the lateral direction by the build angle for each unit vector
lateralDirection = lateralDirection.getTransformedVector(buildAngleMatrix);
accumulatedLength += delta;
measuredDepth += delta;
}
coords.push_back(std::make_pair(accumulatedPosition, measuredDepth));
return coords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RigFisbonesGeometry::closestMainAxis(const cvf::Vec3d& vec)
{
size_t maxComponent = 0;
double maxValue = cvf::Math::abs(vec.x());
if (cvf::Math::abs(vec.y()) > maxValue)
{
maxComponent = 1;
maxValue = cvf::Math::abs(vec.y());
}
if (cvf::Math::abs(vec.z()) > maxValue)
{
maxComponent = 2;
maxValue = cvf::Math::abs(vec.z());
}
if (maxComponent == 0)
{
return cvf::Vec3d::X_AXIS;
}
else if (maxComponent == 1)
{
return cvf::Vec3d::Y_AXIS;
}
else
{
return cvf::Vec3d::Z_AXIS;
}
}

View File

@@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmPointer.h"
#include "cvfBase.h"
#include "cvfVector3.h"
#include "cvfMatrix4.h"
#include <vector>
class RimFishbonesMultipleSubs;
//==================================================================================================
///
///
//==================================================================================================
class RigFisbonesGeometry
{
public:
explicit RigFisbonesGeometry(RimFishbonesMultipleSubs* fishbonesSub);
std::vector<std::pair<cvf::Vec3d, double>> coordsForLateral(size_t subIndex, size_t lateralIndex) const;
private:
void computeLateralPositionAndOrientation(size_t subIndex, size_t lateralIndex,
cvf::Vec3d* startCoord, cvf::Vec3d* startDirection,
cvf::Mat4d* buildAngleMatrix) const;
static std::vector<std::pair<cvf::Vec3d, double>> computeCoordsAlongLateral(double startMeasuredDepth, double lateralLength,
const cvf::Vec3d& startCoord, const cvf::Vec3d& startDirection,
const cvf::Mat4d& buildAngleMatrix);
static cvf::Vec3d closestMainAxis(const cvf::Vec3d& vec);
private:
caf::PdmPointer<RimFishbonesMultipleSubs> m_fishbonesSub;
};