Carna Registration API Version 1.16.0
|
00001 /* 00002 * Copyright (C) 2010 - 2013 Leonid Kostrykin 00003 * 00004 * Chair of Medical Engineering (mediTEC) 00005 * RWTH Aachen University 00006 * Pauwelsstr. 20 00007 * 52074 Aachen 00008 * Germany 00009 * 00010 */ 00011 00012 #ifndef LINKEDCAMERA_H_2521354512 00013 #define LINKEDCAMERA_H_2521354512 00014 00015 #include "VirtualElement.h" 00016 #include "LinkedCameraImplementation.h" 00017 #include "LinkedCameraDebugger.h" 00018 #include <Carna/base/view/SceneProvider.h> 00019 #include <Carna/base/view/Camera.h> 00020 #include <Carna/base/model/Position.h> 00021 #include <Carna/base/Transformation.h> 00022 #include <Carna/base/view/Renderer.h> 00023 #include <Carna/base/Visualization.h> 00024 #include <Carna/base/VisualizationEnvironment.h> 00025 00026 class QGLPixelBuffer; 00027 class QGLContext; 00028 00029 namespace CRA 00030 { 00031 00032 00033 00034 // ---------------------------------------------------------------------------------- 00035 // LinkedCamera Adaptive Interface 00036 // ---------------------------------------------------------------------------------- 00037 00047 class LinkedCamera : public Carna::base::view::Camera, public VirtualElement, protected LinkedCameraDebugger 00048 { 00049 00050 public: 00051 00063 LinkedCamera(); 00064 00069 LinkedCamera 00070 ( const std::string& xrayEmptyTrf 00071 , const std::string& xrayEmptyCof 00072 , const std::string& transformationIni ); 00073 00076 virtual ~LinkedCamera(); 00077 00078 00079 virtual void update 00080 ( const Transformation& bearing 00081 , const Registration& registration ) override; 00082 00083 00086 virtual void fetchCameraMatrix( Carna::base::view::Renderer&, Transformation& ) override; 00087 00090 virtual void fetchProjectionMatrix( Carna::base::view::Renderer&, Transformation& ) override; 00091 00092 00097 virtual void openShutter( Carna::base::view::Renderer& ) override; 00098 00103 virtual void closeShutter( Carna::base::view::Renderer& ) override; 00104 00105 00110 bool isInDebugMode() const; 00111 00116 void setInDebugMode( bool ); 00117 00118 00119 protected: 00120 00121 virtual void paintText( const Vector& position, const std::string& text ) override; 00122 00123 00124 private: 00125 00126 const std::unique_ptr< LinkedCameraImplementation > implementation; 00127 00128 // ---------------------------------------------------------------------------------- 00129 00130 void compute( Carna::base::view::Renderer& ); 00131 00132 // ---------------------------------------------------------------------------------- 00133 00134 bool inDebugMode; 00135 00136 Carna::base::view::Renderer* lastUsedRenderer; 00137 00138 }; // LinkedCamera 00139 00140 00141 00142 // ---------------------------------------------------------------------------------- 00143 // LinkedCamera Implementation 00144 // ---------------------------------------------------------------------------------- 00145 00146 inline 00147 LinkedCamera::LinkedCamera 00148 ( const std::string& xrayEmptyTrf 00149 , const std::string& xrayEmptyCof 00150 , const std::string& transformationIni ) 00151 00152 : Carna::base::view::Camera() 00153 , implementation( new LinkedCameraImplementation( *this, xrayEmptyTrf, xrayEmptyCof, transformationIni ) ) 00154 , inDebugMode( false ) 00155 , lastUsedRenderer( nullptr ) 00156 { 00157 } 00158 00159 00160 inline 00161 LinkedCamera::LinkedCamera() 00162 : implementation( new LinkedCameraImplementation( *this ) ) 00163 , inDebugMode( false ) 00164 , lastUsedRenderer( nullptr ) 00165 { 00166 } 00167 00168 00169 inline 00170 LinkedCamera::~LinkedCamera() 00171 { 00172 } 00173 00174 00175 inline 00176 void LinkedCamera::update( const Transformation& physical_bearing, const Registration& registration ) 00177 { 00178 implementation->update( physical_bearing, registration ); 00179 00180 emit viewChanged(); 00181 } 00182 00183 00184 inline 00185 void LinkedCamera::compute( Carna::base::view::Renderer& renderer ) 00186 { 00187 implementation->compute( renderer.shortestTargetSide() ); 00188 00189 // ---------------------------------------------------------------------------------- 00190 00191 const Transformation reverse_trafo = implementation->registration().getTransformation().inverse(); 00192 00193 const Vector model_center_offset = Carna::base::model::Position::fromVolumeUnits 00194 ( renderer.provider.scene, 0.5, 0.5, 0.5 ).toMillimeters(); 00195 00196 fromReferenceBase = implementation->cameraTransformation(); 00197 fromLocalToReferenceBase = implementation->physicalBearing(); 00198 fromSceneSpaceToReferenceBase = reverse_trafo 00199 * Transformation().translate( model_center_offset.x() 00200 , model_center_offset.y() 00201 , model_center_offset.z() ); 00202 00203 implementation->setCameraTransformation 00204 ( implementation->cameraTransformation() 00205 * fromSceneSpaceToReferenceBase ); 00206 } 00207 00208 00209 inline 00210 void LinkedCamera::fetchCameraMatrix( Carna::base::view::Renderer& renderer, Transformation& out ) 00211 { 00212 out = implementation->cameraTransformation(); 00213 } 00214 00215 00216 inline 00217 void LinkedCamera::fetchProjectionMatrix( Carna::base::view::Renderer& renderer, Transformation& out ) 00218 { 00219 out = implementation->projectionTransformation(); 00220 } 00221 00222 00223 inline 00224 void LinkedCamera::openShutter( Carna::base::view::Renderer& renderer ) 00225 { 00226 if( implementation->hasRegistration() ) 00227 { 00228 this->compute( renderer ); 00229 } 00230 } 00231 00232 00233 inline 00234 void LinkedCamera::closeShutter( Carna::base::view::Renderer& renderer ) 00235 { 00236 if( isInDebugMode() ) 00237 { 00238 renderer.setSquareViewport(); 00239 00240 this->lastUsedRenderer = &renderer; 00241 this->paintDebugInfo( *implementation ); 00242 } 00243 } 00244 00245 00246 inline 00247 void LinkedCamera::paintText( const Vector& position, const std::string& text ) 00248 { 00249 lastUsedRenderer->module().environment().paintText( position, text ); 00250 } 00251 00252 00253 inline 00254 bool LinkedCamera::isInDebugMode() const 00255 { 00256 return inDebugMode; 00257 } 00258 00259 00260 inline 00261 void LinkedCamera::setInDebugMode( bool inDebugMode ) 00262 { 00263 if( this->inDebugMode != inDebugMode ) 00264 { 00265 this->inDebugMode = inDebugMode; 00266 emit viewChanged(); 00267 } 00268 } 00269 00270 00271 00272 } // namespace CRA 00273 00274 #endif // LINKEDCAMERA_H_2521354512
Documentation generated by Doxygen