7 #include "visuVTKAdaptor/SNegatoMPR.hpp" 9 #include "visuVTKAdaptor/SNegatoOneSlice.hpp" 10 #include "visuVTKAdaptor/SNegatoSlicingInteractor.hpp" 11 #include "visuVTKAdaptor/SNegatoWindowingInteractor.hpp" 12 #include "visuVTKAdaptor/SSlicesCursor.hpp" 14 #include <fwCom/Slot.hpp> 15 #include <fwCom/Slot.hxx> 16 #include <fwCom/Slots.hpp> 17 #include <fwCom/Slots.hxx> 19 #include <fwData/Boolean.hpp> 20 #include <fwData/Image.hpp> 21 #include <fwData/Integer.hpp> 22 #include <fwData/String.hpp> 24 #include <fwDataTools/fieldHelper/Image.hpp> 25 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 27 #include <fwServices/macros.hpp> 28 #include <fwServices/op/Add.hpp> 29 #include <fwServices/registry/Proxy.hpp> 31 #include <fwTools/fwID.hpp> 39 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_TYPE_SLOT =
"updateSliceType";
40 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_MODE_SLOT =
"updateSliceMode";
41 static const ::fwCom::Slots::SlotKeyType s_SHOW_SLICE_SLOT =
"showSlice";
42 static const ::fwCom::Slots::SlotKeyType s_SET_CROSS_SCALE_SLOT =
"setCrossScale";
43 static const ::fwCom::Slots::SlotKeyType S_CHANGE_IMAGE_SOURCE_SLOT =
"changeImageSource";
45 static const std::string s_slicingStartingProxy =
"slicingStartingProxy";
46 static const std::string s_slicingStoppingProxy =
"slicingStoppingProxy";
48 const ::fwServices::IService::KeyType SNegatoMPR::s_IMAGE_INOUT =
"image";
49 const ::fwServices::IService::KeyType SNegatoMPR::s_TF_INOUT =
"tf";
53 SNegatoMPR::SNegatoMPR() noexcept :
54 m_allowAlphaInTF(false),
55 m_interpolation(false),
57 m_3dModeEnabled( ::
boost::logic::indeterminate ),
58 m_sliceMode(THREE_SLICES),
59 m_backupedSliceMode(THREE_SLICES)
61 newSlot(s_UPDATE_SLICE_TYPE_SLOT, &SNegatoMPR::updateSliceType,
this);
62 newSlot(s_UPDATE_SLICE_MODE_SLOT, &SNegatoMPR::updateSliceMode,
this);
63 newSlot(s_SHOW_SLICE_SLOT, &SNegatoMPR::showSlice,
this);
64 newSlot(s_SET_CROSS_SCALE_SLOT, &SNegatoMPR::setCrossScale,
this);
65 newSlot(S_CHANGE_IMAGE_SOURCE_SLOT, &SNegatoMPR::changeImageSource,
this);
70 SNegatoMPR::~SNegatoMPR() noexcept
86 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
94 SNegatoSlicingInteractor::sptr negatoSlicingInteractor = SNegatoSlicingInteractor::dynamicCast(srv.lock());
95 SSlicesCursor::sptr sliceCursor = SSlicesCursor::dynamicCast(srv.lock());
96 if (negatoSlicingInteractor)
98 proxy->disconnect(m_slicingStartingProxy, negatoSlicingInteractor->signal(
100 proxy->disconnect(m_slicingStoppingProxy, negatoSlicingInteractor->signal(
106 proxy->disconnect(m_slicingStartingProxy, sliceCursor->slot(
109 proxy->disconnect(m_slicingStoppingProxy, sliceCursor->slot(
124 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
131 if(this->getSliceMode() != NO_SLICE)
133 if(this->getSliceMode() == ONE_SLICE)
135 this->addAdaptor(
"::visuVTKAdaptor::SNegatoOneSlice",
m_orientation);
137 else if(this->getSliceMode() == THREE_SLICES)
139 this->addAdaptor(
"::visuVTKAdaptor::SNegatoOneSlice", X_AXIS);
140 this->addAdaptor(
"::visuVTKAdaptor::SNegatoOneSlice", Y_AXIS);
141 this->addAdaptor(
"::visuVTKAdaptor::SNegatoOneSlice", Z_AXIS);
144 ::fwRenderVTK::IAdaptor::sptr sliceCursor;
145 ::fwRenderVTK::IAdaptor::sptr negatoSlicingInteractor;
146 this->addAdaptor(
"::visuVTKAdaptor::SNegatoWindowingInteractor");
147 negatoSlicingInteractor = this->addAdaptor(
"::visuVTKAdaptor::SNegatoSlicingInteractor",
m_orientation);
148 sliceCursor = this->addAdaptor(
"::visuVTKAdaptor::SSlicesCursor",
m_orientation);
149 this->addAdaptor(
"::visuVTKAdaptor::SProbeCursor",
m_orientation);
153 m_slicingStartingProxy = image->getID() + s_slicingStartingProxy;
154 m_slicingStoppingProxy = image->getID() + s_slicingStoppingProxy;
155 proxy->connect(m_slicingStartingProxy, negatoSlicingInteractor->signal(
157 proxy->connect(m_slicingStartingProxy, sliceCursor->slot(
160 proxy->connect(m_slicingStoppingProxy, negatoSlicingInteractor->signal(
162 proxy->connect(m_slicingStoppingProxy, sliceCursor->slot(
164 m_sliceCursor = sliceCursor;
166 if(this->is3dModeEnabled())
168 this->addAdaptor(
"::visuVTKAdaptor::SMedical3DCamera",
m_orientation);
170 else if(!this->is3dModeEnabled())
172 this->addAdaptor(
"::visuVTKAdaptor::SSliceFollowerCamera",
m_orientation);
187 if (key == s_TF_INOUT)
189 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
194 ::fwServices::IService::sptr service = srv.lock();
197 service->registerInOut(tf, s_TF_INOUT,
false,
true);
198 service->swapKey(s_TF_INOUT,
nullptr);
202 ::fwServices::OSR::unregisterService(s_TF_INOUT, AccessType::INOUT, service);
203 service->swapKey(s_TF_INOUT,
nullptr);
211 void SNegatoMPR::updateSliceType(
int from,
int to)
225 void SNegatoMPR::updateSliceMode(
int mode)
231 this->setSliceMode(NO_SLICE);
236 this->setSliceMode(ONE_SLICE);
241 this->setSliceMode(THREE_SLICES);
246 FW_RAISE(
"Slice mode " << mode <<
" is not implemented.");
249 m_backupedSliceMode = this->getSliceMode();
254 void SNegatoMPR::showSlice(
bool isShown)
258 this->setSliceMode(m_backupedSliceMode);
262 m_backupedSliceMode = this->getSliceMode();
263 this->setSliceMode(NO_SLICE);
270 void SNegatoMPR::setCrossScale(
double scale)
272 if (!m_sliceCursor.expired())
274 ::fwCom::SlotBase::sptr slot = m_sliceCursor.lock()->slot(s_SET_CROSS_SCALE_SLOT);
275 slot->asyncRun(scale);
281 void SNegatoMPR::changeImageSource(std::string _value, std::string _key)
283 if( _key ==
"ImageSource" )
286 m_imageSourceId = _value;
298 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
300 if (config.count(
"mode"))
302 std::string value = config.get<std::string>(
"mode");
303 std::transform(value.begin(), value.end(), value.begin(), tolower);
304 SLM_ASSERT(
"Bad value '" + value +
"' for attribute mode, it should either be '2d' or '3d'.",
305 value ==
"3d" || value ==
"2d");
306 this->set3dMode(value ==
"3d");
308 if (config.count(
"slices"))
310 const std::string value = config.get<std::string>(
"slices");
314 this->setSliceMode(NO_SLICE);
316 else if(value ==
"1")
318 this->setSliceMode(ONE_SLICE);
320 else if(value ==
"3")
322 this->setSliceMode(THREE_SLICES);
326 SLM_FATAL(
"'slice' value must be '0', '1' or '3', actual: " + value);
328 m_backupedSliceMode = this->getSliceMode();
331 const std::string orientation = config.get<std::string>(
"sliceIndex",
"axial");
332 if(orientation ==
"axial" )
336 else if(orientation ==
"frontal" )
340 else if(orientation ==
"sagittal" )
345 const std::string tfalpha = config.get<std::string>(
"tfalpha",
"no");
346 SLM_ASSERT(
"'tfalpha' value must be 'yes' or 'no', actual: " + tfalpha, tfalpha ==
"yes" || tfalpha ==
"no");
347 this->setAllowAlphaInTF(tfalpha ==
"yes");
349 const std::string interpolation = config.get<std::string>(
"interpolation",
"off");
350 SLM_ASSERT(
"'interpolation' value must be 'on' or 'off', actual: " + interpolation,
351 interpolation ==
"on" || interpolation ==
"off");
352 this->setInterpolation(interpolation ==
"yes");
354 this->setVtkImageSourceId( config.get<std::string>(
"vtkimagesource",
""));
356 m_actorOpacity = config.get<
double>(
"actorOpacity", 1.);
361 void SNegatoMPR::setSliceMode(SliceMode sliceMode)
363 if(m_sliceMode != sliceMode)
365 m_sliceMode = sliceMode;
371 SNegatoMPR::SliceMode SNegatoMPR::getSliceMode()
const 378 ::boost::logic::tribool SNegatoMPR::is3dModeEnabled()
const 380 return m_3dModeEnabled;
385 void SNegatoMPR::set3dMode(
bool enabled )
387 m_3dModeEnabled = enabled;
392 ::fwRenderVTK::IAdaptor::sptr SNegatoMPR::addAdaptor(
const std::string& adaptorType,
int axis)
394 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
398 auto service = this->registerService< ::fwRenderVTK::IAdaptor>(adaptorType);
400 service->registerInOut(image, s_IMAGE_INOUT,
true);
404 auto adaptorSrv = ::fwDataTools::helper::MedicalImageAdaptor::dynamicCast(service);
405 SLM_ASSERT(
"adaptorSrv not instanced", adaptorSrv);
409 auto negatoAdaptor = ::visuVTKAdaptor::SNegatoOneSlice::dynamicCast(service);
413 negatoAdaptor->setAllowAlphaInTF(m_allowAlphaInTF);
414 negatoAdaptor->setInterpolation(m_interpolation);
415 if (!m_imageSourceId.empty())
417 negatoAdaptor->setVtkImageSourceId(m_imageSourceId);
419 negatoAdaptor->setActorOpacity(m_actorOpacity);
422 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
426 service->registerInOut(tf, s_TF_INOUT,
false,
true);
This class is a helper to define the connections of a service and its data.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWSERVICES_API Proxy::sptr getDefault()
Returns an instance of Proxy.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
static VISUVTKADAPTOR_APIconst::fwCom::Signals::SignalKeyType s_SLICING_STARTED_SIG
Type of signal when slicing is updated.
static const ::fwCom::Slots::SlotKeyType s_SHOW_FULL_CROSS_SLOT
Slot: update image slice index.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
static VISUVTKADAPTOR_APIconst::fwCom::Signals::SignalKeyType s_SLICING_STOPPED_SIG
Type of signal when slicing is updated.
const ServiceVector & getRegisteredServices() const
Get all subservices linked to this service.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
virtual void swapping()
Swap the service from associated object to another object.
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
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.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
#define SLM_FATAL(message)
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) ...
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWRENDERVTK_API SRender::VtkObjectIdType getTransformId() const
Returns the identifier of the transform used by this adaptor.
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.
#define SLM_TRACE(message)
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
static const ::fwCom::Slots::SlotKeyType s_SHOW_NORMAL_CROSS_SLOT
Slot: update image slice index.
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.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.