fw4spl
SOrientationMarker.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 #ifndef ANDROID
7 
8 #include "visuVTKAdaptor/SOrientationMarker.hpp"
9 
10 #include <fwRuntime/operations.hpp>
11 
12 #include <fwServices/macros.hpp>
13 
14 #include <vtkActor.h>
15 #include <vtkAxesActor.h>
16 #include <vtkCubeSource.h>
17 #include <vtkGenericDataObjectReader.h>
18 #include <vtkOrientationMarkerWidget.h>
19 #include <vtkPolyData.h>
20 #include <vtkPolyDataMapper.h>
21 #include <vtkRenderer.h>
22 #include <vtkSmartPointer.h>
23 #include <vtkTransform.h>
24 
25 fwServicesRegisterMacro( ::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::SOrientationMarker);
26 
27 namespace visuVTKAdaptor
28 {
29 
30 //-----------------------------------------------------------------------------
31 
32 SOrientationMarker::SOrientationMarker() :
33  m_hAlign("left")
34 {
35 }
36 
37 //-----------------------------------------------------------------------------
38 
39 void SOrientationMarker::starting()
40 {
41  this->initialize();
42 
43  auto filePath = ::fwRuntime::getBundleResourceFilePath("visuVTKAdaptor", "human.vtk");
44 
45  vtkSmartPointer< vtkGenericDataObjectReader > reader = vtkSmartPointer< vtkGenericDataObjectReader >::New();
46  reader->SetFileName( filePath.string().c_str() );
47  reader->Update();
48  vtkDataObject* obj = reader->GetOutput();
49  vtkPolyData* mesh = vtkPolyData::SafeDownCast(obj);
50 
51  SLM_WARN_IF("Orientation marker load failed", !obj);
52 
53  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
54  mapper->SetInputData(mesh);
55 
56  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
57  actor->SetMapper(mapper);
58 
59  m_widget = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
60  m_widget->SetOrientationMarker( actor );
61  m_widget->SetInteractor( this->getInteractor() );
62 
63  if(m_hAlign == "left")
64  {
65  m_widget->SetViewport( 0.0, 0.0, 0.1, 0.1 );
66  }
67  else if(m_hAlign == "right")
68  {
69  m_widget->SetViewport( 0.9, 0.0, 1, 0.1 );
70  }
71 
72  m_widget->SetEnabled( 1 );
73  m_widget->InteractiveOff();
74  this->setVtkPipelineModified();
75  this->requestRender();
76 }
77 
78 //-----------------------------------------------------------------------------
79 
80 void SOrientationMarker::stopping()
81 {
82  this->removeAllPropFromRenderer();
83  m_widget = nullptr;
84 }
85 
86 //-----------------------------------------------------------------------------
87 
88 void SOrientationMarker::configuring()
89 {
90  this->configureParams();
91 
92  const ConfigType config = this->getConfigTree().get_child("config.<xmlattr>");
93 
94  m_hAlign = config.get<std::string>("hAlign", "left");
95  SLM_ASSERT("'hAlign' value must be 'left' or 'right'", m_hAlign == "left" || m_hAlign == "right");
96 }
97 
98 } //namespace visuVTKAdaptor
99 #endif // ANDROID
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
#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
Adaptor used to display an orientationMarker in a generic scene.
FWGUI_API void initialize()
Initialize managers.
#define SLM_WARN_IF(message, cond)
Definition: spyLog.hpp:265
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247