7 #include "uiMeasurement/action/RemoveDistance.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwCore/base.hpp> 13 #include <fwData/Image.hpp> 14 #include <fwData/Point.hpp> 15 #include <fwData/PointList.hpp> 16 #include <fwData/Vector.hpp> 18 #include <fwDataTools/fieldHelper/Image.hpp> 19 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 21 #include <fwGui/dialog/SelectorDialog.hpp> 23 #include <fwServices/macros.hpp> 25 #include <boost/lexical_cast.hpp> 37 static const ::fwServices::IService::KeyType s_IMAGE_INOUT =
"image";
41 RemoveDistance::RemoveDistance( ) noexcept
47 RemoveDistance::~RemoveDistance() noexcept
53 std::string distanceToStr(
double dist)
63 ::fwData::PointList::sptr getDistanceToRemove(::fwData::Image::sptr image,
bool& removeAll)
65 ::fwData::PointList::sptr distToRemove;
67 ::fwData::Vector::sptr vectDist;
72 std::vector< std::string > selections;
73 selections.push_back(
"ALL");
74 std::map< std::string, ::fwData::PointList::sptr > correspondance;
76 for(::fwData::Object::sptr obj : *vectDist)
78 ::fwData::PointList::sptr pl = ::fwData::PointList::dynamicCast(obj);
80 if ( pl->getPoints().size() != 2 )
84 ::fwData::Point::sptr pt1 = pl->getPoints().front();
85 ::fwData::Point::sptr pt2 = pl->getPoints().back();
88 double delta = pt1->getCoord()[0] - pt2->getCoord()[0];
90 delta = pt1->getCoord()[1] - pt2->getCoord()[1];
92 delta = pt1->getCoord()[2] - pt2->getCoord()[2];
96 selections.push_back( distanceToStr(dist) );
97 correspondance[ selections.back() ] = pl;
100 if ( !selections.empty() )
102 ::fwGui::dialog::SelectorDialog::sptr selector = ::fwGui::dialog::SelectorDialog::New();
103 selector->setTitle(
"Select a distance to remove");
104 selector->setSelections(selections);
105 std::string selection = selector->show();
106 if( !selection.empty() )
108 if (selection ==
"ALL")
115 distToRemove = correspondance[selection];
125 void RemoveDistance::notifyDeleteDistance(const ::fwData::Image::csptr& image,
126 const ::fwData::PointList::csptr& distance)
const 129 sig->asyncEmit(distance);
134 void RemoveDistance::notifyNewDistance(const ::fwData::Image::csptr& image,
135 const ::fwData::PointList::sptr& distance)
const 138 sig->asyncEmit(distance);
145 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
149 image = this->getObject< ::fwData::Image >();
152 ::fwData::Vector::sptr vectDist;
159 ::fwData::PointList::sptr distToRemove = getDistanceToRemove(image, requestAll );
164 SLM_ASSERT(
"No Field ImageDistancesId", vectDist);
165 ::fwData::Vector::IteratorType newEnd = std::remove(vectDist->begin(), vectDist->end(), distToRemove);
166 vectDist->getContainer().erase(newEnd, vectDist->end());
168 this->notifyDeleteDistance(image, distToRemove);
177 this->notifyNewDistance(image, backupDistance);
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
The namespace uiMeasurement contains actions to add/show/remove distances and landmarks.
void configuring() override
Configure the service before starting. Apply the configuration to service.
FWDATA_API void removeField(const FieldNameType &name)
Removes field with specified name.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Defines the service interface managing the menu items.
This class defines a vector of objects.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_ADDED_SIG
Type of signal when image's buffer is added.
void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void initialize()
Initialize the action.
void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
This class defines a list of points.
This class defines an image.
void starting() override
Initialize the service activity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_REMOVED_SIG
Type of signal when image's buffer is added.
This action removes distances from the image field.