7 #include "visuVTKAdaptor/SNegatoOneSlice.hpp" 9 #include "visuVTKAdaptor/SImage.hpp" 10 #include "visuVTKAdaptor/SImageSlice.hpp" 12 #include <fwCom/Slot.hpp> 13 #include <fwCom/Slot.hxx> 14 #include <fwCom/Slots.hpp> 15 #include <fwCom/Slots.hxx> 17 #include <fwData/Color.hpp> 18 #include <fwData/Image.hpp> 19 #include <fwData/String.hpp> 20 #include <fwData/TransferFunction.hpp> 22 #include <fwDataTools/fieldHelper/Image.hpp> 23 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 25 #include <fwServices/macros.hpp> 26 #include <fwServices/op/Add.hpp> 28 #include <fwVtkIO/vtk.hpp> 30 #include <vtkImageBlend.h> 31 #include <vtkImageCheckerboard.h> 32 #include <vtkImageData.h> 33 #include <vtkImageMapToColors.h> 40 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_TYPE_SLOT =
"updateSliceType";
41 static const ::fwCom::Slots::SlotKeyType s_UPDATE_IMAGE_SLOT =
"updateImage";
43 static const ::fwServices::IService::KeyType s_IMAGE_INOUT =
"image";
44 static const ::fwServices::IService::KeyType s_TF_INOUT =
"tf";
48 SNegatoOneSlice::SNegatoOneSlice() noexcept :
49 m_manageImageSource(false),
50 m_imageSource(
nullptr),
51 m_allowAlphaInTF(false),
52 m_interpolation(true),
55 newSlot(s_UPDATE_SLICE_TYPE_SLOT, &SNegatoOneSlice::updateSliceType,
this);
56 newSlot(s_UPDATE_IMAGE_SLOT, &SNegatoOneSlice::updateImage,
this);
61 SNegatoOneSlice::~SNegatoOneSlice() noexcept
64 this->cleanImageSource();
69 vtkObject* SNegatoOneSlice::getImageSource()
74 if (!m_imageSourceId.empty())
80 m_imageSource = vtkImageMapToColors::New();
81 m_manageImageSource =
true;
90 void SNegatoOneSlice::cleanImageSource()
92 if (m_manageImageSource && m_imageSource)
94 m_imageSource->Delete();
95 m_imageSource =
nullptr;
101 ::fwRenderVTK::IAdaptor::sptr SNegatoOneSlice::getImageSliceAdaptor()
103 if (m_imageSliceAdaptor.expired())
106 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
110 auto imgSliceAdaptor = this->registerService< ::visuVTKAdaptor::SImageSlice>(
"::visuVTKAdaptor::SImageSlice");
111 imgSliceAdaptor->registerInOut(image, s_IMAGE_INOUT,
true);
115 imgSliceAdaptor->setPickerId( this->
getPickerId() );
118 imgSliceAdaptor->setVtkImageSource(this->getImageSource());
119 imgSliceAdaptor->setInterpolation(m_interpolation);
120 imgSliceAdaptor->setActorOpacity(m_actorOpacity);
123 m_imageSliceAdaptor = imgSliceAdaptor;
126 return m_imageSliceAdaptor.lock();
131 ::fwRenderVTK::IAdaptor::sptr SNegatoOneSlice::getImageAdaptor()
133 if (m_imageAdaptor.expired())
136 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
140 auto imgAdaptor = this->registerService< ::visuVTKAdaptor::SImage>(
"::visuVTKAdaptor::SImage");
141 imgAdaptor->registerInOut(image, s_IMAGE_INOUT,
true);
148 imgAdaptor->setVtkImageRegister(this->getImageSource());
150 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
153 imgAdaptor->registerInOut(tf, s_TF_INOUT,
false,
true);
156 imgAdaptor->setImageOpacity(1.);
157 imgAdaptor->setAllowAlphaInTF(m_allowAlphaInTF);
159 m_imageAdaptor = imgAdaptor;
162 return m_imageAdaptor.lock();
170 if (
nullptr == vtkImageBlend::SafeDownCast(this->getImageSource())
171 &&
nullptr == vtkImageCheckerboard::SafeDownCast(this->getImageSource()))
173 this->getImageAdaptor()->start();
175 this->getImageSliceAdaptor()->start();
183 this->cleanImageSource();
190 if (
nullptr == vtkImageBlend::SafeDownCast(this->getImageSource())
191 &&
nullptr == vtkImageCheckerboard::SafeDownCast(this->getImageSource()))
193 this->getImageAdaptor()->update();
195 this->getImageSliceAdaptor()->update();
202 if (key == s_TF_INOUT
203 &&
nullptr == vtkImageBlend::SafeDownCast(this->getImageSource())
204 &&
nullptr == vtkImageCheckerboard::SafeDownCast(this->getImageSource()))
206 IAdaptor::sptr imageAdaptor = this->getImageAdaptor();
207 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
210 imageAdaptor->registerInOut(tf, s_TF_INOUT,
false,
true);
211 imageAdaptor->swapKey(s_TF_INOUT,
nullptr);
215 ::fwServices::OSR::unregisterService(s_TF_INOUT, AccessType::INOUT, imageAdaptor);
216 imageAdaptor->swapKey(s_TF_INOUT,
nullptr);
223 void SNegatoOneSlice::updateSliceType(
int from,
int to)
237 void SNegatoOneSlice::updateImage()
250 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
252 const std::string orientation = config.get<std::string>(
"sliceIndex",
"axial");
253 if(orientation ==
"axial" )
257 else if(orientation ==
"frontal" )
261 else if(orientation ==
"sagittal" )
266 const std::string tfalpha = config.get<std::string>(
"tfalpha",
"no");
267 SLM_ASSERT(
"'tfalpha' value must be 'yes' or 'no', actual: " + tfalpha, tfalpha ==
"yes" || tfalpha ==
"no");
268 this->setAllowAlphaInTF(tfalpha ==
"yes");
270 const std::string interpolation = config.get<std::string>(
"interpolation",
"off");
271 SLM_ASSERT(
"'interpolation' value must be 'on' or 'off', actual: " + interpolation,
272 interpolation ==
"on" || interpolation ==
"off");
273 this->setInterpolation(interpolation ==
"yes");
275 this->setVtkImageSourceId( config.get<std::string>(
"vtkimagesource",
""));
277 m_actorOpacity = config.get<
double>(
"actorOpacity", 1.);
This class is a helper to define the connections of a service and its data.
FWRENDERVTK_API vtkObject * getVtkObject(const SRender::VtkObjectIdType &objectId) const
Returns the vtk object defined by 'objectId' in the vtk scene.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
Display a negato image with one slice.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
virtual void swapping()
Swap the service from associated object to another object.
#define OSLM_TRACE(message)
FWRENDERVTK_API SRender::sptr getRenderService() const
Returd the associated render service.
FWRENDERVTK_API SRender::PickerIdType getPickerId() const
Gets the identifier of the picker used by this adaptor.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWSERVICES_API void unregisterServices(const std::string &_implType="")
Unregister all services linked to this service, optionally matches only a given type of services...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRENDERVTK_API SRender::VtkObjectIdType getTransformId() const
Returns the identifier of the transform used by this adaptor.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWRENDERVTK_API SRender::RendererIdType getRendererId() const
Returns the renderer identifier.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
FWSERVICES_API bool isRegistered(const ::fwServices::IService::KeyType &objKey,::fwServices::IService::AccessType access,::fwServices::IService::sptr service)
Return true if a key is registered for a given service.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_TYPE_MODIFIED_SIG
Type of signal when image's buffer is added.
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.