mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3249 Refactoring: RiuPickItemInfo into separate file
This commit is contained in:
parent
9ce814a3b2
commit
714ba1e605
@ -44,6 +44,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuTreeViewEventFilter.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuViewer.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuViewerToViewInterface.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuViewerCommands.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPickItemInfo.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuWellLogPlot.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuWellLogTrack.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotAnnotationTool.h
|
||||
@ -117,6 +118,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuToolTipMenu.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuTreeViewEventFilter.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuViewer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuViewerCommands.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPickItemInfo.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuWellLogPlot.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuWellLogTrack.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotAnnotationTool.cpp
|
||||
|
50
ApplicationCode/UserInterface/RiuPickItemInfo.cpp
Normal file
50
ApplicationCode/UserInterface/RiuPickItemInfo.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Equinor 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 "RiuPickItemInfo.h"
|
||||
|
||||
#include "cvfHitItem.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfTransform.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuPickItemInfo RiuPickItemInfo::extractPickItemInfo(const cvf::HitItem* hitItem)
|
||||
{
|
||||
RiuPickItemInfo pickInfo;
|
||||
|
||||
pickInfo.m_pickedPart = hitItem->part();
|
||||
pickInfo.m_globalPickedPoint = hitItem->intersectionPoint();
|
||||
if ( pickInfo.m_pickedPart ) pickInfo.m_sourceInfo = pickInfo.m_pickedPart->sourceInfo();
|
||||
|
||||
cvf::uint faceIdx = -1;
|
||||
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(hitItem->detail());
|
||||
if ( detail ) pickInfo.m_faceIdx = detail->faceIndex();
|
||||
|
||||
pickInfo.m_localPickedPoint = pickInfo.m_globalPickedPoint;
|
||||
const cvf::Transform* xf = pickInfo.m_pickedPart->transform();
|
||||
if ( xf )
|
||||
{
|
||||
pickInfo.m_localPickedPoint.transformPoint(xf->worldTransform().getInverted());
|
||||
}
|
||||
|
||||
return pickInfo;
|
||||
}
|
73
ApplicationCode/UserInterface/RiuPickItemInfo.h
Normal file
73
ApplicationCode/UserInterface/RiuPickItemInfo.h
Normal file
@ -0,0 +1,73 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Equinor 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 "cvfBase.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class Part;
|
||||
class Object;
|
||||
class HitItem;
|
||||
}
|
||||
|
||||
|
||||
class RiuPickItemInfo
|
||||
{
|
||||
public:
|
||||
RiuPickItemInfo()
|
||||
: m_distanceAlongRay(std::numeric_limits<double>::infinity())
|
||||
, m_pickedPart(nullptr)
|
||||
, m_globalPickedPoint (cvf::Vec3d::UNDEFINED)
|
||||
, m_localPickedPoint (cvf::Vec3d::UNDEFINED)
|
||||
, m_sourceInfo (nullptr)
|
||||
, m_faceIdx (-1)
|
||||
{}
|
||||
|
||||
explicit RiuPickItemInfo(const cvf::HitItem* hitItem)
|
||||
: m_pickedPart(nullptr)
|
||||
, m_globalPickedPoint (cvf::Vec3d::UNDEFINED)
|
||||
, m_localPickedPoint (cvf::Vec3d::UNDEFINED)
|
||||
, m_sourceInfo (nullptr)
|
||||
, m_faceIdx (-1)
|
||||
{
|
||||
*this = extractPickItemInfo(hitItem);
|
||||
}
|
||||
|
||||
const cvf::Part* pickedPart() const { return m_pickedPart;}
|
||||
cvf::Vec3d globalPickedPoint() const { return m_globalPickedPoint;}
|
||||
cvf::Vec3d localPickedPoint() const { return m_localPickedPoint;}
|
||||
const cvf::Object* sourceInfo() const { return m_sourceInfo;}
|
||||
cvf::uint faceIdx() const { return m_faceIdx;}
|
||||
double distanceAlongRay() const { return m_distanceAlongRay;}
|
||||
|
||||
static RiuPickItemInfo extractPickItemInfo(const cvf::HitItem* hitItem);
|
||||
|
||||
private:
|
||||
double m_distanceAlongRay;
|
||||
const cvf::Part* m_pickedPart;
|
||||
cvf::Vec3d m_globalPickedPoint;
|
||||
cvf::Vec3d m_localPickedPoint;
|
||||
const cvf::Object* m_sourceInfo;
|
||||
cvf::uint m_faceIdx;
|
||||
|
||||
};
|
||||
|
||||
|
@ -65,6 +65,7 @@
|
||||
#include "RiuResultTextBuilder.h"
|
||||
#include "RiuSelectionManager.h"
|
||||
#include "RiuViewer.h"
|
||||
#include "RiuPickItemInfo.h"
|
||||
|
||||
#include "RivFemPartGeometryGenerator.h"
|
||||
#include "RivFemPickSourceInfo.h"
|
||||
@ -898,47 +899,11 @@ void RiuViewerCommands::findCellAndGridIndex(const RivIntersectionBoxSourceInfo*
|
||||
}
|
||||
}
|
||||
|
||||
struct RiuPickItemInfo
|
||||
{
|
||||
RiuPickItemInfo()
|
||||
: pickedPart(nullptr)
|
||||
, globalPickedPoint (cvf::Vec3d::UNDEFINED)
|
||||
, localPickedPoint (cvf::Vec3d::UNDEFINED)
|
||||
, sourceInfo (nullptr)
|
||||
, faceIdx (-1)
|
||||
{}
|
||||
|
||||
const cvf::Part* pickedPart;
|
||||
cvf::Vec3d globalPickedPoint;
|
||||
cvf::Vec3d localPickedPoint;
|
||||
const cvf::Object* sourceInfo;
|
||||
cvf::uint faceIdx;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuPickItemInfo extractPickItemInfo(const cvf::HitItem* hitItem)
|
||||
{
|
||||
RiuPickItemInfo pickInfo;
|
||||
|
||||
pickInfo.pickedPart = hitItem->part();
|
||||
pickInfo.globalPickedPoint = hitItem->intersectionPoint();
|
||||
if (pickInfo.pickedPart) pickInfo.sourceInfo = pickInfo.pickedPart->sourceInfo();
|
||||
|
||||
cvf::uint faceIdx = -1;
|
||||
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>(hitItem->detail());
|
||||
if (detail) pickInfo.faceIdx = detail->faceIndex();
|
||||
|
||||
pickInfo.localPickedPoint = pickInfo.globalPickedPoint;
|
||||
const cvf::Transform* xf = pickInfo.pickedPart->transform();
|
||||
if ( xf )
|
||||
{
|
||||
pickInfo.localPickedPoint.transformPoint(xf->worldTransform().getInverted());
|
||||
}
|
||||
|
||||
return pickInfo;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// If there is an nnc-item within a depth-tolerance distance from the first hit-item
|
||||
@ -974,7 +939,7 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
|
||||
pickItemInfos.reserve(hitItems.count());
|
||||
for (size_t i = 0; i < hitItems.count(); i++)
|
||||
{
|
||||
pickItemInfos.emplace_back(extractPickItemInfo(hitItems.item(i)));
|
||||
pickItemInfos.emplace_back(RiuPickItemInfo(hitItems.item(i)));
|
||||
}
|
||||
|
||||
// Find first nnc part, and store as a separate thing if the nnc is first or close behind the first hit item.
|
||||
@ -982,22 +947,22 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
|
||||
|
||||
for (size_t i = 0; i < pickItemInfos.size(); i++)
|
||||
{
|
||||
cvf::Vec3d distFirstNonNNCToCandidate = firstOrFirstNonNncIntersectionPoint - pickItemInfos[i].globalPickedPoint;
|
||||
cvf::Vec3d distFirstNonNNCToCandidate = firstOrFirstNonNncIntersectionPoint - pickItemInfos[i].globalPickedPoint();
|
||||
|
||||
bool isNncpart = false;
|
||||
|
||||
// If hit item is nnc and is close to first (none-nnc) hit, store nncpart and face id
|
||||
|
||||
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(pickItemInfos[i].sourceInfo);
|
||||
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(pickItemInfos[i].sourceInfo());
|
||||
if ( rivSourceInfo && rivSourceInfo->hasNNCIndices() )
|
||||
{
|
||||
// This candidate is an NNC hit
|
||||
if ( distFirstNonNNCToCandidate.lengthSquared() < pickDepthThresholdSquared )
|
||||
{
|
||||
// it is first, or close to the first item
|
||||
if ( nncPart ) *nncPart = pickItemInfos[i].pickedPart;
|
||||
if ( nncPart ) *nncPart = pickItemInfos[i].pickedPart();
|
||||
|
||||
if ( nncPartFaceHit && pickItemInfos[i].faceIdx != -1 ) *nncPartFaceHit = pickItemInfos[i].faceIdx;
|
||||
if ( nncPartFaceHit && pickItemInfos[i].faceIdx() != -1 ) *nncPartFaceHit = pickItemInfos[i].faceIdx();
|
||||
|
||||
isNncpart = true;
|
||||
nncHitIndex = i;
|
||||
@ -1008,7 +973,7 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
|
||||
|
||||
if (!isNncpart && firstNonNncHitIndex == cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
firstOrFirstNonNncIntersectionPoint = pickItemInfos[i].globalPickedPoint;
|
||||
firstOrFirstNonNncIntersectionPoint = pickItemInfos[i].globalPickedPoint();
|
||||
firstNonNncHitIndex = i;
|
||||
}
|
||||
|
||||
@ -1023,20 +988,20 @@ void RiuViewerCommands::extractIntersectionData(const cvf::HitItemCollection& hi
|
||||
// if found a none-nnc part
|
||||
if (firstNonNncHitIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
if ( globalIntersectionPoint ) *globalIntersectionPoint = pickItemInfos[firstNonNncHitIndex].globalPickedPoint;
|
||||
if ( localIntersectionPoint ) *localIntersectionPoint = pickItemInfos[firstNonNncHitIndex].localPickedPoint;
|
||||
if ( globalIntersectionPoint ) *globalIntersectionPoint = pickItemInfos[firstNonNncHitIndex].globalPickedPoint();
|
||||
if ( localIntersectionPoint ) *localIntersectionPoint = pickItemInfos[firstNonNncHitIndex].localPickedPoint();
|
||||
|
||||
for (size_t i = firstNonNncHitIndex; i < pickItemInfos.size(); i++)
|
||||
{
|
||||
partAndTriangleIndexPairs->push_back(std::make_pair(pickItemInfos[i].pickedPart, pickItemInfos[i].faceIdx));
|
||||
partAndTriangleIndexPairs->push_back(std::make_pair(pickItemInfos[i].pickedPart(), pickItemInfos[i].faceIdx()));
|
||||
}
|
||||
}
|
||||
else // Only found an nnc-part
|
||||
{
|
||||
if (localIntersectionPoint && nncPart && *nncPart)
|
||||
{
|
||||
if (globalIntersectionPoint) *globalIntersectionPoint = pickItemInfos[nncHitIndex].globalPickedPoint;
|
||||
if ( localIntersectionPoint ) *localIntersectionPoint = pickItemInfos[nncHitIndex].localPickedPoint;
|
||||
if (globalIntersectionPoint) *globalIntersectionPoint = pickItemInfos[nncHitIndex].globalPickedPoint();
|
||||
if ( localIntersectionPoint ) *localIntersectionPoint = pickItemInfos[nncHitIndex].localPickedPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user