Python: Add support for camera manipulation in a view

This commit is contained in:
Magne Sjaastad
2025-02-15 12:12:18 +01:00
parent 3e23b967c3
commit 4990d1a634
3 changed files with 269 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimcEclipseStatisticsCase.h ${CMAKE_CURRENT_LIST_DIR}/RimcEclipseStatisticsCase.h
${CMAKE_CURRENT_LIST_DIR}/RimcIdenticalGridCaseGroup.h ${CMAKE_CURRENT_LIST_DIR}/RimcIdenticalGridCaseGroup.h
${CMAKE_CURRENT_LIST_DIR}/RimcPressureTable.h ${CMAKE_CURRENT_LIST_DIR}/RimcPressureTable.h
${CMAKE_CURRENT_LIST_DIR}/Rimc3dView.h
) )
set(SOURCE_GROUP_SOURCE_FILES set(SOURCE_GROUP_SOURCE_FILES
@@ -58,6 +59,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimcEclipseStatisticsCase.cpp ${CMAKE_CURRENT_LIST_DIR}/RimcEclipseStatisticsCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimcIdenticalGridCaseGroup.cpp ${CMAKE_CURRENT_LIST_DIR}/RimcIdenticalGridCaseGroup.cpp
${CMAKE_CURRENT_LIST_DIR}/RimcPressureTable.cpp ${CMAKE_CURRENT_LIST_DIR}/RimcPressureTable.cpp
${CMAKE_CURRENT_LIST_DIR}/Rimc3dView.cpp
) )
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@@ -0,0 +1,185 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "Rimc3dView.h"
#include "Rim3dView.h"
#include "RiuViewer.h"
#include "cvfCamera.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmFieldScriptingCapabilityCvfVec3d.h"
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, Rimc3dView_cameraVectors, "CameraVectors" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Rimc3dView_cameraVectors::Rimc3dView_cameraVectors( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self )
{
CAF_PDM_InitObject( "Get Camera Vectors for View", "", "", "Export a surface to file" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* Rimc3dView_cameraVectors::execute()
{
auto dataObject = new RimcCameraVectors();
if ( auto view = self<Rim3dView>() )
{
if ( view->viewer() && view->viewer()->mainCamera() )
{
cvf::Vec3d eye = view->viewer()->mainCamera()->position();
cvf::Vec3d up = view->viewer()->mainCamera()->up();
auto pointOfInterest = view->viewer()->pointOfInterest();
dataObject->setEye( eye );
dataObject->setUp( up );
dataObject->setReferencePoint( pointOfInterest );
}
}
return dataObject;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rimc3dView_cameraVectors::resultIsPersistent() const
{
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::unique_ptr<caf::PdmObjectHandle> Rimc3dView_cameraVectors::defaultResult() const
{
return std::unique_ptr<caf::PdmObjectHandle>( new RimcCameraVectors() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rimc3dView_cameraVectors::isNullptrValidResult() const
{
return true;
}
CAF_PDM_SOURCE_INIT( RimcCameraVectors, "RimcCameraVectors" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcCameraVectors::RimcCameraVectors()
{
CAF_PDM_InitScriptableObject( "Camera Vectors" );
CAF_PDM_InitScriptableFieldNoDefault( &m_eye, "Eye", "Eye" );
CAF_PDM_InitScriptableFieldNoDefault( &m_up, "Up", "Up" );
CAF_PDM_InitScriptableFieldNoDefault( &m_referencePoint, "ReferencePoint", "Reference point" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimcCameraVectors::setEye( const cvf::Vec3d& eye )
{
m_eye = eye;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimcCameraVectors::setUp( const cvf::Vec3d& up )
{
m_up = up;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimcCameraVectors::setReferencePoint( const cvf::Vec3d& referencePoint )
{
m_referencePoint = referencePoint;
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, Rimc3dView_setCameraVectors, "set_camera_vectors" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Rimc3dView_setCameraVectors::Rimc3dView_setCameraVectors( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self )
{
CAF_PDM_InitScriptableFieldNoDefault( &m_eye, "Eye", "Eye" );
CAF_PDM_InitScriptableFieldNoDefault( &m_up, "Up", "Up" );
CAF_PDM_InitScriptableFieldNoDefault( &m_referencePoint, "ReferencePoint", "Reference point" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* Rimc3dView_setCameraVectors::execute()
{
if ( auto view = self<Rim3dView>() )
{
if ( view->viewer() && view->viewer()->mainCamera() )
{
view->viewer()->mainCamera()->setFromLookAt( m_eye(), m_referencePoint(), m_up() );
// Investigate if the following code is required
// view->viewer()->setPointOfInterest( m_referencePoint() );
view->updateDisplayModelForCurrentTimeStepAndRedraw();
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rimc3dView_setCameraVectors::resultIsPersistent() const
{
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::unique_ptr<caf::PdmObjectHandle> Rimc3dView_setCameraVectors::defaultResult() const
{
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rimc3dView_setCameraVectors::isNullptrValidResult() const
{
return true;
}

View File

@@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "cafPdmField.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmObjectMethod.h"
#include "cvfVector3.h"
//==================================================================================================
///
//==================================================================================================
class RimcCameraVectors : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimcCameraVectors();
void setEye( const cvf::Vec3d& eye );
void setUp( const cvf::Vec3d& up );
void setReferencePoint( const cvf::Vec3d& referencePoint );
private:
caf::PdmField<cvf::Vec3d> m_eye;
caf::PdmField<cvf::Vec3d> m_up;
caf::PdmField<cvf::Vec3d> m_referencePoint;
};
//==================================================================================================
///
//==================================================================================================
class Rimc3dView_cameraVectors : public caf::PdmObjectMethod
{
CAF_PDM_HEADER_INIT;
public:
Rimc3dView_cameraVectors( caf::PdmObjectHandle* self );
caf::PdmObjectHandle* execute() override;
bool resultIsPersistent() const override;
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
bool isNullptrValidResult() const override;
};
//==================================================================================================
///
//==================================================================================================
class Rimc3dView_setCameraVectors : public caf::PdmObjectMethod
{
CAF_PDM_HEADER_INIT;
public:
Rimc3dView_setCameraVectors( caf::PdmObjectHandle* self );
caf::PdmObjectHandle* execute() override;
bool resultIsPersistent() const override;
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
bool isNullptrValidResult() const override;
private:
caf::PdmField<cvf::Vec3d> m_eye;
caf::PdmField<cvf::Vec3d> m_up;
caf::PdmField<cvf::Vec3d> m_referencePoint;
};