mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3881 Prepare for better edge clipping by making interpolation function more accessible.
This commit is contained in:
@@ -62,9 +62,8 @@ bool RicContourMapPickEventHandler::handlePickEvent(const Ric3DPickEvent& eventO
|
|||||||
contourMap->firstAncestorOrThisOfTypeAsserted(view);
|
contourMap->firstAncestorOrThisOfTypeAsserted(view);
|
||||||
|
|
||||||
cvf::Vec2d pickedPoint;
|
cvf::Vec2d pickedPoint;
|
||||||
cvf::Vec2ui pickedCell;
|
|
||||||
double valueAtPoint = 0.0;
|
double valueAtPoint = 0.0;
|
||||||
if (contourMap->checkForMapIntersection(firstPickedItem.globalPickedPoint(), &pickedPoint, &pickedCell, &valueAtPoint))
|
if (contourMap->checkForMapIntersection(firstPickedItem.globalPickedPoint(), &pickedPoint, &valueAtPoint))
|
||||||
{
|
{
|
||||||
QString curveText;
|
QString curveText;
|
||||||
curveText += QString("%1\n").arg(view->createAutoName());
|
curveText += QString("%1\n").arg(view->createAutoName());
|
||||||
|
|||||||
@@ -580,44 +580,62 @@ void RimContourMapProjection::updatedWeightingResult()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RimContourMapProjection::checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const
|
bool RimContourMapProjection::checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, double* valueAtPoint) const
|
||||||
{
|
{
|
||||||
CVF_TIGHT_ASSERT(contourMapPoint);
|
CVF_TIGHT_ASSERT(contourMapPoint);
|
||||||
CVF_TIGHT_ASSERT(valueAtPoint);
|
CVF_TIGHT_ASSERT(valueAtPoint);
|
||||||
cvf::Vec3d localPos3d(localPoint3d.x() + m_sampleSpacing, localPoint3d.y() + m_sampleSpacing, 0.0);
|
|
||||||
cvf::Vec2d localPos2d(localPos3d.x(), localPos3d.y());
|
|
||||||
cvf::Vec2ui pickedCell = ijFromLocalPos(localPos2d);
|
|
||||||
*contourMapCell = pickedCell;
|
|
||||||
|
|
||||||
|
cvf::Vec3d localPos3d(localPoint3d.x() + m_sampleSpacing, localPoint3d.y() + m_sampleSpacing, 0.0);
|
||||||
|
cvf::Vec2d gridPos2d(localPos3d.x(), localPos3d.y());
|
||||||
|
cvf::Vec2d gridorigin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y());
|
||||||
|
|
||||||
|
double value = interpolateValue(gridPos2d);
|
||||||
|
if (value != std::numeric_limits<double>::infinity())
|
||||||
|
{
|
||||||
|
*valueAtPoint = value;
|
||||||
|
*contourMapPoint = gridPos2d + gridorigin;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
double RimContourMapProjection::interpolateValue(const cvf::Vec2d& gridPos2d) const
|
||||||
{
|
{
|
||||||
cvf::Vec2d gridorigin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y());
|
cvf::Vec2d gridorigin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y());
|
||||||
cvf::Vec2d globalCellCenter = globalCellCenterPosition(pickedCell.x(), pickedCell.y());
|
|
||||||
|
cvf::Vec2ui cellContainingPoint = ijFromLocalPos(gridPos2d);
|
||||||
|
cvf::Vec2d globalCellCenter = globalCellCenterPosition(cellContainingPoint.x(), cellContainingPoint.y());
|
||||||
cvf::Vec2d cellCenter = globalCellCenter - gridorigin;
|
cvf::Vec2d cellCenter = globalCellCenter - gridorigin;
|
||||||
|
|
||||||
std::array<cvf::Vec3d, 4> x;
|
std::array<cvf::Vec3d, 4> x;
|
||||||
x[0] = cvf::Vec3d(cellCenter + cvf::Vec2d(-m_sampleSpacing * 0.5, -m_sampleSpacing * 0.5), 0.0);
|
x[0] = cvf::Vec3d(cellCenter + cvf::Vec2d(-m_sampleSpacing * 0.5, -m_sampleSpacing * 0.5), 0.0);
|
||||||
x[1] = cvf::Vec3d(cellCenter + cvf::Vec2d(m_sampleSpacing * 0.5, -m_sampleSpacing * 0.5), 0.0);
|
x[1] = cvf::Vec3d(cellCenter + cvf::Vec2d(m_sampleSpacing * 0.5, -m_sampleSpacing * 0.5), 0.0);
|
||||||
x[2] = cvf::Vec3d(cellCenter + cvf::Vec2d(m_sampleSpacing * 0.5, m_sampleSpacing * 0.5), 0.0);
|
x[2] = cvf::Vec3d(cellCenter + cvf::Vec2d(m_sampleSpacing * 0.5, m_sampleSpacing * 0.5), 0.0);
|
||||||
x[3] = cvf::Vec3d(cellCenter + cvf::Vec2d(-m_sampleSpacing * 0.5, m_sampleSpacing * 0.5), 0.0);
|
x[3] = cvf::Vec3d(cellCenter + cvf::Vec2d(-m_sampleSpacing * 0.5, m_sampleSpacing * 0.5), 0.0);
|
||||||
cvf::Vec4d baryCentricCoords = cvf::GeometryTools::barycentricCoords(x[0], x[1], x[2], x[3], localPos3d);
|
|
||||||
|
cvf::Vec4d baryCentricCoords = cvf::GeometryTools::barycentricCoords(x[0], x[1], x[2], x[3], cvf::Vec3d(gridPos2d, 0.0));
|
||||||
|
|
||||||
std::array<cvf::Vec2ui, 4> v;
|
std::array<cvf::Vec2ui, 4> v;
|
||||||
v[0] = pickedCell;
|
v[0] = cellContainingPoint;
|
||||||
v[1] = cvf::Vec2ui(pickedCell.x() + 1u, pickedCell.y());
|
v[1] = cvf::Vec2ui(cellContainingPoint.x() + 1u, cellContainingPoint.y());
|
||||||
v[2] = cvf::Vec2ui(pickedCell.x() + 1u, pickedCell.y() + 1u);
|
v[2] = cvf::Vec2ui(cellContainingPoint.x() + 1u, cellContainingPoint.y() + 1u);
|
||||||
v[3] = cvf::Vec2ui(pickedCell.x(), pickedCell.y() + 1u);
|
v[3] = cvf::Vec2ui(cellContainingPoint.x(), cellContainingPoint.y() + 1u);
|
||||||
|
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
value += baryCentricCoords[i] * valueAtVertex(v[i].x(), v[i].y());
|
double vertexValue = valueAtVertex(v[i].x(), v[i].y());
|
||||||
|
if (vertexValue == std::numeric_limits<double>::infinity())
|
||||||
|
{
|
||||||
|
return std::numeric_limits<double>::infinity();
|
||||||
}
|
}
|
||||||
|
value += baryCentricCoords[i] * vertexValue;
|
||||||
*valueAtPoint = value;
|
|
||||||
*contourMapPoint = localPos2d + gridorigin;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -111,10 +111,12 @@ public:
|
|||||||
|
|
||||||
void updatedWeightingResult();
|
void updatedWeightingResult();
|
||||||
|
|
||||||
bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const;
|
bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, double* valueAtPoint) const;
|
||||||
void setPickPoint(cvf::Vec2d pickedPoint);
|
void setPickPoint(cvf::Vec2d pickedPoint);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
double interpolateValue(const cvf::Vec2d& gridPosition2d) const;
|
||||||
|
|
||||||
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||||
void defineEditorAttribute(const caf::PdmFieldHandle* field,
|
void defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||||
QString uiConfigName,
|
QString uiConfigName,
|
||||||
|
|||||||
Reference in New Issue
Block a user