fw4spl
SPointLabel.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 #ifndef ANDROID
8 
9 #include "visuVTKAdaptor/SPointLabel.hpp"
10 
11 #include <fwData/Point.hpp>
12 #include <fwData/String.hpp>
13 
14 #include <fwDataTools/fieldHelper/Image.hpp>
15 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp>
16 
17 #include <fwServices/macros.hpp>
18 
19 #include <boost/format.hpp>
20 
21 #include <vtkRenderer.h>
22 #include <vtkTextActor.h>
23 
24 #include <sstream>
25 
26 fwServicesRegisterMacro(::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::SPointLabel);
27 
28 namespace visuVTKAdaptor
29 {
30 
31 const ::fwServices::IService::KeyType SPointLabel::s_POINT_INPUT = "point";
32 
33 //------------------------------------------------------------------------------
34 
35 SPointLabel::SPointLabel() :
36  SText()
37 {
38  m_actor->GetPositionCoordinate()->SetCoordinateSystemToWorld();
39  m_actor->GetPosition2Coordinate()->SetCoordinateSystemToWorld();
40 }
41 
42 //------------------------------------------------------------------------------
43 
45 {
46  this->SText::starting();
47  this->updating();
48 }
49 
50 //------------------------------------------------------------------------------
51 
53 {
54  this->SText::stopping();
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61  ::fwData::Point::csptr point = this->getInput< ::fwData::Point >(s_POINT_INPUT);
62  SLM_ASSERT("Missing point.", point);
63 
64  ::fwData::String::sptr strField = point->getField< ::fwData::String >(::fwDataTools::fieldHelper::Image::m_labelId);
65 
66  if (strField)
67  {
68  std::string label = strField->value();
69 
70  this->setText( label );
71 
72  const double px = point->getCoord()[0];
73  const double py = point->getCoord()[1];
74  const double pz = point->getCoord()[2];
75 
76  m_actor->GetPositionCoordinate()->SetValue(px, py, pz);
77  this->setVtkPipelineModified();
78  this->requestRender();
79  }
80 }
81 
82 //------------------------------------------------------------------------------
83 
85 {
86  KeyConnectionsMap connections;
87  connections.push(s_POINT_INPUT, ::fwData::Point::s_MODIFIED_SIG, s_UPDATE_SLOT);
88 
89  return connections;
90 }
91 
92 //------------------------------------------------------------------------------
93 
94 } //namespace visuVTKAdaptor
95 
96 #endif // ANDROID
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: SPointLabel.cpp:84
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
virtual VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
Definition: SText.cpp:133
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
Definition: SPointLabel.cpp:59
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
Definition: SPointLabel.cpp:44
virtual VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
Definition: SText.cpp:109
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 ...
T & value() noexcept
Get the value (mutable version).
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
Definition: SPoint.cpp:233
#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
static FWDATATOOLS_API const std::string m_labelId
to assign a label
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Displays a label on a point. The label is given in point field "m_labelId".
Definition: SPointLabel.hpp:41
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
Definition: SPointLabel.cpp:52
This class contains an std::string value.