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; +}; + +}