7 #include "visuVTKAdaptor/SImagePickerInteractor.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Slot.hpp> 12 #include <fwCom/Slot.hxx> 13 #include <fwCom/Slots.hpp> 14 #include <fwCom/Slots.hxx> 16 #include <fwData/Composite.hpp> 17 #include <fwData/Material.hpp> 18 #include <fwData/Reconstruction.hpp> 20 #include <fwRenderVTK/vtk/Helpers.hpp> 22 #include <fwServices/macros.hpp> 24 #include <boost/tokenizer.hpp> 26 #include <vtkAbstractPropPicker.h> 28 #include <vtkCommand.h> 29 #include <vtkCubeSource.h> 30 #include <vtkPolyDataMapper.h> 31 #include <vtkRenderWindowInteractor.h> 33 #define START_INTERACTION_EVENT vtkCommand::LeftButtonPressEvent 34 #define STOP_INTERACTION_EVENT vtkCommand::LeftButtonReleaseEvent 41 static const ::fwServices::IService::KeyType s_IMAGE_INOUT =
"image";
43 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_INDEX_SLOT =
"updateSliceIndex";
64 this->PassiveObserverOn();
75 virtual void Execute( vtkObject* caller,
unsigned long eventId,
void*)
77 SLM_ASSERT(
"m_adaptor not instanced", m_adaptor);
78 SLM_ASSERT(
"m_picker not instanced", m_picker);
80 this->process(vtkRenderWindowInteractor::SafeDownCast(caller), eventId);
90 m_adaptor->getInteractor()->GetEventPosition(x, y);
95 return (m_picker->Pick( display, m_adaptor->getRenderer() ) != 0);
100 void process(vtkRenderWindowInteractor* caller,
unsigned long eventId)
102 if( m_eventId->find( static_cast< SImagePickerInteractor::EventID>(eventId) ) != m_eventId->end() )
105 if(eventId == SImagePickerInteractor::MOUSE_MOVE)
110 if( m_skipMove % 10 )
118 if ( this->pickSomething() )
120 double world[3] = {-1, 0, 0};
121 ::fwRenderVTK::vtk::getNearestPickedPosition(m_picker, m_adaptor->getRenderer(), world);
122 OSLM_TRACE(
"PICK" << world[0] <<
" ," << world[1] <<
" ," << world[2] );
126 m_adaptor->worldToImageSliceIndex(world, info.
m_worldPos);
128 const auto iter = SPickerInteractor::s_vtkEventIDConversion.find(eventId);
129 SLM_ASSERT(
"Unknown eventId", iter != SPickerInteractor::s_vtkEventIDConversion.end());
135 caller->GetControlKey() ? ::fwDataTools::PickingInfo::CTRL : ::fwDataTools::PickingInfo::NONE;
137 caller->GetShiftKey() ? ::fwDataTools::PickingInfo::SHIFT : ::fwDataTools::PickingInfo::NONE;
140 SPickerInteractor::s_PICKED_SIGNAL);
141 sig->asyncEmit(info);
149 void setAdaptor( SImagePickerInteractor::sptr adaptor)
156 void setPicker( vtkAbstractPropPicker* picker)
163 void setEventId(SImagePickerInteractor::SetEventIdType* eventId)
169 SImagePickerInteractor::sptr m_adaptor;
170 vtkAbstractPropPicker* m_picker;
171 SImagePickerInteractor::SetEventIdType* m_eventId;
174 unsigned int m_skipMove = 0u;
180 SImagePickerInteractor::SImagePickerInteractor() noexcept
182 newSlot(s_UPDATE_SLICE_INDEX_SLOT, &SImagePickerInteractor::updateSliceIndex,
this);
187 SImagePickerInteractor::~SImagePickerInteractor() noexcept
205 observer->setAdaptor( SImagePickerInteractor::dynamicCast(this->getSptr()) );
206 observer->setPicker(this->getPicker());
207 observer->setEventId(&m_eventId);
209 m_interactionCommand = observer;
211 vtkRenderWindowInteractor* interactor = this->getInteractor();
212 const float priority = 0.999f;
213 interactor->AddObserver(vtkCommand::LeftButtonPressEvent, m_interactionCommand, priority);
214 interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, m_interactionCommand, priority);
215 interactor->AddObserver(vtkCommand::MiddleButtonPressEvent, m_interactionCommand, priority);
216 interactor->AddObserver(vtkCommand::MiddleButtonReleaseEvent, m_interactionCommand, priority);
217 interactor->AddObserver(vtkCommand::RightButtonPressEvent, m_interactionCommand, priority);
218 interactor->AddObserver(vtkCommand::RightButtonReleaseEvent, m_interactionCommand, priority);
219 interactor->AddObserver(vtkCommand::MouseMoveEvent, m_interactionCommand, priority);
220 interactor->AddObserver(vtkCommand::MouseWheelForwardEvent, m_interactionCommand, priority);
221 interactor->AddObserver(vtkCommand::MouseWheelBackwardEvent, m_interactionCommand, priority);
222 interactor->AddObserver(vtkCommand::KeyPressEvent, m_interactionCommand, priority);
224 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
227 this->updateImageInfos(image);
234 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
237 this->updateImageInfos(image);
242 void SImagePickerInteractor::updateSliceIndex(
int axial,
int frontal,
int sagittal)
244 m_axialIndex->value() = axial;
245 m_frontalIndex->value() = frontal;
246 m_sagittalIndex->value() = sagittal;
253 vtkRenderWindowInteractor* interactor = this->getInteractor();
254 interactor->RemoveObservers(vtkCommand::LeftButtonPressEvent, m_interactionCommand);
255 interactor->RemoveObservers(vtkCommand::LeftButtonReleaseEvent, m_interactionCommand);
256 interactor->RemoveObservers(vtkCommand::MiddleButtonPressEvent, m_interactionCommand);
257 interactor->RemoveObservers(vtkCommand::MiddleButtonReleaseEvent, m_interactionCommand);
258 interactor->RemoveObservers(vtkCommand::RightButtonPressEvent, m_interactionCommand);
259 interactor->RemoveObservers(vtkCommand::RightButtonReleaseEvent, m_interactionCommand);
260 interactor->RemoveObservers(vtkCommand::MouseMoveEvent, m_interactionCommand);
261 interactor->RemoveObservers(vtkCommand::MouseWheelForwardEvent, m_interactionCommand);
262 interactor->RemoveObservers(vtkCommand::MouseWheelBackwardEvent, m_interactionCommand);
263 interactor->RemoveObservers(vtkCommand::KeyPressEvent, m_interactionCommand);
265 m_interactionCommand->Delete();
266 m_interactionCommand = NULL;
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_INDEX_MODIFIED_SIG
Type of signal when image's buffer is added.
This class is a helper to define the connections of a service and its data.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
#define OSLM_TRACE(message)
SImagePickerInteractor::PickedSignalType::sptr m_sigPickedCell
signal to emit
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
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.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
This service emits a signal when the user click on the associated image in the scene.
Base class for VTK adaptors.