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;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user