From de11836e033260e2b242753501787cbe541dc33c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 29 Sep 2016 11:43:24 +0200 Subject: [PATCH] AppFwk : Added DisplayCoordTransform --- Fwk/AppFwk/cafVizExtensions/CMakeLists.txt | 2 + .../cafDisplayCoordTransform.cpp | 54 +++++++++++++++++++ .../cafDisplayCoordTransform.h | 30 +++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp create mode 100644 Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h diff --git a/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt b/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt index 040b30288d..a743f3b293 100644 --- a/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt +++ b/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt @@ -15,6 +15,8 @@ include_directories( ) add_library( ${PROJECT_NAME} + cafDisplayCoordTransform.cpp + cafDisplayCoordTransform.h cafBoxManipulatorPartManager.cpp cafBoxManipulatorPartManager.h cafBoxManipulatorGeometryGenerator.cpp diff --git a/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp new file mode 100644 index 0000000000..93cd8fff83 --- /dev/null +++ b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp @@ -0,0 +1,54 @@ + +#include "cafDisplayCoordTransform.h" +#include "cvfMatrix4.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::DisplayCoordTransform::DisplayCoordTransform() + : m_scale(1.0, 1.0, 1.0), + m_translation(cvf::Vec3d::ZERO) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::DisplayCoordTransform::setScale(const cvf::Vec3d& scale) +{ + m_scale = scale; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::DisplayCoordTransform::setTranslation(const cvf::Vec3d& translation) +{ + m_translation = translation; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d caf::DisplayCoordTransform::transformToDisplayCoord(const cvf::Vec3d& domainCoord) const +{ + cvf::Vec3d coord = domainCoord - m_translation; + coord.x() *= m_scale.x(); + coord.y() *= m_scale.y(); + coord.z() *= m_scale.z(); + + return coord; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d caf::DisplayCoordTransform::scaleToDisplaySize(const cvf::Vec3d& domainSize) const +{ + cvf::Vec3d coord = domainSize; + coord.x() *= m_scale.x(); + coord.y() *= m_scale.y(); + coord.z() *= m_scale.z(); + + return coord; +} diff --git a/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h new file mode 100644 index 0000000000..bc485ae093 --- /dev/null +++ b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h @@ -0,0 +1,30 @@ + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cvfVector3.h" + +namespace caf { + +//================================================================================================== +// +// +//================================================================================================== +class DisplayCoordTransform : public cvf::Object +{ +public: + DisplayCoordTransform(); + + void setScale(const cvf::Vec3d& scale); + void setTranslation(const cvf::Vec3d& translation); + + cvf::Vec3d transformToDisplayCoord(const cvf::Vec3d& domainCoord) const; + cvf::Vec3d scaleToDisplaySize(const cvf::Vec3d& domainSize) const; + +private: + cvf::Vec3d m_scale; + cvf::Vec3d m_translation; +}; + +}