mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-08 07:03:25 -06:00
#1288 Moved copy of camera properties to RimViewManipulator
This commit is contained in:
parent
028f9458e9
commit
ecfd61ce68
@ -61,6 +61,7 @@ ${CEE_CURRENT_LIST_DIR}RimGeoMechResultDefinition.h
|
||||
${CEE_CURRENT_LIST_DIR}RimGeoMechCellColors.h
|
||||
${CEE_CURRENT_LIST_DIR}RimViewWindow.h
|
||||
${CEE_CURRENT_LIST_DIR}RimView.h
|
||||
${CEE_CURRENT_LIST_DIR}RimViewManipulator.h
|
||||
${CEE_CURRENT_LIST_DIR}RimCase.h
|
||||
${CEE_CURRENT_LIST_DIR}RimTreeViewStateSerializer.h
|
||||
${CEE_CURRENT_LIST_DIR}RimViewController.h
|
||||
@ -146,6 +147,7 @@ ${CEE_CURRENT_LIST_DIR}RimGeoMechResultDefinition.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimGeoMechCellColors.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimViewWindow.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimView.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimViewManipulator.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimCase.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimTreeViewStateSerializer.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimViewController.cpp
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "RimView.h"
|
||||
#include "RimViewController.h"
|
||||
#include "RimViewLinkerCollection.h"
|
||||
#include "RimViewManipulator.h"
|
||||
|
||||
#include "RiuViewer.h"
|
||||
|
||||
@ -537,110 +538,7 @@ void RimViewLinker::updateCamera(RimView* sourceView)
|
||||
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->mainGrid())
|
||||
{
|
||||
cvf::Vec3d offset = eclipseView->mainGrid()->displayModelOffset();
|
||||
offset.z() *= eclipseView->scaleZ();
|
||||
|
||||
sourceCamGlobalEye += offset;
|
||||
sourceCamGlobalViewRefPoint += offset;
|
||||
|
||||
cvf::Mat4d trans;
|
||||
trans.setTranslation(offset);
|
||||
sourceSceneBB.transform(trans);
|
||||
}
|
||||
|
||||
for (RimView* destinationView : viewsToUpdate)
|
||||
{
|
||||
if (!destinationView) continue;
|
||||
|
||||
destinationView->isPerspectiveView = sourceView->isPerspectiveView;
|
||||
|
||||
RiuViewer* destinationViewer = destinationView->viewer();
|
||||
if (destinationViewer)
|
||||
{
|
||||
destinationViewer->enableParallelProjection(!sourceView->isPerspectiveView);
|
||||
|
||||
// Destination bounding box in global coordinates including scaleZ
|
||||
cvf::BoundingBox destSceneBB = destinationViewer->currentScene()->boundingBox();
|
||||
|
||||
RimEclipseView* destEclipseView = dynamic_cast<RimEclipseView*>(destinationView);
|
||||
if (destEclipseView && destEclipseView->mainGrid())
|
||||
{
|
||||
cvf::Vec3d destOffset = destEclipseView->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->updateParallelProjectionSettings(sourceView->viewer());
|
||||
|
||||
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;
|
||||
RimViewManipulator::applySourceViewCameraOnDestinationViews(sourceView, viewsToUpdate);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -99,8 +99,6 @@ private:
|
||||
|
||||
void removeOverrides();
|
||||
|
||||
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
|
||||
|
||||
private:
|
||||
caf::PdmChildArrayField<RimViewController*> m_viewControllers;
|
||||
caf::PdmPtrField<RimView*> m_masterView;
|
||||
|
143
ApplicationCode/ProjectDataModel/RimViewManipulator.cpp
Normal file
143
ApplicationCode/ProjectDataModel/RimViewManipulator.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil 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 "RimViewManipulator.h"
|
||||
|
||||
#include "RigMainGrid.h"
|
||||
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimView.h"
|
||||
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfScene.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimViewManipulator::applySourceViewCameraOnDestinationViews(RimView* sourceView, std::vector<RimView*>& destinationViews)
|
||||
{
|
||||
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->mainGrid())
|
||||
{
|
||||
cvf::Vec3d offset = eclipseView->mainGrid()->displayModelOffset();
|
||||
offset.z() *= eclipseView->scaleZ();
|
||||
|
||||
sourceCamGlobalEye += offset;
|
||||
sourceCamGlobalViewRefPoint += offset;
|
||||
|
||||
cvf::Mat4d trans;
|
||||
trans.setTranslation(offset);
|
||||
sourceSceneBB.transform(trans);
|
||||
}
|
||||
|
||||
for (RimView* destinationView : destinationViews)
|
||||
{
|
||||
if (!destinationView) continue;
|
||||
|
||||
destinationView->isPerspectiveView = sourceView->isPerspectiveView;
|
||||
|
||||
RiuViewer* destinationViewer = destinationView->viewer();
|
||||
if (destinationViewer)
|
||||
{
|
||||
destinationViewer->enableParallelProjection(!sourceView->isPerspectiveView);
|
||||
|
||||
// Destination bounding box in global coordinates including scaleZ
|
||||
cvf::BoundingBox destSceneBB = destinationViewer->currentScene()->boundingBox();
|
||||
|
||||
RimEclipseView* destEclipseView = dynamic_cast<RimEclipseView*>(destinationView);
|
||||
if (destEclipseView && destEclipseView->mainGrid())
|
||||
{
|
||||
cvf::Vec3d destOffset = destEclipseView->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->updateParallelProjectionSettings(sourceView->viewer());
|
||||
|
||||
destinationViewer->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimViewManipulator::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;
|
||||
}
|
36
ApplicationCode/ProjectDataModel/RimViewManipulator.h
Normal file
36
ApplicationCode/ProjectDataModel/RimViewManipulator.h
Normal file
@ -0,0 +1,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil 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 <vector>
|
||||
|
||||
namespace cvf {
|
||||
class BoundingBox;
|
||||
}
|
||||
|
||||
class RimView;
|
||||
|
||||
class RimViewManipulator
|
||||
{
|
||||
public:
|
||||
static void applySourceViewCameraOnDestinationViews(RimView* sourceView, std::vector<RimView*>& destinationViews);
|
||||
|
||||
private:
|
||||
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
|
||||
};
|
Loading…
Reference in New Issue
Block a user