fw4spl
SManageLandmark.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017-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/SManageLandmark.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Slots.hxx>
12 
13 #include <fwData/PointList.hpp>
14 #include <fwData/String.hpp>
15 
16 #include <fwDataTools/fieldHelper/Image.hpp>
17 
18 #include <fwServices/macros.hpp>
19 
21 
22 namespace uiMeasurement
23 {
24 const ::fwServices::IService::KeyType s_LANDMARKS_INOUT = "landmarks";
25 
26 const ::fwCom::Slots::SlotKeyType SManageLandmark::s_CREATE_LANDMARK_SLOT = "createLandmark";
27 const ::fwCom::Slots::SlotKeyType SManageLandmark::s_CLEAR_SLOT = "clearPointlist";
28 
29 // ----------------------------------------------------------------------------
30 
32  m_counter(0)
33 {
34  newSlot(s_CREATE_LANDMARK_SLOT, &SManageLandmark::createLandmark, this);
35  newSlot(s_CLEAR_SLOT, &SManageLandmark::clearPointlist, this);
36 }
37 
38 // ----------------------------------------------------------------------------
39 
41 {
42 }
43 
44 // ----------------------------------------------------------------------------
45 
47 {
48 }
49 
50 // ----------------------------------------------------------------------------
51 
53 {
54 }
55 
56 // ----------------------------------------------------------------------------
57 
59 {
60 }
61 
62 // ----------------------------------------------------------------------------
63 
64 void SManageLandmark::createLandmark(::fwDataTools::PickingInfo info)
65 {
66  if (info.m_eventId == ::fwDataTools::PickingInfo::Event::MOUSE_LEFT_UP &&
67  info.m_modifierMask == ::fwDataTools::PickingInfo::CTRL )
68  {
69  auto pointList = this->getInOut< ::fwData::PointList >(s_LANDMARKS_INOUT);
70 
71  m_counter = pointList->getPoints().size();
72 
73  ::fwData::Point::sptr point = ::fwData::Point::New(info.m_worldPos[0], info.m_worldPos[1], info.m_worldPos[2]);
74 
75  ::fwData::String::sptr label = ::fwData::String::New(std::to_string(m_counter));
76  point->setField( ::fwDataTools::fieldHelper::Image::m_labelId, label );
77 
78  pointList->getPoints().push_back(point);
79 
80  auto sig = pointList->signal< ::fwData::PointList::PointAddedSignalType >(
82  sig->asyncEmit(point);
83  }
84 }
85 
86 //------------------------------------------------------------------------------
87 
88 void SManageLandmark::clearPointlist()
89 {
90  auto pointList = this->getInOut< ::fwData::PointList >(s_LANDMARKS_INOUT);
91 
92  if (pointList)
93  {
94  pointList->getPoints().clear();
95  ::fwData::Point::sptr point;
96  auto sig = pointList->signal< ::fwData::PointList::PointAddedSignalType >(
98  sig->asyncEmit(point);
99  }
100 }
101 
102 // ----------------------------------------------------------------------------
103 
104 } // namespace uiMeasurement
double m_worldPos[3]
Position clicked in world coordinates.
Definition: PickingInfo.hpp:44
UIMEASUREMENT_API void stopping() override
Does nothing.
The namespace uiMeasurement contains actions to add/show/remove distances and landmarks.
Definition: AddDistance.hpp:13
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_ADDED_SIG
Signal emitted when a Point is added.
std::int8_t m_modifierMask
Modifier mask.
Definition: PickingInfo.hpp:52
UIMEASUREMENT_API void configuring() override
This method is used to configure the service.
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
UIMEASUREMENT_API void updating() override
Does nothing.
static FWDATATOOLS_API const std::string m_labelId
to assign a label
Structure to store picking information.
Definition: PickingInfo.hpp:20
UIMEASUREMENT_API SManageLandmark() noexcept
Constructor.
This class defines a list of points.
SManageLandmark adds a point into a pointlist on ctrl-left click.
UIMEASUREMENT_API void starting() override
This method is used to initialize the service.
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.
Definition: IService.cpp:74
Event m_eventId
Mouse event.
Definition: PickingInfo.hpp:50
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_REMOVED_SIG
Signal emitted when a Point is added.