mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Moved camera update from RimView to RimViewLinker
This commit is contained in:
@@ -572,114 +572,6 @@ void RimView::setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc
|
||||
this->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimView::notifyCameraHasChanged()
|
||||
{
|
||||
if (!this->viewer()) return;
|
||||
|
||||
std::vector<RimView*> viewsToUpdate;
|
||||
|
||||
viewsToUpdate.push_back(this);
|
||||
|
||||
RimProject* proj = NULL;
|
||||
this->firstAnchestorOrThisOfType(proj);
|
||||
RimViewLinker* viewLinker = proj->findViewLinkerFromView(this);
|
||||
if (viewLinker)
|
||||
{
|
||||
RimViewLink* viewLink = viewLinker->viewLinkForView(this);
|
||||
|
||||
if (this == viewLinker->mainView() || (viewLink && viewLink->isActive() && viewLink->syncCamera()))
|
||||
{
|
||||
viewLinker->allViewsForCameraSync(this, viewsToUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
cvf::Vec3d sourceCamUp;
|
||||
cvf::Vec3d sourceCamEye;
|
||||
cvf::Vec3d sourceCamViewRefPoint;
|
||||
this->viewer()->mainCamera()->toLookAt(&sourceCamEye, &sourceCamViewRefPoint, &sourceCamUp);
|
||||
|
||||
cvf::Vec3d sourceCamGlobalEye = sourceCamEye;
|
||||
cvf::Vec3d sourceCamGlobalViewRefPoint = sourceCamViewRefPoint;
|
||||
|
||||
// Source bounding box in global coordinates including scaleZ
|
||||
cvf::BoundingBox sourceSceneBB = this->viewer()->currentScene()->boundingBox();
|
||||
|
||||
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(this);
|
||||
if (eclipseView
|
||||
&& eclipseView->eclipseCase()
|
||||
&& eclipseView->eclipseCase()->reservoirData()
|
||||
&& eclipseView->eclipseCase()->reservoirData()->mainGrid())
|
||||
{
|
||||
cvf::Vec3d offset = eclipseView->eclipseCase()->reservoirData()->mainGrid()->displayModelOffset();
|
||||
offset.z() *= eclipseView->scaleZ();
|
||||
|
||||
sourceCamGlobalEye += offset;
|
||||
sourceCamGlobalViewRefPoint += offset;
|
||||
|
||||
cvf::Mat4d trans;
|
||||
trans.setTranslation(offset);
|
||||
sourceSceneBB.transform(trans);
|
||||
}
|
||||
|
||||
// Propagate view matrix to all relevant views
|
||||
|
||||
const cvf::Mat4d mat = this->viewer()->mainCamera()->viewMatrix();
|
||||
for (size_t i = 0; i < viewsToUpdate.size(); i++)
|
||||
{
|
||||
if (viewsToUpdate[i] && viewsToUpdate[i]->viewer())
|
||||
{
|
||||
RiuViewer* destinationViewer = viewsToUpdate[i]->viewer();
|
||||
|
||||
// Destination bounding box in global coordinates including scaleZ
|
||||
cvf::BoundingBox destSceneBB = destinationViewer->currentScene()->boundingBox();
|
||||
|
||||
RimEclipseView* destEclipseView = dynamic_cast<RimEclipseView*>(viewsToUpdate[i]);
|
||||
if (destEclipseView
|
||||
&& destEclipseView->eclipseCase()
|
||||
&& destEclipseView->eclipseCase()->reservoirData()
|
||||
&& destEclipseView->eclipseCase()->reservoirData()->mainGrid())
|
||||
{
|
||||
cvf::Vec3d destOffset = destEclipseView->eclipseCase()->reservoirData()->mainGrid()->displayModelOffset();
|
||||
destOffset.z() *= destEclipseView->scaleZ();
|
||||
|
||||
cvf::Vec3d destinationCamEye = sourceCamGlobalEye - destOffset;
|
||||
cvf::Vec3d destinationCamViewRefPoint = sourceCamGlobalViewRefPoint - destOffset;
|
||||
|
||||
cvf::Mat4d trans;
|
||||
trans.setTranslation(destOffset);
|
||||
destSceneBB.transform(trans);
|
||||
|
||||
if (isBoundingBoxesOverlappingOrClose(sourceSceneBB, destSceneBB))
|
||||
{
|
||||
destinationViewer->mainCamera()->setFromLookAt(destinationCamEye, destinationCamViewRefPoint, sourceCamUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback using values from source camera
|
||||
destinationViewer->mainCamera()->setFromLookAt(sourceCamEye, sourceCamViewRefPoint, sourceCamUp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isBoundingBoxesOverlappingOrClose(sourceSceneBB, destSceneBB))
|
||||
{
|
||||
destinationViewer->mainCamera()->setFromLookAt(sourceCamGlobalEye, sourceCamGlobalViewRefPoint, sourceCamUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback using values from source camera
|
||||
destinationViewer->mainCamera()->setFromLookAt(sourceCamEye, sourceCamViewRefPoint, sourceCamUp);
|
||||
}
|
||||
}
|
||||
|
||||
destinationViewer->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -690,31 +582,6 @@ void RimView::setScaleZAndUpdate(double scaleZ)
|
||||
this->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimView::isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB)
|
||||
{
|
||||
if (!sourceBB.isValid() || !destBB.isValid()) return false;
|
||||
|
||||
if (sourceBB.intersects(destBB)) return true;
|
||||
|
||||
double largestExtent = sourceBB.extent().length();
|
||||
if (destBB.extent().length() > largestExtent)
|
||||
{
|
||||
largestExtent = destBB.extent().length();
|
||||
}
|
||||
|
||||
double centerDist = (sourceBB.center() - destBB.center()).length();
|
||||
if (centerDist < largestExtent * 5)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -79,8 +79,6 @@ public:
|
||||
const RimCellRangeFilterCollection* rangeFilterCollection() const;
|
||||
void setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc);
|
||||
|
||||
void notifyCameraHasChanged();
|
||||
|
||||
caf::PdmField< std::vector<int> > windowGeometry;
|
||||
|
||||
|
||||
@@ -176,8 +174,6 @@ protected:
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||
|
||||
cvf::ref<cvf::UByteArray> m_currentReservoirCellVisibility;
|
||||
private:
|
||||
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
|
||||
|
||||
private:
|
||||
bool m_previousGridModeMeshLinesWasFaults;
|
||||
|
||||
@@ -177,16 +177,15 @@ void RimViewLink::fieldChangedByUi(const caf::PdmFieldHandle* changedField, cons
|
||||
|
||||
if (m_managedView)
|
||||
{
|
||||
RimViewLinker* linkedViews = NULL;
|
||||
this->firstAnchestorOrThisOfType(linkedViews);
|
||||
RimViewLinker* viewLinker = ownerViewLinker();
|
||||
|
||||
if (syncCellResult())
|
||||
{
|
||||
linkedViews->updateCellResult();
|
||||
viewLinker->updateCellResult();
|
||||
}
|
||||
if (syncCamera())
|
||||
{
|
||||
m_managedView->notifyCameraHasChanged();
|
||||
viewLinker->updateCamera(m_managedView);
|
||||
}
|
||||
|
||||
name = RimViewLinker::displayNameForView(m_managedView);
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RigCaseData.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimEclipseInputCase.h"
|
||||
#include "RimEclipseResultCase.h"
|
||||
@@ -39,6 +42,7 @@
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfScene.h"
|
||||
#include "cafFrameAnimationControl.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
@@ -253,8 +257,7 @@ void RimViewLinker::applyAllOperations()
|
||||
updateRangeFilters();
|
||||
updatePropertyFilters();
|
||||
updateScaleZ(m_mainView, m_mainView->scaleZ());
|
||||
|
||||
m_mainView->notifyCameraHasChanged();
|
||||
updateCamera(m_mainView);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -542,3 +545,132 @@ RimViewLinker* RimViewLinker::viewLinkerForMainOrControlledView(RimView* view)
|
||||
return viewLinker;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimViewLinker::updateCamera(RimView* sourceView)
|
||||
{
|
||||
if (!sourceView->viewer()) return;
|
||||
|
||||
if (!isActive()) return;
|
||||
|
||||
RimViewLink* viewLink = RimViewLinker::viewLinkForView(sourceView);
|
||||
if (viewLink)
|
||||
{
|
||||
if ((!viewLink->isActive() || !viewLink->syncCamera()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<RimView*> viewsToUpdate;
|
||||
allViewsForCameraSync(sourceView, viewsToUpdate);
|
||||
|
||||
cvf::Vec3d sourceCamUp;
|
||||
cvf::Vec3d sourceCamEye;
|
||||
cvf::Vec3d sourceCamViewRefPoint;
|
||||
sourceView->viewer()->mainCamera()->toLookAt(&sourceCamEye, &sourceCamViewRefPoint, &sourceCamUp);
|
||||
|
||||
cvf::Vec3d sourceCamGlobalEye = sourceCamEye;
|
||||
cvf::Vec3d sourceCamGlobalViewRefPoint = sourceCamViewRefPoint;
|
||||
|
||||
// Source bounding box in global coordinates including scaleZ
|
||||
cvf::BoundingBox sourceSceneBB = sourceView->viewer()->currentScene()->boundingBox();
|
||||
|
||||
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(sourceView);
|
||||
if (eclipseView
|
||||
&& eclipseView->eclipseCase()
|
||||
&& eclipseView->eclipseCase()->reservoirData()
|
||||
&& eclipseView->eclipseCase()->reservoirData()->mainGrid())
|
||||
{
|
||||
cvf::Vec3d offset = eclipseView->eclipseCase()->reservoirData()->mainGrid()->displayModelOffset();
|
||||
offset.z() *= eclipseView->scaleZ();
|
||||
|
||||
sourceCamGlobalEye += offset;
|
||||
sourceCamGlobalViewRefPoint += offset;
|
||||
|
||||
cvf::Mat4d trans;
|
||||
trans.setTranslation(offset);
|
||||
sourceSceneBB.transform(trans);
|
||||
}
|
||||
|
||||
// Propagate view matrix to all relevant views
|
||||
|
||||
const cvf::Mat4d mat = sourceView->viewer()->mainCamera()->viewMatrix();
|
||||
for (size_t i = 0; i < viewsToUpdate.size(); i++)
|
||||
{
|
||||
if (viewsToUpdate[i] && viewsToUpdate[i]->viewer())
|
||||
{
|
||||
RiuViewer* destinationViewer = viewsToUpdate[i]->viewer();
|
||||
|
||||
// Destination bounding box in global coordinates including scaleZ
|
||||
cvf::BoundingBox destSceneBB = destinationViewer->currentScene()->boundingBox();
|
||||
|
||||
RimEclipseView* destEclipseView = dynamic_cast<RimEclipseView*>(viewsToUpdate[i]);
|
||||
if (destEclipseView
|
||||
&& destEclipseView->eclipseCase()
|
||||
&& destEclipseView->eclipseCase()->reservoirData()
|
||||
&& destEclipseView->eclipseCase()->reservoirData()->mainGrid())
|
||||
{
|
||||
cvf::Vec3d destOffset = destEclipseView->eclipseCase()->reservoirData()->mainGrid()->displayModelOffset();
|
||||
destOffset.z() *= destEclipseView->scaleZ();
|
||||
|
||||
cvf::Vec3d destinationCamEye = sourceCamGlobalEye - destOffset;
|
||||
cvf::Vec3d destinationCamViewRefPoint = sourceCamGlobalViewRefPoint - destOffset;
|
||||
|
||||
cvf::Mat4d trans;
|
||||
trans.setTranslation(destOffset);
|
||||
destSceneBB.transform(trans);
|
||||
|
||||
if (isBoundingBoxesOverlappingOrClose(sourceSceneBB, destSceneBB))
|
||||
{
|
||||
destinationViewer->mainCamera()->setFromLookAt(destinationCamEye, destinationCamViewRefPoint, sourceCamUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback using values from source camera
|
||||
destinationViewer->mainCamera()->setFromLookAt(sourceCamEye, sourceCamViewRefPoint, sourceCamUp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isBoundingBoxesOverlappingOrClose(sourceSceneBB, destSceneBB))
|
||||
{
|
||||
destinationViewer->mainCamera()->setFromLookAt(sourceCamGlobalEye, sourceCamGlobalViewRefPoint, sourceCamUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback using values from source camera
|
||||
destinationViewer->mainCamera()->setFromLookAt(sourceCamEye, sourceCamViewRefPoint, sourceCamUp);
|
||||
}
|
||||
}
|
||||
|
||||
destinationViewer->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimViewLinker::isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB)
|
||||
{
|
||||
if (!sourceBB.isValid() || !destBB.isValid()) return false;
|
||||
|
||||
if (sourceBB.intersects(destBB)) return true;
|
||||
|
||||
double largestExtent = sourceBB.extent().length();
|
||||
if (destBB.extent().length() > largestExtent)
|
||||
{
|
||||
largestExtent = destBB.extent().length();
|
||||
}
|
||||
|
||||
double centerDist = (sourceBB.center() - destBB.center()).length();
|
||||
if (centerDist < largestExtent * 5)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,17 @@
|
||||
|
||||
#include "RimDefines.h"
|
||||
|
||||
#include "RivCellSetEnum.h"
|
||||
|
||||
#include "cafPdmChildArrayField.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmPtrField.h"
|
||||
#include "RivCellSetEnum.h"
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class BoundingBox;
|
||||
}
|
||||
|
||||
class RimViewLink;
|
||||
class RiuViewer;
|
||||
@@ -50,8 +56,9 @@ public:
|
||||
|
||||
void applyAllOperations();
|
||||
|
||||
void updateCamera(RimView* sourceView);
|
||||
void updateTimeStep(RimView* sourceView, int timeStep);
|
||||
void updateScaleZ(RimView* source, double scaleZ);
|
||||
void updateScaleZ(RimView* sourceView, double scaleZ);
|
||||
void allViewsForCameraSync(RimView* source, std::vector<RimView*>& views);
|
||||
|
||||
void updateCellResult();
|
||||
@@ -84,6 +91,7 @@ protected:
|
||||
|
||||
private:
|
||||
bool isActive();
|
||||
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
|
||||
|
||||
private:
|
||||
caf::PdmPtrField<RimView*> m_mainView;
|
||||
|
||||
@@ -483,9 +483,15 @@ void RiuViewer::updateNavigationPolicy()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuViewer::navigationPolicyUpdate()
|
||||
{
|
||||
update();
|
||||
|
||||
if (m_reservoirView)
|
||||
{
|
||||
m_reservoirView->notifyCameraHasChanged();
|
||||
RimViewLinker* viewLinker = RimViewLinker::viewLinkerForMainOrControlledView(m_reservoirView);
|
||||
if (viewLinker)
|
||||
{
|
||||
viewLinker->updateCamera(m_reservoirView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user