#1905 Perforation Intervals : Picking the well path pipe does not work at perforations

Forward all parts intersected to 3d viewer event handler
This commit is contained in:
Magne Sjaastad 2018-01-12 07:54:37 +01:00
parent b70d39cc6c
commit f027027618
7 changed files with 162 additions and 97 deletions

View File

@ -29,25 +29,24 @@ namespace cvf {
class Part; class Part;
} }
class RicViewerEventInterface
class RicViewerEventObject
{ {
public: public:
virtual bool handleEvent(cvf::Object* eventObject) = 0; RicViewerEventObject(cvf::Vec3d globalIntersectionPoint, const std::vector<std::pair<const cvf::Part*, cvf::uint>>& partAndTriangleIndexPairs)
}; : m_globalIntersectionPoint(globalIntersectionPoint),
m_partAndTriangleIndexPairs(partAndTriangleIndexPairs)
class RicViewerEventObject : public cvf::Object
{
public:
RicViewerEventObject(cvf::Vec3d globalIntersectionPoint, cvf::Part* firstHitPart, cvf::uint firstPartTriangleIndex)
: globalIntersectionPoint(globalIntersectionPoint),
firstHitPart(firstHitPart),
firstPartTriangleIndex(firstPartTriangleIndex)
{ {
} }
cvf::Vec3d globalIntersectionPoint; cvf::Vec3d m_globalIntersectionPoint;
cvf::Part* firstHitPart; std::vector<std::pair<const cvf::Part*, cvf::uint>> m_partAndTriangleIndexPairs;
cvf::uint firstPartTriangleIndex; };
class RicViewerEventInterface
{
public:
virtual bool handleEvent(const RicViewerEventObject& eventObject) = 0;
}; };

View File

