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();
|
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();
|
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;
|
const RimCellRangeFilterCollection* rangeFilterCollection() const;
|
||||||
void setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc);
|
void setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc);
|
||||||
|
|
||||||
void notifyCameraHasChanged();
|
|
||||||
|
|
||||||
caf::PdmField< std::vector<int> > windowGeometry;
|
caf::PdmField< std::vector<int> > windowGeometry;
|
||||||
|
|
||||||
|
|
||||||
@@ -176,8 +174,6 @@ protected:
|
|||||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||||
|
|
||||||
cvf::ref<cvf::UByteArray> m_currentReservoirCellVisibility;
|
cvf::ref<cvf::UByteArray> m_currentReservoirCellVisibility;
|
||||||
private:
|
|
||||||
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_previousGridModeMeshLinesWasFaults;
|
bool m_previousGridModeMeshLinesWasFaults;
|
||||||
|
|||||||
@@ -177,16 +177,15 @@ void RimViewLink::fieldChangedByUi(const caf::PdmFieldHandle* changedField, cons
|
|||||||
|
|
||||||
if (m_managedView)
|
if (m_managedView)
|
||||||
{
|
{
|
||||||
RimViewLinker* linkedViews = NULL;
|
RimViewLinker* viewLinker = ownerViewLinker();
|
||||||
this->firstAnchestorOrThisOfType(linkedViews);
|
|
||||||
|
|
||||||
if (syncCellResult())
|
if (syncCellResult())
|
||||||
{
|
{
|
||||||
linkedViews->updateCellResult();
|
viewLinker->updateCellResult();
|
||||||
}
|
}
|
||||||
if (syncCamera())
|
if (syncCamera())
|
||||||
{
|
{
|
||||||
m_managedView->notifyCameraHasChanged();
|
viewLinker->updateCamera(m_managedView);
|
||||||
}
|
}
|
||||||
|
|
||||||
name = RimViewLinker::displayNameForView(m_managedView);
|
name = RimViewLinker::displayNameForView(m_managedView);
|
||||||
|
|||||||
@@ -21,7 +21,10 @@
|
|||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
|
#include "RigCaseData.h"
|
||||||
|
|
||||||
#include "RimCase.h"
|
#include "RimCase.h"
|
||||||
|
|
||||||
#include "RimEclipseCellColors.h"
|
#include "RimEclipseCellColors.h"
|
||||||
#include "RimEclipseInputCase.h"
|
#include "RimEclipseInputCase.h"
|
||||||
#include "RimEclipseResultCase.h"
|
#include "RimEclipseResultCase.h"
|
||||||
@@ -39,6 +42,7 @@
|
|||||||
#include "RiuViewer.h"
|
#include "RiuViewer.h"
|
||||||
|
|
||||||
#include "cvfCamera.h"
|
#include "cvfCamera.h"
|
||||||
|
#include "cvfScene.h"
|
||||||
#include "cafFrameAnimationControl.h"
|
#include "cafFrameAnimationControl.h"
|
||||||
#include "cvfMatrix4.h"
|
#include "cvfMatrix4.h"
|
||||||
#include "cafPdmUiTreeOrdering.h"
|
#include "cafPdmUiTreeOrdering.h"
|
||||||
@@ -253,8 +257,7 @@ void RimViewLinker::applyAllOperations()
|
|||||||
updateRangeFilters();
|
updateRangeFilters();
|
||||||
updatePropertyFilters();
|
updatePropertyFilters();
|
||||||
updateScaleZ(m_mainView, m_mainView->scaleZ());
|
updateScaleZ(m_mainView, m_mainView->scaleZ());
|
||||||
|
updateCamera(m_mainView);
|
||||||
m_mainView->notifyCameraHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -542,3 +545,132 @@ RimViewLinker* RimViewLinker::viewLinkerForMainOrControlledView(RimView* view)
|
|||||||
return viewLinker;
|
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 "RimDefines.h"
|
||||||
|
|
||||||
|
#include "RivCellSetEnum.h"
|
||||||
|
|
||||||
#include "cafPdmChildArrayField.h"
|
#include "cafPdmChildArrayField.h"
|
||||||
#include "cafPdmField.h"
|
#include "cafPdmField.h"
|
||||||
#include "cafPdmObject.h"
|
#include "cafPdmObject.h"
|
||||||
#include "cafPdmPtrField.h"
|
#include "cafPdmPtrField.h"
|
||||||
#include "RivCellSetEnum.h"
|
|
||||||
|
namespace cvf
|
||||||
|
{
|
||||||
|
class BoundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
class RimViewLink;
|
class RimViewLink;
|
||||||
class RiuViewer;
|
class RiuViewer;
|
||||||
@@ -50,8 +56,9 @@ public:
|
|||||||
|
|
||||||
void applyAllOperations();
|
void applyAllOperations();
|
||||||
|
|
||||||
|
void updateCamera(RimView* sourceView);
|
||||||
void updateTimeStep(RimView* sourceView, int timeStep);
|
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 allViewsForCameraSync(RimView* source, std::vector<RimView*>& views);
|
||||||
|
|
||||||
void updateCellResult();
|
void updateCellResult();
|
||||||
@@ -84,6 +91,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmPtrField<RimView*> m_mainView;
|
caf::PdmPtrField<RimView*> m_mainView;
|
||||||
|
|||||||
@@ -483,9 +483,15 @@ void RiuViewer::updateNavigationPolicy()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuViewer::navigationPolicyUpdate()
|
void RiuViewer::navigationPolicyUpdate()
|
||||||
{
|
{
|
||||||
|
update();
|
||||||
|
|
||||||
if (m_reservoirView)
|
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