diff --git a/Modules/IGT/IGTFilters/mitkCameraVisualization.cpp b/Modules/IGT/IGTFilters/mitkCameraVisualization.cpp index 85727a7a3b..3ab657b9c4 100644 --- a/Modules/IGT/IGTFilters/mitkCameraVisualization.cpp +++ b/Modules/IGT/IGTFilters/mitkCameraVisualization.cpp @@ -1,146 +1,148 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkCameraVisualization.h" #include "vtkCamera.h" #include "mitkPropertyList.h" #include "mitkProperties.h" mitk::CameraVisualization::CameraVisualization(): NavigationDataToNavigationDataFilter(), m_Renderer(NULL), m_FocalLength(10.0), m_ViewAngle(30.0) { // initialize members m_DirectionOfProjectionInToolCoordinates[0] = 0; m_DirectionOfProjectionInToolCoordinates[1] = 0; m_DirectionOfProjectionInToolCoordinates[2] = -1; m_ViewUpInToolCoordinates[0] = 1; m_ViewUpInToolCoordinates[1] = 0; m_ViewUpInToolCoordinates[2] = 0; + m_DirectionOfProjection.Fill(0); } mitk::CameraVisualization::~CameraVisualization() { } void mitk::CameraVisualization::GenerateData() { // check if renderer was set if (m_Renderer.IsNull()) itkExceptionMacro(<< "Renderer was not properly set"); /* update outputs with tracking data from tools */ unsigned int numberOfInputs = this->GetNumberOfInputs(); for (unsigned int i = 0; i < numberOfInputs ; ++i) { mitk::NavigationData* output = this->GetOutput(i); assert(output); const mitk::NavigationData* input = this->GetInput(i); assert(input); if (input->IsDataValid() == false) { continue; } output->Graft(input); // First, copy all information from input to output } const NavigationData* navigationData = this->GetInput(); // get position from NavigationData to move the camera to this position Point3D cameraPosition = navigationData->GetPosition(); + m_TipPosition = cameraPosition; //calculate the transform from the quaternions static itk::QuaternionRigidTransform::Pointer quatTransform = itk::QuaternionRigidTransform::New(); mitk::NavigationData::OrientationType orientation = navigationData->GetOrientation(); // convert mitk::Scalartype quaternion to double quaternion because of itk bug vnl_quaternion doubleQuaternion(orientation.x(), orientation.y(), orientation.z(), orientation.r()); quatTransform->SetIdentity(); quatTransform->SetRotation(doubleQuaternion); quatTransform->Modified(); /* because of an itk bug, the transform can not be calculated with float datatype. To use it in the mitk geometry classes, it has to be transfered to mitk::ScalarType which is float */ static AffineTransform3D::MatrixType m; mitk::TransferMatrix(quatTransform->GetMatrix(), m); - Vector3D directionOfProjection = m*m_DirectionOfProjectionInToolCoordinates; - directionOfProjection.Normalize(); - Point3D focalPoint = cameraPosition + m_FocalLength*directionOfProjection; + m_DirectionOfProjection = m*m_DirectionOfProjectionInToolCoordinates; + m_DirectionOfProjection.Normalize(); + Point3D focalPoint = cameraPosition + m_FocalLength*m_DirectionOfProjection; // compute current view up vector Vector3D viewUp = m*m_ViewUpInToolCoordinates; m_Renderer->GetVtkRenderer()->GetActiveCamera()->SetPosition(cameraPosition[0],cameraPosition[1],cameraPosition[2]); m_Renderer->GetVtkRenderer()->GetActiveCamera()->SetFocalPoint(focalPoint[0],focalPoint[1],focalPoint[2]); m_Renderer->GetVtkRenderer()->GetActiveCamera()->SetViewUp(viewUp[0],viewUp[1],viewUp[2]); m_Renderer->GetVtkRenderer()->ResetCameraClippingRange(); m_Renderer->RequestUpdate(); } void mitk::CameraVisualization::SetRenderer(mitk::BaseRenderer* renderer) { m_Renderer = renderer; // if (m_Renderer) // { // m_Renderer->GetVtkRenderer()->GetActiveCamera()->Zoom(0.4); // } } const mitk::BaseRenderer* mitk::CameraVisualization::GetRenderer() { return m_Renderer; } void mitk::CameraVisualization::SetParameters( const mitk::PropertyList* p ) { if (p == NULL) return; mitk::Vector3D doP; if (p->GetPropertyValue("CameraVisualization_DirectionOfProjectionInToolCoordinates", doP) == true) // search for DirectionOfProjectionInToolCoordinates parameter this->SetDirectionOfProjectionInToolCoordinates(doP); // apply if found; mitk::Vector3D vUp; if (p->GetPropertyValue("CameraVisualization_ViewUpInToolCoordinates", vUp) == true) // search for ViewUpInToolCoordinates parameter this->SetViewUpInToolCoordinates(vUp); // apply if found; float fL; if (p->GetPropertyValue("CameraVisualization_FocalLength", fL) == true) // search for FocalLength parameter this->SetFocalLength(fL); // apply if found; float vA; if (p->GetPropertyValue("CameraVisualization_ViewAngle", vA) == true) // search for ViewAngle parameter this->SetFocalLength(vA); // apply if found; } mitk::PropertyList::ConstPointer mitk::CameraVisualization::GetParameters() const { mitk::PropertyList::Pointer p = mitk::PropertyList::New(); p->SetProperty("CameraVisualization_DirectionOfProjectionInToolCoordinates", mitk::Vector3DProperty::New(this->GetDirectionOfProjectionInToolCoordinates())); // store DirectionOfProjectionInToolCoordinates parameter p->SetProperty("CameraVisualization_ViewUpInToolCoordinates", mitk::Vector3DProperty::New(this->GetViewUpInToolCoordinates())); // store ViewUpInToolCoordinates parameter p->SetProperty("CameraVisualization_FocalLength", mitk::Vector3DProperty::New(this->GetFocalLength())); // store FocalLength parameter p->SetProperty("CameraVisualization_ViewAngle", mitk::Vector3DProperty::New(this->GetViewAngle())); // store ViewAngle parameter return mitk::PropertyList::ConstPointer(p); } diff --git a/Modules/IGT/IGTFilters/mitkCameraVisualization.h b/Modules/IGT/IGTFilters/mitkCameraVisualization.h index da0bf96784..6c7a3a1a64 100644 --- a/Modules/IGT/IGTFilters/mitkCameraVisualization.h +++ b/Modules/IGT/IGTFilters/mitkCameraVisualization.h @@ -1,133 +1,135 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef CAMERAVISUALIZATION_H_INCLUDED #define CAMERAVISUALIZATION_H_INCLUDED #include "mitkCommon.h" #include "mitkNavigationDataToNavigationDataFilter.h" #include "mitkBaseRenderer.h" namespace mitk { /**Documentation * \brief CameraVisualization controls the camera according to the spatial information of the navigation data * * The camera of the renderer will be placed at the position of the navigation data and oriented according to * its orientation and the camera specific information "direction of projection", "view up", "focal length", "view angle" * * \ingroup IGT */ class MitkIGT_EXPORT CameraVisualization : public NavigationDataToNavigationDataFilter { public: mitkClassMacro(CameraVisualization, NavigationDataToNavigationDataFilter); itkNewMacro(Self); /** * \brief sets the direction of projection of the camera of the renderer in tool coordinates */ itkSetMacro(DirectionOfProjectionInToolCoordinates, mitk::Vector3D); /** * \brief sets the view up vector of the camera of the renderer in tool coordinates */ itkSetMacro(ViewUpInToolCoordinates, mitk::Vector3D); /** * \brief sets the focal length of the camera */ itkSetMacro(FocalLength, float); /** * \brief sets the view angle of the camera of the renderer which angular height of the camera view measured in degrees (cf. vtkCamera) */ itkSetMacro(ViewAngle, float); /** * \brief returns the direction of projection of the camera of the renderer in tool coordinates */ itkGetConstMacro(DirectionOfProjectionInToolCoordinates, mitk::Vector3D); /** * \brief returns the view up vector of the camera of the renderer in tool coordinates */ itkGetConstMacro(ViewUpInToolCoordinates, mitk::Vector3D); /** * \brief returns the focal length of the camera */ itkGetConstMacro(FocalLength, float); /** * \brief returns the view angle of the camera of the renderer which angular height of the camera view measured in degrees (cf. vtkCamera) */ itkGetConstMacro(ViewAngle, float); /** * \brief sets renderer that visualizes the navigation data */ virtual void SetRenderer( mitk::BaseRenderer* renderer ); /** * \brief returns the renderer that visualizes the navigation data */ virtual const mitk::BaseRenderer* GetRenderer(); /**Documentation *\brief Set all filter parameters as the PropertyList p * * This method reads the following properties from the PropertyList (name : data type): * - "CameraVisualization_DirectionOfProjectionInToolCoordinates" : mitk::Vector3DProperty * - "CameraVisualization_ViewUpInToolCoordinates" : mitk::Vector3DProperty * - "CameraVisualization_FocalLength" : mitk::FloatProperty * - "CameraVisualization_ViewAngle" : mitk::FloatProperty */ virtual void SetParameters(const mitk::PropertyList* p); /**Documentation *\brief Get all filter parameters as a PropertyList * * This method returns a PropertyList containing the following * properties (name : data type): * - "CameraVisualization_DirectionOfProjectionInToolCoordinates" : mitk::Vector3DProperty * - "CameraVisualization_ViewUpInToolCoordinates" : mitk::Vector3DProperty * - "CameraVisualization_FocalLength" : mitk::FloatProperty * - "CameraVisualization_ViewAngle" : mitk::FloatProperty * The returned PropertyList must be assigned to a * SmartPointer immediately, or else it will get destroyed. */ mitk::PropertyList::ConstPointer GetParameters() const; protected: CameraVisualization(); virtual ~CameraVisualization(); /**Documentation * \brief filter execute method * * positions and orients camera according to the position and orientation hold in the NavigationData */ virtual void GenerateData(); mitk::BaseRenderer::Pointer m_Renderer; ///< renderer that visualizes the navigation data- Vector3D m_DirectionOfProjectionInToolCoordinates; ///< vector of the direction of projection in tool coordinates Vector3D m_ViewUpInToolCoordinates; ///< view up vector in tool coordinates + Vector3D m_DirectionOfProjection; ///< vector of the current direction of view of the camera in world coordinates + Point3D m_TipPosition; ///< current position of the tip of the instrument float m_FocalLength; ///< focal length of the camera: distance between camera position and focal point. float m_ViewAngle; ///< view angle of the camera: angular height of the camera view measured in degrees. }; } // namespace mitk #endif