@ -37,15 +37,13 @@ RicIntersectionViewerEventHandler* RicIntersectionViewerEventHandler::instance()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicIntersectionViewerEventHandler::handleEvent(cvf::Object* eventObject) bool RicIntersectionViewerEventHandler::handleEvent(const RicViewerEventObject& eventObject)
{ {
std::vector<RimIntersection*> selection; std::vector<RimIntersection*> selection;
caf::SelectionManager::instance()->objectsByType(&selection); caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() == 1) if (selection.size() == 1)
{ {
RicViewerEventObject* polylineUiEvent = dynamic_cast<RicViewerEventObject*>(eventObject);
if (polylineUiEvent)
{ {
RimIntersection* intersection = selection[0]; RimIntersection* intersection = selection[0];
@ -54,7 +52,7 @@ bool RicIntersectionViewerEventHandler::handleEvent(cvf::Object* eventObject)
CVF_ASSERT(rimView); CVF_ASSERT(rimView);
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform(); cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(polylineUiEvent->globalIntersectionPoint); cvf::Vec3d domainCoord = transForm->transformToDomainCoord(eventObject.m_globalIntersectionPoint);
if (intersection->inputPolyLineFromViewerEnabled()) if (intersection->inputPolyLineFromViewerEnabled())
{ {

View File

@ -29,6 +29,6 @@ public:
static RicIntersectionViewerEventHandler* instance(); static RicIntersectionViewerEventHandler* instance();
protected: protected:
virtual bool handleEvent(cvf::Object* eventObject) override; virtual bool handleEvent(const RicViewerEventObject& eventObject) override;
}; };

View File

@ -26,6 +26,7 @@
#include "RiuMainWindow.h" #include "RiuMainWindow.h"
#include "RivObjectSourceInfo.h"
#include "RivWellPathSourceInfo.h" #include "RivWellPathSourceInfo.h"
#include "cafDisplayCoordTransform.h" #include "cafDisplayCoordTransform.h"
@ -46,28 +47,46 @@ RicWellPathViewerEventHandler* RicWellPathViewerEventHandler::instance()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicWellPathViewerEventHandler::handleEvent(cvf::Object* eventObject) bool RicWellPathViewerEventHandler::handleEvent(const RicViewerEventObject& eventObject)
{ {
RicViewerEventObject* uiEvent = dynamic_cast<RicViewerEventObject*>(eventObject); if (eventObject.m_partAndTriangleIndexPairs.empty()) return false;
if (!uiEvent) return false;
if (uiEvent->firstHitPart && uiEvent->firstHitPart->sourceInfo()) const caf::PdmObject* objectToSelect = nullptr;
cvf::uint wellPathTriangleIndex = cvf::UNDEFINED_UINT;
const RivWellPathSourceInfo* wellPathSourceInfo = nullptr;
for (const auto & partAndTriangleIndexPair : eventObject.m_partAndTriangleIndexPairs)
{ {
const RivWellPathSourceInfo* wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(uiEvent->firstHitPart->sourceInfo()); const cvf::Part* part = partAndTriangleIndexPair.first;
const RivObjectSourceInfo* sourceInfo = dynamic_cast<const RivObjectSourceInfo*>(part->sourceInfo());
if (!objectToSelect && sourceInfo)
{
objectToSelect = sourceInfo->object();
}
if (part && part->sourceInfo() && dynamic_cast<const RivWellPathSourceInfo*>(part->sourceInfo()))
{
wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(part->sourceInfo());
wellPathTriangleIndex = partAndTriangleIndexPair.second;
break;
}
}
if (wellPathSourceInfo) if (wellPathSourceInfo)
{ {
Rim3dView* rimView = RiaApplication::instance()->activeReservoirView(); Rim3dView* rimView = RiaApplication::instance()->activeReservoirView();
if (!rimView) return false; if (!rimView) return false;
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform(); cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(uiEvent->globalIntersectionPoint); cvf::Vec3d domainCoord = transForm->transformToDomainCoord(eventObject.m_globalIntersectionPoint);
double measuredDepth = wellPathSourceInfo->measuredDepth(uiEvent->firstPartTriangleIndex, domainCoord); double measuredDepth = wellPathSourceInfo->measuredDepth(wellPathTriangleIndex, domainCoord);
// NOTE: This computation was used to find the location for a fracture when clicking on a well path // NOTE: This computation was used to find the location for a fracture when clicking on a well path
// It turned out that the computation was a bit inaccurate // It turned out that the computation was a bit inaccurate
// Consider to use code in RigSimulationWellCoordsAndMD instead // Consider to use code in RigSimulationWellCoordsAndMD instead
cvf::Vec3d trueVerticalDepth = wellPathSourceInfo->trueVerticalDepth(uiEvent->firstPartTriangleIndex, domainCoord); cvf::Vec3d trueVerticalDepth = wellPathSourceInfo->trueVerticalDepth(wellPathTriangleIndex, domainCoord);
QString wellPathText; QString wellPathText;
wellPathText += QString("Well path name : %1\n").arg(wellPathSourceInfo->wellPath()->name()); wellPathText += QString("Well path name : %1\n").arg(wellPathSourceInfo->wellPath()->name());
@ -79,11 +98,17 @@ bool RicWellPathViewerEventHandler::handleEvent(cvf::Object* eventObject)
RiuMainWindow::instance()->setResultInfo(wellPathText); RiuMainWindow::instance()->setResultInfo(wellPathText);
if (objectToSelect)
{
RiuMainWindow::instance()->selectAsCurrentItem(objectToSelect);
}
else
{
RiuMainWindow::instance()->selectAsCurrentItem(wellPathSourceInfo->wellPath()); RiuMainWindow::instance()->selectAsCurrentItem(wellPathSourceInfo->wellPath());
}
return true; return true;
} }
}
return false; return false;
} }

View File

@ -30,6 +30,6 @@ class RicWellPathViewerEventHandler : public RicViewerEventInterface
public: public:
static RicWellPathViewerEventHandler* instance(); static RicWellPathViewerEventHandler* instance();
virtual bool handleEvent(cvf::Object* eventObject); virtual bool handleEvent(const RicViewerEventObject& eventObject);
}; };

View File

@ -148,15 +148,15 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
cvf::Vec3d localIntersectionPoint(cvf::Vec3d::ZERO); cvf::Vec3d localIntersectionPoint(cvf::Vec3d::ZERO);
cvf::Vec3d globalIntersectionPoint(cvf::Vec3d::ZERO); cvf::Vec3d globalIntersectionPoint(cvf::Vec3d::ZERO);
cvf::Part* firstHitPart = nullptr; const cvf::Part* firstHitPart = nullptr;
cvf::Part* nncFirstHitPart = nullptr; const cvf::Part* nncFirstHitPart = nullptr;
m_currentPickPositionInDomainCoords = cvf::Vec3d::UNDEFINED; m_currentPickPositionInDomainCoords = cvf::Vec3d::UNDEFINED;
cvf::HitItemCollection hitItems; cvf::HitItemCollection hitItems;
if (m_viewer->rayPick(winPosX, winPosY, &hitItems)) if (m_viewer->rayPick(winPosX, winPosY, &hitItems))
{ {
extractIntersectionData(hitItems, &localIntersectionPoint, &globalIntersectionPoint, &firstHitPart, &firstPartTriangleIndex, &nncFirstHitPart, NULL); extractIntersectionData(hitItems, &localIntersectionPoint, &globalIntersectionPoint, &firstHitPart, &firstPartTriangleIndex, &nncFirstHitPart, nullptr);
cvf::Vec3d displayModelOffset = cvf::Vec3d::ZERO; cvf::Vec3d displayModelOffset = cvf::Vec3d::ZERO;
@ -426,25 +426,32 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
// Extract all the above information from the pick // Extract all the above information from the pick
{ {
cvf::Part* firstHitPart = nullptr; const cvf::Part* firstHitPart = nullptr;
uint firstPartTriangleIndex = cvf::UNDEFINED_UINT; uint firstPartTriangleIndex = cvf::UNDEFINED_UINT;
cvf::Part* firstNncHitPart = nullptr; const cvf::Part* firstNncHitPart = nullptr;
uint nncPartTriangleIndex = cvf::UNDEFINED_UINT; uint nncPartTriangleIndex = cvf::UNDEFINED_UINT;
cvf::HitItemCollection hitItems; cvf::HitItemCollection hitItems;
if (m_viewer->rayPick(winPosX, winPosY, &hitItems)) if (m_viewer->rayPick(winPosX, winPosY, &hitItems))
{ {
extractIntersectionData(hitItems, &localIntersectionPoint, &globalIntersectionPoint, &firstHitPart, &firstPartTriangleIndex, &firstNncHitPart, &nncPartTriangleIndex); std::vector<std::pair<const cvf::Part*, cvf::uint>> partAndTriangleIndexPairs;
extractIntersectionData(hitItems, &localIntersectionPoint, &globalIntersectionPoint, &partAndTriangleIndexPairs, &firstNncHitPart, &nncPartTriangleIndex);
cvf::ref<RicViewerEventObject> eventObj = new RicViewerEventObject(globalIntersectionPoint, firstHitPart, firstPartTriangleIndex); if (!partAndTriangleIndexPairs.empty())
{
RicViewerEventObject viewerEventObject(globalIntersectionPoint, partAndTriangleIndexPairs);
for (size_t i = 0; i < m_viewerEventHandlers.size(); i++) for (size_t i = 0; i < m_viewerEventHandlers.size(); i++)
{ {
if (m_viewerEventHandlers[i]->handleEvent(eventObj.p())) if (m_viewerEventHandlers[i]->handleEvent(viewerEventObject))
{ {
return; return;
} }
} }
firstHitPart = partAndTriangleIndexPairs.front().first;
firstPartTriangleIndex = partAndTriangleIndexPairs.front().second;
}
} }
if (firstHitPart && firstHitPart->sourceInfo()) if (firstHitPart && firstHitPart->sourceInfo())
@ -632,8 +639,35 @@ void RiuViewerCommands::findCellAndGridIndex(const RivIntersectionBoxSourceInfo*
void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hitItems, void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hitItems,
cvf::Vec3d* localIntersectionPoint, cvf::Vec3d* localIntersectionPoint,
cvf::Vec3d* globalIntersectionPoint, cvf::Vec3d* globalIntersectionPoint,
cvf::Part** firstPart, uint* firstPartFaceHit, const cvf::Part** firstPart, uint* firstPartFaceHit,
cvf::Part** nncPart, uint* nncPartFaceHit) const cvf::Part** nncPart, uint* nncPartFaceHit)
{
std::vector<std::pair<const cvf::Part*, cvf::uint>> partAndTriangleIndexPairs;
extractIntersectionData(hitItems, localIntersectionPoint, globalIntersectionPoint,
&partAndTriangleIndexPairs, nncPart, nncPartFaceHit);
if (!partAndTriangleIndexPairs.empty())
{
if (firstPart)
{
*firstPart = partAndTriangleIndexPairs.front().first;
}
if (firstPartFaceHit)
{
*firstPartFaceHit = partAndTriangleIndexPairs.front().second;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hitItems,
cvf::Vec3d* localIntersectionPoint,
cvf::Vec3d*globalIntersectionPoint,
std::vector<std::pair<const cvf::Part*, cvf::uint>>* partAndTriangleIndexPairs,
const cvf::Part** nncPart, uint* nncPartFaceHit)
{ {
CVF_ASSERT(hitItems.count() > 0); CVF_ASSERT(hitItems.count() > 0);
@ -649,7 +683,7 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
} }
} }
const cvf::HitItem* firstNonNncHitItem = nullptr; size_t firstNonNncPartIndex = cvf::UNDEFINED_SIZE_T;
cvf::Vec3d firstItemIntersectionPoint = hitItems.item(0)->intersectionPoint(); cvf::Vec3d firstItemIntersectionPoint = hitItems.item(0)->intersectionPoint();
// Check if we have a close hit item with NNC data // Check if we have a close hit item with NNC data
@ -684,26 +718,27 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
} }
} }
if (!isNncpart && !firstNonNncHitItem) if (!isNncpart && firstNonNncPartIndex == cvf::UNDEFINED_SIZE_T)
{ {
firstNonNncHitItem = hitItemCandidate; firstItemIntersectionPoint = hitItemCandidate->intersectionPoint();
firstItemIntersectionPoint = firstNonNncHitItem->intersectionPoint(); firstNonNncPartIndex = i;
} }
if (firstNonNncHitItem && *nncPart) if (firstNonNncPartIndex != cvf::UNDEFINED_SIZE_T && *nncPart)
{ {
break; break;
} }
} }
if (firstNonNncHitItem) if (firstNonNncPartIndex != cvf::UNDEFINED_SIZE_T)
{ {
{
const cvf::HitItem* firstNonNncHitItem = hitItems.item(firstNonNncPartIndex);
const cvf::Part* pickedPart = firstNonNncHitItem->part(); const cvf::Part* pickedPart = firstNonNncHitItem->part();
CVF_ASSERT(pickedPart); CVF_ASSERT(pickedPart);
*firstPart = const_cast<cvf::Part*>(pickedPart);
const cvf::Transform* xf = pickedPart->transform(); const cvf::Transform* xf = pickedPart->transform();
cvf::Vec3d globalPickedPoint = firstNonNncHitItem->intersectionPoint(); const cvf::Vec3d& globalPickedPoint = firstNonNncHitItem->intersectionPoint();
if (globalIntersectionPoint) if (globalIntersectionPoint)
{ {
@ -721,21 +756,28 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
*localIntersectionPoint = globalPickedPoint; *localIntersectionPoint = globalPickedPoint;
} }
} }
}
if (firstPartFaceHit) for (size_t i = firstNonNncPartIndex; i < hitItems.count(); i++)
{ {
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(firstNonNncHitItem->detail()); const cvf::HitItem* hitItem = hitItems.item(i);
const cvf::Part* pickedPart = hitItem->part();
cvf::uint faceIndex = cvf::UNDEFINED_UINT;
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(hitItem->detail());
if (detail) if (detail)
{ {
*firstPartFaceHit = detail->faceIndex(); faceIndex = detail->faceIndex();
} }
partAndTriangleIndexPairs->push_back(std::make_pair(pickedPart, faceIndex));
} }
} }
else else
{ {
if (localIntersectionPoint && nncPart && *nncPart) if (localIntersectionPoint && nncPart && *nncPart)
{ {
cvf::Vec3d globalPickedPoint = firstItemIntersectionPoint; const cvf::Vec3d& globalPickedPoint = firstItemIntersectionPoint;
if (globalIntersectionPoint) if (globalIntersectionPoint)
{ {

View File

@ -64,7 +64,8 @@ private:
void findCellAndGridIndex(const RivIntersectionBoxSourceInfo* intersectionBoxSourceInfo, cvf::uint firstPartTriangleIndex, size_t* cellIndex, size_t* gridIndex); void findCellAndGridIndex(const RivIntersectionBoxSourceInfo* intersectionBoxSourceInfo, cvf::uint firstPartTriangleIndex, size_t* cellIndex, size_t* gridIndex);
void ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size_t* i, size_t* j, size_t* k); void ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size_t* i, size_t* j, size_t* k);
void extractIntersectionData(const cvf::HitItemCollection& hitItems, cvf::Vec3d* localIntersectionPoint, cvf::Vec3d* globalIntersectionPoint, cvf::Part** firstPart, uint* firstPartFaceHit, cvf::Part** nncPart, uint* nncPartFaceHit); void extractIntersectionData(const cvf::HitItemCollection& hitItems, cvf::Vec3d* localIntersectionPoint, cvf::Vec3d* globalIntersectionPoint, const cvf::Part** firstPart, uint* firstPartFaceHit, const cvf::Part** nncPart, uint* nncPartFaceHit);
void extractIntersectionData(const cvf::HitItemCollection& hitItems, cvf::Vec3d* localIntersectionPoint, cvf::Vec3d* globalIntersectionPoint, std::vector<std::pair<const cvf::Part*, cvf::uint>>* partAndTriangleIndexPairs, const cvf::Part** nncPart, uint* nncPartFaceHit);
bool handleOverlayItemPicking(int winPosX, int winPosY); bool handleOverlayItemPicking(int winPosX, int winPosY);