fw4spl
SMedical3DCamera.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "visuVTKAdaptor/SMedical3DCamera.hpp"
8 
9 #include <fwCom/Slot.hxx>
10 #include <fwCom/Slots.hxx>
11 
12 #include <fwData/String.hpp>
13 #include <fwData/TransformationMatrix3D.hpp>
14 
15 #include <fwServices/macros.hpp>
16 
17 #include <boost/assign/list_of.hpp>
18 
19 #include <vtkActor.h>
20 #include <vtkCamera.h>
21 #include <vtkInteractorStyleImage.h>
22 #include <vtkRenderer.h>
23 #include <vtkRenderWindowInteractor.h>
24 
26 
27 namespace visuVTKAdaptor
28 {
29 
30 static const ::fwCom::Slots::SlotKeyType SET_AXIAL_SLOT = "setAxial";
31 static const ::fwCom::Slots::SlotKeyType SET_SAGITTAL_SLOT = "setSagittal";
32 static const ::fwCom::Slots::SlotKeyType SET_FRONTAL_SLOT = "setFrontal";
33 
34 std::map< std::string, ::fwDataTools::helper::MedicalImageAdaptor::Orientation >
35 SMedical3DCamera::m_orientationConversion = ::boost::assign::map_list_of
36  (std::string("axial"), Z_AXIS)
37  (std::string("frontal"), Y_AXIS)
38  (std::string("sagittal"), X_AXIS);
39 
40 //------------------------------------------------------------------------------
41 
42 SMedical3DCamera::SMedical3DCamera() noexcept :
43  m_resetAtStart(false)
44 
45 {
46  newSlot(SET_AXIAL_SLOT, &SMedical3DCamera::setAxialView, this);
47  newSlot(SET_SAGITTAL_SLOT, &SMedical3DCamera::setSagittalView, this);
48  newSlot(SET_FRONTAL_SLOT, &SMedical3DCamera::setFrontalView, this);
49 }
50 
51 //------------------------------------------------------------------------------
52 
53 SMedical3DCamera::~SMedical3DCamera() noexcept
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61  this->configureParams();
62 
63  const ConfigType config = this->getConfigTree().get_child("config.<xmlattr>");
64 
65  const std::string orientation = config.get<std::string>("sliceIndex", "axial");
66  SLM_ASSERT("Unknown orientation", m_orientationConversion.find(orientation) != m_orientationConversion.end());
67  m_orientation = m_orientationConversion[orientation];
68 
69  const std::string reset = config.get<std::string>("resetAtStart", "no");
70  SLM_ASSERT("'resetAtStart' value must be 'yes' or 'no'", reset == "yes" || reset == "no");
71  m_resetAtStart = (reset == "yes");
72 }
73 
74 //------------------------------------------------------------------------------
75 
77 {
78  this->initialize();
79 
80  m_camera = this->getRenderer()->GetActiveCamera();
81 
82  if(m_resetAtStart)
83  {
84  this->updateView();
85  }
86 }
87 
88 //------------------------------------------------------------------------------
89 
91 {
92  this->updateView();
93  this->requestRender();
94 }
95 
96 //------------------------------------------------------------------------------
97 
99 {
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 void SMedical3DCamera::setSagittalView()
105 {
106  m_orientation = X_AXIS;
107  this->updating();
108 }
109 
110 //------------------------------------------------------------------------------
111 
112 void SMedical3DCamera::setFrontalView()
113 {
114  m_orientation = Y_AXIS;
115  this->updating();
116 }
117 
118 //------------------------------------------------------------------------------
119 
120 void SMedical3DCamera::setAxialView()
121 {
122  m_orientation = Z_AXIS;
123  this->updating();
124 }
125 
126 //------------------------------------------------------------------------------
127 
128 void SMedical3DCamera::updateView()
129 {
130  if(m_orientation == Z_AXIS )
131  {
132  this->resetAxialView();
133  }
134  else if(m_orientation == Y_AXIS )
135  {
136  this->resetFrontalView();
137  }
138  else if(m_orientation == X_AXIS )
139  {
140  this->resetSagittalView();
141  }
142 }
143 
144 //------------------------------------------------------------------------------
145 
146 void SMedical3DCamera::resetSagittalView()
147 {
148  m_camera->SetPosition(-1, 0, 0);
149  m_camera->SetFocalPoint(0, 0, 0);
150  m_camera->SetViewUp(0, 0, 1);
151  this->getRenderer()->ResetCamera();
152  this->setVtkPipelineModified();
153 }
154 
155 //------------------------------------------------------------------------------
156 
157 void SMedical3DCamera::resetFrontalView()
158 {
159  m_camera->SetPosition(0, -1, 0);
160  m_camera->SetFocalPoint(0, 0, 0);
161  m_camera->SetViewUp(0, 0, 1);
162  this->getRenderer()->ResetCamera();
163  this->setVtkPipelineModified();
164 
165 }
166 
167 //------------------------------------------------------------------------------
168 
169 void SMedical3DCamera::resetAxialView()
170 {
171  m_camera->SetPosition(0, 0, -1);
172  m_camera->SetFocalPoint(0, 0, 0);
173  m_camera->SetViewUp(0, -1, 0);
174  this->getRenderer()->ResetCamera();
175  this->setVtkPipelineModified();
176 }
177 
178 //------------------------------------------------------------------------------
179 
180 } //namespace visuVTKAdaptor
181 
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
Update camera scene according to defined axes (axial, sagittal, frontal).
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
Orientation m_orientation
Image orientation.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
Base class for each data object.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247