7 #include "opImageFilter/SThreshold.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 12 #include <fwData/Image.hpp> 14 #include <fwDataTools/helper/Image.hpp> 15 #include <fwDataTools/helper/ImageGetter.hpp> 17 #include <fwMedData/ImageSeries.hpp> 19 #include <fwServices/macros.hpp> 21 #include <fwTools/Dispatcher.hpp> 22 #include <fwTools/DynamicTypeKeyTypeMapping.hpp> 23 #include <fwTools/fwID.hpp> 24 #include <fwTools/IntrinsicTypes.hpp> 31 static const std::string s_IMAGE_INPUT =
"source";
32 static const std::string s_IMAGE_OUTPUT =
"target";
36 SThreshold::SThreshold() noexcept :
43 SThreshold::~SThreshold() noexcept
63 const ::fwServices::IService::ConfigType& srvConfig = this->
getConfigTree();
65 SLM_ASSERT(
"You must have one <config/> element.", srvConfig.count(
"config") == 1 );
67 const ::fwServices::IService::ConfigType& config = srvConfig.get_child(
"config");
69 SLM_ASSERT(
"You must have one <threshold/> element.", config.count(
"threshold") == 1);
70 const ::fwServices::IService::ConfigType& thresholdCfg = config.get_child(
"threshold");
71 m_threshold = thresholdCfg.get_value<
double>();
97 template<
class PIXELTYPE>
100 const PIXELTYPE thresholdValue =
static_cast<PIXELTYPE
>(param.
thresholdValue);
101 ::fwData::Image::csptr imageIn = param.
imageIn;
102 ::fwData::Image::sptr imageOut = param.
imageOut;
103 SLM_ASSERT(
"Sorry, image must be 3D", imageIn->getNumberOfDimensions() == 3 );
104 imageOut->copyInformation(imageIn);
105 imageOut->allocate();
111 const PIXELTYPE* buffer1 = (PIXELTYPE*)imageInHelper.
getBuffer();
112 PIXELTYPE* buffer2 = (PIXELTYPE*)imageOutHelper.
getBuffer();
115 const size_t NbPixels = imageIn->getSize()[0] * imageIn->getSize()[1] * imageIn->getSize()[2];
118 for(
size_t i = 0; i < NbPixels; ++i, ++buffer1, ++buffer2 )
120 * buffer2 = ( *buffer1 < thresholdValue ) ? 0 : std::numeric_limits<PIXELTYPE>::max();
131 ::fwData::Object::csptr input = this->getInput< ::fwData::Object >(s_IMAGE_INPUT);
132 ::fwMedData::ImageSeries::csptr imageSeriesSrc = ::fwMedData::ImageSeries::dynamicConstCast(input);
133 ::fwData::Image::csptr imageSrc = ::fwData::Image::dynamicConstCast(input);
134 ::fwData::Object::sptr output;
139 param.
imageIn = imageSeriesSrc->getImage();
140 ::fwMedData::ImageSeries::sptr imageSeriesDest = ::fwMedData::ImageSeries::New();
142 ::fwData::Object::DeepCopyCacheType cache;
143 imageSeriesDest->::fwMedData::Series::cachedDeepCopy(imageSeriesSrc, cache);
144 imageSeriesDest->setDicomReference(imageSeriesSrc->getDicomReference());
146 ::fwData::Image::sptr imageOut = ::fwData::Image::New();
147 imageSeriesDest->setImage(imageOut);
149 output = imageSeriesDest;
154 ::fwData::Image::sptr imageOut = ::fwData::Image::New();
160 FW_RAISE(
"Wrong type: source type must be an ImageSeries or an Image");
double thresholdValue
threshold value.
The namespace opImageFilter contains several operators on image.
OPIMAGEFILTER_API void configuring() override
Configure the service.
FWSERVICES_API void setOutput(const ::fwServices::IService::KeyType &key, const ::fwData::Object::sptr &object, size_t index=0)
Register an output object at a given key in the OSR, replacing it if it already exists.
::fwData::Image::sptr imageOut
image target: contains the result of the filter
OPIMAGEFILTER_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
OPIMAGEFILTER_API void starting() override
Initialize the service activity.
::fwData::Image::csptr imageIn
image source
OPIMAGEFILTER_API void updating() override
Apply the threshold.
void operator()(Parameter ¶m)
Applies the filter.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.