7 #include "visuVTKAdaptor/SNegatoWindowingInteractor.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 13 #include <fwData/Image.hpp> 14 #include <fwData/Integer.hpp> 15 #include <fwData/TransferFunction.hpp> 17 #include <fwDataTools/fieldHelper/Image.hpp> 18 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 20 #include <fwRenderVTK/IAdaptor.hpp> 21 #include <fwRenderVTK/vtk/fwVtkCellPicker.hpp> 23 #include <fwServices/macros.hpp> 25 #include <vtkCommand.h> 26 #include <vtkInteractorStyleImage.h> 27 #include <vtkRenderWindowInteractor.h> 31 #define START_WINDOWING_EVENT vtkCommand::RightButtonPressEvent 32 #define STOP_WINDOWING_EVENT vtkCommand::RightButtonReleaseEvent 37 static const ::fwServices::IService::KeyType s_IMAGE_INOUT =
"image";
38 static const ::fwServices::IService::KeyType s_TF_INOUT =
"tf";
58 m_mouseMoveObserved(
false)
60 this->PassiveObserverOff();
70 virtual void Execute( vtkObject* caller,
unsigned long eventId,
void*)
72 if ( m_mouseMoveObserved || !m_adaptor->getInteractor()->GetShiftKey() )
74 if ( eventId == START_WINDOWING_EVENT)
76 SLM_ASSERT(
"m_adaptor not instanced", m_adaptor);
77 SLM_ASSERT(
"m_picker not instanced", m_picker);
81 m_adaptor->getInteractor()->GetEventPosition(m_x, m_y);
86 if ( m_picker->Pick( display, m_adaptor->getRenderer() ) )
88 assert(!m_mouseMoveObserved);
89 m_adaptor->startWindowing();
90 m_adaptor->getInteractor()->AddObserver(vtkCommand::MouseMoveEvent,
this, 1.);
91 m_mouseMoveObserved =
true;
98 else if ( eventId == STOP_WINDOWING_EVENT)
100 SLM_ASSERT(
"m_adaptor not instanced", m_adaptor);
101 SLM_ASSERT(
"m_picker not instanced", m_picker);
103 if(m_mouseMoveObserved)
105 m_adaptor->getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent,
this);
106 m_mouseMoveObserved =
false;
107 m_adaptor->stopWindowing();
111 else if (eventId == vtkCommand::MouseMoveEvent)
113 SLM_ASSERT(
"m_mouseMoveObserved not instanced", m_mouseMoveObserved);
115 m_adaptor->getInteractor()->GetEventPosition(x, y);
117 double dx = m_windowStep * ( x - m_x );
118 double dy = m_levelStep * ( m_y - y );
120 m_adaptor->updateWindowing(dx, dy);
124 else if (m_adaptor->getInteractor()->GetShiftKey())
126 vtkRenderWindowInteractor* rwi = vtkRenderWindowInteractor::SafeDownCast(caller);
127 char* keySym = rwi->GetKeySym();
128 if(keySym !=
nullptr)
130 if (std::string(keySym) ==
"R")
132 m_adaptor->resetWindowing();
140 void setAdaptor( SNegatoWindowingInteractor::sptr adaptor)
147 void setPicker( vtkAbstractPropPicker* picker)
153 SNegatoWindowingInteractor::sptr m_adaptor;
154 vtkAbstractPropPicker* m_picker;
162 bool m_mouseMoveObserved;
168 SNegatoWindowingInteractor::SNegatoWindowingInteractor() noexcept :
169 m_vtkObserver(
nullptr),
178 SNegatoWindowingInteractor::~SNegatoWindowingInteractor() noexcept
186 this->configureParams();
195 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
198 this->setTransferFunction(tf);
202 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
204 this->createTransferFunction(image);
208 observer->setAdaptor( SNegatoWindowingInteractor::dynamicCast(this->getSptr()) );
209 observer->setPicker(this->getPicker());
211 m_vtkObserver = observer;
213 this->getInteractor()->AddObserver(START_WINDOWING_EVENT, m_vtkObserver, m_priority);
214 this->getInteractor()->AddObserver(STOP_WINDOWING_EVENT, m_vtkObserver, m_priority);
215 this->getInteractor()->AddObserver(vtkCommand::KeyPressEvent, m_vtkObserver, m_priority);
224 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
227 this->updateImageInfos(image);
228 this->requestRender();
235 this->getInteractor()->RemoveObservers(START_WINDOWING_EVENT, m_vtkObserver);
236 this->getInteractor()->RemoveObservers(STOP_WINDOWING_EVENT, m_vtkObserver);
237 this->getInteractor()->RemoveObservers(vtkCommand::KeyPressEvent, m_vtkObserver);
238 m_vtkObserver->Delete();
239 m_vtkObserver =
nullptr;
240 this->removeAllPropFromRenderer();
247 if (key == s_TF_INOUT)
249 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
252 this->setTransferFunction(tf);
256 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
258 this->createTransferFunction(image);
266 void SNegatoWindowingInteractor::startWindowing( )
268 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
273 ::fwData::TransferFunction::sptr tf = this->getTransferFunction();
275 m_initialLevel = tf->getLevel();
276 m_initialWindow = tf->getWindow();
281 void SNegatoWindowingInteractor::stopWindowing( )
287 void SNegatoWindowingInteractor::updateWindowing(
double dw,
double dl )
289 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
291 ::fwData::TransferFunction::sptr tf = this->getTransferFunction();
293 double newWindow = m_initialWindow + dw;
294 double newLevel = m_initialLevel - dl;
296 tf->setWindow( newWindow );
297 tf->setLevel( newLevel );
303 sig->asyncEmit( newWindow, newLevel);
306 this->setVtkPipelineModified();
311 void SNegatoWindowingInteractor::resetWindowing()
313 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
315 ::fwData::TransferFunction::sptr tf = this->getTransferFunction();
317 double newWindow = image->getWindowWidth();
318 double newLevel = image->getWindowCenter();
320 tf->setWindow( newWindow );
321 tf->setLevel( newLevel );
327 sig->asyncEmit( newWindow, newLevel);
330 this->setVtkPipelineModified();
This class is a helper to define the connections of a service and its data.
Class allowing to block a Connection.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
Manage windowing interaction for image.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
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.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
#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/...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_WINDOWING_MODIFIED_SIG
Type of signal when points are modified.
Base class for VTK adaptors.