Implemented #310 Result info when picking

This included some refactorization to remove the command stuff out of
RiuViewer,
and to communicate the grid index via the source info struct, and not as
a cvfPart::id
This commit is contained in:
Jacob Støren 2015-06-11 11:38:51 +02:00
parent 24fb7ac584
commit 4f77afe43c
10 changed files with 930 additions and 421 deletions

View File

@ -51,12 +51,15 @@ set( APPLICATION_FILES
set( USER_INTERFACE_FILES
UserInterface/RiuCursors.cpp
UserInterface/RiuResultTextBuilder.cpp
UserInterface/RiuFemResultTextBuilder.cpp
UserInterface/RiuMainWindow.cpp
UserInterface/RiuResultInfoPanel.cpp
UserInterface/RiuViewer.cpp
UserInterface/RiuSimpleHistogramWidget.cpp
UserInterface/RiuMultiCaseImportDialog.cpp
UserInterface/RiuProcessMonitor.cpp
UserInterface/RiuViewerCommands.cpp
)
set( SOCKET_INTERFACE_FILES
@ -133,6 +136,8 @@ set ( QT_MOC_HEADERS
UserInterface/RiuProcessMonitor.h
SocketInterface/RiaSocketServer.h
UserInterface/RiuMultiCaseImportDialog.h
UserInterface/RiuViewerCommands.h
)
qt4_wrap_cpp( MOC_FILES_CPP ${QT_MOC_HEADERS} )

View File

@ -236,11 +236,10 @@ void RivFaultPartMgr::generatePartGeometry()
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName("Grid " + cvf::String(static_cast<int>(m_grid->gridIndex())));
part->setId(m_grid->gridIndex()); // !! For now, use grid index as part ID (needed for pick info)
part->setDrawable(geo.p());
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> si = new RivSourceInfo;
cvf::ref<RivSourceInfo> si = new RivSourceInfo(m_grid->gridIndex());
si->m_cellFaceFromTriangleMapper = m_nativeFaultGenerator->triangleToCellFaceMapper();
part->setSourceInfo(si.p());
@ -289,11 +288,10 @@ void RivFaultPartMgr::generatePartGeometry()
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName("Grid " + cvf::String(static_cast<int>(m_grid->gridIndex())));
part->setId(m_grid->gridIndex()); // !! For now, use grid index as part ID (needed for pick info)
part->setDrawable(geo.p());
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> si = new RivSourceInfo;
cvf::ref<RivSourceInfo> si = new RivSourceInfo(m_grid->gridIndex());
si->m_cellFaceFromTriangleMapper = m_oppositeFaultGenerator->triangleToCellFaceMapper();
part->setSourceInfo(si.p());
@ -340,11 +338,10 @@ void RivFaultPartMgr::generatePartGeometry()
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName("NNC in Fault. Grid " + cvf::String(static_cast<int>(m_grid->gridIndex())));
part->setId(m_grid->gridIndex()); // !! For now, use grid index as part ID (needed for pick info)
part->setDrawable(geo.p());
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> si = new RivSourceInfo;
cvf::ref<RivSourceInfo> si = new RivSourceInfo(m_grid->gridIndex());;
si->m_NNCIndices = m_NNCGenerator->triangleToNNCIndex().p();
part->setSourceInfo(si.p());

View File

@ -120,12 +120,11 @@ void RivGridPartMgr::generatePartGeometry(cvf::StructGridGeometryGenerator& geoB
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName("Grid " + cvf::String(static_cast<int>(m_gridIdx)));
part->setId(m_gridIdx); // !! For now, use grid index as part ID (needed for pick info)
part->setDrawable(geo.p());
part->setTransform(m_scaleTransform.p());
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> si = new RivSourceInfo;
cvf::ref<RivSourceInfo> si = new RivSourceInfo(m_gridIdx);
si->m_cellFaceFromTriangleMapper = geoBuilder.triangleToCellFaceMapper();
part->setSourceInfo(si.p());

View File

@ -27,10 +27,15 @@
class RivSourceInfo : public cvf::Object
{
public:
RivSourceInfo(size_t gridIndex) : m_gridIndex(gridIndex) {}
size_t gridIndex() const { return m_gridIndex; }
bool hasCellFaceMapping() const;
bool hasNNCIndices() const;
public:
cvf::cref<cvf::StuctGridTriangleToCellFaceMapper> m_cellFaceFromTriangleMapper;
cvf::ref<cvf::Array<size_t> > m_NNCIndices;
private:
size_t m_gridIndex;
};

View File

@ -0,0 +1,279 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA
// Copyright (C) Ceetron Solutions AS
//
// 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 "RiuFemResultTextBuilder.h"
#include "RigGeomechCaseData.h"
#include "RimGeoMechView.h"
#include "RimGeoMechCase.h"
#include "RigFemPartCollection.h"
#include "RigFemPart.h"
#include "RigFemPartGrid.h"
#include "RimGeoMechResultSlot.h"
#include "RigFemPartResultsCollection.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuFemResultTextBuilder::RiuFemResultTextBuilder(RimGeoMechView* reservoirView, size_t gridIndex, size_t cellIndex, size_t timeStepIndex)
{
CVF_ASSERT(reservoirView);
m_reservoirView = reservoirView;
m_gridIndex = gridIndex;
m_cellIndex = cellIndex;
m_timeStepIndex = timeStepIndex;
m_intersectionPoint = cvf::Vec3d::UNDEFINED;
m_face = cvf::StructGridInterface::NO_FACE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFemResultTextBuilder::setIntersectionPoint(cvf::Vec3d intersectionPoint)
{
m_intersectionPoint = intersectionPoint;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFemResultTextBuilder::setFace(cvf::StructGridInterface::FaceType face)
{
m_face = face;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuFemResultTextBuilder::mainResultText()
{
QString text;
text = closestNodeResultText(m_reservoirView->cellResult());
if (!text.isEmpty()) text += "\n";
QString topoText = this->topologyText("\n");
text += topoText;
text += "\n";
appendDetails(text, gridResultDetails());
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuFemResultTextBuilder::topologyText(QString itemSeparator)
{
QString text;
if (m_reservoirView->geoMechCase())
{
RigGeoMechCaseData* geomData = m_reservoirView->geoMechCase()->geoMechData();
if (geomData)
{
RigFemPart* femPart = geomData->femParts()->part(m_gridIndex);
int elementId = femPart->elmId(m_cellIndex);
text += QString("Element : Id[%1]").arg(elementId);
size_t i = 0;
size_t j = 0;
size_t k = 0;
if (geomData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k))
{
// Adjust to 1-based Eclipse indexing
i++;
j++;
k++;
cvf::Vec3d domainCoord = m_intersectionPoint; // + geomCase->femParts()->displayModelOffset();
//cvf::StructGridInterface::FaceEnum faceEnum(m_face);
//QString faceText = faceEnum.text();
//text += QString("Face : %1").arg(faceText) + itemSeparator;
//text += QString("Fem Part %1").arg(m_gridIndex) + itemSeparator;
text += QString(", ijk[%1, %2, %3]").arg(i).arg(j).arg(k) + itemSeparator;
QString formattedText;
formattedText.sprintf("Intersection point : [E: %.2f, N: %.2f, Depth: %.2f]", domainCoord.x(), domainCoord.y(), -domainCoord.z());
text += formattedText;
}
}
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuFemResultTextBuilder::gridResultDetails()
{
QString text;
if (m_reservoirView->geoMechCase() && m_reservoirView->geoMechCase()->geoMechData())
{
RigGeoMechCaseData* eclipseCaseData = m_reservoirView->geoMechCase()->geoMechData();
this->appendTextFromResultSlot(eclipseCaseData, m_gridIndex, m_cellIndex, m_timeStepIndex, m_reservoirView->cellResult(), &text);
if (!text.isEmpty())
{
text.prepend("-- Element result details --\n");
}
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFemResultTextBuilder::appendTextFromResultSlot(RigGeoMechCaseData* geomData, size_t gridIndex, size_t cellIndex, size_t timeStepIndex, RimGeoMechResultSlot* resultSlot, QString* resultInfoText)
{
if (!resultSlot)
{
return;
}
if (resultSlot->hasResult())
{
const std::vector<float>& scalarResults = geomData->femPartResults()->resultValues(resultSlot->resultAddress(), gridIndex, timeStepIndex);
if (scalarResults.size())
{
caf::AppEnum<RigFemResultPosEnum> resPosAppEnum = resultSlot->resultPositionType();
resultInfoText->append(resPosAppEnum.uiText() + ", ");
resultInfoText->append(resultSlot->resultFieldName()+ ", ") ;
resultInfoText->append(resultSlot->resultComponentName() + ":\n");
RigFemPart* femPart = geomData->femParts()->part(gridIndex);
RigElementType elmType = femPart->elementType(cellIndex);
const int* elmentConn = femPart->connectivities(cellIndex);
int elmNodeCount = RigFemTypes::elmentNodeCount(elmType);
for (int lNodeIdx = 0; lNodeIdx < elmNodeCount; ++lNodeIdx)
{
float scalarValue = std::numeric_limits<float>::infinity();
int nodeIdx = elmentConn[lNodeIdx];
if (resultSlot->resultPositionType() == RIG_NODAL)
{
scalarValue = scalarResults[nodeIdx];
}
else
{
size_t resIdx = femPart->elementNodeResultIdx(cellIndex, lNodeIdx);
scalarValue = scalarResults[resIdx];
}
resultInfoText->append(QString("\tN:%1 \t: %2\n").arg(femPart->nodes().nodeIds[nodeIdx]).arg(scalarValue));
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFemResultTextBuilder::appendDetails(QString& text, const QString& details)
{
if (!details.isEmpty())
{
text += "\n";
text += details;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuFemResultTextBuilder::closestNodeResultText(RimGeoMechResultSlot* resultSlot)
{
QString text;
if (!resultSlot)
{
return text;
}
if (resultSlot->hasResult())
{
if (! (m_reservoirView->geoMechCase() && m_reservoirView->geoMechCase()->geoMechData())) return text;
RigGeoMechCaseData* geomData = m_reservoirView->geoMechCase()->geoMechData();
const std::vector<float>& scalarResults = geomData->femPartResults()->resultValues(resultSlot->resultAddress(), m_gridIndex, m_timeStepIndex);
if (scalarResults.size())
{
RigFemPart* femPart = geomData->femParts()->part(m_gridIndex);
RigElementType elmType = femPart->elementType(m_cellIndex);
const int* elmentConn = femPart->connectivities(m_cellIndex);
int elmNodeCount = RigFemTypes::elmentNodeCount(elmType);
// Find the closest node
int closestLocalNode = -1;
float minDist = std::numeric_limits<float>::infinity();
for (int lNodeIdx = 0; lNodeIdx < elmNodeCount; ++lNodeIdx)
{
int nodeIdx = elmentConn[lNodeIdx];
cvf::Vec3f nodePos = femPart->nodes().coordinates[nodeIdx];
float dist = (nodePos - cvf::Vec3f(m_intersectionPoint)).lengthSquared();
if (dist < minDist)
{
closestLocalNode = lNodeIdx;
minDist = dist;
}
}
// Create a text showing the results from the closest node
if (closestLocalNode >= 0)
{
float scalarValue = std::numeric_limits<float>::infinity();
int nodeIdx = elmentConn[closestLocalNode];
if (resultSlot->resultPositionType() == RIG_NODAL)
{
scalarValue = scalarResults[nodeIdx];
}
else
{
size_t resIdx = femPart->elementNodeResultIdx(m_cellIndex, closestLocalNode);
scalarValue = scalarResults[resIdx];
}
text.append(QString("Closest result: N[%1], %2\n").arg(femPart->nodes().nodeIds[nodeIdx]).arg(scalarValue));
}
}
}
return text;
}

View File

@ -0,0 +1,70 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA
// Copyright (C) Ceetron Solutions AS
//
// 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 "cvfBase.h"
#include "cafPdmPointer.h"
#include "cvfStructGrid.h"
#include <QString>
class RimGeoMechView;
class RimResultSlot;
class RigGeoMechCaseData;
class RimGeoMechResultSlot;
namespace cvf {
class Part;
}
//==================================================================================================
//
//
//==================================================================================================
class RiuFemResultTextBuilder
{
public:
RiuFemResultTextBuilder(RimGeoMechView* reservoirView, size_t gridIndex, size_t cellIndex, size_t timeStepIndex);
void setFace(cvf::StructGridInterface::FaceType face);
void setIntersectionPoint(cvf::Vec3d intersectionPoint);
QString mainResultText();
QString topologyText(QString itemSeparator);
private:
void appendDetails(QString& text, const QString& details);
QString gridResultDetails();
QString closestNodeResultText(RimGeoMechResultSlot* resultSlot);
void appendTextFromResultSlot(RigGeoMechCaseData* eclipseCase, size_t gridIndex, size_t cellIndex, size_t timeStepIndex, RimGeoMechResultSlot* resultSlot, QString* resultInfoText);
private:
caf::PdmPointer<RimGeoMechView> m_reservoirView;
size_t m_gridIndex;
size_t m_cellIndex;
size_t m_timeStepIndex;
cvf::StructGridInterface::FaceType m_face;
cvf::Vec3d m_intersectionPoint;
};

View File

@ -21,6 +21,7 @@
#include "RiaStdInclude.h"
#include "RiuViewer.h"
#include "RiuViewerCommands.h"
#include "RiaApplication.h"
#include "RiuMainWindow.h"
@ -140,6 +141,8 @@ RiuViewer::RiuViewer(const QGLFormat& format, QWidget* parent)
m_histogramWidget->setPalette(p);
m_showHistogram = false;
m_viewerCommands = new RiuViewerCommands(this);
}
@ -205,7 +208,7 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event)
if (event->button() == Qt::LeftButton)
{
handlePickAction(event->x(), event->y());
m_viewerCommands->handlePickAction(event->x(), event->y());
return;
}
else if (event->button() == Qt::RightButton)
@ -217,250 +220,11 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event)
return;
}
displayContextMenu(event);
m_viewerCommands->displayContextMenu(event);
return;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::displayContextMenu(QMouseEvent* event)
{
m_currentGridIdx = cvf::UNDEFINED_SIZE_T;
m_currentCellIndex = cvf::UNDEFINED_SIZE_T;
int winPosX = event->x();
int winPosY = event->y();
uint faceIndex = cvf::UNDEFINED_UINT;
cvf::Vec3d localIntersectionPoint(cvf::Vec3d::ZERO);
cvf::Part* firstHitPart = NULL;
cvf::Part* nncFirstHitPart = NULL;
findPointAndFaceFromMousePos(winPosX, winPosY, &localIntersectionPoint, &firstHitPart, &faceIndex, &nncFirstHitPart, NULL);
if (!firstHitPart) return;
if (faceIndex == cvf::UNDEFINED_UINT) return;
if (!firstHitPart->sourceInfo()) return;
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstHitPart->sourceInfo());
const RivFemPickSourceInfo* femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>(firstHitPart->sourceInfo());
if (!(rivSourceInfo || femSourceInfo) ) return;
if (rivSourceInfo)
{
if (!rivSourceInfo->hasCellFaceMapping()) return;
// Set the data regarding what was hit
m_currentGridIdx = firstHitPart->id();
m_currentCellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex(faceIndex);
m_currentFaceIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace(faceIndex);
}
else
{
m_currentGridIdx = femSourceInfo->femPartIndex();
m_currentCellIndex = femSourceInfo->triangleToElmMapper()->elementIndex(faceIndex);
}
// IJK -slice commands
QMenu menu;
menu.addAction(QString("I-slice range filter"), this, SLOT(slotRangeFilterI()));
menu.addAction(QString("J-slice range filter"), this, SLOT(slotRangeFilterJ()));
menu.addAction(QString("K-slice range filter"), this, SLOT(slotRangeFilterK()));
// Hide faults command
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
if (eclipseView)
{
const RigCaseData* reservoir = eclipseView->eclipseCase()->reservoirData();
const RigFault* fault = reservoir->mainGrid()->findFaultFromCellIndexAndCellFace(m_currentCellIndex, m_currentFaceIndex);
if (fault)
{
menu.addSeparator();
QString faultName = fault->name();
menu.addAction(QString("Hide ") + faultName, this, SLOT(slotHideFault()));
}
}
menu.exec(event->globalPos());
}
//--------------------------------------------------------------------------------------------------
/// Todo: Move this to a command instead
//--------------------------------------------------------------------------------------------------
void RiuViewer::slotRangeFilterI()
{
createSliceRangeFilter(0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::slotRangeFilterJ()
{
createSliceRangeFilter(1);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::slotRangeFilterK()
{
createSliceRangeFilter(2);
}
void RiuViewer::createSliceRangeFilter(int ijOrk)
{
RimView* eclipseView = m_reservoirView.p();
if (!eclipseView) return;
size_t i, j, k;
ijkFromCellIndex(m_currentGridIdx, m_currentCellIndex, &i, &j, &k);
RiuMainWindow* mainWindow = RiuMainWindow::instance();
RimUiTreeModelPdm* myModel = mainWindow->uiPdmModel();
if (myModel)
{
RimCellRangeFilterCollection* rangeFilterCollection = eclipseView->rangeFilterCollection();
QModelIndex collectionModelIndex = myModel->getModelIndexFromPdmObject(rangeFilterCollection);
QModelIndex insertedIndex;
RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(collectionModelIndex, insertedIndex);
if (ijOrk == 0){
rangeFilter->name = QString("Slice I (%1)").arg(rangeFilterCollection->rangeFilters().size());
rangeFilter->cellCountI = 1;
int startIndex = CVF_MAX(static_cast<int>(i + 1), 1);
rangeFilter->startIndexI = startIndex;
}
else if (ijOrk == 1){
rangeFilter->name = QString("Slice J (%1)").arg(rangeFilterCollection->rangeFilters().size());
rangeFilter->cellCountJ = 1;
int startIndex = CVF_MAX(static_cast<int>(j + 1), 1);
rangeFilter->startIndexJ = startIndex;
}
else if (ijOrk == 2){
rangeFilter->name = QString("Slice K (%1)").arg(rangeFilterCollection->rangeFilters().size());
rangeFilter->cellCountK = 1;
int startIndex = CVF_MAX(static_cast<int>(k + 1), 1);
rangeFilter->startIndexK = startIndex;
}
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED);
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE);
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
mainWindow->setCurrentObjectInTreeView(rangeFilter);
}
eclipseView->setSurfaceDrawstyle();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::keyPressEvent(QKeyEvent* event)
{
// Trap escape key so we can get out of direct button press actions
if (event->key() == Qt::Key_Escape)
{
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::handlePickAction(int winPosX, int winPosY)
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
RiaApplication* app = RiaApplication::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if (!mainWnd) return;
size_t gridIndex = cvf::UNDEFINED_SIZE_T;
size_t cellIndex = cvf::UNDEFINED_SIZE_T;
size_t nncIndex = cvf::UNDEFINED_SIZE_T;
cvf::StructGridInterface::FaceType face = cvf::StructGridInterface::NO_FACE;
cvf::Vec3d localIntersectionPoint(cvf::Vec3d::ZERO);
{
cvf::Part* firstHitPart = NULL;
uint firstPartFaceIndex = cvf::UNDEFINED_UINT;
cvf::Part* firstNncHitPart = NULL;
uint nncPartFaceIndex = cvf::UNDEFINED_UINT;
findPointAndFaceFromMousePos(winPosX, winPosY, &localIntersectionPoint, &firstHitPart, &firstPartFaceIndex, &firstNncHitPart, &nncPartFaceIndex);
if (firstHitPart)
{
gridIndex = firstHitPart->id();
if (firstHitPart->sourceInfo())
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstHitPart->sourceInfo());
if (rivSourceInfo)
{
if (rivSourceInfo->hasCellFaceMapping())
{
CVF_ASSERT(rivSourceInfo->m_cellFaceFromTriangleMapper.notNull());
cellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex(firstPartFaceIndex);
face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace(firstPartFaceIndex);
}
}
}
}
if (firstNncHitPart && firstNncHitPart->sourceInfo())
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstNncHitPart->sourceInfo());
if (rivSourceInfo)
{
if (nncPartFaceIndex < rivSourceInfo->m_NNCIndices->size())
{
nncIndex = rivSourceInfo->m_NNCIndices->get(nncPartFaceIndex);
}
}
}
}
QString pickInfo = "No hits";
QString resultInfo = "";
if (cellIndex != cvf::UNDEFINED_SIZE_T)
{
RiuResultTextBuilder textBuilder(eclipseView, gridIndex, cellIndex, eclipseView->currentTimeStep());
textBuilder.setFace(face);
textBuilder.setNncIndex(nncIndex);
textBuilder.setIntersectionPoint(localIntersectionPoint);
resultInfo = textBuilder.mainResultText();
pickInfo = textBuilder.topologyText(", ");
}
mainWnd->statusBar()->showMessage(pickInfo);
mainWnd->setResultInfo(resultInfo);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -511,6 +275,7 @@ void RiuViewer::setPointOfInterest(cvf::Vec3d poi)
void RiuViewer::setOwnerReservoirView(RimView * owner)
{
m_reservoirView = owner;
m_viewerCommands->setOwnerView(owner);
}
//--------------------------------------------------------------------------------------------------
@ -521,110 +286,6 @@ void RiuViewer::setEnableMask(unsigned int mask)
m_mainRendering->setEnableMask(mask);
}
//--------------------------------------------------------------------------------------------------
/// Perform picking and return the index of the face that was hit, if a drawable geo was hit
//--------------------------------------------------------------------------------------------------
void RiuViewer::findPointAndFaceFromMousePos(int winPosX, int winPosY,
cvf::Vec3d* localIntersectionPoint, cvf::Part** firstPart, uint* firstPartFaceHit,
cvf::Part** nncPart, uint* nncPartFaceHit)
{
cvf::HitItemCollection hitItems;
bool isSomethingHit = rayPick(winPosX, winPosY, &hitItems);
if (isSomethingHit)
{
CVF_ASSERT(hitItems.count() > 0);
double pickDepthThresholdSquared = 0.05 *0.05;
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
if (eclipseView && eclipseView->eclipseCase())
{
double characteristicCellSize = eclipseView->eclipseCase()->reservoirData()->mainGrid()->characteristicIJCellSize();
pickDepthThresholdSquared = characteristicCellSize / 100.0;
pickDepthThresholdSquared = pickDepthThresholdSquared * pickDepthThresholdSquared;
}
}
cvf::HitItem* firstNonNncHitItem = NULL;
cvf::Vec3d firstItemIntersectionPoint = hitItems.item(0)->intersectionPoint();
// Check if we have a close hit item with NNC data
for (size_t i = 0; i < hitItems.count(); i++)
{
cvf::HitItem* hitItemCandidate = hitItems.item(i);
cvf::Vec3d diff = firstItemIntersectionPoint - hitItemCandidate->intersectionPoint();
const cvf::Part* pickedPartCandidate = hitItemCandidate->part();
bool isNncpart = false;
if (pickedPartCandidate && pickedPartCandidate->sourceInfo())
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(pickedPartCandidate->sourceInfo());
if (rivSourceInfo && rivSourceInfo->hasNNCIndices())
{
// Hit items are ordered by distance from eye
if (diff.lengthSquared() < pickDepthThresholdSquared)
{
*nncPart = const_cast<cvf::Part*>(pickedPartCandidate);
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(hitItemCandidate->detail());
if (detail && nncPartFaceHit)
{
*nncPartFaceHit = detail->faceIndex();
}
isNncpart = true;
}
}
}
if (!isNncpart && !firstNonNncHitItem)
{
firstNonNncHitItem = hitItemCandidate;
firstItemIntersectionPoint = firstNonNncHitItem->intersectionPoint();
}
if (firstNonNncHitItem && *nncPart)
{
break;
}
}
const cvf::Part* pickedPart = firstNonNncHitItem->part();
CVF_ASSERT(pickedPart);
*firstPart = const_cast<cvf::Part*>(pickedPart);
const cvf::Transform* xf = pickedPart->transform();
cvf::Vec3d globalPickedPoint = firstNonNncHitItem->intersectionPoint();
if(localIntersectionPoint)
{
if (xf)
{
*localIntersectionPoint = globalPickedPoint.getTransformedPoint(xf->worldTransform().getInverted());
}
else
{
*localIntersectionPoint = globalPickedPoint;
}
}
if (firstPartFaceHit)
{
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(firstNonNncHitItem->detail());
if (detail)
{
*firstPartFaceHit = detail->faceIndex();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -724,26 +385,6 @@ void RiuViewer::showHistogram(bool enable)
m_showHistogram = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size_t* i, size_t* j, size_t* k)
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
RimGeoMechView* geomView = dynamic_cast<RimGeoMechView*>(m_reservoirView.p());
if (eclipseView && eclipseView->eclipseCase())
{
eclipseView->eclipseCase()->reservoirData()->grid(gridIdx)->ijkFromCellIndex(cellIndex, i, j, k);
}
if (geomView && geomView->geoMechCase())
{
geomView->geoMechCase()->geoMechData()->femParts()->part(gridIdx)->structGrid()->ijkFromCellIndex(cellIndex, i, j, k);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -753,28 +394,6 @@ void RiuViewer::mousePressEvent(QMouseEvent* event)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::slotHideFault()
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
if(!eclipseView) return;
const RigCaseData* reservoir = eclipseView->eclipseCase()->reservoirData();
const RigFault* fault = reservoir->mainGrid()->findFaultFromCellIndexAndCellFace(m_currentCellIndex, m_currentFaceIndex);
if (fault)
{
QString faultName = fault->name();
RimFault* rimFault = eclipseView->faultCollection()->findFaultByName(faultName);
if (rimFault)
{
rimFault->showFault.setValueFromUi(!rimFault->showFault);
}
}
}
//--------------------------------------------------------------------------------------------------
///
@ -805,4 +424,3 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
m_visibleLegends.push_back(legend);
}
}

View File

@ -33,6 +33,7 @@ class QLabel;
class QProgressBar;
class RiuSimpleHistogramWidget;
class QCDEStyle;
class RiuViewerCommands;
namespace cvf
{
@ -75,27 +76,11 @@ public slots:
virtual void slotSetCurrentFrame(int frameIndex);
virtual void slotEndAnimation();
protected:
void paintOverlayItems(QPainter* painter);
void keyPressEvent(QKeyEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void displayContextMenu(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void handlePickAction(int winPosX, int winPosY);
void findPointAndFaceFromMousePos(int winPosX, int winPosY, cvf::Vec3d* localIntersectionPoint, cvf::Part** firstPart, uint* firstPartFaceHit, cvf::Part** nncPart, uint* nncPartFaceHit);
private slots:
void slotRangeFilterI();
void slotRangeFilterJ();
void slotRangeFilterK();
void slotHideFault();
private:
void ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size_t* i, size_t* j, size_t* k);
void createSliceRangeFilter(int ijOrk);
void paintOverlayItems(QPainter* painter);
void mouseReleaseEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
QLabel* m_InfoLabel;
bool m_showInfoText;;
@ -111,10 +96,8 @@ private:
cvf::Collection<cvf::OverlayItem> m_visibleLegends;
caf::PdmPointer<RimView> m_reservoirView;
QPoint m_lastMousePressPosition;
size_t m_currentGridIdx;
size_t m_currentCellIndex;
cvf::StructGridInterface::FaceType m_currentFaceIndex;
QPoint m_lastMousePressPosition;
RiuViewerCommands * m_viewerCommands;
};

View File

@ -0,0 +1,485 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "RiuViewerCommands.h"
#include "RiuViewer.h"
#include "RimUiTreeModelPdm.h"
#include "RimCellRangeFilter.h"
#include "RimView.h"
#include "RimCellRangeFilterCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimGeoMechView.h"
#include "RimFaultCollection.h"
#include "RivSourceInfo.h"
#include "RivFemPickSourceInfo.h"
#include "RivFemPartGeometryGenerator.h"
#include "RigCaseData.h"
#include "RiuMainWindow.h"
#include "RiaApplication.h"
#include "RiuResultTextBuilder.h"
#include "RigGeomechCaseData.h"
#include "RimGeoMechCase.h"
#include "RigFemPartCollection.h"
#include "RigFemPartGrid.h"
#include "cvfDrawableGeo.h"
#include "cvfPart.h"
#include "cvfHitItemCollection.h"
#include <QMenu>
#include <QMouseEvent>
#include <QStatusBar>
#include "RiuFemResultTextBuilder.h"
//==================================================================================================
//
// RiaViewerCommands
//
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuViewerCommands::RiuViewerCommands(RiuViewer* ownerViewer) : QObject(ownerViewer), m_viewer(ownerViewer)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuViewerCommands::~RiuViewerCommands()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::setOwnerView(RimView * owner)
{
m_reservoirView = owner;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
{
m_currentGridIdx = cvf::UNDEFINED_SIZE_T;
m_currentCellIndex = cvf::UNDEFINED_SIZE_T;
int winPosX = event->x();
int winPosY = event->y();
uint faceIndex = cvf::UNDEFINED_UINT;
cvf::Vec3d localIntersectionPoint(cvf::Vec3d::ZERO);
cvf::Part* firstHitPart = NULL;
cvf::Part* nncFirstHitPart = NULL;
cvf::HitItemCollection hitItems;
if (m_viewer->rayPick(winPosX, winPosY, &hitItems))
{
extractIntersectionData(hitItems, &localIntersectionPoint, &firstHitPart, &faceIndex, &nncFirstHitPart, NULL);
}
if (!firstHitPart) return;
if (faceIndex == cvf::UNDEFINED_UINT) return;
if (!firstHitPart->sourceInfo()) return;
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstHitPart->sourceInfo());
const RivFemPickSourceInfo* femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>(firstHitPart->sourceInfo());
if (!(rivSourceInfo || femSourceInfo) ) return;
if (rivSourceInfo)
{
if (!rivSourceInfo->hasCellFaceMapping()) return;
// Set the data regarding what was hit
m_currentGridIdx = rivSourceInfo->gridIndex();
m_currentCellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex(faceIndex);
m_currentFaceIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace(faceIndex);
}
else
{
m_currentGridIdx = femSourceInfo->femPartIndex();
m_currentCellIndex = femSourceInfo->triangleToElmMapper()->elementIndex(faceIndex);
}
// IJK -slice commands
QMenu menu;
menu.addAction(QString("I-slice range filter"), this, SLOT(slotRangeFilterI()));
menu.addAction(QString("J-slice range filter"), this, SLOT(slotRangeFilterJ()));
menu.addAction(QString("K-slice range filter"), this, SLOT(slotRangeFilterK()));
// Hide faults command
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
if (eclipseView)
{
const RigCaseData* reservoir = eclipseView->eclipseCase()->reservoirData();
const RigFault* fault = reservoir->mainGrid()->findFaultFromCellIndexAndCellFace(m_currentCellIndex, m_currentFaceIndex);
if (fault)
{
menu.addSeparator();
QString faultName = fault->name();
menu.addAction(QString("Hide ") + faultName, this, SLOT(slotHideFault()));
}
}
menu.exec(event->globalPos());
}
//--------------------------------------------------------------------------------------------------
/// Todo: Move this to a command instead
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::slotRangeFilterI()
{
createSliceRangeFilter(0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::slotRangeFilterJ()
{
createSliceRangeFilter(1);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::slotRangeFilterK()
{
createSliceRangeFilter(2);
}
void RiuViewerCommands::createSliceRangeFilter(int ijOrk)
{
RimView* eclipseView = m_reservoirView.p();
if (!eclipseView) return;
size_t i, j, k;
ijkFromCellIndex(m_currentGridIdx, m_currentCellIndex, &i, &j, &k);
RiuMainWindow* mainWindow = RiuMainWindow::instance();
RimUiTreeModelPdm* myModel = mainWindow->uiPdmModel();
if (myModel)
{
RimCellRangeFilterCollection* rangeFilterCollection = eclipseView->rangeFilterCollection();
QModelIndex collectionModelIndex = myModel->getModelIndexFromPdmObject(rangeFilterCollection);
QModelIndex insertedIndex;
RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(collectionModelIndex, insertedIndex);
if (ijOrk == 0){
rangeFilter->name = QString("Slice I (%1)").arg(rangeFilterCollection->rangeFilters().size());
rangeFilter->cellCountI = 1;
int startIndex = CVF_MAX(static_cast<int>(i + 1), 1);
rangeFilter->startIndexI = startIndex;
}
else if (ijOrk == 1){
rangeFilter->name = QString("Slice J (%1)").arg(rangeFilterCollection->rangeFilters().size());
rangeFilter->cellCountJ = 1;
int startIndex = CVF_MAX(static_cast<int>(j + 1), 1);
rangeFilter->startIndexJ = startIndex;
}
else if (ijOrk == 2){
rangeFilter->name = QString("Slice K (%1)").arg(rangeFilterCollection->rangeFilters().size());
rangeFilter->cellCountK = 1;
int startIndex = CVF_MAX(static_cast<int>(k + 1), 1);
rangeFilter->startIndexK = startIndex;
}
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED);
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE);
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
mainWindow->setCurrentObjectInTreeView(rangeFilter);
}
eclipseView->setSurfaceDrawstyle();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::slotHideFault()
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
if(!eclipseView) return;
const RigCaseData* reservoir = eclipseView->eclipseCase()->reservoirData();
const RigFault* fault = reservoir->mainGrid()->findFaultFromCellIndexAndCellFace(m_currentCellIndex, m_currentFaceIndex);
if (fault)
{
QString faultName = fault->name();
RimFault* rimFault = eclipseView->faultCollection()->findFaultByName(faultName);
if (rimFault)
{
rimFault->showFault.setValueFromUi(!rimFault->showFault);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::handlePickAction(int winPosX, int winPosY)
{
size_t gridIndex = cvf::UNDEFINED_SIZE_T;
size_t cellIndex = cvf::UNDEFINED_SIZE_T;
size_t nncIndex = cvf::UNDEFINED_SIZE_T;
cvf::StructGridInterface::FaceType face = cvf::StructGridInterface::NO_FACE;
cvf::Vec3d localIntersectionPoint(cvf::Vec3d::ZERO);
// Extract all the above information from the pick
{
cvf::Part* firstHitPart = NULL;
uint firstPartTriangleIndex = cvf::UNDEFINED_UINT;
cvf::Part* firstNncHitPart = NULL;
uint nncPartTriangleIndex = cvf::UNDEFINED_UINT;
cvf::HitItemCollection hitItems;
if (m_viewer->rayPick(winPosX, winPosY, &hitItems))
{
extractIntersectionData(hitItems, &localIntersectionPoint, &firstHitPart, &firstPartTriangleIndex, &firstNncHitPart, &nncPartTriangleIndex);
}
if (firstHitPart && firstHitPart->sourceInfo())
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstHitPart->sourceInfo());
const RivFemPickSourceInfo* femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>(firstHitPart->sourceInfo());
if (rivSourceInfo)
{
gridIndex = rivSourceInfo->gridIndex();
if (rivSourceInfo->hasCellFaceMapping())
{
CVF_ASSERT(rivSourceInfo->m_cellFaceFromTriangleMapper.notNull());
cellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex(firstPartTriangleIndex);
face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace(firstPartTriangleIndex);
}
}
else if (femSourceInfo)
{
gridIndex = femSourceInfo->femPartIndex();
cellIndex = femSourceInfo->triangleToElmMapper()->elementIndex(firstPartTriangleIndex);
}
}
if (firstNncHitPart && firstNncHitPart->sourceInfo())
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstNncHitPart->sourceInfo());
if (rivSourceInfo)
{
if (nncPartTriangleIndex < rivSourceInfo->m_NNCIndices->size())
{
nncIndex = rivSourceInfo->m_NNCIndices->get(nncPartTriangleIndex);
}
}
}
}
// Compose a info text regarding the hit
QString pickInfo = "No hits";
QString resultInfo = "";
if (cellIndex != cvf::UNDEFINED_SIZE_T)
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
RimGeoMechView* geomView = dynamic_cast<RimGeoMechView*>(m_reservoirView.p());
if (eclipseView)
{
RiuResultTextBuilder textBuilder(eclipseView, gridIndex, cellIndex, eclipseView->currentTimeStep());
textBuilder.setFace(face);
textBuilder.setNncIndex(nncIndex);
textBuilder.setIntersectionPoint(localIntersectionPoint);
resultInfo = textBuilder.mainResultText();
pickInfo = textBuilder.topologyText(", ");
}
else if (geomView)
{
RiuFemResultTextBuilder textBuilder(geomView, gridIndex, cellIndex, geomView->currentTimeStep());
//textBuilder.setFace(face);
textBuilder.setIntersectionPoint(localIntersectionPoint);
resultInfo = textBuilder.mainResultText();
pickInfo = textBuilder.topologyText(", ");
}
}
// Display the text
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if (!mainWnd) return;
mainWnd->statusBar()->showMessage(pickInfo);
mainWnd->setResultInfo(resultInfo);
}
//--------------------------------------------------------------------------------------------------
/// Perform picking and return the index of the face that was hit, if a drawable geo was hit
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hitItems,
cvf::Vec3d* localIntersectionPoint, cvf::Part** firstPart, uint* firstPartFaceHit,
cvf::Part** nncPart, uint* nncPartFaceHit)
{
CVF_ASSERT(hitItems.count() > 0);
double pickDepthThresholdSquared = 0.05 *0.05;
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
if (eclipseView && eclipseView->eclipseCase())
{
double characteristicCellSize = eclipseView->eclipseCase()->reservoirData()->mainGrid()->characteristicIJCellSize();
pickDepthThresholdSquared = characteristicCellSize / 100.0;
pickDepthThresholdSquared = pickDepthThresholdSquared * pickDepthThresholdSquared;
}
}
const cvf::HitItem* firstNonNncHitItem = NULL;
cvf::Vec3d firstItemIntersectionPoint = hitItems.item(0)->intersectionPoint();
// Check if we have a close hit item with NNC data
for (size_t i = 0; i < hitItems.count(); i++)
{
const cvf::HitItem* hitItemCandidate = hitItems.item(i);
cvf::Vec3d diff = firstItemIntersectionPoint - hitItemCandidate->intersectionPoint();
const cvf::Part* pickedPartCandidate = hitItemCandidate->part();
bool isNncpart = false;
if (pickedPartCandidate && pickedPartCandidate->sourceInfo())
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(pickedPartCandidate->sourceInfo());
if (rivSourceInfo && rivSourceInfo->hasNNCIndices())
{
// Hit items are ordered by distance from eye
if (diff.lengthSquared() < pickDepthThresholdSquared)
{
*nncPart = const_cast<cvf::Part*>(pickedPartCandidate);
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(hitItemCandidate->detail());
if (detail && nncPartFaceHit)
{
*nncPartFaceHit = detail->faceIndex();
}
isNncpart = true;
}
}
}
if (!isNncpart && !firstNonNncHitItem)
{
firstNonNncHitItem = hitItemCandidate;
firstItemIntersectionPoint = firstNonNncHitItem->intersectionPoint();
}
if (firstNonNncHitItem && *nncPart)
{
break;
}
}
const cvf::Part* pickedPart = firstNonNncHitItem->part();
CVF_ASSERT(pickedPart);
*firstPart = const_cast<cvf::Part*>(pickedPart);
const cvf::Transform* xf = pickedPart->transform();
cvf::Vec3d globalPickedPoint = firstNonNncHitItem->intersectionPoint();
if (localIntersectionPoint)
{
if (xf)
{
*localIntersectionPoint = globalPickedPoint.getTransformedPoint(xf->worldTransform().getInverted());
}
else
{
*localIntersectionPoint = globalPickedPoint;
}
}
if (firstPartFaceHit)
{
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(firstNonNncHitItem->detail());
if (detail)
{
*firstPartFaceHit = detail->faceIndex();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size_t* i, size_t* j, size_t* k)
{
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(m_reservoirView.p());
RimGeoMechView* geomView = dynamic_cast<RimGeoMechView*>(m_reservoirView.p());
if (eclipseView && eclipseView->eclipseCase())
{
eclipseView->eclipseCase()->reservoirData()->grid(gridIdx)->ijkFromCellIndex(cellIndex, i, j, k);
}
if (geomView && geomView->geoMechCase())
{
geomView->geoMechCase()->geoMechData()->femParts()->part(gridIdx)->structGrid()->ijkFromCellIndex(cellIndex, i, j, k);
}
}

View File

@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 <QObject>
class RiuViewer;
class RimView;
class QMouseEvent;
#include "cvfStructGrid.h"
#include "cafPdmPointer.h"
#include <QPointer>
namespace cvf {
class HitItemCollection;
class Part;
}
class RiuViewerCommands: public QObject
{
Q_OBJECT
public:
RiuViewerCommands(RiuViewer* ownerViewer);
~RiuViewerCommands();
void setOwnerView(RimView * owner);
void displayContextMenu(QMouseEvent* event);
void handlePickAction(int winPosX, int winPosY);
private slots:
void slotRangeFilterI();
void slotRangeFilterJ();
void slotRangeFilterK();
void slotHideFault();
private:
void ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size_t* i, size_t* j, size_t* k);
void createSliceRangeFilter(int ijOrk);
void extractIntersectionData(const cvf::HitItemCollection& hitItems, cvf::Vec3d* localIntersectionPoint, cvf::Part** firstPart, uint* firstPartFaceHit, cvf::Part** nncPart, uint* nncPartFaceHit);
size_t m_currentGridIdx;
size_t m_currentCellIndex;
cvf::StructGridInterface::FaceType m_currentFaceIndex;
caf::PdmPointer<RimView> m_reservoirView;
QPointer<RiuViewer> m_viewer;
};