fw4spl
AddDistance.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 #include "uiMeasurement/action/AddDistance.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwCore/base.hpp>
14 
15 #include <fwData/Boolean.hpp>
16 #include <fwData/Image.hpp>
17 #include <fwData/Point.hpp>
18 #include <fwData/PointList.hpp>
19 #include <fwData/Vector.hpp>
20 
21 #include <fwDataTools/fieldHelper/Image.hpp>
22 
23 #include <fwServices/macros.hpp>
24 
25 #include <exception>
26 
27 namespace uiMeasurement
28 {
29 namespace action
30 {
31 
32 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::uiMeasurement::action::AddDistance, ::fwData::Image );
33 
34 static const ::fwServices::IService::KeyType s_IMAGE_INOUT = "image";
35 
36 //------------------------------------------------------------------------------
37 
38 AddDistance::AddDistance( ) noexcept
39 {
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 AddDistance::~AddDistance() noexcept
45 {
46 }
47 
48 //------------------------------------------------------------------------------
49 
51 {
52  ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
53  if (!image)
54  {
55  FW_DEPRECATED_KEY(s_IMAGE_INOUT, "inout", "18.0");
56  image = this->getObject< ::fwData::Image >();
57  }
58  if (!image)
59  {
60  SLM_WARN("The key '" + s_IMAGE_INOUT + "' is not found.");
61  return;
62  }
63 
64  ::fwData::Point::sptr pt1 = ::fwData::Point::New();
65  std::copy( image->getOrigin().begin(), image->getOrigin().begin() +3, pt1->getCoord().begin() );
66 
67  ::fwData::Point::sptr pt2 = ::fwData::Point::New();
68  std::copy( image->getSize().begin(), image->getSize().begin() +3, pt2->getCoord().begin() );
69 
70  std::transform( pt2->getCoord().begin(), pt2->getCoord().end(),
71  image->getSpacing().begin(),
72  pt2->getCoord().begin(),
73  std::multiplies<double>() );
74  std::transform( pt2->getCoord().begin(), pt2->getCoord().end(),
75  image->getOrigin().begin(),
76  pt2->getCoord().begin(),
77  std::plus<double>() );
78 
79  ::fwData::PointList::sptr pl = ::fwData::PointList::New();
80 
81  pl->getPoints().push_back( pt1 );
82  pl->getPoints().push_back( pt2 );
83 
84  ::fwData::Vector::sptr vectDist;
85  vectDist = image->setDefaultField(::fwDataTools::fieldHelper::Image::m_imageDistancesId, ::fwData::Vector::New());
86 
87  vectDist->getContainer().push_back(pl);
88 
89  // force distance to be shown
90  image->setField("ShowDistances", ::fwData::Boolean::New(true));
91 
93  sig->asyncEmit(pl);
94 }
95 
96 //------------------------------------------------------------------------------
97 
99 {
101 }
102 
103 //------------------------------------------------------------------------------
104 
106 {
108 }
109 
110 //------------------------------------------------------------------------------
111 
113 {
115 }
116 
117 //------------------------------------------------------------------------------
118 
119 } // namespace action
120 
121 } // namespace uiMeasurement
void configuring() override
Configure the service before starting. Apply the configuration to service.
Definition: AddDistance.cpp:98
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
The namespace uiMeasurement contains actions to add/show/remove distances and landmarks.
Definition: AddDistance.hpp:13
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
Definition: AddDistance.cpp:50
#define SLM_WARN(message)
Definition: spyLog.hpp:261
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_ADDED_SIG
Type of signal when image&#39;s buffer is added.
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
This action adds distances on an image field.
Definition: AddDistance.hpp:31
This class defines an image.
void starting() override
Initialize the service activity.